y.prices package

Subpackages

Submodules

y.prices.band module

class y.prices.band.Band[source]

Bases: ASyncGenericSingleton

A class to interact with the Band Protocol oracle on supported networks.

This class provides methods to check asset support and fetch prices using the Band Protocol oracle.

Raises:

UnsupportedNetwork – If the Band Protocol is not supported on the current network.

Examples

>>> band = Band(asynchronous=True)
>>> "0xaf319E5789945197e365E7f7fbFc56B130523B33" in band
True
__contains__(asset)[source]

Check if an asset is supported by the Band Protocol on the current network.

Parameters:

asset (str | HexBytes | AnyAddress | EthAddress | Contract) – The asset address or contract to check.

Return type:

bool

Examples

>>> band = Band(asynchronous=True)
>>> "0xaf319E5789945197e365E7f7fbFc56B130523B33" in band
True
__init__(*, asynchronous=False)[source]

Initialize the Band class.

Parameters:

asynchronous (bool) – Whether to use asynchronous operations.

Raises:

UnsupportedNetwork – If the Band Protocol is not supported on the current network.

Return type:

None

Examples

>>> band = Band(asynchronous=True)
__oracle__: HiddenMethodDescriptor[Self, Contract]

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

get_price[source]

Get the price of an asset in terms of USDC using the Band Protocol oracle.

Parameters:
Returns:

The price of the asset in terms of USDC, or None if the price cannot be fetched.

Return type:

float | None

Examples

>>> band = Band(asynchronous=True)
>>> price = await band.get_price("0xaf319E5789945197e365E7f7fbFc56B130523B33")
>>> print(price)
1.0
oracle[source]

Get the Band Protocol oracle contract for the current network.

Examples

>>> band = Band(asynchronous=True)
>>> oracle = await band.oracle

y.prices.convex module

