Skip to content

Commit

Permalink
Fix/update_to_inflationDistributionInfo (#73)
Browse files Browse the repository at this point in the history
* fix: first implementation

* fix: clean up code

* fix: error message
  • Loading branch information
stepanLav authored Nov 6, 2024
1 parent 32ba14f commit 37f0aad
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/mappings/rewards/CollatorStakingRewardCalculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,22 @@ export class CollatorStakingRewardCalculator implements RewardCalculator {
}

private async fetchParachainBondPercent(): Promise<number> {
const parachainBondInfo = await api.query.parachainStaking.parachainBondInfo()
return PercentToNumber(parachainBondInfo.percent)
if (api.query.parachainStaking.parachainBondInfo) {
const parachainBondInfo = await api.query.parachainStaking.parachainBondInfo()
return PercentToNumber(parachainBondInfo.percent)
} else if (api.query.parachainStaking.inflationDistributionInfo) {
return await this.fetchInflationDistributionInfo()
}
throw new Error("No parachain info found")
}

private async fetchInflationDistributionInfo(): Promise<number> {
const inflationDistributionInfo = await api.query.parachainStaking.inflationDistributionInfo()
const distributionInfos = JSON.parse(inflationDistributionInfo.toString())

return distributionInfos.reduce((total: number, info: any) => {
return total + PercentToNumber(info.percent)
}, 0)
}

private async fetchCommission(): Promise<number> {
Expand Down

0 comments on commit 37f0aad

Please sign in to comment.