From dae26e68c2be2c579a2430057bb13a251fc72e8e Mon Sep 17 00:00:00 2001 From: onmax Date: Fri, 22 Nov 2024 07:40:03 -0600 Subject: [PATCH] fix: add default value to autoRestake and improve documentation for staking rewards calculation --- packages/nimiq-rewards-calculator/src/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/nimiq-rewards-calculator/src/index.ts b/packages/nimiq-rewards-calculator/src/index.ts index 8759811..121e9a8 100644 --- a/packages/nimiq-rewards-calculator/src/index.ts +++ b/packages/nimiq-rewards-calculator/src/index.ts @@ -21,6 +21,7 @@ export interface CalculateStakingRewardsParams { /** * Indicates whether the staking rewards are restaked (default is true). Restaked mean that each staking reward is added to the pool of staked cryptocurrency for compound interest. + * @default true */ autoRestake?: boolean @@ -56,7 +57,7 @@ export interface CalculateStakingRewardsResult { * Calculates the potential wealth accumulation based on staking in a cryptocurrency network, * considering the effects of reward decay over time. It computes the final amount of cryptocurrency * after a specified number of days of staking, taking into account whether the rewards are restaked or not. - * @param {CalculateStakingRewardsParams} params The parameters for the calculation. + * @param {CalculateStakingRewardsParams} params The parameters for the calculation. @see CalculateStakingRewardsParams * @returns {CalculateStakingRewardsResult} The result of the calculation. */ export function calculateStakingRewards(params: CalculateStakingRewardsParams): CalculateStakingRewardsResult { @@ -64,12 +65,11 @@ export function calculateStakingRewards(params: CalculateStakingRewardsParams): const genesisSupply = network === 'main-albatross' ? SUPPLY_AT_PROOF_OF_STAKE_FORK_DATE : SUPPLY_AT_PROOF_OF_STAKE_FORK_DATE_TESTNET const initialRewardsPerDay = posSupplyAt(24 * 60 * 60 * 1000) - genesisSupply - const decayFactor = Math.E ** (-DECAY_PER_DAY * durationInDays) - const rewardFactor = initialRewardsPerDay / (DECAY_PER_DAY * stakedSupplyRatio * genesisSupply) let gainRatio = 0 if (autoRestake) { + const rewardFactor = initialRewardsPerDay / (DECAY_PER_DAY * stakedSupplyRatio * genesisSupply) gainRatio = rewardFactor * (1 - decayFactor) } else {