Sub-Adapters 6

Preview and test each sub adapter.

SushiSwap - Ethereum (sushiswap-ethereum)

SushiSwap - Polygon (sushiswap-polygon)

SushiSwap - Fantom (sushiswap-fantom)

SushiSwap - Arbitrum One (sushiswap-arbitrum-one)

SushiSwap - Avalanche (sushiswap-avalanche)

SushiSwap - Binance (sushiswap-binance)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'SushiSwap Fees';
2export const version = '1.0.3';
3export const license = 'MIT';
4
5interface NetInfo {
6  subgraph: string;
7  factory: string;
8  blockchain: string;
9  protocolLaunch: string;
10  blacklist?: string[];
11}
12
13const networks: { [network: string]: NetInfo } = {
14  ethereum: {
15    subgraph: 'sushiswap/exchange',
16    factory: '0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac',
17    blockchain: 'Ethereum',
18    protocolLaunch: '2020-09-09',
19  },
20  polygon: {
21    subgraph: 'sushiswap/matic-exchange',
22    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
23    blockchain: 'Polygon',
24    protocolLaunch: '2021-02-26',
25  },
26  fantom: {
27    subgraph: 'sushiswap/fantom-exchange',
28    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
29    blockchain: 'Fantom',
30    protocolLaunch: '2021-02-26',
31  },
32  'arbitrum-one': {
33    subgraph: 'sushiswap/arbitrum-exchange',
34    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
35    blockchain: 'Arbitrum One',
36    protocolLaunch: '2021-08-31',
37    blacklist: [
38      '0x2f8fe2fbb99b80e0ccb97fc89ab59dd8901ebec4',
39      '0x89c273fa22bf1d21ce8afeb7c5a71df1b4ed608c',
40      '0xe0ed3e29afa55d0ac1470354fd30519316246594',
41      '0x09960d053b796415671cc4123cc6fb39973ed305',
42      '0xddd71d6fee63cda7cc6f151451f2c1cf739e745c',
43      '0xec363d9ccabe97c974b6209e08eae5110c411204',
44      '0x714689bc4cb5b5b3d5b2ffc9546f1cefaeeb78bc',
45      '0xcbefb6423cf3c7c9a9901930eb14266ff40a99cd',
46      '0x724f91c7f0a12f4b4cf95abb134548793577e4b7',
47      '0x37f6558ce7d210396da6876615998cea0c8c6bad',
48      '0x91917f056fb6f668f47dc9b9a36b697146b4af1b',
49      '0x0d61b5cfafd64b917f3a182a31c120f0c4341b06',
50      '0x4dba8798ea3e5be03345a65b61d362f0a6fda74c',
51      '0x34ff63ab5f638c0947309ab2c26fbbae26ae3fac',
52      '0x479373f0be596f2326d7edda81a14a265ea451c0',
53      '0x23491d3d72a60c59ee2508f84be80dcf779563a0',
54      '0x6bd9d9b824fc680ab90407ccb3c5b0e8d1ae5734',
55      '0x821c69bb168f21fb82c25a95d1770fffc18517ab',
56      '0x87672c17fc72b044323dd41966b48317893e822a',
57      '0x6cf69dae87de36acfcae3172e5525c7a99deb303',
58      '0xf315b2c32dc8d774d28028389c79cb03c9f7b4c3',
59      '0x5e8b8d2226408e476bd11d88eb1f895f6f776e73',
60      '0x7733378b93e44af6e77801e3168366fa930289e6',
61      '0xe38f7a4e4cf299ed3443131693bd2be5ba5f3369',
62      '0x4e64f5890ee335c5ac1dbb9be47ca8b4771cb274',
63      '0x1aeceef77d3156ce3f6123dc8e7e873b1487b08e',
64      '0xe5e4b591b0a8128c859a441f85797d5d5e6f634e',
65      '0xc45888f959171d49c460387eb69e096143b3277c',
66      '0xb59331d452e002194c840b42314c12d1fd218ff6',
67      '0x11a487570d4e1e56c75a164aaa8de73573e42dd3',
68      '0x87672c17fc72b044323dd41966b48317893e822a',
69      '0x6f6aad96892b92e02ee15943e4322adaaa98a1bf',
70      '0x6cf69dae87de36acfcae3172e5525c7a99deb303',
71      '0x7dd94eafb07eefd0a01f5667e002ab33a2773746',
72      '0x1db176ff50ccb3ff45dcc3e3886499462ef29e30',
73      '0x5f2bc46eccb72ea9eee07f6aeeae53a7e8a8fbdb',
74      '0xe38f7a4e4cf299ed3443131693bd2be5ba5f3369',
75      '0xc194529d770675f6d5041bc4b76c478b33025996',
76      '0x6cf69dae87de36acfcae3172e5525c7a99deb303',
77      '0xfede07e0c5ab1ed14c662a317c38a1eb8851a090',
78      '0x7b055c47b13f7cdbc4e6888faa36b48f2aaee8e6',
79      '0x7733378b93e44af6e77801e3168366fa930289e6',
80      '0xa4ed31f74dfb456eac1611561235bb11840313fd',
81      '0x4608a268603bcb320a29e5b1c75af92016e39443',
82      '0x29a4ee3f95154ee9143d1e5e92404bad81754f67',
83      '0x96b347c61858e3d96b74d0cabadf2c960473bef2',
84      '0x2036ac1e3361bc9c3fe66e08f911a9a55c5cd2fc',
85      '0x0e04b7c840a3b63d9eeff9050df17dd606fd032f',
86      '0x08fe32fae9c79de9b6fb080ff835d80a50657dc9',
87      '0x8051650ccb6a1118cdca7709d6691a2f32456919',
88      '0x1fc7ccd15c95622cedbfc197ea3de971d16157a3',
89      '0x835c452c02ce65f0a77e051d067d1c69362f536e',
90      '0x1403618a26b6a77c7826df4c82c7a71abef1667a',
91      '0xa7dd02bafaa8fddc863a5a8477cd3fdad8a12ebb',
92      '0x956de1b4aab09e93442ba833422994d08dcb5070',
93      '0x49fb1248eb9986e949902b19039866a7b82e1b57',
94      '0x5a1aac749f5befea0aa77102a9426c9c54a2724e',
95      '0x5487f9c556f574653764eb226331d8bb8076f4b6',
96      '0x3b1d8ddd166ff1d2d498941a50833dca6905aceb',
97      '0x14f18dcb0def3a122eab6011df208e146d9ea0bb',
98      '0x385b29e089623d5d07f0179ba1af69d2274c72f6',
99      '0x1d0b158b4af70b085a9b5cd2af36456b0fdbd481',
100      '0x99dd433024c26465c57d7f27d789b11e5e3d600a',
101      '0x3d8007c836336adec16b20f7c8f25b4f1e6b5245',
102      '0xec4ccbf642cf6fd288e4177281e6211af811b8cf',
103      '0xf07776406307cfeb5c64219b65f0f4a5b555ed37',
104      '0x3e8d81ae189638d64695abb32d361a1eb74eba58',
105      '0xc79d8b1ceed3a8fbb19c3bcca4920e0d07fc389d',
106      '0x9b7fc97185fd17f14e116da275c9ba17829be17b',
107      '0x4483270d5d2e77dc75bee6365bbbeb5e0b791a1b',
108      '0x22e81ffdc94000e9d6199e491a41dc4692b63277',
109      '0xb96faff9b8059e8e86a134f484fdedc4d6f9c4c6',
110      '0x714d51dcce15ae5686803013eb6d0eb3c9f6cdd5',
111      '0xedaa0f277890a781f42e4a5e9082005caf39c523',
112      '0x1bfcda4acaa2c684c4bacd4686cd0592322c8767',
113      '0x7d904e0a8a569269955ae35ca6be6e8d258c16d6',
114      '0xfde37cacc570297031ac582025cd92bce1bbf90a',
115      '0xa05efac732167f19282b3df8c7f216008e4a90a6',
116      '0x80447d57dd56a79f28b612b733afd73933b0d9a5',
117      '0x2515374080150674a649493faadbf1e372c8ff09',
118      '0x0a4517b310e5f132e5651dc4124b140a8142cb68',
119      '0x3c71e3e6607981e615df709f1a245e61f7674caa',
120      '0x1c5d037bdb68f4bbe790f5daffb5a7fb49001389',
121      '0xfe594f45576b26be8932a1758dfea4953d4167e2',
122      '0x429ddbe9f3519cd47c86efd5ed9c0213117656c8',
123      '0x85074caf0991a9e4087091f8a7d80a8287557e73',
124      '0x58698655ed5d38c9c40d783b0982a736471552fc',
125      '0xbab8c3207c481f503a503997a3f5edc5eb12faff',
126    ],
127  },
128  avalanche: {
129    subgraph: 'sushiswap/avalanche-exchange',
130    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
131    blockchain: 'Avalanche',
132    protocolLaunch: '2021-03-15'
133  },
134  binance: {
135    subgraph: 'sushiswap/bsc-exchange',
136    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
137    blockchain: 'Binance',
138    protocolLaunch: '2021-03-02'
139  }
140}
141
142const SEC_IN_DAY = 86400;
143
144export function setup(sdk: Context) {
145  const createFeeDataQuery = (subgraph: string, feePercentage: number, blacklist?: string[]) => async (date: string): Promise<number> => {
146    const dateId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
147    
148    const graphQuery = `query fees(
149      $date: Int!,
150      $dateId: Int!,
151      $nextDay: Int!,
152      $blacklist: [Bytes!]!
153    ) {
154      dayData(id: $dateId) {
155        volumeUSD
156      }
157      nextDay: dayData(id: $nextDay) {
158        volumeUSD
159      }
160      blacklist: pairDayDatas(where: { pair_in: $blacklist, date: $date }) {
161        volumeUSD
162      }
163    }`;
164
165    const data = await sdk.graph.query(
166      subgraph,
167      graphQuery,
168      {
169        date: sdk.date.dateToTimestamp(date),
170        dateId,
171        nextDay: dateId + 1,
172        blacklist: blacklist || [],
173      },
174    );
175
176    if (!data.nextDay) {
177      return null;
178    }
179
180    const totalVolume = data.blacklist.reduce(
181      (current: number, blacklistItem: any) => current - parseFloat(blacklistItem.volumeUSD),
182      parseFloat(data.dayData.volumeUSD),
183    );
184
185    const oneDay = totalVolume * feePercentage;
186
187    return oneDay;
188  }
189
190  const createFeeRangeQuery = (subgraph: string, network: string, factory: string, feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
191    const startBlock = await sdk.chainData.getBlockNumber(startDate, network);
192    const endBlock = await sdk.chainData.getBlockNumber(endDate, network);
193    
194    const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
195      startValue: factory(id: "${factory}", block: { number: $startBlock }) {
196        volumeUSD
197        volumeUSD
198      }
199      endValue: factory(id: "${factory}", block: { number: $endBlock }) {
200        volumeUSD
201        volumeUSD
202      }
203    }`;
204
205    const data = await sdk.graph.query(subgraph, graphQuery, { startBlock, endBlock });
206
207    const volumeDiff = data.endValue.volumeUSD - data.startValue.volumeUSD;
208    const fees = volumeDiff * feePercentage;
209    return fees;
210  }
211
212  const metadata = {
213    category: 'dex',
214    name: 'SushiSwap',
215    description: 'SushiSwap is a community-owned permissionless, decentralized exchange',
216    feeDescription: 'Trading fees are paid by traders to liquidity providers and SUSHI stakers',
217    source: 'The Graph Protocol',
218    tokenTicker: 'SUSHI',
219    tokenCoingecko: 'sushi',
220    website: 'https://sushi.com',
221    icon: sdk.ipfs.getDataURILoader('QmVAko4auvE2NDr8kfnovVqTqujrJ69YrUZQFPZeREMWk5', 'image/svg+xml'),
222    protocolLaunch: '2020-09-09',
223  };
224
225  sdk.registerBundle('sushi', metadata);
226
227  Object.entries(networks).map(([network, { subgraph, factory, ...deployment }]: [string, NetInfo]) => {
228    sdk.register({
229      id: `sushiswap-${network}`,
230      bundle: 'sushi',
231      queries: {
232        oneDayTotalFees: createFeeDataQuery(subgraph, 0.003, deployment.blacklist),
233        oneDayProtocolFees: createFeeDataQuery(subgraph, 0.0005, deployment.blacklist),
234        oneDayTotalVolumeUSD: createFeeDataQuery(subgraph, 1, deployment.blacklist),
235        dateRangeTotalFees: createFeeRangeQuery(subgraph, network, factory, 0.003),
236        dateRangeProtocolFees: createFeeRangeQuery(subgraph, network, factory, 0.0005),
237      },
238      metadata: {
239        ...metadata,
240        subtitle: deployment.blockchain,
241        blockchain: deployment.blockchain,
242        protocolLaunch: deployment.protocolLaunch,
243      },
244    })
245  })
246}
247

It's something off?

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

Adapter Info

Version

1.0.3

License

MIT

IPFS CID

QmZTN5be2T9NxLt6MwqqQaN7WMS5mvfStWrbuWLa8zaL37

CID (source)

QmSaa8WGqhT23ctMLQZHU3hc5D8GPpZppqrAjxi19p7p3m

Collections

Author

mihal.eth