Skip to content

Commit e95969e

Browse files
authored
TW-1537 Add TKEY stats endpoint (#173) (#175)
* TW-1537 Add TKEY stats endpoint * TW-1537 Fix linter errors * TW-1537 Fetch incentives, developer rewards and investment fund dynamically
1 parent dd06c1a commit e95969e

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { getPlatforms } from './notifications/utils/get-platforms.util';
2222
import { redisClient } from './redis';
2323
import { evmRouter } from './routers/evm';
2424
import { adRulesRouter } from './routers/slise-ad-rules';
25+
import { getTkeyStats } from './tkey-stats';
2526
import { getABData } from './utils/ab-test';
2627
import { cancelAliceBobOrder } from './utils/alice-bob/cancel-alice-bob-order';
2728
import { createAliceBobOrder } from './utils/alice-bob/create-alice-bob-order';
@@ -105,6 +106,10 @@ app.get('/api/top-coins', (_req, res) => {
105106
res.status(200).send(coinGeckoTokens);
106107
});
107108

109+
app.get('/api/tkey', async (_req, res) => {
110+
res.send(await getTkeyStats());
111+
});
112+
108113
app.get('/api/notifications', async (_req, res) => {
109114
try {
110115
const { platform, startFromTime } = _req.query;

src/tkey-stats.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import axios from 'axios';
2+
import memoizee from 'memoizee';
3+
4+
const BURN_ADDRESS = 'tz1burnburnburnburnburnburnburjAYjjX';
5+
const INCENTIVES_ADDRESS = 'tz1Ntpk55Q6AVJHVrCs1uN4HyTTxBbVMFZcb';
6+
const INVESTMENT_ADDRESS = 'tz1imUX3aTc4HX6KygaQUe8e1sQqYvGs6eCF';
7+
const DEVELOPER_REWARDS_ADDRESS = 'tz1bxHEHAtKubVy44vBDFVEZ1iqYPYdJVS9U';
8+
const CONTRACT = 'KT1VaEsVNiBoA56eToEK6n6BcPgh1tdx9eXi';
9+
const DECIMALS = 18n;
10+
const TOTAL_SUPPLY = 14_000_000_000_000_000_000_000_000n;
11+
const TOTAL_SUPPLY_WITH_DECIMALS = TOTAL_SUPPLY / 10n ** DECIMALS;
12+
13+
const getTkeyBalance = memoizee(
14+
async (holder: string) => {
15+
const response = await axios.get(
16+
`https://api.tzkt.io/v1/tokens/balances?account=${holder}&token.contract=${CONTRACT}`
17+
);
18+
19+
return BigInt(response.data[0].balance) / 10n ** DECIMALS;
20+
},
21+
{
22+
maxAge: 1000 * 60 * 60 // 1 hour
23+
}
24+
);
25+
26+
const getBurnedTokens = () => getTkeyBalance(BURN_ADDRESS);
27+
const getInvestmentFund = () => getTkeyBalance(INVESTMENT_ADDRESS);
28+
const getIncentivesFund = () => getTkeyBalance(INCENTIVES_ADDRESS);
29+
const getDeveloperRewardsFund = () => getTkeyBalance(DEVELOPER_REWARDS_ADDRESS);
30+
31+
export const getTkeyStats = memoizee(
32+
async () => {
33+
const burned = await getBurnedTokens();
34+
const incentives = await getIncentivesFund();
35+
const investment = await getInvestmentFund();
36+
const developerRewards = await getDeveloperRewardsFund();
37+
38+
const circulating = TOTAL_SUPPLY_WITH_DECIMALS - incentives - developerRewards - investment - burned;
39+
40+
return {
41+
incentivesFund: incentives.toString(),
42+
investmentFund: investment.toString(),
43+
developerRewardsFund: developerRewards.toString(),
44+
totalSupply: TOTAL_SUPPLY_WITH_DECIMALS.toString(),
45+
circulating: circulating.toString(),
46+
burned: burned.toString()
47+
};
48+
},
49+
{
50+
maxAge: 1000 * 60 * 60 // 1 hour
51+
}
52+
);

tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"compilerOptions": {
33
/* Basic Options */
4-
"target": "ES2019",
4+
"target": "ES2020",
55
"module": "commonjs",
66
"lib": ["esnext"],
77
"allowJs": true,

0 commit comments

Comments
 (0)