y.prices.dex package
Subpackages
- y.prices.dex.balancer package
- Submodules
- y.prices.dex.balancer.balancer module
BalancerMultiplexer
BalancerMultiplexer.__init__()
BalancerMultiplexer.__v1__
BalancerMultiplexer.__v2__
BalancerMultiplexer.__versions__
BalancerMultiplexer.get_pool_price
BalancerMultiplexer.get_price
BalancerMultiplexer.get_version
BalancerMultiplexer.is_balancer_pool
BalancerMultiplexer.v1
BalancerMultiplexer.v2
BalancerMultiplexer.versions
- y.prices.dex.balancer.v1 module
BalancerV1
BalancerV1Pool
BalancerV1Pool._decimals
BalancerV1Pool._scale
BalancerV1Pool.__eq__()
BalancerV1Pool.__init__()
BalancerV1Pool.__str__()
BalancerV1Pool.__build_name__
BalancerV1Pool.__decimals__
BalancerV1Pool.__name__
BalancerV1Pool.__scale__
BalancerV1Pool.__symbol__
BalancerV1Pool.__tokens__
BalancerV1Pool.address
BalancerV1Pool.asynchronous
BalancerV1Pool.balance_of
BalancerV1Pool.balance_of_readable
BalancerV1Pool.build_name
BalancerV1Pool.check_liquidity
BalancerV1Pool.contract
BalancerV1Pool.decimals
BalancerV1Pool.deploy_block
BalancerV1Pool.get_balance
BalancerV1Pool.get_balances
BalancerV1Pool.get_pool_price
BalancerV1Pool.get_tvl
BalancerV1Pool.has_method
BalancerV1Pool.name
BalancerV1Pool.price
BalancerV1Pool.scale
BalancerV1Pool.symbol
BalancerV1Pool.tokens
BalancerV1Pool.total_supply
BalancerV1Pool.total_supply_readable
- y.prices.dex.balancer.v2 module
BalancerEvents
BalancerEvents.obj_type
BalancerEvents.__aiter__()
BalancerEvents.__await__()
BalancerEvents.__init__()
BalancerEvents.__iter__()
BalancerEvents._objects_thru()
BalancerEvents.events()
BalancerEvents.filter()
BalancerEvents.logs()
BalancerEvents.objects()
BalancerEvents.sort()
BalancerEvents.wrap()
BalancerEvents.__wrapped__
BalancerEvents.addresses
BalancerEvents.asynchronous
BalancerEvents.bulk_insert
BalancerEvents.cache
BalancerEvents.executor
BalancerEvents.from_block
BalancerEvents.insert_to_db
BalancerEvents.is_asleep
BalancerEvents.is_reusable
BalancerEvents.materialized
BalancerEvents.semaphore
BalancerEvents.to_block
BalancerEvents.topics
BalancerV2
BalancerV2Pool
BalancerV2Pool._decimals
BalancerV2Pool._scale
BalancerV2Pool.__eq__()
BalancerV2Pool.__init__()
BalancerV2Pool.__str__()
BalancerV2Pool.__build_name__
BalancerV2Pool.__decimals__
BalancerV2Pool.__id__
BalancerV2Pool.__name__
BalancerV2Pool.__pool_type__
BalancerV2Pool.__scale__
BalancerV2Pool.__symbol__
BalancerV2Pool.__vault__
BalancerV2Pool.address
BalancerV2Pool.asynchronous
BalancerV2Pool.balance_of
BalancerV2Pool.balance_of_readable
BalancerV2Pool.build_name
BalancerV2Pool.contract
BalancerV2Pool.decimals
BalancerV2Pool.deploy_block
BalancerV2Pool.get_balance
BalancerV2Pool.get_balances
BalancerV2Pool.get_pool_price
BalancerV2Pool.get_token_price
BalancerV2Pool.get_tvl
BalancerV2Pool.has_method
BalancerV2Pool.id
BalancerV2Pool.name
BalancerV2Pool.pool_type
BalancerV2Pool.price
BalancerV2Pool.scale
BalancerV2Pool.symbol
BalancerV2Pool.tokens
BalancerV2Pool.total_supply
BalancerV2Pool.total_supply_readable
BalancerV2Pool.vault
BalancerV2Pool.weights
BalancerV2Vault
BalancerV2Vault.__eq__()
BalancerV2Vault.__init__()
BalancerV2Vault.__str__()
BalancerV2Vault.pools()
BalancerV2Vault.pools_for_token()
BalancerV2Vault.__build_name__
BalancerV2Vault.address
BalancerV2Vault.asynchronous
BalancerV2Vault.build_name
BalancerV2Vault.contract
BalancerV2Vault.deepest_pool_for
BalancerV2Vault.deploy_block
BalancerV2Vault.get_pool_info
BalancerV2Vault.get_pool_tokens
BalancerV2Vault.has_method
PoolSpecialization
PoolSpecialization.__add__()
PoolSpecialization.__and__()
PoolSpecialization.__bool__()
PoolSpecialization.__eq__()
PoolSpecialization.__floordiv__()
PoolSpecialization.__ge__()
PoolSpecialization.__getattribute__()
PoolSpecialization.__gt__()
PoolSpecialization.__index__()
PoolSpecialization.__invert__()
PoolSpecialization.__le__()
PoolSpecialization.__lshift__()
PoolSpecialization.__lt__()
PoolSpecialization.__mul__()
PoolSpecialization.__or__()
PoolSpecialization.__pow__()
PoolSpecialization.__radd__()
PoolSpecialization.__rand__()
PoolSpecialization.__rlshift__()
PoolSpecialization.__ror__()
PoolSpecialization.__rrshift__()
PoolSpecialization.__rshift__()
PoolSpecialization.__rxor__()
PoolSpecialization.__sizeof__()
PoolSpecialization.__sub__()
PoolSpecialization.__truediv__()
PoolSpecialization.__xor__()
PoolSpecialization.from_bytes()
PoolSpecialization.to_bytes()
PoolSpecialization.with_immutable_tokens()
PoolSpecialization.ComposableStablePool
PoolSpecialization.CronV1Pool
PoolSpecialization.WeightedPool
PoolSpecialization.WeightedPool2Tokens
PoolSpecialization.denominator
PoolSpecialization.numerator
- Module contents
- y.prices.dex.uniswap package
- Submodules
- y.prices.dex.uniswap.uniswap module
- y.prices.dex.uniswap.v1 module
- y.prices.dex.uniswap.v2 module
PoolsFromEvents
PoolsFromEvents.obj_type
PoolsFromEvents.__aiter__()
PoolsFromEvents.__await__()
PoolsFromEvents.__init__()
PoolsFromEvents.__iter__()
PoolsFromEvents._objects_thru()
PoolsFromEvents.events()
PoolsFromEvents.filter()
PoolsFromEvents.logs()
PoolsFromEvents.objects()
PoolsFromEvents.pools()
PoolsFromEvents.sort()
PoolsFromEvents.wrap()
PoolsFromEvents.PairCreated
PoolsFromEvents.__wrapped__
PoolsFromEvents.addresses
PoolsFromEvents.asynchronous
PoolsFromEvents.bulk_insert
PoolsFromEvents.cache
PoolsFromEvents.executor
PoolsFromEvents.from_block
PoolsFromEvents.insert_to_db
PoolsFromEvents.is_asleep
PoolsFromEvents.is_reusable
PoolsFromEvents.label
PoolsFromEvents.materialized
PoolsFromEvents.semaphore
PoolsFromEvents.to_block
PoolsFromEvents.topics
UniswapRouterV2
UniswapRouterV2.__eq__()
UniswapRouterV2.__init__()
UniswapRouterV2.__str__()
UniswapRouterV2.pools_for_token()
UniswapRouterV2.__build_name__
UniswapRouterV2.__pools__
UniswapRouterV2.address
UniswapRouterV2.all_pools_for
UniswapRouterV2.asynchronous
UniswapRouterV2.build_name
UniswapRouterV2.check_liquidity
UniswapRouterV2.contract
UniswapRouterV2.deepest_pool
UniswapRouterV2.deepest_pool_for
UniswapRouterV2.deepest_stable_pool
UniswapRouterV2.deploy_block
UniswapRouterV2.get_path_to_stables
UniswapRouterV2.get_pools_for
UniswapRouterV2.get_price
UniswapRouterV2.get_quote
UniswapRouterV2.has_method
UniswapRouterV2.pools
UniswapV2Pool
UniswapV2Pool._decimals
UniswapV2Pool._scale
UniswapV2Pool.__eq__()
UniswapV2Pool.__init__()
UniswapV2Pool.__str__()
UniswapV2Pool.__build_name__
UniswapV2Pool.__decimals__
UniswapV2Pool.__factory__
UniswapV2Pool.__name__
UniswapV2Pool.__scale__
UniswapV2Pool.__symbol__
UniswapV2Pool.__token0__
UniswapV2Pool.__token1__
UniswapV2Pool.__tokens__
UniswapV2Pool.address
UniswapV2Pool.asynchronous
UniswapV2Pool.balance_of
UniswapV2Pool.balance_of_readable
UniswapV2Pool.build_name
UniswapV2Pool.check_liquidity
UniswapV2Pool.contract
UniswapV2Pool.decimals
UniswapV2Pool.deploy_block
UniswapV2Pool.factory
UniswapV2Pool.get_price
UniswapV2Pool.get_reserves
UniswapV2Pool.get_token_out
UniswapV2Pool.has_method
UniswapV2Pool.is_uniswap_pool
UniswapV2Pool.name
UniswapV2Pool.price
UniswapV2Pool.reserves
UniswapV2Pool.scale
UniswapV2Pool.symbol
UniswapV2Pool.token0
UniswapV2Pool.token1
UniswapV2Pool.tokens
UniswapV2Pool.total_supply
UniswapV2Pool.total_supply_readable
UniswapV2Pool.tvl
- y.prices.dex.uniswap.v2_forks module
- y.prices.dex.uniswap.v3 module
UniV3Pools
UniV3Pools.obj_type
UniV3Pools.__aiter__()
UniV3Pools.__await__()
UniV3Pools.__init__()
UniV3Pools.__iter__()
UniV3Pools._objects_thru()
UniV3Pools.events()
UniV3Pools.filter()
UniV3Pools.logs()
UniV3Pools.objects()
UniV3Pools.sort()
UniV3Pools.wrap()
UniV3Pools.__wrapped__
UniV3Pools.addresses
UniV3Pools.asynchronous
UniV3Pools.bulk_insert
UniV3Pools.cache
UniV3Pools.executor
UniV3Pools.from_block
UniV3Pools.insert_to_db
UniV3Pools.is_asleep
UniV3Pools.is_reusable
UniV3Pools.materialized
UniV3Pools.semaphore
UniV3Pools.to_block
UniV3Pools.topics
UniswapV3
UniswapV3Pool
UniswapV3Pool._check_liquidity_token_out
UniswapV3Pool.__contains__()
UniswapV3Pool.__eq__()
UniswapV3Pool.__getitem__()
UniswapV3Pool.__init__()
UniswapV3Pool.__str__()
UniswapV3Pool.__build_name__
UniswapV3Pool.__contains_cache__
UniswapV3Pool.address
UniswapV3Pool.asynchronous
UniswapV3Pool.build_name
UniswapV3Pool.check_liquidity
UniswapV3Pool.contract
UniswapV3Pool.deploy_block
UniswapV3Pool.fee
UniswapV3Pool.has_method
UniswapV3Pool.tick_spacing
UniswapV3Pool.token0
UniswapV3Pool.token1
- Module contents
Submodules
y.prices.dex.genericamm module
- class y.prices.dex.genericamm.GenericAmm[source]
Bases:
ASyncGenericBase
A class for handling generic Automated Market Maker (AMM) Liquidity Pool (LP) tokens.
This class provides methods to interact with and price generic AMM LP token contracts.
- __init__(*, asynchronous=False)[source]
Initialize the GenericAmm instance.
- Parameters:
asynchronous (optional) – Whether methods will return coroutines by default. Defaults to False.
- Return type:
None
- get_price[source]
Get the price of the LP token in USD.
- Parameters:
lp_token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the LP token.
block (optional) – The block number to query. Defaults to None (latest).
skip_cache (optional) – Whether to skip cache. Defaults to
ENVS.SKIP_CACHE
.
- Returns:
The price of the LP token in USD.
- Return type:
Example
>>> amm = GenericAmm(asynchronous=True) >>> address = "0x6B175474E89094C44Da98b954EedeAC495271d0F" >>> price = await amm.get_price(address) >>> print(price) 0.5
See also
ERC20.total_supply_readable()
- get_tokens[source]
Get the tokens in the AMM pool.
- Args:
lp_token_address: The address of the LP token.
- Returns:
A tuple containing the two ERC20 tokens in the pool.
- Example:
>>> amm = GenericAmm(asynchronous=True) >>> address = "0x6B175474E89094C44Da98b954EedeAC495271d0F" >>> tokens = await amm.get_tokens(address) >>> print(tokens) (ERC20(0x123...), ERC20(0x456...))
- See Also:
ERC20
Since get_tokens is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
lp_token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
- get_tvl[source]
Get the Total Value Locked (TVL) in the AMM pool.
- Parameters:
lp_token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the LP token.
block (optional) – The block number to query. Defaults to None (latest).
skip_cache (optional) – Whether to skip cache. Defaults to
ENVS.SKIP_CACHE
.
- Returns:
The Total Value Locked in USD.
- Return type:
Example
>>> amm = GenericAmm(asynchronous=True) >>> address = "0x6B175474E89094C44Da98b954EedeAC495271d0F" >>> tvl = await amm.get_tvl(address) >>> print(tvl) 1000000.0
See also
- async y.prices.dex.genericamm.is_generic_amm(lp_token_address)[source]
Check if the given address is a generic AMM LP token.
- Parameters:
lp_token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address to check.
- Returns:
True if the address is a generic AMM LP token, False otherwise.
- Return type:
Example
>>> address = "0x6B175474E89094C44Da98b954EedeAC495271d0F" >>> is_amm = await is_generic_amm(address) >>> print(is_amm) False
- y.prices.dex.genericamm.generic_amm = <y.prices.dex.genericamm.GenericAmm object>
A global instance of
GenericAmm
with asynchronous mode enabled.
y.prices.dex.mooniswap module
- ASyncFunctiony.prices.dex.mooniswap.get_pool_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) y.datatypes.UsdPrice [source]
Get the price of the given Mooniswap pool token.
- Args:
token: The address of the pool token. block (optional): The block number to get the price at. Defaults to latest block. skip_cache (optional): Whether to skip the cache. Defaults to
ENVS.SKIP_CACHE
.- Returns:
The price of the pool token in USD as a
UsdPrice
.- Examples:
>>> get_pool_price("0x1234567890abcdef1234567890abcdef12345678") UsdPrice('1.2345')
>>> get_pool_price("0xabcdefabcdefabcdefabcdefabcdefabcdef", block=12345678) UsdPrice('0.9876')
- See Also:
Since get_pool_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
- ASyncFunctiony.prices.dex.mooniswap.is_mooniswap_pool(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool [source]
Check if the given token address is a Mooniswap pool.
- Args:
token: The address of the token to check.
- Returns:
True if the token is a Mooniswap pool, False otherwise.
- Examples:
>>> is_mooniswap_pool("0x1234567890abcdef1234567890abcdef12345678") True
>>> is_mooniswap_pool("0xabcdefabcdefabcdefabcdefabcdefabcdef") False
Since is_mooniswap_pool is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
y.prices.dex.solidly module
- class y.prices.dex.solidly.SolidlyPool[source]
Bases:
UniswapV2Pool
Represents a liquidity pool in the Solidly protocol.
This class inherits from
UniswapV2Pool
and provides the same interface for interacting with liquidity pools.See also
- ASyncFunction_decimals(block: int | eth_typing.evm.BlockNumber | NoneType = None) int
used to fetch decimals at specific block
Since _decimals is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
- Return type:
- ASyncFunction_scale(block: int | eth_typing.evm.BlockNumber | NoneType = None) int
Since _scale is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
- Return type:
- __eq__(_ContractBase__o)
Return self==value.
- __init__(self)
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
token0 (str | HexBytes | AnyAddress | EthAddress | None)
token1 (str | HexBytes | AnyAddress | EthAddress | None)
deploy_block (int | None)
asynchronous (bool)
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- __build_name__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __decimals__: HiddenMethodDescriptor[Self, int]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __factory__: HiddenMethodDescriptor[Self, str | HexBytes | AnyAddress | EthAddress]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __scale__: HiddenMethodDescriptor[Self, int]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __symbol__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __token0__: HiddenMethodDescriptor[Self, ERC20]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __token1__: HiddenMethodDescriptor[Self, ERC20]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __tokens__: HiddenMethodDescriptor[Self, Tuple[ERC20, ERC20]]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address: Address
The contract address of the token.
- balance_of
Query the balance of the token for a given address at a specific block.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address to query.
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The balance of the token held by address at block block.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.balance_of("0xabcdefabcdefabcdefabcdefabcdefabcdef") 500000000000000000000
- balance_of_readable
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
- Return type:
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- check_liquidity
Check the liquidity of a specific token in the pool at a given block.
- Args:
token: The address of the token to check. block: The block number to query.
- Returns:
The liquidity of the token in the pool.
- Raises:
TokenNotFound: If the token is not one of the two tokens in the liquidity pool.
- Examples:
>>> pool = UniswapV2Pool("0xAddress") >>> liquidity = await pool.check_liquidity("0xTokenAddress", 12345678) >>> print(liquidity)
Since check_liquidity is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- decimals
The number of decimal places for the token.
- Returns:
The number of decimal places for the token.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.decimals 18
- deploy_block: ASyncBoundMethod[Self, Any, int]
Get the block number when the contract was deployed.
- Parameters:
when_no_history_return_0 (bool) – If True, return 0 when no history is found instead of raising an exception.
- Returns:
The block number when the contract was deployed, or 0 if when_no_history_return_0 is True and the deploy block cannot be determined.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- factory
- get_price
Calculate the price of the pool’s liquidity token in USD.
This method calculates the price of the pool’s liquidity token by dividing the total value locked (TVL) by the total supply of the liquidity token.
- Args:
block: The block number to query. Defaults to the latest block. skip_cache: If True, skip using the cache while fetching price data.
- Examples:
>>> pool = UniswapV2Pool("0xAddress") >>> price = await pool.get_price() >>> print(price)
- See Also:
Since get_price is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
UsdPrice | None
- get_reserves
- get_token_out
Since get_token_out is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
- Return type:
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- is_uniswap_pool
Check if this contract is a valid liquidity pool for Uniswap V2 or one of its forks.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
- Returns:
True if the contract is a valid Uniswap V2 pool, False otherwise.
- Return type:
Examples
>>> pool = UniswapV2Pool("0xAddress") >>> is_valid = await pool.is_uniswap_pool() >>> print(is_valid)
- name
The token’s name.
- Returns:
The token’s name.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.name 'TokenName'
- price
Get the price of the token in USD.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
return_None_on_failure (bool) – If True, return None instead of raising a
yPriceMagicError
on failure.skip_cache (bool) – If True, skip using the cache while fetching price data.
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...]) – An optional tuple of pools to ignore when calculating the price.
- Returns:
The price of the token in USD, or None if return_None_on_failure is True and the price cannot be retrieved.
- Raises:
yPriceMagicError – If return_None_on_failure is False and the price cannot be retrieved.
- Return type:
UsdPrice | None
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.price() 1.23
See also
- reserves
- Parameters:
block (int | BlockNumber | None)
- Return type:
Tuple[WeiBalance, WeiBalance] | None
- scale
Get the scaling factor for the token.
- Returns:
The scaling factor for the token.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.scale 1000000000000000000
- symbol
The token’s symbol.
- Returns:
The token’s symbol.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.symbol 'TKN'
- token0
- token1
- tokens
- total_supply
Get the total supply of the token.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The total supply of the token.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.total_supply() 1000000000000000000000
- total_supply_readable
Get the total supply of the token scaled to a human-readable decimal.
- Parameters:
block (optional) – The block number to query.
- Returns:
The total supply of the token scaled to a decimal.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.total_supply_readable() 1000.0
- tvl
Calculate the total value locked (TVL) in the pool in USD.
This method calculates the TVL by summing the USD value of the reserves of the two tokens in the pool.
- Parameters:
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
skip_cache (bool) – If True, skip using the cache while fetching price data.
- Return type:
Decimal | None
Examples
>>> pool = UniswapV2Pool("0xAddress") >>> tvl = await pool.tvl() >>> print(tvl)
See also
- class y.prices.dex.solidly.SolidlyRouter[source]
Bases:
SolidlyRouterBase
A router for interacting with the Solidly protocol.
This class extends
SolidlyRouterBase
to provide additional functionality specific to the Solidly protocol, such as determining the appropriate pool for a token pair and calculating swap routes.See also
- __eq__(_ContractBase__o)
Return self==value.
- __init__(self)
- Parameters:
router_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
asynchronous (bool)
- Return type:
None
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- pools_for_token(token_address, block=None, _ignore_pools=())
- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
- __build_name__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __pools__: HiddenMethodDescriptor[Self, List[UniswapV2Pool]]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address
- all_pools_for
Since all_pools_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- check_liquidity
Since check_liquidity is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- deepest_pool
returns the deepest pool for token_address at block, excluding pools in _ignore_pools
Since deepest_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- deepest_pool_for
Since deepest_pool_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
Tuple[str | HexBytes | AnyAddress | EthAddress, int]
- deepest_stable_pool
returns the deepest pool for token_address at block which has token_address paired with a stablecoin, excluding pools in _ignore_pools
Since deepest_stable_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- deploy_block: ASyncBoundMethod[Self, Any, int]
Get the block number when the contract was deployed.
- Parameters:
when_no_history_return_0 (bool) – If True, return 0 when no history is found instead of raising an exception.
- Returns:
The block number when the contract was deployed, or 0 if when_no_history_return_0 is True and the deploy block cannot be determined.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- get_path_to_stables
Since get_path_to_stables is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_loop_count (int)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
List[str | HexBytes | AnyAddress | EthAddress | Contract]
- get_pool[source]
Get the pool object for a given token pair.
This method returns a
SolidlyPool
object representing the pool that contains the specified input and output tokens, and indicates whether the pool is stable.- Args:
input_token: The address of the input token. output_token: The address of the output token. stable: A boolean indicating whether to look for a stable pool. block: The block number to query.
- Returns:
A
SolidlyPool
object if the pool exists, otherwise None.- Examples:
>>> router = SolidlyRouter("0xRouterAddress") >>> pool = await router.get_pool("0xTokenA", "0xTokenB", True, 12345678) >>> print(pool)
Since get_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
input_token (str | HexBytes | AnyAddress | EthAddress)
output_token (str | HexBytes | AnyAddress | EthAddress)
stable (bool)
block (int | BlockNumber)
- Return type:
SolidlyPool | None
- get_pools_for
- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- get_price
- Calculate a price based on Uniswap Router quote for selling one token_in.
Always uses intermediate WETH pair if [token_in,weth,token_out] swap path available.
Since get_price is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
token_out (str | HexBytes | AnyAddress | EthAddress)
paired_against (str | HexBytes | AnyAddress | EthAddress)
skip_cache (bool)
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...])
- Return type:
UsdPrice | None
- get_quote
Get a price quote for a given input amount and swap path.
This method calculates the output amount for a given input amount and swap path by interacting with the Solidly contract.
- Parameters:
amount_in (int) – The amount of input tokens.
path (List[str | HexBytes | AnyAddress | EthAddress | Contract]) – The swap path as a list of token addresses.
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
- Returns:
A tuple containing the output amount and the path used.
- Raises:
Exception – If the call reverts for reasons other than insufficient
input amount or liquidity. –
- Return type:
Examples
>>> router = SolidlyRouterBase("0xRouterAddress") >>> quote = await router.get_quote(1000, ["0xTokenA", "0xTokenB"]) >>> print(quote)
- get_routes_from_path[source]
Determine the swap routes from a given path.
This method calculates the swap routes for a given path by checking for available stable and unstable pools and selecting the deepest pool.
- Parameters:
path (List[str | HexBytes | AnyAddress | EthAddress | Contract]) – The swap path as a list of token addresses.
block (int | BlockNumber) – The block number to query.
- Returns:
A list of tuples, each containing the input token, output token, and a boolean indicating whether the pool is stable.
- Raises:
ValueError – If no pool is found for a token pair.
- Return type:
List[Tuple[str | HexBytes | AnyAddress | EthAddress, str | HexBytes | AnyAddress | EthAddress, bool]]
Examples
>>> router = SolidlyRouter("0xRouterAddress") >>> routes = await router.get_routes_from_path(["0xTokenA", "0xTokenB"], 12345678) >>> print(routes)
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- pair_for[source]
Get the address of the pool for a given token pair.
This method returns the address of the pool that contains the specified input and output tokens, and indicates whether the pool is stable.
- Args:
input_token: The address of the input token. output_token: The address of the output token. stable: A boolean indicating whether to look for a stable pool.
- Returns:
The address of the pool.
- Examples:
>>> router = SolidlyRouter("0xRouterAddress") >>> pool_address = await router.pair_for("0xTokenA", "0xTokenB", True) >>> print(pool_address)
Since pair_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
input_token (str | HexBytes | AnyAddress | EthAddress)
output_token (str | HexBytes | AnyAddress | EthAddress)
stable (bool)
- Return type:
str | HexBytes | AnyAddress | EthAddress
- pools
- class y.prices.dex.solidly.SolidlyRouterBase[source]
Bases:
UniswapRouterV2
Solidly is a modified fork of Uni V2. The uniswap_multiplexer is the entrypoint for pricing using this object.
This class provides methods to interact with the Solidly protocol, which is based on the Uniswap V2 model. It includes functionality to get price quotes and determine routes for token swaps.
See also
- __eq__(_ContractBase__o)
Return self==value.
- __init__(self)
- Parameters:
router_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
asynchronous (bool)
- Return type:
None
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- pools_for_token(token_address, block=None, _ignore_pools=())
- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
- __build_name__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __pools__: HiddenMethodDescriptor[Self, List[UniswapV2Pool]]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address
- all_pools_for
Since all_pools_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- check_liquidity
Since check_liquidity is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- deepest_pool
returns the deepest pool for token_address at block, excluding pools in _ignore_pools
Since deepest_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- deepest_pool_for
Since deepest_pool_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
Tuple[str | HexBytes | AnyAddress | EthAddress, int]
- deepest_stable_pool
returns the deepest pool for token_address at block which has token_address paired with a stablecoin, excluding pools in _ignore_pools
Since deepest_stable_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- deploy_block: ASyncBoundMethod[Self, Any, int]
Get the block number when the contract was deployed.
- Parameters:
when_no_history_return_0 (bool) – If True, return 0 when no history is found instead of raising an exception.
- Returns:
The block number when the contract was deployed, or 0 if when_no_history_return_0 is True and the deploy block cannot be determined.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- get_path_to_stables
Since get_path_to_stables is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_loop_count (int)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
List[str | HexBytes | AnyAddress | EthAddress | Contract]
- get_pools_for
- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- get_price
- Calculate a price based on Uniswap Router quote for selling one token_in.
Always uses intermediate WETH pair if [token_in,weth,token_out] swap path available.
Since get_price is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
token_out (str | HexBytes | AnyAddress | EthAddress)
paired_against (str | HexBytes | AnyAddress | EthAddress)
skip_cache (bool)
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...])
- Return type:
UsdPrice | None
- get_quote[source]
Get a price quote for a given input amount and swap path.
This method calculates the output amount for a given input amount and swap path by interacting with the Solidly contract.
- Parameters:
amount_in (int) – The amount of input tokens.
path (List[str | HexBytes | AnyAddress | EthAddress | Contract]) – The swap path as a list of token addresses.
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
- Returns:
A tuple containing the output amount and the path used.
- Raises:
Exception – If the call reverts for reasons other than insufficient
input amount or liquidity. –
- Return type:
Examples
>>> router = SolidlyRouterBase("0xRouterAddress") >>> quote = await router.get_quote(1000, ["0xTokenA", "0xTokenB"]) >>> print(quote)
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- pools
y.prices.dex.velodrome module
- class y.prices.dex.velodrome.VelodromePool[source]
Bases:
UniswapV2Pool
- ASyncFunction_decimals(block: int | eth_typing.evm.BlockNumber | NoneType = None) int
used to fetch decimals at specific block
Since _decimals is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
- Return type:
- ASyncFunction_scale(block: int | eth_typing.evm.BlockNumber | NoneType = None) int
Since _scale is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
- Return type:
- __eq__(_ContractBase__o)
Return self==value.
- __init__(address, token0=None, token1=None, stable=None, deploy_block=None, *, asynchronous=False)[source]
Initialize a
VelodromePool
instance.- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the pool.
token0 (str | HexBytes | AnyAddress | EthAddress | Contract | int | None) – The address of the first token in the pool.
token1 (str | HexBytes | AnyAddress | EthAddress | Contract | int | None) – The address of the second token in the pool.
stable (bool | None) – Indicates if the pool is stable.
deploy_block (int | None) – The block number at which the pool was deployed.
asynchronous (bool) – Whether to use asynchronous operations.
Examples
>>> pool = VelodromePool("0xPoolAddress", "0xToken0", "0xToken1", True, 12345678) >>> print(pool.is_stable) True
See also
UniswapV2Pool
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- __build_name__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __decimals__: HiddenMethodDescriptor[Self, int]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __factory__: HiddenMethodDescriptor[Self, str | HexBytes | AnyAddress | EthAddress]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __scale__: HiddenMethodDescriptor[Self, int]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __symbol__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __token0__: HiddenMethodDescriptor[Self, ERC20]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __token1__: HiddenMethodDescriptor[Self, ERC20]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __tokens__: HiddenMethodDescriptor[Self, Tuple[ERC20, ERC20]]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address: Address
The contract address of the token.
- balance_of
Query the balance of the token for a given address at a specific block.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address to query.
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The balance of the token held by address at block block.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.balance_of("0xabcdefabcdefabcdefabcdefabcdefabcdef") 500000000000000000000
- balance_of_readable
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
- Return type:
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- check_liquidity
Check the liquidity of a specific token in the pool at a given block.
- Args:
token: The address of the token to check. block: The block number to query.
- Returns:
The liquidity of the token in the pool.
- Raises:
TokenNotFound: If the token is not one of the two tokens in the liquidity pool.
- Examples:
>>> pool = UniswapV2Pool("0xAddress") >>> liquidity = await pool.check_liquidity("0xTokenAddress", 12345678) >>> print(liquidity)
Since check_liquidity is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- decimals
The number of decimal places for the token.
- Returns:
The number of decimal places for the token.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.decimals 18
- deploy_block: ASyncBoundMethod[Self, Any, int]
Get the block number when the contract was deployed.
- Parameters:
when_no_history_return_0 (bool) – If True, return 0 when no history is found instead of raising an exception.
- Returns:
The block number when the contract was deployed, or 0 if when_no_history_return_0 is True and the deploy block cannot be determined.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- factory
- get_price
Calculate the price of the pool’s liquidity token in USD.
This method calculates the price of the pool’s liquidity token by dividing the total value locked (TVL) by the total supply of the liquidity token.
- Args:
block: The block number to query. Defaults to the latest block. skip_cache: If True, skip using the cache while fetching price data.
- Examples:
>>> pool = UniswapV2Pool("0xAddress") >>> price = await pool.get_price() >>> print(price)
- See Also:
Since get_price is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
UsdPrice | None
- get_reserves
- get_token_out
Since get_token_out is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
- Return type:
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- is_stable
Indicates if the pool is stable, as opposed to volatile.
- is_uniswap_pool
Check if this contract is a valid liquidity pool for Uniswap V2 or one of its forks.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
- Returns:
True if the contract is a valid Uniswap V2 pool, False otherwise.
- Return type:
Examples
>>> pool = UniswapV2Pool("0xAddress") >>> is_valid = await pool.is_uniswap_pool() >>> print(is_valid)
- name
The token’s name.
- Returns:
The token’s name.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.name 'TokenName'
- price
Get the price of the token in USD.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
return_None_on_failure (bool) – If True, return None instead of raising a
yPriceMagicError
on failure.skip_cache (bool) – If True, skip using the cache while fetching price data.
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...]) – An optional tuple of pools to ignore when calculating the price.
- Returns:
The price of the token in USD, or None if return_None_on_failure is True and the price cannot be retrieved.
- Raises:
yPriceMagicError – If return_None_on_failure is False and the price cannot be retrieved.
- Return type:
UsdPrice | None
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.price() 1.23
See also
- reserves
- Parameters:
block (int | BlockNumber | None)
- Return type:
Tuple[WeiBalance, WeiBalance] | None
- scale
Get the scaling factor for the token.
- Returns:
The scaling factor for the token.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.scale 1000000000000000000
- symbol
The token’s symbol.
- Returns:
The token’s symbol.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.symbol 'TKN'
- token0
- token1
- tokens
- total_supply
Get the total supply of the token.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The total supply of the token.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.total_supply() 1000000000000000000000
- total_supply_readable
Get the total supply of the token scaled to a human-readable decimal.
- Parameters:
block (optional) – The block number to query.
- Returns:
The total supply of the token scaled to a decimal.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.total_supply_readable() 1000.0
- tvl
Calculate the total value locked (TVL) in the pool in USD.
This method calculates the TVL by summing the USD value of the reserves of the two tokens in the pool.
- Parameters:
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
skip_cache (bool) – If True, skip using the cache while fetching price data.
- Return type:
Decimal | None
Examples
>>> pool = UniswapV2Pool("0xAddress") >>> tvl = await pool.tvl() >>> print(tvl)
See also
- class y.prices.dex.velodrome.VelodromeRouterV2[source]
Bases:
SolidlyRouterBase
- __eq__(_ContractBase__o)
Return self==value.
- __init__(*args, **kwargs)[source]
Initialize a
VelodromeRouterV2
instance.This class is a specialized router for Velodrome V2, inheriting from
SolidlyRouterBase
.- Parameters:
*args – Variable length argument list.
**kwargs – Arbitrary keyword arguments.
- Return type:
None
Examples
>>> router = VelodromeRouterV2() >>> print(router.default_factory) 0xF1046053aa5682b4F9a81b5481394DA16BE5FF5a
See also
SolidlyRouterBase
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- pools_for_token(token_address, block=None, _ignore_pools=())
- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
- __build_name__: HiddenMethodDescriptor[Self, str]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __pools__: HiddenMethodDescriptor[Self, Set[VelodromePool]]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address
- all_pools_for
Since all_pools_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- check_liquidity
Since check_liquidity is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
- deepest_pool
returns the deepest pool for token_address at block, excluding pools in _ignore_pools
Since deepest_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- deepest_pool_for
Since deepest_pool_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
- Return type:
Tuple[str | HexBytes | AnyAddress | EthAddress, int]
- deepest_stable_pool
returns the deepest pool for token_address at block which has token_address paired with a stablecoin, excluding pools in _ignore_pools
Since deepest_stable_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
UniswapV2Pool | None
- default_factory
The default factory address for the current network.
- deploy_block: ASyncBoundMethod[Self, Any, int]
Get the block number when the contract was deployed.
- Parameters:
when_no_history_return_0 (bool) – If True, return 0 when no history is found instead of raising an exception.
- Returns:
The block number when the contract was deployed, or 0 if when_no_history_return_0 is True and the deploy block cannot be determined.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- get_path_to_stables
Since get_path_to_stables is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
_loop_count (int)
_ignore_pools (Tuple[UniswapV2Pool, ...])
- Return type:
List[str | HexBytes | AnyAddress | EthAddress | Contract]
- get_pool[source]
Get the
VelodromePool
instance for a given pair of tokens and stability preference.- Args:
input_token: The address of the input token. output_token: The address of the output token. stable: Indicates if a stable pool is preferred. block: The block number to consider.
- Returns:
A
VelodromePool
instance if the pool exists and the address is a contract, otherwise None.- Examples:
>>> router = VelodromeRouterV2() >>> pool = await router.get_pool("0xTokenA", "0xTokenB", True, 12345678) >>> print(pool) <VelodromePool instance>
- See Also:
Since get_pool is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
input_token (str | HexBytes | AnyAddress | EthAddress)
output_token (str | HexBytes | AnyAddress | EthAddress)
stable (bool)
block (int | BlockNumber)
- Return type:
VelodromePool | None
- get_pools_for
- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
- Return type:
Dict[UniswapV2Pool, str | HexBytes | AnyAddress | EthAddress]
- get_price
- Calculate a price based on Uniswap Router quote for selling one token_in.
Always uses intermediate WETH pair if [token_in,weth,token_out] swap path available.
Since get_price is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token_in (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
token_out (str | HexBytes | AnyAddress | EthAddress)
paired_against (str | HexBytes | AnyAddress | EthAddress)
skip_cache (bool)
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...])
- Return type:
UsdPrice | None
- get_quote
Get a price quote for a given input amount and swap path.
This method calculates the output amount for a given input amount and swap path by interacting with the Solidly contract.
- Parameters:
amount_in (int) – The amount of input tokens.
path (List[str | HexBytes | AnyAddress | EthAddress | Contract]) – The swap path as a list of token addresses.
block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.
- Returns:
A tuple containing the output amount and the path used.
- Raises:
Exception – If the call reverts for reasons other than insufficient
input amount or liquidity. –
- Return type:
Examples
>>> router = SolidlyRouterBase("0xRouterAddress") >>> quote = await router.get_quote(1000, ["0xTokenA", "0xTokenB"]) >>> print(quote)
- get_routes_from_path[source]
Get the routes for a given path of tokens.
- Parameters:
path (List[str | HexBytes | AnyAddress | EthAddress | Contract]) – A list of token addresses representing the path.
block (int | BlockNumber) – The block number to consider.
- Returns:
A list of tuples, each containing the input token, output token, and stability preference.
- Raises:
NoReservesError – If no route is available for the given path.
- Return type:
List[Tuple[str | HexBytes | AnyAddress | EthAddress, str | HexBytes | AnyAddress | EthAddress, bool]]
Examples
>>> router = VelodromeRouterV2() >>> routes = await router.get_routes_from_path(["0xTokenA", "0xTokenB"], 12345678) >>> print(routes) [("0xTokenA", "0xTokenB", True)]
See also
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- pool_for[source]
Get the pool address for a given pair of tokens and stability preference.
- Args:
input_token: The address of the input token. output_token: The address of the output token. stable: Indicates if a stable pool is preferred.
- Returns:
The address of the pool if it exists, otherwise None.
- Examples:
>>> router = VelodromeRouterV2() >>> pool_address = await router.pool_for("0xTokenA", "0xTokenB", True) >>> print(pool_address) 0xPoolAddress
- See Also:
Since pool_for is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
input_token (str | HexBytes | AnyAddress | EthAddress)
output_token (str | HexBytes | AnyAddress | EthAddress)
stable (bool)
- Return type:
str | HexBytes | AnyAddress | EthAddress | None
- pools[source]
Fetch all Velodrome pools.
This method retrieves all pools for the Velodrome protocol on the current network.
- Returns:
A set of
VelodromePool
instances.
Examples
>>> router = VelodromeRouterV2() >>> pools = await router.pools >>> print(len(pools)) 42
See also
- async y.prices.dex.velodrome.is_contract(pool_address)[source]
Check if a given address is a contract.
- Parameters:
pool_address (str | HexBytes | AnyAddress | EthAddress) – The address to check.
- Returns:
True if the address is a contract, otherwise False.
- Return type:
Examples
>>> result = await is_contract("0xPoolAddress") >>> print(result) True