-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcombine_rewards.py
96 lines (75 loc) · 2.59 KB
/
combine_rewards.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
84
85
86
87
88
89
90
91
92
93
94
95
96
import decimal
import json
from decimal import Decimal
import pandas as pd
import web3
bridgoor = pd.DataFrame(
pd.read_json("final/bridgoor_rewards.json", typ="series"),
columns=["bridgoor"]
)
if bridgoor["bridgoor"].isna().any():
raise ValueError("Missing values in bridgoor data")
lp = pd.DataFrame(
pd.read_json("final/lp_rewards.json", typ="series"),
columns=["lp"]
)
if lp["lp"].isna().any():
raise ValueError("Missing values in lp data")
travelers = pd.DataFrame(
pd.read_json("final/traveler_rewards.json", typ="series"),
columns=["bridge-traveler"]
)
if travelers["bridge-traveler"].isna().any():
raise ValueError("Missing values in traveler data")
community = pd.DataFrame(
pd.read_json("final/community_rewards.json", typ="series"),
columns=["community"]
)
out = (
pd.DataFrame(travelers).join(
[bridgoor, community, lp], how="outer"
)
.fillna(0.0)
)
out.index.name = "address"
out.index = out.index.map(lambda x: web3.Web3.toChecksumAddress(x))
# Make sure no duplicates
assert out.index.duplicated().sum() == 0
# Convert everything to decimal types for more accurate/consistent computations
out = out.applymap(lambda x: Decimal(x).quantize(Decimal("0.0000")))
# Format for mr
mrout = {}
mrout["recipients"] = []
# Metadata
mrout["chainId"] = 1
mrout["rewardToken"] = ""
mrout["windowIndex"] = 0
# Constant 1e18 for convenience
zeros = Decimal(1e18)
runningSum = Decimal(0)
# Iterate through rows and compute total and save to merkle tree object
def removeDecimals(x):
return x.quantize(Decimal("0"))
for (address, row) in out.iterrows():
# Add by hand because `.sum` converted to float
totalDecimal = row["bridge-traveler"] + row["bridgoor"] + row["community"] + row["lp"]
runningSum += totalDecimal*zeros
out.at[address, "total"] = totalDecimal
entry = {
"account": address,
"amount": str(removeDecimals(totalDecimal*zeros)),
"metadata": {
"amountBreakdown": {
"communityRewards": str(removeDecimals(row["community"] * zeros)),
"welcomeTravelerRewards": str(removeDecimals(row["bridge-traveler"] * zeros)),
"earlyUserRewards": str(removeDecimals(row["bridgoor"] * zeros)),
"liquidityProviderRewards": str(removeDecimals(row["lp"] * zeros))
}
}
}
mrout["recipients"].append(entry)
mrout["rewardsToDeposit"] = str(removeDecimals(runningSum))
out.to_json("final/final_combined.json", orient="index")
out.to_csv("final/final_combined.csv")
with open("final/mr.json", "w") as f:
json.dump(mrout, f)