erc_4626.classification
Documentation for eth_defi.erc_4626.classification Python module.
ERC-4626 vault type classification.
Used in vault discovery to figure out what kind of vaults we have autodetected
Use multicall based apporach to probe contracts
Functions
|
Create calls that call each vault address using multicall. |
|
Create a new vault instance class based on the detected features. |
|
Create any vault instance. |
|
Detect the ERC-4626 features of a vault smart contract. |
|
Based on multicall results, create the feature flags for the vault.. |
|
Perform multicalls against each vault address to extract the features of the vault smart contract. |
Classes
Results of a multicall probing to a vault address. |
- class VaultFeatureProbe
Bases:
objectResults of a multicall probing to a vault address.
Method generated by attrs for class VaultFeatureProbe.
- __init__(address, features)
Method generated by attrs for class VaultFeatureProbe.
- Parameters
address (eth_typing.evm.HexAddress) –
features (set[eth_defi.erc_4626.core.ERC4626Feature]) –
- Return type
None
- create_probe_calls(addresses, share_probe_amount=1000000, chain_id=None)
Create calls that call each vault address using multicall.
Because ERC standards are such a shit show, and nobody is using good interface standard, we figure out the vault type by probing it with various calls
Skips protocol-specific probes for protocols only deployed on certain chains (see
CHAIN_RESTRICTED_PROBESfor the list)
- Parameters
addresses (collections.abc.Iterable[eth_typing.evm.HexAddress]) – Iterable of vault contract addresses to probe.
share_probe_amount – Amount used for convertToShares() probe call.
chain_id (Optional[int]) – If provided, filters out probe calls for protocols that are not deployed on this chain. This reduces unnecessary RPC calls when scanning chains where certain protocols don’t exist. Protocols deployed on 3 or fewer chains have their probes skipped on other chains. If None, all probes are generated (no filtering).
- Return type
collections.abc.Iterable[eth_defi.event_reader.multicall_batcher.EncodedCall]
- create_vault_instance(web3, address, features=None, token_cache=None, auto_detect=False, default_block_identifier=None, require_denomination_token=False)
Create a new vault instance class based on the detected features.
Get a protocol-specific Python instance that can e.g. read the fees of the vault (not standardised).
See also -
detect_vault_features()to determine features for a vault address- Parameters
features (Optional[set[eth_defi.erc_4626.core.ERC4626Feature]]) –
Previously/manually extracted vault feature flags for the type.
Give empty set for generic ERC-4626 vault class.
auto_detect (bool) –
Auto-detect the vault protocol.
Very slow, do not use except in tutorials and scripts. Prefer to manually pass
feature.default_block_identifier (Optional[Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], eth_typing.evm.BlockNumber, eth_typing.evm.Hash32, eth_typing.encoding.HexStr, hexbytes.main.HexBytes, int]]) –
Override block identifier for on-chain metadata reads.
Set to
"latest"for freshly deployed vaults whose contracts do not exist at the safe-cached block number.require_denomination_token (bool) – If
True, accessingdenomination_tokenwill raiseRuntimeErrorwhen the on-chain lookup returnsNone.web3 (web3.main.Web3) –
address (Union[eth_typing.evm.HexAddress, str]) –
- Returns
None if the vault creation is not supported
- Return type
- create_vault_instance_autodetect(web3, vault_address, token_cache=None)
Create any vault instance.
Probes smart contract call first to identify what kind of vault we are dealing with
- Parameters
web3 (web3.main.Web3) –
vault_address (Union[eth_typing.evm.HexAddress, str]) –
- Return type
- detect_vault_features(web3, address, verbose=True)
Detect the ERC-4626 features of a vault smart contract.
Protocols: Harvest, Lagoon, etc.
Does support ERC-7540
Very slow, only use in scripts and tutorials.
Use to pass to
create_vault_instance()to get a correct Python proxy class for the vault institated.
Example:
features = detect_vault_features(web3, spec.vault_address, verbose=False) logger.info("Detected vault features: %s", features) vault = create_vault_instance( web3, spec.vault_address, features=features, )
- Parameters
verbose – Disable for command line scripts
web3 (web3.main.Web3) –
address (Union[eth_typing.evm.HexAddress, str]) –
- Return type
- identify_vault_features(address, calls, debug_text)
Based on multicall results, create the feature flags for the vault..
- Parameters
calls (dict[str, eth_defi.event_reader.multicall_batcher.EncodedCallResult]) – Call name -> result
address (eth_typing.evm.HexAddress) –
- Return type
- probe_vaults(chain_id, web3factory, addresses, block_identifier, max_workers=8, progress_bar_desc=None)
Perform multicalls against each vault address to extract the features of the vault smart contract.
- Returns
Iterator of what vault smart contract features we detected for each potential vault address
- Parameters
chain_id (int) –
web3factory (eth_defi.event_reader.web3factory.Web3Factory) –
addresses (list[eth_typing.evm.HexAddress]) –
block_identifier (Union[Literal['latest', 'earliest', 'pending', 'safe', 'finalized'], eth_typing.evm.BlockNumber, eth_typing.evm.Hash32, eth_typing.encoding.HexStr, hexbytes.main.HexBytes, int]) –
- Return type
collections.abc.Iterable[eth_defi.erc_4626.classification.VaultFeatureProbe]