proposal-25-restore-rewards/scripts/writeStakersData.ts

61 lines
2.6 KiB
TypeScript

import fs from "fs";
import path from "path";
import BigNumber from "bignumber.js";
import { getStakersWithRewardsBeforeHack, getStakersWithdrawedAfterHack } from "../utils/stakers";
// Format options for BigNumber printing
const fmt = {
prefix: "",
decimalSeparator: ".",
groupSeparator: "_",
groupSize: 3,
secondaryGroupSize: 0,
fractionGroupSeparator: " ",
fractionGroupSize: 0,
suffix: "",
};
BigNumber.config({ FORMAT: fmt });
async function main() {
// All stakers who had more than 1 TORN in rewards at the time of the hack
const stakersWithRewardsBeforeHack = await getStakersWithRewardsBeforeHack();
// Stakers who withdrew rewards from the time of hack until the balance of the old Staking contract was nullified
const stakersWithdrawedAfterHack = await getStakersWithdrawedAfterHack();
// It makes no sense to restore awards to those who already withdrew them from the old Staking contract
const stakersToRestoreRewards = stakersWithRewardsBeforeHack.filter((staker) => !stakersWithdrawedAfterHack.includes(staker.address));
const stakersDisplayedInfo = stakersWithRewardsBeforeHack.map((staker) => {
return `${staker.address} = ${staker.rewardBalance.toString(10)} (~ ${staker.rewardBalance.div(1e18).toFixed(2)} TORN)`;
});
fs.writeFileSync(path.join("data", "rewardsBeforeHack.txt"), stakersDisplayedInfo.join("\n"));
const rewardsSum = stakersToRestoreRewards.reduce((acc, staker) => acc.plus(staker.rewardBalance), BigNumber(0));
console.log("Sum of rewards before hack:", rewardsSum.div(1e18).toFixed(2), "TORN");
const stakersData = stakersToRestoreRewards.map((staker) => {
return `Staker(${staker.address}, ${staker.rewardBalance.toFormat()})`;
});
const commandToAccrueRewards = `accrueOldReward(stakers[i].addr, stakers[i].oldRewards);`;
const commandToReplenishStaking = `IERC20(tornAddress).transfer(stakingProxyAddress, ${rewardsSum.toFormat()});`;
const codePadding2 = " ".repeat(8);
const codePadding3 = " ".repeat(12);
const codeToAccrueRewards =
codePadding2 +
`Staker[${stakersToRestoreRewards.length}] memory stakers = [\n` +
codePadding3 +
stakersData.join(`,\n${codePadding3}`) +
`\n${codePadding2}];\n\n` +
codePadding2 +
`for (uint64 i = 0; i < stakers.length; i++){\n` +
`${codePadding3}` +
commandToAccrueRewards +
`\n${codePadding2}}\n\n` +
codePadding2 +
commandToReplenishStaking;
fs.writeFileSync(path.join("data", "codeToAccrueRewards.txt"), codeToAccrueRewards);
}
main();