UNPKG

@vechain/vebetterdao-contracts

Version:

Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.

49 lines (48 loc) 2.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.generateB3trAllocations = generateB3trAllocations; const promises_1 = __importDefault(require("fs/promises")); const hardhat_1 = require("hardhat"); const allocations_1 = require("./allocations"); /** * Saves the given allocations to a file in JSON format. * @param allocations Array of Allocation objects to save. * @param path Name of the file to save the allocations to. */ async function saveAllocationsToFile(allocations, path) { await promises_1.default.writeFile(path, JSON.stringify(allocations, (_, value) => (typeof value === "bigint" ? value.toString() : value), // return everything else unchanged 2)); console.log(`Cycles' allocations saved to ${path}`); } /** * Generates token allocations based on predetermined decay cycles and percentages. * @returns A Promise that resolves to an array of Allocation objects. */ async function generateB3trAllocations(config, path) { const xAllocations = []; const b3trCap = hardhat_1.ethers.parseEther("1000243154"); let b3trSupply = config.MIGRATION_AMOUNT; let cycle = 1; let lastCycleEmissions = undefined; while (b3trSupply < b3trCap) { const xAllocation = (0, allocations_1.calculateNextXAllocation)(cycle, config.INITIAL_X_ALLOCATION, config.EMISSIONS_X_ALLOCATION_DECAY_PERIOD, BigInt(config.EMISSIONS_X_ALLOCATION_DECAY_PERCENTAGE), lastCycleEmissions); const vote2EarnAllocation = (0, allocations_1.calculateVote2Earn)(cycle, xAllocation, config.EMISSIONS_VOTE_2_EARN_ALLOCATION_DECAY_PERIOD, BigInt(config.EMISSIONS_VOTE_2_EARN_DECAY_PERCENTAGE), BigInt(config.EMISSIONS_MAX_VOTE_2_EARN_DECAY_PERCENTAGE)); const treasuryAllocation = (0, allocations_1.calculateTreasuryAllocation)(xAllocation, vote2EarnAllocation, BigInt(config.EMISSIONS_TREASURY_PERCENTAGE)); xAllocations.push({ cycle, xAllocation, vote2EarnAllocation, treasuryAllocation }); b3trSupply += xAllocation + vote2EarnAllocation + treasuryAllocation; lastCycleEmissions = xAllocation; cycle++; } // If the b3trSupply exceeds the MAX_SUPPLY, remove the last allocation if (b3trSupply > b3trCap) { xAllocations.pop(); } // Save the allocations to a file if (path) { await saveAllocationsToFile(xAllocations, path); } return xAllocations; }