y package

Subpackages

Submodules

y.ENVIRONMENT_VARIABLES module

y.cli module

y.constants module

y.contracts module

y.convert module

y.convert.checksum(address)
y.convert.to_address(address)
async y.convert.to_address_async()

y.datatypes module

class y.datatypes.UsdPrice[source]

Bases: UsdValue

Represents a USD price.

Examples

>>> price = UsdPrice(1234.5678)
>>> str(price)
'$1234.56780000'
classmethod fromhex(string, /)

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
__add__(value, /)

Return self+value.

__bool__()

True if self else False

__eq__(value, /)

Return self==value.

__floordiv__(value, /)

Return self//value.

__ge__(value, /)

Return self>=value.

__gt__(value, /)

Return self>value.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__mul__(value, /)

Return self*value.

__pow__(value, mod=None, /)

Return pow(self, value, mod).

__radd__(value, /)

Return value+self.

__str__()

Return a string representation of the USD value. The value is formatted as a USD value with 8 decimal places.

Return type:

str

__sub__(value, /)

Return self-value.

__truediv__(value, /)

Return self/value.

hex()

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
class y.datatypes.UsdValue[source]

Bases: float

Represents a USD value with custom string representation.

Examples

>>> value = UsdValue(1234.5678)
>>> str(value)
'$1234.56780000'
classmethod fromhex(string, /)

Create a floating-point number from a hexadecimal string.

>>> float.fromhex('0x1.ffffp10')
2047.984375
>>> float.fromhex('-0x1p-1074')
-5e-324
__add__(value, /)

Return self+value.

__bool__()

True if self else False

__eq__(value, /)

Return self==value.

__floordiv__(value, /)

Return self//value.

__ge__(value, /)

Return self>=value.

__gt__(value, /)

Return self>value.

__le__(value, /)

Return self<=value.

__lt__(value, /)

Return self<value.

__mul__(value, /)

Return self*value.

__pow__(value, mod=None, /)

Return pow(self, value, mod).

__radd__(value, /)

Return value+self.

__str__()[source]

Return a string representation of the USD value. The value is formatted as a USD value with 8 decimal places.

Return type:

str

__sub__(value, /)

Return self-value.

__truediv__(value, /)

Return self/value.

hex()

Return a hexadecimal representation of a floating-point number.

>>> (-0.1).hex()
'-0x1.999999999999ap-4'
>>> 3.14159.hex()
'0x1.921f9f01b866ep+1'
y.datatypes.Address

A union of types used to represent Ethereum addresses.

Examples

>>> address_str = "0x1234567890abcdef1234567890abcdef12345678"
>>> address_hex = HexBytes("0x1234567890abcdef1234567890abcdef12345678")
>>> address_any = AnyAddress("0x1234567890abcdef1234567890abcdef12345678")
>>> address_eth = EthAddress("0x1234567890abcdef1234567890abcdef12345678")

alias of str | HexBytes | AnyAddress | Address | EthAddress

y.datatypes.AddressOrContract

A type alias representing either an Ethereum address or a contract object. This can be an Address, a Contract, or its subclasses such as Contract and Contract.

Examples

>>> address = "0x1234567890abcdef1234567890abcdef12345678"
>>> contract = Contract.from_abi("MyContract", address, abi)

alias of str | HexBytes | AnyAddress | Address | EthAddress | Contract

y.datatypes.AnyAddressType

A type alias representing any valid representation of an Ethereum address. This can be an Address, a Contract, or an integer.

Examples

>>> any_address_str = "0x1234567890abcdef1234567890abcdef12345678"
>>> any_address_contract = Contract.from_abi("MyContract", any_address_str, abi)
>>> any_address_int = 12345678

alias of str | HexBytes | AnyAddress | Address | EthAddress | Contract | int

y.datatypes.Block

A union of types used to represent block numbers as integers.

Examples

>>> block_int = 12345678
>>> block_number = BlockNumber(12345678)

alias of int | BlockNumber

y.datatypes.Pool

A union of types representing liquidity pools.

Examples

>>> uniswap_pool = UniswapV2Pool("0xUniswapPoolAddress")
>>> curve_pool = CurvePool("0xCurvePoolAddress")

See also

  • UniswapV2Pool

  • CurvePool

alias of UniswapV2Pool | CurvePool | BalancerV2Pool

y.exceptions module

exception y.exceptions.CallReverted

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.CalldataPreparationError

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.CantFetchParam

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.CantFindSwapPath

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.ContractNotVerified

Bases: _ExplorerError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.InvalidAPIKeyError

Bases: _ExplorerError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.MessedUpBrownieContract

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.NoProxyImplementation

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.NodeNotSynced

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.NonStandardERC20

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.NotABalancerV2Pool

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.NotAUniswapV2Pool

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.PriceError

Bases: Exception

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.TokenError

Bases: ValueError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.TokenNotFound

Bases: ValueError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.UnsupportedNetwork

Bases: ValueError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
exception y.exceptions.yPriceMagicError

Bases: ValueError

__getstate__()

Helper for pickle.

add_note()

Exception.add_note(note) – add a note to the exception

__mypyc_attrs__ = ('__dict__',)
y.exceptions.call_reverted(e)
y.exceptions.continue_if_call_reverted(e)
y.exceptions.contract_not_verified(e)
y.exceptions.out_of_gas(e)
y.exceptions.reraise_excs_with_extra_context(*extra_context, after=True)

y.monkey_patches module

y.monkey_patches.monkey_patch_checksum_cache()[source]

Monkey patch dependency checksums with faster versions.

This function replaces the default checksumming functions in various libraries with a faster implementation using to_address. This improves performance by utilizing caching and optimized checksumming.

