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

41 lines
1.7 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 commandsToAccrueRewards = stakersWithRewardsBeforeHack.map(staker => {
return `staking.setReward(${staker.address}, staking.checkReward(${staker.address}) + ${staker.rewardBalance.toFormat()});`;
})
const commandToReplenishStaking = `IERC20(tornAddress).transfer(stakingProxyAddress, ${rewardsSum.toFormat()});`;
const codePadding = " ".repeat(8);
const codeToAccrueRewards = codePadding + commandsToAccrueRewards.join(`\n${codePadding}`) + '\n' + codePadding + commandToReplenishStaking;
fs.writeFileSync(path.join("data", "codeToAccrueRewards.txt"), codeToAccrueRewards);
}
main();