common

package
v0.2.8 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AppRegistryVersion = "1.0.0"
	AppRegistryFile    = "apps.yaml"
)
View Source
const (
	// Chain IDs
	MainnetChainID uint64 = 1
	SepoliaChainID uint64 = 11155111

	// Fallback environment used if no user-defined default is found
	FallbackEnvironment = "sepolia"
)
View Source
const (
	BuildSuffix        = "-dev"
	KeyringServiceName = "eigenx-cli-dev"
	Build              = "dev"
)

Build-specific constants for dev environment

View Source
const (
	// L1 is the name of the L1 chain
	L1 = "l1"

	// ContractsDir is the subdirectory name for contract components
	ContractsDir = "contracts"

	// Makefile is the name of the makefile used for root level operations
	Makefile = "Makefile"

	// ContractsMakefile is the name of the makefile used for contract level operations
	ContractsMakefile = "Makefile"

	// GlobalConfigFile is the name of the global YAML used to store global config details (eg, user_id)
	GlobalConfigFile = "config.yaml"

	// Docker open timeout
	DockerOpenTimeoutSeconds = 10

	// Docker open retry interval in milliseconds
	DockerOpenRetryIntervalMilliseconds = 500

	// WatchPollIntervalSeconds is the interval between watch loop polls in seconds
	WatchPollIntervalSeconds = 5

	// Environment variable names
	MnemonicEnvVar         = "MNEMONIC"                  // Filtered out, overridden by protocol
	EigenMachineTypeEnvVar = "EIGEN_MACHINE_TYPE_PUBLIC" // Instance type configuration
)

Project structure constants

View Source
const (
	AppStatusCreated     = "Created"
	AppStatusDeploying   = "Deploying"
	AppStatusUpgrading   = "Upgrading"
	AppStatusResuming    = "Resuming"
	AppStatusRunning     = "Running"
	AppStatusStopping    = "Stopping"
	AppStatusStopped     = "Stopped"
	AppStatusTerminating = "Terminating"
	AppStatusTerminated  = "Terminated"
	AppStatusFailed      = "Failed"
	AppStatusExited      = "Exited"
)

App status strings from API

View Source
const (
	KeyPrefix = "eigenx-"
)
View Source
const (
	// VersionCheckInterval is how often to check for updates (24 hours)
	VersionCheckInterval = 24 * time.Hour
)

Variables

View Source
var (
	// Common addresses across all chains
	CommonAddresses = CommonAddr{
		ERC7702Delegator: common.HexToAddress("0x63c0c19a282a1b52b07dd5a65b58948a07dae32b"),
	}

	// Addresses specific to each chain
	ChainAddresses = map[uint64]ChainAddr{
		MainnetChainID: {
			PermissionController: common.HexToAddress("0x25E5F8B1E7aDf44518d35D5B2271f114e081f0E5"),
		},
		SepoliaChainID: {
			PermissionController: common.HexToAddress("0x44632dfBdCb6D3E21EF613B0ca8A6A0c618F5a37"),
		},
	}

	// Default environment for each chain ID
	DefaultEnvironmentForChainID = map[uint64]string{
		MainnetChainID: "mainnet-alpha",
		SepoliaChainID: "sepolia",
	}
)
View Source
var (
	// The permission to view app logs
	// bytes4(keccak256("CAN_VIEW_APP_LOGS()"))
	CanViewAppLogsPermission = [4]byte{0x2f, 0xd3, 0xf2, 0xfe}

	// The permission to view sensitive app info (including real IPs)
	// bytes4(keccak256("CAN_VIEW_SENSITIVE_APP_INFO()"))
	CanViewSensitiveAppInfoPermission = [4]byte{0x0e, 0x67, 0xb2, 0x2f}

	// The address that is used to allow auth to be bypassed for certain permissions
	// address(bytes20(keccak256("PermissionController:AnyoneCanCall")))
	AnyoneCanCallAddress = ethcommon.HexToAddress("0x493219d9949348178af1f58740655951a8cd110c")

	// The address that is permissioned onchain for calls
	// address(bytes20(keccak256("PermissionController:ApiPermissions")))
	ApiPermissionsTarget = ethcommon.HexToAddress("0x57ee1fb74c1087e26446abc4fb87fd8f07c43d8d")
)

API permissions constants

View Source
var (
	EnvironmentFlag = &cli.StringFlag{
		Name:  "environment",
		Usage: "Deployment environment to use",
	}

	RpcUrlFlag = &cli.StringFlag{
		Name:    "rpc-url",
		Usage:   "RPC URL to connect to blockchain",
		EnvVars: []string{"RPC_URL"},
	}

	PrivateKeyFlag = &cli.StringFlag{
		Name:    "private-key",
		Usage:   "Private key for signing transactions",
		EnvVars: []string{"PRIVATE_KEY"},
	}

	ForceFlag = &cli.BoolFlag{
		Name:  "force",
		Usage: "Force operation without confirmation",
	}

	EnvFlag = &cli.StringFlag{
		Name:  "env-file",
		Usage: "Environment file to use",
		Value: ".env",
	}

	ImageNameFlag = &cli.StringFlag{
		Name:  "image-name",
		Usage: "Override app/image name (auto-detected from context if not provided)",
	}

	FileFlag = &cli.StringFlag{
		Name:    "dockerfile",
		Aliases: []string{"f"},
		Usage:   "Path to Dockerfile",
	}

	TemplateFlag = &cli.StringFlag{
		Name:  "template",
		Usage: "Template repository URL",
	}

	TemplateVersionFlag = &cli.StringFlag{
		Name:  "template-version",
		Usage: "Template version/tag to use",
	}

	AllFlag = &cli.BoolFlag{
		Name:  "all",
		Usage: "Show all apps including terminated ones",
	}

	AddressCountFlag = &cli.IntFlag{
		Name:  "address-count",
		Usage: "Number of addresses to fetch",
		Value: 1,
	}

	NameFlag = &cli.StringFlag{
		Name:  "name",
		Usage: "Friendly name for the app",
	}

	LogVisibilityFlag = &cli.StringFlag{
		Name:  "log-visibility",
		Usage: "Log visibility setting: public, private, or off",
	}

	InstanceTypeFlag = &cli.StringFlag{
		Name:  "instance-type",
		Usage: "Machine instance type to use e.g. g1-standard-4t, g1-standard-8t",
	}

	WatchFlag = &cli.BoolFlag{
		Name:    "watch",
		Aliases: []string{"w"},
		Usage:   "Continuously fetch and display updates",
	}
)

Common flag definitions

View Source
var BuildDownloadURL = func(version, arch, distro string) string {
	ext := ".tar.gz"
	if strings.Contains(distro, "windows") {
		ext = ".zip"
	}
	return "https://s3.amazonaws.com/eigenlayer-eigenx-releases" + BuildSuffix + "/" +
		version + "/eigenx-cli-" + distro + "-" + arch + "-" + version + ext
}

BuildDownloadURL constructs the S3 download URL for a specific version and platform

View Source
var EnvironmentConfigs = map[string]EnvironmentConfig{
	"sepolia": {
		Name:                        "sepolia",
		AppControllerAddress:        common.HexToAddress("0xa86DC1C47cb2518327fB4f9A1627F51966c83B92"),
		PermissionControllerAddress: ChainAddresses[SepoliaChainID].PermissionController,
		ERC7702DelegatorAddress:     CommonAddresses.ERC7702Delegator,
		KMSServerURL:                "http://10.128.0.57:8080",
		UserApiServerURL:            "https://34.49.173.26",
		DefaultRPCURL:               "https://ethereum-sepolia-rpc.publicnode.com",
	},
}

EnvironmentConfigs contains all environments available in dev builds

View Source
var ErrKeyNotFound = errors.New("key not found")
View Source
var GetS3VersionURL = func() string {
	return "https://s3.amazonaws.com/eigenlayer-eigenx-releases" + BuildSuffix + "/VERSION"
}

GetS3VersionURL returns the S3 URL for the VERSION file

View Source
var GlobalFlags = []cli.Flag{
	&cli.BoolFlag{
		Name:    "verbose",
		Aliases: []string{"v"},
		Usage:   "Enable verbose logging",
	},
	&cli.BoolFlag{
		Name:  "enable-telemetry",
		Usage: "Enable telemetry collection on first run without prompting",
	},
	&cli.BoolFlag{
		Name:  "disable-telemetry",
		Usage: "Disable telemetry collection on first run without prompting",
	},
}

GlobalFlags defines flags that apply to the entire application (global flags).

Functions

func DeletePrivateKey

func DeletePrivateKey(environment string) error

func EncodeExecutions

func EncodeExecutions(executions []erc7702delegatorV2.Execution) ([]byte, error)

func EnsureDockerIsRunning

func EnsureDockerIsRunning(cCtx *cli.Context) error

EnsureDockerIsRunning checks if Docker is running and attempts to launch Docker Desktop if not.

func ForceFlagWithUsage

func ForceFlagWithUsage(usage string) *cli.BoolFlag

func FormatAppDisplay

func FormatAppDisplay(context string, appID common.Address) string

FormatAppDisplay returns a user-friendly display string for an app Returns "name (0x123...)" if name exists, or just "0x123..." if no name

func FormatETH

func FormatETH(weiAmount *big.Int) string

FormatETH converts wei amount to ETH and formats it as a readable string

func GetAddressFromPrivateKey

func GetAddressFromPrivateKey(privateKeyHex string) (string, error)

GetAddressFromPrivateKey validates a private key and returns the corresponding address

func GetAppName

func GetAppName(context, appID string) string

GetAppName returns the name for a given app ID, or empty string if not found

func GetAppRegistryPath

func GetAppRegistryPath(context string) (string, error)

GetAppRegistryPath returns the path to the app registry file for a specific context

func GetDefaultEnvironment

func GetDefaultEnvironment() (string, error)

GetDefaultEnvironment returns the user's preferred deployment environment

func GetGlobalConfigDir

func GetGlobalConfigDir() (string, error)

GetGlobalConfigDir returns the XDG-compliant directory where global eigenx config should be stored

func GetGlobalConfigPath

func GetGlobalConfigPath() (string, error)

GetGlobalConfigPath returns the full path to the global config file

func GetGlobalTelemetryPreference

func GetGlobalTelemetryPreference() (*bool, error)

GetGlobalTelemetryPreference returns the global telemetry preference

func GetLatestVersionFromS3 added in v0.2.6

func GetLatestVersionFromS3(version string) (string, error)

GetLatestVersionFromS3 fetches the latest version from the S3 bucket If version is "latest", it fetches from the VERSION file Otherwise, it returns the specified version (for explicit version upgrades)

func GetLogger

func GetLogger(verbose bool) (iface.Logger, iface.ProgressTracker)

Get logger for the env we're in

func GetLoggerFromCLIContext

func GetLoggerFromCLIContext(cCtx *cli.Context) (iface.Logger, iface.ProgressTracker)

GetLoggerFromCLIContext creates a logger based on the CLI context It checks the verbose flag and returns the appropriate logger

func GetPrivateKey

func GetPrivateKey(environment string) (string, error)

func IsFirstRun

func IsFirstRun() (bool, error)

IsFirstRun checks if this is the user's first time running devkit

func IsMainnetEnvironment

func IsMainnetEnvironment(env string) bool

IsMainnetEnvironment checks if the given environment is a mainnet environment

func ListApps

func ListApps(context string) (map[string]App, error)

ListApps returns all apps in the registry

func LoggerFromContext

func LoggerFromContext(cCtx *cli.Context) iface.Logger

LoggerFromContext retrieves the logger from the context If no logger is found, it returns a non-verbose logger as fallback

func MarkFirstRunComplete

func MarkFirstRunComplete() error

MarkFirstRunComplete marks that the first run has been completed

func Parallel

func Parallel[T1, T2 any](fn1 func() (T1, error), fn2 func() (T2, error)) (T1, T2, error)

Parallel executes two functions concurrently and returns both results

func PeelBoolFromFlags

func PeelBoolFromFlags(args []string, longFlag, shortFlag string) bool

PeelBoolFromFlags reports whether a boolean CLI flag is set anywhere in args, It supports these forms:

--verbose
--verbose=true|false|1|0|yes|no|t|f
--verbose true|false|1|0|yes|no|t|f
-v
-v=true|false|1|0|yes|no|t|f
-v true|false|1|0|yes|no|t|f

The last occurrence wins. If a flag is present without an explicit value, it is treated as true.

func PrintUpdateNotification added in v0.2.6

func PrintUpdateNotification(info *UpdateInfo)

PrintUpdateNotification prints a user-friendly notification about an available update

func ProgressTrackerFromContext

func ProgressTrackerFromContext(ctx context.Context) iface.ProgressTracker

ProgressTrackerFromContext retrieves the progress tracker from the context If no tracker is found, it returns a non-verbose tracker as fallback

func ResolveAppID

func ResolveAppID(context, nameOrID string) (string, error)

ResolveAppID resolves a name or app ID to an app ID

func SaveAppRegistry

func SaveAppRegistry(context string, registry *AppRegistry) error

SaveAppRegistry saves the app registry to disk

func SaveGlobalConfig

func SaveGlobalConfig(config *GlobalConfig) error

SaveGlobalConfig saves the global configuration to disk

func SaveUserId

func SaveUserId(userUuid string) error

SaveUserId saves user settings to the global config, but preserves existing UUID if present

func SetAppName

func SetAppName(context, appIDOrName, newName string) error

SetAppName sets or updates a name for an app

func SetDefaultEnvironment

func SetDefaultEnvironment(environment string) error

SetDefaultEnvironment sets the user's preferred deployment environment

func SetGlobalTelemetryPreference

func SetGlobalTelemetryPreference(enabled bool) error

SetGlobalTelemetryPreference sets the global telemetry preference

func ShowTelemetryNotice

func ShowTelemetryNotice(logger iface.Logger, opts TelemetryPromptOptions) bool

ShowTelemetryNotice displays telemetry information notice without prompting

func StorePrivateKey

func StorePrivateKey(environment, privateKey string) error

func ValidateAppName

func ValidateAppName(name string) error

ValidateAppName validates that an app name follows Docker image naming restrictions

func ValidatePrivateKey

func ValidatePrivateKey(key string) error

ValidatePrivateKey validates that a private key is in the correct format

func WithAppEnvironment

func WithAppEnvironment(ctx *cli.Context)

func WithLogger

func WithLogger(ctx context.Context, logger iface.Logger) context.Context

WithLogger stores the logger in the context

func WithProgressTracker

func WithProgressTracker(ctx context.Context, tracker iface.ProgressTracker) context.Context

WithProgressTracker stores the progress tracker in the context

func WithShutdown

func WithShutdown(ctx context.Context) context.Context

WithShutdown creates a new context that will be cancelled on SIGTERM/SIGINT

Types

type App

type App struct {
	AppID     string    `yaml:"app_id"`
	CreatedAt time.Time `yaml:"created_at"`
	UpdatedAt time.Time `yaml:"updated_at"`
}

type AppEnvironment

type AppEnvironment struct {
	CLIVersion string
	OS         string
	Arch       string
	UserUUID   string
}

func AppEnvironmentFromContext

func AppEnvironmentFromContext(ctx context.Context) (*AppEnvironment, bool)

func NewAppEnvironment

func NewAppEnvironment(os, arch, userUuid string) *AppEnvironment

type AppRegistry

type AppRegistry struct {
	Version string         `yaml:"version"`
	Apps    map[string]App `yaml:"apps"`
}

func LoadAppRegistry

func LoadAppRegistry(context string) (*AppRegistry, error)

LoadAppRegistry loads the app registry from disk

type AppStatus

type AppStatus uint8
const (
	ContractAppStatusNone AppStatus = iota
	ContractAppStatusStarted
	ContractAppStatusStopped
	ContractAppStatusTerminated
)

type ChainAddr

type ChainAddr struct {
	PermissionController common.Address
}

type CommonAddr

type CommonAddr struct {
	ERC7702Delegator common.Address
}

type ContractCaller

type ContractCaller struct {
	SelfAddress common.Address
	// contains filtered or unexported fields
}

ContractCaller provides a high-level interface for interacting with contracts

func NewContractCaller

func NewContractCaller(privateKeyHex string, chainID *big.Int, environmentConfig EnvironmentConfig, client *ethclient.Client, logger iface.Logger) (*ContractCaller, error)

func (*ContractCaller) CheckERC7702Delegation

func (cc *ContractCaller) CheckERC7702Delegation(ctx context.Context, account common.Address) (bool, error)

CheckERC7702Delegation checks if the given account already delegates to the ERC-7702 delegator

func (*ContractCaller) DeployApp

func (cc *ContractCaller) DeployApp(ctx context.Context, salt [32]byte, release appcontrollerV2.IAppControllerRelease, publicLogs bool, imageRef string) (appID common.Address, err error)

DeployApp creates a new app via AppController contract, accepts admin permissions, and upgrades the app

func (*ContractCaller) ExecuteBatch

func (cc *ContractCaller) ExecuteBatch(ctx context.Context, executions []erc7702delegatorV2.Execution, needsConfirmation bool, confirmationPrompt string, pendingMessage string) error

