Skip to content

Commit aefdf2e

Browse files
Merge branch 'main' into Message-expiration
2 parents 7490333 + ce2b7c7 commit aefdf2e

File tree

7 files changed

+185
-139
lines changed

7 files changed

+185
-139
lines changed

pages/interop/tutorials/transfer-superchainERC20.mdx

Lines changed: 98 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ categories:
2121
is_imported_content: 'false'
2222
---
2323

24-
import { Callout, Steps } from 'nextra/components'
24+
import { Callout, Steps, Tabs } from 'nextra/components'
2525
import { AutorelayCallout } from '@/components/AutorelayCallout'
2626

2727
<Callout>
@@ -45,110 +45,144 @@ Note that this tutorial provides step-by-step instructions for transferring `Sup
4545
Cross-chain transfers cannot be reversed.
4646
</Callout>
4747

48-
### What you'll build
49-
50-
* A TypeScript application to transfer `SuperchainERC20` tokens between chains
48+
<details>
49+
<summary>About this tutorial</summary>
5150

52-
### What you'll learn
51+
**What you'll learn**
5352

54-
* How to send `SuperchainERC20` tokens on the blockchain and between blockchains
55-
* How to relay messages between chains
53+
* How to send `SuperchainERC20` tokens on the blockchain and between blockchains
54+
* How to relay messages between chains
5655

57-
## Prerequisites
56+
**Technical knowledge**
5857

59-
Before starting this tutorial, ensure your development environment meets the following requirements:
58+
* Intermediate TypeScript knowledge
59+
* Understanding of smart contract development
60+
* Familiarity with blockchain concepts
6061

61-
### Technical knowledge
62+
**Development environment**
6263

63-
* Intermediate TypeScript knowledge
64-
* Understanding of smart contract development
65-
* Familiarity with blockchain concepts
64+
* Unix-like operating system (Linux, macOS, or WSL for Windows)
65+
* Node.js version 16 or higher
66+
* Git for version control
6667

67-
### Development environment
68+
**Required tools**
6869

69-
* Unix-like operating system (Linux, macOS, or WSL for Windows)
70-
* Node.js version 16 or higher
71-
* Git for version control
70+
The tutorial uses these primary tools:
7271

73-
### Required tools
72+
* Node: For running TypeScript code from the command line
73+
* Viem: For blockchain interaction
74+
</details>
7475

75-
The tutorial uses these primary tools:
76+
### What you'll build
7677

77-
* Foundry: For issuing transactions
78-
* TypeScript: For implementation
79-
* Node: For running TypeScript code from the command line
80-
* Viem: For blockchain interaction
78+
* Commands to transfer `SuperchainERC20` tokens between chains
79+
* A TypeScript application to transfer `SuperchainERC20` tokens between chains
8180

8281
## Directions
8382

8483
<Steps>
8584
### Preparation
8685

87-
You need onchain `SuperchainERC20` tokens.
88-
You can [deploy your own token](./deploy-superchain-erc20), but in this tutorial we will use [`CustomSuperchainToken`](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8), existing `SuperchainERC20` token on the [Interop devnet](/interop/tools/devnet).
86+
1. If you are using Supersim, setup the [SuperchainERC20 starter kit](/app-developers/starter-kit#setup).
87+
The `pnpm dev` step also starts Supersim.
8988

90-
1. Create environment variables for the RPC endpoints for the blockchains and the token address.
89+
2. Store the configuration in environment variables.
9190

92-
```sh
93-
RPC_DEV0=https://interop-alpha-0.optimism.io
94-
RPC_DEV1=https://interop-alpha-1.optimism.io
95-
TOKEN_ADDRESS=0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8
96-
```
91+
<Tabs items={['Supersim', 'Devnets']}>
92+
<Tabs.Tab>
93+
```sh
94+
PRIVATE_KEY=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
95+
USER_ADDRESS=0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
96+
URL_CHAIN_A=http://127.0.0.1:9545
97+
URL_CHAIN_B=http://127.0.0.1:9546
98+
CHAIN_B_ID=`cast chain-id --rpc-url $URL_CHAIN_B`
99+
TOKEN_ADDRESS=`cat superchainerc20-starter/packages/contracts/broadcast/multi/SuperchainERC20Deployer.s.sol-latest/run.json | jq --raw-output .deployments[0].transactions[0].contractAddress`
100+
```
101+
</Tabs.Tab>
97102

98-
2. Set `PRIVATE_KEY` to the private key of an address that has [Sepolia ETH](https://cloud.google.com/application/web3/faucet/ethereum/sepolia).
103+
<Tabs.Tab>
104+
1. Set `PRIVATE_KEY` to the private key for an address that has ETH on the two devnets.
99105

100-
```sh
101-
export PRIVATE_KEY=0x<private key here>
102-
MY_ADDRESS=`cast wallet address $PRIVATE_KEY`
103-
```
106+
2. Run these commands to specify the rest of the environment variables.
104107

105-
3. Send ETH to the two L2 blockchains.
108+
```sh
109+
USER_ADDRESS=`cast wallet address --private-key $PRIVATE_KEY`
110+
URL_CHAIN_A=https://interop-alpha-0.optimism.io
111+
URL_CHAIN_B=https://interop-alpha-1.optimism.io
112+
CHAIN_B_ID=`cast chain-id --rpc-url $URL_CHAIN_B`
113+
TOKEN_ADDRESS=0x0FAe7deDb9CfC2d8288d432B85998e6b263F3A72
114+
```
115+
</Tabs.Tab>
116+
</Tabs>
106117

107-
```sh
108-
cast send --rpc-url https://endpoints.omniatech.io/v1/eth/sepolia/public --private-key $PRIVATE_KEY --value 0.02ether 0x7385d89d38ab79984e7c84fab9ce5e6f4815468a
109-
cast send --rpc-url https://endpoints.omniatech.io/v1/eth/sepolia/public --private-key $PRIVATE_KEY --value 0.02ether 0x55f5c4653dbcde7d1254f9c690a5d761b315500c
110-
```
118+
3. Obtain tokens on chain A.
111119

112-
4. Wait a few minutes until you can see the ETH [on the block explorer](https://sid.testnet.routescan.io/) for your address.
120+
<Tabs items={['Supersim', 'Devnets']}>
121+
<Tabs.Tab>
122+
```sh
123+
ONE=`echo 1 | cast to-wei`
124+
cast send $TOKEN_ADDRESS "mintTo(address,uint256)" $USER_ADDRESS $ONE --private-key $PRIVATE_KEY --rpc-url $URL_CHAIN_A
125+
```
126+
</Tabs.Tab>
127+
128+
<Tabs.Tab>
129+
```sh
130+
cast send $TOKEN_ADDRESS "faucet()" --private-key $PRIVATE_KEY --rpc-url $URL_CHAIN_A
131+
```
132+
</Tabs.Tab>
133+
</Tabs>
113134

114135
<details>
115136
<summary>Sanity check</summary>
116137

117-
Check the ETH balance of your address on both blockchains.
138+
Check that you have at least one token on chain A.
118139

119140
```sh
120-
cast balance --ether $MY_ADDRESS --rpc-url $RPC_DEV0
121-
cast balance --ether $MY_ADDRESS --rpc-url $RPC_DEV1
141+
cast call $TOKEN_ADDRESS "balanceOf(address)" $USER_ADDRESS --rpc-url $URL_CHAIN_A | cast from-wei
122142
```
123143
</details>
124144

125-
5. Obtain tokens on Interop devnet 0.
126-
When using `CustomSuperchainToken`, there are two ways to do this:
145+
### Transfer tokens using the command line
127146

128-
* Use the [block explorer](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8/contract/420120000/writeContract?chainid=420120000) and a browser wallet to run the [faucet](https://sid.testnet.routescan.io/address/0xF3Ce0794cB4Ef75A902e07e5D2b75E4D71495ee8/contract/420120000/writeContract?chainid=420120000#F6) function.
147+
1. Specify configuration variables.
129148

130-
* Use `cast` to call the `faucet` function.
149+
```sh
150+
TENTH=`echo 0.1 | cast to-wei`
151+
INTEROP_BRIDGE=0x4200000000000000000000000000000000000028
152+
```
131153

132-
```sh
133-
cast send --rpc-url $RPC_DEV0 --private-key $PRIVATE_KEY $TOKEN_ADDRESS "faucet()"
134-
```
154+
2. See your balance on both blockchains.
135155

136-
<details>
137-
<summary>Sanity check</summary>
156+
```sh
157+
cast call $TOKEN_ADDRESS "balanceOf(address)" $USER_ADDRESS --rpc-url $URL_CHAIN_A | cast from-wei
158+
cast call $TOKEN_ADDRESS "balanceOf(address)" $USER_ADDRESS --rpc-url $URL_CHAIN_B | cast from-wei
159+
```
138160

139-
Run this command to check your token balance.
161+
3. Call [`SuperchainTokenBridge`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol) to transfer tokens.
140162

141-
```sh
142-
cast call --rpc-url $RPC_DEV0 $TOKEN_ADDRESS "balanceOf(address)" $MY_ADDRESS | cast --from-wei
143-
```
144-
</details>
163+
```sh
164+
cast send $INTEROP_BRIDGE "sendERC20(address,address,uint256,uint256)" $TOKEN_ADDRESS $USER_ADDRESS $TENTH $CHAIN_B_ID --private-key $PRIVATE_KEY --rpc-url $URL_CHAIN_A
165+
```
166+
167+
4. See your balance on both blockchains.
168+
169+
```sh
170+
cast call $TOKEN_ADDRESS "balanceOf(address)" $USER_ADDRESS --rpc-url $URL_CHAIN_A | cast from-wei
171+
cast call $TOKEN_ADDRESS "balanceOf(address)" $USER_ADDRESS --rpc-url $URL_CHAIN_B | cast from-wei
172+
```
145173

146174
### Transfer tokens using TypeScript
147175

148176
We are going to use a [Node](https://nodejs.org/en) project, to be able to use [`@eth-optimism/viem`](https://www.npmjs.com/package/@eth-optimism/viem) to send the executing message.
149177
We use [TypeScript](https://www.typescriptlang.org/) to have [type safety](https://en.wikipedia.org/wiki/Type_safety) combined with JavaScript functionality.
150178

151-
1. Initialize a new Node project.
179+
1. Export environment variables
180+
181+
```sh
182+
export PRIVATE_KEY TOKEN_ADDRESS CHAIN_B_ID
183+
```
184+
185+
2. Initialize a new Node project.
152186

153187
```sh
154188
mkdir xfer-erc20
@@ -158,69 +192,25 @@ The tutorial uses these primary tools:
158192
mkdir src
159193
```
160194

161-
2. Edit `package.json` to add the `start` script.
162-
163-
```json
164-
{
165-
"name": "xfer-erc20",
166-
"version": "1.0.0",
167-
"main": "index.js",
168-
"scripts": {
169-
"test": "echo \"Error: no test specified\" && exit 1",
170-
"start": "tsx src/xfer-erc20.mts"
171-
},
172-
"keywords": [],
173-
"author": "",
174-
"license": "ISC",
175-
"type": "module",
176-
"description": "",
177-
"devDependencies": {
178-
"@eth-optimism/viem": "^0.3.2",
179-
"@types/node": "^22.13.4",
180-
"tsx": "^4.19.3",
181-
"viem": "^2.23.3"
182-
}
183-
}
184-
```
185-
186195
3. Create `src/xfer-erc20.mts`:
187196

188-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts hash=26d412ead555cdd59c16676a4dcd91e8
197+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts hash=2964a6dcafacb8b7dc1e115a54fb3b7c
189198
```
190199

