From 43e0cd2c74a493d5fbe03ca50b8ac92870fe3259 Mon Sep 17 00:00:00 2001 From: Korney Vasilchenko Date: Tue, 10 Sep 2024 12:59:02 +0100 Subject: [PATCH 1/3] TW-1537 Add TKEY stats endpoint --- src/index.ts | 5 +++++ src/tkey-stats.ts | 44 ++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 2 +- 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 src/tkey-stats.ts diff --git a/src/index.ts b/src/index.ts index 66a1771..88dbeb9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -39,6 +39,7 @@ import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url'; import { getSigningNonce } from './utils/signing-nonce'; import SingleQueryDataProvider from './utils/SingleQueryDataProvider'; import { getExchangeRates } from './utils/tokens'; +import { getTkeyStats } from './tkey-stats'; const PINO_LOGGER = { logger: logger.child({ name: 'web' }), @@ -105,6 +106,10 @@ app.get('/api/top-coins', (_req, res) => { res.status(200).send(coinGeckoTokens); }); +app.get('/api/tkey', async (_req, res) => { + res.send(await getTkeyStats()); +}); + app.get('/api/notifications', async (_req, res) => { try { const { platform, startFromTime } = _req.query; diff --git a/src/tkey-stats.ts b/src/tkey-stats.ts new file mode 100644 index 0000000..c93a862 --- /dev/null +++ b/src/tkey-stats.ts @@ -0,0 +1,44 @@ +import memoizee from 'memoizee'; +import axios from 'axios'; + +const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi'; +const BURN_ADDRESS = 'tz1burnburnburnburnburnburnburjAYjjX'; +const DECIMALS = 18n; +const TOTAL_SUPPLY = 14_000_000_000_000_000_000_000_000n; +const TOTAL_SUPPLY_WITH_DECIMALS = TOTAL_SUPPLY / 10n ** DECIMALS; + +const INCENTIVES = 1_000_000n; +const INVESTMENT = 1_000_000n; +const DEVELOPER_REWARDS = 2_000_000n; + +const getBurnedTokens = memoizee( + async () => { + const response = await axios.get( + `https://api.tzkt.io/v1/tokens/balances?account=${BURN_ADDRESS}&token.contract=${CONTRACT}` + ); + + return BigInt(response.data[0].balance) / 10n ** DECIMALS; + }, + { + maxAge: 1000 * 60 * 60 // 1 hour + } +); + +export const getTkeyStats = memoizee( + async () => { + const burned = await getBurnedTokens(); + const circulating = TOTAL_SUPPLY_WITH_DECIMALS - INCENTIVES - DEVELOPER_REWARDS - INVESTMENT - burned; + + return { + incentivesFund: INCENTIVES.toString(), + investmentFund: INVESTMENT.toString(), + developerRewardsFund: DEVELOPER_REWARDS.toString(), + totalSupply: TOTAL_SUPPLY_WITH_DECIMALS.toString(), + circulatingSupply: circulating.toString(), + burned: burned.toString() + }; + }, + { + maxAge: 1000 * 60 * 60 // 1 hour + } +); diff --git a/tsconfig.json b/tsconfig.json index 87d512f..aa0ae21 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { /* Basic Options */ - "target": "ES2019", + "target": "ES2020", "module": "commonjs", "lib": ["esnext"], "allowJs": true, From d3222494ff2d8881bd5318a151c8abb321cf3952 Mon Sep 17 00:00:00 2001 From: Korney Vasilchenko Date: Tue, 10 Sep 2024 13:01:28 +0100 Subject: [PATCH 2/3] TW-1537 Fix linter errors --- src/index.ts | 2 +- src/tkey-stats.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 88dbeb9..35f8f26 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,6 +22,7 @@ import { getPlatforms } from './notifications/utils/get-platforms.util'; import { redisClient } from './redis'; import { evmRouter } from './routers/evm'; import { adRulesRouter } from './routers/slise-ad-rules'; +import { getTkeyStats } from './tkey-stats'; import { getABData } from './utils/ab-test'; import { cancelAliceBobOrder } from './utils/alice-bob/cancel-alice-bob-order'; import { createAliceBobOrder } from './utils/alice-bob/create-alice-bob-order'; @@ -39,7 +40,6 @@ import { getSignedMoonPayUrl } from './utils/moonpay/get-signed-moonpay-url'; import { getSigningNonce } from './utils/signing-nonce'; import SingleQueryDataProvider from './utils/SingleQueryDataProvider'; import { getExchangeRates } from './utils/tokens'; -import { getTkeyStats } from './tkey-stats'; const PINO_LOGGER = { logger: logger.child({ name: 'web' }), diff --git a/src/tkey-stats.ts b/src/tkey-stats.ts index c93a862..7ca4975 100644 --- a/src/tkey-stats.ts +++ b/src/tkey-stats.ts @@ -1,5 +1,5 @@ -import memoizee from 'memoizee'; import axios from 'axios'; +import memoizee from 'memoizee'; const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi'; const BURN_ADDRESS = 'tz1burnburnburnburnburnburnburjAYjjX'; From ffca30cf5b8046a3bf56d7237ddf30f15e14ba7a Mon Sep 17 00:00:00 2001 From: Korney Vasilchenko Date: Tue, 10 Sep 2024 13:16:34 +0100 Subject: [PATCH 3/3] TW-1537 Fetch incentives, developer rewards and investment fund dynamically --- src/tkey-stats.ts | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/src/tkey-stats.ts b/src/tkey-stats.ts index 7ca4975..bbcc38c 100644 --- a/src/tkey-stats.ts +++ b/src/tkey-stats.ts @@ -1,20 +1,19 @@ import axios from 'axios'; import memoizee from 'memoizee'; -const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi'; const BURN_ADDRESS = 'tz1burnburnburnburnburnburnburjAYjjX'; +const INCENTIVES_ADDRESS = 'tz1Ntpk55Q6AVJHVrCs1uN4HyTTxBbVMFZcb'; +const INVESTMENT_ADDRESS = 'tz1imUX3aTc4HX6KygaQUe8e1sQqYvGs6eCF'; +const DEVELOPER_REWARDS_ADDRESS = 'tz1bxHEHAtKubVy44vBDFVEZ1iqYPYdJVS9U'; +const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi'; const DECIMALS = 18n; const TOTAL_SUPPLY = 14_000_000_000_000_000_000_000_000n; const TOTAL_SUPPLY_WITH_DECIMALS = TOTAL_SUPPLY / 10n ** DECIMALS; -const INCENTIVES = 1_000_000n; -const INVESTMENT = 1_000_000n; -const DEVELOPER_REWARDS = 2_000_000n; - -const getBurnedTokens = memoizee( - async () => { +const getTkeyBalance = memoizee( + async (holder: string) => { const response = await axios.get( - `https://api.tzkt.io/v1/tokens/balances?account=${BURN_ADDRESS}&token.contract=${CONTRACT}` + `https://api.tzkt.io/v1/tokens/balances?account=${holder}&token.contract=${CONTRACT}` ); return BigInt(response.data[0].balance) / 10n ** DECIMALS; @@ -24,17 +23,26 @@ const getBurnedTokens = memoizee( } ); +const getBurnedTokens = () => getTkeyBalance(BURN_ADDRESS); +const getInvestmentFund = () => getTkeyBalance(INVESTMENT_ADDRESS); +const getIncentivesFund = () => getTkeyBalance(INCENTIVES_ADDRESS); +const getDeveloperRewardsFund = () => getTkeyBalance(DEVELOPER_REWARDS_ADDRESS); + export const getTkeyStats = memoizee( async () => { const burned = await getBurnedTokens(); - const circulating = TOTAL_SUPPLY_WITH_DECIMALS - INCENTIVES - DEVELOPER_REWARDS - INVESTMENT - burned; + const incentives = await getIncentivesFund(); + const investment = await getInvestmentFund(); + const developerRewards = await getDeveloperRewardsFund(); + + const circulating = TOTAL_SUPPLY_WITH_DECIMALS - incentives - developerRewards - investment - burned; return { - incentivesFund: INCENTIVES.toString(), - investmentFund: INVESTMENT.toString(), - developerRewardsFund: DEVELOPER_REWARDS.toString(), + incentivesFund: incentives.toString(), + investmentFund: investment.toString(), + developerRewardsFund: developerRewards.toString(), totalSupply: TOTAL_SUPPLY_WITH_DECIMALS.toString(), - circulatingSupply: circulating.toString(), + circulating: circulating.toString(), burned: burned.toString() }; },