Sub-Adapters 12
Preview and test each sub adapter.
Kyberswap - Ethereum (kyberswap-ethereum)
Kyberswap - Arbitrum One (kyberswap-arbitrum-one)
Kyberswap - Aurora (kyberswap-aurora)
Kyberswap - Avalanche (kyberswap-avalanche)
Kyberswap - Binance (kyberswap-binance)
Kyberswap - BitTorrent (kyberswap-bittorrent)
Kyberswap - Cronos (kyberswap-cronos)
Kyberswap - Fantom (kyberswap-fantom)
Kyberswap - Oasis (kyberswap-oasis)
Kyberswap - Optimism (kyberswap-optimism)
Kyberswap - Polygon (kyberswap-polygon)
Kyberswap - Velas (kyberswap-velas)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Kyberswap Fees';
2export const version = '1.1.1';
3export const license = 'MIT';
4
5// used https://analytics.kyberswap.com/ as primary source of graphql endpoints, referencing documentation show below as well
6interface NetInfo {
7 classicSubgraph?: string; // https://docs.kyberswap.com/Classic/reference/subgraph-data
8 elasticSubgraph?: string; // https://docs.kyberswap.com/reference/subgraph-data
9 blockchain: string;
10 protocolLaunch: string;
11}
12
13const networks: { [network: string]: NetInfo } = {
14 ethereum: {
15 classicSubgraph: 'kybernetwork/kyberswap-exchange-ethereum',
16 elasticSubgraph: 'kybernetwork/kyberswap-elastic-mainnet',
17 blockchain: 'Ethereum',
18 protocolLaunch: '2021-04-05',
19 },
20 'arbitrum-one': {
21 classicSubgraph: 'https://arbitrum-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-arbitrum',
22 elasticSubgraph: 'kybernetwork/kyberswap-elastic-arbitrum-one',
23 blockchain: 'Arbitrum One',
24 protocolLaunch: '2022-03-02',
25 },
26 aurora: {
27 classicSubgraph: 'kybernetwork/kyberswap-exchange-aurora',
28 elasticSubgraph: null,
29 blockchain: 'Aurora',
30 protocolLaunch: '2022-03-08'
31 },
32 avalanche: {
33 classicSubgraph: 'kybernetwork/kyberswap-exchange-avalanche',
34 elasticSubgraph: 'kybernetwork/kyberswap-elastic-avalanche',
35 blockchain: 'Avalanche',
36 protocolLaunch: '2021-09-16'
37 },
38 binance: {
39 classicSubgraph: 'kybernetwork/kyberswap-exchange-bsc',
40 elasticSubgraph: 'kybernetwork/kyberswap-elastic-bsc',
41 blockchain: 'Binance',
42 protocolLaunch: '2021-09-01'
43 },
44 bittorrent: {
45 classicSubgraph: 'https://bttc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-bttc',
46 elasticSubgraph: 'https://bttc-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-bttc',
47 blockchain: 'BitTorrent',
48 protocolLaunch: '2022-02-22',
49 },
50 cronos: {
51 classicSubgraph: 'https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-cronos',
52 elasticSubgraph: 'https://cronos-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-cronos',
53 blockchain: 'Cronos',
54 protocolLaunch: '2021-12-07'
55 },
56 fantom: {
57 classicSubgraph: 'kybernetwork/kyberswap-exchange-fantom',
58 elasticSubgraph: 'kybernetwork/kyberswap-elastic-fantom',
59 blockchain: 'Fantom',
60 protocolLaunch: '2021-10-22',
61 },
62 oasis: {
63 classicSubgraph: 'https://oasis-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-oasis',
64 elasticSubgraph: 'https://oasis-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-oasis',
65 blockchain: 'Oasis',
66 protocolLaunch: '2022-06-09'
67 },
68 optimism: {
69 classicSubgraph: 'kybernetwork/kyberswap-exchange-optimism',
70 elasticSubgraph: 'kybernetwork/kyberswap-elastic-optimism',
71 blockchain: 'Optimism',
72 protocolLaunch: '2022-06-22'
73 },
74 polygon: {
75 classicSubgraph: 'kybernetwork/kyberswap-exchange-polygon',
76 elasticSubgraph: 'kybernetwork/kyberswap-elastic-matic',
77 blockchain: 'Polygon',
78 protocolLaunch: '2021-06-24',
79 },
80 velas: {
81 classicSubgraph: 'https://velas-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-exchange-velas',
82 elasticSubgraph: 'https://velas-graph.kyberengineering.io/subgraphs/name/kybernetwork/kyberswap-elastic-velas',
83 blockchain: 'Velas',
84 protocolLaunch: '2022-03-08'
85 }
86
87}
88
89export function setup(sdk: Context) {
90 const createFeeDataQuery = (classicSubgraph: string, elasticSubgraph: string) => async (date: string): Promise<number> => {
91
92 const timestamp = Math.floor(sdk.date.dateToTimestamp(date));
93
94 let classicDailyFeeUSD: number = 0;
95 if (classicSubgraph) {
96 const classicSubgraphQuery = `{
97 poolDayDatas(where: {date: ${timestamp} }, limit: 1000) { dailyFeeUSD }
98 }`;
99
100 const data = await sdk.graph.query(
101 classicSubgraph,
102 classicSubgraphQuery
103 );
104
105 classicDailyFeeUSD = data.poolDayDatas
106 .map(day => Number(day.dailyFeeUSD))
107 .reduce((accumulator: number, currentValue: number) => (accumulator + currentValue), 0)
108 }
109
110 let elasticFeesUSD = 0;
111 if (elasticSubgraph) {
112 const elasticSubgraphQuery = `{
113 kyberSwapDayDatas(where: {date: ${timestamp} }) { feesUSD }
114 }`;
115
116 const elasticData = await sdk.graph.query(
117 elasticSubgraph,
118 elasticSubgraphQuery
119 );
120
121 elasticFeesUSD = Number(elasticData.kyberSwapDayDatas[0]?.feesUSD || 0);
122 }
123
124 return classicDailyFeeUSD + elasticFeesUSD;
125 }
126
127 const metadata = {
128 category: 'dex',
129 name: 'Kyberswap',
130 icon: sdk.ipfs.getDataURILoader('QmR9JcqBneYd1xch5pXqXsMKGAvDgKyurTAdhh4m73oWDW', 'image/svg+xml'),
131 description: 'Kyber Network is a decentralized, blockchain-based protocol that aggregates liquidity and enables the exchange of tokens without an intermediary.',
132 feeDescription: 'Trading fees are paid to KNC stakers.',
133 source: 'The Graph Protocol',
134 tokenTicker: 'KNC',
135 tokenCoingecko: 'kyber-network-crystal',
136 website: 'https://kyber.network',
137 protocolLaunch: '2021-04-05',
138 };
139
140 sdk.registerBundle('kyberswap', metadata);
141
142 Object.entries(networks).map(([network, { classicSubgraph, elasticSubgraph, blockchain, protocolLaunch }]: [string, NetInfo]) => {
143 sdk.register({
144 id: `kyberswap-${network}`,
145 bundle: 'kyberswap',
146 queries: {
147 oneDayTotalFees: createFeeDataQuery(classicSubgraph, elasticSubgraph)
148 },
149 metadata: {
150 ...metadata,
151 subtitle: blockchain,
152 blockchain,
153 protocolLaunch,
154 },
155 })
156 })
157}
158
It's something off?
Report it to the discussion board on Discord, we will take care of it.