y.prices.eth_derivs package

Submodules

y.prices.eth_derivs.creth module

ASyncFunctiony.prices.eth_derivs.creth.get_price_creth(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 crETH in USD.

This function retrieves the accumulated balance and total supply of crETH, divides the total balance by the total supply to calculate the value per token, and then multiplies this value by the current WETH price to determine the price of crETH in USD.

Args:

token: The crETH token address. 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_creth("0xcBc1065255cBc3aB41a6868c22d1f1C573AB89fd")
1234.56
See Also:

Since get_price_creth 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.eth_derivs.creth.is_creth(token)[source]

Check if a token is crETH.

Parameters:

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

Returns:

True if the token is crETH on the Ethereum Mainnet, False otherwise.

Return type:

bool

Example

>>> is_creth("0xcBc1065255cBc3aB41a6868c22d1f1C573AB89fd")
True

y.prices.eth_derivs.wsteth module

class y.prices.eth_derivs.wsteth.wstEth[source]

Bases: ASyncGenericBase

A class to interact with the wstETH token on Ethereum Mainnet.

This class provides methods to fetch the price of wstETH in USD, leveraging the a_sync library to support both synchronous and asynchronous operations.

Examples

Initialize the class with asynchronous behavior:

>>> wsteth = wstEth(asynchronous=True)
>>> price = await wsteth.get_price(block=12345678)

Initialize the class with synchronous behavior:

>>> wsteth_sync = wstEth(asynchronous=False)
>>> price_sync = wsteth_sync.get_price(block=12345678)
__init__(*, asynchronous=False)[source]

Initialize the wstEth class with optional asynchronous behavior.

Parameters:

asynchronous (bool) – A boolean indicating if the operations should be asynchronous.

Return type:

None

address

The address of the wstETH token on the Ethereum Mainnet, or None if not on Mainnet.

wrapped_for_curve

The address of the wrapped version of wstETH for Curve on the Ethereum Mainnet, or None if not on Mainnet.

get_price[source]

Fetch the price of wstETH in USD.

This method retrieves the price of wstETH by calling the stEthPerToken method on the wstETH contract using y.utils.raw_calls.raw_call() and fetching the current price of WETH using y.prices.magic.get_price().

Parameters:
  • block (int | BlockNumber | None) – The block number at which to fetch the price.

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

Return type:

UsdPrice

Examples

Fetch the price asynchronously:

>>> price = await wsteth.get_price(block=12345678)

Fetch the price synchronously:

>>> price_sync = wsteth_sync.get_price(block=12345678)
y.prices.eth_derivs.wsteth.is_wsteth(address)[source]

Check if a given address is wstETH or its wrapped version for Curve on Ethereum Mainnet.

This function verifies the network ID to ensure it is operating on the Ethereum Mainnet before performing the address comparison.

Parameters:

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

Return type:

bool

Examples

Check if an address is wstETH:

>>> is_wsteth("0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0")
True

Check if an address is not wstETH:

>>> is_wsteth("0x0000000000000000000000000000000000000000")
False

See also

Module contents