Skip to content

Commit aceafed

Browse files
authored
Merge pull request #102 from Layr-Labs/fix_read_config
ReadYamlConfig fixed
2 parents 2a67cca + c08f8f7 commit aceafed

File tree

10 files changed

+81
-22
lines changed

10 files changed

+81
-22
lines changed

cli/actions/deposit_into_strategy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"log"
77
"math/big"
88

9-
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
9+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
1010
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
1111
"github.com/Layr-Labs/incredible-squaring-avs/operator"
1212
"github.com/Layr-Labs/incredible-squaring-avs/types"
@@ -18,7 +18,7 @@ func DepositIntoStrategy(ctx *cli.Context) error {
1818

1919
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
2020
nodeConfig := types.NodeConfig{}
21-
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
21+
err := commonincredible.ReadYamlConfig(configPath, &nodeConfig)
2222
if err != nil {
2323
return err
2424
}

cli/actions/print_operator_status.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"encoding/json"
55
"log"
66

7-
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
7+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
88
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
99
"github.com/Layr-Labs/incredible-squaring-avs/operator"
1010
"github.com/Layr-Labs/incredible-squaring-avs/types"
@@ -15,7 +15,7 @@ func PrintOperatorStatus(ctx *cli.Context) error {
1515

1616
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
1717
nodeConfig := types.NodeConfig{}
18-
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
18+
err := commonincredible.ReadYamlConfig(configPath, &nodeConfig)
1919
if err != nil {
2020
return err
2121
}

cli/actions/register_operator_with_avs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77

88
sdkecdsa "github.com/Layr-Labs/eigensdk-go/crypto/ecdsa"
9-
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
9+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
1010
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
1111
"github.com/Layr-Labs/incredible-squaring-avs/operator"
1212
"github.com/Layr-Labs/incredible-squaring-avs/types"
@@ -17,7 +17,7 @@ func RegisterOperatorWithAvs(ctx *cli.Context) error {
1717

1818
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
1919
nodeConfig := types.NodeConfig{}
20-
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
20+
err := commonincredible.ReadYamlConfig(configPath, &nodeConfig)
2121
if err != nil {
2222
return err
2323
}

cli/actions/register_operator_with_eigenlayer.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package actions
22

33
import (
44
"encoding/json"
5-
"github.com/urfave/cli"
65
"log"
76

8-
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
7+
"github.com/urfave/cli"
8+
9+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
910
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
1011
"github.com/Layr-Labs/incredible-squaring-avs/operator"
1112
"github.com/Layr-Labs/incredible-squaring-avs/types"
@@ -15,7 +16,7 @@ func RegisterOperatorWithEigenlayer(ctx *cli.Context) error {
1516

1617
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
1718
nodeConfig := types.NodeConfig{}
18-
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
19+
err := commonincredible.ReadYamlConfig(configPath, &nodeConfig)
1920
if err != nil {
2021
return err
2122
}

common/read_config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package common
2+
3+
import (
4+
"encoding/json"
5+
"errors"
6+
"log"
7+
"os"
8+
"path/filepath"
9+
10+
"gopkg.in/yaml.v3"
11+
)
12+
13+
func ReadYamlConfig(path string, o interface{}) error {
14+
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
15+
log.Fatal("Path ", path, " does not exist")
16+
}
17+
b, err := ReadFile(path)
18+
if err != nil {
19+
return err
20+
}
21+
22+
err = yaml.Unmarshal(b, o)
23+
if err != nil {
24+
log.Fatalf("unable to parse file with error %#v", err)
25+
}
26+
27+
return nil
28+
}
29+
30+
func ReadFile(path string) ([]byte, error) {
31+
b, err := os.ReadFile(filepath.Clean(path))
32+
if err != nil {
33+
return nil, err
34+
}
35+
return b, nil
36+
}
37+
38+
func ReadJsonConfig(path string, o interface{}) error {
39+
b, err := ReadFile(path)
40+
if err != nil {
41+
return err
42+
}
43+
44+
err = json.Unmarshal(b, o)
45+
if err != nil {
46+
log.Fatalf("unable to parse file with error %#v", err)
47+
}
48+
49+
return nil
50+
}

core/config/config.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
1616
sdklogging "github.com/Layr-Labs/eigensdk-go/logging"
1717
"github.com/Layr-Labs/eigensdk-go/signerv2"
18+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
1819
"github.com/ethereum/go-ethereum/ethclient"
1920

2021
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
@@ -69,15 +70,15 @@ func NewConfig(ctx *cli.Context) (*Config, error) {
6970
var configRaw ConfigRaw
7071
configFilePath := ctx.GlobalString(ConfigFileFlag.Name)
7172
if configFilePath != "" {
72-
sdkutils.ReadYamlConfig(configFilePath, &configRaw)
73+
commonincredible.ReadYamlConfig(configFilePath, &configRaw)
7374
}
7475

7576
var credibleSquaringDeploymentRaw IncredibleSquaringDeploymentRaw
7677
credibleSquaringDeploymentFilePath := ctx.GlobalString(CredibleSquaringDeploymentFileFlag.Name)
7778
if _, err := os.Stat(credibleSquaringDeploymentFilePath); errors.Is(err, os.ErrNotExist) {
7879
panic("Path " + credibleSquaringDeploymentFilePath + " does not exist")
7980
}
80-
sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw)
81+
commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw)
8182

8283
logger, err := sdklogging.NewZapLogger(configRaw.Environment)
8384
if err != nil {

operator/cmd/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import (
88

99
"github.com/urfave/cli"
1010

11+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
1112
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
1213
"github.com/Layr-Labs/incredible-squaring-avs/operator"
1314
"github.com/Layr-Labs/incredible-squaring-avs/types"
14-
15-
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
1615
)
1716

1817
func main() {
@@ -34,7 +33,7 @@ func operatorMain(ctx *cli.Context) error {
3433
log.Println("Initializing Operator")
3534
configPath := ctx.GlobalString(config.ConfigFileFlag.Name)
3635
nodeConfig := types.NodeConfig{}
37-
err := sdkutils.ReadYamlConfig(configPath, &nodeConfig)
36+
err := commonincredible.ReadYamlConfig(configPath, &nodeConfig)
3837
if err != nil {
3938
return err
4039
}

operator/registration.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func (o *Operator) RegisterOperatorWithEigenlayer() error {
6363
}
6464

6565
func (o *Operator) DepositIntoStrategy(strategyAddr common.Address, amount *big.Int) error {
66-
_, tokenAddr, err := o.eigenlayerReader.GetStrategyAndUnderlyingToken(&bind.CallOpts{}, strategyAddr)
66+
_, tokenAddr, err := o.eigenlayerReader.GetStrategyAndUnderlyingToken(nil, strategyAddr)
6767
if err != nil {
6868
o.logger.Error("Failed to fetch strategy contract", "err", err)
6969
return err
@@ -74,6 +74,10 @@ func (o *Operator) DepositIntoStrategy(strategyAddr common.Address, amount *big.
7474
return err
7575
}
7676
txOpts, err := o.avsWriter.TxMgr.GetNoSendTxOpts()
77+
if err != nil {
78+
o.logger.Errorf("Error in GetNoSendTxOpts")
79+
return err
80+
}
7781
tx, err := contractErc20Mock.Mint(txOpts, o.operatorAddr, amount)
7882
if err != nil {
7983
o.logger.Errorf("Error assembling Mint tx")

plugin/cmd/main.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@ import (
1717
"github.com/Layr-Labs/eigensdk-go/logging"
1818
"github.com/Layr-Labs/eigensdk-go/signerv2"
1919
sdktypes "github.com/Layr-Labs/eigensdk-go/types"
20-
"github.com/Layr-Labs/eigensdk-go/utils"
20+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
2121
"github.com/Layr-Labs/incredible-squaring-avs/core/chainio"
2222
"github.com/Layr-Labs/incredible-squaring-avs/types"
23-
"github.com/ethereum/go-ethereum/accounts/abi/bind"
2423
"github.com/ethereum/go-ethereum/common"
2524
"github.com/ethereum/go-ethereum/ethclient"
2625
"github.com/urfave/cli"
@@ -86,7 +85,7 @@ func plugin(ctx *cli.Context) {
8685
configPath := ctx.GlobalString(ConfigFileFlag.Name)
8786

8887
avsConfig := types.NodeConfig{}
89-
err := utils.ReadYamlConfig(configPath, &avsConfig)
88+
err := commonincredible.ReadYamlConfig(configPath, &avsConfig)
9089
if err != nil {
9190
fmt.Println(err)
9291
return
@@ -134,6 +133,10 @@ func plugin(ctx *cli.Context) {
134133
return
135134
}
136135
clients, err := sdkclients.BuildAll(buildClientConfig, operatorEcdsaPrivateKey, logger)
136+
if err != nil {
137+
fmt.Println(err)
138+
return
139+
}
137140
avsReader, err := chainio.BuildAvsReader(
138141
common.HexToAddress(avsConfig.AVSRegistryCoordinatorAddress),
139142
common.HexToAddress(avsConfig.OperatorStateRetrieverAddress),
@@ -201,7 +204,7 @@ func plugin(ctx *cli.Context) {
201204
return
202205
}
203206
strategyAddr := common.HexToAddress(ctx.GlobalString(StrategyAddrFlag.Name))
204-
_, tokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken(&bind.CallOpts{}, strategyAddr)
207+
_, tokenAddr, err := clients.ElChainReader.GetStrategyAndUnderlyingToken(nil, strategyAddr)
205208
if err != nil {
206209
logger.Error("Failed to fetch strategy contract", "err", err)
207210
return

tests/integration/integration_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/Layr-Labs/eigensdk-go/signerv2"
1818
sdkutils "github.com/Layr-Labs/eigensdk-go/utils"
1919
"github.com/Layr-Labs/incredible-squaring-avs/aggregator"
20+
commonincredible "github.com/Layr-Labs/incredible-squaring-avs/common"
2021
"github.com/Layr-Labs/incredible-squaring-avs/core/chainio"
2122
"github.com/Layr-Labs/incredible-squaring-avs/core/config"
2223
"github.com/Layr-Labs/incredible-squaring-avs/operator"
@@ -48,13 +49,13 @@ func TestIntegration(t *testing.T) {
4849
/* Prepare the config file for aggregator */
4950
var aggConfigRaw config.ConfigRaw
5051
aggConfigFilePath := "../../config-files/aggregator.yaml"
51-
sdkutils.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw)
52+
commonincredible.ReadYamlConfig(aggConfigFilePath, &aggConfigRaw)
5253
aggConfigRaw.EthRpcUrl = "http://" + anvilEndpoint
5354
aggConfigRaw.EthWsUrl = "ws://" + anvilEndpoint
5455

5556
var credibleSquaringDeploymentRaw config.IncredibleSquaringDeploymentRaw
5657
credibleSquaringDeploymentFilePath := "../../contracts/script/output/31337/credible_squaring_avs_deployment_output.json"
57-
sdkutils.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw)
58+
commonincredible.ReadJsonConfig(credibleSquaringDeploymentFilePath, &credibleSquaringDeploymentRaw)
5859

5960
logger, err := sdklogging.NewZapLogger(aggConfigRaw.Environment)
6061
if err != nil {
@@ -115,7 +116,7 @@ func TestIntegration(t *testing.T) {
115116
/* Prepare the config file for operator */
116117
nodeConfig := types.NodeConfig{}
117118
nodeConfigFilePath := "../../config-files/operator.anvil.yaml"
118-
err = sdkutils.ReadYamlConfig(nodeConfigFilePath, &nodeConfig)
119+
err = commonincredible.ReadYamlConfig(nodeConfigFilePath, &nodeConfig)
119120
if err != nil {
120121
t.Fatalf("Failed to read yaml config: %s", err.Error())
121122
}

0 commit comments

Comments
 (0)