diff --git a/cli/actions/deposit_into_strategy.go b/cli/actions/deposit_into_strategy.go index 0ccf9bdf..94f64bf8 100644 --- a/cli/actions/deposit_into_strategy.go +++ b/cli/actions/deposit_into_strategy.go @@ -6,7 +6,7 @@ import ( "log" "math/big" - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -18,7 +18,7 @@ func DepositIntoStrategy(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/print_operator_status.go b/cli/actions/print_operator_status.go index 88bdcf95..36648170 100644 --- a/cli/actions/print_operator_status.go +++ b/cli/actions/print_operator_status.go @@ -4,7 +4,7 @@ import ( "encoding/json" "log" - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -15,7 +15,7 @@ func PrintOperatorStatus(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/register_operator_with_avs.go b/cli/actions/register_operator_with_avs.go index e2a19342..dfea077b 100644 --- a/cli/actions/register_operator_with_avs.go +++ b/cli/actions/register_operator_with_avs.go @@ -6,7 +6,7 @@ import ( "os" sdkecdsa "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa" - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -17,7 +17,7 @@ func RegisterOperatorWithAvs(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/cli/actions/register_operator_with_eigenlayer.go b/cli/actions/register_operator_with_eigenlayer.go index 53ff3134..786c440b 100644 --- a/cli/actions/register_operator_with_eigenlayer.go +++ b/cli/actions/register_operator_with_eigenlayer.go @@ -2,10 +2,11 @@ package actions import ( "encoding/json" - "github.com/urfave/cli" "log" - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" + "github.com/urfave/cli" + + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" @@ -15,7 +16,7 @@ func RegisterOperatorWithEigenlayer(ctx *cli.Context) error { configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/common/read_config.go b/common/read_config.go new file mode 100644 index 00000000..a7e2cfd7 --- /dev/null +++ b/common/read_config.go @@ -0,0 +1,50 @@ +package common + +import ( + "encoding/json" + "errors" + "log" + "os" + "path/filepath" + + "gopkg.in/yaml.v3" +) + +func ReadYamlConfig(path string, o interface{}) error { + if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) { + log.Fatal("Path ", path, " does not exist") + } + b, err := ReadFile(path) + if err != nil { + return err + } + + err = yaml.Unmarshal(b, o) + if err != nil { + log.Fatalf("unable to parse file with error %#v", err) + } + + return nil +} + +func ReadFile(path string) ([]byte, error) { + b, err := os.ReadFile(filepath.Clean(path)) + if err != nil { + return nil, err + } + return b, nil +} + +func ReadJsonConfig(path string, o interface{}) error { + b, err := ReadFile(path) + if err != nil { + return err + } + + err = json.Unmarshal(b, o) + if err != nil { + log.Fatalf("unable to parse file with error %#v", err) + } + + return nil +} diff --git a/core/config/config.go b/core/config/config.go index 56058a2d..51f94466 100644 --- a/core/config/config.go +++ b/core/config/config.go @@ -15,6 +15,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/crypto/bls" sdklogging "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/ethereum/go-ethereum/ethclient" sdkutils "github.com/Layr-Labs/eigensdk-go/utils" @@ -69,7 +70,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) { var configRaw ConfigRaw configFilePath := ctx.GlobalString(ConfigFileFlag.Name) if configFilePath != "" { - sdkutils.ReadYamlConfig(configFilePath, &configRaw) + commonincredible.ReadYamlConfig(configFilePath, &configRaw) } var credibleSquaringDeploymentRaw IncredibleSquaringDeploymentRaw @@ -77,7 +78,7 @@ func NewConfig(ctx *cli.Context) (*Config, error) { if _, err := os.Stat(credibleSquaringDeploymentFilePath); errors.Is(err, os.ErrNotExist) { panic("Path " + credibleSquaringDeploymentFilePath + " does not exist") } - sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) + commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) logger, err := sdklogging.NewZapLogger(configRaw.Environment) if err != nil { diff --git a/operator/cmd/main.go b/operator/cmd/main.go index d033bfa2..b443c2b0 100644 --- a/operator/cmd/main.go +++ b/operator/cmd/main.go @@ -8,11 +8,10 @@ import ( "github.com/urfave/cli" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" "github.com/Layr-Labs/incredible-squaring-avs/types" - - sdkutils "github.com/Layr-Labs/eigensdk-go/utils" ) func main() { @@ -34,7 +33,7 @@ func operatorMain(ctx *cli.Context) error { log.Println("Initializing Operator") configPath := ctx.GlobalString(config.ConfigFileFlag.Name) nodeConfig := types.NodeConfig{} - err := sdkutils.ReadYamlConfig(configPath, &nodeConfig) + err := commonincredible.ReadYamlConfig(configPath, &nodeConfig) if err != nil { return err } diff --git a/operator/registration.go b/operator/registration.go index a1ddcbb9..23f824fa 100644 --- a/operator/registration.go +++ b/operator/registration.go @@ -63,7 +63,7 @@ func (o *Operator) RegisterOperatorWithEigenlayer() error { } func (o *Operator) DepositIntoStrategy(strategyAddr common.Address, amount *big.Int) error { - _, tokenAddr, err := o.eigenlayerReader.GetStrategyAndUnderlyingToken(&bind.CallOpts{}, strategyAddr) + _, tokenAddr, err := o.eigenlayerReader.GetStrategyAndUnderlyingToken(nil, strategyAddr) if err != nil { o.logger.Error("Failed to fetch strategy contract", "err", err) return err @@ -74,6 +74,10 @@ func (o *Operator) DepositIntoStrategy(strategyAddr common.Address, amount *big. return err } txOpts, err := o.avsWriter.TxMgr.GetNoSendTxOpts() + if err != nil { + o.logger.Errorf("Error in GetNoSendTxOpts") + return err + } tx, err := contractErc20Mock.Mint(txOpts, o.operatorAddr, amount) if err != nil { o.logger.Errorf("Error assembling Mint tx") diff --git a/plugin/cmd/main.go b/plugin/cmd/main.go index f441ed7d..69f149be 100644 --- a/plugin/cmd/main.go +++ b/plugin/cmd/main.go @@ -17,10 +17,9 @@ import ( "github.com/Layr-Labs/eigensdk-go/logging" "github.com/Layr-Labs/eigensdk-go/signerv2" sdktypes "github.com/Layr-Labs/eigensdk-go/types" - "github.com/Layr-Labs/eigensdk-go/utils" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/chainio" "github.com/Layr-Labs/incredible-squaring-avs/types" - "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/ethclient" "github.com/urfave/cli" @@ -86,7 +85,7 @@ func plugin(ctx *cli.Context) { configPath := ctx.GlobalString(ConfigFileFlag.Name) avsConfig := types.NodeConfig{} - err := utils.ReadYamlConfig(configPath, &avsConfig) + err := commonincredible.ReadYamlConfig(configPath, &avsConfig) if err != nil { fmt.Println(err) return @@ -134,6 +133,10 @@ func plugin(ctx *cli.Context) { return } clients, err := sdkclients.BuildAll(buildClientConfig, operatorEcdsaPrivateKey, logger) + if err != nil { + fmt.Println(err) + return + } avsReader, err := chainio.BuildAvsReader( common.HexToAddress(avsConfig.AVSRegistryCoordinatorAddress), common.HexToAddress(avsConfig.OperatorStateRetrieverAddress), @@ -201,7 +204,7 @@ func plugin(ctx *cli.Context) { return } strategyAddr := common.HexToAddress(ctx.GlobalString(StrategyAddrFlag.Name)) - _, tokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken(&bind.CallOpts{}, strategyAddr) + _, tokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken(nil, strategyAddr) if err != nil { logger.Error("Failed to fetch strategy contract", "err", err) return diff --git a/tests/integration/integration_test.go b/tests/integration/integration_test.go index 7f22fa3e..75da7938 100644 --- a/tests/integration/integration_test.go +++ b/tests/integration/integration_test.go @@ -17,6 +17,7 @@ import ( "github.com/Layr-Labs/eigensdk-go/signerv2" sdkutils "github.com/Layr-Labs/eigensdk-go/utils" "github.com/Layr-Labs/incredible-squaring-avs/aggregator" + commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common" "github.com/Layr-Labs/incredible-squaring-avs/core/chainio" "github.com/Layr-Labs/incredible-squaring-avs/core/config" "github.com/Layr-Labs/incredible-squaring-avs/operator" @@ -48,13 +49,13 @@ func TestIntegration(t *testing.T) { /* Prepare the config file for aggregator */ var aggConfigRaw config.ConfigRaw aggConfigFilePath := "../../config-files/aggregator.yaml" - sdkutils.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw) + commonincredible.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw) aggConfigRaw.EthRpcUrl = "http://" + anvilEndpoint aggConfigRaw.EthWsUrl = "ws://" + anvilEndpoint var credibleSquaringDeploymentRaw config.IncredibleSquaringDeploymentRaw credibleSquaringDeploymentFilePath := "../../contracts/script/output/31337/credible_squaring_avs_deployment_output.json" - sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) + commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw) logger, err := sdklogging.NewZapLogger(aggConfigRaw.Environment) if err != nil { @@ -115,7 +116,7 @@ func TestIntegration(t *testing.T) { /* Prepare the config file for operator */ nodeConfig := types.NodeConfig{} nodeConfigFilePath := "../../config-files/operator.anvil.yaml" - err = sdkutils.ReadYamlConfig(nodeConfigFilePath, &nodeConfig) + err = commonincredible.ReadYamlConfig(nodeConfigFilePath, &nodeConfig) if err != nil { t.Fatalf("Failed to read yaml config: %s", err.Error()) }