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 df6fc30 commit e50c7c3
Show file tree
Hide file tree
Showing 41 changed files with 162 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 0x420beeF000000000000000000000000000000001 "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 0x420beeF000000000000000000000000000000001 "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=0x420beeF000000000000000000000000000000001 target=0x420beeF000000000000000000000000000000001
```
**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 0x420beeF000000000000000000000000000000001 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
35 changes: 32 additions & 3 deletions contracts/script/DeployL2PeripheryContracts.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import {Script, console} from "forge-std/Script.sol";
import {L2NativeSuperchainERC20} from "../src/L2NativeSuperchainERC20.sol";

contract DeployL2PeripheryContracts is Script {
/// @notice Used for tracking the next address to deploy a periphery contract at.
address internal nextDeploymentAddress = 0x420beeF000000000000000000000000000000001;

/// @notice Modifier that wraps a function in broadcasting.
modifier broadcast() {
vm.startBroadcast();
_;
vm.stopBroadcast();
}

function setUp() public {}

function _salt() internal pure returns (bytes32) {
Expand All @@ -19,8 +29,27 @@ 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 {
deployL2NativeSuperchainERC20();
}

function deployL2NativeSuperchainERC20() public {
address _l2NativeSuperchainERC20Contract = address(new L2NativeSuperchainERC20{salt: _salt()}());
address deploymentAddress = deployAtNextDeploymentAddress(_l2NativeSuperchainERC20Contract.code);
console.log("Deployed L2NativeSuperchainERC20 at address: ", deploymentAddress);
}

function deployAtNextDeploymentAddress(bytes memory newRuntimeBytecode)
internal
returns (address _deploymentAddr)
{
vm.etch(nextDeploymentAddress, newRuntimeBytecode);
_deploymentAddr = nextDeploymentAddress;
nextDeploymentAddress = addOneToAddress(nextDeploymentAddress);
return _deploymentAddr;
}

function addOneToAddress(address addr) internal pure returns (address) {
return address(uint160(addr) + 1);
}
}
25 changes: 16 additions & 9 deletions contracts/src/TicTacToe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
pragma solidity ^0.8.13;

contract TicTacToe {
enum PlayerTurn { PlayerOne, PlayerTwo }
enum PlayerTurn {
PlayerOne,
PlayerTwo
}

enum GameState {
WaitingForPlayer,
Expand Down Expand Up @@ -30,7 +33,7 @@ contract TicTacToe {

uint256 numOfGames;
mapping(uint256 => Game) public games;

// Magic Square: https://mathworld.wolfram.com/MagicSquare.html
uint8[3][3] private MAGIC_SQUARE = [[8, 3, 4], [1, 5, 9], [6, 7, 2]];
uint8 private constant MAGIC_SUM_PLAYER_ONE = 15;
Expand Down Expand Up @@ -58,7 +61,7 @@ contract TicTacToe {
return numOfGames;
}

function joinGame(address player2, uint256 gameId) public validGame(gameId) returns (bool) {
function joinGame(address player2, uint256 gameId) public validGame(gameId) returns (bool) {
Game storage game = games[gameId];

require(game.state == GameState.WaitingForPlayer, "Game already has enough players");
Expand All @@ -74,7 +77,7 @@ contract TicTacToe {
function makeMove(address player, uint256 gameId, uint8 x, uint8 y) public validGame(gameId) returns (bool) {
Game storage game = games[gameId];
require(game.state == GameState.Playing, "Game hasn't started or has already been completed");

bool isPlayerOneTurn = game.currentTurn == PlayerTurn.PlayerOne;
require(isPlayerOneTurn ? player == game.player1 : player == game.player2, "Not a valid player in the game");
require(x >= 0 && x <= 2 || y >= 0 && y <= 2, "Move out of bounds");
Expand All @@ -101,25 +104,29 @@ contract TicTacToe {
return games[gameId];
}

function checkForWin(address player, uint256 gameId) public validGame(gameId) view returns (bool) {
function checkForWin(address player, uint256 gameId) public view validGame(gameId) returns (bool) {
Game storage game = games[gameId];
require(player == game.player1 || player == game.player2, "Not a valid player in the game");

uint8 magicSum = player == game.player1 ? MAGIC_SUM_PLAYER_ONE : MAGIC_SUM_PLAYER_TWO;

// row & col check
for (uint8 i = 0; i < 3; i++) {
uint8 rowSum = (game.board[i][0] * MAGIC_SQUARE[i][0]) + (game.board[i][1] * MAGIC_SQUARE[i][1]) + (game.board[i][2] * MAGIC_SQUARE[i][2]);
uint8 colSum = (game.board[0][i] * MAGIC_SQUARE[0][i]) + (game.board[1][i] * MAGIC_SQUARE[1][i]) + (game.board[2][i] * MAGIC_SQUARE[2][i]);
uint8 rowSum = (game.board[i][0] * MAGIC_SQUARE[i][0]) + (game.board[i][1] * MAGIC_SQUARE[i][1])
+ (game.board[i][2] * MAGIC_SQUARE[i][2]);
uint8 colSum = (game.board[0][i] * MAGIC_SQUARE[0][i]) + (game.board[1][i] * MAGIC_SQUARE[1][i])
+ (game.board[2][i] * MAGIC_SQUARE[2][i]);

if (rowSum == magicSum || colSum == magicSum) {
return true;
}
}

// diag check
uint8 leftToRightSum = (game.board[0][0] * MAGIC_SQUARE[0][0]) + (game.board[1][1] * MAGIC_SQUARE[1][1]) + (game.board[2][2] * MAGIC_SQUARE[2][2]);
uint8 rightToLeftSum = (game.board[0][2] * MAGIC_SQUARE[0][2]) + (game.board[1][1] * MAGIC_SQUARE[1][1]) + (game.board[2][0] * MAGIC_SQUARE[2][0]);
uint8 leftToRightSum = (game.board[0][0] * MAGIC_SQUARE[0][0]) + (game.board[1][1] * MAGIC_SQUARE[1][1])
+ (game.board[2][2] * MAGIC_SQUARE[2][2]);
uint8 rightToLeftSum = (game.board[0][2] * MAGIC_SQUARE[0][2]) + (game.board[1][1] * MAGIC_SQUARE[1][1])
+ (game.board[2][0] * MAGIC_SQUARE[2][0]);
if (leftToRightSum == magicSum || rightToLeftSum == magicSum) {
return true;
}
Expand Down
12 changes: 6 additions & 6 deletions contracts/test/TicTacToe.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ contract TicTacToeTest is Test {
TicTacToe.Game memory game = ticTacToe.getGame(gameId);
assertEq(gameId, game.id);
assertEq(game.player1, player1);
assertEq(uint(game.state), uint(TicTacToe.GameState.WaitingForPlayer));
assertEq(uint256(game.state), uint256(TicTacToe.GameState.WaitingForPlayer));
}

function test_JoinGameSuccessful() public {
Expand Down Expand Up @@ -56,7 +56,7 @@ contract TicTacToeTest is Test {
ticTacToe.makeMove(player2, gameId, 1, 1);
ticTacToe.makeMove(player1, gameId, 0, 2);
TicTacToe.Game memory game = ticTacToe.getGame(gameId);
assertEq(uint(game.state), uint(TicTacToe.GameState.PlayerOneWins));
assertEq(uint256(game.state), uint256(TicTacToe.GameState.PlayerOneWins));

// Game 2: col win by player 2
gameId = ticTacToe.createGame(player1);
Expand All @@ -68,8 +68,8 @@ contract TicTacToeTest is Test {
ticTacToe.makeMove(player1, gameId, 1, 0);
ticTacToe.makeMove(player2, gameId, 2, 1);
game = ticTacToe.getGame(gameId);
assertEq(uint(game.state), uint(TicTacToe.GameState.PlayerTwoWins));
assertEq(uint256(game.state), uint256(TicTacToe.GameState.PlayerTwoWins));

// Game 3: dial win by player 1
gameId = ticTacToe.createGame(player1);
ticTacToe.joinGame(player2, gameId);
Expand All @@ -79,7 +79,7 @@ contract TicTacToeTest is Test {
ticTacToe.makeMove(player2, gameId, 1, 2);
ticTacToe.makeMove(player1, gameId, 2, 2);
game = ticTacToe.getGame(gameId);
assertEq(uint(game.state), uint(TicTacToe.GameState.PlayerOneWins));
assertEq(uint256(game.state), uint256(TicTacToe.GameState.PlayerOneWins));
}

function test_PlayGameUntilDraw() public {
Expand All @@ -96,6 +96,6 @@ contract TicTacToeTest is Test {
ticTacToe.makeMove(player2, gameId, 2, 1);
ticTacToe.makeMove(player1, gameId, 2, 2);
TicTacToe.Game memory game = ticTacToe.getGame(gameId);
assertEq(uint(game.state), uint(TicTacToe.GameState.Draw));
assertEq(uint256(game.state), uint256(TicTacToe.GameState.Draw));
}
}
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: `0x420beeF000000000000000000000000000000001`

#### Minting new tokens

```bash
cast send 0x0bEa8920a4FfB1888Ec3Ac1BC0D23f414B0a28cA "mint(address _to, uint256 _amount)" $RECIPIENT_ADDRESS 1ether --rpc-url $L2_RPC_URL
cast send 0x420beeF000000000000000000000000000000001 "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": "0x420beeF000000000000000000000000000000001"
}
```
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": "0x420beeF000000000000000000000000000000001"
}
```
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 0x420beeF000000000000000000000000000000001 "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 0x420beeF000000000000000000000000000000001 "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=0x420beeF000000000000000000000000000000001 target=0x420beeF000000000000000000000000000000001
```

### 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 0x420beeF000000000000000000000000000000001 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`
- `0x420beeF000000000000000000000000000000001`
- [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 0x420beeF000000000000000000000000000000001 "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 0x420beeF000000000000000000000000000000001 "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 0x420beeF000000000000000000000000000000001 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";
"0x420beeF000000000000000000000000000000001";

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";
"0x420beeF000000000000000000000000000000001";

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 e50c7c3

Please sign in to comment.