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

HypersyncVaultDiscover

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.VaultDiscoveryBase

Autoscan 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

list[eth_typing.encoding.HexStr]

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

Parameters
  • start_block (int) –

  • end_block (int) –

Return type

hypersync.Query

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 receiver pagination error. We also cap by RPC height so follow-up vault probing does not request a future block from the JSON-RPC provider.

Parameters
  • start_block (int) – Inclusive scan start block.

  • end_block (int) – Requested inclusive scan end block.

Returns

End block that both Hypersync and RPC should be able to serve.

Return type

int

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 leads as PotentialVaultMatch objects. Mellow keeps decoded factory metadata on the lead for the later detection construction step.

Parameters
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

eth_defi.erc_4626.discovery_base.LeadScanReport

fetch_leads(start_block, end_block, display_progress=True, attempts=3, retry_sleep=30)

Synchronous wrapper around async lead scanning.

Parameters
  • display_progress – Show progress bar.

  • attempts – Deal with HyperSync flakiness by retrying the scan this many times.

  • retry_sleep – How long to sleep between retries.

  • start_block (int) –

  • end_block (int) –

Return type

eth_defi.erc_4626.discovery_base.LeadScanReport

async scan_potential_vaults(start_block, end_block, display_progress=True)

Identify smart contracts emitting 4626 like events.

Parameters
  • start_block (int) –

  • end_block (int) –

Return type

eth_defi.erc_4626.discovery_base.LeadScanReport

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]) –