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

56 lines
2.1 KiB
TypeScript

import fs from 'fs';
import path from "path";
import BigNumber from "bignumber.js";
import { getStakersWithRewardsBeforeHack } 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() {
const stakersWithRewardsBeforeHack = await getStakersWithRewardsBeforeHack();
const rewardsSum = stakersWithRewardsBeforeHack.reduce((acc, staker) => acc.plus(staker.rewardBalance), BigNumber(0));
console.log("Sum of rewards before hack:", rewardsSum.div(1e18).toFixed(2), "TORN");
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 stakersData = stakersWithRewardsBeforeHack.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[${stakersWithRewardsBeforeHack.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();