enzyme.price_feed

Documentation for eth_defi.enzyme.price_feed Python module.

ChainLink price feed functions

Functions

fetch_price_feeds(deployment, start_block, ...)

Iterate configured price feeds

fetch_updated_price_feed(deployment, ...)

Iterate configured price feeds.

Classes

EnzymePriceFeed

High-level Python interface for Enzyme's ValueInterpreter price mechanism.

Exceptions

UnsupportedBaseAsset

Cannot calculate on-chain price using Enzyme's ValueInterpreter.

exception UnsupportedBaseAsset

Bases: Exception

Cannot 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: object

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")
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)

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)

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

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'))

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

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
Return type

Iterable[eth_defi.enzyme.price_feed.EnzymePriceFeed]

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
Return type

Dict[eth_typing.evm.HexAddress, eth_defi.enzyme.price_feed.EnzymePriceFeed]