-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetDelegateDistributionARB.py
57 lines (50 loc) · 2.13 KB
/
getDelegateDistributionARB.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
#import libaries
import pandas as pd
import numpy as np
from web3 import Web3, HTTPProvider
import json
import pickle
from enum import Enum
from multiprocessing import Process
import numpy as np
import pickle
#url of Arbitrum node
urlARB= ""
#connect to Arbitrum client
w3 = Web3(HTTPProvider(urlARB))
#block number for events
class BlockNumberARB(Enum):
Mar31 = 196288427
with open('data/aggregate/votesData.pkl', 'rb') as handle:
votesData = pickle.load(handle)
class Decimals(Enum):
ETH = 18
def getDataFromNodeDelegate(delegates,w3,directory,token,address,blocks):
blocks = [int(x) for x in blocks]
blocks.append(int(BlockNumberARB.Mar31.value))
print(blocks)
abi = json.load(open('abi/ENS.abi'))
contract = w3.eth.contract(address=w3.to_checksum_address(address), abi=abi)
tokenDistribution=[]
decimals = contract.functions.decimals().call()
for delegate in delegates:
delegate0 = "0x"+ delegate[3:]
for block in blocks:
data = contract.functions.getVotes(w3.to_checksum_address(delegate0)).call()
tokenDistribution.append({'delegtate':delegate0,'block':block,'votes':data})
tokenDistributionDF = pd.DataFrame.from_records(tokenDistribution)
tokenDistributionDF['votes'] = tokenDistributionDF['votes'].apply(lambda x: x/(10**decimals))
tokenDistributionDF=tokenDistributionDF[tokenDistributionDF['votes']>0]
tokenDistributionDF.to_pickle(directory+token.lower()+'.pkl')
directory ="data/delDist/"
processes = []
blocks1 = list(votesData['ARBT'].keys())
blocks1 =[i[0] for i in blocks1]
delegatestemp= pd.read_csv("data/delegates/arb.csv",delimiter ="\t",names=['delegate'])
delegates = delegatestemp['delegate'].values.tolist()
getDataFromNodeDelegate(delegates,w3,directory,'ARBT','0x912CE59144191C1204E64559FE8253a0e49E6548',blocks1)
blocks2 = list(votesData['ARBC'].keys())
blocks2 =[i[0] for i in blocks2]
delegatestemp= pd.read_csv("data/delegates/arb.csv",delimiter ="\t",names=['delegate'])
delegates = delegatestemp['delegate'].values.tolist()
getDataFromNodeDelegate(delegates,w3,directory,'ARBC','0x912CE59144191C1204E64559FE8253a0e49E6548',blocks2)