Sub-Adapters 5

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)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'SushiSwap Fees';
2export const version = '0.2.4';
3export const license = 'MIT';
4
5interface NetInfo {
6  subgraph: string;
7  factory: string;
8  blockchain: string;
9  protocolLaunch: string;
10}
11
12const networks: { [network: string]: NetInfo } = {
13  ethereum: {
14    subgraph: 'sushiswap/exchange',
15    factory: '0xc0aee478e3658e2610c5f7a4a2e1777ce9e4f2ac',
16    blockchain: 'Ethereum',
17    protocolLaunch: '2020-09-09',
18  },
19  polygon: {
20    subgraph: 'sushiswap/matic-exchange',
21    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
22    blockchain: 'Polygon',
23    protocolLaunch: '2021-02-26',
24  },
25  fantom: {
26    subgraph: 'sushiswap/fantom-exchange',
27    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
28    blockchain: 'Fantom',
29    protocolLaunch: '2021-02-26',
30  },
31  'arbitrum-one': {
32    subgraph: 'sushiswap/arbitrum-exchange',
33    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
34    blockchain: 'Arbitrum One',
35    protocolLaunch: '2021-08-31',
36  },
37  avalanche: {
38    subgraph: 'sushiswap/avalanche-exchange',
39    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
40    blockchain: 'Avalanche',
41    protocolLaunch: '2021-03-15'
42  }
43}
44
45export function setup(sdk: Context) {
46  const createFeeDataQuery = (subgraph: string, feePercentage: number) => async (date: string): Promise<number> => {
47    const graphQuery = `query fees($date: Int!) {
48      dayDatas(where: { date: $date }) {
49        volumeUSD
50      }
51    }`;
52
53    const data = await sdk.graph.query(
54      subgraph,
55      graphQuery,
56      {
57        variables: {
58          date: sdk.date.dateToTimestamp(date),
59        },
60      }
61    );
62
63    if (data.dayDatas.length === 0) {
64      throw new Error(`No Sushi data found on ${date} from ${subgraph}`);
65    }
66
67    const oneDay = parseFloat(data.dayDatas[0].volumeUSD) * feePercentage;
68
69    return oneDay;
70  }
71
72  const createFeeRangeQuery = (subgraph: string, network: string, factory: string, feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
73    const startBlock = await sdk.chainData.getBlockNumber(startDate, network);
74    const endBlock = await sdk.chainData.getBlockNumber(endDate, network);
75    
76    const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
77      startValue: factory(id: "${factory}", block: { number: $startBlock }) {
78        volumeUSD
79      }
80      endValue: factory(id: "${factory}", block: { number: $endBlock }) {
81        volumeUSD
82      }
83    }`;
84    network;
85
86    const data = await sdk.graph.query(
87      subgraph,
88      graphQuery,
89      { variables: { startBlock, endBlock } }
90    );
91
92    const volumeDiff = data.endValue.volumeUSD - data.startValue.volumeUSD;
93    const fees = volumeDiff * feePercentage;
94    return fees;
95  }
96
97  const metadata = {
98    category: 'dex',
99    name: 'SushiSwap',
100    description: 'SushiSwap is a community-owned permissionless, decentralized exchange',
101    feeDescription: 'Trading fees are paid by traders to liquidity providers and SUSHI stakers',
102    source: 'The Graph Protocol',
103    tokenTicker: 'SUSHI',
104    tokenCoingecko: 'sushi',
105    website: 'https://sushi.com',
106    icon: sdk.ipfs.getDataURILoader('QmVAko4auvE2NDr8kfnovVqTqujrJ69YrUZQFPZeREMWk5', 'image/svg+xml'),
107    protocolLaunch: '2020-09-09',
108  };
109
110  sdk.registerBundle('sushi', metadata);
111
112  Object.entries(networks).map(([network, { subgraph, factory, blockchain, protocolLaunch }]: [string, NetInfo]) => {
113    sdk.register({
114      id: `sushiswap-${network}`,
115      bundle: 'sushi',
116      queries: {
117        oneDayTotalFees: createFeeDataQuery(subgraph, 0.003),
118        oneDayProtocolFees: createFeeDataQuery(subgraph, 0.0005),
119        dateRangeTotalFees: createFeeRangeQuery(subgraph, network, factory, 0.003),
120        dateRangeProtocolFees: createFeeRangeQuery(subgraph, network, factory, 0.0005),
121      },
122      metadata: {
123        ...metadata,
124        subtitle: blockchain,
125        blockchain,
126        protocolLaunch,
127      },
128    })
129  })
130}

It's something off?

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

Adapter Info

Version

0.2.4

License

MIT

IPFS CID

QmNtXQvJNKEgx9zsCMZ9Ap1bWiCoubkADdPkQzhWS5KE9K

CID (source)

QmUWonEtNaaAFdZf2Ww2kNxHLC2w85P3byMeWTcyYSKPMB

Author

ap0calyp.eth