Sub-Adapters 2
Preview and test each sub adapter.
Terra - Transaction Fees (terra-tx-fees)
Terra - Swap Fees (terra-swap-fees)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Terra Fees - Flipside';
2export const version = '0.2.1';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6 const getTerraTxFees = async (date: string) => {
7 // https://app.flipsidecrypto.com/velocity/queries/60060737-ef42-40fc-89c0-ead270fca473
8 const priceData = await sdk.http.get('https://api.flipsidecrypto.com/api/v2/queries/60060737-ef42-40fc-89c0-ead270fca473/data/latest');
9 // https://app.flipsidecrypto.com/velocity/queries/9e29d2d1-4700-48e4-83eb-8478f4585c3b
10 const feeData = await sdk.http.get('https://api.flipsidecrypto.com/api/v2/queries/9e29d2d1-4700-48e4-83eb-8478f4585c3b/data/latest');
11
12 const prices: any = {}
13 for (const price of priceData) {
14 if (price.DATE === `${date} 00:00:00.000`) {
15 prices[price.CURRENCY] = price.PRICE;
16 }
17 }
18
19 let total = 0;
20 for (const fee of feeData) {
21 if (fee.DATE === `${date} 00:00:00.000` && prices[fee.DENOM]) {
22 total += fee.AMT * prices[fee.DENOM] / 1e6;
23 }
24 }
25
26 return total;
27 }
28
29 const getTerraSwapFees = async (date: string) => {
30 // https://app.flipsidecrypto.com/velocity/queries/d905a6ed-ccc9-4075-a663-7aa48a3aa3ff
31 const swapFeeData = await sdk.http.get('https://api.flipsidecrypto.com/api/v2/queries/d905a6ed-ccc9-4075-a663-7aa48a3aa3ff/data/latest');
32
33 let low = 0;
34 let high = swapFeeData.length - 1;
35 while (low <= high) {
36 const mid = Math.floor((low + high) / 2);
37
38 if (swapFeeData[mid].DATE === `${date} 00:00:00.000`) {
39 return swapFeeData[mid].SWAP_FEES;
40 } else if (new Date(date) < new Date(swapFeeData[mid].DATE)) {
41 high = mid - 1;
42 } else {
43 low = mid + 1;
44 }
45 }
46 throw new Error(`Unable to find terra day ${date}`);
47 }
48
49 const metadata = {
50 name: 'Terra',
51 icon: sdk.ipfs.getDataURILoader('QmPhpTU6jPHYSHYDt7qxueXdMBmmiFEv4xcj1cYTz8euta', 'image/svg+xml'),
52 category: 'l1',
53 description: 'Terra is a blockchain built on fiat-pegged stablecoins.',
54 feeDescription: 'Terra stakers earn rewards from gas fees, "taxes" and seigniorage rewards.',
55 blockchain: 'Terra',
56 source: 'Flipside',
57 website: 'https://terra.money',
58 tokenTicker: 'LUNA',
59 tokenCoingecko: 'terra-luna',
60 tokenLaunch: '2019-05-08',
61 protocolLaunch: '2019-05-06',
62 }
63
64 sdk.register({
65 id: 'terra-tx-fees',
66 bundle: 'terra',
67 queries: {
68 oneDayTotalFees: getTerraTxFees,
69 },
70 metadata: {
71 ...metadata,
72 subtitle: 'Transaction Fees',
73 feeDescription: 'Terra stakers earn transaction fees from users.',
74 },
75 });
76
77 sdk.register({
78 id: 'terra-swap-fees',
79 bundle: 'terra',
80 queries: {
81 oneDayTotalFees: getTerraSwapFees,
82 },
83 metadata: {
84 ...metadata,
85 subtitle: 'Swap Fees',
86 category: 'dex',
87 feeDescription: 'LUNA is burned and minted as trades are executed.',
88 },
89 });
90
91 sdk.registerBundle('terra', metadata);
92}
93
It's something off?
Report it to the discussion board on Discord, we will take care of it.