ASyncFunctiony.prices.convex.get_price(token_address: eth_typing.evm.ChecksumAddress, 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 a Convex LP token in USD.

This function retrieves the price of the underlying token mapped to the given Convex LP token address.

Args:

token_address: The address of the Convex LP token. block: The block number at which to fetch the price. Defaults to the latest block. skip_cache: Whether to skip the cache when fetching the price. Defaults to the value of ENVS.SKIP_CACHE.

Returns:

The price of the token in USD.

Examples:
>>> await get_price("0x30D9410ED1D5DA1F6C8391af5338C93ab8d4035C")
1.23456789
See Also:

Since get_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

y.prices.convex.is_convex_lp(token_address)[source]

Check if a given token address is a Convex LP token.

Parameters:

token_address (ChecksumAddress) – The address of the token to check.

Returns:

True if the token is a Convex LP token, False otherwise.

Return type:

bool

Examples

>>> is_convex_lp("0x30D9410ED1D5DA1F6C8391af5338C93ab8d4035C")
True
>>> is_convex_lp("0x0000000000000000000000000000000000000000")
False

y.prices.gearbox module

class y.prices.gearbox.DieselPool[source]

Bases: ContractBase

__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

__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

__contract__: HiddenMethodDescriptor[Self, Contract]

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

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

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

address
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'
contract[source]
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()

diesel_token[source]
exchange_rate[source]
Parameters:

block (int | BlockNumber)

Return type:

Decimal

get_price[source]
Parameters:
Return type:

Decimal

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

underlying[source]
class y.prices.gearbox.Gearbox[source]

Bases: ASyncGenericBase

__init__(*, asynchronous=False)[source]

Initialize a Gearbox instance.

Raises:

UnsupportedNetwork – If the current network is not Ethereum Mainnet.

Parameters:

asynchronous (bool) – Whether to use asynchronous operations. Defaults to False.

Example

>>> from y.prices.gearbox import Gearbox
>>> gearbox = Gearbox(asynchronous=True)
>>> # This will raise an UnsupportedNetwork exception if not on Mainnet
__registry__

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

diesel_tokens[source]
Return type:

Dict[ERC20, DieselPool]

get_price[source]
Parameters:
Return type:

Decimal

is_diesel_token[source]
Parameters:

token (str | HexBytes | AnyAddress | EthAddress)

Return type:

bool

pools[source]

Since pools 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.

Return type:

List[DieselPool]

registry[source]

y.prices.magic module

ASyncFunctiony.prices.magic.get_price(token_address: AnyAddressType, block: Block | None = None, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, ignore_pools: Tuple[Pool, ...] = (), silent: bool = False) UsdPrice | None[source]
ASyncFunctiony.prices.magic.get_price(token_address: AnyAddressType, block: Block | None = None, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, ignore_pools: Tuple[Pool, ...] = (), silent: bool = False) UsdPrice

Get the price of a token in USD.

Args:

token_address: The address of the token to price. block (optional): The block number at which to get the price. If None, uses the latest block. fail_to_None (optional): If True, return None instead of raising a yPriceMagicError on failure. Default False. skip_cache (optional): If True, bypass the cache and fetch the price directly. Defaults to ENVS.SKIP_CACHE. ignore_pools (optional): A tuple of pool addresses to ignore when fetching the price. silent (optional): If True, suppress error logging. Default False.

Returns:

The price of the token in USD, or None if the price couldn’t be determined and fail_to_None is True.

Raises:

yPriceMagicError: If the price couldn’t be determined and fail_to_None is False.

Note:

Don’t pass an int like 123 into token_address please, that’s just silly. - ypricemagic accepts ints to allow you to pass y.get_price(0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e)

so you can save yourself some keystrokes while testing in a console

  • (as opposed to y.get_price(“0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e”))

Since get_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.

ASyncFunctiony.prices.magic.get_prices(token_addresses: Iterable[AnyAddressType], block: Block | None = None, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) List[UsdPrice | None][source]
ASyncFunctiony.prices.magic.get_prices(token_addresses: Iterable[AnyAddressType], block: Block | None = None, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) List[UsdPrice]

Get prices for multiple tokens in USD.

You should use this function over get_price() where possible, it is better optimized for parallel execution.

Args:

token_addresses: An iterable of token addresses to price. block (optional): The block number at which to get the prices. Defaults to the latest block. fail_to_None (optional): If True, return None for tokens whose price couldn’t be determined. Default False. skip_cache (optional): If True, bypass the cache and fetch prices directly. Defaults to ENVS.SKIP_CACHE. silent (optional): If True, suppress progress bar and error logging. This kwarg is not currently implemented.

Returns:

A list of token prices in USD, in the same order as the input token_addresses.

Since get_prices 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.

y.prices.magic.map_prices(token_addresses: Iterable[str | HexBytes | AnyAddress | EthAddress | Contract | int], block: int | BlockNumber, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) TaskMapping[str | HexBytes | AnyAddress | EthAddress | Contract | int, UsdPrice | None][source]
y.prices.magic.map_prices(token_addresses: Iterable[str | HexBytes | AnyAddress | EthAddress | Contract | int], block: int | BlockNumber, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) TaskMapping[str | HexBytes | AnyAddress | EthAddress | Contract | int, UsdPrice]

Map token addresses to their prices asynchronously.

Parameters:
  • token_addresses – An iterable of token addresses to price.

  • block (optional) – The block number at which to get the prices. Defaults to latest block.

  • fail_to_None (optional) – If True, map to None for tokens whose price couldn’t be determined. Default False.

  • skip_cache (optional) – If True, bypass the cache and fetch prices directly. Defaults to ENVS.SKIP_CACHE.

  • silent (optional) – If True, suppress error logging. Default False.

Returns:

An a_sync.TaskMapping object mapping token addresses to their prices.

y.prices.one_to_one module

ASyncFunctiony.prices.one_to_one.get_price(token_address: eth_typing.evm.ChecksumAddress, 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 USD price of a one-to-one token by mapping it to its corresponding token.

This function supports both synchronous and asynchronous execution.

Args:

token_address: The address of the token to get the price for. block: The block number to get the price at. Defaults to the latest block. skip_cache: Whether to skip the cache when fetching the price. Defaults to the value of ENVS.SKIP_CACHE.

Returns:

The USD price of the token.

Examples:

Synchronous usage: >>> get_price(“0x4da27a545c0c5B758a6BA100e3a049001de870f5”)

Asynchronous usage: >>> await get_price(“0x4da27a545c0c5B758a6BA100e3a049001de870f5”, sync=False)

See Also:

Since get_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

y.prices.one_to_one.is_one_to_one_token(token_address)[source]

Check if a token address is a one-to-one token.

Parameters:

token_address (ChecksumAddress) – The address of the token to check.

Returns:

True if the token is a one-to-one token, False otherwise.

Return type:

bool

Examples

>>> is_one_to_one_token("0x4da27a545c0c5B758a6BA100e3a049001de870f5")
True
>>> is_one_to_one_token("0x0000000000000000000000000000000000000000")
False

y.prices.pendle module

ASyncFunctiony.prices.pendle.get_lp_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress], block: Union[int, eth_typing.evm.BlockNumber] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) decimal.Decimal[source]

