commands

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2025 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AVSCommand = &cli.Command{
	Name:  "avs",
	Usage: "Manage EigenLayer AVS (Autonomous Verifiable Services) projects",
	Subcommands: []*cli.Command{
		CreateCommand,
		config.Command,
		context.Command,
		BuildCommand,
		DevnetCommand,
		RunCommand,
		CallCommand,
		ReleaseCommand,
		template.Command,
	},
}
View Source
var BuildCommand = &cli.Command{
	Name:  "build",
	Usage: "Compiles AVS components (smart contracts via Foundry, Go binaries for operators/aggregators)",
	Flags: append([]cli.Flag{

		&cli.StringFlag{
			Name:  "context",
			Usage: "devnet ,testnet or mainnet",
			Value: "devnet",
		},
	}, common.GlobalFlags...),
	Action: func(cCtx *cli.Context) error {
		logger := common.LoggerFromContext(cCtx.Context)

		// Run scriptPath from cwd
		const dir = ""

		// Get the config (based on if we're in a test or not)
		var cfg *common.ConfigWithContextConfig

		if cfgValue := cCtx.Context.Value(testutils.ConfigContextKey); cfgValue != nil {

			cfg = cfgValue.(*common.ConfigWithContextConfig)
		} else {

			context := cCtx.String("context")

			// Load from file if not in context
			var err error
			cfg, err = common.LoadConfigWithContextConfig(context)
			if err != nil {
				return err
			}
		}

		logger.Debug("Project Name: %s", cfg.Config.Project.Name)
		logger.Debug("Building AVS components...")

		scriptsDir := filepath.Join(".devkit", "scripts")

		if _, err := common.CallTemplateScript(cCtx.Context, logger, dir, filepath.Join(scriptsDir, "build"), common.ExpectNonJSONResponse); err != nil {
			return fmt.Errorf("build failed: %w", err)
		}

		logger.Info("Build completed successfully")
		return nil
	},
}

BuildCommand defines the "build" command

View Source
var CallCommand = &cli.Command{
	Name:  "call",
	Usage: "Submits tasks to the local devnet, triggers off-chain execution, and aggregates results",
	Flags: common.GlobalFlags,
	Action: func(cCtx *cli.Context) error {

		logger := common.LoggerFromContext(cCtx.Context)

		logger.Debug("Testing AVS tasks...")

		contextDir := filepath.Join("config", "contexts")
		yamlPath := path.Join(contextDir, "devnet.yaml")
		contextJSON, err := common.LoadRawContext(yamlPath)
		if err != nil {
			return fmt.Errorf("failed to load context %w", err)
		}

		// Run scriptPath from cwd
		const dir = ""

		scriptPath := filepath.Join(".devkit", "scripts", "call")

		parts := cCtx.Args().Slice()
		if len(parts) == 0 {
			return fmt.Errorf("no parameters supplied")
		}

		paramsMap, err := parseParams(strings.Join(parts, " "))
		if err != nil {
			return err
		}
		paramsJSON, err := json.Marshal(paramsMap)
		if err != nil {
			return err
		}

		if _, err := common.CallTemplateScript(cCtx.Context, logger, dir, scriptPath, common.ExpectNonJSONResponse, contextJSON, paramsJSON); err != nil {
			return fmt.Errorf("call failed: %w", err)
		}

		logger.Info("Task execution completed successfully")
		return nil
	},
}

CallCommand defines the "call" command

