Sub-Adapters 8
Preview and test each sub adapter.
Arbitrum Nova (arbitrum-nova)
Arbitrum One (arbitrum-one)
Aztec Protocol (aztec)
Boba (boba)
Metis (metis)
Optimism (optimism)
Polygon zkEVM (polygon-zkevm)
ZKSync Era (zksync-era)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Rollup Gas Consumed - Subgraph';
2export const version = '0.1.2';
3export const license = 'MIT';
4export const changeLog = 'Create adapter';
5
6interface Protocol {
7 id: string;
8 name: string;
9 bundle?: string;
10 address?: string;
11 addresses?: string[];
12 icon: string;
13 category?: string;
14 mimeType?: string;
15 l2BeatSlug?: string;
16 website?: string;
17}
18
19const protocols: Protocol[] = [
20 {
21 id: 'arbitrum-nova',
22 name: 'Arbitrum Nova',
23 icon: 'QmXgPkKwnHGGUcoGA52FNVW83fjeyjHFh8VwCgPPqEXkfX',
24 l2BeatSlug: 'nova',
25 website: 'https://nova.arbitrum.io/',
26 },
27 {
28 id: 'arbitrum-one',
29 name: 'Arbitrum One',
30 icon: 'QmeRunQGxv3haLoMfgwD2VjKwScf7gDQiA1DCYd1HNBCG6',
31 l2BeatSlug: 'arbitrum',
32 website: 'https://arbitrum.one',
33 },
34 {
35 id: 'aztec',
36 name: 'Aztec Protocol',
37 icon: 'QmaaYiAtFKGPeHRR629yQqkDAqzcpywfbEjun5KmhE6QH1',
38 l2BeatSlug: 'aztec',
39 website: 'https://aztec.network',
40 },
41 {
42 id: 'boba',
43 name: 'Boba',
44 icon: 'QmWzHpbSVBX7gc32DqLibssMpxffSfyeAPu2QiSidfjmbh',
45 mimeType: 'image/png',
46 l2BeatSlug: 'boba',
47 },
48 // Loopring data seems inaccurate right now (roughly double)
49 // {
50 // id: 'loopring',
51 // name: 'Loopring',
52 // icon: 'QmZC3WbPX77hYvh6EXuMiBAHBHd3M81EA4BJiKRLyL6vMk',
53 // l2BeatSlug: 'loopring',
54 // },
55 {
56 id: 'metis',
57 name: 'Metis',
58 icon: 'QmRqTqvajx8DFhzda89qdDuADTfw53kPhzPUXzxKAG4M6z',
59 category: 'optimistic-chain',
60 mimeType: 'image/png',
61 l2BeatSlug: 'metis',
62 },
63 {
64 id: 'optimism',
65 name: 'Optimism',
66 icon: 'QmS1mBxRRDjuVPAPkjrmrnVgzYwyfchjvRZTH11vgjqabG',
67 l2BeatSlug: 'optimism',
68 website: 'https://optimism.io'
69 },
70 // {
71 // id: 'zk-sync',
72 // name: 'ZKSync',
73 // icon: 'QmXeCkZTkG8nuNAMbNykxfu1ybJHyDsu8EgVJ7RKuza5WA',
74 // l2BeatSlug: 'zksync',
75 // website: 'https://zksync.io',
76 // },
77 {
78 id: 'polygon-zkevm',
79 name: 'Polygon zkEVM',
80 icon: 'QmcakfgwRpoXotCQdBc8fos31X4p9ujvJBuigSh9C59cKS',
81 l2BeatSlug: 'polygon-zkevm',
82 website: 'https://polygon.technology/polygon-zkevm'
83 },
84 {
85 id: 'zksync-era',
86 name: 'ZKSync Era',
87 icon: 'QmXeCkZTkG8nuNAMbNykxfu1ybJHyDsu8EgVJ7RKuza5WA',
88 l2BeatSlug: 'zksync-era',
89 website: 'https://zksync.io'
90 },
91]
92
93const SEC_IN_DAY = 86400;
94
95export function setup(sdk: Context) {
96 const getFeesOnDate = async (protocol: string, date: string) => {
97 const dateId = Math.floor(sdk.date.dateToTimestamp(date) / SEC_IN_DAY);
98 const query = `query {
99 protocolDayData(id: "${protocol}-${dateId}") {
100 usdFees
101 ethFees
102 }
103 nextDay: protocolDayData(id: "${protocol}-${dateId+1}") {
104 usdFees
105 }
106 }`
107 const result = await sdk.graph.query('dmihal/eth-spent-by-rollups', query);
108
109 if (!result.protocolDayData) {
110 throw new Error('Data unavailable');
111 }
112 if (!result.nextDay) {
113 throw new Error('Day incomplete');
114 }
115
116 return result.protocolDayData;
117 }
118
119 const oneDayFeesPaidNative = (id: string) => async (date: string) => {
120 const result = await getFeesOnDate(id, date);
121 return parseFloat(result.ethFees);
122 }
123
124 const oneDayFeesPaidUSD = (id: string) => async (date: string) => {
125 const result = await getFeesOnDate(id, date);
126 return parseFloat(result.usdFees);
127 }
128
129 for (const protocol of protocols) {
130 sdk.register({
131 id: protocol.id,
132 bundle: protocol.bundle,
133 queries: {
134 oneDayFeesPaidNative: oneDayFeesPaidNative(protocol.id),
135 oneDayFeesPaidUSD: oneDayFeesPaidUSD(protocol.id),
136 },
137 metadata: {
138 name: protocol.name,
139 icon: sdk.ipfs.getDataURILoader(protocol.icon, protocol.mimeType || 'image/svg+xml'),
140 l2BeatSlug: protocol.l2BeatSlug || null,
141 website: protocol.website || null,
142 category: protocol.category || 'rollup',
143 },
144 });
145 }
146}
147
It's something off?
Report it to the discussion board on Discord, we will take care of it.