Skip to content

Commit

Permalink
fix: add default value to autoRestake and improve documentation for s…
Browse files Browse the repository at this point in the history
…taking rewards calculation
  • Loading branch information
onmax committed Nov 22, 2024
1 parent eb15c27 commit dae26e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/nimiq-rewards-calculator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -56,20 +57,19 @@ 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 {
const { amount, durationInDays, autoRestake = true, stakedSupplyRatio, network = 'main-albatross' } = params
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 {
Expand Down

0 comments on commit dae26e6

Please sign in to comment.