Sub-Adapters 7

Preview and test each sub adapter.

Curve - Ethereum (curve-ethereum)

Curve - Arbitrum One (curve-arbitrum)

Curve - Polygon (curve-polygon)

Curve - Avalanche (curve-avalanche)

Curve - Fantom (curve-fantom)

Curve - Gnosis Chain (curve-xdai)

Curve - Optimism (curve-optimism)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Curve Fees';
2export const version = '0.1.7';
3export const license = 'MIT';
4export const changelog = 'Clean up chain names for Arbitrum One and Gnosis Chain';
5
6interface NetInfo {
7  subgraph: string;
8  blockchain: string;
9  protocolLaunch: string;
10}
11
12const FEES_TYPES = {
13  'protocol': 'PROTOCOL',
14  'total': 'TOTAL'
15}
16
17
18// https://github.com/curvefi/volume-subgraphs
19const networks: { [network: string]: NetInfo } = {
20  ethereum: {
21    subgraph: 'convex-community/volume-mainnet-test',
22    blockchain: 'Ethereum',
23    protocolLaunch: '2020-01-01',
24  },
25  arbitrum: {
26    subgraph: 'convex-community/volume-arbitrum-test',
27    blockchain: 'Arbitrum One',
28    protocolLaunch: '2021-09-20',
29  },
30  polygon: {
31    subgraph: 'convex-community/volume-matic-test',
32    blockchain: 'Polygon',
33    protocolLaunch: '2021-05-03',
34  },
35  avalanche: {
36    subgraph: 'convex-community/volume-arbitrum-test',
37    blockchain: 'Avalanche',
38    protocolLaunch: '2021-10-06',
39  },
40  fantom: {
41    subgraph: 'convex-community/volume-fantom-test',
42    blockchain: 'Fantom',
43    protocolLaunch: '2021-05-09',
44  },
45  xdai: {
46    subgraph: 'convex-community/volume-xdai-test',
47    blockchain: 'Gnosis Chain',
48    protocolLaunch: '2021-05-09',
49  },
50  optimism: {
51    subgraph: 'convex-community/volume-optimism-test',
52    blockchain: 'Optimism',
53    protocolLaunch: '2021-05-09',
54  },
55}
56
57export function setup(sdk: Context) {
58  const createFeeDataQuery = (subgraph: string, network: string, feesType: string) => async (date: string): Promise<number> => {
59    // offset date by 1
60    const startDate = sdk.date.offsetDaysFormatted(date, +1);
61    const endDate = sdk.date.offsetDaysFormatted(date, +2);
62    const oneDay = await createFeeRangeQuery(subgraph, network, feesType)(startDate, endDate);
63    return oneDay;
64  }
65
66  // Includes a $1m sanity check
67  const graphQuery = `query fees($timestamp_gte: Int!, $timestamp_lte: Int!) 
68  {
69    dailyPoolSnapshots (
70      orderBy: timestamp
71      orderDirection: desc
72      first: 1000
73      where: {
74        timestamp_gte: $timestamp_gte
75        timestamp_lt: $timestamp_lte
76        totalDailyFeesUSD_lte: 1000000
77      }
78    ) {
79      totalDailyFeesUSD
80      adminFeesUSD
81    }
82  }
83  `;
84  const createFeeRangeQuery =
85    (subgraph: string, network: string, feesType: string) => async (startDate: string, endDate: string): Promise<number> => {
86    const data = await sdk.graph.query(
87      subgraph,
88      graphQuery,
89      {
90        variables: {
91          timestamp_gte: sdk.date.dateToTimestamp(startDate),
92          timestamp_lte: sdk.date.dateToTimestamp(endDate),
93          network
94        },
95      }
96    );
97    const volumesLength = data.dailyPoolSnapshots.length;
98    if (volumesLength === 0) {
99      throw new Error(`No curve data found between ${sdk.date.offsetDaysFormatted(startDate, -1)} and ${startDate} from ${subgraph}`);
100    }
101    const feesPerPool = data.dailyPoolSnapshots.map((vol: any):number => {
102      return (feesType == FEES_TYPES.protocol) ? parseFloat(vol.adminFeesUSD) : parseFloat(vol.totalDailyFeesUSD);
103    })
104
105    const feesDuringRange = feesPerPool.reduce((acc: number, curr: number) => acc + curr, 0.);
106    return feesDuringRange;
107  }
108
109  const metadata = {
110    category: 'dex',
111    name: 'Curve',
112    description: 'Curve is a community-owned permissionless, decentralized exchange',
113    feeDescription: 'Trading fees are paid by traders to liquidity providers and pool admins',
114    source: 'The Graph Protocol',
115    tokenTicker: 'CRV',
116    tokenCoingecko: 'curve-dao-token',
117    website: 'https://curve.fi/',
118    icon: sdk.ipfs.getDataURILoader('QmeGCLQAfUANUB79AJ6hMnY7DeBdX3WssantuZDBXNbAF8', 'image/png'),
119    protocolLaunch: '2020-01-01',
120  };
121
122  sdk.registerBundle('curve', metadata);
123
124  Object.entries(networks).map(([network, { subgraph, blockchain, protocolLaunch }]: [string, NetInfo]) => {
125    sdk.register({
126      id: `curve-${network}`,
127      bundle: 'curve',
128      queries: {
129        oneDayTotalFees: createFeeDataQuery(subgraph, network, FEES_TYPES.total),
130        oneDayProtocolFees: createFeeDataQuery(subgraph, network, FEES_TYPES.protocol),
131      },
132      metadata: {
133        ...metadata,
134        subtitle: blockchain,
135        blockchain,
136        protocolLaunch,
137      },
138    })
139  })
140}

It's something off?

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

Adapter Info

Version

0.1.7

License

MIT

IPFS CID

QmP4uuae9LrwRWTLb72o2pTDNsAe5iz8g5b5Nss6izfqXu

CID (source)

QmZvKk3cxaBJbrgawS369NQGTZP4guiGg7ZFSSAsVKuSsh

Collections

Author

mihal.eth