Calculates the price of a Pendle LP token.

Args:

token: The address of the Pendle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching prices. Defaults to ENVS.SKIP_CACHE.

Returns:

The price of the LP token in USD.

Example:
>>> price = get_lp_price("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23", block=14_000_000)
>>> print(f"{price:.6f}")
1.234567  # The price of the Pendle LP token in USD
Note:

This function retrieves the LP to asset rate using the Pendle Oracle contract and calculates the LP token price by multiplying the LP to asset rate by the asset’s price in USD.

See Also:
  • get_tokens() for retrieving the tokens in a Pendle LP token.

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

Decimal

y.prices.pendle.get_tokens(lp_token)[source]

Retrieves the addresses of the tokens in a Pendle LP token.

This function is cached to improve performance for repeated calls.

Parameters:

lp_token (str | HexBytes | AnyAddress | EthAddress) – The address of the Pendle LP token.

Returns:

A tuple containing the addresses of the SY token, PT token, and YT token.

Return type:

Tuple[str, str, str]

Example

>>> tokens = await get_tokens("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23")
>>> print(tokens)
('0x...', '0x...', '0x...')  # Addresses of SY, PT, and YT tokens

Note

The function returns the result of the readTokens method from the Pendle LP contract, which provides the addresses of the underlying tokens.

See also

ASyncFunctiony.prices.pendle.is_pendle_lp(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress) bool[source]

Determines if the given token address is a Pendle LP token.

Args:

token: The address of the token to check.

Returns:

True if the token is a Pendle LP token, False otherwise.

Example:
>>> is_pendle = is_pendle_lp("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23")
>>> print(is_pendle)
True

Since is_pendle_lp 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)

Return type:

bool

y.prices.popsicle module

ASyncFunctiony.prices.popsicle.get_balances(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]>, _async_balance_objects: bool = False) Tuple[y.classes.common.WeiBalance, y.classes.common.WeiBalance] | None[source]

Retrieves the balances of the underlying tokens in a Popsicle Finance LP token.

Args:

token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching balances. Defaults to ENVS.SKIP_CACHE. _async_balance_objects (optional): Whether to use asynchronous balance objects. Defaults to False.

Returns:

A tuple containing the balances of the two underlying tokens, or None if the balances cannot be determined.

