Skip to content

Commit

Permalink
feat: deploy proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
tremarkley committed Sep 23, 2024
1 parent f400984 commit dfdc930
Show file tree
Hide file tree
Showing 39 changed files with 249 additions and 92,076 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ supersim --interop.autorelay
Run the following command to mint 1000 `L2NativeSuperchainERC20` tokens to the recipient address:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

```

Expand All @@ -118,7 +118,7 @@ cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256
Send the tokens from Chain 901 to Chain 902 using the following command:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

**4. Wait for the relayed message to appear on chain 902**
Expand All @@ -127,14 +127,14 @@ In a few seconds, you should see the RelayedMessage on chain 902:

```sh
# example
INFO [08-30|14:30:14.698] L2ToL2CrossChainMessenger#RelayedMessage sourceChainID=901 destinationChainID=902 nonce=0 sender=0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA target=0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA
INFO [08-30|14:30:14.698] L2ToL2CrossChainMessenger#RelayedMessage sourceChainID=901 destinationChainID=902 nonce=0 sender=0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 target=0x7d1a0053944f2A3c6C99A93395F035281DEB6a08
```
**5. Check the balance on chain 902**

Verify that the balance of the L2NativeSuperchainERC20 on chain 902 has increased:

```sh
cast balance --erc20 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
cast balance --erc20 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
```
For more **detailed instructions** and **usage guides**, refer to the [**📚 Supersim docs**](https://supersim.pages.dev).

Expand Down
2 changes: 1 addition & 1 deletion contracts/lib/optimism
Submodule optimism updated 480 files
63 changes: 56 additions & 7 deletions contracts/script/DeployL2PeripheryContracts.s.sol
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.25;
pragma solidity ^0.8.0;

import {Script, console} from "forge-std/Script.sol";
import {ProxyAdmin} from "@contracts-bedrock/universal/ProxyAdmin.sol";
import {Proxy} from "@contracts-bedrock/universal/Proxy.sol";
import {L2NativeSuperchainERC20} from "../src/L2NativeSuperchainERC20.sol";

contract DeployL2PeripheryContracts is Script {
function setUp() public {}
address _proxyAdminContract;
address _l2NativeSuperchainERC20ProxyContract;
address _l2NativeSuperchainERC20Contract;

function _salt() internal pure returns (bytes32) {
return bytes32(0);
/// @notice Modifier that wraps a function in broadcasting.
modifier broadcast() {
vm.startBroadcast();
_;
vm.stopBroadcast();
}

function setUp() public {}

function runWithStateDump(string memory allocsPath, string memory outputPath) public {
vm.loadAllocs(allocsPath);

Expand All @@ -19,8 +28,48 @@ contract DeployL2PeripheryContracts is Script {
vm.dumpState(outputPath);
}

function run() public {
address l2NativeSuperchainERC20 = address(new L2NativeSuperchainERC20{salt: _salt()}());
console.log("Deployed L2NativeSuperchainERC20 at address: ", l2NativeSuperchainERC20);
function run() public broadcast {
deployProxies();
deployImplementations();
initializeContracts();
}

/// @notice Deploy all of the proxies
function deployProxies() public {
deployProxyAdmin();
deployL2NativeSuperchainERC20Proxy();
}

/// @notice Deploy all of the implementations
function deployImplementations() public {
deployL2NativeSuperchainERC20();
}

function initializeContracts() public {
initializeL2NativeSuperchainERC20();
}

/// @notice Deploy the ProxyAdmin
function deployProxyAdmin() public {
bytes32 salt = keccak256(bytes("ProxyAdmin"));
_proxyAdminContract = address(new ProxyAdmin{salt: salt}(msg.sender));

require(ProxyAdmin(payable(_proxyAdminContract)).owner() == msg.sender);
}

function deployL2NativeSuperchainERC20Proxy() public {
bytes32 salt = keccak256(bytes("L2NativeSuperchainERC20Proxy"));
_l2NativeSuperchainERC20ProxyContract = address(new Proxy{salt: salt}(_proxyAdminContract));
console.log("Deployed L2NativeSuperchainERC20 at address: ", _l2NativeSuperchainERC20ProxyContract);
}

function deployL2NativeSuperchainERC20() public {
bytes32 salt = keccak256(bytes("L2NativeSuperchainERC20"));
_l2NativeSuperchainERC20Contract = address(new L2NativeSuperchainERC20{salt: salt}());
}

function initializeL2NativeSuperchainERC20() public {
ProxyAdmin proxyAdmin = ProxyAdmin(_proxyAdminContract);
proxyAdmin.upgrade({_proxy: payable(_l2NativeSuperchainERC20ProxyContract), _implementation: _l2NativeSuperchainERC20Contract});
}
}
8 changes: 6 additions & 2 deletions contracts/src/L2NativeSuperchainERC20.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
pragma solidity ^0.8.15;

import {ERC20} from "@solady/tokens/ERC20.sol";
import {IL2ToL2CrossDomainMessenger} from "@contracts-bedrock/L2/interfaces/IL2ToL2CrossDomainMessenger.sol";
Expand Down Expand Up @@ -34,10 +34,14 @@ contract L2NativeSuperchainERC20 is ISuperchainERC20Extensions, ERC20, ISemver {
event Burn(address indexed account, uint256 amount);

/// @notice Address of the L2ToL2CrossDomainMessenger Predeploy.
address internal constant MESSENGER = Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER;
address internal immutable MESSENGER;

string public constant version = "0.0.1";

constructor() {
MESSENGER = Predeploys.L2_TO_L2_CROSS_DOMAIN_MESSENGER;
}

/// @notice Allows ANYONE to mint tokens. For production use, this should be restricted.
/// @param _to Address to mint tokens to.
/// @param _amount Amount of tokens to mint.
Expand Down
4 changes: 2 additions & 2 deletions docs/src/chain-environment/contracts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ A simple ERC20 that adheres to the SuperchainERC20 standard. It includes permiss

Source: [L2NativeSuperchainERC20.sol](/contracts/src/L2NativeSuperchainERC20.sol)

Deployed address: `0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA`
Deployed address: `0x7d1a0053944f2A3c6C99A93395F035281DEB6a08`

#### Minting new tokens

```bash
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256 _amount)" $RECIPIENT_ADDRESS 1ether --rpc-url $L2_RPC_URL
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "mint(address _to, uint256 _amount)" $RECIPIENT_ADDRESS 1ether --rpc-url $L2_RPC_URL
```
2 changes: 1 addition & 1 deletion docs/src/chain-environment/network-details/op-chain-a.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"L2ToL2CrossDomainMessenger": "0x4200000000000000000000000000000000000023",

// Periphery
"L2NativeSuperchainERC20": "0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA"
"L2NativeSuperchainERC20": "0x7d1a0053944f2A3c6C99A93395F035281DEB6a08"
}
```
2 changes: 1 addition & 1 deletion docs/src/chain-environment/network-details/op-chain-b.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@
"L2ToL2CrossDomainMessenger": "0x4200000000000000000000000000000000000023",

