y.classes package

Submodules

y.classes.common module

class y.classes.common.ContractBase[source]

Bases: ASyncGenericBase

__eq__(_ContractBase__o)[source]

Return self==value.

Parameters:

_ContractBase__o (object)

Return type:

bool

__init__(self)[source]
Parameters:
Return type:

None

__str__()[source]

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

address
asynchronous: bool = False
build_name[source]

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

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

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

class y.classes.common.ERC20[source]

Bases: ContractBase

Represents an ERC20 token.

ASyncFunction_decimals(block: int | eth_typing.evm.BlockNumber | NoneType = None) int[source]

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

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] = 'ERC20'
__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

address: str | HexBytes | AnyAddress | EthAddress

The contract address of the token.

asynchronous: bool = False
balance_of[source]

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

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

The token’s name.

Returns:

The token’s name.

Examples

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

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

Get the scaling factor for the token.

Returns:

The scaling factor for the token.

Examples

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

The token’s symbol.

Returns:

The token’s symbol.

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.symbol
'TKN'
total_supply[source]

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

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
final class y.classes.common.WeiBalance[source]

Bases: ASyncGenericBase

Represents a balance of a token in wei.

This class provides utility methods for working with token balances in wei, including converting to readable format, getting the price in USD, and performing arithmetic operations.

__add__(_WeiBalance__o)[source]
Parameters:

_WeiBalance__o (WeiBalance)

Return type:

WeiBalance

__bool__()[source]

Check if the balance is non-zero.

Returns:

True if the balance is non-zero, False otherwise.

Return type:

bool

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> bool(balance)
True
__eq__(_WeiBalance__o)[source]

Check if two WeiBalance objects are equal.

Parameters:
  • __o – The object to compare with.

  • _WeiBalance__o (object)

Returns:

True if the objects are equal, False otherwise.

Return type:

bool

Examples

>>> balance1 = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance2 = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance1 == balance2
True
__ge__(_WeiBalance__o)[source]

Check if one WeiBalance object is greater than or equal to another.

Parameters:
  • __o – The object to compare with.

  • _WeiBalance__o (object)

Returns:

True if the current object is greater than or equal to the other object, False otherwise.

Raises:

TypeError – If the objects are not of the same type.

Return type:

bool

Examples

>>> balance1 = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance2 = WeiBalance(500000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance1 >= balance2
True
__init__(balance, token, block=None, *, skip_cache=<EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>, ignore_pools=(), asynchronous=False)[source]

Initialize a WeiBalance object.

Parameters:
  • balance (int) – The balance in wei.

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

  • block (int | BlockNumber | None) – The block number for the balance (optional).

  • skip_cache (bool) – If True, skip using the local cache for price data.

  • ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...]) – A tuple of pools to ignore when calculating the price.

  • asynchronous (bool) – True if this object will be used with its asynchronous API, False for its sync API.

Return type:

None

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> print(balance)
1000000000000000000
__lt__(_WeiBalance__o)[source]

Return self<value.

Parameters:

_WeiBalance__o (object)

Return type:

bool

__mul__(_WeiBalance__o)[source]

Multiply a WeiBalance object by a scalar value.

Parameters:
  • __o – The scalar value to multiply by.

  • _WeiBalance__o (int | float | Decimal)

Returns:

A new WeiBalance object representing the product.

Raises:

TypeError – If the scalar value is not a number.

Return type:

WeiBalance

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance * 2
<WeiBalance token=<ERC20 TKN '0x1234567890abcdef1234567890abcdef12345678'> balance=2000000000000000000 block=None>
__radd__(_WeiBalance__o)[source]
Parameters:

_WeiBalance__o (WeiBalance | Literal[0])

Return type:

WeiBalance

__str__()[source]

Return the balance in wei as a string.

Returns:

The balance in wei as a string.

Return type:

str

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> str(balance)
'1000000000000000000'
__sub__(_WeiBalance__o)[source]
Parameters:

_WeiBalance__o (WeiBalance)

Return type:

WeiBalance

__truediv__(_WeiBalance__o)[source]

Divide a WeiBalance object by a scalar value.

Parameters:
  • __o – The scalar value to divide by.

  • _WeiBalance__o (int | float | Decimal)

Returns:

A new WeiBalance object representing the quotient.

Raises:

TypeError – If the scalar value is not a number.

Return type:

WeiBalance

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> balance / 2
<WeiBalance token=<ERC20 TKN '0x1234567890abcdef1234567890abcdef12345678'> balance=500000000000000000 block=None>
__price__: HiddenMethodDescriptor[Self, Decimal]

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

__readable__: HiddenMethodDescriptor[Self, Decimal]

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

__value_usd__: HiddenMethodDescriptor[Self, Decimal]

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

asynchronous: bool = False
block: int | BlockNumber | None = None
price[source]

Get the price of the token in USD.

Returns:

The price of the token in USD.

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> await balance.price
Decimal('1.23')
readable[source]

