EnzymePriceFeed
Documentation for eth_defi.enzyme.price_feed.EnzymePriceFeed Python class.
- class EnzymePriceFeed[source]
High-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")
Attributes summary
Solidity event where this price feed was added
Block number when the feed was added
Resolve the Chainlink aggregator contract.
Access the non-indexed Solidity event arguments.
Solidity event where this price feed was deleted
Block number when the feed was removed.
The connection we use to resolve on-chain info
The Enzyme deploymet for which this price feed is associated with
Token for which is price is for
Used contract to get the price data
Do we nominate the price in USD or ETH
Decimal place divider for the price feed
Methods summary
__init__
(deployment, primitive, aggregator, ...)calculate_current_onchain_price
(quote[, amount])Get the primitive asset price for this price feed.
Fetch the Chainlink round data from the underlying Chainlink price feed.
fetch_price_feed
(deployment, token)Get a price feed for a particular token.
wrap
(deployment, event)Wrap the raw Solidity event to a high-level Python interface.
- 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)[source]
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)[source]
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()[source]
Fetch the Chainlink round data from the underlying Chainlink price feed.
- calculate_current_onchain_price(quote, amount=Decimal('1'))[source]
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) –
- Return type
None