Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReadYamlConfig fixed #102

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/actions/deposit_into_strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cli/actions/print_operator_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions cli/actions/register_operator_with_avs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions cli/actions/register_operator_with_eigenlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
}
Expand Down
50 changes: 50 additions & 0 deletions common/read_config.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 3 additions & 2 deletions core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -69,15 +70,15 @@ 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
credibleSquaringDeploymentFilePath := ctx.GlobalString(CredibleSquaringDeploymentFileFlag.Name)
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 {
Expand Down
5 changes: 2 additions & 3 deletions operator/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
Expand Down
6 changes: 5 additions & 1 deletion operator/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
11 changes: 7 additions & 4 deletions plugin/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down
Loading