Skip to content

Commit

Permalink
fireblocks config parse helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed May 2, 2024
1 parent 7117d59 commit 1851b74
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 79 deletions.
57 changes: 57 additions & 0 deletions common/fireblocks_config.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package common

import (
"context"
"errors"
"fmt"
"time"

"github.com/Layr-Labs/eigenda/common/aws/secretmanager"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks"
walletsdk "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/logging"
gcommon "github.com/ethereum/go-ethereum/common"
"github.com/urfave/cli"
)

Expand Down Expand Up @@ -94,3 +102,52 @@ func ReadFireblocksCLIConfig(ctx *cli.Context, flagPrefix string) FireblocksConf
APITimeout: ctx.GlobalDuration(PrefixFlag(flagPrefix, FireblocksAPITimeoutFlagName)),
}
}

func NewFireblocksWallet(config *FireblocksConfig, ethClient EthClient, logger logging.Logger) (walletsdk.Wallet, error) {
if config.Disable {
logger.Info("Fireblocks wallet disabled")
return nil, fmt.Errorf("fireblocks wallet is disabled")
}

validConfigflag := len(config.APIKeyName) > 0 &&
len(config.SecretKeyName) > 0 &&
len(config.BaseURL) > 0 &&
len(config.VaultAccountName) > 0 &&
len(config.WalletAddress) > 0 &&
len(config.Region) > 0
if !validConfigflag {
return nil, errors.New("fireblocks config is either invalid or incomplete")
}
apiKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.APIKeyName, config.Region)
if err != nil {
return nil, fmt.Errorf("cannot read fireblocks api key %s from secret manager: %w", config.APIKeyName, err)
}
secretKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.SecretKeyName, config.Region)
if err != nil {
return nil, fmt.Errorf("cannot read fireblocks secret key %s from secret manager: %w", config.SecretKeyName, err)
}
fireblocksClient, err := fireblocks.NewClient(
apiKey,
[]byte(secretKey),
config.BaseURL,
config.APITimeout,
logger.With("component", "FireblocksClient"),
)
if err != nil {
return nil, err
}
wallet, err := walletsdk.NewFireblocksWallet(fireblocksClient, ethClient, config.VaultAccountName, logger.With("component", "FireblocksWallet"))
if err != nil {
return nil, err
}
sender, err := wallet.SenderAddress(context.Background())
if err != nil {
return nil, err
}
if sender.Cmp(gcommon.HexToAddress(config.WalletAddress)) != 0 {
return nil, fmt.Errorf("configured wallet address %s does not match derived address %s", config.WalletAddress, sender.Hex())
}
logger.Info("Initialized Fireblocks wallet", "vaultAccountName", config.VaultAccountName, "address", sender.Hex())