// Periphery
"L2NativeSuperchainERC20": "0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA"
"L2NativeSuperchainERC20": "0x7d1a0053944f2A3c6C99A93395F035281DEB6a08"
}
```
8 changes: 4 additions & 4 deletions docs/src/getting-started/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ supersim --interop.autorelay
Run the following command to mint 1000 `L2NativeSuperchainERC20` tokens to the recipient address:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

```

Expand All @@ -53,7 +53,7 @@ cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256
Send the tokens from Chain 901 to Chain 902 using the following command:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 4. Wait for the relayed message to appear on chain 902
Expand All @@ -62,15 +62,15 @@ In a few seconds, you should see the RelayedMessage on chain 902:

```sh
# example
INFO [08-30|14:30:14.698] L2ToL2CrossChainMessenger#RelayedMessage sourceChainID=901 destinationChainID=902 nonce=0 sender=0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA target=0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA
INFO [08-30|14:30:14.698] L2ToL2CrossChainMessenger#RelayedMessage sourceChainID=901 destinationChainID=902 nonce=0 sender=0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 target=0x7d1a0053944f2A3c6C99A93395F035281DEB6a08
```

### 5. Check the balance on chain 902

Verify that the balance of the L2NativeSuperchainERC20 on chain 902 has increased:

```sh
cast balance --erc20 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
cast balance --erc20 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
```

