diff --git a/src/api/controllers/token.controller.js b/src/api/controllers/token.controller.js index b04e0eb..5df0311 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_SUBTRACT_AMPLITUDE, ACCOUNTS_TO_SUBTRACT_PENDULUM} = require("../utils/constants"); 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,24 @@ async function fetchTokenStats(network) { const free = BigInt(balances.free.replace(/,/g, "")); const reserved = BigInt(balances.reserved.replace(/,/g, "")); + // We mantain the supplyToIgnore to subtract it from the total transferable + let accountsToSubtract = []; + if (network === "amplitude") { + accountsToSubtract = ACCOUNTS_TO_SUBTRACT_AMPLITUDE; + } else if (network === "pendulum") { + accountsToSubtract = ACCOUNTS_TO_SUBTRACT_PENDULUM; + } else { + console.error("Invalid 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 be subtracted from the total transferable + if (accountsToSubtract.includes(String(account))) { + supplyToIgnore += free - frozen; + } + totalIssuance += free + reserved; totalTransferable += free - frozen; totalLocked += frozen; @@ -43,6 +64,7 @@ async function fetchTokenStats(network) { totalTransferable: format(totalTransferable), totalLocked: format(totalLocked), totalReserved: format(totalReserved), + totalCirculating: format(totalTransferable-supplyToIgnore), }; } @@ -148,3 +170,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..af1e850 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 stats for 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/constants.js b/src/api/utils/constants.js new file mode 100644 index 0000000..4ea679d --- /dev/null +++ b/src/api/utils/constants.js @@ -0,0 +1,21 @@ +const ACCOUNTS_TO_SUBTRACT_PENDULUM = [ + "6cY3Zrb2gr1xt3BczzJ3xoMpF7UyrcGNfR3cjkjcF7auq2Y9", + "6gfLdZvfW2w6fDaPpVfUs53W8Aay17s1bjwcFaqDaBVt7Muo", + "6biLQnLREwRd9aSPiN9xxR2UDCPa1XL3ZSwqNUxNEr3QvGDk", + "6eiGivQB9dtQUMs1VpxATipDYrewWSr4kGsvgjELgqnvRYyx", + "6gKuTtzLBtgYyW3SP6jh7DnXbNU8fDVFG2AxHCLbGYqaspe7", + "6cGTMDwqhePxUw5Fgfz8zHhJUhW7xkLRASSt6cwUmbSL137U", + "6gB6fuaAazhhctdcEfUmQDqHkzYBsdSHFoe7TAv8wSNdAgMx", + "6cABSUjhvnGP6fHrs8LRtzbvrvG9o9AtA92aakSSYpPtjP58", + "6gKxy1JM3FeUU9SB9BtQEzH8XTTZBPmyEjYYJBVFae23je5h", + "6eS2NM9rpKgM7HKVc5aksfSfyMqLWbKmqiavxQ9wxfvDnN7Y", + "6cE1nHQu9XRH6pUSjMejCUzF39XqFx3HwgZNTMHNTZZw2c7M", +] + +const ACCOUNTS_TO_SUBTRACT_AMPLITUDE = [ +] + +module.exports = { + ACCOUNTS_TO_SUBTRACT_PENDULUM, + ACCOUNTS_TO_SUBTRACT_AMPLITUDE, +} \ No newline at end of file