Sub-Adapters 11

Preview and test each sub adapter.

ApeX (apex)

RhinoFi (rhinofi)

dYdX (dydx)

Polygon Hermez (hermez)

Immutable X (immutable-x)

Loopring (loopring)

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.17';
3export const license = 'MIT';
4export const changeLog = 'Remove rollups handled by the new subgraph 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
19
20const protocols: Protocol[] = [
21  {
22    id: 'apex',
23    name: 'ApeX',
24    bundle: 'starkware',
25    icon: 'QmSsZicFrmv1j2DkMLVf41sLLkn3U1fVNnKGFq3GSUG6an',
26    address: '0x78e802d42Bbc1834f962A11B54e0F8e07f52d4Fb',
27    l2BeatSlug: 'apex',
28    website: 'https://apex.exchange/',
29  },
30  // {
31  //   id: 'arbitrum-one',
32  //   name: 'Arbitrum One',
33  //   address: '0xa4b10ac61e79ea1e150df70b8dda53391928fd14', // Sequencer
34  //   icon: 'QmeRunQGxv3haLoMfgwD2VjKwScf7gDQiA1DCYd1HNBCG6',
35  //   l2BeatSlug: 'arbitrum',
36  //   website: 'http://arbitrum.io',
37  // },
38  // {
39  //   id: 'aztec',
40  //   name: 'Aztec Protocol',
41  //   address: '0xfcf75295f242c4e87203abb5d7c9bbeda90a8895',
42  //   icon: 'QmaaYiAtFKGPeHRR629yQqkDAqzcpywfbEjun5KmhE6QH1',
43  //   l2BeatSlug: 'aztec',
44  //   website: 'https://aztec.network',
45  // },
46  // {
47  //   id: 'boba',
48  //   name: 'Boba',
49  //   address: '0x702ad5c5fb87aace54978143a707d565853d6fd5',
50  //   icon: 'QmWzHpbSVBX7gc32DqLibssMpxffSfyeAPu2QiSidfjmbh',
51  //   mimeType: 'image/png',
52  //   l2BeatSlug: 'boba',
53  // },
54  // {
55  //   id: 'reddio',
56  //   name: 'Reddio',
57  //   bundle: 'starkware',
58  //   icon: 'QmT7QxqNcvKsBMwW7ktUqvHJ6Gw8H4F29q1yJFeYYVZCHM',
59  //   address: '0x2e1c08E457F0E0F462Ef99eC9271dc5BfAd88b2a',
60  //   l2BeatSlug: 'reddio',
61  // },
62  {
63    id: 'rhinofi',
64    name: 'RhinoFi',
65    bundle: 'starkware',
66    icon: 'QmZMF3zCgtURQjfm6gymE5EVnqzBwTeMbkVKTV9XqvtfTm',
67    mimeType: 'image/png',
68    address: '0x8a6c80aab6497e2db35817817b593b79d78f6ae5',
69    l2BeatSlug: 'rhinofi',
70  },
71  {
72    id: 'dydx',
73    name: 'dYdX',
74    address: '0x8129b737912e17212c8693b781928f5d0303390a',
75    icon: 'QmZaL4DUTSbM7MGTcWzkJrLjm7U8ZmyCDk2r5imC8cahXS',
76    l2BeatSlug: 'dydx',
77    website: 'https://dydx.exchange',
78  },
79  {
80    id: 'hermez',
81    name: 'Polygon Hermez',
82    address: '0xc3867da55e14b722ab2a8e9fa4e39f51f5e03de5',
83    icon: 'QmRcHtv6ZaHRCE8KkVwdXazbKTiUqdkL4FFBT1Bt42q1w2',
84    l2BeatSlug: 'hermez',
85  },
86  {
87    id: 'immutable-x',
88    name: 'Immutable X',
89    bundle: 'starkware',
90    address: '0x9b7f7d0d23d4cace5a3157752d0d4e4bf25e927e',
91    icon: 'QmRhT3WhgjQqpr4neWNyxuZA2PzL9robMf4kmvorp7EdEE',
92    website: 'https://immutable.com',
93  },
94  {
95    id: 'loopring',
96    name: 'Loopring',
97    address: '0x7961076f6130092c1c90bd0d2c6f7f54055fa6c7',
98    icon: 'QmZC3WbPX77hYvh6EXuMiBAHBHd3M81EA4BJiKRLyL6vMk',
99    l2BeatSlug: 'loopring',
100  },
101  // {
102  //   id: 'metis',
103  //   name: 'Metis',
104  //   addresses: [
105  //     '0xcdf02971871b7736874e20b8487c019d28090019',
106  //     '0x9cB01d516D930EF49591a05B09e0D33E6286689D',
107  //   ],
108  //   icon: 'QmRqTqvajx8DFhzda89qdDuADTfw53kPhzPUXzxKAG4M6z',
109  //   category: 'optimistic-chain',
110  //   mimeType: 'image/png',
111  //   l2BeatSlug: 'metis',
112  // },
113  // {
114  //   id: 'myria',
115  //   name: 'Myria',
116  //   bundle: 'starkware',
117  //   address: '0xe997ece81cb8A686206ea6042886B594Ecf6DdED',
118  //   icon: 'QmSUEaoqsAQZQ7oxqp17NjpMBmBG2edG6mJguVdaNKrB1U',
119  //   l2BeatSlug: 'myria',
120  //   website: 'https://myria.com/',
121  // },
122  // {
123  //   id: 'optimism',
124  //   name: 'Optimism',
125  //   addresses: [
126  //     '0x6887246668a3b87f54deb3b94ba47a6f63f32985',
127  //     '0x473300df21d047806a082244b417f96b32f13a33',
128  //   ],
129  //   icon: 'QmS1mBxRRDjuVPAPkjrmrnVgzYwyfchjvRZTH11vgjqabG',
130  //   l2BeatSlug: 'optimism',
131  //   website: 'https://optimism.io'
132  // },
133  {
134    id: 'sorare',
135    name: 'Sorare',
136    icon: 'QmQfxwFyiEzkRjHNUJZ1hERPw3SDHijky3vvNg3UEsBgQu',
137    bundle: 'starkware',
138    address: '0x63881ac44293e22f3c3183a0c4113586abb3e653',
139    l2BeatSlug: 'sorare',
140    website: 'https://sorare.com',
141  },
142  {
143    id: 'starknet',
144    name: 'Starknet',
145    bundle: 'starkware',
146    address: '0x2c169dfe5fbba12957bdd0ba47d9cedbfe260ca7',
147    icon: 'QmTSD1JggWfNa9kRQ9FMJDdkup8HFCC7Eod3zkMEeWr8m8',
148    l2BeatSlug: 'starknet',
149  },
150  {
151    id: 'starkware-prover',
152    name: 'Starkware Shared Prover',
153    bundle: 'starkware',
154    addresses: [
155      '0xff6b2185e357b6e9136a1b2ca5d7c45765d5c591',
156      '0x99Ade43Be1C386423eA4AB53e69EFCD98e211FDA',
157      '0x16D5783a96ab20c9157d7933ac236646B29589A4',
158    ],
159    icon: 'QmNxZ2SfcSxx8mZtbvwx5mfThi2FXXVQR1ndFPQGki31zD',
160  },
161  {
162    id: 'zk-sync',
163    name: 'ZKSync',
164    addresses: [
165      '0xda7357bbce5e8c616bc7b0c3c86f0c71c5b4eabb',
166      '0x18c208921f7a741510a7fc0cfa51e941735dae54',
167    ],
168    icon: 'QmXeCkZTkG8nuNAMbNykxfu1ybJHyDsu8EgVJ7RKuza5WA',
169    l2BeatSlug: 'zksync',
170    website: 'https://zksync.io',
171  },
172  {
173    id: 'zkswap-v2',
174    name: 'ZKSwap V2',
175    address: '0x38101ae98196c8bcf7df1835bf3983b384272ae4',
176    icon: 'Qme3tdUeqfaZmX7DJ8ivVEJjwQkS6rJzPW7A6MRJyvb9Ts',
177    mimeType: 'image/png',
178    website: 'https://zks.org',
179  },
180]
181
182export function setup(sdk: Context) {
183  const getETHFeesBetweenBlocks = async (address: string, startblock: number, endblock: number) => {
184    const txs = await sdk.etherscan.query({
185      module: 'account',
186      action: 'txlist',
187      address,
188      startblock,
189      endblock,
190    }).catch(() => []); // TODO: remove this catch once 'No transactions found' errors handled
191
192    let total = 0;
193
194    for (const tx of txs) {
195      if (tx.from.toLowerCase() === address.toLowerCase()) {
196        total += tx.gasUsed * tx.gasPrice / 1e18;
197      }
198    }
199
200    return total;
201  }
202
203  const oneDayFeesPaidNative = (addresses: string | string[]) => async (date: string) => {
204    const [startblock, endblock] = await Promise.all([
205      sdk.chainData.getBlockNumber(date),
206      sdk.chainData.getBlockNumber(sdk.date.offsetDaysFormatted(date, 1)),
207    ]);
208
209    const _addresses = Array.isArray(addresses) ? addresses : [addresses];
210
211    const feesPerAddress = await Promise.all(_addresses.map(
212      (address: string) => getETHFeesBetweenBlocks(address, startblock, endblock))
213    )
214    const totalFees = feesPerAddress.reduce((total: number, current: number) => total + current, 0);
215
216    return totalFees;
217  }
218
219  const oneDayFeesPaidUSD = (address: string | string[]) => async (date: string) => {
220    const [ethPrice, feesInETH] = await Promise.all([
221      sdk.coinGecko.getHistoricalPrice('ethereum', date),
222      oneDayFeesPaidNative(address)(date),
223    ]);
224
225    return ethPrice * feesInETH;
226  }
227
228  sdk.registerBundle('starkware', {
229    name: 'Starkware',
230    subtitle: 'Shared Prover Applications',
231    icon: sdk.ipfs.getDataURILoader('QmNxZ2SfcSxx8mZtbvwx5mfThi2FXXVQR1ndFPQGki31zD', 'image/svg+xml'),
232    description: 'Starkware technology powers many ZK rollups on Ethereum, and security costs are shared using the Starkware Shared Prover.',
233    website: 'https://starkware.co',
234  });
235
236  for (const protocol of protocols) {
237    sdk.register({
238      id: protocol.id,
239      bundle: protocol.bundle,
240      queries: {
241        oneDayFeesPaidNative: oneDayFeesPaidNative(protocol.address || protocol.addresses),
242        oneDayFeesPaidUSD: oneDayFeesPaidUSD(protocol.address || protocol.addresses),
243      },
244      metadata: {
245        name: protocol.name,
246        icon: sdk.ipfs.getDataURILoader(protocol.icon, protocol.mimeType || 'image/svg+xml'),
247        l2BeatSlug: protocol.l2BeatSlug || null,
248        website: protocol.website || null,
249        category: protocol.category || 'rollup',
250      },
251    });
252  }
253}
254

It's something off?

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

Adapter Info

Version

0.0.17

License

MIT

IPFS CID

QmcDGYcW1g2fzWYWUyjvZFhRAJL5A4V3EXnV4LqkQv9sLG

CID (source)

QmTU214TBd8sETSwxQdLcxvvXca4pv9anLWmWLgiKQumho

Collections

Author

mihal.eth