y.prices.lending package

Submodules

y.prices.lending.aave module

class y.prices.lending.aave.AaveMarketBase[source]

Bases: ContractBase

Base class for Aave markets.

This class provides common functionality for Aave markets, including methods to check if a token is an aToken from the market and to retrieve reserve data.

__contains__(token)[source]

Check if token is an aToken from this market.

This method is intended for synchronous use. If self.asynchronous is not False, a RuntimeError will be raised.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Raises:

RuntimeError – If self.asynchronous is not False.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress")
>>> token = "0xTokenAddress"
>>> token in market
True
__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

__atokens__: HiddenMethodDescriptor[Self, List[ERC20]]
__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

address
asynchronous: bool = False
abstract property atokens: Awaitable[List[ERC20]]

Get the aTokens of the market.

This is an abstract property and must be implemented by subclasses.

Returns:

A list of aTokens as ERC20 objects.

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> atokens = await market.atokens
>>> print(atokens)
[<ERC20 '0xTokenAddress1'>, <ERC20 '0xTokenAddress2'>]
build_name

Get the contract’s build name.

Returns:

The contract’s build name.

Examples

>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678")
>>> await contract.build_name
'MyContract'
contains[source]

Check if token is an aToken from this market.

This method is intended for asynchronous use.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> token = "0xTokenAddress"
>>> await market.contains(token)
True
property contract: Contract
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_reserve_data[source]
Parameters:

reserve (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

tuple

get_reserves[source]
Return type:

List[str | HexBytes | AnyAddress | EthAddress]

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]

Get the underlying asset of the given aToken address.

This is an abstract method and must be implemented by subclasses.

Parameters:

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract) – The address of the aToken.

Returns:

The underlying asset.

Return type:

ERC20

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> underlying_asset = await market.underlying("0xATokenAddress")
>>> print(underlying_asset)
<ERC20 '0xUnderlyingAssetAddress'>
class y.prices.lending.aave.AaveMarketV1[source]

Bases: AaveMarketBase

__contains__(token)

Check if token is an aToken from this market.

This method is intended for synchronous use. If self.asynchronous is not False, a RuntimeError will be raised.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Raises:

RuntimeError – If self.asynchronous is not False.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress")
>>> token = "0xTokenAddress"
>>> token in market
True
__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

