From 3cd7b85fe23d1de51835c9f970e74629ea86a5b0 Mon Sep 17 00:00:00 2001 From: Eugene Way Date: Tue, 6 Feb 2024 14:18:43 +0100 Subject: [PATCH] fix total staking (#12) --- src/calculators/circulation-supply.js | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/calculators/circulation-supply.js b/src/calculators/circulation-supply.js index 85d95fc..1da7b52 100644 --- a/src/calculators/circulation-supply.js +++ b/src/calculators/circulation-supply.js @@ -50,21 +50,11 @@ export async function totalVesting() { } export async function totalStaking() { - const prefix = api.query.balances.locks.keyPrefix(); - const keys = await getKeys(prefix); - const allLocks = await api.rpc.state.queryStorageAt(keys); - - let total = BigInt(0); - - for (const lock of allLocks) { - const withType = api.registry.createType('PalletBalancesBalanceLock', lock.toU8a().slice(2)); + const currentEra = (await api.query.staking.currentEra()).toHuman(); + const staking = await api.query.staking.erasTotalStake(currentEra); + const total = staking.toBigInt() / BigInt(10 ** DECIMALS) - if (withType.id.toHex() == STAKING_HEX) { - total += withType.amount.toBigInt(); - } - } - const totalStaking = total / BigInt(10 ** DECIMALS); - return Number(totalStaking); + return Number(total) } // Get all pool addresses