See also

  • to_address() for the checksumming process.

y.networks module

class y.networks.Network

Bases: IntEnum

mypyc filler docstring

classmethod __contains__(value)

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod __getitem__(name)

Return the member matching name.

classmethod __iter__()

Return members in definition order.

classmethod __len__()

Return the number of members (no aliases)

classmethod from_bytes(bytes, byteorder='big', *, signed=False)

Return the integer represented by the given array of bytes.

bytes

Holds the array of bytes to convert. The argument must either support the buffer protocol or be an iterable object producing bytes. Bytes and bytearray are examples of built-in objects that support the buffer protocol.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Indicates whether two’s complement is used to represent the integer.

__add__(value, /)

Return self+value.

__and__(value, /)

Return self&value.

__bool__()

True if self else False

__dir__()

Returns public methods and other interesting attributes.

__eq__(value, /)

Return self==value.

__floordiv__(value, /)

Return self//value.

__ge__(value, /)

Return self>=value.

__getattribute__(name, /)

Return getattr(self, name).

__gt__(value, /)

Return self>value.

__index__()

Return self converted to an integer, if self is suitable for use as an index into a list.

__init__(*args, **kwds)
__invert__()

~self

__le__(value, /)

Return self<=value.

__lshift__(value, /)

Return self<<value.

__lt__(value, /)

Return self<value.

__mul__(value, /)

Return self*value.

__or__(value, /)

Return self|value.

__pow__(value, mod=None, /)

Return pow(self, value, mod).

__radd__(value, /)

Return value+self.

__rand__(value, /)

Return value&self.

__reduce_ex__(proto)

Helper for pickle.

__rlshift__(value, /)

Return value<<self.

__ror__(value, /)

Return value|self.

__rrshift__(value, /)

Return value>>self.

__rshift__(value, /)

Return self>>value.

__rxor__(value, /)

Return value^self.

__sizeof__()

Returns size in memory, in bytes.

__str__()

Return repr(self).

__sub__(value, /)

Return self-value.

__truediv__(value, /)

Return self/value.

__xor__(value, /)

Return self^value.

to_bytes(length=1, byteorder='big', *, signed=False)

Return an array of bytes representing an integer.

length

Length of bytes object to use. An OverflowError is raised if the integer is not representable with the given number of bytes. Default is length 1.

byteorder

The byte order used to represent the integer. If byteorder is ‘big’, the most significant byte is at the beginning of the byte array. If byteorder is ‘little’, the most significant byte is at the end of the byte array. To request the native byte order of the host system, use `sys.byteorder’ as the byte order value. Default is to use ‘big’.

signed

Determines whether two’s complement is used to represent the integer. If signed is False and a negative integer is given, an OverflowError is raised.

Arbitrum: int = 42161
Aurora: int = 1313161554
Avalanche: int = 43114
Base: int = 8453
Berachain: int = 80094
BinanceSmartChain: int = 56
Cronos: int = 25
Fantom: int = 250
Gnosis: int = 100
Harmony: int = 1666600000
Heco: int = 128
Katana: int = 747474
Mainnet: int = 1
Moonriver: int = 1285
OKEx: int = 66
Optimism: int = 10
Polygon: int = 137
__final__ = True
__members__ = mappingproxy({'Mainnet': <Network.Mainnet: 1>, 'Optimism': <Network.Optimism: 10>, 'Cronos': <Network.Cronos: 25>, 'BinanceSmartChain': <Network.BinanceSmartChain: 56>, 'OKEx': <Network.OKEx: 66>, 'Gnosis': <Network.Gnosis: 100>, 'xDai': <Network.Gnosis: 100>, 'Heco': <Network.Heco: 128>, 'Polygon': <Network.Polygon: 137>, 'Fantom': <Network.Fantom: 250>, 'Moonriver': <Network.Moonriver: 1285>, 'Base': <Network.Base: 8453>, 'Arbitrum': <Network.Arbitrum: 42161>, 'Avalanche': <Network.Avalanche: 43114>, 'Harmony': <Network.Harmony: 1666600000>, 'Aurora': <Network.Aurora: 1313161554>, 'Katana': <Network.Katana: 747474>, 'Berachain': <Network.Berachain: 80094>})
__name__ = 'Network'
__qualname__ = 'Network'
denominator

the denominator of a rational number in lowest terms

label
name
numerator

the numerator of a rational number in lowest terms

printable
xDai: int = 100

y.time module

final exception y.time.NoBlockFound[source]

Bases: Exception

Raised when no block is found for a specified timestamp because the timestamp is in the future.

Parameters:

timestamp – The timestamp for which no block was found.

__init__(timestamp)[source]
Parameters:

timestamp (UnixTimestamp | datetime)

add_note()

Exception.add_note(note) – add a note to the exception

__final__ = True
y.time.check_node()[source]

Check if the Ethereum node is synced.

Raises:

y.exceptions.NodeNotSynced – If the node is not synced.

Return type:

None

Examples

>>> check_node()
y.time.closest_block_after_timestamp(timestamp, wait_for_block_if_needed=False)[source]

Get the closest block after a given timestamp.

Parameters:
  • timestamp (UnixTimestamp | datetime) – The timestamp to find the closest block after.

  • wait_for_block_if_needed (bool) – Whether to wait for a block if needed.

Returns:

The block number closest after the given timestamp.

Raises:

NoBlockFound – If no block is found after the timestamp.

Return type:

BlockNumber

Example

>>> closest_block_after_timestamp(1672531199)
12345678

See also

  • get_block_at_timestamp()

  • get_block_timestamp()

Module contents