Skip to content

Commit

Permalink
UAM Command Schema with CanCall Implementation (#244)
Browse files Browse the repository at this point in the history
Co-authored-by: Brandon Chatham <[email protected]>
  • Loading branch information
bdchatham and Brandon Chatham authored Dec 9, 2024
1 parent 32daab3 commit 5db8d6d
Show file tree
Hide file tree
Showing 31 changed files with 914 additions and 14 deletions.
1 change: 1 addition & 0 deletions cmd/eigenlayer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func main() {
app.Commands = append(app.Commands, pkg.RewardsCmd(prompter))
app.Commands = append(app.Commands, pkg.KeysCmd(prompter))
app.Commands = append(app.Commands, pkg.EigenPodCmd(prompter))
app.Commands = append(app.Commands, pkg.UserCmd())

if err := app.Run(os.Args); err != nil {
_, err := fmt.Fprintln(os.Stderr, err)
Expand Down
6 changes: 1 addition & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,12 @@ module github.com/Layr-Labs/eigenlayer-cli

go 1.21.11

replace (
github.com/Layr-Labs/eigensdk-go => ../eigensdk-go
)

require (
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/Layr-Labs/eigenlayer-contracts v0.3.2-mainnet-rewards
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241122062350-76ffacff7c4e
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241205221048-fe823e1c912f
github.com/blang/semver/v4 v4.0.0
github.com/consensys/gnark-crypto v0.12.1
github.com/ethereum/go-ethereum v1.14.5
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e/go.mod h1:T7tYN8bTdca2pkMnz9G2+ZwXYWw5gWqQUIu4KLgC/vM=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241122062350-76ffacff7c4e h1:l+iq4tg0iHZjHOHWzLxoLDVEhhEEuK0iCBiuWXqZpy0=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241122062350-76ffacff7c4e/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241204193922-c60d25970459 h1:37Upmqc4RTTNjmtzkEshKZu4yis8ogSEnrQmLqZ8cxU=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241204193922-c60d25970459/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241205221048-fe823e1c912f h1:A/rKI4aDTTgfzDacgKwyV/XMFdibxbc2WXavaWPzn1Q=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241205221048-fe823e1c912f/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
Expand Down
53 changes: 47 additions & 6 deletions pkg/internal/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package common
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
Expand All @@ -14,8 +15,6 @@ import (
"strings"
"time"

"github.com/urfave/cli/v2"

"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
Expand All @@ -36,6 +35,15 @@ import (
"github.com/ethereum/go-ethereum/ethclient"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
)

const (
mainnet = "mainnet"
testnet = "testnet"
local = "local"
selectorHexIdLength = 10
addressPrefix = "0x"
)

var ChainMetadataMap = map[int64]types.ChainMetadata{
Expand All @@ -44,6 +52,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
ELDelegationManagerAddress: "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A",
ELAVSDirectoryAddress: "0x135dda560e946695d6f155dacafc6f1f25c1f5af",
ELRewardsCoordinatorAddress: "0x7750d328b314EfFa365A0402CcfD489B80B0adda",
ELPermissionManagerAddress: "",
WebAppUrl: "https://app.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-mainnet-ethereum.s3.amazonaws.com",
},
Expand All @@ -52,6 +61,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
ELDelegationManagerAddress: "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
ELAVSDirectoryAddress: "0x055733000064333CaDDbC92763c58BF0192fFeBf",
ELRewardsCoordinatorAddress: "0xAcc1fb458a1317E886dB376Fc8141540537E68fE",
ELPermissionManagerAddress: "",
WebAppUrl: "https://holesky.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-testnet-holesky.s3.amazonaws.com",
},
Expand All @@ -60,6 +70,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
ELDelegationManagerAddress: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
ELAVSDirectoryAddress: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
ELRewardsCoordinatorAddress: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
ELPermissionManagerAddress: "",
WebAppUrl: "",
ProofStoreBaseURL: "",
},
Expand Down Expand Up @@ -331,6 +342,16 @@ func GetDelegationManagerAddress(chainID *big.Int) (string, error) {
}
}

func GetPermissionManagerAddress(chainID *big.Int) (string, error) {
chainIDInt := chainID.Int64()
chainMetadata, ok := ChainMetadataMap[chainIDInt]
if !ok {
return "", fmt.Errorf("chain ID %d not supported", chainIDInt)
} else {
return chainMetadata.ELDelegationManagerAddress, nil
}
}

func GetTransactionLink(txHash string, chainId *big.Int) string {
chainIDInt := chainId.Int64()
chainMetadata, ok := ChainMetadataMap[chainIDInt]
Expand Down Expand Up @@ -490,7 +511,7 @@ func GetNoSendTxOpts(from common.Address) *bind.TransactOpts {
}

func Trim0x(s string) string {
return strings.TrimPrefix(s, "0x")
return strings.TrimPrefix(s, addressPrefix)
}

func Sign(digest []byte, cfg types.SignerConfig, p utils.Prompter) ([]byte, error) {
Expand Down Expand Up @@ -544,13 +565,33 @@ func Sign(digest []byte, cfg types.SignerConfig, p utils.Prompter) ([]byte, erro
return signed, nil
}

func ValidateAndConvertSelectorString(selector string) ([4]byte, error) {
if len(selector) != selectorHexIdLength || selector[:2] != addressPrefix {
return [4]byte{}, errors.New("selector must be a 4-byte hex string prefixed with '0x'")
}

decoded, err := hex.DecodeString(selector[2:])
if err != nil {
return [4]byte{}, eigenSdkUtils.WrapError("invalid hex encoding: %v", err)
}

if len(decoded) != 4 {
return [4]byte{}, fmt.Errorf("decoded selector must be 4 bytes, got %d bytes", len(decoded))
}

var selectorBytes [4]byte
copy(selectorBytes[:], decoded)

return selectorBytes, nil
}

func GetEnvFromNetwork(network string) string {
switch network {
case utils.HoleskyNetworkName:
return "testnet"
return testnet
case utils.MainnetNetworkName:
return "mainnet"
return mainnet
default:
return "local"
return local
}
}
4 changes: 2 additions & 2 deletions pkg/operator/allocations/set_allocation_delay.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func setDelayAction(cCtx *cli.Context, p utils.Prompter) error {
return eigenSdkUtils.WrapError("failed to get EL writer", err)
}

receipt, err := eLWriter.SetAllocationDelay(ctx, config.allocationDelay, true)
receipt, err := eLWriter.SetAllocationDelay(ctx, config.operatorAddress, config.allocationDelay, true)
if err != nil {
return err
}
Expand All @@ -99,7 +99,7 @@ func setDelayAction(cCtx *cli.Context, p utils.Prompter) error {
noSendTxOpts.GasLimit = 150_000
}

unsignedTx, err := contractBindings.AllocationManager.SetAllocationDelay0(noSendTxOpts, config.allocationDelay)
unsignedTx, err := contractBindings.AllocationManager.SetAllocationDelay(noSendTxOpts, config.operatorAddress, config.allocationDelay)
if err != nil {
return eigenSdkUtils.WrapError("failed to create unsigned tx", err)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/operator/allocations/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ func showAction(cCtx *cli.Context, p utils.Prompter) error {
*/
operatorDelegatedSharesMap := make(map[string]*big.Int)
shares, err := elReader.GetOperatorShares(ctx, config.operatorAddress, config.strategyAddresses)
if err != nil {
return eigenSdkUtils.WrapError("failed to get operator shares", err)
}
for i, strategyAddress := range config.strategyAddresses {
operatorDelegatedSharesMap[strategyAddress.String()] = shares[i]
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/operator/allocations/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error {

receipt, err := eLWriter.ModifyAllocations(
ctx,
config.operatorAddress,
allocationsToUpdate.Allocations,
true,
)
Expand All @@ -136,6 +137,7 @@ func updateAllocations(cCtx *cli.Context, p utils.Prompter) error {

unsignedTx, err := contractBindings.AllocationManager.ModifyAllocations(
noSendTxOpts,
config.operatorAddress,
allocationsToUpdate.Allocations,
)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/operator/register_operator_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ func registerOperatorSetsAction(cCtx *cli.Context, p utils.Prompter) error {
}
unsignedTx, err := contractBindings.AllocationManager.RegisterForOperatorSets(
noSendTxOpts,
config.operatorAddress,
allocationmanager.IAllocationManagerTypesRegisterParams{
Avs: config.avsAddress,
OperatorSetIds: config.operatorSetIds,
Expand Down
7 changes: 6 additions & 1 deletion pkg/operator/update_metadata_uri.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ Requires the same file used for registration as argument
return eigenSdkUtils.WrapError("failed to get EL writer", err)
}

receipt, err := elWriter.UpdateMetadataURI(context.Background(), operatorCfg.Operator.MetadataUrl, true)
receipt, err := elWriter.UpdateMetadataURI(
context.Background(),
gethcommon.HexToAddress(operatorCfg.Operator.Address),
operatorCfg.Operator.MetadataUrl,
true,
)
if err != nil {
fmt.Printf("%s Error while updating operator metadata uri\n", utils.EmojiCrossMark)
return err
Expand Down
1 change: 1 addition & 0 deletions pkg/types/chain_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ type ChainMetadata struct {
ELDelegationManagerAddress string
ELAVSDirectoryAddress string
ELRewardsCoordinatorAddress string
ELPermissionManagerAddress string
WebAppUrl string
ProofStoreBaseURL string
}
32 changes: 32 additions & 0 deletions pkg/user/admin/accept.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package admin

import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/urfave/cli/v2"
"sort"
)

func AcceptCmd() *cli.Command {
acceptCmd := &cli.Command{
Name: "accept-admin",
Usage: "user admin accept-admin --account-address <AccountAddress>",
UsageText: "Accepts a user to become admin who is currently pending admin acceptance.",
Description: `
Accepts a user to become admin who is currently pending admin acceptance.
`,
After: telemetry.AfterRunAction(),
Flags: acceptFlags(),
}

return acceptCmd
}

func acceptFlags() []cli.Flag {
cmdFlags := []cli.Flag{
&flags.VerboseFlag,
&AccountAddressFlag,
}
sort.Sort(cli.FlagsByName(cmdFlags))
return append(cmdFlags, flags.GetSignerFlags()...)
}
33 changes: 33 additions & 0 deletions pkg/user/admin/add_pending.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package admin

import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/urfave/cli/v2"
"sort"
)

func AddPendingCmd() *cli.Command {
addPendingCmd := &cli.Command{
Name: "add-pending-admin",
Usage: "user admin add-pending-admin --account-address <AccountAddress> --admin-address <AdminAddress>",
UsageText: "Add an admin to be pending until accepted.",
Description: `
Add an admin to be pending until accepted.
`,
After: telemetry.AfterRunAction(),
Flags: addPendingFlags(),
}

return addPendingCmd
}

func addPendingFlags() []cli.Flag {
cmdFlags := []cli.Flag{
&flags.VerboseFlag,
&AccountAddressFlag,
&AdminAddressFlag,
}
sort.Sort(cli.FlagsByName(cmdFlags))
return append(cmdFlags, flags.GetSignerFlags()...)
}
34 changes: 34 additions & 0 deletions pkg/user/admin/admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package admin

import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/urfave/cli/v2"
)

func AdminCmd() *cli.Command {
adminCmd := &cli.Command{
Name: "admin",
Usage: "user admin <command>",
UsageText: "Manage admin users.",
Description: `
Manage admin users.
`,
After: telemetry.AfterRunAction(),
Flags: []cli.Flag{
&flags.VerboseFlag,
},
Subcommands: []*cli.Command{
AcceptCmd(),
AddPendingCmd(),
IsAdminCmd(),
IsPendingCmd(),
ListCmd(),
ListPendingCmd(),
RemoveCmd(),
RemovePendingCmd(),
},
}

return adminCmd
}
36 changes: 36 additions & 0 deletions pkg/user/admin/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package admin

import "github.com/urfave/cli/v2"

var (
AccountAddressFlag = cli.StringFlag{
Name: "account-address",
Aliases: []string{"aa"},
Usage: "user admin ... --account-address \"0x...\"",
EnvVars: []string{"ACCOUNT_ADDRESS"},
}
AdminAddressFlag = cli.StringFlag{
Name: "admin-address",
Aliases: []string{"aa"},
Usage: "user admin ... --admin-address \"0x...\"",
EnvVars: []string{"ADMIN_ADDRESS"},
}
CallerAddressFlag = cli.StringFlag{
Name: "caller-address",
Aliases: []string{"ca"},
Usage: "user admin ... --caller-address \"0x...\"",
EnvVars: []string{"CALLER_ADDRESS"},
}
PendingAdminAddressFlag = cli.StringFlag{
Name: "pending-admin-address",
Aliases: []string{"paa"},
Usage: "user admin ... --pending-admin-address \"0x...\"",
EnvVars: []string{"PENDING_ADMIN_ADDRESS"},
}
PermissionControllerAddressFlag = cli.StringFlag{
Name: "permission-controller-address",
Aliases: []string{"pca"},
Usage: "user admin ... --permission-controller-address \"0x...\"",
EnvVars: []string{"PERMISSION_CONTROLLER_ADDRESS"},
}
)
26 changes: 26 additions & 0 deletions pkg/user/admin/is_admin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package admin

import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/urfave/cli/v2"
)

func IsAdminCmd() *cli.Command {
isAdmin := &cli.Command{
Name: "is-admin",
Usage: "user admin is-admin --account-address <AccountAddress> --caller-address <CallerAddress>",
UsageText: "Checks if a user is an admin.",
Description: `
Checks if a user is an admin.
`,
After: telemetry.AfterRunAction(),
Flags: []cli.Flag{
&flags.VerboseFlag,
&AccountAddressFlag,
&CallerAddressFlag,
},
}

return isAdmin
}
Loading

0 comments on commit 5db8d6d

Please sign in to comment.