2023-06-14 17:27:09 +03:00
|
|
|
import fs from "fs";
|
2023-06-03 20:53:36 +03:00
|
|
|
import path from "path";
|
|
|
|
import BigNumber from "bignumber.js";
|
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
import { getStakersWithRewardsBeforeHack, getStakersWithdrawedAfterHack } from "../utils/stakers";
|
2023-06-03 20:53:36 +03:00
|
|
|
|
2023-06-12 16:22:32 +03:00
|
|
|
// Format options for BigNumber printing
|
|
|
|
const fmt = {
|
2023-06-14 17:27:09 +03:00
|
|
|
prefix: "",
|
|
|
|
decimalSeparator: ".",
|
|
|
|
groupSeparator: "_",
|
2023-06-12 16:22:32 +03:00
|
|
|
groupSize: 3,
|
|
|
|
secondaryGroupSize: 0,
|
2023-06-14 17:27:09 +03:00
|
|
|
fractionGroupSeparator: " ",
|
2023-06-12 16:22:32 +03:00
|
|
|
fractionGroupSize: 0,
|
2023-06-14 17:27:09 +03:00
|
|
|
suffix: "",
|
|
|
|
};
|
2023-06-12 16:22:32 +03:00
|
|
|
BigNumber.config({ FORMAT: fmt });
|
|
|
|
|
2023-06-03 20:53:36 +03:00
|
|
|
async function main() {
|
2023-06-14 17:27:09 +03:00
|
|
|
// All stakers who had more than 1 TORN in rewards at the time of the hack
|
2023-06-03 20:53:36 +03:00
|
|
|
const stakersWithRewardsBeforeHack = await getStakersWithRewardsBeforeHack();
|
2023-06-14 17:27:09 +03:00
|
|
|
// Stakers who withdrew rewards from the time of hack until the balance of the old Staking contract was nullified
|
|
|
|
const stakersWithdrawedAfterHack = await getStakersWithdrawedAfterHack();
|
2023-06-03 20:53:36 +03:00
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
// 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));
|
2023-06-03 20:53:36 +03:00
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
const stakersDisplayedInfo = stakersWithRewardsBeforeHack.map((staker) => {
|
2023-06-03 20:53:36 +03:00
|
|
|
return `${staker.address} = ${staker.rewardBalance.toString(10)} (~ ${staker.rewardBalance.div(1e18).toFixed(2)} TORN)`;
|
2023-06-14 17:27:09 +03:00
|
|
|
});
|
|
|
|
fs.writeFileSync(path.join("data", "rewardsBeforeHack.txt"), stakersDisplayedInfo.join("\n"));
|
2023-06-12 16:22:32 +03:00
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
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");
|
2023-06-13 00:17:26 +03:00
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
const stakersData = stakersToRestoreRewards.map((staker) => {
|
|
|
|
return `Staker(${staker.address}, ${staker.rewardBalance.toFormat()})`;
|
2023-06-13 00:17:26 +03:00
|
|
|
});
|
|
|
|
const commandToAccrueRewards = `accrueOldReward(stakers[i].addr, stakers[i].oldRewards);`;
|
2023-06-12 16:22:32 +03:00
|
|
|
const commandToReplenishStaking = `IERC20(tornAddress).transfer(stakingProxyAddress, ${rewardsSum.toFormat()});`;
|
2023-06-13 00:17:26 +03:00
|
|
|
const codePadding2 = " ".repeat(8);
|
|
|
|
const codePadding3 = " ".repeat(12);
|
|
|
|
const codeToAccrueRewards =
|
|
|
|
codePadding2 +
|
2023-06-14 17:27:09 +03:00
|
|
|
`Staker[${stakersToRestoreRewards.length}] memory stakers = [\n` +
|
2023-06-13 00:17:26 +03:00
|
|
|
codePadding3 +
|
|
|
|
stakersData.join(`,\n${codePadding3}`) +
|
|
|
|
`\n${codePadding2}];\n\n` +
|
|
|
|
codePadding2 +
|
|
|
|
`for (uint64 i = 0; i < stakers.length; i++){\n` +
|
|
|
|
`${codePadding3}` +
|
|
|
|
commandToAccrueRewards +
|
2023-06-13 01:18:32 +03:00
|
|
|
`\n${codePadding2}}\n\n` +
|
2023-06-13 00:17:26 +03:00
|
|
|
codePadding2 +
|
|
|
|
commandToReplenishStaking;
|
2023-06-12 16:22:32 +03:00
|
|
|
fs.writeFileSync(path.join("data", "codeToAccrueRewards.txt"), codeToAccrueRewards);
|
2023-06-03 20:53:36 +03:00
|
|
|
}
|
|
|
|
|
2023-06-14 17:27:09 +03:00
|
|
|
main();
|