web3.py – How to Fetch All Transactions of a Liquidity Pool on CRONOS Chain with Web3.py

web3.py

How to you fetch all transactions (swap, mint, burn) of a Liquidity Pool? I searched up and down found this. However, it's making a REST call to Polygon API. Is there a way to do this strictly using web3.py?

For CRONOS chain, I can write this:

cronos_mainnet_rpc = "https://evm.cronos.org"
w3 = Web3(Web3.HTTPProvider(cronos_mainnet_rpc))

latest_block = w3.eth.getBlock('latest')
latest_block_number = latest_block['number']
for block_number in range(latest_block_number):
    this_block = w3.eth.getBlock(block_number)
    for trx_hash in this_block.transactions:
        try:
            trx = w3.eth.getTransaction(trx_hash)
            print(trx)
        except:
            print("oops")

However,

  1. When I look at fields from trx, I cannot find the fields I'm familiar with that identifies for example a swap transaction:
  • Token in
  • token out
  • amount in and out
  • Sender and Recepient address
    ..etc
    (See picture below)

See this post for details.

  1. Specifically I am searching for swap transactions in SINGLE/USDC pool on VVS:
    https://vvs.finance/info/farm/0x0fbab8a90cac61b481530aad3a64fe17b322c25d
    I cannot filter "trx" by pool contract address "0x0fbab8a90cac61b481530aad3a64fe17b322c25d"

Futher checking the LP contract I cannot find any function that's relevant https://cronos.org/explorer/address/0x0fBAB8A90CAC61b481530AAd3a64fE17B322C25d/transactions

enter image description here
I also checked VVSRouter contract "0x145863Eb42Cf62847A6Ca784e6416C1682b1b2Ae", no joy.

This article is close to what I need but does not cover fetching historical swap transactions.

Best Answer

The example from web3 doc "Advanced example: Fetching all token transfer events" worked. A few modifications on top of original example here, so one can filter on these criteria, which are quite common:

a) Another token address

b) cutoff <-- But I think this wasn't done very elegantly (Precisely) in the mods.

c) Particular events only (For example Transfer)

The core of this query is how to fetch transactions, not how to parse them. For parsing of transactions into common fields needed, reference this instead.