y.prices.dex package

Subpackages

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:

UsdPrice

Example

>>> amm = GenericAmm(asynchronous=True)
>>> address = "0x6B175474E89094C44Da98b954EedeAC495271d0F"
>>> price = await amm.get_price(address)
>>> print(price)
0.5

See also

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:

Tuple[ERC20, ERC20]

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:

UsdValue

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:

bool

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:
Return type:

UsdPrice

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:

bool

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:

int

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:

int

__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(self)
Parameters:
__str__()

Return the contract address as a string.

Returns:

The contract address as a string.

Return type:

str

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__name__: HiddenMethodDescriptor[Self, str] = 'SolidlyPool'
__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

address: Address

The contract address of the token.

asynchronous: bool = False
balance_of

Query the balance of the token for a given address at a specific block.

Parameters:
Returns:

The balance of the token held by address at block block.

Return type:

int

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.balance_of("0xabcdefabcdefabcdefabcdefabcdefabcdef")
500000000000000000000
balance_of_readable
Parameters:
Return type:

float

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:
Return type:

int

property contract: Contract
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:

int

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:
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:

ERC20

has_method

Check if the contract has a specific method.

Parameters:
  • method (str) – The name of the method to check for.

  • return_response (bool) – If True, return the response of the method call instead of a boolean.

Returns:

A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.

Return type:

bool | Any

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:

bool

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
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:

int

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:

float

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)
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.

__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(self)
Parameters:
Return type:

None

__str__()

Return the contract address as a string.

Returns:

The contract address as a string.

Return type:

str

pools_for_token(token_address, block=None, _ignore_pools=())
Parameters:
Return type:

AsyncIterator[UniswapV2Pool]

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

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]

asynchronous: bool = False
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:
Return type:

int

property contract: Contract
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:
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:
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:
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:

int

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:
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:
Return type:

SolidlyPool | None

get_pools_for
Parameters:
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:
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:
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:

Tuple[int, int]

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:
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:
  • method (str) – The name of the method to check for.

  • return_response (bool) – If True, return the response of the method call instead of a boolean.

Returns:

A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.

Return type:

bool | Any

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:
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.

__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(self)
Parameters:
Return type:

None

__str__()

Return the contract address as a string.

Returns:

The contract address as a string.

Return type:

str

pools_for_token(token_address, block=None, _ignore_pools=())
Parameters:
Return type:

AsyncIterator[UniswapV2Pool]

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

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]

asynchronous: bool = False
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:
Return type:

int

property contract: Contract
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:
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:
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:
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:

int

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:
Return type:

List[str | HexBytes | AnyAddress | EthAddress | Contract]

get_pools_for
Parameters:
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:
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:
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:

Tuple[int, int]

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:
  • method (str) – The name of the method to check for.

  • return_response (bool) – If True, return the response of the method call instead of a boolean.

Returns:

A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.

Return type:

bool | Any

Examples

>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678")
>>> await contract.has_method("name()")
True

See also

pools

y.prices.dex.velodrome module

exception y.prices.dex.velodrome.NoReservesError[source]

Bases: Exception

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:

int

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:

int

__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(address, token0=None, token1=None, stable=None, deploy_block=None, *, asynchronous=False)[source]

Initialize a VelodromePool instance.

Parameters:

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:

str

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__name__: HiddenMethodDescriptor[Self, str] = 'VelodromePool'
__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

address: Address

The contract address of the token.

asynchronous: bool = False
balance_of

Query the balance of the token for a given address at a specific block.

Parameters:
Returns:

The balance of the token held by address at block block.

Return type:

int

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.balance_of("0xabcdefabcdefabcdefabcdefabcdefabcdef")
500000000000000000000
balance_of_readable
Parameters:
Return type:

float

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:
Return type:

int

property contract: Contract
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:

int

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:
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:

ERC20

has_method

Check if the contract has a specific method.

Parameters:
  • method (str) – The name of the method to check for.

  • return_response (bool) – If True, return the response of the method call instead of a boolean.

Returns:

A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.

Return type:

bool | Any

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:

bool

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
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:

int

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:

float

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)
class y.prices.dex.velodrome.VelodromeRouterV2[source]

Bases: SolidlyRouterBase

__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__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:

str

pools_for_token(token_address, block=None, _ignore_pools=())
Parameters:
Return type:

AsyncIterator[UniswapV2Pool]

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

__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.

Type:

_ASyncPropertyDescriptorBase.get(self, instance

Type:

I, owner

Parameters:
  • instance (I)

  • owner (Type[I] | None)

Return type:

T

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]

asynchronous: bool = False
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:
Return type:

int

property contract: Contract
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:
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:
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:
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:

int

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:
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:
Return type:

VelodromePool | None

get_pools_for
Parameters:
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:
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:
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:

Tuple[int, int]

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:
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:
  • method (str) – The name of the method to check for.

  • return_response (bool) – If True, return the response of the method call instead of a boolean.

Returns:

A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.

Return type:

bool | Any

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:
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:

bool

Examples

>>> result = await is_contract("0xPoolAddress")
>>> print(result)
True

Module contents