Sub-Adapters 4
Preview and test each sub adapter.
Hop Protocol - Optimism (hop-optimism)
Hop Protocol - Gnosis Chain (hop-gnosis-chain)
Hop Protocol - Arbitrum One (hop-arbitrum)
Hop Protocol - Polygon (hop-polygon)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source. 
1export const name = 'Hop Protocol Fees';
2export const version = '0.1.2';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const getHopFeeHandler = (network: string, subgraph: string) => async (date: string): Promise<number> => {
7    const startOfDayBlock = await sdk.chainData.getBlockNumber(date, network);
8    const nextDayDate = sdk.date.offsetDaysFormatted(date, 1);
9    const endOfDayBlock = await sdk.chainData.getBlockNumber(nextDayDate, network);
10
11    const data = await sdk.graph.query(
12      subgraph,
13      `query txFees($startOfDay: Int!, $endOfDay: Int!){
14        startOfDayAMM: ammFees(block: {number: $startOfDay}) {
15          token
16          amount
17        }
18        startOfDayBonder: bonderFees(block: {number: $startOfDay}) {
19          token
20          amount
21        }
22        endOfDayAMM: ammFees(block: {number: $endOfDay}) {
23          token
24          amount
25        }
26        endOfDayBonder: bonderFees(block: {number: $endOfDay}) {
27          token
28          amount
29        }
30      }`,
31      {
32        variables: {
33          startOfDay: startOfDayBlock,
34          endOfDay: endOfDayBlock,
35        },
36      },
37    );
38
39    let startOfDayTotal = 0;
40    let startOfDayETH = 0;
41
42    const startOfDayFees = [...data.startOfDayAMM, ...data.startOfDayBonder];
43    // @ts-ignore
44    console.log(data);
45    for (const day of startOfDayFees) {
46      if (day.token === 'USDC' || day.token === 'USDT') {
47        startOfDayTotal += day.amount / 1e6;
48      } else if (day.token === 'ETH') {
49        startOfDayETH += day.amount / 1e18;
50      } else {
51        // Warn: unknown pool
52      }
53    }
54
55    let endOfDayTotal = 0;
56    let endOfDayETH = 0;
57
58    const endOfDayFees = [...data.endOfDayAMM, ...data.endOfDayBonder];
59    for (const day of endOfDayFees) {
60      if (day.token === 'USDC' || day.token === 'USDT') {
61        endOfDayTotal += day.amount / 1e6;
62      } else if (day.token === 'ETH') {
63        endOfDayETH += day.amount / 1e18;
64      } else {
65        // Warn: unknown pool
66      }
67    }
68
69    const totalStables = endOfDayTotal - startOfDayTotal;
70    const totalETH = endOfDayETH - startOfDayETH;
71
72    const ethPrice = totalETH > 0
73      ? await sdk.coinGecko.getHistoricalPrice('ethereum', date)
74      : 0;
75
76    return totalStables + (totalETH * ethPrice);
77  }
78
79  const metadata = {
80    name: 'Hop Protocol',
81    category: 'xchain',
82    description: 'Hop protocol is a decentralized token bridge between Ethereum scaling solutions.',
83    feeDescription: 'Trading fees are paid to liquidity providers and bonder fees are paid to cross-chain bonders',
84    source: 'The Graph Protocol',
85    website: 'https://hop.exchange',
86    protocolLaunch: '2020-09-09',
87    icon: sdk.ipfs.getDataURILoader('Qma6xqAk9BksRvPZvTtJZs1BrPaAxAEyeY7ufWvAmteKso', 'image/svg+xml'),
88  };
89
90  sdk.registerBundle('hop', metadata);
91
92  sdk.register({
93    id: 'hop-optimism',
94    bundle: 'hop',
95    queries: {
96      oneDayTotalFees: getHopFeeHandler('optimism', 'hop-protocol/hop-optimism'),
97    },
98    metadata: {
99      ...metadata,
100      subtitle: 'Optimism',
101      blockchain: 'Optimism',
102      protocolLaunch: '2021-08-24',
103    },
104  });
105
106  sdk.register({
107    id: 'hop-gnosis-chain',
108    bundle: 'hop',
109    queries: {
110      oneDayTotalFees: getHopFeeHandler('xdai', 'hop-protocol/hop-xdai'),
111    },
112    metadata: {
113      ...metadata,
114      subtitle: 'Gnosis Chain',
115      blockchain: 'Gnosis Chain',
116    },
117  });
118
119  sdk.register({
120    id: 'hop-arbitrum',
121    bundle: 'hop',
122    queries: {
123      oneDayTotalFees: getHopFeeHandler('arbitrum-one', 'hop-protocol/hop-arbitrum'),
124    },
125    metadata: {
126      ...metadata,
127      subtitle: 'Arbitrum One',
128      blockchain: 'Arbitrum One',
129      protocolLaunch: '2021-09-01',
130    },
131  });
132
133  sdk.register({
134    id: 'hop-polygon',
135    bundle: 'hop',
136    queries: {
137      oneDayTotalFees: getHopFeeHandler('polygon', 'hop-protocol/hop-polygon'),
138    },
139    metadata: {
140      ...metadata,
141      subtitle: 'Polygon',
142      blockchain: 'Polygon',
143    },
144  });
145}
146
It's something off?
Report it to the discussion board on Discord, we will take care of it.