View Source
var CreateCommand = &cli.Command{
	Name:      "create",
	Usage:     "Initializes a new AVS project scaffold (Hourglass model)",
	ArgsUsage: "<project-name> [target-dir]",
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "dir",
			Usage: "Set output directory for the new project",
			Value: ".",
		},
		&cli.StringFlag{
			Name:  "lang",
			Usage: "Programming language to generate project files",
			Value: "go",
		},
		&cli.StringFlag{
			Name:  "arch",
			Usage: "Specifies AVS architecture (task-based/hourglass, epoch-based, etc.)",
			Value: "task",
		},
		&cli.StringFlag{
			Name:  "template-url",
			Usage: "Direct GitHub base URL to use as template (overrides templates.yml)",
		},
		&cli.StringFlag{
			Name:  "template-version",
			Usage: "Git ref (tag, commit, branch) for the template",
		},
		&cli.StringFlag{
			Name:  "env",
			Usage: "Chooses the environment (local, testnet, mainnet)",
			Value: "local",
		},
		&cli.BoolFlag{
			Name:  "overwrite",
			Usage: "Force overwrite if project directory already exists",
		},
	}, common.GlobalFlags...),
	Action: func(cCtx *cli.Context) error {

		if cCtx.NArg() == 0 {
			return fmt.Errorf("project name is required\nUsage: avs create <project-name> [flags]")
		}
		projectName := cCtx.Args().First()
		dest := cCtx.Args().Get(1)

		logger := common.LoggerFromContext(cCtx.Context)
		tracker := common.ProgressTrackerFromContext(cCtx.Context)

		// use dest from dir flag or positional
		var targetDir string
		if dest != "" {
			targetDir = dest
		} else {
			targetDir = cCtx.String("dir")
		}

		targetDir, err := filepath.Abs(filepath.Join(targetDir, projectName))
		if err != nil {
			return fmt.Errorf("failed to resolve absolute path for target directory: %w", err)
		}

		logger.Debug("Creating new AVS project: %s", projectName)
		logger.Debug("Directory: %s", cCtx.String("dir"))
		logger.Debug("Language: %s", cCtx.String("lang"))
		logger.Debug("Architecture: %s", cCtx.String("arch"))
		logger.Debug("Environment: %s", cCtx.String("env"))
		if cCtx.String("template-path") != "" {
			logger.Debug("Template Path: %s", cCtx.String("template-path"))
		}

		mainBaseURL, mainVersion, err := getTemplateURLs(cCtx)
		if err != nil {
			return err
		}

		if err := createProjectDir(logger, targetDir, cCtx.Bool("overwrite")); err != nil {
			return err
		}

		logger.Debug("Using template: %s", mainBaseURL)
		if mainVersion != "" {
			logger.Info("Template version: %s", mainVersion)
		}

		fetcher := &template.GitFetcher{

			Client: template.NewGitClient(),
			Logger: *progresslogger.NewProgressLogger(
				logger,
				tracker,
			),
			Config: template.GitFetcherConfig{
				Verbose: cCtx.Bool("verbose"),
			},
		}
		if err := fetcher.Fetch(cCtx.Context, mainBaseURL, mainVersion, targetDir); err != nil {
			return fmt.Errorf("failed to fetch template from %s: %w", mainBaseURL, err)
		}

		readMePath := filepath.Join(targetDir, "README.md")
		readMeTemplate, err := os.ReadFile(readMePath)
		if err != nil {
			logger.Warn("Project README.md is missing: %w", err)
		}
		readMeTemplate = append(readMeTemplate, project.RawReadme...)
		err = os.WriteFile(readMePath, readMeTemplate, 0644)
		if err != nil {
			return fmt.Errorf("failed to write README.md: %w", err)
		}

		scriptDir := filepath.Join(".devkit", "scripts")
		scriptPath := filepath.Join(scriptDir, "init")

		logger.Info("Installing template dependencies\n\n")

		if _, err = common.CallTemplateScript(cCtx.Context, logger, targetDir, scriptPath, common.ExpectNonJSONResponse, nil); err != nil {
			return fmt.Errorf("failed to initialize %s: %w", scriptPath, err)
		}

		logger.Debug("\nFinalising new project\n\n")

		err = os.WriteFile(filepath.Join(targetDir, ".env.example"), []byte(config.EnvExample), 0644)
		if err != nil {
			return fmt.Errorf("failed to write .env.example: %w", err)
		}

		appEnv, ok := common.AppEnvironmentFromContext(cCtx.Context)
		if !ok {
			return fmt.Errorf("could not determine application environment")
		}

		if err := common.SaveUserId(appEnv.UserUUID); err != nil {
			return fmt.Errorf("failed to save global settings: %w", err)
		}

		globalTelemetryEnabled, err := common.GetGlobalTelemetryPreference()
		if err != nil {

			logger.Debug("Unable to get global telemetry preference, defaulting to false: %v", err)
		}

		telemetryEnabled := false
		if globalTelemetryEnabled != nil {
			telemetryEnabled = *globalTelemetryEnabled
		}

		if err := copyDefaultConfigToProject(logger, targetDir, projectName, appEnv.ProjectUUID, mainBaseURL, mainVersion, telemetryEnabled); err != nil {
			return fmt.Errorf("failed to initialize %s: %w", common.BaseConfig, err)
		}

		if err := copyDefaultKeystoresToProject(logger, targetDir); err != nil {
			return fmt.Errorf("failed to initialize keystores: %w", err)
		}

		if err := copyZeusFileToProject(logger, targetDir); err != nil {
			return fmt.Errorf("failed to initialize .zeus: %w", err)
		}

		if err := initGitRepo(cCtx, targetDir, logger); err != nil {
			logger.Warn("Failed to initialize Git repository in %s: %v", targetDir, err)
		}

		logger.Info("\nProject %s created successfully in %s. Run 'cd %s' to get started.", projectName, targetDir, targetDir)
		return nil
	},
}