return wallet, nil
}
39 changes: 1 addition & 38 deletions disperser/cmd/batcher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigenda/common/aws/s3"
"github.com/Layr-Labs/eigenda/common/aws/secretmanager"
"github.com/Layr-Labs/eigenda/common/geth"
"github.com/Layr-Labs/eigenda/core"
coreeth "github.com/Layr-Labs/eigenda/core/eth"
Expand All @@ -23,7 +22,6 @@ import (
"github.com/Layr-Labs/eigenda/disperser/cmd/batcher/flags"
"github.com/Layr-Labs/eigenda/disperser/common/blobstore"
"github.com/Layr-Labs/eigenda/disperser/encoder"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks"
walletsdk "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/signerv2"
gethcommon "github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -170,45 +168,10 @@ func RunBatcher(ctx *cli.Context) error {
finalizer := batcher.NewFinalizer(config.TimeoutConfig.ChainReadTimeout, config.BatcherConfig.FinalizerInterval, queue, client, rpcClient, config.BatcherConfig.MaxNumRetriesPerBlob, 1000, config.BatcherConfig.FinalizerPoolSize, logger, metrics.FinalizerMetrics)
var wallet walletsdk.Wallet
if !config.FireblocksConfig.Disable {
validConfigflag := len(config.FireblocksConfig.APIKeyName) > 0 &&
len(config.FireblocksConfig.SecretKeyName) > 0 &&
len(config.FireblocksConfig.BaseURL) > 0 &&
len(config.FireblocksConfig.VaultAccountName) > 0 &&
len(config.FireblocksConfig.WalletAddress) > 0 &&
len(config.FireblocksConfig.Region) > 0
if !validConfigflag {
return errors.New("fireblocks config is either invalid or incomplete")
}
apiKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.FireblocksConfig.APIKeyName, config.FireblocksConfig.Region)
if err != nil {
return fmt.Errorf("cannot read fireblocks api key %s from secret manager: %w", config.FireblocksConfig.APIKeyName, err)
}
secretKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.FireblocksConfig.SecretKeyName, config.FireblocksConfig.Region)
if err != nil {
return fmt.Errorf("cannot read fireblocks secret key %s from secret manager: %w", config.FireblocksConfig.SecretKeyName, err)
}
fireblocksClient, err := fireblocks.NewClient(
apiKey,
[]byte(secretKey),
config.FireblocksConfig.BaseURL,
config.FireblocksConfig.APITimeout,
logger.With("component", "FireblocksClient"),
)
wallet, err = common.NewFireblocksWallet(&config.FireblocksConfig, client, logger)
if err != nil {
return err
}
wallet, err = walletsdk.NewFireblocksWallet(fireblocksClient, client, config.FireblocksConfig.VaultAccountName, logger.With("component", "FireblocksWallet"))
if err != nil {
return err
}
sender, err := wallet.SenderAddress(context.Background())
if err != nil {
return err
}
if sender.Cmp(gethcommon.HexToAddress(config.FireblocksConfig.WalletAddress)) != 0 {
return fmt.Errorf("configured wallet address %s does not match derived address %s", config.FireblocksConfig.WalletAddress, sender.Hex())
}
logger.Info("Initialized Fireblocks wallet", "vaultAccountName", config.FireblocksConfig.VaultAccountName, "address", sender.Hex())
} else if len(config.EthClientConfig.PrivateKeyString) > 0 {
privateKey, err := crypto.HexToECDSA(config.EthClientConfig.PrivateKeyString)
if err != nil {
Expand Down
42 changes: 1 addition & 41 deletions disperser/cmd/dataapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ import (
"github.com/Layr-Labs/eigenda/common"
"github.com/Layr-Labs/eigenda/common/aws/dynamodb"
"github.com/Layr-Labs/eigenda/common/aws/s3"
"github.com/Layr-Labs/eigenda/common/aws/secretmanager"
"github.com/Layr-Labs/eigenda/common/geth"
coreeth "github.com/Layr-Labs/eigenda/core/eth"
"github.com/Layr-Labs/eigenda/disperser/cmd/dataapi/flags"
"github.com/Layr-Labs/eigenda/disperser/common/blobstore"
"github.com/Layr-Labs/eigenda/disperser/dataapi"
"github.com/Layr-Labs/eigenda/disperser/dataapi/prometheus"
"github.com/Layr-Labs/eigenda/disperser/dataapi/subgraph"
"github.com/Layr-Labs/eigensdk-go/chainio/clients/fireblocks"
walletsdk "github.com/Layr-Labs/eigensdk-go/chainio/clients/wallet"
"github.com/Layr-Labs/eigensdk-go/logging"
"github.com/Layr-Labs/eigensdk-go/signerv2"
Expand Down Expand Up @@ -164,45 +162,7 @@ func RunDataApi(ctx *cli.Context) error {
func getWallet(config Config, ethClient common.EthClient, logger logging.Logger) (walletsdk.Wallet, error) {
var wallet walletsdk.Wallet
if !config.FireblocksConfig.Disable {
validConfigflag := len(config.FireblocksConfig.APIKeyName) > 0 &&
len(config.FireblocksConfig.SecretKeyName) > 0 &&
len(config.FireblocksConfig.BaseURL) > 0 &&
len(config.FireblocksConfig.VaultAccountName) > 0 &&
len(config.FireblocksConfig.WalletAddress) > 0 &&
len(config.FireblocksConfig.Region) > 0
if !validConfigflag {
return nil, errors.New("fireblocks config is either invalid or incomplete")
}
apiKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.FireblocksConfig.APIKeyName, config.FireblocksConfig.Region)
if err != nil {
return nil, fmt.Errorf("cannot read fireblocks api key %s from secret manager: %w", config.FireblocksConfig.APIKeyName, err)
}
secretKey, err := secretmanager.ReadStringFromSecretManager(context.Background(), config.FireblocksConfig.SecretKeyName, config.FireblocksConfig.Region)
if err != nil {
return nil, fmt.Errorf("cannot read fireblocks secret key %s from secret manager: %w", config.FireblocksConfig.SecretKeyName, err)
}
fireblocksClient, err := fireblocks.NewClient(
apiKey,
[]byte(secretKey),
config.FireblocksConfig.BaseURL,
config.FireblocksConfig.APITimeout,
logger.With("component", "FireblocksClient"),
)
if err != nil {
return nil, err
}
wallet, err = walletsdk.NewFireblocksWallet(fireblocksClient, ethClient, config.FireblocksConfig.VaultAccountName, logger.With("component", "FireblocksWallet"))
if err != nil {
return nil, err
}
sender, err := wallet.SenderAddress(context.Background())
if err != nil {
return nil, err
}
if sender.Cmp(gethcommon.HexToAddress(config.FireblocksConfig.WalletAddress)) != 0 {
return nil, fmt.Errorf("configured wallet address %s does not match derived address %s", config.FireblocksConfig.WalletAddress, sender.Hex())
}
logger.Info("Initialized Fireblocks wallet", "vaultAccountName", config.FireblocksConfig.VaultAccountName, "address", sender.Hex())
return common.NewFireblocksWallet(&config.FireblocksConfig, ethClient, logger)
} else if len(config.EthClientConfig.PrivateKeyString) > 0 {
privateKey, err := crypto.HexToECDSA(config.EthClientConfig.PrivateKeyString)
if err != nil {
Expand Down

0 comments on commit 1851b74

Please sign in to comment.