191200
<details>
192201
<summary>Explanation of `xfer-erc20.mts`</summary>
193202

194-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L79-L84 hash=5084a0cf4064dc7cfaf1cf0f88e1f2d1
203+
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L76-L81 hash=b144852a4fa9ae45e79ec6f124e48e79
195204
```
196205

197206
Use `@eth-optimism/viem`'s `walletActionsL2().sendSuperchainERC20` to send the `SuperchainERC20` tokens.
198207
Internally, this function calls [`SuperchainTokenBridge.sendERC20`](https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/L2/SuperchainTokenBridge.sol#L52-L78) to send the tokens.
199-
200-
<AutorelayCallout />
201-
202-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L88-L90 hash=b353aebabd92c4af52858461d18fe8cd
203-
```
204-
205-
To relay a message, we need the information in the receipt.
206-
Also, we need to wait until the transaction with the relayed message is actually part of a block.
207-
208-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L92-L94 hash=47d2387a65e4a5f5dbfa98868c2c5abc
209-
```
210-
211-
A single transaction can send multiple messages.
212-
But here we know we sent just one, so we look for the first one in the list.
213-
214-
```typescript file=<rootDir>/public/tutorials/xfer-erc20.mts#L96-L99 hash=4cf177987a894a8cb58ae5a3e9d731e8
215-
```
216-
217-
This is how you use `@eth-optimism/viem` to create an executing message.
218208
</details>
219209

220-
4. Run the TypeScript program, and see the change in your `CustomSuperchainToken` balances.
210+
4. Run the TypeScript program, and see the change in your token balances.
221211

222212
```sh
223-
npm start
213+
pnpm tsx src/xfer-erc20.mts
224214
```
225215
</Steps>
226216

pages/notices/_meta.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2+
"pectra-fees": "Pectra user fees notice",
3+
"pectra-changes": "Preparing for Pectra breaking changes",
24
"superchain-withdrawal-pause-test": "Superchain withdrawal pause test",
5+
"holocene-changes": "Preparing for Holocene breaking changes",
36
"upgrade-15": "Upgrade 15: Isthmus Hard Fork",
47
"upgrade-14": "Upgrade 14: MT-Cannon and Isthmus L1 Contracts",
58
"upgrade-13": "Upgrade 13: OPCM and incident response improvements",
69
"blob-fee-bug": "Superchain testnets' blob fee bug",
7-
"pectra-changes": "Preparing for Pectra breaking changes",
8-
"holocene-changes": "Preparing for Holocene breaking changes",
9-
"sdk-deprecation": "Preparing for Optimism SDK deprecation",
10-
"custom-gas-tokens-deprecation": "Preparing for Custom Gas Tokens deprecation"
10+
"custom-gas-tokens-deprecation": "Preparing for Custom Gas Tokens deprecation",
11+
"sdk-deprecation": "Preparing for Optimism SDK deprecation"
1112
}

pages/notices/pectra-changes.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ The following sections are how chain operators can prepare the first part of the
102102

103103
* [`op-batcher/v1.11.5`](https://github.com/ethereum-optimism/optimism/releases/tag/op-batcher%2Fv1.11.5).
104104
* [`op-proposer/v1.10.0`](https://github.com/ethereum-optimism/optimism/releases/tag/op-proposer%2Fv1.10.0).
105+
106+
### Double-check your fee scalars
107+
See [this notice about modifying fee scalars after the Pectra upgrade on L1](/notices/pectra-fees).
105108
</Steps>
106109

107110
## For fault proof enabled chains

pages/notices/pectra-fees.mdx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: L1 Pectra user fees and chain profitability
3+
description: L1 Pectra affect on user fees and chain profitability analysis
4+
lang: en-US
5+
content_type: notice
6+
topic: pectra-fees
7+
personas:
8+
- chain-operator
9+
- node-operator
10+
categories:
11+
- security
12+
- protocol
13+
- infrastructure
14+
- l1-contracts
15+
is_imported_content: 'false'
16+
---
17+
18+
import { Callout } from 'nextra/components'
19+
20+
# Pectra impact on user fees and chain profitability
21+
22+
The Ethereum L1 Pectra upgrade has introduced changes to calldata gas costs via [EIP-7623](https://eips.ethereum.org/EIPS/eip-7623) that may affect OP Stack chain profitability in specific configurations and market conditions. This notice outlines the potential impact on your chain and recommends specific actions.
23+
24+
[EIP-7623](https://eips.ethereum.org/EIPS/eip-7623) increases the amount of gas payable for calldata-heavy transactions. These include such transactions as those used by OPStack chains *before the [Ecotone upgrade](https://specs.optimism.io/protocol/ecotone/overview.html)* when blob data availability (blob DA) was introduced.
25+
26+
Blob DA has now been the default and recommended option for the OPStack for some time, so almost all chains make use of it. In order to continue to optimize for chains operating with blob DA, the Optimism protocol's current DA fee pricing formula has remained unchanged despite Pectra activating on Ethereum. This has allowed chains using blob DA to continue without updating their fee config.
27+
28+
Chains configured for blob data availability remain entirely unaffected by the Pectra upgrade. However, chains configured for calldata (i.e. operating in a legacy DA mode) may experience a reduction in profitability. It is possible for such chains to be making a loss on data availability costs under certain market conditions. Therefore all chains should check their fee scalar config.
29+
30+
## Actions required
31+
32+
Since the Ecotone upgrade, the Optimism protocol prices L2 transactions using a function that incorporates the L1 base fee as well as the L1 blob base fee. The other inputs are the so-called "Ecotone scalars": operator-controlled parameters stored in the SystemConfig contract which can be used to tune the chain's (approximate) target profit margin for DA.
33+
34+
Please review your [Ecotone scalar chain configuration](/operators/chain-operators/management/blobs).
35+
36+
<Callout type="info">
37+
If your chain uses a zero blob base fee scalar, meaning it's configured to price for calldata only, you may need to update the base fee scalar and/or the blob base fee scalar. Otherwise, no action is necessary and the rest of this section does not apply.
38+
</Callout>
39+
40+
### Chains charging for calldata DA and spending on calldata DA
41+
If your chain uses a zero blob base fee scalar and your batcher is configured to submit using calldata *only*, then you should take the opportunity to check your chain's profit margin according to [this guide](/operators/chain-operators/management/blobs) and make any adjustments to your Ecotone scalars as necessary. This will ensure that, since you are paying exclusively for calldata DA, you are charging users appropriately such that your target profit margin is as desired.
42+
43+
If your profit margin was perfectly tuned before Pectra, then you should scale your base fee scalar by 10/4.
44+
45+
### Chains charging for calldata DA and spending on blob DA
46+
If your chain uses a zero blob base fee scalar and your batcher is configured to submit using blob DA, or configured to automatically choose the cheaper of the two DA modes, then you should adjust your Ecotone scalars for blob DA pricing (meaning a nonzero blob base fee scalar). You are referred back to [this guide](/operators/chain-operators/management/blobs). Doing so will ensure that you are charging accurately for using blob DA. Without such a change it is likely that you are overcharging users most of the time, and undercharging them in the rare occasions where blob DA is more expensive than calldata DA on Ethereum mainnet.
47+
48+
As ever, you may continue to tweak the Ecotone scalars as desired in order to adjust the profitability of your chain.
49+
50+
### Technical references
51+
52+
* [Optimism protocol specification - Ecotone L1 cost fee changes](https://specs.optimism.io/protocol/exec-engine.html#ecotone-l1-cost-fee-changes-eip-4844-da)
53+
* [Optimism protocol specification - Fjord execution engine fees](https://specs.optimism.io/protocol/fjord/exec-engine.html#fees)
54+
* [Implementation source code](https://github.com/ethereum-optimism/op-geth/blob/3d7afdc2701b74c5987e31521e2c336c4511afdf/core/types/rollup_cost.go#L527)

pages/operators/chain-operators/management/blobs.mdx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ This guide walks you through how to switch to using blobs for your chain after E
4949
For example, if you wished to increase your margin on L1 data costs by \~10%, you would do:
5050

5151
```
52-
newBaseFeeScalar= prevBaseFeeScalar * 1.1
52+
newBaseFeeScalar = prevBaseFeeScalar * 1.1
5353
newBlobBaseFeeScalar = prevBlobBaseFeeScalar * 1.1
5454
```
5555

@@ -121,6 +121,10 @@ blobs back to using calldata.
121121
to get a better estimate for scalar values on your chain. The following
122122
information is tuned to a network like OP Mainnet.
123123

124+
<Callout type="warning">
125+
Since the Pectra upgrade on L1, chains which exclusively use calldata DA need to scale up their BaseFeeScalar by 10/4. See [this notice](/notices/pectra-fees).
126+
</Callout>
127+
124128
Chains can update their fees to increase or decrease their margin. If using calldata, then `BaseFeeScalar` should be scaled to achieve the desired margin.
125129
For example, to increase your L1 Fee margin by 10%:
126130

@@ -145,6 +149,10 @@ blobs back to using calldata.
145149
* Ensure your `OP_BATCHER_MAX_CHANNEL_DURATION` is properly set to maximize savings. **NOTE:** While setting a high value here will lower costs, it will be less meaningful than for low throughput chains using blobs. See [OP Batcher Max Channel Configuration](/operators/chain-operators/configuration/batcher#set-your--op_batcher_max_channel_duration) for more details.
146150
</Steps>
147151

152+
## Use auto DA mode in your batcher
153+
The batcher now supports automatically switching from blobs to calldata depending on which DA type is more affordable. This is an optimization which allows for a slightly better DA profit margin for your chain.
154+
To enable this mode, set `OP_BATCHER_DATA_AVAILABILITY_TYPE=auto`.
155+
148156
## Other considerations
149157

150158
* For information on L1 Data Fee changes related to the Ecotone upgrade, visit the [Transaction Fees page](/stack/transactions/fees#ecotone).

0 commit comments

Comments
 (0)