@vechain/vebetterdao-contracts
Version:
Open-source repository that houses the smart contracts powering the decentralized VeBetterDAO on the VeChain Thor blockchain.
78 lines (77 loc) • 2.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.calculateNextXAllocation = calculateNextXAllocation;
exports.calculateVote2Earn = calculateVote2Earn;
exports.calculateTreasuryAllocation = calculateTreasuryAllocation;
const SCALING_FACTOR = BigInt(1000000);
/**
* Calculates the next X allocation for the next cycle.
* @param cycle
* @param initialAllocation
* @param decayPeriod
* @param decayPercentage
* @param lastCycleEmissions
* @returns The next X allocation as a BigInt.
*/
function calculateNextXAllocation(cycle, initialAllocation, decayPeriod, decayPercentage, lastCycleEmissions) {
if (!lastCycleEmissions) {
return initialAllocation;
}
let scaledValue = lastCycleEmissions * SCALING_FACTOR;
// Check if we need to decay again by getting the modulus
if (cycle > 1 && (cycle - 1) % decayPeriod === 0) {
scaledValue = (scaledValue * (100n - decayPercentage)) / 100n;
}
return scaledValue / SCALING_FACTOR;
}
/**
* Calculates the number of decay periods that have passed since the start of the emissions.
* @param cycle
* @param decayPeriod
* @returns The number of decay periods as a number.
*/
function calculateVote2EarnDecayPeriods(cycle, decayPeriod) {
if (cycle <= 1) {
return 0;
}
return Math.floor((cycle - 1) / decayPeriod);
}
/**
* Calculates the Vote2Earn decay percentage for the next cycle.
* @param cycle
* @param decayPeriod
* @param decayPercentage
* @param maxDecay
* @returns The decay percentage as a number.
*/
function calculateVote2EarnDecayPercentage(cycle, decayPeriod, decayPercentage, maxDecay) {
const vote2earnDecayPeriods = calculateVote2EarnDecayPeriods(cycle, decayPeriod);
const percentageToDecay = decayPercentage * BigInt(vote2earnDecayPeriods);
return percentageToDecay > maxDecay ? maxDecay : percentageToDecay;
}
/**
* Calculates the Vote2Earn allocation for the next cycle.
* @param cycle
* @param xAllocation
* @param decayPeriod
* @param decayPercentage
* @param maxDecay
* @returns vote2EarnAllocation as a BigInt
*/
function calculateVote2Earn(cycle, xAllocation, decayPeriod, decayPercentage, maxDecay) {
const vote2EarnDecay = calculateVote2EarnDecayPercentage(cycle, decayPeriod, decayPercentage, maxDecay);
let scaledValue = xAllocation * SCALING_FACTOR;
scaledValue = (scaledValue * (100n - vote2EarnDecay)) / 100n;
return scaledValue / SCALING_FACTOR;
}
/**
* Calculates the treasury allocation for the next cycle.
* @param xAllocation
* @param vote2EarnAllocation
* @returns treasuryAllocation as a BigInt
*/
function calculateTreasuryAllocation(xAllocation, vote2EarnAllocation, treasuryPercentage) {
let scaledValue = (xAllocation + vote2EarnAllocation) * SCALING_FACTOR;
scaledValue = (scaledValue * treasuryPercentage) / 10000n;
return scaledValue / SCALING_FACTOR;
}