Skip to content

Commit

Permalink
feat(genesis): use OPCM for deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
jakim929 committed Sep 27, 2024
1 parent bd741f1 commit 8a748d8
Show file tree
Hide file tree
Showing 57 changed files with 2,425 additions and 4,049 deletions.
15 changes: 2 additions & 13 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,5 @@ start:
clean-lib:
rm -rf lib

checkout-optimism-monorepo:
rm -rf lib/optimism
mkdir -p lib/optimism && \
cd lib/optimism && \
git init && \
git remote add origin https://github.com/ethereum-optimism/optimism.git && \
git fetch --depth=1 origin 3210a8c6bb7f98639213fb49718919d84aa8774a && \
git reset --hard FETCH_HEAD && \
git submodule update --init --recursive && \
make cannon-prestate

generate-genesis: checkout-optimism-monorepo
python3 scripts/generate-genesis.py
generate-genesis: build-contracts
go run ./genesis/cmd/main.go --monorepo-artifacts $(cat monorepo-artifacts-url) --periphery-artifacts ./contracts/out --outdir ./genesis/generated
2 changes: 1 addition & 1 deletion contracts/lib/optimism
Submodule optimism updated 594 files
14 changes: 10 additions & 4 deletions docs/src/getting-started/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ To see it in practice, let's first try sending some ETH from the L1 to the L2.

## Deposit ETH from the L1 into the L2 (L1 to L2 message passing)

### 1. Call `bridgeETH` function on the `L1StandardBridgeProxy` contract on the L1 (chain 900)
**1. Check initial balance on the L2 (chain 901)**

Grab the balance of the sender account on L2:

```sh
cast balance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9545
```

**2. Call `bridgeETH` function on the `L1StandardBridgeProxy` contract on the L1 (chain 900)**

Initiate a bridge transaction on the L1:

```sh
cast send 0xa01ae68902e205B420FD164435F299E07b0C778b "bridgeETH(uint32 _minGasLimit, bytes calldata _extraData)" 50000 0x --value 0.1ether --rpc-url http://127.0.0.1:8545 --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
```

### 2. Check the balance on the L2 (chain 901)
**3. Check the balance on the L2 (chain 901)**

Verify that the ETH balance of the sender has increased on the L2:

```sh
cast balance 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --rpc-url http://127.0.0.1:9545
```

Now that you know how to pass messages from the L1 to the L2, let's try a sending an L2 to L2 message!

## Send an interoperable SuperchainERC20 token from chain 901 to 902 (L2 to L2 message passing)

In a typical L2 to L2 cross-chain transfer, two transactions are required:
Expand Down
103 changes: 103 additions & 0 deletions genesis/cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package main

import (
"fmt"
"os"
"path"

"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/pipeline"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer/state"
"github.com/ethereum-optimism/optimism/op-chain-ops/foundry"
"github.com/ethereum-optimism/optimism/op-service/ioutil"
"github.com/ethereum-optimism/optimism/op-service/jsonutil"
oplog "github.com/ethereum-optimism/optimism/op-service/log"
"github.com/ethereum-optimism/supersim/genesis/worldgen"
"github.com/urfave/cli/v2"
)

func main() {
oplog.SetupDefaults()

app := cli.NewApp()
app.Name = "supersim-worldgen"
app.Usage = "Supersim Genesis Generator"
app.Description = "Generate genesis files for supersim"
app.Action = worldgenMain
app.Flags = worldgen.CLIFlags()

if err := app.Run(os.Args); err != nil {
fmt.Println(err)
}
}

