-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlp_events.py
73 lines (57 loc) · 2.36 KB
/
lp_events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import json
import pandas as pd
import web3
from pyaml_env import parse_config
from acx.abis import getABI
from acx.data.tokens import SYMBOL_TO_CHAIN_TO_ADDRESS
from acx.utils import findEvents
if __name__ == "__main__":
# Load parameters
params = parse_config("parameters.yaml")
nBlocks = params["lp"]["n_blocks"]
# Connect to RPC node
provider = web3.Web3.HTTPProvider(
params["rpc_node"]["mainnet"],
request_kwargs={"timeout": 60}
)
w3 = web3.Web3(provider)
# -------------------------------------
# V1 Liquidity Add/Remove
# -------------------------------------
v1EndBlock = params["lp"]["v1_end_block"]
v1Transfers = {}
for token in params["lp"]["tokens"]:
# Get information about specific BridgePool
# NOTE: We have to start with `bridgeInfo["first_block"]` because
# we need to track liquidity deposits/removals that occurred
# prior to the first block we track for...
bridgeInfo = params["across"]["v1"]["mainnet"]["bridge"][token]
poolAddress = bridgeInfo["address"]
v1FirstBlock = bridgeInfo["first_block"]
v1EndBlock = params["lp"]["v1_end_block"]
# Create BridgePool object
pool = w3.eth.contract(address=poolAddress, abi=getABI("BridgePool"))
# Track transfer events
v1Transfers[token] = findEvents(
w3, pool.events.Transfer, v1FirstBlock, v1EndBlock,
nBlocks, {}, True
)
with open("raw/v1Transfers.json", "w") as f:
json.dump(v1Transfers, f)
# -------------------------------------
# V2 Liquidity Add/Remove
# -------------------------------------
hubInfo = params["across"]["v2"]["mainnet"]["hub"]
v2FirstBlock = hubInfo["first_block"]
v2EndBlock = params["lp"]["v2_end_block"]
hub = w3.eth.contract(address=hubInfo["address"], abi=getABI("HubPool"))
v2Transfers = {}
for token in params["lp"]["tokens"]:
lpTokenAddress = hub.functions.pooledTokens(SYMBOL_TO_CHAIN_TO_ADDRESS[token][1]).call()[0]
lpToken = w3.eth.contract(address=lpTokenAddress, abi=getABI("ERC20"))
v2Transfers[token] = findEvents(
w3, lpToken.events.Transfer, v2FirstBlock, v2EndBlock,
nBlocks, {}, True
)
with open(f"raw/v2Transfers.json", "w") as f:
json.dump(v2Transfers, f)