From 4289dd25bd8519ee5ecfe30c6baa385bfed7b0b6 Mon Sep 17 00:00:00 2001 From: woodenfurniture <125113430+woodenfurniture@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:40:32 +1000 Subject: [PATCH] feat: print out rune allocation per account as a table --- .../calculateRewards/calculateRewards.ts | 20 +++++++++----- scripts/rewards-distribution/index.ts | 27 +++++++++++++++++-- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/scripts/rewards-distribution/calculateRewards/calculateRewards.ts b/scripts/rewards-distribution/calculateRewards/calculateRewards.ts index 912f540..a5a595f 100644 --- a/scripts/rewards-distribution/calculateRewards/calculateRewards.ts +++ b/scripts/rewards-distribution/calculateRewards/calculateRewards.ts @@ -4,11 +4,11 @@ import { getStakingAmount, isLogType } from "../helpers"; import { REWARD_RATE, WAD } from "../constants"; import assert from "assert"; -type StakingInfo = { +export type StakingInfo = { stakingBalance: bigint; earnedRewards: bigint; rewardPerTokenStored: bigint; - runeAddress: String; + runeAddress: string; }; const getEmptyStakingInfo = () => { @@ -83,7 +83,7 @@ const updateReward = ( const stake = ( amount: bigint, - runeAddress: String, + runeAddress: string, stakingInfo: StakingInfo, rewardPerTokenStored: bigint, totalStaked: bigint, @@ -250,14 +250,20 @@ export const calculateRewards = ( ); } - const earnedRewardsByAccount: Record = {}; + const epochMetadataByAccount: Record< + Address, + { runeAddress: string; earnedRewards: bigint } + > = {}; for (const [account, epochEndReward] of Object.entries( epochEndRewardsByAccount, )) { - earnedRewardsByAccount[account as Address] = - epochEndReward - (epochStartRewardsByAccount[account as Address] ?? 0n); + epochMetadataByAccount[account as Address] = { + runeAddress: stakingInfoByAccount[account as Address].runeAddress, + earnedRewards: + epochEndReward - (epochStartRewardsByAccount[account as Address] ?? 0n), + }; } - return earnedRewardsByAccount; + return epochMetadataByAccount; }; diff --git a/scripts/rewards-distribution/index.ts b/scripts/rewards-distribution/index.ts index 3389d85..e3a8fd7 100644 --- a/scripts/rewards-distribution/index.ts +++ b/scripts/rewards-distribution/index.ts @@ -13,6 +13,7 @@ import { inquireTotalRuneAmountToDistroBaseUnit, } from "./input"; import { distributeAmount } from "./distributeAmount/distributeAmount"; +import { Address } from "viem"; const main = async () => { const [currentBlock, [initLog]] = await Promise.all([ @@ -64,13 +65,20 @@ const main = async () => { toBlock, ); - const earnedRewardsByAccount = calculateRewards( + const epochMetadataByAccount = calculateRewards( contractCreationBlock, previousEpochEndBlock, epochEndBlock, logs, ); + const earnedRewardsByAccount: Record = {}; + for (const [account, { earnedRewards }] of Object.entries( + epochMetadataByAccount, + )) { + earnedRewardsByAccount[account as Address] = earnedRewards; + } + await validateRewardsDistribution( publicClient, earnedRewardsByAccount, @@ -78,13 +86,28 @@ const main = async () => { toBlock, ); + console.log("Calculating rewards distribution..."); + // compute the allocation of rewards as a percentage of the totalRuneAmountToDistroBaseUnit const runeAllocationBaseUnitByAccount = distributeAmount( totalRuneAmountToDistroBaseUnit, earnedRewardsByAccount, ); - console.log(runeAllocationBaseUnitByAccount); + console.log("Rewards distribution calculated successfully!"); + + const tableRows = Object.entries(epochMetadataByAccount).map( + ([account, { runeAddress }]) => { + return { + account, + runeAddress, + runeAllocationBaseUnit: + runeAllocationBaseUnitByAccount[account as Address], + }; + }, + ); + + console.table(tableRows); // TODO: Confirm details again before proceeding };