commands

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 57 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,
		TransportCommand,
		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")

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

		contextPath := filepath.Join("config", "contexts", fmt.Sprintf("%s.yaml", cCtx.String("context")))
		contextNode, err := common.LoadYAML(contextPath)
		if err != nil {
			return fmt.Errorf("failed to load context yaml: %w", err)
		}

		rootNode := contextNode.Content[0]

		contextSection := common.GetChildByKey(rootNode, "context")
		if contextSection == nil {
			contextSection = &yaml.Node{Kind: yaml.MappingNode}
			rootNode.Content = append(rootNode.Content,
				&yaml.Node{Kind: yaml.ScalarNode, Value: "context"},
				contextSection,
			)
		}

		outputNode, err := common.InterfaceToNode(output)
		if err != nil {
			return fmt.Errorf("failed to convert build output to yaml node: %w", err)
		}

		mergedNode := common.DeepMerge(contextSection, outputNode)
		contextSection.Content = mergedNode.Content

		if err := common.WriteYAML(contextPath, contextNode); err != nil {
			return fmt.Errorf("failed to write merged yaml: %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...")

		contextJSON, err := common.LoadRawContext("devnet")
		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-transporter",
					Usage: "Skip starting/submitting Stake Root via transporter",
					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 holesky 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 holesky 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

View Source
var TransportCommand = &cli.Command{
	Name:  "transport",
	Usage: "Transport Stake Root to L1",
	Subcommands: []*cli.Command{
		{
			Name:   "run",
			Usage:  "Immediately transport stake root to L1",
			Flags:  append([]cli.Flag{}, common.GlobalFlags...),
			Action: Transport,
		},
		{
			Name:   "verify",
			Usage:  "Verify that the context active_stake_roots match onchain state",
			Flags:  append([]cli.Flag{}, common.GlobalFlags...),
			Action: VerifyActiveStakeTableRoots,
		},
		{
			Name:  "schedule",
			Usage: "Schedule transport stake root to L1",
			Flags: append([]cli.Flag{
				&cli.StringFlag{
					Name:  "cron-expr",
					Usage: "Specify a custom schedule to override config schedule",
					Value: "",
				},
			}, common.GlobalFlags...),
			Action: func(cCtx *cli.Context) error {

				cfg, err := common.LoadConfigWithContextConfig(devnet.DEVNET_CONTEXT)
				if err != nil {
					return fmt.Errorf("failed to load configurations for whitelist chain id in cross registry: %w", err)
				}
				envCtx, ok := cfg.Context[devnet.DEVNET_CONTEXT]
				if !ok {
					return fmt.Errorf("context '%s' not found in configuration", devnet.DEVNET_CONTEXT)
				}

				schedule := cCtx.String("cron-expr")
				if schedule == "" {
					schedule = envCtx.Transporter.Schedule
				}

				err = ScheduleTransport(cCtx, schedule)
				if err != nil {
					return fmt.Errorf("ScheduleTransport failed: %v", err)
				}

				select {}
			},
		},
	},
}
View Source
var UpgradeCommand = &cli.Command{
	Name:  "upgrade",
	Usage: "Upgrade devkit and template",
	Flags: append([]cli.Flag{
		&cli.StringFlag{
			Name:  "version",
			Usage: "Version to upgrade to (e.g. v0.0.8)",
			Value: "latest",
		},
	}, common.GlobalFlags...),
	Action: func(cCtx *cli.Context) error {
		return UpgradeDevkit(cCtx)
	},
}

UpgradeCommand defines the CLI command to upgrade the devkit binary and templates

Functions

func AVSRun

func AVSRun(cCtx *cli.Context) error

func ConfigureOpSetCurveTypeAction added in v0.0.9

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

ConfigureOpSetCurveType

func CreateAVSOperatorSetsAction

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

func CreateGenerationReservationAction added in v0.0.9

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

func DelegateToOperatorsAction added in v0.0.9

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

func DeployContractsAction

func DeployContractsAction(cCtx *cli.Context) error

func DepositIntoStrategiesAction added in v0.0.9

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

func FetchZeusAddressesAction

func FetchZeusAddressesAction(cCtx *cli.Context) error

func GetLatestVersionFromGitHub added in v0.0.9

func GetLatestVersionFromGitHub(version string) (string, string, error)

GetLatestVersionFromGitHub queries the GitHub releases API and returns the latest tag and commit

func GetOnchainStakeTableRoots added in v0.0.9

func GetOnchainStakeTableRoots(cCtx *cli.Context) (map[uint64][32]byte, error)

Get all stake table roots from appropriate OperatorTableUpdaters

func ListDevnetContainersAction

func ListDevnetContainersAction(cCtx *cli.Context) error

func ModifyAllocationsAction added in v0.0.9

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

func PerformUpgrade added in v0.0.9

func PerformUpgrade(version, binDir string, logger iface.Logger) error

PerformUpgrade downloads and installs the target version of the devkit binary. It supports both .tar.gz and raw .tar archive formats.

func RegisterKeyInKeyRegistrarAction added in v0.0.9

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

func RegisterOperatorsToAvsFromConfigAction added in v0.0.9

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

func RegisterOperatorsToEigenLayerFromConfigAction added in v0.0.9

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

func ScheduleTransport added in v0.0.9

func ScheduleTransport(cCtx *cli.Context, cronExpr string) error

Schedule transport using the default parser and transportFunc

func ScheduleTransportWithParserAndFunc added in v0.0.9

func ScheduleTransportWithParserAndFunc(cCtx *cli.Context, cronExpr string, parser cron.Parser, transportFunc func()) error

Schedule transport using custom parser and transportFunc

func SetAVSRegistrarAction

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

func SetAllocationDelayAction added in v0.0.9

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

func StartDevnetAction

func StartDevnetAction(cCtx *cli.Context) error

func StopDevnetAction

func StopDevnetAction(cCtx *cli.Context) error

func Transport added in v0.0.9

func Transport(cCtx *cli.Context) error

func UpdateAVSMetadataAction

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

func UpgradeDevkit added in v0.0.9

func UpgradeDevkit(cCtx *cli.Context) error

UpgradeDevkit resolves the latest version if needed and invokes PerformUpgrade to install the new version

func VerifyActiveStakeTableRoots added in v0.0.9

func VerifyActiveStakeTableRoots(cCtx *cli.Context) error

Verify the context stored ActiveStakeRoots match onchain state

func WhitelistChainIdInCrossRegistryAction added in v0.0.9

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

func WriteStakeTableRootsToContext added in v0.0.9

func WriteStakeTableRootsToContext(roots map[uint64][32]byte) error

Record StakeTableRoots in the context for later retrieval

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
}

type LatestRelease added in v0.0.9

type LatestRelease struct {
	TagName      string `json:"tag_name"`
	TargetCommit string `json:"target_commitish"`
}

LatestRelease defines the subset of GitHub release fields we care about

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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