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 };