feat: compare rewards against last cycle
@@ -10,50 +10,69 @@ from assistant.rewards.rewards_assistant import run_action
console = Console()
rewardsInfo = {}
+
+
def main():
- trees = download_past_trees(5)
+ trees = download_past_trees(2)
+ pastRewards = json.loads(trees[1])
+ lastTree = json.loads(trees[0])
+
badger = connect_badger(
badger_config.prod_json, load_keeper=False, load_deployer=False
)
- for index, merkle in enumerate(trees):
- if index == (len(trees)- 1):
- break
- currentTree = json.loads(merkle)
- previousTree = json.loads(trees[index + 1])
- compare_trees(currentTree, previousTree)
-
- newRewardsTree = run_action(
+ startBlock = int(lastTree["startBlock"])
+ endBlock = int(lastTree["endBlock"])
+
+ newTree = run_action(
badger,
{
"action": "rootUpdater",
- "startBlock": int(currentTree["startBlock"]),
- "endBlock": int(currentTree["endBlock"]),
- "pastRewards": previousTree,
+ "startBlock": startBlock,
+ "endBlock": endBlock,
+ "pastRewards": pastRewards,
},
test=True,
)["merkleTree"]
- compare_trees(newRewardsTree,previousTree)
+ compare_trees(newTree, lastTree)
with open('logs/rewards-data.json', 'w') as fp:
json.dump(rewardsInfo, fp, indent=4)
def compare_trees(current, previous):
- console.log("Comparing {} and {}".format(
- current["merkleRoot"],previous["merkleRoot"]
- ))
- rewardsKey = "{}-{}".format(
- current["merkleRoot"],
- previous["merkleRoot"]
- )
- rewardsInfo[rewardsKey] = {
- "diff":{},
- "startBlock":current["startBlock"],
- "endBlock":current["endBlock"],
+ rewardsInfo["old"] = {
+ "tokenTotals": previous["tokenTotals"]
+ }
+ rewardsInfo["new"] = {
+ "tokenTotals": current["tokenTotals"]
}
+ rewardsInfo["diffs"] = {}
+ console.log(len(previous["claims"]))
+ console.log(len(current["claims"]))
+ rewardsInfo["addressDiff"] = list(set(current["claims"].keys()) ^ set(previous["claims"].keys()))
+
+ for addr,data in previous["claims"].items():
+ if addr not in rewardsInfo["diffs"]:
+ rewardsInfo["diffs"][addr] = {
+ "old":{},
+ "new":{}
+ }
+ for i in range(len(data["tokens"])):
+ token = data["tokens"][i]
+ amount = data["cumulativeAmounts"][i]
+ rewardsInfo["diffs"][addr]["old"][token] = amount
+
+
+ for addr,data in current["claims"].items():
+ if addr not in rewardsInfo["diffs"]:
+ rewardsInfo["diffs"][addr] = {
+ "old":{},
+ "new":{}
+ }
+ for i in range(len(data["tokens"])):
+ token = data["tokens"][i]
+ amount = data["cumulativeAmounts"][i]
+ rewardsInfo["diffs"][addr]["new"][token] = amount
+
+
- assert previous["cycle"] < current["cycle"]
- for token, total in current["tokenTotals"].items():
- diff = total - previous["tokenTotals"][token]
- rewardsInfo[rewardsKey]["diff"][token] = int(diff)
- console.log("Diff of {} is {}".format(token, diff))