With the steps above, you've now successfully completed both an L1 to L2 ETH bridge and an L2 to L2 interoperable SuperchainERC20 token transfer, all done locally using `supersim`. This approach simplifies multichain testing, allowing you to focus on development without the need for complex setups or relying on external testnets.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ We'll perform the SuperchainERC20 interop transfer in [First steps](../../gettin

### Contracts used
- [L2NativeSuperchainERC20](https://github.com/ethereum-optimism/supersim/blob/main/contracts/src/L2NativeSuperchainERC20.sol)
- `0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA`
- `0x7d1a0053944f2A3c6C99A93395F035281DEB6a08`
- [CrossL2Inbox](https://github.com/ethereum-optimism/optimism/blob/92ed64e171c6eb9c6a080c626640e8836f0653cc/packages/contracts-bedrock/src/L2/CrossL2Inbox.sol)
- `0x4200000000000000000000000000000000000022`
- [L2ToL2CrossDomainMessenger](https://github.com/ethereum-optimism/optimism/blob/92ed64e171c6eb9c6a080c626640e8836f0653cc/packages/contracts-bedrock/src/L2/L2ToL2CrossDomainMessenger.sol)
Expand Down Expand Up @@ -77,15 +77,15 @@ supersim
Run the following command to mint 1000 `L2NativeSuperchainERC20` tokens to the recipient address:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "mint(address _to, uint256 _amount)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 3. Initiate the send transaction on chain 901

Send the tokens from Chain 901 to Chain 902 using the following command:

```sh
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
cast send 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 "sendERC20(address _to, uint256 _amount, uint256 _chainId)" 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 1000 902 --rpc-url http://127.0.0.1:9545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 4. Get the log emitted by the `L2ToL2CrossDomainMessenger`
Expand Down Expand Up @@ -215,7 +215,7 @@ cast send 0x4200000000000000000000000000000000000022 \
Verify that the balance of the L2NativeSuperchainERC20 on chain 902 has increased:

```sh
cast balance --erc20 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
cast balance --erc20 0x7d1a0053944f2A3c6C99A93395F035281DEB6a08 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9546
```

## Alternatives
Expand Down
4 changes: 2 additions & 2 deletions docs/src/guides/interop/relay-using-viem.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { anvil } from "viem/chains";

// Define constants - L2NativeSuperchainERC20 contract address is the same on every chain
const L2_NATIVE_SUPERCHAINERC20_ADDRESS =
"0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA";
"0x7d1a0053944f2A3c6C99A93395F035281DEB6a08";

const L2_TO_L2_CROSS_DOMAIN_MESSENGER_ADDRESS =
"0x4200000000000000000000000000000000000023";
Expand Down Expand Up @@ -206,7 +206,7 @@ import { anvil } from "viem/chains";

// Define constants - L2NativeSuperchainERC20 contract address is the same on every chain
const L2_NATIVE_SUPERCHAINERC20_ADDRESS =
"0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA";
"0x7d1a0053944f2A3c6C99A93395F035281DEB6a08";

const L2_TO_L2_CROSS_DOMAIN_MESSENGER_ADDRESS =
"0x4200000000000000000000000000000000000023";
Expand Down
2 changes: 1 addition & 1 deletion genesis/generated/l1-allocs/901-l1-allocs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genesis/generated/l1-allocs/902-l1-allocs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genesis/generated/l1-allocs/903-l1-allocs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genesis/generated/l1-allocs/904-l1-allocs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genesis/generated/l1-allocs/905-l1-allocs.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion genesis/generated/l1-combined-allocs.json

Large diffs are not rendered by default.

20 changes: 10 additions & 10 deletions genesis/generated/l1-genesis.json

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit dfdc930

Please sign in to comment.