Sub-Adapters 15
Preview and test each sub adapter.
Arbitrum One (arbitrum-one)
Aztec Protocol (aztec)
Boba (boba)
Deversifi (deversifi)
dYdX (dydx)
Polygon Hermez (hermez)
Immutable X (immutable-x)
Loopring (loopring)
Metis (metis)
Optimism (optimism)
Sorare (sorare)
Starknet (starknet)
Starkware Shared Prover (starkware-prover)
ZKSync (zk-sync)
ZKSwap V2 (zkswap-v2)
Adapter Code
Check the entire code written for the Adapter.
Source code
Showing TS source.
1export const name = 'Rollup Gas Consumed';
2export const version = '0.0.11';
3export const license = 'MIT';
4export const changeLog = 'Add new ZKSync operator';
5
6interface Protocol {
7 id: string;
8 name: string;
9 bundle?: string;
10 address?: string;
11 addresses?: string[];
12 icon: string;
13 mimeType?: string;
14 l2BeatSlug?: string;
15 website?: string;
16}
17
18
19const protocols: Protocol[] = [
20 {
21 id: 'arbitrum-one',
22 name: 'Arbitrum One',
23 address: '0xa4b10ac61e79ea1e150df70b8dda53391928fd14', // Sequencer
24 icon: 'QmeRunQGxv3haLoMfgwD2VjKwScf7gDQiA1DCYd1HNBCG6',
25 l2BeatSlug: 'arbitrum',
26 website: 'http://arbitrum.io',
27 },
28 {
29 id: 'aztec',
30 name: 'Aztec Protocol',
31 address: '0xfcf75295f242c4e87203abb5d7c9bbeda90a8895',
32 icon: 'QmaaYiAtFKGPeHRR629yQqkDAqzcpywfbEjun5KmhE6QH1',
33 l2BeatSlug: 'aztec',
34 website: 'https://aztec.network',
35 },
36 {
37 id: 'boba',
38 name: 'Boba',
39 address: '0x702ad5c5fb87aace54978143a707d565853d6fd5',
40 icon: 'QmWzHpbSVBX7gc32DqLibssMpxffSfyeAPu2QiSidfjmbh',
41 mimeType: 'image/png',
42 l2BeatSlug: 'boba',
43 },
44 {
45 id: 'deversifi',
46 name: 'Deversifi',
47 bundle: 'starkware',
48 icon: 'QmNp62iWbF4NjsNSVDjsS7Y9s1tJEmuFQMvGy1et35fNGS',
49 address: '0x8a6c80aab6497e2db35817817b593b79d78f6ae5',
50 l2BeatSlug: 'deversifi',
51 },
52 {
53 id: 'dydx',
54 name: 'dYdX',
55 address: '0x8129b737912e17212c8693b781928f5d0303390a',
56 icon: 'QmZaL4DUTSbM7MGTcWzkJrLjm7U8ZmyCDk2r5imC8cahXS',
57 l2BeatSlug: 'dydx',
58 website: 'https://dydx.exchange',
59 },
60 {
61 id: 'hermez',
62 name: 'Polygon Hermez',
63 address: '0xc3867da55e14b722ab2a8e9fa4e39f51f5e03de5',
64 icon: 'QmRcHtv6ZaHRCE8KkVwdXazbKTiUqdkL4FFBT1Bt42q1w2',
65 l2BeatSlug: 'hermez',
66 },
67 {
68 id: 'immutable-x',
69 name: 'Immutable X',
70 bundle: 'starkware',
71 address: '0x9b7f7d0d23d4cace5a3157752d0d4e4bf25e927e',
72 icon: 'QmRhT3WhgjQqpr4neWNyxuZA2PzL9robMf4kmvorp7EdEE',
73 website: 'https://immutable.com',
74 },
75 {
76 id: 'loopring',
77 name: 'Loopring',
78 address: '0x7961076f6130092c1c90bd0d2c6f7f54055fa6c7',
79 icon: 'QmZC3WbPX77hYvh6EXuMiBAHBHd3M81EA4BJiKRLyL6vMk',
80 l2BeatSlug: 'loopring',
81 },
82 {
83 id: 'metis',
84 name: 'Metis',
85 address: '0xcdf02971871b7736874e20b8487c019d28090019',
86 icon: 'QmRqTqvajx8DFhzda89qdDuADTfw53kPhzPUXzxKAG4M6z',
87 mimeType: 'image/png',
88 l2BeatSlug: 'metis',
89 },
90 {
91 id: 'optimism',
92 name: 'Optimism',
93 addresses: [
94 '0x6887246668a3b87f54deb3b94ba47a6f63f32985',
95 '0x473300df21d047806a082244b417f96b32f13a33',
96 ],
97 icon: 'QmS1mBxRRDjuVPAPkjrmrnVgzYwyfchjvRZTH11vgjqabG',
98 l2BeatSlug: 'optimism',
99 website: 'https://optimism.io'
100 },
101 {
102 id: 'sorare',
103 name: 'Sorare',
104 icon: 'QmQfxwFyiEzkRjHNUJZ1hERPw3SDHijky3vvNg3UEsBgQu',
105 bundle: 'starkware',
106 address: '0x63881ac44293e22f3c3183a0c4113586abb3e653',
107 l2BeatSlug: 'sorare',
108 website: 'https://sorare.com',
109 },
110 {
111 id: 'starknet',
112 name: 'Starknet',
113 bundle: 'starkware',
114 address: '0x2c169dfe5fbba12957bdd0ba47d9cedbfe260ca7',
115 icon: 'QmTSD1JggWfNa9kRQ9FMJDdkup8HFCC7Eod3zkMEeWr8m8',
116 l2BeatSlug: 'starknet',
117 },
118 {
119 id: 'starkware-prover',
120 name: 'Starkware Shared Prover',
121 bundle: 'starkware',
122 address: '0xff6b2185e357b6e9136a1b2ca5d7c45765d5c591',
123 icon: 'QmNxZ2SfcSxx8mZtbvwx5mfThi2FXXVQR1ndFPQGki31zD',
124 },
125 {
126 id: 'zk-sync',
127 name: 'ZKSync',
128 addresses: [
129 '0xda7357bbce5e8c616bc7b0c3c86f0c71c5b4eabb',
130 '0x18c208921f7a741510a7fc0cfa51e941735dae54',
131 ],
132 icon: 'QmXeCkZTkG8nuNAMbNykxfu1ybJHyDsu8EgVJ7RKuza5WA',
133 l2BeatSlug: 'zksync',
134 website: 'https://zksync.io',
135 },
136 {
137 id: 'zkswap-v2',
138 name: 'ZKSwap V2',
139 address: '0x38101ae98196c8bcf7df1835bf3983b384272ae4',
140 icon: 'Qme3tdUeqfaZmX7DJ8ivVEJjwQkS6rJzPW7A6MRJyvb9Ts',
141 mimeType: 'image/png',
142 website: 'https://zks.org',
143 },
144]
145
146export function setup(sdk: Context) {
147 const getETHFeesBetweenBlocks = async (address: string, startblock: number, endblock: number) => {
148 const txs = await sdk.etherscan.query({
149 module: 'account',
150 action: 'txlist',
151 address,
152 startblock,
153 endblock,
154 }).catch(() => []); // TODO: remove this catch once 'No transactions found' errors handled
155
156 let total = 0;
157
158 for (const tx of txs) {
159 if (tx.from === address) {
160 total += tx.gasUsed * tx.gasPrice / 1e18;
161 }
162 }
163
164 return total;
165 }
166
167 const oneDayFeesPaidNative = (addresses: string | string[]) => async (date: string) => {
168 const [startblock, endblock] = await Promise.all([
169 sdk.chainData.getBlockNumber(date),
170 sdk.chainData.getBlockNumber(sdk.date.offsetDaysFormatted(date, 1)),
171 ]);
172
173 const _addresses = Array.isArray(addresses) ? addresses : [addresses];
174
175 const feesPerAddress = await Promise.all(_addresses.map(
176 (address: string) => getETHFeesBetweenBlocks(address, startblock, endblock))
177 )
178 const totalFees = feesPerAddress.reduce((total: number, current: number) => total + current, 0);
179
180 return totalFees;
181 }
182
183 const oneDayFeesPaidUSD = (address: string | string[]) => async (date: string) => {
184 const [ethPrice, feesInETH] = await Promise.all([
185 sdk.coinGecko.getHistoricalPrice('ethereum', date),
186 oneDayFeesPaidNative(address)(date),
187 ]);
188
189 return ethPrice * feesInETH;
190 }
191
192 sdk.registerBundle('starkware', {
193 name: 'Starkware',
194 subtitle: 'Shared Prover Applications',
195 icon: sdk.ipfs.getDataURILoader('QmNxZ2SfcSxx8mZtbvwx5mfThi2FXXVQR1ndFPQGki31zD', 'image/svg+xml'),
196 description: 'Starkware technology powers many ZK rollups on Ethereum, and security costs are shared using the Starkware Shared Prover.',
197 website: 'https://starkware.co',
198 });
199
200 for (const protocol of protocols) {
201 sdk.register({
202 id: protocol.id,
203 bundle: protocol.bundle,
204 queries: {
205 oneDayFeesPaidNative: oneDayFeesPaidNative(protocol.address || protocol.addresses),
206 oneDayFeesPaidUSD: oneDayFeesPaidUSD(protocol.address || protocol.addresses),
207 },
208 metadata: {
209 name: protocol.name,
210 icon: sdk.ipfs.getDataURILoader(protocol.icon, protocol.mimeType || 'image/svg+xml'),
211 l2BeatSlug: protocol.l2BeatSlug || null,
212 website: protocol.website || null,
213 },
214 });
215 }
216}
217
It's something off?
Report it to the discussion board on Discord, we will take care of it.