Adapter

CoinMetrics - Fees

Sub-Adapters 13

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)

Decred (dcr)

Zcash (zec)

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.4';
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      id: 'dcr',
143      icon: sdk.ipfs.getDataURILoader('QmTSz4gXBzNeLPQKdEJTVaAjcH68E39uvkgTUCKwcK44VT', 'image/webp'),
144      name: 'Decred',
145      description: 'Decred aims to build a community-directed digital currency.',
146      feeDescription: 'Transaction fees are paid by users to miners.',
147      website: 'https://www.decred.org/',
148      source: 'CoinMetrics',
149      tokenTicker: 'DCR',
150      tokenCoingecko: 'decred',
151    },
152    {
153      id: 'zec',
154      icon: sdk.ipfs.getDataURILoader('QmXmNpmiDTrAWxJq3ZQmVS3BJkb2WLiaLp1VYs4pWGwRD1', 'image/webp'),
155      name: 'Zcash',
156      description: 'Zcash is a decentralized and open-source cryptocurrency that offers privacy and selective transparency of transactions.',
157      feeDescription: 'Transaction fees are paid by users to miners.',
158      website: 'https://z.cash/',
159      source: 'CoinMetrics',
160      tokenTicker: 'ZEC',
161      tokenCoingecko: 'zcash',
162    },
163  ];
164
165  const getDailyFeesQuery = (id: string) => async (date: string) => {
166    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?page_size=10000&metrics=FeeTotUSD&assets=${id}&start_time=${date}&end_time=${date}`);
167
168    if (!result.data[0]) {
169      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${date}`);
170    }
171
172    return parseFloat(result.data[0].FeeTotUSD);
173  }
174
175  const getFeeRangeQuery = (id: string) => async (startDate: string, endDate: string) => {
176    const result = await sdk.http.get(`https://community-api.coinmetrics.io/v4/timeseries/asset-metrics?page_size=10000&metrics=FeeTotUSD&assets=${id}&start_time=${startDate}&end_time=${endDate}`);
177
178    if (!result.data[0]) {
179      throw new Error(`Failed to fetch CoinMetrics data for ${id} on ${startDate}`);
180    }
181
182    let totalFees = 0;
183    // return endDate
184    // We skip the last value, since CoinMetrics date queries include the
185    // last date, but CryptoStats skips it
186    for (let i = 0; i < result.data.length - 1; i += 1) {
187      totalFees += parseFloat(result.data[i].FeeTotUSD);
188    }
189
190    return totalFees;
191  }
192
193  for (const protocol of protocols) {
194    const { id, ...metadata } = protocol;
195    sdk.register({
196      id,
197      queries: {
198        oneDayTotalFees: getDailyFeesQuery(id),
199        dateRangeTotalFees: getFeeRangeQuery(id),
200      },
201      metadata: {
202        category: 'l1',
203        ...metadata,
204      },
205    });
206  }
207}
208

It's something off?

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

Adapter Info

Version

0.1.4

License

MIT

IPFS CID

QmPCc7RJRmQAmDRHgq9bHgwULFyXnrxk34hnWUMu7NLhHj

CID (source)

QmXZHRNFkFsxhRGZMNs47qoPvzPujtznjz3WdaA5ngmHV1

Collections

fees

Author

jochemla.sismo.eth