y.prices package
Subpackages
- y.prices.dex package
- Subpackages
- Submodules
- y.prices.dex.genericamm module
- y.prices.dex.mooniswap module
- y.prices.dex.solidly module
SolidlyPool
SolidlyPool._decimals
SolidlyPool._scale
SolidlyPool.__eq__()
SolidlyPool.__init__()
SolidlyPool.__str__()
SolidlyPool.__build_name__
SolidlyPool.__decimals__
SolidlyPool.__factory__
SolidlyPool.__name__
SolidlyPool.__scale__
SolidlyPool.__symbol__
SolidlyPool.__token0__
SolidlyPool.__token1__
SolidlyPool.__tokens__
SolidlyPool.address
SolidlyPool.asynchronous
SolidlyPool.balance_of
SolidlyPool.balance_of_readable
SolidlyPool.build_name
SolidlyPool.check_liquidity
SolidlyPool.contract
SolidlyPool.decimals
SolidlyPool.deploy_block
SolidlyPool.factory
SolidlyPool.get_price
SolidlyPool.get_reserves
SolidlyPool.get_token_out
SolidlyPool.has_method
SolidlyPool.is_uniswap_pool
SolidlyPool.name
SolidlyPool.price
SolidlyPool.reserves
SolidlyPool.scale
SolidlyPool.symbol
SolidlyPool.token0
SolidlyPool.token1
SolidlyPool.tokens
SolidlyPool.total_supply
SolidlyPool.total_supply_readable
SolidlyPool.tvl
SolidlyRouter
SolidlyRouter.__eq__()
SolidlyRouter.__init__()
SolidlyRouter.__str__()
SolidlyRouter.pools_for_token()
SolidlyRouter.__build_name__
SolidlyRouter.__pools__
SolidlyRouter.address
SolidlyRouter.all_pools_for
SolidlyRouter.asynchronous
SolidlyRouter.build_name
SolidlyRouter.check_liquidity
SolidlyRouter.contract
SolidlyRouter.deepest_pool
SolidlyRouter.deepest_pool_for
SolidlyRouter.deepest_stable_pool
SolidlyRouter.deploy_block
SolidlyRouter.get_path_to_stables
SolidlyRouter.get_pool
SolidlyRouter.get_pools_for
SolidlyRouter.get_price
SolidlyRouter.get_quote
SolidlyRouter.get_routes_from_path
SolidlyRouter.has_method
SolidlyRouter.pair_for
SolidlyRouter.pools
SolidlyRouterBase
SolidlyRouterBase.__eq__()
SolidlyRouterBase.__init__()
SolidlyRouterBase.__str__()
SolidlyRouterBase.pools_for_token()
SolidlyRouterBase.__build_name__
SolidlyRouterBase.__pools__
SolidlyRouterBase.address
SolidlyRouterBase.all_pools_for
SolidlyRouterBase.asynchronous
SolidlyRouterBase.build_name
SolidlyRouterBase.check_liquidity
SolidlyRouterBase.contract
SolidlyRouterBase.deepest_pool
SolidlyRouterBase.deepest_pool_for
SolidlyRouterBase.deepest_stable_pool
SolidlyRouterBase.deploy_block
SolidlyRouterBase.get_path_to_stables
SolidlyRouterBase.get_pools_for
SolidlyRouterBase.get_price
SolidlyRouterBase.get_quote
SolidlyRouterBase.has_method
SolidlyRouterBase.pools
- y.prices.dex.velodrome module
NoReservesError
VelodromePool
VelodromePool._decimals
VelodromePool._scale
VelodromePool.__eq__()
VelodromePool.__init__()
VelodromePool.__str__()
VelodromePool.__build_name__
VelodromePool.__decimals__
VelodromePool.__factory__
VelodromePool.__name__
VelodromePool.__scale__
VelodromePool.__symbol__
VelodromePool.__token0__
VelodromePool.__token1__
VelodromePool.__tokens__
VelodromePool.address
VelodromePool.asynchronous
VelodromePool.balance_of
VelodromePool.balance_of_readable
VelodromePool.build_name
VelodromePool.check_liquidity
VelodromePool.contract
VelodromePool.decimals
VelodromePool.deploy_block
VelodromePool.factory
VelodromePool.get_price
VelodromePool.get_reserves
VelodromePool.get_token_out
VelodromePool.has_method
VelodromePool.is_stable
VelodromePool.is_uniswap_pool
VelodromePool.name
VelodromePool.price
VelodromePool.reserves
VelodromePool.scale
VelodromePool.symbol
VelodromePool.token0
VelodromePool.token1
VelodromePool.tokens
VelodromePool.total_supply
VelodromePool.total_supply_readable
VelodromePool.tvl
VelodromeRouterV2
VelodromeRouterV2.__eq__()
VelodromeRouterV2.__init__()
VelodromeRouterV2.__str__()
VelodromeRouterV2.pools_for_token()
VelodromeRouterV2.__build_name__
VelodromeRouterV2.__pools__
VelodromeRouterV2.address
VelodromeRouterV2.all_pools_for
VelodromeRouterV2.asynchronous
VelodromeRouterV2.build_name
VelodromeRouterV2.check_liquidity
VelodromeRouterV2.contract
VelodromeRouterV2.deepest_pool
VelodromeRouterV2.deepest_pool_for
VelodromeRouterV2.deepest_stable_pool
VelodromeRouterV2.default_factory
VelodromeRouterV2.deploy_block
VelodromeRouterV2.get_path_to_stables
VelodromeRouterV2.get_pool
VelodromeRouterV2.get_pools_for
VelodromeRouterV2.get_price
VelodromeRouterV2.get_quote
VelodromeRouterV2.get_routes_from_path
VelodromeRouterV2.has_method
VelodromeRouterV2.pool_for
VelodromeRouterV2.pools
is_contract()
- Module contents
- y.prices.eth_derivs package
- y.prices.lending package
- Submodules
- y.prices.lending.aave module
AaveMarketBase
AaveMarketBase.__contains__()
AaveMarketBase.__eq__()
AaveMarketBase.__init__()
AaveMarketBase.__str__()
AaveMarketBase.__atokens__
AaveMarketBase.__build_name__
AaveMarketBase.address
AaveMarketBase.asynchronous
AaveMarketBase.atokens
AaveMarketBase.build_name
AaveMarketBase.contains
AaveMarketBase.contract
AaveMarketBase.deploy_block
AaveMarketBase.get_reserve_data
AaveMarketBase.get_reserves
AaveMarketBase.has_method
AaveMarketBase.underlying
AaveMarketV1
AaveMarketV1.__contains__()
AaveMarketV1.__eq__()
AaveMarketV1.__init__()
AaveMarketV1.__str__()
AaveMarketV1.__atokens__
AaveMarketV1.__build_name__
AaveMarketV1.address
AaveMarketV1.asynchronous
AaveMarketV1.atokens
AaveMarketV1.build_name
AaveMarketV1.contains
AaveMarketV1.contract
AaveMarketV1.deploy_block
AaveMarketV1.get_reserve_data
AaveMarketV1.get_reserves
AaveMarketV1.has_method
AaveMarketV1.underlying
AaveMarketV2
AaveMarketV2.__contains__()
AaveMarketV2.__eq__()
AaveMarketV2.__init__()
AaveMarketV2.__str__()
AaveMarketV2.__atokens__
AaveMarketV2.__build_name__
AaveMarketV2.address
AaveMarketV2.asynchronous
AaveMarketV2.atokens
AaveMarketV2.build_name
AaveMarketV2.contains
AaveMarketV2.contract
AaveMarketV2.deploy_block
AaveMarketV2.get_reserve_data
AaveMarketV2.get_reserves
AaveMarketV2.has_method
AaveMarketV2.underlying
AaveMarketV3
AaveMarketV3.__contains__()
AaveMarketV3.__eq__()
AaveMarketV3.__init__()
AaveMarketV3.__str__()
AaveMarketV3.__atokens__
AaveMarketV3.__build_name__
AaveMarketV3.address
AaveMarketV3.asynchronous
AaveMarketV3.atokens
AaveMarketV3.build_name
AaveMarketV3.contains
AaveMarketV3.contract
AaveMarketV3.deploy_block
AaveMarketV3.get_reserve_data
AaveMarketV3.get_reserves
AaveMarketV3.has_method
AaveMarketV3.underlying
AaveRegistry
AaveRegistry.__contains__()
AaveRegistry.__init__()
AaveRegistry.__pools__
AaveRegistry.__pools_v1__
AaveRegistry.__pools_v2__
AaveRegistry.__pools_v3__
AaveRegistry.get_price
AaveRegistry.get_price_wrapped_v2
AaveRegistry.get_price_wrapped_v3
AaveRegistry.is_atoken
AaveRegistry.is_wrapped_atoken_v2
AaveRegistry.is_wrapped_atoken_v3
AaveRegistry.pool_for_atoken
AaveRegistry.pools
AaveRegistry.pools_v1
AaveRegistry.pools_v2
AaveRegistry.pools_v3
AaveRegistry.underlying
- y.prices.lending.compound module
CToken
CToken._decimals
CToken._scale
CToken.__eq__()
CToken.__init__()
CToken.__str__()
CToken.__build_name__
CToken.__decimals__
CToken.__name__
CToken.__scale__
CToken.__symbol__
CToken.__underlying__
CToken.address
CToken.asynchronous
CToken.balance_of
CToken.balance_of_readable
CToken.build_name
CToken.contract
CToken.decimals
CToken.deploy_block
CToken.exchange_rate
CToken.get_price
CToken.get_underlying_price
CToken.has_method
CToken.name
CToken.price
CToken.scale
CToken.symbol
CToken.total_supply
CToken.total_supply_readable
CToken.underlying
CToken.underlying_per_ctoken
Compound
Comptroller
Comptroller.__contains__()
Comptroller.__eq__()
Comptroller.__init__()
Comptroller.__str__()
Comptroller.__build_name__
Comptroller.__markets__
Comptroller.address
Comptroller.asynchronous
Comptroller.build_name
Comptroller.contract
Comptroller.deploy_block
Comptroller.has_method
Comptroller.markets
Comptroller.oracle
- y.prices.lending.ib module
- Module contents
- y.prices.stable_swap package
- Submodules
- y.prices.stable_swap.belt module
- y.prices.stable_swap.curve module
AddressProvider
AddressProvider.__await__()
AddressProvider.__eq__()
AddressProvider.__init__()
AddressProvider.__str__()
AddressProvider.__build_name__
AddressProvider.address
AddressProvider.asynchronous
AddressProvider.build_name
AddressProvider.contract
AddressProvider.deploy_block
AddressProvider.get_registry
AddressProvider.has_method
AddressProvider.identifiers
AddressProvider.loaded
AddressProviderEvents
AddressProviderEvents.obj_type
AddressProviderEvents.__aiter__()
AddressProviderEvents.__await__()
AddressProviderEvents.__init__()
AddressProviderEvents.__iter__()
AddressProviderEvents._objects_thru()
AddressProviderEvents.events()
AddressProviderEvents.filter()
AddressProviderEvents.logs()
AddressProviderEvents.objects()
AddressProviderEvents.sort()
AddressProviderEvents.wrap()
AddressProviderEvents.__wrapped__
AddressProviderEvents.addresses
AddressProviderEvents.bulk_insert
AddressProviderEvents.cache
AddressProviderEvents.executor
AddressProviderEvents.from_block
AddressProviderEvents.insert_to_db
AddressProviderEvents.is_asleep
AddressProviderEvents.is_reusable
AddressProviderEvents.materialized
AddressProviderEvents.provider
AddressProviderEvents.semaphore
AddressProviderEvents.to_block
AddressProviderEvents.topics
CurveEvents
CurveEvents.obj_type
CurveEvents.__aiter__()
CurveEvents.__await__()
CurveEvents.__init__()
CurveEvents.__iter__()
CurveEvents._objects_thru()
CurveEvents.events()
CurveEvents.filter()
CurveEvents.logs()
CurveEvents.objects()
CurveEvents.sort()
CurveEvents.wrap()
CurveEvents.__wrapped__
CurveEvents.addresses
CurveEvents.bulk_insert
CurveEvents.cache
CurveEvents.executor
CurveEvents.from_block
CurveEvents.insert_to_db
CurveEvents.is_asleep
CurveEvents.is_reusable
CurveEvents.materialized
CurveEvents.semaphore
CurveEvents.to_block
CurveEvents.topics
CurvePool
CurvePool._decimals
CurvePool._scale
CurvePool.__eq__()
CurvePool.__init__()
CurvePool.__str__()
CurvePool.__build_name__
CurvePool.__coins__
CurvePool.__coins_decimals__
CurvePool.__decimals__
CurvePool.__factory__
CurvePool.__get_underlying_coins__
CurvePool.__name__
CurvePool.__num_coins__
CurvePool.__scale__
CurvePool.__symbol__
CurvePool.address
CurvePool.asynchronous
CurvePool.balance_of
CurvePool.balance_of_readable
CurvePool.build_name
CurvePool.check_liquidity
CurvePool.coins
CurvePool.coins_decimals
CurvePool.contract
CurvePool.decimals
CurvePool.deploy_block
CurvePool.factory
CurvePool.get_balances
CurvePool.get_coin_index
CurvePool.get_dy
CurvePool.get_tvl
CurvePool.get_underlying_coins
CurvePool.has_method
CurvePool.name
CurvePool.num_coins
CurvePool.price
CurvePool.scale
CurvePool.symbol
CurvePool.total_supply
CurvePool.total_supply_readable
CurveRegistry
CurveRegistry.__init__()
CurveRegistry.__coin_to_pools__
CurveRegistry.__registry__
CurveRegistry.check_liquidity
CurveRegistry.coin_to_pools
CurveRegistry.get_factory
CurveRegistry.get_pool
CurveRegistry.get_price
CurveRegistry.get_price_for_underlying
CurveRegistry.identifiers
CurveRegistry.load_all
CurveRegistry.registry
Factory
Ids
Ids.__add__()
Ids.__and__()
Ids.__bool__()
Ids.__eq__()
Ids.__floordiv__()
Ids.__ge__()
Ids.__getattribute__()
Ids.__gt__()
Ids.__index__()
Ids.__invert__()
Ids.__le__()
Ids.__lshift__()
Ids.__lt__()
Ids.__mul__()
Ids.__or__()
Ids.__pow__()
Ids.__radd__()
Ids.__rand__()
Ids.__rlshift__()
Ids.__ror__()
Ids.__rrshift__()
Ids.__rshift__()
Ids.__rxor__()
Ids.__sizeof__()
Ids.__sub__()
Ids.__truediv__()
Ids.__xor__()
Ids.from_bytes()
Ids.to_bytes()
Ids.CryptoPool_Factory
Ids.CryptoSwap_Registry
Ids.Cryptopool_Factory
Ids.CurveStableswapFactoryNG
Ids.Curve_Tricrypto_Factory
Ids.Exchanges
Ids.Fee_Distributor
Ids.Main_Registry
Ids.Metapool_Factory
Ids.PoolInfo_Getters
Ids.crvUSD_Plain_Pools
Ids.crvUSD_Plain_Pools_deprecated_1
Ids.crvUSD_Plain_Pools_deprecated_2
Ids.denominator
Ids.numerator
Registry
RegistryEvents
RegistryEvents.obj_type
RegistryEvents.__aiter__()
RegistryEvents.__await__()
RegistryEvents.__init__()
RegistryEvents.__iter__()
RegistryEvents._objects_thru()
RegistryEvents.events()
RegistryEvents.filter()
RegistryEvents.logs()
RegistryEvents.objects()
RegistryEvents.sort()
RegistryEvents.wrap()
RegistryEvents.__wrapped__
RegistryEvents.addresses
RegistryEvents.bulk_insert
RegistryEvents.cache
RegistryEvents.executor
RegistryEvents.from_block
RegistryEvents.insert_to_db
RegistryEvents.is_asleep
RegistryEvents.is_reusable
RegistryEvents.materialized
RegistryEvents.registry
RegistryEvents.semaphore
RegistryEvents.to_block
RegistryEvents.topics
ADDRESS_PROVIDER
DED_POOLS
- y.prices.stable_swap.ellipsis module
- y.prices.stable_swap.froyo module
- y.prices.stable_swap.mstablefeederpool module
- y.prices.stable_swap.saddle module
- Module contents
- y.prices.tokenized_fund package
- Submodules
- y.prices.tokenized_fund.basketdao module
- y.prices.tokenized_fund.gelato module
- y.prices.tokenized_fund.piedao module
- y.prices.tokenized_fund.reserve module
- y.prices.tokenized_fund.tokensets module
TokenSet
TokenSet._decimals
TokenSet._scale
TokenSet.__eq__()
TokenSet.__init__()
TokenSet.__str__()
TokenSet.__build_name__
TokenSet.__decimals__
TokenSet.__name__
TokenSet.__scale__
TokenSet.__symbol__
TokenSet.address
TokenSet.asynchronous
TokenSet.balance_of
TokenSet.balance_of_readable
TokenSet.balances
TokenSet.build_name
TokenSet.components
TokenSet.contract
TokenSet.decimals
TokenSet.deploy_block
TokenSet.get_price
TokenSet.has_method
TokenSet.name
TokenSet.price
TokenSet.scale
TokenSet.symbol
TokenSet.total_supply
TokenSet.total_supply_readable
get_price
is_token_set
- Module contents
- y.prices.utils package
Submodules
y.prices.band module
- class y.prices.band.Band[source]
Bases:
ASyncGenericSingleton
A class to interact with the Band Protocol oracle on supported networks.
This class provides methods to check asset support and fetch prices using the Band Protocol oracle.
- Raises:
UnsupportedNetwork – If the Band Protocol is not supported on the current network.
Examples
>>> band = Band(asynchronous=True) >>> "0xaf319E5789945197e365E7f7fbFc56B130523B33" in band True
See also
- __contains__(asset)[source]
Check if an asset is supported by the Band Protocol on the current network.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress | Contract) – The asset address or contract to check.
- Return type:
Examples
>>> band = Band(asynchronous=True) >>> "0xaf319E5789945197e365E7f7fbFc56B130523B33" in band True
- __init__(*, asynchronous=False)[source]
Initialize the Band class.
- Parameters:
asynchronous (bool) – Whether to use asynchronous operations.
- Raises:
UnsupportedNetwork – If the Band Protocol is not supported on the current network.
- Return type:
None
Examples
>>> band = Band(asynchronous=True)
- __oracle__: HiddenMethodDescriptor[Self, Contract]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- get_price[source]
Get the price of an asset in terms of USDC using the Band Protocol oracle.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress) – The asset address to get the price for.
block (int | BlockNumber | None) – The block number to query the price at. Defaults to the latest block.
- Returns:
The price of the asset in terms of USDC, or None if the price cannot be fetched.
- Return type:
float | None
Examples
>>> band = Band(asynchronous=True) >>> price = await band.get_price("0xaf319E5789945197e365E7f7fbFc56B130523B33") >>> print(price) 1.0
y.prices.chainlink module
- class y.prices.chainlink.Chainlink[source]
Bases:
ASyncGenericBase
- __init__(*, asynchronous=True)[source]
Initialize the Chainlink class.
- Parameters:
asynchronous (bool) – Whether to use asynchronous operations.
- Raises:
UnsupportedNetwork – If Chainlink is not supported on the current network.
- Return type:
None
Examples
>>> chainlink = Chainlink(asynchronous=True)
- get_feed[source]
Get the feed for a specific asset.
- Args:
asset: The address of the asset.
- Examples:
>>> feed = await chainlink.get_feed("0xAsset") >>> print(feed)
- Returns:
The feed for the specified asset, or None if not found.
Since get_feed 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:
asset (str | HexBytes | AnyAddress | EthAddress)
- Return type:
Feed | None
- get_price[source]
Get the price of an asset at a specific block.
If the block is not specified, it uses the latest block.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the asset.
block (int | BlockNumber | None) – The block number to get the price for.
- Return type:
UsdPrice | None
Examples
>>> price = await chainlink.get_price("0xAsset", 12345678) >>> print(price)
- Returns:
The price of the asset in USD, or None if the price cannot be fetched.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
- Return type:
UsdPrice | None
See also
- has_feed[source]
Check if a feed exists for a specific asset.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address of the asset.
- Return type:
Examples
>>> has_feed = await chainlink.has_feed("0xAsset") >>> print(has_feed)
- Returns:
True if a feed exists for the specified asset, False otherwise.
- Parameters:
asset (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
- class y.prices.chainlink.Feed[source]
Bases:
object
- __init__(address, asset, start_block=0, *, asynchronous=False)[source]
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
asset (str | HexBytes | AnyAddress | EthAddress | Contract | int)
start_block (int)
asynchronous (bool)
- async get_price(block)[source]
Get the price of the asset at a specific block.
If the feed is stale, it returns None.
Examples
>>> feed = Feed("0xAddress", "0xAsset") >>> price = await feed.get_price(12345678) >>> print(price)
- address
- asset
- latest_answer
- latest_timestamp
- start_block
- class y.prices.chainlink.FeedsFromEvents[source]
Bases:
ProcessedEvents
[Feed
]When awaited, a list of all
Feed
will be returned.Example
>>> my_object = FeedsFromEvents(...) >>> all_contents = await my_object >>> isinstance(all_contents, list) True >>> isinstance(all_contents[0], Feed) True
- obj_type
alias of
_EventItem
- __aiter__(self) AsyncIterator[T]
Return an async iterator that yields
T
objects from the ASyncIterable.- Return type:
- __await__(self) Generator[Any, Any, List[T]]
Asynchronously iterate through the ASyncIterable and return all
T
objects.
- __init__(addresses, topics, *, asynchronous=True)[source]
Initialize a LogFilter instance.
- Parameters:
addresses – List of contract addresses to fetch logs from.
topics – List of event topics to filter logs by.
from_block – The starting block to fetch logs from.
chunk_size – The number of blocks to fetch in each chunk.
chunks_per_batch – The number of chunks to fetch in each batch.
semaphore – A semaphore for limiting concurrent requests.
executor – An executor for running tasks asynchronously.
is_reusable – Whether the filter is reusable.
verbose – Verbosity level for logging.
asynchronous (bool)
Examples
>>> log_filter = LogFilter(addresses=["0x1234..."], topics=["0x5678..."]) >>> logs = log_filter.logs(1000100) >>> print(logs)
- __iter__(self) Iterator[T]
Return an iterator that yields
T
objects from the ASyncIterable.Note
Synchronous iteration leverages
ASyncIterator
, which usesasyncio.BaseEventLoop.run_until_complete()
to fetch items.ASyncIterator.__next__()
raises aSyncModeInAsyncContextError
if the event loop is already running.If you encounter a
SyncModeInAsyncContextError
, you are likely working in an async codebase and should consider asynchronous iteration using__aiter__()
and__anext__()
instead.- Return type:
Iterator[T]
- events(to_block)
Get events up to a given block.
- Parameters:
to_block (int) – The ending block to fetch events to.
- Yields:
A decoded event.
- Return type:
Examples
>>> events = Events(addresses=["0x1234..."], topics=["0x5678..."]) >>> async for event in events.events(1000100): ... print(event)
- filter(self, function: ViewFn[T]) 'ASyncFilter[T]'
Filters the
T
objects yielded by the ASyncIterable based on a function.- Parameters:
function (Callable[[T], Awaitable[bool]] | Callable[[T], bool]) – A function that returns a boolean that indicates if an item should be included in the filtered result. Can be sync or async.
- Returns:
An instance of
ASyncFilter
that yields the filteredT
objects from the ASyncIterable.- Return type:
ASyncFilter[T]
- logs(to_block)
Get logs up to a given block.
- Parameters:
to_block (int | None) – The ending block to fetch logs to.
- Yields:
A raw log.
- Return type:
Examples
>>> log_filter = LogFilter(addresses=["0x1234..."], topics=["0x5678..."]) >>> logs = log_filter.logs(1000100) >>> print(logs)
- objects(to_block)
Get an
ASyncIterator
that yields all events up to a given block.- Parameters:
to_block (int) – The ending block to fetch events to.
- Returns:
An
ASyncIterator
that yields all included events.- Return type:
Examples
>>> processed_events = ProcessedEvents(addresses=["0x1234..."], topics=["0x5678..."]) >>> async for event in processed_events.objects(1000100): ... print(event)
- sort(self, *, key: SortKey[T] = None, reverse: bool = False) 'ASyncSorter[T]'
Sort the
T
objects yielded by the ASyncIterable.- Parameters:
key (optional) – A function of one argument that is used to extract a comparison key from each list element. If None, the elements themselves will be sorted. Defaults to None.
reverse (optional) – If True, the yielded elements will be sorted in reverse order. Defaults to False.
- Returns:
An instance of
ASyncSorter
that will yield theT
objects yielded from this ASyncIterable, but sorted.- Return type:
ASyncSorter[T]
- classmethod wrap(cls, wrapped: AsyncIterable[T]) 'ASyncIterable[T]'
Class method to wrap an AsyncIterable for backward compatibility.
- Parameters:
wrapped (AsyncIterable[T])
- Return type:
- __wrapped__
- addresses
- asynchronous
- property bulk_insert: Callable[[List[Log]], Awaitable[None]]
Get the function for bulk inserting logs into the database.
- Returns:
A function for bulk inserting logs.
Examples
>>> log_filter = LogFilter(addresses=["0x1234..."], topics=["0x5678..."]) >>> await log_filter.bulk_insert(logs)
- property cache: LogCache
- property executor: AsyncThreadPoolExecutor
- from_block
- property insert_to_db: Callable[[Log], None]
Get the function for inserting logs into the database.
- Raises:
NotImplementedError – If this method is not implemented in the subclass.
- is_reusable
- property materialized: List[T]
Synchronously iterate through the ASyncIterable and return all
T
objects.- Returns:
A list of the
T
objects yielded by the ASyncIterable.
- property semaphore: BlockSemaphore
- to_block
- topics
y.prices.convex module
- ASyncFunctiony.prices.convex.get_price(token_address: eth_typing.evm.ChecksumAddress, block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) y.datatypes.UsdPrice [source]
Get the price of a Convex LP token in USD.
This function retrieves the price of the underlying token mapped to the given Convex LP token address.
- Args:
token_address: The address of the Convex LP token. block: The block number at which to fetch the price. Defaults to the latest block. skip_cache: Whether to skip the cache when fetching the price. Defaults to the value of ENVS.SKIP_CACHE.
- Returns:
The price of the token in USD.
- Examples:
>>> await get_price("0x30D9410ED1D5DA1F6C8391af5338C93ab8d4035C") 1.23456789
- See Also:
y.prices.magic.get_price()
for more details on how the price is fetched.
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:
token_address (ChecksumAddress)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
- y.prices.convex.is_convex_lp(token_address)[source]
Check if a given token address is a Convex LP token.
- Parameters:
token_address (ChecksumAddress) – The address of the token to check.
- Returns:
True if the token is a Convex LP token, False otherwise.
- Return type:
Examples
>>> is_convex_lp("0x30D9410ED1D5DA1F6C8391af5338C93ab8d4035C") True
>>> is_convex_lp("0x0000000000000000000000000000000000000000") False
y.prices.gearbox module
- class y.prices.gearbox.DieselPool[source]
Bases:
ContractBase
- __eq__(_ContractBase__o)
Return self==value.
- __init__(self)
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
asynchronous (bool)
_deploy_block (int | None)
- Return type:
None
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- __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.
- __contract__: HiddenMethodDescriptor[Self, Contract]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __diesel_token__: HiddenMethodDescriptor[Self, ERC20]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __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.
- address
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- 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:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.deploy_block() 1234567
See also
contract_creation_block_async()
- exchange_rate[source]
- Parameters:
block (int | BlockNumber)
- Return type:
- has_method
Check if the contract has a specific method.
- Parameters:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- class y.prices.gearbox.Gearbox[source]
Bases:
ASyncGenericBase
- __init__(*, asynchronous=False)[source]
Initialize a Gearbox instance.
- Raises:
UnsupportedNetwork – If the current network is not Ethereum Mainnet.
- Parameters:
asynchronous (bool) – Whether to use asynchronous operations. Defaults to False.
Example
>>> from y.prices.gearbox import Gearbox >>> gearbox = Gearbox(asynchronous=True) >>> # This will raise an UnsupportedNetwork exception if not on Mainnet
- __registry__
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- get_price[source]
- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
skip_cache (bool)
- Return type:
- is_diesel_token[source]
- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
- Return type:
- pools[source]
Since pools is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Return type:
y.prices.magic module
- ASyncFunctiony.prices.magic.get_price(token_address: AnyAddressType, block: Block | None = None, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, ignore_pools: Tuple[Pool, ...] = (), silent: bool = False) UsdPrice | None [source]
- ASyncFunctiony.prices.magic.get_price(token_address: AnyAddressType, block: Block | None = None, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, ignore_pools: Tuple[Pool, ...] = (), silent: bool = False) UsdPrice
Get the price of a token in USD.
- Args:
token_address: The address of the token to price. block (optional): The block number at which to get the price. If None, uses the latest block. fail_to_None (optional): If True, return None instead of raising a
yPriceMagicError
on failure. Default False. skip_cache (optional): If True, bypass the cache and fetch the price directly. Defaults toENVS.SKIP_CACHE
. ignore_pools (optional): A tuple of pool addresses to ignore when fetching the price. silent (optional): If True, suppress error logging. Default False.- Returns:
The price of the token in USD, or None if the price couldn’t be determined and fail_to_None is True.
- Raises:
yPriceMagicError: If the price couldn’t be determined and fail_to_None is False.
- Note:
Don’t pass an int like 123 into token_address please, that’s just silly. - ypricemagic accepts ints to allow you to pass y.get_price(0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e)
so you can save yourself some keystrokes while testing in a console
(as opposed to y.get_price(“0x0bc529c00C6401aEF6D220BE8C6Ea1667F6Ad93e”))
Since get_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.
- ASyncFunctiony.prices.magic.get_prices(token_addresses: Iterable[AnyAddressType], block: Block | None = None, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) List[UsdPrice | None] [source]
- ASyncFunctiony.prices.magic.get_prices(token_addresses: Iterable[AnyAddressType], block: Block | None = None, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) List[UsdPrice]
Get prices for multiple tokens in USD.
You should use this function over
get_price()
where possible, it is better optimized for parallel execution.- Args:
token_addresses: An iterable of token addresses to price. block (optional): The block number at which to get the prices. Defaults to the latest block. fail_to_None (optional): If True, return None for tokens whose price couldn’t be determined. Default False. skip_cache (optional): If True, bypass the cache and fetch prices directly. Defaults to
ENVS.SKIP_CACHE
. silent (optional): If True, suppress progress bar and error logging. This kwarg is not currently implemented.- Returns:
A list of token prices in USD, in the same order as the input token_addresses.
Since get_prices is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.
- y.prices.magic.map_prices(token_addresses: Iterable[str | HexBytes | AnyAddress | EthAddress | Contract | int], block: int | BlockNumber, *, fail_to_None: Literal[True], skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) TaskMapping[str | HexBytes | AnyAddress | EthAddress | Contract | int, UsdPrice | None] [source]
- y.prices.magic.map_prices(token_addresses: Iterable[str | HexBytes | AnyAddress | EthAddress | Contract | int], block: int | BlockNumber, *, fail_to_None: bool = False, skip_cache: bool = ENVS.SKIP_CACHE, silent: bool = False) TaskMapping[str | HexBytes | AnyAddress | EthAddress | Contract | int, UsdPrice]
Map token addresses to their prices asynchronously.
- Parameters:
token_addresses – An iterable of token addresses to price.
block (optional) – The block number at which to get the prices. Defaults to latest block.
fail_to_None (optional) – If True, map to None for tokens whose price couldn’t be determined. Default False.
skip_cache (optional) – If True, bypass the cache and fetch prices directly. Defaults to
ENVS.SKIP_CACHE
.silent (optional) – If True, suppress error logging. Default False.
- Returns:
An
a_sync.TaskMapping
object mapping token addresses to their prices.
y.prices.one_to_one module
- ASyncFunctiony.prices.one_to_one.get_price(token_address: eth_typing.evm.ChecksumAddress, block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) y.datatypes.UsdPrice [source]
Get the USD price of a one-to-one token by mapping it to its corresponding token.
This function supports both synchronous and asynchronous execution.
- Args:
token_address: The address of the token to get the price for. block: The block number to get the price at. Defaults to the latest block. skip_cache: Whether to skip the cache when fetching the price. Defaults to the value of ENVS.SKIP_CACHE.
- Returns:
The USD price of the token.
- Examples:
Synchronous usage: >>> get_price(“0x4da27a545c0c5B758a6BA100e3a049001de870f5”)
Asynchronous usage: >>> await get_price(“0x4da27a545c0c5B758a6BA100e3a049001de870f5”, sync=False)
- See Also:
y.prices.magic.get_price()
for the underlying price fetching logic.
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:
token_address (ChecksumAddress)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
- y.prices.one_to_one.is_one_to_one_token(token_address)[source]
Check if a token address is a one-to-one token.
- Parameters:
token_address (ChecksumAddress) – The address of the token to check.
- Returns:
True if the token is a one-to-one token, False otherwise.
- Return type:
Examples
>>> is_one_to_one_token("0x4da27a545c0c5B758a6BA100e3a049001de870f5") True
>>> is_one_to_one_token("0x0000000000000000000000000000000000000000") False
y.prices.pendle module
- ASyncFunctiony.prices.pendle.get_lp_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress], block: Union[int, eth_typing.evm.BlockNumber] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) decimal.Decimal [source]
Calculates the price of a Pendle LP token.
- Args:
token: The address of the Pendle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching prices. Defaults to
ENVS.SKIP_CACHE
.- Returns:
The price of the LP token in USD.
- Example:
>>> price = get_lp_price("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23", block=14_000_000) >>> print(f"{price:.6f}") 1.234567 # The price of the Pendle LP token in USD
- Note:
This function retrieves the LP to asset rate using the Pendle Oracle contract and calculates the LP token price by multiplying the LP to asset rate by the asset’s price in USD.
- See Also:
get_tokens()
for retrieving the tokens in a Pendle LP token.
Since get_lp_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber)
skip_cache (bool)
- Return type:
- y.prices.pendle.get_tokens(lp_token)[source]
Retrieves the addresses of the tokens in a Pendle LP token.
This function is cached to improve performance for repeated calls.
- Parameters:
lp_token (str | HexBytes | AnyAddress | EthAddress) – The address of the Pendle LP token.
- Returns:
A tuple containing the addresses of the SY token, PT token, and YT token.
- Return type:
Example
>>> tokens = await get_tokens("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23") >>> print(tokens) ('0x...', '0x...', '0x...') # Addresses of SY, PT, and YT tokens
Note
The function returns the result of the readTokens method from the Pendle LP contract, which provides the addresses of the underlying tokens.
See also
is_pendle_lp()
for checking if a token is a Pendle LP token.
- ASyncFunctiony.prices.pendle.is_pendle_lp(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress) bool [source]
Determines if the given token address is a Pendle LP token.
- Args:
token: The address of the token to check.
- Returns:
True if the token is a Pendle LP token, False otherwise.
- Example:
>>> is_pendle = is_pendle_lp("0x1b92b5242301ce4a8c73cc3ef0d6dee33a3a5b23") >>> print(is_pendle) True
Since is_pendle_lp is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress)
- Return type:
y.prices.popsicle module
- ASyncFunctiony.prices.popsicle.get_balances(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>, _async_balance_objects: bool = False) Tuple[y.classes.common.WeiBalance, y.classes.common.WeiBalance] | None [source]
Retrieves the balances of the underlying tokens in a Popsicle Finance LP token.
- Args:
token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching balances. Defaults to
ENVS.SKIP_CACHE
. _async_balance_objects (optional): Whether to use asynchronous balance objects. Defaults to False.- Returns:
A tuple containing the balances of the two underlying tokens, or None if the balances cannot be determined.
- Example:
>>> balances = get_balances("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000) >>> if balances: ... balance0, balance1 = balances ... print(f"Token0 Balance: {balance0.readable}, Token1 Balance: {balance1.readable}") ... else: ... print("Balances could not be determined.") Token0 Balance: 1000.0, Token1 Balance: 2000.0
- Note:
If the contract probed has the correct method name but the method returns the wrong type for Popsicle, an exception “not enough values to unpack (expected 3, got 2)” will be caught, and the function will return None.
- See Also:
Since get_balances is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
skip_cache (bool)
_async_balance_objects (bool)
- Return type:
Tuple[WeiBalance, WeiBalance] | None
- ASyncFunctiony.prices.popsicle.get_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, *, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) y.datatypes.UsdPrice | None [source]
Calculates the price of a Popsicle Finance LP token.
- Args:
token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching prices. Defaults to
ENVS.SKIP_CACHE
.- Returns:
The price of the LP token in USD, or None if the price cannot be determined.
- Example:
>>> price = get_price("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000) >>> print(f"{price:.6f}") 1.234567 # The price of the Popsicle LP token in USD
- See Also:
Since get_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
UsdPrice | None
- ASyncFunctiony.prices.popsicle.get_tvl(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) y.datatypes.UsdValue | None [source]
Calculates the total value locked (TVL) in a Popsicle Finance LP token.
- Args:
token: The address of the Popsicle LP token. block (optional): The block number to query. Defaults to the latest block. skip_cache (optional): Whether to skip the cache when fetching TVL. Defaults to
ENVS.SKIP_CACHE
.- Returns:
The total value locked in the LP token in USD, or None if the TVL cannot be determined.
- Example:
>>> tvl = get_tvl("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf", block=14_000_000) >>> print(f"{tvl:.2f}") 1234567.89 # The TVL of the Popsicle LP token in USD
- See Also:
Since get_tvl is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
UsdValue | None
- ASyncFunctiony.prices.popsicle.is_popsicle_lp(token_address: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool [source]
Determines if the given token address is a Popsicle Finance LP token.
- Args:
token_address: The address of the token to check.
- Returns:
True if the token is a Popsicle LP token, False otherwise.
- Example:
>>> is_popsicle = is_popsicle_lp("0xd2C5A739ebfE3E00CFa88A51749d367d7c496CCf") >>> print(is_popsicle) True
Since is_popsicle_lp is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token_address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
y.prices.rkp3r module
- async y.prices.rkp3r.get_discount(block=None)[source]
Retrieve the discount for the RKP3R token from the contract.
- Parameters:
block (int | BlockNumber | None) – The block number to query the discount at.
- Returns:
The discount as a percentage.
- Return type:
Examples
>>> await get_discount() Decimal('5.0')
See also
- ASyncFunctiony.prices.rkp3r.get_price(address: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>) decimal.Decimal [source]
Get the price of the KP3R token and apply a discount to calculate the RKP3R token price.
This function retrieves the price of the KP3R token and applies a discount specific to the RKP3R token.
- Args:
address: The address of the token. block: The block number to query the price at. skip_cache: Whether to skip the cache when retrieving the price.
- Returns:
The discounted price of the RKP3R token.
- Examples:
>>> await get_price("0xEdB67Ee1B171c4eC66E6c10EC43EDBbA20FaE8e9") Decimal('123.45')
- See Also:
Since get_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
address (str | HexBytes | AnyAddress | EthAddress)
block (int | BlockNumber | None)
skip_cache (bool)
- Return type:
- y.prices.rkp3r.is_rkp3r(address)[source]
Check if the given address is the RKP3R token on the Ethereum Mainnet.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress) – The address to check.
- Returns:
True if the address is RKP3R on Mainnet, False otherwise.
- Return type:
Examples
>>> is_rkp3r("0xEdB67Ee1B171c4eC66E6c10EC43EDBbA20FaE8e9") True
>>> is_rkp3r("0x1cEB5cB57C4D4E2b2433641b95Dd330A33185A44") False
y.prices.solidex module
- ASyncFunctiony.prices.solidex.get_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Optional[int] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>)[source]
Retrieve the price of a given token.
This function first obtains the associated pool using the cached
_get_pool()
function and then callsmagic.get_price()
on that pool to retrieve the price.- Args:
token: The address of the token to get the price for. block: The block number to query. Defaults to the latest block. skip_cache: If True, skip using the cache while fetching price data.
- Examples:
>>> await get_price("0xTokenAddress") 123.45
- See Also:
_get_pool()
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:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | None)
skip_cache (bool)
- ASyncFunctiony.prices.solidex.is_solidex_deposit(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool [source]
Determine if a given token is a Solidex deposit token.
This function checks if the current network is Fantom and if the token contract has a pool attribute. It also verifies that the token name starts with “Solidex” and ends with “Deposit”.
- Args:
token: The address of the token to check.
- Returns:
True if the token is a Solidex deposit token, False otherwise.
- Examples:
>>> await is_solidex_deposit("0xTokenAddress") True
- See Also:
Since is_solidex_deposit is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
y.prices.synthetix module
- class y.prices.synthetix.Synthetix[source]
Bases:
ASyncGenericSingleton
A class to interact with the Synthetix protocol.
This class provides methods to interact with the Synthetix protocol, allowing users to get contract addresses, synths, and prices.
- Raises:
UnsupportedNetwork – If the Synthetix protocol is not supported on the current network.
Examples
>>> synthetix = Synthetix(asynchronous=True) >>> address = await synthetix.get_address("ProxyERC20") >>> print(address) <Contract object at 0x...>
- __address_resolver__: HiddenMethodDescriptor[Self, Contract]
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- __synths__
Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
The original docstring for
get()
is shown below:_ASyncPropertyDescriptorBase.get(self, instance: I, owner: Optional[Type[I]] = None) -> T Asynchronously retrieves the property value.
- Args:
instance: The instance from which the property is accessed. owner: The owner class of the property.
- Returns:
The property value.
- address_resolver[source]
Get the address resolver contract.
- Returns:
The address resolver contract.
Examples
>>> resolver = await synthetix.address_resolver >>> print(resolver) <Contract object at 0x...>
- get_address[source]
Get contract from Synthetix registry.
- Args:
name: The name of the contract to retrieve. block: The block number to query at. Defaults to the latest block.
- Returns:
The contract associated with the given name. If the contract is a proxy, it returns the target contract if available, otherwise the proxy itself.
- See Also:
- Examples:
>>> contract = await synthetix.get_address("ProxyERC20") >>> print(contract) <Contract object at 0x...>
Since get_address is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
name (str)
block (int | BlockNumber)
- Return type:
- get_currency_key[source]
Get the currency key for a given token.
- Args:
token: The token address to get the currency key for.
- Returns:
The currency key as a hex string, or None if not found.
- Examples:
>>> currency_key = await synthetix.get_currency_key("0x...") >>> print(currency_key) '0x...'
Since get_currency_key is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
HexStr | None
- get_price[source]
Get the price of a synth in dollars.
- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The token address to get the price for.
block (int | BlockNumber | None) – The block number to query at. Defaults to the latest block.
- Returns:
The price of the synth in USD, or None if the price is stale.
- Raises:
Exception – If an unexpected error occurs during the price retrieval.
- Return type:
UsdPrice | None
Examples
>>> price = await synthetix.get_price("0x...") >>> print(price) 1.23
See also
- is_synth[source]
Check if a token is a synth.
- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The token address to check.
- Returns:
True if the token is a synth, False if not.
- Raises:
Exception – If an unexpected error occurs during the check.
- Return type:
Examples
>>> is_synth = await synthetix.is_synth("0x...") >>> print(is_synth) True
See also
- y.prices.synthetix.encode_bytes(s)
y.prices.yearn module
- class y.prices.yearn.YearnInspiredVault[source]
Bases:
ERC20
Represents a vault token from Yearn or a similar protocol.
This class extends ERC20 and provides methods to interact with vaults, including fetching the underlying asset, share price, and token price.
- ASyncFunction_decimals(block: int | eth_typing.evm.BlockNumber | NoneType = None) int
used to fetch decimals at specific block
Since _decimals is an
ASyncFunctionAsyncDefault
, you can optionally pass sync=True or asynchronous=False to force it to run synchronously and return a value. Without either kwarg, it will return a coroutine for you to await.- Parameters:
block (int | BlockNumber | None)
- Return type:
- 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:
- __eq__(_ContractBase__o)
Return self==value.
- __init__(self)
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
asynchronous (bool)
_deploy_block (int | None)
- Return type:
None
- __str__()
Return the contract address as a string.
- Returns:
The contract address as a string.
- Return type:
- __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.
- __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.
- __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.
- __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.
- __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.
- address: Address
The contract address of the token.
- balance_of
Query the balance of the token for a given address at a specific block.
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int) – The address to query.
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The balance of the token held by address at block block.
- Return type:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.balance_of("0xabcdefabcdefabcdefabcdefabcdefabcdef") 500000000000000000000
- balance_of_readable
- Parameters:
address (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
- Return type:
- build_name
Get the contract’s build name.
- Returns:
The contract’s build name.
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.build_name 'MyContract'
- 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:
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:
- Returns:
A boolean indicating whether the contract has the method, or the response of the method call if return_response is True.
- Return type:
Examples
>>> contract = ContractBase("0x1234567890abcdef1234567890abcdef12345678") >>> await contract.has_method("name()") True
See also
- name
The token’s name.
- Returns:
The token’s name.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.name 'TokenName'
- price[source]
Calculates the USD price of the vault token.
- Parameters:
block (optional) – The block number to query. Defaults to the latest block.
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...]) – Pools to ignore when calculating the price.
skip_cache (bool) – Whether to skip the cache when fetching prices.
- Returns:
The USD price of the vault token.
- Return type:
Example
>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9") # yvUSDC >>> price = vault.price(block=14_000_000) >>> print(f"{price:.6f}") 1.096431 # The price of yvUSDC in USD
- scale
Get the scaling factor for the token.
- Returns:
The scaling factor for the token.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.scale 1000000000000000000
Calculates the share price of the vault.
- Parameters:
block (optional) – The block number to query. Defaults to the latest block.
- Returns:
The share price of the vault, or None if the vault’s total supply is zero.
- Raises:
CantFetchParam – If the share price cannot be fetched or calculated.
- Return type:
Decimal | None
Example
>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9") # yvUSDC >>> share_price = await vault.share_price(block=14_000_000) >>> print(f"{share_price:.6f}") 1.096431
- symbol
The token’s symbol.
- Returns:
The token’s symbol.
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.symbol 'TKN'
- total_supply
Get the total supply of the token.
- Parameters:
block (optional) – The block number to query. Defaults to latest block.
- Returns:
The total supply of the token.
- Return type:
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:
Examples
>>> token = ERC20("0x1234567890abcdef1234567890abcdef12345678") >>> await token.total_supply_readable() 1000.0
- underlying[source]
Fetches the underlying asset of the vault.
- Returns:
The underlying ERC20 token.
- Raises:
CantFetchParam – If the underlying asset cannot be determined.
- Special Cases:
Arbitrum USDL: For the specific address 0x57c7E0D43C05bCe429ce030132Ca40F6FA5839d7 on Arbitrum, it uses the ‘usdl()’ method to fetch the underlying token.
Beefy Vaults: For certain Beefy vaults (BeefyVaultV6Matic and BeefyVenusVaultBNB), it uses ‘wmatic()’ or ‘wbnb()’ methods respectively.
Reaper Vaults: For certain Reaper vaults, it checks for a ‘lendPlatform()’ method and then queries the ‘underlying()’ method on the lend platform contract.
Example
>>> vault = YearnInspiredVault("0x5f18C75AbDAe578b483E5F43f12a39cF75b973a9") # yvUSDC >>> underlying = vault.underlying() >>> underlying.address "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" # USDC address
- ASyncFunctiony.prices.yearn.get_price(token: Union[str, hexbytes.main.HexBytes, ~AnyAddress, brownie.convert.datatypes.EthAddress, brownie.network.contract.Contract, int], block: Union[int, eth_typing.evm.BlockNumber, NoneType] = None, skip_cache: bool = <EnvironmentVariable[name=`YPRICEMAGIC_SKIP_CACHE`, type=bool, default_value=False, current_value=False, using_default=True]>, ignore_pools: Tuple[Union[ForwardRef('UniswapV2Pool'), ForwardRef('CurvePool')], ...] = ()) y.datatypes.UsdPrice [source]
Since get_price is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
block (int | BlockNumber | None)
skip_cache (bool)
ignore_pools (Tuple[UniswapV2Pool | CurvePool, ...])
- Return type:
- ASyncFunctiony.prices.yearn.is_yearn_vault(token: str | hexbytes.main.HexBytes | AnyAddress | brownie.convert.datatypes.EthAddress | brownie.network.contract.Contract | int) bool [source]
Since is_yearn_vault is an
ASyncFunctionSyncDefault
, you can optionally pass sync=False or asynchronous=True to force it to return a coroutine. Without either kwarg, it will run synchronously.- Parameters:
token (str | HexBytes | AnyAddress | EthAddress | Contract | int)
- Return type:
List of methods which might be used to get the share price of a vault.
- y.prices.yearn.underlying_methods = ('token()(address)', 'underlying()(address)', 'native()(address)', 'want()(address)', 'input()(address)', 'asset()(address)', 'wmatic()(address)', 'wbnb()(address)', 'based()(address)')
List of methods which might be used to get the underlying asset of a vault.