Skip to content

Commit

Permalink
TW-1537 Add TKEY stats endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
lourenc committed Sep 10, 2024
1 parent b369658 commit 43e0cd2
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Check failure on line 42 in src/index.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

`./tkey-stats` import should occur before import of `./utils/ab-test`

const PINO_LOGGER = {
logger: logger.child({ name: 'web' }),
Expand Down Expand Up @@ -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;
Expand Down
44 changes: 44 additions & 0 deletions src/tkey-stats.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import memoizee from 'memoizee';
import axios from 'axios';

Check failure on line 2 in src/tkey-stats.ts

View workflow job for this annotation

GitHub Actions / Checks if ts and lint works

`axios` import should occur before import of `memoizee`

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
}
);
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
/* Basic Options */
"target": "ES2019",
"target": "ES2020",
"module": "commonjs",
"lib": ["esnext"],
"allowJs": true,
Expand Down

0 comments on commit 43e0cd2

Please sign in to comment.