|
| 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 | +); |
0 commit comments