Get the balance scaled to a human-readable decimal.

Returns:

The balance scaled to a decimal.

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> await balance.readable
Decimal('1.0')
value_usd[source]

Get the value of the balance in USD.

Returns:

The value of the balance in USD.

Examples

>>> balance = WeiBalance(1000000000000000000, "0x1234567890abcdef1234567890abcdef12345678")
>>> await balance.value_usd
Decimal('1.23')
y.classes.common.hex_to_string(h)[source]

Convert a HexString to a string.

Parameters:

h (HexString) – The HexString to convert.

Returns:

The converted string.

Return type:

str

y.classes.singleton module

class y.classes.singleton.ChecksumASyncSingletonMeta[source]

Bases: ASyncMeta, Generic[T]

A metaclass for creating singleton instances with checksummed addresses and asynchronous capabilities.

This metaclass extends ASyncMeta to ensure that only one instance of a class is created for each synchronous or asynchronous context, with the added functionality of checksumming Ethereum addresses using ChecksumAddressDict.

The differentiation between synchronous and asynchronous contexts is achieved by using the __a_sync_instance_will_be_sync__ method to determine the context during instance creation. Instances are stored in cls.__instances, which is a DefaultDict of ChecksumAddressDict keyed by the context (synchronous or asynchronous). This ensures that separate instances are created for each context.

Examples

>>> class MySingleton(metaclass=ChecksumASyncSingletonMeta):
...     def __init__(self, address, asynchronous=False):
...         self.address = address
...         self.asynchronous = asynchronous
...
>>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb', asynchronous=True)
>>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb', asynchronous=True)
>>> assert instance1 is instance2
__base__

alias of ASyncMeta

__call__(address, *args, **kwargs)[source]

Create or retrieve a singleton instance for the given address.

This method ensures that only one instance of a class is created for each address in a synchronous or asynchronous context. The address is checksummed to ensure consistency.

Note

This will only work if you init your objects using a kwarg not a positional arg. TODO: Make it work with positional args.

Parameters:
  • address (AnyAddress) – The address for which to create or retrieve the singleton instance.

  • *args – Additional positional arguments for instance creation.

  • **kwargs – Additional keyword arguments for instance creation.

Raises:

AssertionError – If the instance’s asynchronous state does not match the expected state.

Return type:

T

Examples

>>> class MySingleton(metaclass=ChecksumASyncSingletonMeta):
...     def __init__(self, address, asynchronous=False):
...         self.address = address
...         self.asynchronous = asynchronous
...
>>> instance1 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb', asynchronous=True)
>>> instance2 = MySingleton('0xb47e3cd837ddf8e4c57f05d70ab865de6e193bbb', asynchronous=True)
>>> assert instance1 is instance2
__dir__()

Specialized __dir__ implementation for types.

__getattribute__(name, /)

Return getattr(self, name).

__init__(name, bases, namespace)[source]

Initialize the metaclass with a name, bases, and namespace.

Parameters:
  • name – The name of the class being created.

  • bases – A tuple of base classes.

  • namespace – A dictionary representing the class namespace.

__instancecheck__(instance)

Override for isinstance(instance, cls).

__or__(value, /)

Return self|value.

__prepare__() dict

used to create the namespace for the class statement

__ror__(value, /)

Return value|self.

__sizeof__()

Return memory consumption of the type object.

__subclasscheck__(subclass)

Override for issubclass(subclass, cls).

__subclasses__()

Return a list of immediate subclasses.

mro()

Return a type’s method resolution order.

register(subclass)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

__bases__ = (<class 'a_sync.a_sync._meta.ASyncMeta'>, <class 'typing.Generic'>)
__basicsize__ = 888
__dictoffset__ = 264
__flags__ = 2148029952
__itemsize__ = 40
__mro__ = (<class 'y.classes.singleton.ChecksumASyncSingletonMeta'>, <class 'a_sync.a_sync._meta.ASyncMeta'>, <class 'abc.ABCMeta'>, <class 'type'>, <class 'typing.Generic'>, <class 'object'>)
__name__ = 'ChecksumASyncSingletonMeta'
__qualname__ = 'ChecksumASyncSingletonMeta'
__text_signature__ = None
__weakrefoffset__ = 368

Module contents

class y.classes.ERC20[source]

Bases: ContractBase

Represents an ERC20 token.

ASyncFunction_decimals(block: int | eth_typing.evm.BlockNumber | NoneType = None) int[source]

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

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] = 'ERC20'
__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

address: str | HexBytes | AnyAddress | EthAddress

The contract address of the token.

asynchronous: bool = False
balance_of[source]

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

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

The token’s name.

Returns:

The token’s name.

Examples

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

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

Get the scaling factor for the token.

Returns:

The scaling factor for the token.

Examples

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

The token’s symbol.

Returns:

The token’s symbol.

Examples

>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678")
>>> await token.symbol
'TKN'
total_supply[source]

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

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