Adapter

Polkadot Fees

Fetches fee & price data from Subscan for Polkadot and other substrate-based chains

Sub-Adapters 2

Preview and test each sub adapter.

Polkadot (polkadot)

Kusama (kusama)

Adapter Code

Check the entire code written for the Adapter.

Source code

Showing TS source.
1export const name = 'Polkadot Fees';
2export const version = '0.1.1';
3export const license = 'MIT';
4export const description = 'Fetches fee & price data from Subscan for Polkadot and other substrate-based chains';
5
6export function setup(sdk: Context) {
7  const getSubstrateData = async (id: string, date: string, divisor: number): Promise<number> => {
8    const followingDay = sdk.date.offsetDaysFormatted(date, 1);
9    const [fees, prices] = await Promise.all([
10      sdk.http.post(`https://${id}.api.subscan.io/api/scan/daily`, {
11        start: date,
12        end: date,
13        format: 'day',
14        category: 'Fee',
15      }),
16      sdk.http.post(`https://${id}.api.subscan.io/api/scan/price/history`, {
17        start: date,
18        end: followingDay,
19      }),
20    ]);
21
22    if (fees.data.list.length === 0 || prices.data.list.length === 0) {
23      throw new Error(`No substrate data found for ${id} on ${date}`);
24    }
25
26    return (fees.data.list[0].balance_amount_total * prices.data.list[0].price) / divisor;
27  }
28
29  sdk.register({
30    id: 'polkadot',
31    queries: {
32      oneDayTotalFees: (date: string) => getSubstrateData('polkadot', date, 10 ** 10),
33    },
34    metadata: {
35      name: 'Polkadot',
36      icon: sdk.ipfs.getDataURILoader('Qmc2A56wLVhqcxeKC3ueje88d9YhEBWgiNXAz32to8yu5g', 'image/svg+xml'),
37      category: 'l1',
38      description: 'Polkadot is a protocol for securing and connecting blockchains.',
39      feeDescription: 'Transaction fees are paid from users to validators.',
40      blockchain: 'Polkadot',
41      source: 'Subscan',
42      website: 'https://polkadot.network',
43      tokenTicker: 'DOT',
44      tokenCoingecko: 'polkadot',
45      protocolLaunch: '2020-07-25',
46      tokenLaunch: '2020-08-19',
47    },
48  });
49
50  sdk.register({
51    id: 'kusama',
52    queries: {
53      oneDayTotalFees: (date: string) => getSubstrateData('kusama', date, 10 ** 12),
54    },
55    metadata: {
56      name: 'Kusama',
57      icon: sdk.ipfs.getDataURILoader('QmQRkTqJpf4GgC86fiimKVMUVxWZixrgGzfw3J43wy3vrb', 'image/svg+xml'),
58      category: 'l1',
59      description: 'Kusama is the "canary chain for early-stage Polkadot development.',
60      feeDescription: 'Transaction fees are paid from users to validators.',
61      blockchain: 'Kusama',
62      source: 'Subscan',
63      website: 'https://kusama.network',
64      tokenTicker: 'KSM',
65      tokenCoingecko: 'kusama',
66      protocolLaunch: '2020-07-25',
67      tokenLaunch: '2020-09-20',
68      events: [
69        {
70          date: '2021-11-11',
71          description: 'First Parachain auction begins',
72        },
73        {
74          date: '2021-11-13',
75          description: 'First Parachain auction ends',
76        },
77      ],
78    },
79  });
80}
81

It's something off?

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

Adapter Info

Version

0.1.1

License

MIT

IPFS CID

QmdA3NsH55KeCa1MBmfWkwyyCziJLNKF5PKCSE3UeNtWkz

CID (source)

QmRvQ84AdpYok9AyViWo2ijGmv5NaEioxL5WcL82n5UvL2

Collections

Author

mihal.eth