Sub-Adapters 1
Preview and test each sub adapter.
Optimism (optimism)
Metadata
- ID
- optimism
- category
"l2"
- name
"Optimism"
- description
"Optimism is a Layer 2 Optimistic Rollup network designed to utilize the strong security guarantees of Ethereum while reducing its cost and latency."
- feeDescription
"Every Optimism transaction has two costs: An L2 (execution) fee and an L1 (security) fee."
- source
"The Graph Protocol"
- website
"https://www.optimism.io"
- blockchain
"Optimism"
- icon
- protocolLaunch
"2021-11-16"
- tokenLaunch
"2022-06-01"
- tokenCoingecko
"optimism"
Queries
Adapter Code
Check the entire code written for the Adapter.
Source code
1export const name = 'Optimism Fees';
2export const version = '0.1.5';
3export const license = 'MIT';
4
5export function setup(sdk: Context) {
6 const oneDayTotalFees = async (date: string): Promise<number> => {
7 const nextDay = new Date(date);
8 nextDay.setDate(nextDay.getDate() + 1);
9 const subgraph = 'ap0calyp/optimism-fee-withdrawn';
10 const provider = sdk.ethers.getProvider('optimism');
11
12 const feeWallet = '0x4200000000000000000000000000000000000011';
13
14 const graphQuery = `query feesWithdrawn($startBlock: Int!, $endBlock: Int!) {
15 start: withdrawn(id: 1, block: { number: $startBlock }) {
16 amount
17 }
18 end: withdrawn(id: 1, block: {number: $endBlock}) {
19 amount
20 }
21 }`;
22
23 const [startBlock, endBlock,ethPrice] = await Promise.all([
24 sdk.chainData.getBlockNumber(date, 'optimism'),
25 sdk.chainData.getBlockNumber(nextDay, 'optimism'),
26 sdk.coinGecko.getHistoricalPrice('ethereum', date)
27 ]);
28
29 const [startBalance,endBalance, { start: startWithdrawn, end: endWithdrawn }] = await Promise.all([
30 provider.getBalance(feeWallet, startBlock),
31 provider.getBalance(feeWallet, endBlock),
32 sdk.graph.query(subgraph,graphQuery,{ variables: { startBlock, endBlock } })
33 ])
34
35 if (endWithdrawn === null) {
36 throw new Error(`No Optimism data found on ${date}`);
37 }
38
39 const ethBalanceChange = endBalance - startBalance;
40 const withdrawn = endWithdrawn.amount - (startWithdrawn?.amount || 0)
41 const fees = (withdrawn + ethBalanceChange) / 1e18
42 return fees * ethPrice
43 }
44
45 sdk.register({
46 id: `optimism`,
47 queries: {
48 oneDayTotalFees
49 },
50 metadata: {
51 category: 'l2',
52 name: 'Optimism',
53 description: 'Optimism is a Layer 2 Optimistic Rollup network designed to utilize the strong security guarantees of Ethereum while reducing its cost and latency.',
54 feeDescription: 'Every Optimism transaction has two costs: An L2 (execution) fee and an L1 (security) fee.',
55 source: 'The Graph Protocol',
56 website: 'https://www.optimism.io',
57 blockchain: 'Optimism',
58 icon: sdk.ipfs.getDataURILoader('QmegSBGwcyoYU9yrgGS2U13DAexE9VYdetTn9rqa88yjZK', 'image/svg+xml'),
59 protocolLaunch: '2021-11-16',
60 tokenLaunch: '2022-06-01',
61 tokenCoingecko: 'optimism',
62 }
63 })
64}
It's something off?
Report it to the discussion board on Discord, we will take care of it.