func worldgenMain(ctx *cli.Context) error {
logger := oplog.NewLogger(oplog.AppOut(nil), oplog.DefaultCLIConfig())

cliConfig, err := worldgen.ParseCLIConfig(ctx)
if err != nil {
return fmt.Errorf("failed to parse cli config: %w", err)
}

// Download monorepo contract artifacts
monorepoProgressor := func(curr, total int64) {
logger.Info("monorepo artifacts download progress", "current", curr, "total", total)
}

monorepoArtifactsFS, monorepoArtifactsCleanup, err := pipeline.DownloadArtifacts(ctx.Context, (*state.ArtifactsURL)(cliConfig.MonorepoArtifactsURL), monorepoProgressor)
if err != nil {
return fmt.Errorf("failed to download monorepo artifacts: %w", err)
}
defer func() {
if err := monorepoArtifactsCleanup(); err != nil {
logger.Warn("failed to clean up monorepo artifacts", "err", err)
}
}()

// Download periphery contract artifacts
peripheryProgressor := func(curr, total int64) {
logger.Info("monorepo artifacts download progress", "current", curr, "total", total)
}

peripheryArtifactsFS, peripheryArtifactsCleanup, err := pipeline.DownloadArtifacts(ctx.Context, (*state.ArtifactsURL)(cliConfig.PeripheryArtifactsURL), peripheryProgressor)
if err != nil {
return fmt.Errorf("failed to download periphery artifacts: %w", err)
}
defer func() {
if err := peripheryArtifactsCleanup(); err != nil {
logger.Warn("failed to clean up periphery artifacts", "err", err)
}
}()

worldDeployment, worldOutput, err := worldgen.GenerateWorld(ctx.Context, logger, &foundry.ArtifactsFS{FS: monorepoArtifactsFS}, &foundry.ArtifactsFS{FS: peripheryArtifactsFS})

if err != nil {
return fmt.Errorf("failed to generate world: %w", err)
}

logger.Info("Successfully generated world")

logger.Info("writing L1 genesis")
outfile := fmt.Sprintf("%s-l1-genesis.json", worldOutput.L1.Genesis.Config.ChainID)
if err := jsonutil.WriteJSON(worldOutput.L1.Genesis, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write L1 genesis: %w", err)
}

for l2ChainID, l2Deployment := range worldDeployment.L2s {
logger.Info("writing addresses for l2", "chain_id", l2ChainID)
outfile := fmt.Sprintf("%s-l2-addresses.json", l2ChainID)
if err := jsonutil.WriteJSON(l2Deployment, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write addresses: %w", err)
}
}

for l2ChainID, l2Output := range worldOutput.L2s {
logger.Info("writing genesis for l2", "chain_id", l2ChainID)
outfile := fmt.Sprintf("%s-l2-genesis.json", l2ChainID)
l2Genesis := l2Output.Genesis
if err := jsonutil.WriteJSON(l2Genesis, ioutil.ToStdOutOrFileOrNoop(path.Join(cliConfig.Outdir, outfile), 0o666)); err != nil {
return fmt.Errorf("failed to write genesis: %w", err)
}
}

return nil
}
22 changes: 11 additions & 11 deletions genesis/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,43 +23,43 @@ type Alloc struct {
/*******************
L1 Genesis files
*******************/
//go:embed generated/l1-genesis.json
//go:embed generated/900-l1-genesis.json
var l1GenesisJSON []byte

/*******************
L2 Genesis files
*******************/
//go:embed generated/l2-genesis/901-l2-genesis.json
//go:embed generated/901-l2-genesis.json
var l2Genesis901JSON []byte

//go:embed generated/l2-genesis/902-l2-genesis.json
//go:embed generated/902-l2-genesis.json
var l2Genesis902JSON []byte

//go:embed generated/l2-genesis/903-l2-genesis.json
//go:embed generated/903-l2-genesis.json
var l2Genesis903JSON []byte

//go:embed generated/l2-genesis/904-l2-genesis.json
//go:embed generated/904-l2-genesis.json
var l2Genesis904JSON []byte

//go:embed generated/l2-genesis/905-l2-genesis.json
//go:embed generated/905-l2-genesis.json
var l2Genesis905JSON []byte

/*******************
L2 Addresses files
*******************/
//go:embed generated/addresses/901-addresses.json
//go:embed generated/901-l2-addresses.json
var addresses901JSON []byte

//go:embed generated/addresses/902-addresses.json
//go:embed generated/902-l2-addresses.json
var addresses902JSON []byte

//go:embed generated/addresses/903-addresses.json
//go:embed generated/903-l2-addresses.json
var addresses903JSON []byte

//go:embed generated/addresses/904-addresses.json
//go:embed generated/904-l2-addresses.json
var addresses904JSON []byte

//go:embed generated/addresses/905-addresses.json
//go:embed generated/905-l2-addresses.json
var addresses905JSON []byte

var GeneratedGenesisDeployment = &GenesisDeployment{
Expand Down
1,414 changes: 1,414 additions & 0 deletions genesis/generated/900-l1-genesis.json

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions genesis/generated/901-l2-addresses.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"OpChainProxyAdmin": "0xa997d7ebd1700558b8e18a9096fc16f4098dc634",
"AddressManager": "0xc3c632e95ae78bb07449a4977ae9025a9258228e",
"L1ERC721BridgeProxy": "0x68a7cdc5bbc0146a57cdd18e42c7d17fc3d2c715",
"SystemConfigProxy": "0x8e46f8035e7251683cfe4570740b1c8b2f173174",
"OptimismMintableERC20FactoryProxy": "0xc56f57ecaa24899d8fd70908f07a2fa70cfb3bcf",
"L1StandardBridgeProxy": "0x82233841d0de03e0d7cee1bf06b17f9071578417",
"L1CrossDomainMessengerProxy": "0x721214724ad72ff4bb3603a95e041f4ef733365c",
"OptimismPortalProxy": "0xc92f7768dd850a850f4512d02840989ab7520920",
"DisputeGameFactoryProxy": "0xf7046e2dbbc017d76afaa7c03f87aed547c566c7",
"AnchorStateRegistryProxy": "0xc8a07aefdc8efc1545d409ad5517a34fdfb07e57",
"AnchorStateRegistryImpl": "0xc77e3e906a1588930d101756b932336384176448",
"FaultDisputeGame": "0x0000000000000000000000000000000000000000",
"PermissionedDisputeGame": "0xf16a44284cbb6032534ef84d94c5ede61fbdf75c",
"DelayedWETHPermissionedGameProxy": "0xbd2dfa523a1a0d3a72637a62322b031ca7552d13",
"DelayedWETHPermissionlessGameProxy": "0x1f356a056d5317d49e30cad77d3f57e1be62c09d"
}

Loading

0 comments on commit 8a748d8

Please sign in to comment.