__atokens__: HiddenMethodDescriptor[Self, List[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

__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

address
asynchronous: bool = False
atokens[source]
build_name

Get the contract’s build name.

Returns:

The contract’s build name.

Examples

>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678")
>>> await contract.build_name
'MyContract'
contains

Check if token is an aToken from this market.

This method is intended for asynchronous use.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> token = "0xTokenAddress"
>>> await market.contains(token)
True
property contract: Contract
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_reserve_data
Parameters:

reserve (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

tuple

get_reserves
Return type:

List[str | HexBytes | AnyAddress | EthAddress]

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]

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

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract)

Return type:

ERC20

class y.prices.lending.aave.AaveMarketV2[source]

Bases: AaveMarketBase

__contains__(token)

Check if token is an aToken from this market.

This method is intended for synchronous use. If self.asynchronous is not False, a RuntimeError will be raised.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Raises:

RuntimeError – If self.asynchronous is not False.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress")
>>> token = "0xTokenAddress"
>>> token in market
True
__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

__atokens__: HiddenMethodDescriptor[Self, List[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

__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

address
asynchronous: bool = False
atokens[source]
build_name

Get the contract’s build name.

Returns:

The contract’s build name.

Examples

>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678")
>>> await contract.build_name
'MyContract'
contains

Check if token is an aToken from this market.

This method is intended for asynchronous use.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> token = "0xTokenAddress"
>>> await market.contains(token)
True
property contract: Contract
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_reserve_data[source]
Parameters:

reserve (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

tuple

get_reserves
Return type:

List[str | HexBytes | AnyAddress | EthAddress]

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]

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

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract)

Return type:

ERC20

class y.prices.lending.aave.AaveMarketV3[source]

Bases: AaveMarketBase

__contains__(token)

Check if token is an aToken from this market.

This method is intended for synchronous use. If self.asynchronous is not False, a RuntimeError will be raised.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Raises:

RuntimeError – If self.asynchronous is not False.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress")
>>> token = "0xTokenAddress"
>>> token in market
True
__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

__atokens__: HiddenMethodDescriptor[Self, List[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

__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

address
asynchronous: bool = False
atokens[source]
build_name

Get the contract’s build name.

Returns:

The contract’s build name.

Examples

>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678")
>>> await contract.build_name
'MyContract'
contains

Check if token is an aToken from this market.

This method is intended for asynchronous use.

Parameters:

token (object) – The item to check.

Returns:

True if the token is an aToken from the market, False otherwise.

Return type:

bool

Example

>>> market = AaveMarketV1("0xAddress", asynchronous=True)
>>> token = "0xTokenAddress"
>>> await market.contains(token)
True
property contract: Contract
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_reserve_data
Parameters:

reserve (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

tuple

get_reserves
Return type:

List[str | HexBytes | AnyAddress | EthAddress]

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]

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

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract)

Return type:

ERC20

class y.prices.lending.aave.AaveRegistry[source]

Bases: ASyncGenericSingleton

__contains__(_AaveRegistry__o)[source]
Parameters:

_AaveRegistry__o (object)

Return type:

bool

__init__(self)[source]
Parameters:

asynchronous (bool)

Return type:

None

__pools__: HiddenMethodDescriptor[Self, List[AaveMarketV1 | AaveMarketV2 | AaveMarketV3]]

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_v1__: HiddenMethodDescriptor[Self, List[AaveMarketV1]]

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_v2__: HiddenMethodDescriptor[Self, List[AaveMarketV2]]

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_v3__: HiddenMethodDescriptor[Self, List[AaveMarketV3]]

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

UsdPrice

get_price_wrapped_v2[source]
Parameters:
Return type:

UsdPrice | None

get_price_wrapped_v3[source]
Parameters:
Return type:

UsdPrice | None

is_atoken[source]

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

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

bool

is_wrapped_atoken_v2[source]
Parameters:

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

bool

is_wrapped_atoken_v3[source]
Parameters:

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

bool

pool_for_atoken[source]
Parameters:

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)

Return type:

AaveMarketV1 | AaveMarketV2 | AaveMarketV3 | None

pools[source]
pools_v1[source]
pools_v2[source]
pools_v3[source]
underlying[source]

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

atoken_address (str | HexBytes | AnyAddress | EthAddress | Contract)

Return type:

ERC20

y.prices.lending.compound module

class y.prices.lending.compound.CToken[source]

Bases: ERC20

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, comptroller=None, *, asynchronous=False)[source]

Initialize a CToken instance.

Parameters:
Return type:

None

Examples

>>> ctoken = CToken("0x1234567890abcdef1234567890abcdef12345678")
>>> ctoken_with_comptroller = CToken("0x1234567890abcdef1234567890abcdef12345678", comptroller=my_comptroller)
__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] = 'CToken'
__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()

exchange_rate[source]

Get the current exchange rate of the CToken.

Parameters:

block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.

Return type:

float

Examples

>>> rate = await ctoken.exchange_rate()
>>> rate_at_block = await ctoken.exchange_rate(block=12345678)
get_price[source]

Get the price of the CToken in USD.

Parameters:
  • block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.

  • skip_cache (bool) – Whether to skip using the cache while fetching price data.

Return type:

UsdPrice

Examples

>>> price = await ctoken.get_price()
>>> price_at_block = await ctoken.get_price(block=12345678)
get_underlying_price[source]

Get the price of the underlying token in USD.

Parameters:
  • block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.

  • skip_cache (bool) – Whether to skip using the cache while fetching price data.

Return type:

float | None

Examples

>>> price = await ctoken.get_underlying_price()
>>> price_at_block = await ctoken.get_underlying_price(block=12345678)
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

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
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'
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]

Get the underlying ERC20 token for this CToken.

Returns:

An instance of ERC20 representing the underlying token.

Examples

>>> underlying_token = await ctoken.underlying
underlying_per_ctoken[source]

Get the exchange rate of the CToken, adjusted for decimals.

This method calculates the amount of underlying tokens per CToken by multiplying the exchange rate by a factor based on the difference in decimals between the CToken and its underlying token.

Parameters:

block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.

Return type:

float

Examples

>>> amount = await ctoken.underlying_per_ctoken()
>>> amount_at_block = await ctoken.underlying_per_ctoken(block=12345678)

See also

class y.prices.lending.compound.Compound[source]

