Skip to content

Commit

Permalink
feat: print out rune allocation per account as a table
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed Jun 4, 2024
1 parent d7f2318 commit 4289dd2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
20 changes: 13 additions & 7 deletions scripts/rewards-distribution/calculateRewards/calculateRewards.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -83,7 +83,7 @@ const updateReward = (

const stake = (
amount: bigint,
runeAddress: String,
runeAddress: string,
stakingInfo: StakingInfo,
rewardPerTokenStored: bigint,
totalStaked: bigint,
Expand Down Expand Up @@ -250,14 +250,20 @@ export const calculateRewards = (
);
}

const earnedRewardsByAccount: Record<Address, bigint> = {};
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;
};
27 changes: 25 additions & 2 deletions scripts/rewards-distribution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -64,27 +65,49 @@ const main = async () => {
toBlock,
);

const earnedRewardsByAccount = calculateRewards(
const epochMetadataByAccount = calculateRewards(
contractCreationBlock,
previousEpochEndBlock,
epochEndBlock,
logs,
);

const earnedRewardsByAccount: Record<Address, bigint> = {};
for (const [account, { earnedRewards }] of Object.entries(
epochMetadataByAccount,
)) {
earnedRewardsByAccount[account as Address] = earnedRewards;
}

await validateRewardsDistribution(
publicClient,
earnedRewardsByAccount,
fromBlock,
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
};
Expand Down

0 comments on commit 4289dd2

Please sign in to comment.