uniswap_v3.events

Documentation for eth_defi.uniswap_v3.events Python module.

Uniswap v3 event reader.

Efficiently read Uniswap v3 from a blockchain.

Currently we are tracking these events:

  • PoolCreated

  • Swap

  • Mint

  • Burn

Functions

decode_burn(log)

Process burn event.

decode_mint(log)

Process mint event.

decode_pool_created(web3, log)

Process a pool created event.

decode_swap(log)

Process swap event.

fetch_events_to_csv(json_rpc_url, state[, ...])

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

get_event_mapping(web3)

Returns tracked event types and mapping.

Classes

TokenCache

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

class TokenCache

Bases: eth_defi.event_reader.logresult.LogContext

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

Do not do extra requests for already known tokens.

__init__()
decode_pool_created(web3, log)

Process a pool created event. The event signature is:

event PoolCreated(
    address indexed token0,
    address indexed token1,
    uint24 indexed fee,
    int24 tickSpacing,
    address pool
);
Parameters
Return type

dict

decode_swap(log)

Process swap event. The event signature is:

event Swap(
    address indexed sender,
    address indexed recipient,
    int256 amount0,
    int256 amount1,
    uint160 sqrtPriceX96,
    uint128 liquidity,
    int24 tick
);
Parameters

log (eth_defi.event_reader.logresult.LogResult) –

Return type

dict

decode_mint(log)

Process mint event. The event signature is:

event Mint(
    address sender,
    address indexed owner,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount,
    uint256 amount0,
    uint256 amount1
);
Parameters

log (eth_defi.event_reader.logresult.LogResult) –

Return type

dict

decode_burn(log)

Process burn event. The event signature is:

event Burn(
    address indexed owner,
    int24 indexed tickLower,
    int24 indexed tickUpper,
    uint128 amount,
    uint256 amount0,
    uint256 amount1
);
Parameters

log (eth_defi.event_reader.logresult.LogResult) –

Return type

dict

get_event_mapping(web3)

Returns tracked event types and mapping.

Currently we are tracking these events:
  • PoolCreated

  • Swap

  • Mint

  • Burn

Parameters

web3 (web3.main.Web3) –

Return type

dict

fetch_events_to_csv(json_rpc_url, state, start_block=12369621, end_block=12370621, output_folder='/tmp', max_workers=16, log_info=<built-in function print>, max_blocks_once=2000, max_threads=10)

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

Creates couple of CSV files with the event data:

  • /tmp/uniswap-v3-swap.csv

  • /tmp/uniswap-v3-poolcreated.csv

  • /tmp/uniswap-v3-mint.csv

  • /tmp/uniswap-v3-burn.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 12369621 (when Uniswap v3 factory was created on mainnet)

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

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

  • max_blocks_once – How many blocks your JSON-RPC provider allows for eth_getLogs call

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

Returns

Our web3 instance we constructed for reading events

Return type

eth_defi.provider.multi_provider.MultiProviderWeb3