Basepool Events
- Pull basepool events from LTP
- To run locally, download notebook from SYS-Labs repos
import json
from pachira import *
test_net_addresses_path = '/Users/ian_moore/repos/indexeddefi/script/deployments/TestnetStage1-addresses.json'
f = open(test_net_addresses_path)
test_net_addresses = json.load(f)
base_pool_addr = test_net_addresses['basePool']
connect = ConnectW3(Net.LOCALHOST)
connect.apply()
abi = ABILoad(Platform.PACHIRA, JSONContract.IUniswapV2Pair)
(1) Extract Mint Events
rEvents = RetrieveEvents(connect, abi)
dict_events = rEvents.apply(EventType.MINT, base_pool_addr)
mint at block:4 tx:0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f2717995fb70c0d7a6249
mint at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
.
dict_events
{0: {'chain': 'localhost',
'contract': 'iuniswapv2pair',
'type': 'mint',
'platform': 'pachira',
'address': '0x387e3656de052275554f8d8b78c4b1a9b088345c',
'tx_hash': '0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f2717995fb70c0d7a6249',
'blk_num': 4,
'timestamp': 1725384111,
'details': {'web3_type': web3._utils.datatypes.Mint,
'token0': '0x088Ba56A560dfF690a1C6feF26394F4C03821c4f',
'token1': '0x0165878A594ca255338adfa4d48449f69242Eb8F',
'amount0In': 100000000000000000000000,
'amount1Out': 100000000000000000000000}},
1: {'chain': 'localhost',
'contract': 'iuniswapv2pair',
'type': 'mint',
'platform': 'pachira',
'address': '0x387e3656de052275554f8d8b78c4b1a9b088345c',
'tx_hash': '0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c',
'blk_num': 6,
'timestamp': 1725384132,
'details': {'web3_type': web3._utils.datatypes.Mint,
'token0': '0x088Ba56A560dfF690a1C6feF26394F4C03821c4f',
'token1': '0x0165878A594ca255338adfa4d48449f69242Eb8F',
'amount0In': 25,
'amount1Out': 24}}}
df_events = rEvents.to_dataframe(dict_events)
df_events
chain | contract | type | platform | address | tx_hash | blk_num | timestamp | details | |
---|---|---|---|---|---|---|---|---|---|
0 | localhost | iuniswapv2pair | mint | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f... | 4 | 1725384111 | {'web3_type': <class 'web3._utils.datatypes.Mi... |
1 | localhost | iuniswapv2pair | mint | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Mi... |
(2) Extract Swap Events
rEvents = RetrieveEvents(connect, abi)
dict_events = rEvents.apply(EventType.SWAP, base_pool_addr)
swap at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
.
df_events = rEvents.to_dataframe(dict_events)
df_events
chain | contract | type | platform | address | tx_hash | blk_num | timestamp | details | |
---|---|---|---|---|---|---|---|---|---|
0 | localhost | iuniswapv2pair | swap | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Sw... |
(3) Extract Burn Events
rEvents = RetrieveEvents(connect, abi)
dict_events = rEvents.apply(EventType.BURN, base_pool_addr)
.
df_events = rEvents.to_dataframe(dict_events)
df_events
(4) Extract Sync Events (Price Oracle)
rEvents = RetrieveEvents(connect, abi)
dict_events = rEvents.apply(EventType.SYNC, base_pool_addr)
sync at block:4 tx:0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f2717995fb70c0d7a6249
sync at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
sync at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
sync at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
.
df_events = rEvents.to_dataframe(dict_events)
df_events
chain | contract | type | platform | address | tx_hash | blk_num | timestamp | details | |
---|---|---|---|---|---|---|---|---|---|
0 | localhost | iuniswapv2pair | sync | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f... | 4 | 1725384111 | {'web3_type': <class 'web3._utils.datatypes.Sy... |
1 | localhost | iuniswapv2pair | sync | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Sy... |
2 | localhost | iuniswapv2pair | sync | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Sy... |
3 | localhost | iuniswapv2pair | sync | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Sy... |
(5) Extract Transfer Events
rEvents = RetrieveEvents(connect, abi)
dict_events = rEvents.apply(EventType.TRANSFER, base_pool_addr)
transfer at block:3 tx:0xb8297fbe177f1c7fb28f0b9023b56734ada6cd26ce44799b20a01a42c6b34d91
transfer at block:4 tx:0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f2717995fb70c0d7a6249
transfer at block:4 tx:0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f2717995fb70c0d7a6249
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
transfer at block:6 tx:0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e89e7bb8a65a63eb904b2c
.
df_events = rEvents.to_dataframe(dict_events)
df_events
chain | contract | type | platform | address | tx_hash | blk_num | timestamp | details | |
---|---|---|---|---|---|---|---|---|---|
0 | localhost | iuniswapv2pair | transfer | pachira | 0x0165878a594ca255338adfa4d48449f69242eb8f | 0xb8297fbe177f1c7fb28f0b9023b56734ada6cd26ce44... | 3 | 1725384110 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
1 | localhost | iuniswapv2pair | transfer | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f... | 4 | 1725384111 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
2 | localhost | iuniswapv2pair | transfer | pachira | 0x0165878a594ca255338adfa4d48449f69242eb8f | 0x5b6bb5937981e4642696449ed6ca25474bf87dfe8d3f... | 4 | 1725384111 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
3 | localhost | iuniswapv2pair | transfer | pachira | 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
4 | localhost | iuniswapv2pair | transfer | pachira | 0xfaefac1c9e8af3a030857c4e61066f0a510253af | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
5 | localhost | iuniswapv2pair | transfer | pachira | 0x9fe46736679d2d9a65f0992f2272de9f3c7fa6e0 | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
6 | localhost | iuniswapv2pair | transfer | pachira | 0xfaefac1c9e8af3a030857c4e61066f0a510253af | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
7 | localhost | iuniswapv2pair | transfer | pachira | 0x387e3656de052275554f8d8b78c4b1a9b088345c | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |
8 | localhost | iuniswapv2pair | transfer | pachira | 0x0165878a594ca255338adfa4d48449f69242eb8f | 0xcd394a390bd2f1d5fce86d583a7bdaa54a74647642e8... | 6 | 1725384132 | {'web3_type': <class 'web3._utils.datatypes.Tr... |