Adapter

SushiSwap Fees

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 = '0.2.5';
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
51export function setup(sdk: Context) {
52  const createFeeDataQuery = (subgraph: string, feePercentage: number) => async (date: string): Promise<number> => {
53    const graphQuery = `query fees($date: Int!) {
54      dayDatas(where: { date: $date }) {
55        volumeUSD
56      }
57    }`;
58
59    const data = await sdk.graph.query(
60      subgraph,
61      graphQuery,
62      {
63        variables: {
64          date: sdk.date.dateToTimestamp(date),
65        },
66      }
67    );
68
69    if (data.dayDatas.length === 0) {
70      throw new Error(`No Sushi data found on ${date} from ${subgraph}`);
71    }
72
73    const oneDay = parseFloat(data.dayDatas[0].volumeUSD) * feePercentage;
74
75    return oneDay;
76  }
77
78  const createFeeRangeQuery = (subgraph: string, network: string, factory: string, feePercentage: number) => async (startDate: string, endDate: string): Promise<number> => {
79    const startBlock = await sdk.chainData.getBlockNumber(startDate, network);
80    const endBlock = await sdk.chainData.getBlockNumber(endDate, network);
81    
82    const graphQuery = `query fees($startBlock: Int!, $endBlock: Int!) {
83      startValue: factory(id: "${factory}", block: { number: $startBlock }) {
84        volumeUSD
85      }
86      endValue: factory(id: "${factory}", block: { number: $endBlock }) {
87        volumeUSD
88      }
89    }`;
90    network;
91
92    const data = await sdk.graph.query(
93      subgraph,
94      graphQuery,
95      { variables: { startBlock, endBlock } }
96    );
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        dateRangeTotalFees: createFeeRangeQuery(subgraph, network, factory, 0.003),
126        dateRangeProtocolFees: createFeeRangeQuery(subgraph, network, factory, 0.0005),
127      },
128      metadata: {
129        ...metadata,
130        subtitle: blockchain,
131        blockchain,
132        protocolLaunch,
133      },
134    })
135  })
136}

It's something off?

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

Adapter Info

Version

0.2.5

License

MIT

IPFS CID

QmaBUbVHAU4c9A4Zxf4Q2tdM33jseJyPY7b1TLkaeqphvK

CID (source)

Qmaifk2DpFQK6oWbmLRawBEurdzHNc4atKqrXDqFgzuZRT

Collections

fee-range

Author

ap0calyp.eth