From 8f36d1584754e6727d0c3c8a5bb417fa5b50321b Mon Sep 17 00:00:00 2001 From: Gianfranco Tasteri Date: Mon, 19 Feb 2024 12:39:07 -0300 Subject: [PATCH 1/4] add circulating supply endpoint and accounts to ignore for it --- src/api/controllers/token.controller.js | 30 +++++++++++++++++++ src/api/routes/v1/stats.route.js | 13 ++++++++ .../utils/circulating_accounts_to_ignore.js | 21 +++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 src/api/utils/circulating_accounts_to_ignore.js diff --git a/src/api/controllers/token.controller.js b/src/api/controllers/token.controller.js index b04e0eb..8e5ca10 100644 --- a/src/api/controllers/token.controller.js +++ b/src/api/controllers/token.controller.js @@ -1,5 +1,6 @@ const memcached = require("../../config/memcached"); const { executeApiCall } = require("../services/rpc.service"); +const {ACCOUNTS_TO_SUBSTRACT_AMPLITUDE, ACCOUNTS_TO_SUBSTRACT_PENDULUM} = require("../utils/circulating_accounts_to_ignore"); async function fetchTokenStats(network) { console.log(`Fetching token stats for network ${network}`); @@ -11,8 +12,10 @@ async function fetchTokenStats(network) { let totalTransferable = BigInt(0); let totalLocked = BigInt(0); let totalReserved = BigInt(0); + let supplyToIgnore = BigInt(0); accounts.forEach((entry) => { + const account = entry[0].toHuman()[0] const balances = entry[1].toHuman().data; const miscFrozen = BigInt(balances.miscFrozen.replace(/,/g, "")); const feeFrozen = BigInt(balances.feeFrozen.replace(/,/g, "")); @@ -20,6 +23,22 @@ async function fetchTokenStats(network) { const free = BigInt(balances.free.replace(/,/g, "")); const reserved = BigInt(balances.reserved.replace(/,/g, "")); + // We mantain the supplyToIgnore to substract it from the total transferable + let accountsToSubstract = []; + if (network === "amplitude") { + accountsToSubstract = ACCOUNTS_TO_SUBSTRACT_AMPLITUDE; + } else if (network === "pendulum") { + accountsToSubstract = ACCOUNTS_TO_SUBSTRACT_PENDULUM; + } else { + console.error("Invalid network"); + } + // Supply to ignore is the sum of the free - frozen of the accounts to substract + // which would otherwise end up in the total transferable variable + // that we define here as the circulating supply + if (accountsToSubstract.includes(String(account))) { + supplyToIgnore += free - frozen; + } + totalIssuance += free + reserved; totalTransferable += free - frozen; totalLocked += frozen; @@ -43,6 +62,7 @@ async function fetchTokenStats(network) { totalTransferable: format(totalTransferable), totalLocked: format(totalLocked), totalReserved: format(totalReserved), + totalCirculating: format(totalTransferable-supplyToIgnore), }; } @@ -148,3 +168,13 @@ exports.getTotalReserved = async (req, res, next) => { res.json(stats.totalReserved); }); }; + +/** + * Get token cirulating supply + * @public + */ +exports.getCirculatingSupply = async (req, res, next) => { + tryGetTokenStats({ req, res, next }, (stats) => { + res.json(stats.totalCirculating); + }); +}; diff --git a/src/api/routes/v1/stats.route.js b/src/api/routes/v1/stats.route.js index 884f594..e821ee4 100644 --- a/src/api/routes/v1/stats.route.js +++ b/src/api/routes/v1/stats.route.js @@ -63,4 +63,17 @@ router */ .get(controller.getTotalReserved); +router + .route("/circulatingsupply") + /** + * @api {get} token/stats/circulatingsupply Token circulating supply + * @apiDescription Get the current token adjusted circulating supply + * @apiVersion 1.0.0 + * @apiName ListTokenStatsCirculatingSupply + * + * @apiSuccess {Object[]} tokenStats List of token stats total adjusted circulating supply. + */ + .get(controller.getCirculatingSupply); + module.exports = router; + diff --git a/src/api/utils/circulating_accounts_to_ignore.js b/src/api/utils/circulating_accounts_to_ignore.js new file mode 100644 index 0000000..4b9195c --- /dev/null +++ b/src/api/utils/circulating_accounts_to_ignore.js @@ -0,0 +1,21 @@ +const ACCOUNTS_TO_SUBSTRACT_PENDULUM = [ + "6cY3Zrb2gr1xt3BczzJ3xoMpF7UyrcGNfR3cjkjcF7auq2Y9", + "6gfLdZvfW2w6fDaPpVfUs53W8Aay17s1bjwcFaqDaBVt7Muo", + "6biLQnLREwRd9aSPiN9xxR2UDCPa1XL3ZSwqNUxNEr3QvGDk", + "6eiGivQB9dtQUMs1VpxATipDYrewWSr4kGsvgjELgqnvRYyx", + "6gKuTtzLBtgYyW3SP6jh7DnXbNU8fDVFG2AxHCLbGYqaspe7", + "6cGTMDwqhePxUw5Fgfz8zHhJUhW7xkLRASSt6cwUmbSL137U", + "6gB6fuaAazhhctdcEfUmQDqHkzYBsdSHFoe7TAv8wSNdAgMx", + "6cABSUjhvnGP6fHrs8LRtzbvrvG9o9AtA92aakSSYpPtjP58", + "6gKxy1JM3FeUU9SB9BtQEzH8XTTZBPmyEjYYJBVFae23je5h", + "6eS2NM9rpKgM7HKVc5aksfSfyMqLWbKmqiavxQ9wxfvDnN7Y", + "6cE1nHQu9XRH6pUSjMejCUzF39XqFx3HwgZNTMHNTZZw2c7M", +] + +const ACCOUNTS_TO_SUBSTRACT_AMPLITUDE = [ +] + +module.exports = { + ACCOUNTS_TO_SUBSTRACT_PENDULUM, + ACCOUNTS_TO_SUBSTRACT_AMPLITUDE, +} \ No newline at end of file From d6a79659858e8352893bd9b7dda3bce31a058605 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Tue, 20 Feb 2024 18:29:48 -0300 Subject: [PATCH 2/4] improve comments --- src/api/controllers/token.controller.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/controllers/token.controller.js b/src/api/controllers/token.controller.js index 8e5ca10..af713d4 100644 --- a/src/api/controllers/token.controller.js +++ b/src/api/controllers/token.controller.js @@ -32,9 +32,11 @@ async function fetchTokenStats(network) { } else { console.error("Invalid network"); } - // Supply to ignore is the sum of the free - frozen of the accounts to substract - // which would otherwise end up in the total transferable variable - // that we define here as the circulating supply + + // We define the circulating supply as the total transferable (free - frozen) minus + // the total transferable of a set of predefined multisig accounts (https://github.com/pendulum-chain/tasks/issues/242) + // We keep track of the transferable of these accounts + // which will then will be substratect to the total transferable if (accountsToSubstract.includes(String(account))) { supplyToIgnore += free - frozen; } From 8a6e58219ab2d4c85555fbc1494dd8341578271e Mon Sep 17 00:00:00 2001 From: gianfra-t <96739519+gianfra-t@users.noreply.github.com> Date: Wed, 28 Feb 2024 06:04:49 -0300 Subject: [PATCH 3/4] Update src/api/controllers/token.controller.js Co-authored-by: Marcel Ebert --- src/api/controllers/token.controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/controllers/token.controller.js b/src/api/controllers/token.controller.js index af713d4..3801bd2 100644 --- a/src/api/controllers/token.controller.js +++ b/src/api/controllers/token.controller.js @@ -23,7 +23,7 @@ async function fetchTokenStats(network) { const free = BigInt(balances.free.replace(/,/g, "")); const reserved = BigInt(balances.reserved.replace(/,/g, "")); - // We mantain the supplyToIgnore to substract it from the total transferable + // We maintain the supplyToIgnore to substract it from the total transferable let accountsToSubstract = []; if (network === "amplitude") { accountsToSubstract = ACCOUNTS_TO_SUBSTRACT_AMPLITUDE; From 17cfcffa9d44b48de2a21f4cced849504536c734 Mon Sep 17 00:00:00 2001 From: Gianfranco Date: Wed, 28 Feb 2024 06:28:34 -0300 Subject: [PATCH 4/4] spelling corrections, comments --- src/api/controllers/token.controller.js | 14 +++++++------- src/api/routes/v1/stats.route.js | 2 +- ...culating_accounts_to_ignore.js => constants.js} | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) rename src/api/utils/{circulating_accounts_to_ignore.js => constants.js} (80%) diff --git a/src/api/controllers/token.controller.js b/src/api/controllers/token.controller.js index 3801bd2..5df0311 100644 --- a/src/api/controllers/token.controller.js +++ b/src/api/controllers/token.controller.js @@ -1,6 +1,6 @@ const memcached = require("../../config/memcached"); const { executeApiCall } = require("../services/rpc.service"); -const {ACCOUNTS_TO_SUBSTRACT_AMPLITUDE, ACCOUNTS_TO_SUBSTRACT_PENDULUM} = require("../utils/circulating_accounts_to_ignore"); +const {ACCOUNTS_TO_SUBTRACT_AMPLITUDE, ACCOUNTS_TO_SUBTRACT_PENDULUM} = require("../utils/constants"); async function fetchTokenStats(network) { console.log(`Fetching token stats for network ${network}`); @@ -23,12 +23,12 @@ async function fetchTokenStats(network) { const free = BigInt(balances.free.replace(/,/g, "")); const reserved = BigInt(balances.reserved.replace(/,/g, "")); - // We maintain the supplyToIgnore to substract it from the total transferable - let accountsToSubstract = []; + // We mantain the supplyToIgnore to subtract it from the total transferable + let accountsToSubtract = []; if (network === "amplitude") { - accountsToSubstract = ACCOUNTS_TO_SUBSTRACT_AMPLITUDE; + accountsToSubtract = ACCOUNTS_TO_SUBTRACT_AMPLITUDE; } else if (network === "pendulum") { - accountsToSubstract = ACCOUNTS_TO_SUBSTRACT_PENDULUM; + accountsToSubtract = ACCOUNTS_TO_SUBTRACT_PENDULUM; } else { console.error("Invalid network"); } @@ -36,8 +36,8 @@ async function fetchTokenStats(network) { // We define the circulating supply as the total transferable (free - frozen) minus // the total transferable of a set of predefined multisig accounts (https://github.com/pendulum-chain/tasks/issues/242) // We keep track of the transferable of these accounts - // which will then will be substratect to the total transferable - if (accountsToSubstract.includes(String(account))) { + // which will then be subtracted from the total transferable + if (accountsToSubtract.includes(String(account))) { supplyToIgnore += free - frozen; } diff --git a/src/api/routes/v1/stats.route.js b/src/api/routes/v1/stats.route.js index e821ee4..af1e850 100644 --- a/src/api/routes/v1/stats.route.js +++ b/src/api/routes/v1/stats.route.js @@ -67,7 +67,7 @@ router .route("/circulatingsupply") /** * @api {get} token/stats/circulatingsupply Token circulating supply - * @apiDescription Get the current token adjusted circulating supply + * @apiDescription Get the current token stats for adjusted circulating supply * @apiVersion 1.0.0 * @apiName ListTokenStatsCirculatingSupply * diff --git a/src/api/utils/circulating_accounts_to_ignore.js b/src/api/utils/constants.js similarity index 80% rename from src/api/utils/circulating_accounts_to_ignore.js rename to src/api/utils/constants.js index 4b9195c..4ea679d 100644 --- a/src/api/utils/circulating_accounts_to_ignore.js +++ b/src/api/utils/constants.js @@ -1,4 +1,4 @@ -const ACCOUNTS_TO_SUBSTRACT_PENDULUM = [ +const ACCOUNTS_TO_SUBTRACT_PENDULUM = [ "6cY3Zrb2gr1xt3BczzJ3xoMpF7UyrcGNfR3cjkjcF7auq2Y9", "6gfLdZvfW2w6fDaPpVfUs53W8Aay17s1bjwcFaqDaBVt7Muo", "6biLQnLREwRd9aSPiN9xxR2UDCPa1XL3ZSwqNUxNEr3QvGDk", @@ -12,10 +12,10 @@ const ACCOUNTS_TO_SUBSTRACT_PENDULUM = [ "6cE1nHQu9XRH6pUSjMejCUzF39XqFx3HwgZNTMHNTZZw2c7M", ] -const ACCOUNTS_TO_SUBSTRACT_AMPLITUDE = [ +const ACCOUNTS_TO_SUBTRACT_AMPLITUDE = [ ] module.exports = { - ACCOUNTS_TO_SUBSTRACT_PENDULUM, - ACCOUNTS_TO_SUBSTRACT_AMPLITUDE, + ACCOUNTS_TO_SUBTRACT_PENDULUM, + ACCOUNTS_TO_SUBTRACT_AMPLITUDE, } \ No newline at end of file