Skip to content

Commit

Permalink
feat: add progress bar to rewards validation
Browse files Browse the repository at this point in the history
  • Loading branch information
woodenfurniture committed May 29, 2024
1 parent 8c7f76f commit df7ae17
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 34 deletions.
40 changes: 6 additions & 34 deletions scripts/rewards-distribution/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { publicClient } from "./client";
import { calculateRewards } from "./calculateRewards/calculateRewards";
import { stakingV1Abi } from "./generated/abi-types";
import assert from "assert";
import { Address } from "viem";
import { validateRewardsDistribution } from "./validation";

const inquireBlockRange = async (): Promise<{
fromBlock: bigint;
Expand Down Expand Up @@ -130,40 +130,12 @@ const main = async () => {
logs,
);

// validate rewards per account against the contract
for (const [account, calculatedReward] of Object.entries(
await validateRewardsDistribution(
publicClient,
earnedRewardsByAccount,
)) {
const [previousTotalEarnedForAccount, currentTotalEarnedForAccount] =
await Promise.all([
publicClient.readContract({
// TODO: dotenv or similar for contract addresses
address: ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS,
abi: stakingV1Abi,
functionName: "earned",
args: [account as Address],
blockNumber: fromBlock - 1n, // The end of the previous epoch
}),
publicClient.readContract({
// TODO: dotenv or similar for contract addresses
address: ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS,
abi: stakingV1Abi,
functionName: "earned",
args: [account as Address],
blockNumber: toBlock,
}),
]);

const onChainReward =
currentTotalEarnedForAccount - previousTotalEarnedForAccount;

assert(
calculatedReward === onChainReward,
`Expected reward for ${account} to be ${onChainReward}, got ${calculatedReward}`,
);
}

console.log("Validation passed.");
fromBlock,
toBlock,
);

// TODO: Confirm details again before proceeding
};
Expand Down
66 changes: 66 additions & 0 deletions scripts/rewards-distribution/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import cliProgress from "cli-progress";
import colors from "ansi-colors";
import { Address, PublicClient } from "viem";
import { ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS } from "./constants";
import { stakingV1Abi } from "./generated/abi-types";
import assert from "assert";

export const validateRewardsDistribution = async (
publicClient: PublicClient,
earnedRewardsByAccount: Record<Address, bigint>,
fromBlock: bigint,
toBlock: bigint,
) => {
const progressBar = new cliProgress.SingleBar({
format:
"Validation Progress |" +
colors.cyan("{bar}") +
"| {percentage}% || {value}/{total} Accounts",
barCompleteChar: "\u2588",
barIncompleteChar: "\u2591",
hideCursor: true,
});

progressBar.start(Object.keys(earnedRewardsByAccount).length, 0, {
speed: "N/A",
});

// validate rewards per account against the contract
for (const [account, calculatedReward] of Object.entries(
earnedRewardsByAccount,
)) {
const [previousTotalEarnedForAccount, currentTotalEarnedForAccount] =
await Promise.all([
publicClient.readContract({
// TODO: dotenv or similar for contract addresses
address: ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS,
abi: stakingV1Abi,
functionName: "earned",
args: [account as Address],
blockNumber: fromBlock - 1n, // The end of the previous epoch
}),
publicClient.readContract({
// TODO: dotenv or similar for contract addresses
address: ARBITRUM_RFOX_PROXY_CONTRACT_ADDRESS,
abi: stakingV1Abi,
functionName: "earned",
args: [account as Address],
blockNumber: toBlock,
}),
]);

const onChainReward =
currentTotalEarnedForAccount - previousTotalEarnedForAccount;

assert(
calculatedReward === onChainReward,
`Expected reward for ${account} to be ${onChainReward}, got ${calculatedReward}`,
);

progressBar.increment();
}

progressBar.stop();

console.log("Validation passed.");
};

0 comments on commit df7ae17

Please sign in to comment.