Sub-Adapters 11

Preview and test each sub adapter.

Ethereum (eth)

Bitcoin (btc)

Litecoin (ltc)

Cardano (ada)

Tezos (xtz)

Bitcoin SV (bsv)

Bitcoin Cash (bch)

Ripple (xrp)

Dogecoin (doge)

Monero (xmr)

Stellar (xlm)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'CoinMetrics - Fees';
2export const version = '0.1.2';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6  const protocols = [
7    {
8      id: 'eth',
9      icon: sdk.ipfs.getDataURILoader('QmedJLPy6R7x3dDEy2cfMd8gXbZm9e3vxvgBLXp3YZEHCy', 'image/svg+xml'),
10      name: 'Ethereum',
11      description: 'Ethereum is the first blockchain for turing-complete smart contracts.',
12      feeDescription: 'Transaction fees are partially burnt and partially paid to miners.',
13      tokenTicker: 'ETH',
14      tokenCoingecko: 'ethereum',
15      website: 'https://ethereum.org',
16      blockchain: 'Ethereum',
17      source: 'CoinMetrics',
18      events: [
19        {
20          date: '2021-08-05',
21          description: 'London hard fork, including EIP-1559',
22        },
23      ],
24    },
25    {
26      id: 'btc',
27      icon: sdk.ipfs.getDataURILoader('QmerwCGnYE4DE9oe4a6hppgKRz2vvMdx1AuwvgFLgrdeh7', 'image/svg+xml'),
28      name: 'Bitcoin',
29      description: 'Bitcoin is the first decentralized cryptocurrency.',
30      feeDescription: 'Transaction fees are paid by users to miners.',
31      tokenTicker: 'BTC',
32      tokenCoingecko: 'bitcoin',
33      website: 'https://bitcoin.org',
34      source: 'CoinMetrics',
35    },
36    {
37      id: 'ltc',
38      icon: sdk.ipfs.getDataURILoader('QmQfWmmsfGDsVfgkjMwneB9MRgg8SEumgM7ZaGSP98ZsgW', 'image/svg+xml'),
39      name: 'Litecoin',
40      description: 'Litecoin is cryptocurrency based on a fork of the Bitcoin Core codebase.',
41      feeDescription: 'Transaction fees are paid by users to miners.',
42      website: 'https://litecoin.org',
43      source: 'CoinMetrics',
44      tokenTicker: 'LTC',
45      tokenCoingecko: 'litecoin',
46    },
47    {
48      id: 'ada',
49      icon: sdk.ipfs.getDataURILoader('QmbyTYm2BzcwgbRXoXXjihYT2mrwVPejFgKaJJXy6SHBRT', 'image/svg+xml'),
50      name: 'Cardano',
51      description: 'Cardano is a PoS blockchain which will support smart contracts in the future.',
52      feeDescription: 'Transaction fees are paid by users to validators.',
53      website: 'https://cardano.org',
54      source: 'CoinMetrics',
55      tokenTicker: 'ADA',
56      tokenCoingecko: 'cardano',
57      events: [
58        {
59          date: '2021-09-12',
60          description: 'Alonzo upgrade introduces smart contracts',
61        },
62      ],
63    },
64    {
65      id: 'xtz',
66      icon: sdk.ipfs.getDataURILoader('QmS1MvZJqD3CAxnos5t64HXtMsTh2SqXoWWndkL6dHVduW', 'image/svg+xml'),
67      name: 'Tezos',
68      description: 'Tezos is a PoS blockchain that supports smart contracts',
69      feeDescription: 'Transaction fees are paid by users to validators (bakers).',
70      website: 'https://tezos.com',
71      source: 'CoinMetrics',
72      tokenTicker: 'XTZ',
73      tokenCoingecko: 'tezos',
74    },
75    {
76      id: 'bsv',
77      icon: sdk.ipfs.getDataURILoader('QmPLRz1dZCbm2T5DeXrqULuqZU35TxcwYnbQFfN9GNiCf5', 'image/svg+xml'),
78      name: 'Bitcoin SV',
79      description: 'Bitcoin SV is a fork of the Bitcoin Cash blockchain',
80      feeDescription: 'Transaction fees are paid by users to miners.',
81      website: 'https://bitcoinsv.com',
82      source: 'CoinMetrics',
83      tokenTicker: 'BSV',
84      tokenCoingecko: 'bitcoin-cash-sv',
85    },
86    {
87      id: 'bch',
88      icon: sdk.ipfs.getDataURILoader('QmT1RaaEdJiJnyGMWLpHxamk3mhjrqoodAkjpD2wCxHeyS', 'image/svg+xml'),
89      name: 'Bitcoin Cash',
90      description: 'Bitcoin Cash is a fork of the Bitcoin blockchain',
91      feeDescription: 'Transaction fees are paid by users to miners.',
92      website: 'https://bitcoincash.org',
93      source: 'CoinMetrics',
94      tokenTicker: 'BCH',
95      tokenCoingecko: 'bitcoin-cash',
96    },
97    {
98      id: 'xrp',
99      icon: sdk.ipfs.getDataURILoader('QmYU37p3av9QDNLpG6sY2hiDDsVXewbovs9KtTzZAocasm', 'image/svg+xml'),
100      name: 'Ripple',
101      description: 'Ripple is a payment & settlment platform.',
102      feeDescription: 'Transaction fees are paid by users and burned.',
103      website: 'https://ripple.com',
104      source: 'CoinMetrics',
105      tokenTicker: 'XRP',
106      tokenCoingecko: 'ripple',
107    },
108    {
109      id: 'doge',
110      icon: sdk.ipfs.getDataURILoader('QmRpogZjZEKLX33245zT6QSiDENMb26fS922Ds6pp3VzE3', 'image/svg+xml'),
111      name: 'Dogecoin',
112      description: 'Dogecoin is a cryptocurrency based on the "Doge" meme.',
113      feeDescription: 'Transaction fees are paid by users to miners.',
114      website: 'https://dogecoin.com',
115      source: 'CoinMetrics',
116      tokenTicker: 'DOGE',
117      tokenCoingecko: 'dogecoin',
118    },
119    {
120      id: 'xmr',
121      icon: sdk.ipfs.getDataURILoader('QmWVPtKiQYo2up8ewEzGWLWRZHRNcQLn5U38NFBGm7X6cd', 'image/svg+xml'),
122      name: 'Monero',
123      description: 'Monero is a privacy-focused cryptocurrency.',
124      feeDescription: 'Transaction fees are paid by users to miners.',
125      website: 'https://getmonero.org',
126      source: 'CoinMetrics',
127      tokenTicker: 'XMR',
128      tokenCoingecko: 'monero',
129    },
130    {
131      id: 'xlm',
132      icon: sdk.ipfs.getDataURILoader('QmZJAgQbxghu7c47wnY7eqPhFBHcwZedp5ZqA99wEm92UK', 'image/svg+xml'),
133      name: 'Stellar',
134      description: 'Stellar is global payment network.',
135      feeDescription: 'Transaction fees are paid by users into a pool.',
136      website: 'https://stellar.org',
137      source: 'CoinMetrics',
138      tokenTicker: 'XLM',
139      tokenCoingecko: 'stellar',
140    },
141  ];
142
143  const getDailyFeesQuery = (id: string) => async (date: string) => {
144    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v2/assets/${id}/metricdata?metrics=FeeTotUSD&start=${date}&end=${date}`);
145
146    if (!result.metricData.series[0]) {
147      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${date}`);
148    }
149
150    return parseFloat(result.metricData.series[0].values[0]);
151  }
152
153  const getFeeRangeQuery = (id: string) => async (startDate: string, endDate: string) => {
154    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v2/assets/${id}/metricdata?metrics=FeeTotUSD&start=${startDate}&end=${endDate}`);
155
156    if (!result.metricData.series[0]) {
157      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${startDate}`);
158    }
159
160    let totalFees = 0;
161    
162    // We skip the last value, since CoinMetrics date queries include the
163    // last date, but CryptoStats skips it
164    for (let i = 0; i < result.metricData.series.length - 1; i += 1) {
165      totalFees += parseFloat(result.metricData.series[i].values[0]);
166    }
167
168    return totalFees;
169  }
170
171  for (const protocol of protocols) {
172    const { id, ...metadata } = protocol;
173    sdk.register({
174      id,
175      queries: {
176        oneDayTotalFees: getDailyFeesQuery(id),
177        dateRangeTotalFees: getFeeRangeQuery(id),
178      },
179      metadata: {
180        category: 'l1',
181        ...metadata,
182      },
183    });
184  }
185}

It's something off?

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

Adapter Info

Version

0.1.2

License

MIT

IPFS CID

QmcD23Er1iGeJKgnfQX8wxsn1ZdFJHXFhQ1ievxfP3NUNh

CID (source)

QmZ8atGD4QTYzHWQEx4aGLqLByXNTR5hFAUVn5Y4MQbffu

Collections

Author

mihal.eth