-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDelegateDistributionETHMonthly.py
83 lines (75 loc) · 3.43 KB
/
getDelegateDistributionETHMonthly.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
74
75
76
77
78
79
80
81
82
83
#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 Ethereum node
urlETH = ""
#connect to Ethereum client
w3 = Web3(HTTPProvider(urlETH))
tokens =pd.read_csv('data/general/govInfoETH.csv',sep='\t')
tokens =tokens[tokens['delegation']=='R']
tokens =tokens[tokens['name']=='Gas']
class Decimals(Enum):
ETH = 18
def getDataFromNodeDelegate2(delegates,w3,directory,token,address,blocks):
blocks = [int(x) for x in 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:
try:
data = contract.functions.getVotes(w3.to_checksum_address(delegate0)).call({}, block)
tokenDistribution.append({'delegtate':delegate0,'block':block,'votes':data})
except:
pass
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')
def getDataFromNodeDelegate(delegates,w3,directory,token,address,blocks):
blocks = [int(x) for x in blocks]
abi = json.load(open('abi/COMP.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:
try:
data = contract.functions.getCurrentVotes(w3.to_checksum_address(delegate0)).call({}, block)
tokenDistribution.append({'delegtate':delegate0,'block':block,'votes':data})
except:
pass
tokenDistributionDF = pd.DataFrame.from_records(tokenDistribution).reindex()
tokenDistributionDF['votes'] = tokenDistributionDF['votes'].apply(lambda x: x/(10**decimals))
tokenDistributionDF=tokenDistributionDF[tokenDistributionDF['votes']>0]
tokenDistributionDF.to_pickle(directory+token.lower()+'.pkl')
directory ="data/delDistMonthly/"
processes = []
for idx,row in tokens.iterrows():
blocksMonthly =pd.read_pickle("data/time/blocksMonthly.p")
blocks = blocksMonthly.number.tolist()[1:]
if row['abiToken'] == 'COMP':
delegatestemp= pd.read_csv("data/delegates/"+row['token'].lower()+".csv",delimiter ="\t",names=['delegate'])
delegates = delegatestemp['delegate'].values.tolist()
p = Process(target=getDataFromNodeDelegate, args=(delegates,w3,directory,row['token'],row['address'],blocks), )
processes.append(p)
p.start()
elif row['abiToken']=='ENS':
delegatestemp= pd.read_csv("data/delegates/"+row['token'].lower()+".csv",delimiter ="\t",names=['delegate'])
delegates = delegatestemp['delegate'].values.tolist()
p = Process(target=getDataFromNodeDelegate2, args=(delegates,w3,directory,row['token'],row['address'],blocks), )
processes.append(p)
p.start()
for process in processes:
process.join()
processes.remove(process)