Skip to content

Commit

Permalink
wrote script to get pending rewards
Browse files Browse the repository at this point in the history
  • Loading branch information
deadshotryker committed Dec 14, 2024
1 parent 10d22e7 commit 7f56b6e
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ typechain-types/
generated-abi
scripts/*.json
scripts/data/*.json
scripts/data
solcInputs
hardhat-dependency-compiler/
abi
Expand Down
Binary file added scripts/.DS_Store
Binary file not shown.
70 changes: 70 additions & 0 deletions scripts/getPendingEarndedRewards.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import hre from "hardhat";
import fs from "fs";
import { resolve } from "path";
import { AddressLike, formatEther, parseEther } from "ethers";
import multicallAbi from "./data/multicall-abi.json";

const main = async function () {
const OmnichainStakingToken = await hre.ethers.getContractAt(
"OmnichainStakingToken",
"0xf374229a18ff691406f99ccbd93e8a3f16b68888"
);

const multicall = new hre.ethers.Contract(
"0xcA11bde05977b3631167028862bE2a173976CA11",
new hre.ethers.Interface(multicallAbi),
hre.ethers.provider
);

const balncesCsv = fs.readFileSync(resolve(__dirname, "./data/balances.csv"));
const lines = balncesCsv
.toString()
.split("\n")
.map((l) => l.split('","').map((c) => c.replace(/[",]/g, "")))
.map((c) => [c[0], Number(c[1])]);

fs.writeFileSync(
resolve(__dirname, "./data/results.csv"),
"address,balance,earned\n"
);

const batchSizes = 1000;
for (let i = 0; i < lines.length; i += batchSizes) {
console.log(`Processing ${i} to ${i + batchSizes}`);
const batch = lines.slice(i, i + batchSizes);
// Process each batch

const calls = batch.map(([address]) => ({
target: OmnichainStakingToken.target,
allowFailure: false,
callData: OmnichainStakingToken.interface.encodeFunctionData("earned", [
address as AddressLike,
]),
}));

const results: { success: boolean; returnData: string }[] =
await multicall.aggregate3.staticCall(calls);

const parsed = results.map((result, index) => {
const earned = OmnichainStakingToken.interface.decodeFunctionResult(
"earned",
result.returnData
);
return {
address: batch[index][0],
earned: Number(formatEther(earned[0].toString())),
balance: batch[index][1],
};
});

const data = parsed
.map((p) => `${p.address},${p.balance},${p.earned}\n`)
.join("");

fs.writeFileSync(resolve(__dirname, "./data/results.csv"), data, {
flag: "a",
});
}
};

main();

1 comment on commit 7f56b6e

@SalazahrR

This comment was marked as off-topic.

Please sign in to comment.