Example:
>>> balances = get_balances("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000)
>>> if balances:
...     balance0, balance1 = balances
...     print(f"Token0 Balance: {balance0.readable}, Token1 Balance: {balance1.readable}")
... else:
...     print("Balances could not be determined.")
Token0 Balance: 1000.0, Token1 Balance: 2000.0
Note:

If the contract probed has the correct method name but the method returns the wrong type for Popsicle, an exception “not enough values to unpack (expected 3, got 2)” will be caught, and the function will return None.

See Also:

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

Tuple[WeiBalance, WeiBalance] | None

ASyncFunctiony.prices.popsicle.get_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 | None[source]

Calculates the price of a Popsicle Finance LP token.

Args:

token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching prices. Defaults to ENVS.SKIP_CACHE.

Returns:

The price of the LP token in USD, or None if the price cannot be determined.

Example:
>>> price = get_price("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000)
>>> print(f"{price:.6f}")
1.234567  # The price of the Popsicle LP token in USD
See Also:

Since get_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 | None

ASyncFunctiony.prices.popsicle.get_tvl(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.UsdValue | None[source]

Calculates the total value locked (TVL) in a Popsicle Finance LP token.

Args:

token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching TVL. Defaults to ENVS.SKIP_CACHE.

Returns:

The total value locked in the LP token in USD, or None if the TVL cannot be determined.

Example:
>>> tvl = get_tvl("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000)
>>> print(f"{tvl:.2f}")
1234567.89  # The TVL of the Popsicle LP token in USD
See Also:

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

UsdValue | None

ASyncFunctiony.prices.popsicle.is_popsicle_lp(token_address: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool[source]

Determines if the given token address is a Popsicle Finance LP token.

Args:

token_address: The address of the token to check.

Returns:

True if the token is a Popsicle LP token, False otherwise.

Example:
>>> is_popsicle = is_popsicle_lp("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf")
>>> print(is_popsicle)
True

Since is_popsicle_lp 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_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

bool

y.prices.rkp3r module

async y.prices.rkp3r.get_discount(block=None)[source]

Retrieve the discount for the RKP3R token from the contract.

Parameters:

block (int | BlockNumber | None) – The block number to query the discount at.

Returns:

The discount as a percentage.

Return type:

Decimal

Examples

>>> await get_discount()
Decimal('5.0')
ASyncFunctiony.prices.rkp3r.get_price(address: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress], 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]>) decimal.Decimal[source]

Get the price of the KP3R token and apply a discount to calculate the RKP3R token price.

This function retrieves the price of the KP3R token and applies a discount specific to the RKP3R token.

Args:

address: The address of the token. block: The block number to query the price at. skip_cache: Whether to skip the cache when retrieving the price.

Returns:

The discounted price of the RKP3R token.

Examples:
>>> await get_price("0xEdB67Ee1B171c4eC66E6c10EC43EDBbA20FaE8e9")
Decimal('123.45')
See Also:

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

Decimal

y.prices.rkp3r.is_rkp3r(address)[source]

Check if the given address is the RKP3R token on the Ethereum Mainnet.

Parameters:

address (str | HexBytes | AnyAddress | EthAddress) – The address to check.

Returns:

True if the address is RKP3R on Mainnet, False otherwise.

Return type:

bool

Examples

>>> is_rkp3r("0xEdB67Ee1B171c4eC66E6c10EC43EDBbA20FaE8e9")
True
>>> is_rkp3r("0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44")
False

y.prices.solidex module

ASyncFunctiony.prices.solidex.get_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Optional[int] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>)[source]

Retrieve the price of a given token.

This function first obtains the associated pool using the cached _get_pool() function and then calls magic.get_price() on that pool to retrieve the price.

Args:

token: The address of the token to get the price for. block: The block number to query. Defaults to the latest block. skip_cache: If True, skip using the cache while fetching price data.

Examples:
>>> await get_price("0xTokenAddress")
123.45
See Also:

Since get_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:
ASyncFunctiony.prices.solidex.is_solidex_deposit(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool[source]

Determine if a given token is a Solidex deposit token.

This function checks if the current network is Fantom and if the token contract has a pool attribute. It also verifies that the token name starts with “Solidex” and ends with “Deposit”.

Args:

token: The address of the token to check.

Returns:

True if the token is a Solidex deposit token, False otherwise.

Examples:
>>> await is_solidex_deposit("0xTokenAddress")
True
See Also:

Since is_solidex_deposit 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.synthetix module

class y.prices.synthetix.Synthetix[source]

Bases: ASyncGenericSingleton

A class to interact with the Synthetix protocol.

This class provides methods to interact with the Synthetix protocol, allowing users to get contract addresses, synths, and prices.

Raises:

UnsupportedNetwork – If the Synthetix protocol is not supported on the current network.

Examples

>>> synthetix = Synthetix(asynchronous=True)
>>> address = await synthetix.get_address("ProxyERC20")
>>> print(address)
<Contract object at 0x...>
__init__(self)[source]
Parameters:

asynchronous (bool)

Return type:

None

__address_resolver__: HiddenMethodDescriptor[Self, Contract]

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

__synths__

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_resolver[source]

Get the address resolver contract.

Returns:

The address resolver contract.

Examples

>>> resolver = await synthetix.address_resolver
>>> print(resolver)
<Contract object at 0x...>
get_address[source]

Get contract from Synthetix registry.

Args:

name: The name of the contract to retrieve. block: The block number to query at. Defaults to the latest block.

Returns:

The contract associated with the given name. If the contract is a proxy, it returns the target contract if available, otherwise the proxy itself.

See Also:
Examples:
>>> contract = await synthetix.get_address("ProxyERC20")
>>> print(contract)
<Contract object at 0x...>

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

Contract

get_currency_key[source]

Get the currency key for a given token.

Args:

token: The token address to get the currency key for.

Returns:

The currency key as a hex string, or None if not found.

Examples:
>>> currency_key = await synthetix.get_currency_key("0x...")
>>> print(currency_key)
'0x...'

Since get_currency_key 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)

Return type:

HexStr | None

get_price[source]

Get the price of a synth in dollars.

Parameters:
Returns:

The price of the synth in USD, or None if the price is stale.

Raises:

Exception – If an unexpected error occurs during the price retrieval.

Return type:

UsdPrice | None

Examples

>>> price = await synthetix.get_price("0x...")
>>> print(price)
1.23
is_synth[source]

Check if a token is a synth.

Parameters:

token (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The token address to check.

Returns:

True if the token is a synth, False if not.

Raises:

Exception – If an unexpected error occurs during the check.

Return type:

bool

Examples

>>> is_synth = await synthetix.is_synth("0x...")
>>> print(is_synth)
True
synths[source]

Get target addresses of all synths.

Returns:

A list of target addresses for all synths.

Examples

>>> synths = await synthetix.synths
>>> print(synths)
['0x...', '0x...', ...]
y.prices.synthetix.encode_bytes(s)

y.prices.yearn module

class y.prices.yearn.YearnInspiredVault[source]

Bases: ERC20

Represents a vault token from Yearn or a similar protocol.

This class extends ERC20 and provides methods to interact with vaults, including fetching the underlying asset, share price, and token price.

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

None

__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

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

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

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'
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()

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

name

The token’s name.

Returns:

The token’s name.

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.name
'TokenName'
price[source]

Calculates the USD price of the vault token.

Parameters:
  • block (optional) – The block number to query. Defaults to the latest block.

  • ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...]) – Pools to ignore when calculating the price.

  • skip_cache (bool) – Whether to skip the cache when fetching prices.

Returns:

The USD price of the vault token.

Return type:

UsdPrice

Example

>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9")  # yvUSDC
>>> price = vault.price(block=14_000_000)
>>> print(f"{price:.6f}")
1.096431  # The price of yvUSDC in USD
scale

Get the scaling factor for the token.

Returns:

The scaling factor for the token.

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.scale
1000000000000000000
share_price[source]

Calculates the share price of the vault.

Parameters:

block (optional) – The block number to query. Defaults to the latest block.

Returns:

The share price of the vault, or None if the vault’s total supply is zero.

Raises:

CantFetchParam – If the share price cannot be fetched or calculated.

Return type:

Decimal | None

Example

>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9")  # yvUSDC
>>> share_price = await vault.share_price(block=14_000_000)
>>> print(f"{share_price:.6f}")
1.096431
symbol

The token’s symbol.

Returns:

The token’s symbol.

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.symbol
'TKN'
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
underlying[source]

Fetches the underlying asset of the vault.

Returns:

The underlying ERC20 token.

Raises:

CantFetchParam – If the underlying asset cannot be determined.

Special Cases:
  1. Arbitrum USDL: For the specific address 0x57c7E0D43C05bCe429ce030132Ca40F6FA5839d7 on Arbitrum, it uses the ‘usdl()’ method to fetch the underlying token.

  2. Beefy Vaults: For certain Beefy vaults (BeefyVaultV6Matic and BeefyVenusVaultBNB), it uses ‘wmatic()’ or ‘wbnb()’ methods respectively.

  3. Reaper Vaults: For certain Reaper vaults, it checks for a ‘lendPlatform()’ method and then queries the ‘underlying()’ method on the lend platform contract.

Example

>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9")  # yvUSDC
>>> underlying = vault.underlying()
>>> underlying.address
"0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"  # USDC address
ASyncFunctiony.prices.yearn.get_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]>, ignore_pools: Tuple[Union[ForwardRef('UniswapV2Pool'), ForwardRef('CurvePool')], ...] = ()) y.datatypes.UsdPrice[source]

Since get_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.yearn.is_yearn_vault(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool[source]

Since is_yearn_vault 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.yearn.share_price_methods = ('pricePerShare()(uint)', 'getPricePerShare()(uint)', 'getPricePerFullShare()(uint)', 'getSharesToUnderlying()(uint)', 'exchangeRate()(uint)')

List of methods which might be used to get the share price of a vault.

y.prices.yearn.underlying_methods = ('token()(address)', 'underlying()(address)', 'native()(address)', 'want()(address)', 'input()(address)', 'asset()(address)', 'wmatic()(address)', 'wbnb()(address)', 'based()(address)')

List of methods which might be used to get the underlying asset of a vault.

Module contents