@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
94 lines (93 loc) • 5.54 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.simulateRounds = void 0;
const helpers_1 = require("../../test/helpers");
const seedAccounts_1 = require("../helpers/seedAccounts");
const emissions_1 = require("../helpers/emissions");
const airdrop_1 = require("../helpers/airdrop");
const swap_1 = require("../helpers/swap");
const xApp_1 = require("../helpers/xApp");
const voterRewards_1 = require("../helpers/voterRewards");
const navigators_1 = require("../helpers/navigators");
const config_1 = require("@repo/config");
const hardhat_1 = require("hardhat");
const ve_better_passport_1 = require("../helpers/ve-better-passport");
const NUM_ROUNDS = 10;
const ACCT_OFFSET = 100;
// Number of users to seed. If you increase this number you will need to increase the EMISSIONS_CYCLE_DURATION to make sure there is enough time to vote
const NUM_USERS_TO_SEED = 300;
const SEED_STRATEGY = seedAccounts_1.SeedStrategy.RANDOM;
const simulateRounds = async () => {
const start = performance.now();
console.log("================");
console.log("Running simulation...");
// Get the latest config and create the contracts
const config = (0, config_1.getConfig)();
const b3tr = await hardhat_1.ethers.getContractAt("B3TR", config.b3trContractAddress);
const vot3 = await hardhat_1.ethers.getContractAt("VOT3", config.vot3ContractAddress);
const xAllocationVoting = await hardhat_1.ethers.getContractAt("XAllocationVoting", config.xAllocationVotingContractAddress);
const voterRewards = await hardhat_1.ethers.getContractAt("VoterRewards", config.voterRewardsContractAddress);
const accounts = (0, seedAccounts_1.getTestKeys)(10);
const seedAccounts = (0, seedAccounts_1.getSeedAccounts)(SEED_STRATEGY, NUM_USERS_TO_SEED, ACCT_OFFSET);
// Define specific accounts
const admin = accounts[0];
const migrationAccount = accounts[9];
// Whitelist all seed accounts
await (0, ve_better_passport_1.whitelist)(seedAccounts.map(account => account.key.address.toString()), admin, config.veBetterPassportContractAddress);
// Airdrop VTHO
await (0, airdrop_1.airdropVTHO)(seedAccounts.map(acct => acct.key.address), 500n, admin);
// Airdrop B3TR from Treasury
//// Top the treasury up with tokens from the migration account
const bal = await b3tr.balanceOf(migrationAccount.address.toString());
await (0, airdrop_1.transferErc20)(await b3tr.getAddress(), migrationAccount, config.treasuryContractAddress, bal);
await (0, airdrop_1.airdropB3trFromTreasury)(config.treasuryContractAddress, admin, seedAccounts);
// Convert B3TR for VOT3
await (0, swap_1.convertB3trForVot3)(b3tr, vot3, seedAccounts);
// Start emissions
let roundId = parseInt((await xAllocationVoting.currentRoundId()).toString());
if (roundId === 0) {
await (0, emissions_1.startEmissions)(config.emissionsContractAddress, admin);
roundId = parseInt((await xAllocationVoting.currentRoundId()).toString());
}
const startingRound = roundId.valueOf();
// Casting random votes to xDapps
let xDapps = (await xAllocationVoting.getAppsOfRound(roundId)).map(app => app.id);
if (xDapps.length == 0) {
console.log(`No xDapps found for round ${roundId}, waiting for next round`);
await waitForRoundToEnd(roundId, xAllocationVoting);
await (0, emissions_1.distributeEmissions)(config.emissionsContractAddress, admin);
roundId = parseInt((await xAllocationVoting.currentRoundId()).toString());
xDapps = (await xAllocationVoting.getAppsOfRound(roundId)).map(app => app.id);
}
await (0, xApp_1.castVotesToXDapps)(vot3, xAllocationVoting, seedAccounts, roundId, xDapps, true);
// Wait for round to end
await waitForRoundToEnd(roundId, xAllocationVoting);
// Claim voter rewards
await (0, voterRewards_1.claimVoterRewards)(voterRewards, roundId, admin, seedAccounts, true);
// Convert B3TR for VOT3
await (0, swap_1.convertB3trForVot3)(b3tr, vot3, seedAccounts);
for (let i = 1; i < startingRound + NUM_ROUNDS; i++) {
// Disable quadratic rewarding after 10 rounds, then enable it again after 20 rounds
if (i === 10 || i === 30) {
await (0, emissions_1.toggleQuadraticRewarding)(voterRewards, admin);
}
await (0, emissions_1.distributeEmissions)(config.emissionsContractAddress, admin);
const roundId = parseInt((await xAllocationVoting.currentRoundId()).toString());
console.log(`Casting random votes to xDapps for round ${roundId}...`);
await (0, xApp_1.castVotesToXDapps)(vot3, xAllocationVoting, seedAccounts, roundId, xDapps, true);
await waitForRoundToEnd(roundId, xAllocationVoting);
await (0, voterRewards_1.claimVoterRewards)(voterRewards, roundId, admin, seedAccounts, true);
// Convert B3TR for VOT3
await (0, swap_1.convertB3trForVot3)(b3tr, vot3, seedAccounts);
}
// Seed navigators using the first 2 non-admin accounts
await (0, navigators_1.seedNavigators)(b3tr, vot3, accounts, config);
const end = performance.now();
console.log(`Simulation complete in ${end - start}ms`);
};
exports.simulateRounds = simulateRounds;
const waitForRoundToEnd = async (roundId, xAllocationVoting) => {
const deadline = await xAllocationVoting.roundDeadline(roundId);
const currentBlock = await xAllocationVoting.clock();
await (0, helpers_1.moveBlocks)(parseInt((deadline - currentBlock + BigInt(1)).toString()));
};