Skip to content

Commit

Permalink
feat: add fee parameter to calculateStakingRewards
Browse files Browse the repository at this point in the history
  • Loading branch information
onmax committed Nov 23, 2024
1 parent e672272 commit c20d6b0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/nimiq-rewards-calculator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export interface CalculateStakingRewardsParams {
* @default 'main-albatross'
*/
network?: 'main-albatross' | 'test-albatross'

/**
* The fee percentage that the pool charges for staking.
* @default 0
*/
fee: number
}

export interface CalculateStakingRewardsResult {
Expand Down Expand Up @@ -61,7 +67,7 @@ export interface CalculateStakingRewardsResult {
* @returns {CalculateStakingRewardsResult} The result of the calculation.
*/
export function calculateStakingRewards(params: CalculateStakingRewardsParams): CalculateStakingRewardsResult {
const { amount, durationInDays, autoRestake = true, stakedSupplyRatio, network = 'main-albatross' } = params
const { amount, durationInDays, autoRestake = true, stakedSupplyRatio, network = 'main-albatross', fee = 0 } = 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
Expand All @@ -82,6 +88,7 @@ export function calculateStakingRewards(params: CalculateStakingRewardsParams):
- Math.log(DECAY_PER_DAY * genesisSupply)
)
}
gainRatio = gainRatio * (1 - fee) / 1e5
const totalAmount = amount * (1 + gainRatio)
return { totalAmount, gain: totalAmount - amount, gainRatio }
}

0 comments on commit c20d6b0

Please sign in to comment.