Sub-Adapters 1
Preview and test each sub adapter.
Mycelium - Arbitrum (mycelium-arbitrum)
Metadata
- ID
- mycelium-arbitrum
- name
"Mycelium"
- icon
- protocolLaunch
"2022-08-15"
- category
"dex"
- description
"Trade with liquidity, leverage, low fees."
- feeDescription
"MLP holders earn 70% of revenue from trading fees. Earn 10% of fees as an active trader."
- blockchain
"Arbitrum One"
- source
"The Graph Protocol"
- website
"https://swaps.mycelium.xyz"
- tokenTicker
"MYC"
- tokenCoingecko
"mycelium"
- subtitle
"Arbitrum"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
1export const name = 'Mycelium Fees';
2export const version = '0.0.2';
3export const license = 'MIT';
4
5const MYCELIUM_SUBGRAPH = 'mycelium-ethereum/myc-swaps-stats'
6const SPREAD_PERCENTAGE = 0.0006;
7
8const feesGraphQuery = `query fees($date: String!) {
9 feeStats(where: { period: daily, id_gte: $date, id_lte: $date }) {
10 margin
11 marginAndLiquidation
12 swap
13 mint
14 burn
15 }
16 }`;
17
18const volumeGraphQuery = `query volume($date: String!) {
19 volumeStats(where: { period: daily, id_gte: $date, id_lte: $date }) {
20 margin
21 liquidation
22 swap
23 mint
24 burn
25 }
26 }`;
27
28export function setup(sdk: Context) {
29 const getFeesData = (subgraph: string, postFix = '') => async (date: string): Promise<any> => {
30 // Get volume data to calculate fees + spread
31 const volumeData = await sdk.graph.query(subgraph, volumeGraphQuery, {
32 date: sdk.date.dateToTimestamp(date) + postFix
33 });
34 const feesData = await sdk.graph.query(subgraph, feesGraphQuery, {
35 date: sdk.date.dateToTimestamp(date) + postFix
36 });
37
38 if (!feesData.feeStats[0] || !volumeData.volumeStats[0]) {
39 throw new Error(`No data found for date ${date}`);
40 }
41
42 const totalVolume = Object.values(volumeData.volumeStats[0]).reduce((val: string, next: string) => parseFloat(val) + parseFloat(next), 0)
43 const spread = totalVolume as number * SPREAD_PERCENTAGE;
44 const totalFees = (parseFloat(feesData.feeStats[0].marginAndLiquidation) - parseFloat(feesData.feeStats[0].margin))
45 + parseFloat(feesData.feeStats[0].swap)
46 + parseFloat(feesData.feeStats[0].margin)
47 + parseFloat(feesData.feeStats[0].mint)
48 + parseFloat(feesData.feeStats[0].burn)
49 + spread;
50
51 return totalFees / 1e30;
52 }
53
54 const getVolumeData = (subgraph: string, postFix = '') => async (date: string): Promise<number> => {
55 const data = await sdk.graph.query(subgraph, volumeGraphQuery, {
56 date: sdk.date.dateToTimestamp(date) + postFix,
57 nextDay: sdk.date.dateToTimestamp(date) + postFix,
58 });
59
60 if (!data.volumeStats[0]) {
61 throw new Error(`No data found for date ${date}`);
62 }
63
64 const totalVolume = Object.values(data.volumeStats[0]).reduce((val: string, next: string) => parseFloat(val) + parseFloat(next), 0)
65
66 return totalVolume as number / 1e30;
67 }
68
69 const metadata = {
70 name: 'Mycelium',
71 icon: sdk.ipfs.getDataURILoader('QmQPstDnd8BF647Ww4a1cHoTD6HZ27AGi2LRTswS4d9JCF', 'image/svg+xml'),
72 protocolLaunch: '2022-08-15',
73 category: 'dex',
74 description: 'Trade with liquidity, leverage, low fees.',
75 feeDescription: 'MLP holders earn 70% of revenue from trading fees. Earn 10% of fees as an active trader.', // Update later
76 blockchain: 'Arbitrum One',
77 source: 'The Graph Protocol',
78 website: 'https://swaps.mycelium.xyz',
79 tokenTicker: 'MYC',
80 tokenCoingecko: 'mycelium',
81 };
82
83 sdk.register({
84 id: 'mycelium-arbitrum',
85 bundle: 'myc',
86 queries: {
87 oneDayTotalFees: getFeesData(MYCELIUM_SUBGRAPH),
88 oneDayTotalVolumeUSD: getVolumeData(MYCELIUM_SUBGRAPH),
89 },
90 metadata: {
91 ...metadata,
92 subtitle: 'Arbitrum',
93 blockchain: 'Arbitrum One',
94 protocolLaunch: '2022-08-15',
95 },
96 });
97
98 sdk.registerBundle('myc', metadata);
99}
It's something off?
Report it to the discussion board on Discord, we will take care of it.