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.2';
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    protocolShutdown: '2022-05-27',
63  }
64
65  sdk.register({
66    id: 'terra-tx-fees',
67    bundle: 'terra',
68    queries: {
69      oneDayTotalFees: getTerraTxFees,
70    },
71    metadata: {
72      ...metadata,
73      subtitle: 'Transaction Fees',
74      feeDescription: 'Terra stakers earn transaction fees from users.',
75    },
76  });
77
78  sdk.register({
79    id: 'terra-swap-fees',
80    bundle: 'terra',
81    queries: {
82      oneDayTotalFees: getTerraSwapFees,
83    },
84    metadata: {
85      ...metadata,
86      subtitle: 'Swap Fees',
87      category: 'dex',
88      feeDescription: 'LUNA is burned and minted as trades are executed.',
89    },
90  });
91
92  sdk.registerBundle('terra', metadata);
93}
94

It's something off?

Report it to the discussion board on Discord, we will take care of it.

Adapter Info

Version

0.2.2

License

MIT

IPFS CID

Qmf4dGdLKzrtxfagS8iawXzttjzivevyDWgKd3oqh6hKxB

CID (source)

QmRod2UwwwJAuoSKiZF9QKnrNFEHdVygbTwiVagc3NJJxM

Collections

Author

mihal.eth