@@ -3,6 +3,7 @@ package common
33import (
44 "context"
55 "crypto/ecdsa"
6+ "encoding/hex"
67 "encoding/json"
78 "errors"
89 "fmt"
@@ -14,8 +15,6 @@ import (
1415 "strings"
1516 "time"
1617
17- "github.com/urfave/cli/v2"
18-
1918 "github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common/flags"
2019 "github.com/Layr-Labs/eigenlayer-cli/pkg/types"
2120 "github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
@@ -36,6 +35,15 @@ import (
3635 "github.com/ethereum/go-ethereum/ethclient"
3736
3837 "github.com/fatih/color"
38+ "github.com/urfave/cli/v2"
39+ )
40+
41+ const (
42+ mainnet = "mainnet"
43+ testnet = "testnet"
44+ local = "local"
45+ selectorHexIdLength = 10
46+ addressPrefix = "0x"
3947)
4048
4149var ChainMetadataMap = map [int64 ]types.ChainMetadata {
@@ -44,6 +52,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
4452 ELDelegationManagerAddress : "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A" ,
4553 ELAVSDirectoryAddress : "0x135dda560e946695d6f155dacafc6f1f25c1f5af" ,
4654 ELRewardsCoordinatorAddress : "0x7750d328b314EfFa365A0402CcfD489B80B0adda" ,
55+ ELPermissionManagerAddress : "" ,
4756 WebAppUrl : "https://app.eigenlayer.xyz/operator" ,
4857 ProofStoreBaseURL : "https://eigenlabs-rewards-mainnet-ethereum.s3.amazonaws.com" ,
4958 },
@@ -52,6 +61,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
5261 ELDelegationManagerAddress : "0xA44151489861Fe9e3055d95adC98FbD462B948e7" ,
5362 ELAVSDirectoryAddress : "0x055733000064333CaDDbC92763c58BF0192fFeBf" ,
5463 ELRewardsCoordinatorAddress : "0xAcc1fb458a1317E886dB376Fc8141540537E68fE" ,
64+ ELPermissionManagerAddress : "" ,
5565 WebAppUrl : "https://holesky.eigenlayer.xyz/operator" ,
5666 ProofStoreBaseURL : "https://eigenlabs-rewards-testnet-holesky.s3.amazonaws.com" ,
5767 },
@@ -60,6 +70,7 @@ var ChainMetadataMap = map[int64]types.ChainMetadata{
6070 ELDelegationManagerAddress : "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9" ,
6171 ELAVSDirectoryAddress : "0x0165878A594ca255338adfa4d48449f69242Eb8F" ,
6272 ELRewardsCoordinatorAddress : "0x610178dA211FEF7D417bC0e6FeD39F05609AD788" ,
73+ ELPermissionManagerAddress : "" ,
6374 WebAppUrl : "" ,
6475 ProofStoreBaseURL : "" ,
6576 },
@@ -321,6 +332,26 @@ func GetAVSDirectoryAddress(chainID *big.Int) (string, error) {
321332 }
322333}
323334
335+ func GetDelegationManagerAddress (chainID * big.Int ) (string , error ) {
336+ chainIDInt := chainID .Int64 ()
337+ chainMetadata , ok := ChainMetadataMap [chainIDInt ]
338+ if ! ok {
339+ return "" , fmt .Errorf ("chain ID %d not supported" , chainIDInt )
340+ } else {
341+ return chainMetadata .ELDelegationManagerAddress , nil
342+ }
343+ }
344+
345+ func GetPermissionManagerAddress (chainID * big.Int ) (string , error ) {
346+ chainIDInt := chainID .Int64 ()
347+ chainMetadata , ok := ChainMetadataMap [chainIDInt ]
348+ if ! ok {
349+ return "" , fmt .Errorf ("chain ID %d not supported" , chainIDInt )
350+ } else {
351+ return chainMetadata .ELDelegationManagerAddress , nil
352+ }
353+ }
354+
324355func GetTransactionLink (txHash string , chainId * big.Int ) string {
325356 chainIDInt := chainId .Int64 ()
326357 chainMetadata , ok := ChainMetadataMap [chainIDInt ]
@@ -480,7 +511,7 @@ func GetNoSendTxOpts(from common.Address) *bind.TransactOpts {
480511}
481512
482513func Trim0x (s string ) string {
483- return strings .TrimPrefix (s , "0x" )
514+ return strings .TrimPrefix (s , addressPrefix )
484515}
485516
486517func Sign (digest []byte , cfg types.SignerConfig , p utils.Prompter ) ([]byte , error ) {
@@ -533,3 +564,34 @@ func Sign(digest []byte, cfg types.SignerConfig, p utils.Prompter) ([]byte, erro
533564
534565 return signed , nil
535566}
567+
568+ func ValidateAndConvertSelectorString (selector string ) ([4 ]byte , error ) {
569+ if len (selector ) != selectorHexIdLength || selector [:2 ] != addressPrefix {
570+ return [4 ]byte {}, errors .New ("selector must be a 4-byte hex string prefixed with '0x'" )
571+ }
572+
573+ decoded , err := hex .DecodeString (selector [2 :])
574+ if err != nil {
575+ return [4 ]byte {}, eigenSdkUtils .WrapError ("invalid hex encoding: %v" , err )
576+ }
577+
578+ if len (decoded ) != 4 {
579+ return [4 ]byte {}, fmt .Errorf ("decoded selector must be 4 bytes, got %d bytes" , len (decoded ))
580+ }
581+
582+ var selectorBytes [4 ]byte
583+ copy (selectorBytes [:], decoded )
584+
585+ return selectorBytes , nil
586+ }
587+
588+ func GetEnvFromNetwork (network string ) string {
589+ switch network {
590+ case utils .HoleskyNetworkName :
591+ return testnet
592+ case utils .MainnetNetworkName :
593+ return mainnet
594+ default :
595+ return local
596+ }
597+ }
0 commit comments