Bases: ASyncGenericSingleton

__contains__(token_address)[source]

Check if a token address is a Compound market.

Parameters:

token_address (str | HexBytes | AnyAddress | EthAddress | Contract) – The address of the token to check.

Returns:

True if the token address is a Compound market, False otherwise.

Return type:

bool

Examples

>>> "0x1234567890abcdef1234567890abcdef12345678" in compound
__init__(*, asynchronous=False)[source]

Initialize a Compound instance.

Parameters:

asynchronous (bool) – Whether to use asynchronous operations.

Return type:

None

Examples

>>> compound = Compound()
>>> compound_async = Compound(asynchronous=True)
get_price[source]

Get the price of a token in USD.

Parameters:
Return type:

UsdPrice | None

Examples

>>> price = await compound.get_price("0x1234567890abcdef1234567890abcdef12345678")
>>> price_at_block = await compound.get_price("0x1234567890abcdef1234567890abcdef12345678", block=12345678)
get_troller[source]

Get the Comptroller associated with a token address.

Parameters:

token_address (str | HexBytes | AnyAddress | EthAddress | Contract) – The address of the token.

Returns:

An instance of Comptroller if found, None otherwise.

Return type:

Comptroller | None

Examples

>>> troller = await compound.get_troller("0x1234567890abcdef1234567890abcdef12345678")
is_compound_market[source]

Check if a token address is a Compound market.

Args:

token_address: The address of the token to check.

Returns:

True if the token address is a Compound market, False otherwise.

Examples:
>>> is_market = await compound.is_compound_market("0x1234567890abcdef1234567890abcdef12345678")

Since is_compound_market is an ASyncFunctionAsyncDefault, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.

Parameters:

token_address (str | HexBytes | AnyAddress | EthAddress | Contract)

Return type:

bool

class y.prices.lending.compound.Comptroller[source]

Bases: ContractBase

__contains__(token_address)[source]

Check if a token address is contained within the Comptroller’s markets.

Parameters:

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

Returns:

True if the token address is in the Comptroller’s markets, False otherwise.

Return type:

bool

Examples

>>> "0x1234567890abcdef1234567890abcdef12345678" in comptroller
__eq__(_ContractBase__o)

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(address=None, key=None, *, asynchronous=False)[source]

Initialize a Comptroller instance.

You must provide either an address or a key. If both are provided, the key will be used to look up the address.

Parameters:
  • address (str | HexBytes | AnyAddress | EthAddress | Contract | int | None) – The address of the Comptroller.

  • key (str | None) – The key associated with the Comptroller in the TROLLERS dictionary.

  • asynchronous (bool) – Whether to use asynchronous operations.

Return type:

None

Examples

>>> comptroller = Comptroller(address="0x1234567890abcdef1234567890abcdef12345678")
>>> comptroller_with_key = Comptroller(key="comp")
__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

__markets__

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

markets[source]

Get the markets associated with this Comptroller.

Returns:

A tuple of CToken instances representing the markets.

Examples

>>> markets = await comptroller.markets
oracle[source]

Get the oracle contract associated with this Comptroller.

Parameters:

block (int | BlockNumber | None) – The block number to query. Defaults to the latest block.

Return type:

Contract

Examples

>>> oracle = await comptroller.oracle()
>>> oracle_at_block = await comptroller.oracle(block=12345678)

y.prices.lending.ib module

ASyncFunctiony.prices.lending.ib.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[source]

Calculates the price of an Iron Bank token.

Args:

token: The address of the Iron Bank 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 Iron Bank token in USD.

Example:
>>> price = get_price("0x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393", block=14_000_000)
>>> print(f"{price:.6f}")
1.234567  # The price of the Iron Bank token in USD
Note:

This function calculates the price by retrieving the total balance and total supply of the Iron Bank token, scaling them appropriately, and then calculating the share price. The share price is then multiplied by the price of the underlying asset obtained from y.prices.magic.get_price().

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

ASyncFunctiony.prices.lending.ib.is_ib_token(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool[source]

Determines if the given token address is an Iron Bank token.

Args:

token: The address of the token to check.

Returns:

True if the token is an Iron Bank token, False otherwise.

Example:
>>> is_ib = is_ib_token("0x41c84c0e2EE0b740Cf0d31F63f3B6F627DC6b393")
>>> print(is_ib)
True
See Also:

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

Module contents