CreateCommand defines the "create" command

View Source
var DevnetCommand = &cli.Command{
	Name:  "devnet",
	Usage: "Manage local AVS development network (Docker-based)",
	Subcommands: []*cli.Command{
		{
			Name:  "start",
			Usage: "Starts Docker containers and deploys local contracts",
			Flags: append([]cli.Flag{
				&cli.BoolFlag{
					Name:  "reset",
					Usage: "Wipe and restart the devnet from scratch",
				},
				&cli.StringFlag{
					Name:  "fork",
					Usage: "Fork from a specific chain (e.g. Base, OP)",
				},
				&cli.BoolFlag{
					Name:  "headless",
					Usage: "Run without showing logs or interactive TUI",
				},
				&cli.IntFlag{
					Name:  "port",
					Usage: "Specify a custom port for local devnet",
					Value: 8545,
				},
				&cli.BoolFlag{
					Name:  "skip-avs-run",
					Usage: "Skip starting offchain AVS components",
					Value: false,
				},
				&cli.BoolFlag{
					Name:  "skip-deploy-contracts",
					Usage: "Skip deploying contracts and only start local devnet",
					Value: false,
				},
				&cli.BoolFlag{
					Name:  "skip-setup",
					Usage: "Skip AVS setup steps (metadata update, registrar setup, etc.) after contract deployment",
					Value: false,
				},
				&cli.BoolFlag{
					Name:  "use-zeus",
					Usage: "Use Zeus CLI to fetch mainnet core addresses",
					Value: false,
				},
			}, common.GlobalFlags...),
			Action: StartDevnetAction,
		},
		{
			Name:   "deploy-contracts",
			Usage:  "Deploy all L1/L2 and AVS contracts to devnet",
			Flags:  []cli.Flag{},
			Action: DeployContractsAction,
		},
		{
			Name:  "stop",
			Usage: "Stops and removes all containers and resources",
			Flags: []cli.Flag{
				&cli.BoolFlag{
					Name:  "all",
					Usage: "Stop all running devnet containers",
				},
				&cli.StringFlag{
					Name:  "project.name",
					Usage: "Stop containers associated with the given project name",
				},
				&cli.IntFlag{
					Name:  "port",
					Usage: "Stop container running on the specified port",
				},
			},
			Action: StopDevnetAction,
		},
		{
			Name:   "list",
			Usage:  "Lists all running devkit devnet containers with their ports",
			Action: ListDevnetContainersAction,
		},
		{
			Name:   "fetch-addresses",
			Usage:  "Fetches current EigenLayer core addresses from mainnet using Zeus CLI",
			Action: FetchZeusAddressesAction,
			Flags: []cli.Flag{
				&cli.StringFlag{
					Name:  "context",
					Usage: "Context to update with Zeus addresses",
					Value: "devnet",
				},
			},
		},
	},
}

