Skip to content

Commit

Permalink
chore: refactor and move to internal
Browse files Browse the repository at this point in the history
  • Loading branch information
shrimalmadhur committed Sep 11, 2024
1 parent ef0a2eb commit 3b188c1
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 67 deletions.
9 changes: 9 additions & 0 deletions pkg/internal/common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,13 @@ const (
OutputType_Calldata OutputType = "calldata"
OutputType_Pretty OutputType = "pretty"
OutputType_Json OutputType = "json"

MainnetChainId = 1
HoleskyChainId = 17000
AnvilChainId = 31337

MainnetNetworkName = "mainnet"
HoleskyNetworkName = "holesky"
AnvilNetworkName = "anvil"
UnknownNetworkName = "unknown"
)
1 change: 1 addition & 0 deletions pkg/internal/common/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (t *TxFeeDetails) Print() {
fmt.Printf("Approximate Max Cost of transaction: %0.12f ETH\n", t.CostInEth)
fmt.Println(strings.Repeat("-", len(message)))
}

func GetTxFeeDetails(tx *types.Transaction) *TxFeeDetails {
gasTipCapGwei := float64(tx.GasTipCap().Uint64()) / GweiToWei
gasFeeCapGwei := float64(tx.GasFeeCap().Uint64()) / GweiToWei
Expand Down
48 changes: 37 additions & 11 deletions pkg/internal/common/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,33 @@ import (
"github.com/fatih/color"
)

var ChainMetadataMap = map[int64]types.ChainMetadata{
MainnetChainId: {
BlockExplorerUrl: "https://etherscan.io/tx",
ELDelegationManagerAddress: "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A",
ELAVSDirectoryAddress: "0x135dda560e946695d6f155dacafc6f1f25c1f5af",
ELRewardsCoordinatorAddress: "0x7750d328b314EfFa365A0402CcfD489B80B0adda",
WebAppUrl: "https://app.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-mainnet-ethereum.s3.amazonaws.com",
},
HoleskyChainId: {
BlockExplorerUrl: "https://holesky.etherscan.io/tx",
ELDelegationManagerAddress: "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
ELAVSDirectoryAddress: "0x055733000064333CaDDbC92763c58BF0192fFeBf",
ELRewardsCoordinatorAddress: "0xAcc1fb458a1317E886dB376Fc8141540537E68fE",
WebAppUrl: "https://holesky.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-testnet-holesky.s3.amazonaws.com",
},
AnvilChainId: {
BlockExplorerUrl: "",
ELDelegationManagerAddress: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
ELAVSDirectoryAddress: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
ELRewardsCoordinatorAddress: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
WebAppUrl: "",
ProofStoreBaseURL: "",
},
}

func PrintRegistrationInfo(txHash string, operatorAddress common.Address, chainId *big.Int) {
fmt.Println()
fmt.Println(strings.Repeat("-", 100))
Expand Down Expand Up @@ -255,13 +282,13 @@ func ReadConfigFile(path string) (*types.OperatorConfig, error) {
return nil, err
}

elAVSDirectoryAddress, err := getAVSDirectoryAddress(operatorCfg.ChainId)
elAVSDirectoryAddress, err := GetAVSDirectoryAddress(&operatorCfg.ChainId)
if err != nil {
return nil, err
}
operatorCfg.ELAVSDirectoryAddress = elAVSDirectoryAddress

elRewardsCoordinatorAddress, err := getRewardCoordinatorAddress(operatorCfg.ChainId)
elRewardsCoordinatorAddress, err := GetRewardCoordinatorAddress(&operatorCfg.ChainId)
if err != nil {
return nil, err
}
Expand All @@ -270,30 +297,29 @@ func ReadConfigFile(path string) (*types.OperatorConfig, error) {
return &operatorCfg, nil
}

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

// TODO(shrimalmadhur): remove this and use the utils one in a separate PR
func getRewardCoordinatorAddress(chainID big.Int) (string, error) {
func GetAVSDirectoryAddress(chainID *big.Int) (string, error) {
chainIDInt := chainID.Int64()
chainMetadata, ok := utils.ChainMetadataMap[chainIDInt]
chainMetadata, ok := ChainMetadataMap[chainIDInt]
if !ok {
return "", fmt.Errorf("chain ID %d not supported", chainIDInt)
} else {
return chainMetadata.ELRewardsCoordinatorAddress, nil
return chainMetadata.ELAVSDirectoryAddress, nil
}
}

func GetTransactionLink(txHash string, chainId *big.Int) string {
chainIDInt := chainId.Int64()
chainMetadata, ok := utils.ChainMetadataMap[chainIDInt]
chainMetadata, ok := ChainMetadataMap[chainIDInt]
if !ok {
return txHash
} else {
Expand All @@ -303,7 +329,7 @@ func GetTransactionLink(txHash string, chainId *big.Int) string {

func getWebAppLink(operatorAddress common.Address, chainId *big.Int) string {
chainIDInt := chainId.Int64()
chainMetadata, ok := utils.ChainMetadataMap[chainIDInt]
chainMetadata, ok := ChainMetadataMap[chainIDInt]
if !ok {
return ""
} else {
Expand Down
7 changes: 4 additions & 3 deletions pkg/operator/config/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"os"

"github.com/Layr-Labs/eigenlayer-cli/pkg/internal/common"
"github.com/Layr-Labs/eigenlayer-cli/pkg/telemetry"
"github.com/Layr-Labs/eigenlayer-cli/pkg/types"
"github.com/Layr-Labs/eigenlayer-cli/pkg/utils"
Expand Down Expand Up @@ -166,13 +167,13 @@ func promptOperatorInfo(config *types.OperatorConfig, p utils.Prompter) (types.O
switch chainId {
case utils.MainnetNetworkName:
config.ChainId = *big.NewInt(utils.MainnetChainId)
config.ELDelegationManagerAddress = utils.ChainMetadataMap[utils.MainnetChainId].ELDelegationManagerAddress
config.ELDelegationManagerAddress = common.ChainMetadataMap[utils.MainnetChainId].ELDelegationManagerAddress
case utils.HoleskyNetworkName:
config.ChainId = *big.NewInt(utils.HoleskyChainId)
config.ELDelegationManagerAddress = utils.ChainMetadataMap[utils.HoleskyChainId].ELDelegationManagerAddress
config.ELDelegationManagerAddress = common.ChainMetadataMap[utils.HoleskyChainId].ELDelegationManagerAddress
case utils.AnvilNetworkName:
config.ChainId = *big.NewInt(utils.AnvilChainId)
config.ELDelegationManagerAddress = utils.ChainMetadataMap[utils.AnvilChainId].ELDelegationManagerAddress
config.ELDelegationManagerAddress = common.ChainMetadataMap[utils.AnvilChainId].ELDelegationManagerAddress
}

// Prompt for signer type
Expand Down
14 changes: 12 additions & 2 deletions pkg/rewards/claim.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func readAndValidateClaimConfig(cCtx *cli.Context, logger logging.Logger) (*Clai

var err error
if common.IsEmptyString(rewardsCoordinatorAddress) {
rewardsCoordinatorAddress, err = utils.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network))
rewardsCoordinatorAddress, err = common.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -351,7 +351,7 @@ func readAndValidateClaimConfig(cCtx *cli.Context, logger logging.Logger) (*Clai

// If empty get from utils
if common.IsEmptyString(proofStoreBaseURL) {
proofStoreBaseURL = utils.GetProofStoreBaseURL(network)
proofStoreBaseURL = getProofStoreBaseURL(network)

// If still empty return error
if common.IsEmptyString(proofStoreBaseURL) {
Expand Down Expand Up @@ -397,6 +397,16 @@ func readAndValidateClaimConfig(cCtx *cli.Context, logger logging.Logger) (*Clai
}, nil
}

func getProofStoreBaseURL(network string) string {
chainId := utils.NetworkNameToChainId(network)
chainMetadata, ok := common.ChainMetadataMap[chainId.Int64()]
if !ok {
return ""
} else {
return chainMetadata.ProofStoreBaseURL
}
}

func getEnvFromNetwork(network string) string {
switch network {
case utils.HoleskyNetworkName:
Expand Down
2 changes: 1 addition & 1 deletion pkg/rewards/setclaimer.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func readAndValidateSetClaimerConfig(cCtx *cli.Context, logger logging.Logger) (
rewardsCoordinatorAddress := cCtx.String(RewardsCoordinatorAddressFlag.Name)
var err error
if common.IsEmptyString(rewardsCoordinatorAddress) {
rewardsCoordinatorAddress, err = utils.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network))
rewardsCoordinatorAddress, err = common.GetRewardCoordinatorAddress(utils.NetworkNameToChainId(network))
if err != nil {
return nil, err
}
Expand Down
50 changes: 0 additions & 50 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,14 @@ package utils
import (
"bufio"
"errors"
"fmt"
"log"
"math/big"
"os"
"path/filepath"

"github.com/Layr-Labs/eigenlayer-cli/pkg/types"

"gopkg.in/yaml.v2"
)

var ChainMetadataMap = map[int64]types.ChainMetadata{
MainnetChainId: {
BlockExplorerUrl: "https://etherscan.io/tx",
ELDelegationManagerAddress: "0x39053D51B77DC0d36036Fc1fCc8Cb819df8Ef37A",
ELAVSDirectoryAddress: "0x135dda560e946695d6f155dacafc6f1f25c1f5af",
ELRewardsCoordinatorAddress: "0x7750d328b314EfFa365A0402CcfD489B80B0adda",
WebAppUrl: "https://app.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-mainnet-ethereum.s3.amazonaws.com",
},
HoleskyChainId: {
BlockExplorerUrl: "https://holesky.etherscan.io/tx",
ELDelegationManagerAddress: "0xA44151489861Fe9e3055d95adC98FbD462B948e7",
ELAVSDirectoryAddress: "0x055733000064333CaDDbC92763c58BF0192fFeBf",
ELRewardsCoordinatorAddress: "0xAcc1fb458a1317E886dB376Fc8141540537E68fE",
WebAppUrl: "https://holesky.eigenlayer.xyz/operator",
ProofStoreBaseURL: "https://eigenlabs-rewards-testnet-holesky.s3.amazonaws.com",
},
AnvilChainId: {
BlockExplorerUrl: "",
ELDelegationManagerAddress: "0xDc64a140Aa3E981100a9becA4E685f962f0cF6C9",
ELAVSDirectoryAddress: "0x0165878A594ca255338adfa4d48449f69242Eb8F",
ELRewardsCoordinatorAddress: "0x610178dA211FEF7D417bC0e6FeD39F05609AD788",
WebAppUrl: "",
ProofStoreBaseURL: "",
},
}

func GetRewardCoordinatorAddress(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.ELRewardsCoordinatorAddress, nil
}
}

func ChainIdToNetworkName(chainId int64) string {
switch chainId {
case MainnetChainId:
Expand All @@ -77,16 +37,6 @@ func NetworkNameToChainId(networkName string) *big.Int {
}
}

func GetProofStoreBaseURL(network string) string {
chainId := NetworkNameToChainId(network)
chainMetadata, ok := ChainMetadataMap[chainId.Int64()]
if !ok {
return ""
} else {
return chainMetadata.ProofStoreBaseURL
}
}

func ReadYamlConfig(path string, o interface{}) error {
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
log.Fatal("Path ", path, " does not exist")
Expand Down

0 comments on commit 3b188c1

Please sign in to comment.