enzyme.price_feed
Documentation for eth_defi.enzyme.price_feed Python module.
ChainLink price feed functions
Functions
|
Iterate configured price feeds |
|
Iterate configured price feeds. |
Classes
High-level Python interface for Enzyme's ValueInterpreter price mechanism. |
Exceptions
Cannot calculate on-chain price using Enzyme's ValueInterpreter. |
- exception UnsupportedBaseAsset
Bases:
ExceptionCannot calculate on-chain price using Enzyme’s ValueInterpreter.
Likely the price feed was removed.
- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note()
Exception.add_note(note) – add a note to the exception
- with_traceback()
Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.
- class EnzymePriceFeed
Bases:
objectHigh-level Python interface for Enzyme’s ValueInterpreter price mechanism.
Uses ValueInterpreter methods to calculate on-chain price for supported assets
Note
Enzyme price feeds are dynamic. They can be remvoed by Enzyme’s risk commitee any time.
Example:
# Print out the price Enzyme sees for a token usdc = fetch_erc20_details(web3, POLYGON_DEPLOYMENT["usdc"]) price = feed.calculate_current_onchain_price(usdc) print(f" {feed.primitive_token.symbol}, current price is {price:,.4f} USDC")
- deployment: eth_defi.enzyme.deployment.EnzymeDeployment
The Enzyme deploymet for which this price feed is associated with
- primitive: eth_typing.evm.HexAddress
Token for which is price is for
- aggregator: eth_typing.evm.HexAddress
Used contract to get the price data
- rate_asset: eth_defi.enzyme.deployment.RateAsset
Do we nominate the price in USD or ETH
- property web3: web3.main.Web3
The connection we use to resolve on-chain info
- property added_block_number: eth_typing.evm.BlockNumber
Block number when the feed was added
- property removed_block_number: Optional[eth_typing.evm.BlockNumber]
Block number when the feed was removed.
- Returns
None if the feed still active
- static wrap(deployment, event)
Wrap the raw Solidity event to a high-level Python interface.
- Parameters
web3 – Web3 connection used for further JSON-RPC API calls
event (dict) – PrimitiveAdded Solidity event
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) –
- Returns
Price feed instance
- Return type
- static fetch_price_feed(deployment, token)
Get a price feed for a particular token.
- Parameters
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) – Enzyme deployment.
token (eth_defi.token.TokenDetails) – Which token we are interested in.
- Returns
Price feed instance
- Raises
UnsupportedBaseAsset – In the case there is no registered price feed for token
- Return type
- property primitive_token: eth_defi.token.TokenDetails
Access the non-indexed Solidity event arguments.
- property chainlink_aggregator: web3.contract.contract.Contract
Resolve the Chainlink aggregator contract.
- fetch_latest_round_data()
Fetch the Chainlink round data from the underlying Chainlink price feed.
- calculate_current_onchain_price(quote, amount=Decimal('1'))
Get the primitive asset price for this price feed.
Use Enzyme’s ValueInterpreter to calculate a price in ETH or USD.
See calcCanonicalAssetsTotalValue in ValueInterpreter
See __calcConversionAmount in ChainlinkPriceFeedMixin
- Parameters
quote (eth_defi.token.TokenDetails) – Which quote token we want to use for the valuation
amount (decimal.Decimal) –
Amount to valuate.
If not given assume 1 token of primitive.
- Raises
UnsupportedBaseAsset – In the case the value interpreter has the price feed removed
- Return type
- __init__(deployment, primitive, aggregator, rate_asset, unit, add_event=None, remove_event=None)
- Parameters
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) –
primitive (eth_typing.evm.HexAddress) –
aggregator (eth_typing.evm.HexAddress) –
rate_asset (eth_defi.enzyme.deployment.RateAsset) –
unit (int) –
add_event (dict | None) –
remove_event (dict | None) –
- Return type
None
- fetch_price_feeds(deployment, start_block, end_block, read_events)
Iterate configured price feeds
Uses eth_getLogs ABI
Read both deposits and withdrawals in one go
Serial read
Slow over long block ranges
See ComptrollerLib.sol
Warning
This function does not update status for removed price feeds. Please use
fetch_updated_price_feed().- Parameters
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) –
start_block (int) –
end_block (int) –
read_events (eth_defi.event_reader.reader.Web3EventReader) –
- Return type
- fetch_updated_price_feed(deployment, start_block, end_block, read_events)
Iterate configured price feeds.
Deal dynamic price feed adds and deletes
Uses eth_getLogs ABI
Read both deposits and withdrawals in one go
Serial read
Slow over long block ranges
See ComptrollerLib.sol
- Returns
Token address -> primitive data map
- Parameters
deployment (eth_defi.enzyme.deployment.EnzymeDeployment) –
start_block (int) –
end_block (int) –
read_events (eth_defi.event_reader.reader.Web3EventReader) –
- Return type
Dict[eth_typing.evm.HexAddress, eth_defi.enzyme.price_feed.EnzymePriceFeed]