From 0c2befbf01020d57b978418333c2e7d0b970aad8 Mon Sep 17 00:00:00 2001 From: Wei-Jun Hung Date: Mon, 16 Aug 2021 17:02:27 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=90=9B=20Fix=20voting=20power=20calcu?= =?UTF-8?q?lation=20error?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/cosmos-reducers.js | 4 ++-- apis/cosmos-source.js | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apis/cosmos-reducers.js b/apis/cosmos-reducers.js index 460c05c9..22dc209b 100644 --- a/apis/cosmos-reducers.js +++ b/apis/cosmos-reducers.js @@ -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]') { @@ -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, diff --git a/apis/cosmos-source.js b/apis/cosmos-source.js index 6073685a..10fc92b1 100644 --- a/apis/cosmos-source.js +++ b/apis/cosmos-source.js @@ -209,16 +209,17 @@ export default class CosmosAPI { 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() { From c1adc04f409ea7847760285805da047fa294088f Mon Sep 17 00:00:00 2001 From: Wei-Jun Hung Date: Mon, 16 Aug 2021 18:55:14 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=94=A5=20Remove=20unused=20`getStakin?= =?UTF-8?q?gSupply`=20function?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apis/cosmos-source.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/apis/cosmos-source.js b/apis/cosmos-source.js index 10fc92b1..77922ef3 100644 --- a/apis/cosmos-source.js +++ b/apis/cosmos-source.js @@ -201,10 +201,6 @@ 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,