DevnetCommand defines the "devnet" command

View Source
var ReleaseCommand = &cli.Command{
	Name:  "release",
	Usage: "Packages and publishes AVS artifacts to a registry or channel",
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "tag",
			Usage: "Tag the release (e.g. v0.1, beta, mainnet)",
			Value: "latest",
		},
		&cli.StringFlag{
			Name:  "registry",
			Usage: "Override default release registry",
		},
		&cli.BoolFlag{
			Name:  "sign",
			Usage: "Sign the release artifacts with a local key",
		},
	}, common.GlobalFlags...),
	Action: func(cCtx *cli.Context) error {

		if cCtx.Bool("verbose") {
			log.Printf("Preparing release...")
			log.Printf("Tag: %s", cCtx.String("tag"))
			if registry := cCtx.String("registry"); registry != "" {
				log.Printf("Registry: %s", registry)
			}
			if cCtx.Bool("sign") {
				log.Printf("Signing release artifacts...")
			}
		}

		log.Printf("Release completed successfully")
		return nil
	},
}

ReleaseCommand defines the "release" command

View Source
var RunCommand = &cli.Command{
	Name:  "run",
	Usage: "Start offchain AVS components",
	Flags: append([]cli.Flag{}, common.GlobalFlags...),
	Action: func(cCtx *cli.Context) error {

		return AVSRun(cCtx)
	},
}

RunCommand defines the "run" command

View Source
var TelemetryCommand = &cli.Command{
	Name:  "telemetry",
	Usage: "Manage telemetry settings",
	Flags: []cli.Flag{
		&cli.BoolFlag{
			Name:  "enable",
			Usage: "Enable telemetry collection",
		},
		&cli.BoolFlag{
			Name:  "disable",
			Usage: "Disable telemetry collection",
		},
		&cli.BoolFlag{
			Name:  "status",
			Usage: "Show current telemetry status",
		},
		&cli.BoolFlag{
			Name:  "global",
			Usage: "Apply setting globally (affects all projects and global default)",
		},
	},
	Action: func(cCtx *cli.Context) error {
		logger := common.LoggerFromContext(cCtx.Context)

		enable := cCtx.Bool("enable")
		disable := cCtx.Bool("disable")
		status := cCtx.Bool("status")
		global := cCtx.Bool("global")

		if (enable && disable) || (!enable && !disable && !status) {
			return fmt.Errorf("specify exactly one of --enable, --disable, or --status")
		}

		if status {
			return showTelemetryStatus(logger, global)
		}

		if enable {
			return enableTelemetry(logger, global)
		}

		if disable {
			return disableTelemetry(logger, global)
		}

		return nil
	},
}

TelemetryCommand allows users to manage telemetry settings

Functions

func AVSRun

func AVSRun(cCtx *cli.Context) error

func CreateAVSOperatorSetsAction

func CreateAVSOperatorSetsAction(cCtx *cli.Context, logger iface.Logger) error

func DeployContractsAction

func DeployContractsAction(cCtx *cli.Context) error

func FetchZeusAddressesAction

func FetchZeusAddressesAction(cCtx *cli.Context) error

func ListDevnetContainersAction

func ListDevnetContainersAction(cCtx *cli.Context) error

func RegisterOperatorsFromConfigAction

func RegisterOperatorsFromConfigAction(cCtx *cli.Context, logger iface.Logger) error

func SetAVSRegistrarAction

func SetAVSRegistrarAction(cCtx *cli.Context, logger iface.Logger) error

func StartDevnetAction

func StartDevnetAction(cCtx *cli.Context) error

func StopDevnetAction

func StopDevnetAction(cCtx *cli.Context) error

func UpdateAVSMetadataAction

func UpdateAVSMetadataAction(cCtx *cli.Context, logger iface.Logger) error

Types

type DeployContractJson

type DeployContractJson struct {
	Name    string      `json:"name"`
	Address string      `json:"address"`
	ABI     interface{} `json:"abi"`
}

type DeployContractTransport

type DeployContractTransport struct {
	Name    string
	Address string
	ABI     string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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