-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move expected returns to separate resolver (#172)
* Move expected returns to separate resolver * Scale result by 1/1000000
- Loading branch information
Showing
4 changed files
with
32 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,23 +64,26 @@ const calculateTokens = (validator, shares) => { | |
/* if you don't get this, write [email protected] */ | ||
// expected rewards if delegator stakes x tokens | ||
const expectedRewardsPerToken = (validator, commission, annualProvision) => { | ||
if (validator.status === 0 || validator.jailed === true) { | ||
if (validator.status === 'INACTIVE' || validator.jailed === true) { | ||
return 0 | ||
} | ||
|
||
// share of all provisioned block rewards all delegators of this validator get | ||
const totalAnnualValidatorRewards = validator.voting_power * annualProvision | ||
const totalAnnualValidatorRewards = BigNumber(validator.votingPower).times( | ||
annualProvision | ||
) | ||
// the validator takes a cut in amount of the commission | ||
const totalAnnualDelegatorRewards = | ||
totalAnnualValidatorRewards * (1 - commission) | ||
const totalAnnualDelegatorRewards = totalAnnualValidatorRewards.times( | ||
BigNumber(1).minus(commission) | ||
) | ||
|
||
// validator.tokens is the amount of all tokens delegated to that validator | ||
// one token delegated would receive x percentage of all delegator rewards | ||
const delegatorSharePerToken = 1 / validator.tokens | ||
const annualDelegatorRewardsPerToken = | ||
totalAnnualDelegatorRewards * delegatorSharePerToken | ||
|
||
return annualDelegatorRewardsPerToken | ||
const delegatorSharePerToken = BigNumber(1).div(validator.tokens) | ||
const annualDelegatorRewardsPerToken = totalAnnualDelegatorRewards.times( | ||
delegatorSharePerToken | ||
) | ||
return annualDelegatorRewardsPerToken.div(1000000) | ||
} | ||
|
||
// reduce deposits to one number and filter by required denom | ||
|
@@ -188,12 +191,7 @@ function getValidatorStatus(validator) { | |
} | ||
} | ||
|
||
function validatorReducer( | ||
networkId, | ||
signedBlocksWindow, | ||
validator, | ||
annualProvision | ||
) { | ||
function validatorReducer(networkId, signedBlocksWindow, validator) { | ||
const statusInfo = getValidatorStatus(validator) | ||
let websiteURL = validator.description.website | ||
if (!websiteURL || websiteURL === '[do-not-modify]') { | ||
|
@@ -226,12 +224,7 @@ function validatorReducer( | |
maxChangeCommission: validator.commission.max_change_rate, | ||
status: statusInfo.status, | ||
statusDetailed: statusInfo.status_detailed, | ||
delegatorShares: validator.delegator_shares, // needed to calculate delegation token amounts from shares | ||
expectedReturns: expectedRewardsPerToken( | ||
validator, | ||
validator.commission.rate, | ||
annualProvision | ||
) | ||
delegatorShares: validator.delegator_shares // needed to calculate delegation token amounts from shares | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters