-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* TW-1537 Add TKEY stats endpoint * TW-1537 Fix linter errors * TW-1537 Fetch incentives, developer rewards and investment fund dynamically
- Loading branch information
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import axios from 'axios'; | ||
import memoizee from 'memoizee'; | ||
|
||
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 getTkeyBalance = memoizee( | ||
async (holder: string) => { | ||
const response = await axios.get( | ||
`https://api.tzkt.io/v1/tokens/balances?account=${holder}&token.contract=${CONTRACT}` | ||
); | ||
|
||
return BigInt(response.data[0].balance) / 10n ** DECIMALS; | ||
}, | ||
{ | ||
maxAge: 1000 * 60 * 60 // 1 hour | ||
} | ||
); | ||
|
||
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 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: developerRewards.toString(), | ||
totalSupply: TOTAL_SUPPLY_WITH_DECIMALS.toString(), | ||
circulating: circulating.toString(), | ||
burned: burned.toString() | ||
}; | ||
}, | ||
{ | ||
maxAge: 1000 * 60 * 60 // 1 hour | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters