Skip to content

Commit

Permalink
feat: slashing commands
Browse files Browse the repository at this point in the history
feat: add working cmds

remove unrelated changes

remove unrelated changes

unsigned tx

add some tests

comment

add readme

more allocations

basic show command

update with latest contracts

add more code

add more code

working slashing

%age and comments

update with latest contracts

Update show.go (#226)

updated to latest AM

updated to latest AM

updated to latest AM

update eigensdk

update with latest contracts

update with latest contracts

update allocation delay cmd

update with latest contracts

added registered/deregistered operator sets

only show deregister if there's any allocation left

UAM Command Schema with CanCall Implementation (#244)

Co-authored-by: Brandon Chatham <[email protected]>

fix: tests and fmt (#249)

Implementing `list` and `list_permissions` Commands. (#248)

Co-authored-by: Brandon Chatham <[email protected]>
  • Loading branch information
shrimalmadhur and Brandon Chatham committed Dec 10, 2024
1 parent d41fc29 commit 070a30e
Show file tree
Hide file tree
Showing 52 changed files with 3,891 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ operator-config.yaml.old
operator.yaml
operator.yaml.old
config/*
updates.csv

# build
dist/
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
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.13-0.20241023200243-565bb4438918
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241210000422-beb1a3c4502f
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
10 changes: 8 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12 h1:G5Q1SnLmFbEjhOkky3vIHk
github.com/Layr-Labs/eigenlayer-rewards-proofs v0.2.12/go.mod h1:OlJd1QjqEW53wfWG/lJyPCGvrXwWVEjPQsP4TV+gttQ=
github.com/Layr-Labs/eigenpod-proofs-generation v0.0.14-stable.0.20240730152248-5c11a259293e h1:DvW0/kWHV9mZsbH2KOjEHKTSIONNPUj6X05FJvUohy4=
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.13-0.20241023200243-565bb4438918 h1:Itl141PoMFzq58ZTo4Nu/CyH+x8f4BH6OmBNhZ6Z2/I=
github.com/Layr-Labs/eigensdk-go v0.1.13-0.20241023200243-565bb4438918/go.mod h1:aYdNURUhaqeYOS+Cq12TfSdPbjFfiLaHkxPdR4Exq/s=
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/Layr-Labs/eigensdk-go v0.1.14-0.20241210000422-beb1a3c4502f h1:D94Vf+dALr9W0Ie18lZ8QDPvOAFX8FBbIpyVAtCUL1A=
github.com/Layr-Labs/eigensdk-go v0.1.14-0.20241210000422-beb1a3c4502f/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
12 changes: 12 additions & 0 deletions pkg/internal/common/contracts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package common

import (
"context"
"errors"
"math/big"

Expand Down Expand Up @@ -57,3 +58,14 @@ func GetELWriter(

return eLWriter, nil
}

func IsSmartContractAddress(address gethcommon.Address, ethClient *ethclient.Client) bool {
code, err := ethClient.CodeAt(context.Background(), address, nil)
if err != nil {
// We return true here because we want to treat the address as a smart contract
// This is only used to gas estimation and creating unsigned transactions
// So it's fine if eth client return an error
return true
}
return len(code) > 0
}
46 changes: 46 additions & 0 deletions pkg/internal/common/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package common
import (
"fmt"
"math/big"
"strconv"
"strings"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)

Expand Down Expand Up @@ -46,3 +48,47 @@ func GetTxFeeDetails(tx *types.Transaction) *TxFeeDetails {
GasFeeCapGwei: gasFeeCapGwei,
}
}

func ConvertStringSliceToGethAddressSlice(addresses []string) []common.Address {
gethAddresses := make([]common.Address, 0, len(addresses))
for _, address := range addresses {
parsed := common.HexToAddress(address)
gethAddresses = append(gethAddresses, parsed)
}
return gethAddresses
}

func ShortEthAddress(address common.Address) string {
return fmt.Sprintf("%s...%s", address.Hex()[:6], address.Hex()[len(address.Hex())-4:])
}

func Uint64ToString(num uint64) string {
return strconv.FormatUint(num, 10)
}

func FormatNumberWithUnderscores(numStr string) string {

// If the number is less than 1000, no formatting is needed
if len(numStr) <= 3 {
return numStr
}

// Calculate the number of groups of 3 digits
groups := (len(numStr) - 1) / 3

// Create a slice to hold the result
result := make([]byte, len(numStr)+groups)

// Fill the result slice from right to left
resultIndex := len(result) - 1
for i := len(numStr) - 1; i >= 0; i-- {
if (len(numStr)-i-1)%3 == 0 && i != len(numStr)-1 {
result[resultIndex] = '_'
resultIndex--
}
result[resultIndex] = numStr[i]
resultIndex--
}

return string(result)
}
47 changes: 47 additions & 0 deletions pkg/internal/common/flags/avs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package flags

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

var (
AVSAddressesFlag = cli.StringSliceFlag{
Name: "avs-addresses",
Usage: "AVS addresses",
Aliases: []string{"aa"},
EnvVars: []string{"AVS_ADDRESSES"},
}

AVSAddressFlag = cli.StringFlag{
Name: "avs-address",
Usage: "AVS addresses",
Aliases: []string{"aa"},
EnvVars: []string{"AVS_ADDRESS"},
}

StrategyAddressesFlag = cli.StringSliceFlag{
Name: "strategy-addresses",
Usage: "Strategy addresses",
Aliases: []string{"sa"},
EnvVars: []string{"STRATEGY_ADDRESSES"},
}

StrategyAddressFlag = cli.StringFlag{
Name: "strategy-address",
Usage: "Strategy addresses",
Aliases: []string{"sa"},
EnvVars: []string{"STRATEGY_ADDRESS"},
}

OperatorSetIdFlag = cli.Uint64Flag{
Name: "operator-set-id",
Usage: "Operator set ID",
Aliases: []string{"osid"},
EnvVars: []string{"OPERATOR_SET_ID"},
}

OperatorSetIdsFlag = cli.Uint64SliceFlag{
Name: "operator-set-ids",
Usage: "Operator set IDs. Comma separated list of operator set IDs",
Aliases: []string{"osids"},
EnvVars: []string{"OPERATOR_SET_IDS"},
}
)
28 changes: 28 additions & 0 deletions pkg/internal/common/flags/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,32 @@ var (
EnvVars: []string{"EXPIRY"},
Value: 3600,
}

OperatorAddressFlag = cli.StringFlag{
Name: "operator-address",
Aliases: []string{"oa", "operator"},
Usage: "Operator address",
EnvVars: []string{"OPERATOR_ADDRESS"},
}

CSVFileFlag = cli.StringFlag{
Name: "csv-file",
Aliases: []string{"csv"},
Usage: "CSV file to read data from",
EnvVars: []string{"CSV_FILE"},
}

EnvironmentFlag = cli.StringFlag{
Name: "environment",
Aliases: []string{"env"},
Usage: "environment to use. Currently supports 'preprod' ,'testnet' and 'prod'. If not provided, it will be inferred based on network",
EnvVars: []string{"ENVIRONMENT"},
}

DelegationManagerAddressFlag = cli.StringFlag{
Name: "delegation-manager-address",
Aliases: []string{"dma"},
Usage: "Optional delegation manager address. This can be used if you are testing against your own deployment of eigenlayer contracts",
EnvVars: []string{"DELEGATION_MANAGER_ADDRESS"},
}
)
68 changes: 65 additions & 3 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 @@ -321,6 +332,26 @@ func GetAVSDirectoryAddress(chainID *big.Int) (string, error) {
}
}

func GetDelegationManagerAddress(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 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 @@ -480,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 @@ -533,3 +564,34 @@ 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
case utils.MainnetNetworkName:
return mainnet
default:
return local
}
}
3 changes: 3 additions & 0 deletions pkg/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ func OperatorCmd(p utils.Prompter) *cli.Command {
operator.UpdateCmd(p),
operator.UpdateMetadataURICmd(p),
operator.GetApprovalCmd(p),
operator.AllocationsCmd(p),
operator.DeregisterCommand(p),
operator.RegisterOperatorSetsCommand(p),
},
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/operator/allocations.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package operator

import (
"github.com/Layr-Labs/eigenlayer-cli/pkg/operator/allocations"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
"github.com/urfave/cli/v2"
)

func AllocationsCmd(p utils.Prompter) *cli.Command {
var allocationsCmd = &cli.Command{
Name: "allocations",
Usage: "Stake allocation commands for operators",
Subcommands: []*cli.Command{
allocations.ShowCmd(p),
allocations.UpdateCmd(p),
allocations.SetDelayCmd(p),
},
}

return allocationsCmd
}
Loading

0 comments on commit 070a30e

Please sign in to comment.