Skip to content

Commit

Permalink
fix(sphere): estimation apr (#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimakorzhovnik authored Dec 26, 2024
1 parent a4d07d1 commit 22e7ae8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
1 change: 0 additions & 1 deletion src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export {
StartStageSearchActionBar,
ActionBarSend,
RewardsDelegators,
ReDelegate,
TransactionError,
TextTable,
Vitalik,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function Col({
}

type Options = {
apr?: number;
apr?: string;
power?: number;
delegateAddress?: string;
selfStake?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ function reduceDetails(
? big(100).minus(self).dp(3, BigNumber.ROUND_FLOOR).toNumber()
: undefined;

const totalVotingPower = big(bondedTokens).multipliedBy(
big(1).minus(validatorInfo.commission.commissionRates.rate)
);
const stakingProvisionsByItem = stakingProvisions
? big(stakingProvisions).multipliedBy(
big(1).minus(validatorInfo.commission.commissionRates.rate)
)
: undefined;

const estimatedApr =
bondedTokens && stakingProvisions
? big(stakingProvisions)
.dividedBy(totalVotingPower)
bondedTokens && stakingProvisionsByItem
? big(stakingProvisionsByItem)
.dividedBy(bondedTokens)
.multipliedBy(100)
.dp(2, BigNumber.ROUND_FLOOR)
.toNumber()
.toFixed(2)
: undefined;

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ function reduceValidatorData(data: Validator[], options: Options) {
.dp(2, BigNumber.ROUND_FLOOR)
.toFixed(2);

const totalVotingPower = new BigNumber(bondedTokens).multipliedBy(
new BigNumber(1).minus(commission.commissionRates.rate)
);

const estimatedApr = stakingProvisions
? new BigNumber(stakingProvisions)
.dividedBy(totalVotingPower)
const stakingProvisionsByItem = stakingProvisions
? new BigNumber(stakingProvisions).multipliedBy(
new BigNumber(1).minus(commission.commissionRates.rate)
)
: undefined;

const estimatedApr = stakingProvisionsByItem
? new BigNumber(stakingProvisionsByItem)
.dividedBy(bondedTokens)
.toNumber()
: 0;

Expand Down

0 comments on commit 22e7ae8

Please sign in to comment.