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

add_event

Solidity event where this price feed was added

added_block_number

Block number when the feed was added

chainlink_aggregator

Resolve the Chainlink aggregator contract.

primitive_token

Access the non-indexed Solidity event arguments.

remove_event

Solidity event where this price feed was deleted

removed_block_number

Block number when the feed was removed.

web3

The connection we use to resolve on-chain info

deployment

The Enzyme deploymet for which this price feed is associated with

primitive

Token for which is price is for

aggregator

Used contract to get the price data

rate_asset

Do we nominate the price in USD or ETH

unit

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_latest_round_data()

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

unit: int

Decimal place divider for the price feed

For ETH this is 10**18

add_event: dict | None = None

Solidity event where this price feed was added

remove_event: dict | None = None

Solidity event where this price feed was deleted

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
Returns

Price feed instance

Return type

eth_defi.enzyme.price_feed.EnzymePriceFeed

static fetch_price_feed(deployment, token)[source]

Get a price feed for a particular token.

Parameters
Returns

Price feed instance

Raises

UnsupportedBaseAsset – In the case there is no registered price feed for token

Return type

eth_defi.enzyme.price_feed.EnzymePriceFeed

property primitive_token: eth_defi.token.TokenDetails

Access the non-indexed Solidity event arguments.

Resolve the Chainlink aggregator contract.

fetch_latest_round_data()[source]

Fetch the Chainlink round data from the underlying Chainlink price feed.

Return type

eth_defi.chainlink.round_data.ChainLinkLatestRoundData

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
Raises

UnsupportedBaseAsset – In the case the value interpreter has the price feed removed

Return type

decimal.Decimal

__init__(deployment, primitive, aggregator, rate_asset, unit, add_event=None, remove_event=None)
Parameters
Return type

None