ExecuteBatch executes a batch of executions. It sets the code of the EOA to the delegator contract if not already set.

func (*ContractCaller) SendAndWaitForTransaction

func (cc *ContractCaller) SendAndWaitForTransaction(ctx context.Context, txDescription string, callMsg *ethereum.CallMsg, needsConfirmation bool, confirmationPrompt string, pendingMessage string) error

func (*ContractCaller) StartApp

func (cc *ContractCaller) StartApp(ctx context.Context, appAddress common.Address) error

StartApp starts a stopped app via AppController contract

func (*ContractCaller) StopApp

func (cc *ContractCaller) StopApp(ctx context.Context, appAddress common.Address) error

StopApp stops a running app via AppController contract

func (*ContractCaller) TerminateApp

func (cc *ContractCaller) TerminateApp(ctx context.Context, appAddress common.Address, force bool) error

TerminateApp terminates an app permanently via AppController contract

func (*ContractCaller) Undelegate

func (cc *ContractCaller) Undelegate(ctx context.Context) error

func (*ContractCaller) UpgradeApp

func (cc *ContractCaller) UpgradeApp(ctx context.Context, appAddress common.Address, release appcontrollerV2.IAppControllerRelease, publicLogs bool, needsPermissionChange bool, imageRef string) error

UpgradeApp upgrades an app via AppController contract

type EnvironmentConfig

type EnvironmentConfig struct {
	Name                        string
	AppControllerAddress        common.Address
	PermissionControllerAddress common.Address
	ERC7702DelegatorAddress     common.Address
	KMSServerURL                string
	UserApiServerURL            string
	DefaultRPCURL               string
}

EnvironmentConfig defines the configuration for a specific environment

type GlobalConfig

type GlobalConfig struct {
	// FirstRun tracks if this is the user's first time running devkit
	FirstRun bool `yaml:"first_run"`
	// TelemetryEnabled stores the user's global telemetry preference
	TelemetryEnabled *bool `yaml:"telemetry_enabled,omitempty"`
	// The users uuid to identify user across projects
	UserUUID string `yaml:"user_uuid"`
	// DefaultEnvironment stores the user's preferred deployment environment (sepolia, mainnet-alpha, etc.)
	DefaultEnvironment string `yaml:"default_environment,omitempty"`
	// LastVersionCheck stores the timestamp of the last version check
	LastVersionCheck int64 `yaml:"last_version_check,omitempty"`
	// LastKnownVersion stores the last known latest version from the server
	LastKnownVersion string `yaml:"last_known_version,omitempty"`
}

GlobalConfig contains user-level configuration that persists across all devkit usage

func LoadGlobalConfig

func LoadGlobalConfig() (*GlobalConfig, error)

LoadGlobalConfig loads the global configuration, creating defaults if needed

type KeyringStore

type KeyringStore interface {
	StorePrivateKey(environment, privateKey string) error
	GetPrivateKey(environment string) (string, error)
	DeletePrivateKey(environment string) error
}
var DefaultKeyringStore KeyringStore = &OSKeyringStore{}

type OSKeyringStore

type OSKeyringStore struct{}

func (*OSKeyringStore) DeletePrivateKey

func (o *OSKeyringStore) DeletePrivateKey(environment string) error

func (*OSKeyringStore) GetPrivateKey

func (o *OSKeyringStore) GetPrivateKey(environment string) (string, error)

func (*OSKeyringStore) StorePrivateKey

func (o *OSKeyringStore) StorePrivateKey(environment, privateKey string) error

type TelemetryPromptOptions

type TelemetryPromptOptions struct {
	// EnableTelemetry automatically enables telemetry without prompting (for --enable-telemetry flag)
	EnableTelemetry bool
	// DisableTelemetry automatically disables telemetry without prompting (for --disable-telemetry flag)
	DisableTelemetry bool
	// SkipPromptInCI skips the prompt in CI environments (defaults to disabled)
	SkipPromptInCI bool
}

TelemetryPromptOptions controls how the telemetry prompt behaves

type UpdateInfo added in v0.2.6

type UpdateInfo struct {
	Available      bool
	CurrentVersion string
	LatestVersion  string
}

UpdateInfo contains information about an available version update

func CheckForUpdate added in v0.2.6

func CheckForUpdate(logger iface.Logger) (*UpdateInfo, error)

CheckForUpdate checks if a new version is available, using cached results when possible

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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