interop

package
v1.10.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2024 License: MIT, MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DevKeyAddressCmd = &cli.Command{
	Name:  "address",
	Usage: "Retrieve devkey address, by specifying domain, chain ID, name.",
	Flags: cliapp.ProtectFlags([]cli.Flag{
		mnemonicFlag,
		devkeyDomainFlag,
		devkeyChainIdFlag,
		devkeyNameFlag,
	}),
	Action: func(context *cli.Context) error {
		mnemonic := context.String(mnemonicFlag.Name)
		domain := context.String(devkeyDomainFlag.Name)
		chainID := context.Uint64(devkeyChainIdFlag.Name)
		chainIDBig := new(big.Int).SetUint64(chainID)
		name := context.String(devkeyNameFlag.Name)
		k, err := parseKey(domain, chainIDBig, name)
		if err != nil {
			return err
		}
		mnemonicKeys, err := devkeys.NewMnemonicDevKeys(mnemonic)
		if err != nil {
			return err
		}
		addr, err := mnemonicKeys.Address(k)
		if err != nil {
			return err
		}
		_, err = fmt.Fprintf(context.App.Writer, "%s", addr)
		if err != nil {
			return fmt.Errorf("failed to output address: %w", err)
		}
		return nil
	},
}
View Source
var DevKeyCmd = &cli.Command{
	Name:  "devkey",
	Usage: "Retrieve devkey secret or address",
	Subcommands: cli.Commands{
		DevKeySecretCmd,
		DevKeyAddressCmd,
	},
}
View Source
var DevKeySecretCmd = &cli.Command{
	Name:  "secret",
	Usage: "Retrieve devkey secret, by specifying domain, chain ID, name.",
	Flags: cliapp.ProtectFlags([]cli.Flag{
		mnemonicFlag,
		devkeyDomainFlag,
		devkeyChainIdFlag,
		devkeyNameFlag,
	}),
	Action: func(context *cli.Context) error {
		mnemonic := context.String(mnemonicFlag.Name)
		domain := context.String(devkeyDomainFlag.Name)
		chainID := context.Uint64(devkeyChainIdFlag.Name)
		chainIDBig := new(big.Int).SetUint64(chainID)
		name := context.String(devkeyNameFlag.Name)
		k, err := parseKey(domain, chainIDBig, name)
		if err != nil {
			return err
		}
		mnemonicKeys, err := devkeys.NewMnemonicDevKeys(mnemonic)
		if err != nil {
			return err
		}
		secret, err := mnemonicKeys.Secret(k)
		if err != nil {
			return err
		}
		secretBin := crypto.FromECDSA(secret)
		_, err = fmt.Fprintf(context.App.Writer, "%x", secretBin)
		if err != nil {
			return fmt.Errorf("failed to output secret key: %w", err)
		}
		return nil
	},
}
View Source
var EnvPrefix = "OP_INTEROP"
View Source
var InteropCmd = &cli.Command{
	Name:  "interop",
	Usage: "Experimental tools for OP-Stack interop networks.",
	Subcommands: cli.Commands{
		InteropDevSetup,
		DevKeyCmd,
	},
}
View Source
var InteropDevSetup = &cli.Command{
	Name:  "dev-setup",
	Usage: "Generate devnet genesis configs with one L1 and multiple L2s",
	Flags: cliapp.ProtectFlags(append([]cli.Flag{
		l1ChainIDFlag,
		l2ChainIDsFlag,
		timestampFlag,
		mnemonicFlag,
		artifactsDirFlag,
		foundryDirFlag,
		outDirFlag,
	}, oplog.CLIFlags(EnvPrefix)...)),
	Action: func(cliCtx *cli.Context) error {
		logCfg := oplog.ReadCLIConfig(cliCtx)
		logger := oplog.NewLogger(cliCtx.App.Writer, logCfg)

		recipe := &interopgen.InteropDevRecipe{
			L1ChainID:        cliCtx.Uint64(l1ChainIDFlag.Name),
			L2ChainIDs:       cliCtx.Uint64Slice(l2ChainIDsFlag.Name),
			GenesisTimestamp: cliCtx.Uint64(timestampFlag.Name),
		}
		if recipe.GenesisTimestamp == 0 {
			recipe.GenesisTimestamp = uint64(time.Now().Unix() + 5)
		}
		mnemonic := strings.TrimSpace(cliCtx.String(mnemonicFlag.Name))
		if mnemonic == devkeys.TestMnemonic {
			logger.Warn("Using default test mnemonic!")
		}
		keys, err := devkeys.NewMnemonicDevKeys(mnemonic)
		if err != nil {
			return fmt.Errorf("failed to setup dev keys from mnemonic: %w", err)
		}
		worldCfg, err := recipe.Build(keys)
		if err != nil {
			return fmt.Errorf("failed to build deploy configs from interop recipe: %w", err)
		}
		if err := worldCfg.Check(logger); err != nil {
			return fmt.Errorf("invalid deploy configs: %w", err)
		}
		artifactsDir := cliCtx.String(artifactsDirFlag.Name)
		af := foundry.OpenArtifactsDir(artifactsDir)
		var srcFs *foundry.SourceMapFS
		if cliCtx.IsSet(foundryDirFlag.Name) {
			srcDir := cliCtx.String(foundryDirFlag.Name)
			srcFs = foundry.NewSourceMapFS(os.DirFS(srcDir))
		}
		worldDeployment, worldOutput, err := interopgen.Deploy(logger, af, srcFs, worldCfg)
		if err != nil {
			return fmt.Errorf("failed to deploy interop dev setup: %w", err)
		}
		outDir := cliCtx.String(outDirFlag.Name)

		{
			deploymentsDir := filepath.Join(outDir, "deployments")
			l1Dir := filepath.Join(deploymentsDir, "l1")
			if err := writeJson(filepath.Join(l1Dir, "common.json"), worldDeployment.L1); err != nil {
				return fmt.Errorf("failed to write L1 deployment data: %w", err)
			}
			if err := writeJson(filepath.Join(l1Dir, "superchain.json"), worldDeployment.Superchain); err != nil {
				return fmt.Errorf("failed to write Superchain deployment data: %w", err)
			}
			l2sDir := filepath.Join(deploymentsDir, "l2")
			for id, dep := range worldDeployment.L2s {
				l2Dir := filepath.Join(l2sDir, id)
				if err := writeJson(filepath.Join(l2Dir, "addresses.json"), dep); err != nil {
					return fmt.Errorf("failed to write L2 %s deployment data: %w", id, err)
				}
			}
		}

		{
			genesisDir := filepath.Join(outDir, "genesis")
			l1Dir := filepath.Join(genesisDir, "l1")
			if err := writeJson(filepath.Join(l1Dir, "genesis.json"), worldOutput.L1.Genesis); err != nil {
				return fmt.Errorf("failed to write L1 genesis data: %w", err)
			}
			l2sDir := filepath.Join(genesisDir, "l2")
			for id, dep := range worldOutput.L2s {
				l2Dir := filepath.Join(l2sDir, id)
				if err := writeJson(filepath.Join(l2Dir, "genesis.json"), dep.Genesis); err != nil {
					return fmt.Errorf("failed to write L2 %s genesis config: %w", id, err)
				}
				if err := writeJson(filepath.Join(l2Dir, "rollup.json"), dep.RollupCfg); err != nil {
					return fmt.Errorf("failed to write L2 %s rollup config: %w", id, err)
				}
			}
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL