aave_v3.events

Documentation for eth_defi.aave_v3.events Python module.

Aave v3 event reader.

Efficiently read Aave v3 from a blockchain.

Currently we are tracking these events:

  • ReserveDataUpdated

Functions

aave_v3_fetch_events_to_csv(json_rpc_url, ...)

Fetch all tracked Aave v3 events to CSV files for notebook analysis.

decode_reserve_data_updated(...)

Process a ReserveDataUpdated event.

get_event_mapping(web3)

Returns tracked event types and mapping.

Classes

TokenCache

Manage cache of token data when doing ReserveDataUpdated look-up.

class TokenCache

Bases: eth_defi.event_reader.logresult.LogContext

Manage cache of token data when doing ReserveDataUpdated look-up.

Do not do extra requests for already known tokens.

__init__()
get_event_mapping(web3)

Returns tracked event types and mapping.

Currently we are tracking these events:
  • ReserveDataUpdated(address indexed reserve, uint256 liquidityRate, uint256 stableBorrowRate, uint256 variableBorrowRate, uint256 liquidityIndex, uint256 variableBorrowIndex)

Parameters

web3 (web3.main.Web3) –

Return type

dict

decode_reserve_data_updated(aave_network_name, log, aave_version)

Process a ReserveDataUpdated event.

Note

Both Aave v2 and v3 have this same event, so we use the lending pool smart contract to filter out the correct events.

The event signature is:

# topic0: signature 0x804c9b842b2748a22bb64b345453a3de7ca54a6ca45ce00d415894979e22897a
event ReserveDataUpdated(
    address indexed reserve,    # topic1
    uint256 liquidityRate,      # data0
    uint256 stableBorrowRate,   # data1
    uint256 variableBorrowRate, # data2
    uint256 liquidityIndex,     # data3
    uint256 variableBorrowIndex # data4
);
Parameters
Return type

dict

aave_v3_fetch_events_to_csv(json_rpc_url, state, aave_network_name, start_block, end_block, output_folder='/tmp', max_workers=16, log_info=<built-in function print>, reorg_monitor=None)

Fetch all tracked Aave v3 events to CSV files for notebook analysis.

Creates couple of CSV files with the event data:

  • /tmp/aave-v3-{aave_network_name.lower()}-reservedataupdated.csv

A progress bar and estimation on the completion is rendered for console / Jupyter notebook using tqdm.

The scan be resumed using state storage to retrieve the last scanned block number from the previous round. However, the mechanism here is no perfect and only good for notebook use - for advanced persistent usage like database backed scans, please write your own scan loop using proper transaction management.

Note

Any Ethereum address is lowercased in the resulting dataset and is not checksummed.

Parameters
  • json_rpc_url (str) – JSON-RPC URL

  • start_block (int) – First block to process (inclusive), default is block xxx (when Aave v3 xxx was created on mainnet)

  • end_block (int) – Last block to process (inclusive), default is block xxx (1000 block after default start block)

  • aave_network_name (str) – Network name, e.g. ‘Polygon’

  • state (eth_defi.event_reader.state.ScanState) – Store the current scan state, so we can resume

  • output_folder (str) – Folder to contain output CSV files, default is /tmp folder

  • max_workers (int) – How many threads to allocate for JSON-RPC IO. You can increase your EVM node output a bit by making a lot of parallel requests, until you exhaust your nodes IO capacity. Experiement with different values and see how your node performs.

  • log_info (Callable) – Which function to use to output info messages about the progress

  • reorg_monitor (eth_defi.event_reader.reorganisation_monitor.ReorganisationMonitor | None) –