Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Fix voting power calculation error #64

Open
wants to merge 2 commits into
base: stargate
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apis/cosmos-reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ export function getValidatorUptimePercentage(validator, signedBlocksWindow) {//
}
}

export function validatorReducer(validator, annualProvision, supply, pool) {
export function validatorReducer(validator, annualProvision, totalShares, pool) {
const statusInfo = getValidatorStatus(validator)
let websiteURL = validator.description.website
if (!websiteURL || websiteURL === '[do-not-modify]') {
Expand All @@ -644,7 +644,7 @@ export function validatorReducer(validator, annualProvision, supply, pool) {
website: websiteURL,
identity: validator.description.identity,
name: validator.description.moniker,
votingPower: (validator.tokens / supply).toFixed(6),
votingPower: validator.status === 3 ? (validator.delegator_shares / totalShares).toFixed(6) : '0',
startHeight: validator.signing_info
? validator.signing_info.start_height
: undefined,
Expand Down
13 changes: 5 additions & 8 deletions apis/cosmos-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,24 +201,21 @@ export default class CosmosAPI {
await this.dataReady
return Object.values(this.validators)
}
async getStakingSupply() {
const res = await this.query(`cosmos/bank/v1beta1/supply`)
return BigNumber(res.supply[0].amount)
}
async loadValidators() {
const [
validators,
annualProvision,
supply,
pool
] = await Promise.all([
this.query(`staking/validators?status=BOND_STATUS_BONDED`),
this.getAnnualProvision().catch(() => undefined),
this.getStakingSupply(),
this.query(`cosmos/staking/v1beta1/pool`)
])
return validators.result.map(validator => reducers.validatorReducer(validator, annualProvision, supply, pool))

const totalShares = validators.result.reduce(
(sum, { delegator_shares: delegatorShares }) => sum.plus(delegatorShares),
BigNumber(0)
)
return validators.result.map(validator => reducers.validatorReducer(validator, annualProvision, totalShares, pool))
}

async getInflation() {
Expand Down