Sub-Adapters 2

Preview and test each sub adapter.

GMX - Arbitrum (gmx-arbitrum)

GMX - Avalanche (gmx-avax)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'GMX Fees';
2export const version = '0.2.0';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getFeesData = (subgraph: string, postFix = '') => async (date: string): Promise<number> => {
7    const graphQuery = `query fees($date: String!, $nextDay: String!) {
8      feeStat(id: $date) {
9        mint
10        burn
11        marginAndLiquidation
12        swap
13      }
14      nextDay: feeStat(id: $nextDay) {
15        id
16      }
17    }`;
18    const data = await sdk.graph.query(subgraph, graphQuery, {
19      date: sdk.date.dateToTimestamp(date) + postFix,
20      nextDay: sdk.date.dateToTimestamp(sdk.date.getNextDay(date)) + postFix,
21    });
22
23    if (!data.nextDay) {
24      throw new Error('Day incomplete');
25    }
26
27    const totalFees =
28      parseInt(data.feeStat.mint)
29      + parseInt(data.feeStat.burn)
30      + parseInt(data.feeStat.marginAndLiquidation)
31      + parseInt(data.feeStat.swap)
32    return totalFees / 1e30;
33  }
34
35  const getVolumeData = (subgraph: string, postFix = '') => async (date: string): Promise<number> => {
36    const graphQuery = `query volume($date: String!, $nextDay: String!) {
37      volumeStat(id: $date) {
38        mint
39        burn
40        margin
41        liquidation
42        swap
43      }
44      nextDay: volumeStat(id: $nextDay) {
45        id
46      }
47    }`;
48
49    const data = await sdk.graph.query(subgraph, graphQuery, {
50      date: sdk.date.dateToTimestamp(date) + postFix,
51      nextDay: sdk.date.dateToTimestamp(date) + postFix,
52    });
53
54    if (!data.nextDay) {
55      throw new Error('Day incomplete');
56    }
57
58    const totalVolume =
59      parseInt(data.volumeStats[0].mint)
60      + parseInt(data.volumeStats[0].burn)
61      + parseInt(data.volumeStats[0].margin)
62      + parseInt(data.volumeStats[0].liquidation)
63      + parseInt(data.volumeStats[0].swap)
64    return totalVolume / 1e30;
65  }
66
67  const metadata = {
68    name: 'GMX',
69    icon: sdk.ipfs.getDataURILoader('QmQUsrPhXc8tJzTzz9K78YCoeGZ7mxx1ZuHvyQ5Pcw5jAP', 'image/svg+xml'),
70    protocolLaunch: '2021-09-01',
71    category: 'dex',
72    description: 'GMX is a decentralized spot and perpetual exchange that supports low swap fees and zero price impact trades.',
73    feeDescription: 'All fees generated from swaps and leverage trading are distributed to GMX stakers and GLP liquidity providers.',
74    blockchain: 'Arbitrum One',
75    source: 'The Graph Protocol',
76    website: 'https://gmx.io',
77    tokenTicker: 'GMX',
78    tokenCoingecko: 'gmx',    
79  };
80
81  sdk.register({
82    id: 'gmx-arbitrum',
83    bundle: 'gmx',
84    queries: {
85      oneDayTotalFees: getFeesData('gmx-io/gmx-stats'),
86      oneDayTotalVolumeUSD: getVolumeData('gmx-io/gmx-stats'),
87    },
88    metadata: {
89      ...metadata,
90      subtitle: 'Arbitrum',
91      blockchain: 'Arbitrum One',
92      protocolLaunch: '2021-09-01',
93    },
94  });
95  
96  sdk.register({
97    id: 'gmx-avax',
98    bundle: 'gmx',
99    queries: {
100      oneDayTotalFees: getFeesData('gmx-io/gmx-avalanche-stats', ':daily'),
101      oneDayTotalVolumeUSD: getVolumeData('gmx-io/gmx-avalanche-stats', ':daily'),
102    },
103    metadata: {
104      ...metadata,
105      subtitle: 'Avalanche',
106      blockchain: 'Avalanche',
107      protocolLaunch: '2022-01-06',
108    },
109  })
110
111  sdk.registerBundle('gmx', metadata);
112}

It's something off?

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

Adapter Info

Version

0.2.0

License

MIT

IPFS CID

QmYZN6zcKcdBJAXEeERvbDc8LgN7bConszJzsoqTVxpCqd

CID (source)

QmQNZbnXx1p2bqXVu7Ng9o2tmzcW2wExg9GU4FGJ2UiXuv

Collections

Author

mihal.eth