Skip to content

Commit

Permalink
Merge pull request #18 from novasamatech/fix/parachain-staking-apr
Browse files Browse the repository at this point in the history
Fix inflation comparison #85zt5ptha
  • Loading branch information
ERussel authored Jun 29, 2023
2 parents 257574e + e762376 commit 060a68b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
},
"dependencies": {
"@moonbeam-network/api-augment": "^0.2301.0",
"@oak-network/api-augment": "latest",
"@oak-network/api-augment": "1.8.1",
"@types/big.js": "^6.1.6",
"big.js": "^6.2.1"
}
Expand Down
4 changes: 4 additions & 0 deletions src/mappings/rewards/CollatorStakingRewardCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,13 @@ export class CollatorStakingRewardCalculator implements RewardCalculator {
let apr = stakingDeviation.mul(stakedInfo.totalIssuance).mul(inflation).div(stakedInfo.totalStaked)

logger.info(`Total Issuance ${totalIssuance}`)
logger.info(`Total Staked ${totalStaked}`)
logger.info(`Round ${round}`)
logger.info(`Commission ${collatorCommission}`)
logger.info(`Parachain percent ${parachainBondPercent}`)
logger.info(`Inflation ${inflation}`)
logger.info(`Staking deviation ${stakingDeviation}`)
logger.info(`Apr ${apr}`)

return apr.mul(1 - parachainBondPercent - collatorCommission).toNumber()
}
Expand Down
6 changes: 3 additions & 3 deletions src/mappings/rewards/inflation/ParachainStakingInflation.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import {Inflation, StakedInfo} from "./Inflation";
import Big from "big.js";
import {PerbillToNumber} from "../../utils";
import {BigFromINumber, PerbillToNumber} from "../../utils";
import '@moonbeam-network/api-augment'

export class ParachainStakingInflation implements Inflation {

async from(stakedInfo: StakedInfo): Promise<number> {
let inflationConfig = await api.query.parachainStaking.inflationConfig()

if (stakedInfo.totalStaked < Big(Number(inflationConfig.expect.min))) {
if (stakedInfo.totalStaked.lt(BigFromINumber(inflationConfig.expect.min))) {
return PerbillToNumber(inflationConfig.annual.min)
} else if (stakedInfo.totalStaked > Big(Number(inflationConfig.expect.max))) {
} else if (stakedInfo.totalStaked.gt(BigFromINumber(inflationConfig.expect.max))) {
return PerbillToNumber(inflationConfig.annual.max)
} else {
return PerbillToNumber(inflationConfig.annual.ideal)
Expand Down

0 comments on commit 060a68b

Please sign in to comment.