erc_4626.hypersync_discovery
Documentation for eth_defi.erc_4626.hypersync_discovery Python module.
Find ERC-4626 vaults onchain using HyperSync.
Use HyperSync’s index to quickly get ERC-4626 identification events from the chain
We do not use raw JSON-RPC, because Etheruem JSON-RPC is badly designed piece of crap for reading data
Use tons of heurestics to figure out what’s going on with vaults
This is because ERC-4626, like many other ERC standards, are very poorly designed, lacking proper identification events and interface introspection
Classes
Autoscan the chain for 4626 vaults. |
Exceptions
- exception HypersyncCrappedOut
Bases:
Exception- __init__(*args, **kwargs)
- __new__(**kwargs)
- add_note(note, /)
Add a note to the exception
- with_traceback(tb, /)
Set self.__traceback__ to tb and return self.
- class HypersyncVaultDiscover
Bases:
eth_defi.erc_4626.discovery_base.VaultDiscoveryBaseAutoscan the chain for 4626 vaults.
First build map of potential contracts using
scan_potential_vaults()Then probe given contracts and determine their ERC-4626 vault properties
See scan-erc_4626_vaults for usage.
Create vault discover.
- Parameters
web3 – Current process web3 connection
web3factory – Used to initialise connection in created worker threads/processes
client – HyperSync client used to scan lead event data
max_workers – How many worker processes use in multicall probing
- Parma recv_timeout
Hypersync core reading loop timeout.
- __init__(web3, web3factory, client, max_workers=8, recv_timeout=90.0)
Create vault discover.
- Parameters
web3 (web3.main.Web3) – Current process web3 connection
web3factory (eth_defi.event_reader.web3factory.Web3Factory) – Used to initialise connection in created worker threads/processes
client (hypersync.HypersyncClient) – HyperSync client used to scan lead event data
max_workers (int) – How many worker processes use in multicall probing
recv_timeout (float) –
- Parma recv_timeout
Hypersync core reading loop timeout.
- get_topic_signatures()
Get topic signatures that can seed vault leads.
Find contracts emitting these events
Later prod these contracts to see which of them are proper vaults
A deposit event is enough to create a lead. Some large vaults have not emitted withdrawal events yet because funds are still locked or the vault is in a pre-deposit phase.
Also includes protocol-specific vault flow events
- Return type
- build_query(start_block, end_block)
Create HyperSync query that extracts all potential lead events from the chain.
See example here: https://github.com/enviodev/hypersync-client-python/blob/main/examples/all-erc20-transfers.py
- clip_end_block_to_available_height(start_block, end_block)
Clip scan end block to heights available from RPC and Hypersync.
Hypersync may lag the chain head by a few blocks. Asking it to stream over that head gap can fail with an
inner receiverpagination error. We also cap by RPC height so follow-up vault probing does not request a future block from the JSON-RPC provider.
- process_log(report, leads, topic_map, chain, log, block_timestamp, seen)
Process one Hypersync log into the shared lead map.
Both ERC-4626-like event leads and Mellow factory leads are written to
leadsasPotentialVaultMatchobjects. Mellow keeps decoded factory metadata on the lead for the later detection construction step.- Parameters
report (eth_defi.erc_4626.discovery_base.LeadScanReport) – Mutable scan report.
leads (dict[eth_typing.evm.HexAddress, eth_defi.erc_4626.discovery_base.PotentialVaultMatch]) – Mutable lead map keyed by lower-case vault address.
topic_map (dict[str, object]) – ERC-4626-style event topic classification map.
chain (int) – EVM chain id.
log (hypersync.Log) – Hypersync log.
block_timestamp – Naive UTC timestamp for the log block.
seen (set[eth_typing.evm.HexAddress]) – Addresses already counted as matched candidates.
- Returns
None.
- Return type
None
- fetch_log_timestamp(block_lookup, log)
Resolve a Hypersync log timestamp from the batch block lookup.
- Parameters
block_lookup (dict) –
log (hypersync.Log) –
- scan_vaults(start_block, end_block, display_progress=True, hardcoded_lead_sources=None)
Scan vaults using a Hypersync-safe head block.
- Parameters
- Return type
- fetch_leads(start_block, end_block, display_progress=True, attempts=3, retry_sleep=30)
Synchronous wrapper around async lead scanning.
- Parameters
- Return type
- async scan_potential_vaults(start_block, end_block, display_progress=True)
Identify smart contracts emitting 4626 like events.
Scan all event matches using HyperSync
See stream() example here: https://github.com/enviodev/hypersync-client-python/blob/main/examples/all-erc20-transfers.py
- Parameters
- Return type
- seed_existing_leads(leads)
Seed existing leads to continue the scan where we were left last time.
- Parameters
leads (dict[eth_typing.evm.HexAddress, eth_defi.erc_4626.discovery_base.PotentialVaultMatch]) –