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.0';
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  binance: {
44    subgraph: 'sushiswap/bsc-exchange',
45    factory: '0xc35dadb65012ec5796536bd9864ed8773abc74c4',
46    blockchain: 'Binance',
47    protocolLaunch: '2021-03-02'
48  }
49}
50
51const SEC_IN_DAY = 86400;
52
53export function setup(sdk: Context) {
54  const createFeeDataQuery = (subgraph: string, feePercentage: number) => async (date: string): Promise<number> => {
55    const dateId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
56    
57    const graphQuery = `query fees($dateId: Int!, $nextDay: Int!) {
58      dayData(id: $dateId) {
59        volumeUSD
60      }
61      nextDay: dayData(id: $nextDay) {
62        volumeUSD
63      }
64    }`;
65
66    const data = await sdk.graph.query(
67      subgraph,
68      graphQuery,
69      { dateId, nextDay: dateId + 1 },
70    );
71
72    if (!data.nextDay) {
73      return null;
74    }
75
76    const oneDay = parseFloat(data.dayData.volumeUSD) * feePercentage;
77
78    return oneDay;
79  }
80
81  const createFeeRangeQuery = (subgraph: string, network: string, factory: string, feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
82    const startBlock = await sdk.chainData.getBlockNumber(startDate, network);
83    const endBlock = await sdk.chainData.getBlockNumber(endDate, network);
84    
85    const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
86      startValue: factory(id: "${factory}", block: { number: $startBlock }) {
87        volumeUSD
88        volumeUSD
89      }
90      endValue: factory(id: "${factory}", block: { number: $endBlock }) {
91        volumeUSD
92        volumeUSD
93      }
94    }`;
95
96    const data = await sdk.graph.query(subgraph, graphQuery, { startBlock, endBlock });
97
98    const volumeDiff = data.endValue.volumeUSD - data.startValue.volumeUSD;
99    const fees = volumeDiff * feePercentage;
100    return fees;
101  }
102
103  const metadata = {
104    category: 'dex',
105    name: 'SushiSwap',
106    description: 'SushiSwap is a community-owned permissionless, decentralized exchange',
107    feeDescription: 'Trading fees are paid by traders to liquidity providers and SUSHI stakers',
108    source: 'The Graph Protocol',
109    tokenTicker: 'SUSHI',
110    tokenCoingecko: 'sushi',
111    website: 'https://sushi.com',
112    icon: sdk.ipfs.getDataURILoader('QmVAko4auvE2NDr8kfnovVqTqujrJ69YrUZQFPZeREMWk5', 'image/svg+xml'),
113    protocolLaunch: '2020-09-09',
114  };
115
116  sdk.registerBundle('sushi', metadata);
117
118  Object.entries(networks).map(([network, { subgraph, factory, blockchain, protocolLaunch }]: [string, NetInfo]) => {
119    sdk.register({
120      id: `sushiswap-${network}`,
121      bundle: 'sushi',
122      queries: {
123        oneDayTotalFees: createFeeDataQuery(subgraph, 0.003),
124        oneDayProtocolFees: createFeeDataQuery(subgraph, 0.0005),
125        oneDayTotalVolumeUSD: createFeeDataQuery(subgraph, 1),
126        dateRangeTotalFees: createFeeRangeQuery(subgraph, network, factory, 0.003),
127        dateRangeProtocolFees: createFeeRangeQuery(subgraph, network, factory, 0.0005),
128      },
129      metadata: {
130        ...metadata,
131        subtitle: blockchain,
132        blockchain,
133        protocolLaunch,
134      },
135    })
136  })
137}
138

It's something off?

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

Adapter Info

Version

1.0.0

License

MIT

IPFS CID

QmPwrJDas4pxbXUKzcKs78cRwdzw6caeJje5a2wo422BUc

CID (source)

QmSyoFQo5CFpxX74hNzuRGTYGVjPTjw75nybNEi5FLBuno

Collections

Author

mihal.eth