Skip to content

Commit

Permalink
[HotWallet] Implement Fireblocks TxSender (#131)
Browse files Browse the repository at this point in the history
* more methods in fireblocks client

* add fireblocks txsender
  • Loading branch information
ian-shim authored Feb 27, 2024
1 parent 021a26a commit b739bb7
Show file tree
Hide file tree
Showing 14 changed files with 447 additions and 78 deletions.
6 changes: 3 additions & 3 deletions chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type AvsRegistryChainReader struct {
registryCoordinator *regcoord.ContractRegistryCoordinator
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever
stakeRegistry *stakeregistry.ContractStakeRegistry
ethClient eth.EthClient
ethClient eth.Client
}

// forces AvsReader to implement the clients.ReaderInterface interface
Expand All @@ -99,7 +99,7 @@ func NewAvsRegistryChainReader(
operatorStateRetriever *opstateretriever.ContractOperatorStateRetriever,
stakeRegistry *stakeregistry.ContractStakeRegistry,
logger logging.Logger,
ethClient eth.EthClient,
ethClient eth.Client,
) *AvsRegistryChainReader {
return &AvsRegistryChainReader{
blsApkRegistryAddr: blsApkRegistryAddr,
Expand All @@ -115,7 +115,7 @@ func NewAvsRegistryChainReader(
func BuildAvsRegistryChainReader(
registryCoordinatorAddr gethcommon.Address,
operatorStateRetrieverAddr gethcommon.Address,
ethClient eth.EthClient,
ethClient eth.Client,
logger logging.Logger,
) (*AvsRegistryChainReader, error) {
contractRegistryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
Expand Down
2 changes: 1 addition & 1 deletion chainio/clients/avsregistry/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func NewAvsRegistryChainSubscriber(

func BuildAvsRegistryChainSubscriber(
blsApkRegistryAddr common.Address,
ethWsClient eth.EthClient,
ethWsClient eth.Client,
logger logging.Logger,
) (*AvsRegistryChainSubscriber, error) {
blsapkreg, err := blsapkreg.NewContractBLSApkRegistry(blsApkRegistryAddr, ethWsClient)
Expand Down
6 changes: 3 additions & 3 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type AvsRegistryChainWriter struct {
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry
elReader elcontracts.ELReader
logger logging.Logger
ethClient eth.EthClient
ethClient eth.Client
txMgr txmgr.TxManager
}

Expand All @@ -93,7 +93,7 @@ func NewAvsRegistryChainWriter(
blsApkRegistry *blsapkregistry.ContractBLSApkRegistry,
elReader elcontracts.ELReader,
logger logging.Logger,
ethClient eth.EthClient,
ethClient eth.Client,
txMgr txmgr.TxManager,
) (*AvsRegistryChainWriter, error) {
return &AvsRegistryChainWriter{
Expand All @@ -113,7 +113,7 @@ func BuildAvsRegistryChainWriter(
registryCoordinatorAddr gethcommon.Address,
operatorStateRetrieverAddr gethcommon.Address,
logger logging.Logger,
ethClient eth.EthClient,
ethClient eth.Client,
txMgr txmgr.TxManager,
) (*AvsRegistryChainWriter, error) {
registryCoordinator, err := regcoord.NewContractRegistryCoordinator(registryCoordinatorAddr, ethClient)
Expand Down
12 changes: 6 additions & 6 deletions chainio/clients/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ type Clients struct {
AvsRegistryChainWriter *avsregistry.AvsRegistryChainWriter
ElChainReader *elcontracts.ELChainReader
ElChainWriter *elcontracts.ELChainWriter
EthHttpClient *eth.Client
EthWsClient *eth.Client
EthHttpClient eth.Client
EthWsClient eth.Client
Metrics *metrics.EigenMetrics // exposes main avs node spec metrics that need to be incremented by avs code and used to start the metrics server
PrometheusRegistry *prometheus.Registry // Used if avs teams need to register avs-specific metrics
}
Expand All @@ -68,7 +68,7 @@ func BuildAll(
return nil, types.WrapError(errors.New("Failed to create Eth WS client"), err)
}

txSender, err := txsender.NewPrivateKeyTxSender(config.EthHttpUrl, big.NewInt(1), ecdsaPrivateKey, logger)
txSender, err := txsender.NewPrivateKeyTxSender(ethHttpClient, big.NewInt(1), ecdsaPrivateKey, logger)
if err != nil {
return nil, types.WrapError(errors.New("Failed to create transaction sender"), err)
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func BuildAll(
}

func (config *BuildAllConfig) buildElClients(
ethHttpClient eth.EthClient,
ethHttpClient eth.Client,
txMgr txmgr.TxManager,
logger logging.Logger,
eigenMetrics *metrics.EigenMetrics,
Expand Down Expand Up @@ -182,8 +182,8 @@ func (config *BuildAllConfig) buildElClients(

func (config *BuildAllConfig) buildAvsClients(
elReader elcontracts.ELReader,
ethHttpClient eth.EthClient,
ethWsClient eth.EthClient,
ethHttpClient eth.Client,
ethWsClient eth.Client,
txMgr txmgr.TxManager,
logger logging.Logger,
) (*avsregistry.AvsRegistryChainReader, *avsregistry.AvsRegistryChainSubscriber, *avsregistry.AvsRegistryChainWriter, error) {
Expand Down
6 changes: 3 additions & 3 deletions chainio/clients/elcontracts/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type ELChainReader struct {
delegationManager delegationmanager.ContractDelegationManagerCalls
strategyManager strategymanager.ContractStrategyManagerCalls
avsDirectory avsdirectory.ContractAVSDirectoryCalls
ethClient eth.EthClient
ethClient eth.Client
}

// forces EthReader to implement the chainio.Reader interface
Expand All @@ -79,7 +79,7 @@ func NewELChainReader(
strategyManager strategymanager.ContractStrategyManagerCalls,
avsDirectory avsdirectory.ContractAVSDirectoryCalls,
logger logging.Logger,
ethClient eth.EthClient,
ethClient eth.Client,
) *ELChainReader {
return &ELChainReader{
slasher: slasher,
Expand All @@ -94,7 +94,7 @@ func NewELChainReader(
func BuildELChainReader(
delegationManagerAddr gethcommon.Address,
avsDirectoryAddr gethcommon.Address,
ethClient eth.EthClient,
ethClient eth.Client,
logger logging.Logger,
) (*ELChainReader, error) {
elContractBindings, err := chainioutils.NewEigenlayerContractBindings(
Expand Down
6 changes: 3 additions & 3 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ELChainWriter struct {
strategyManager strategymanager.ContractStrategyManagerTransacts
strategyManagerAddr gethcommon.Address
elChainReader ELReader
ethClient eth.EthClient
ethClient eth.Client
logger logging.Logger
txMgr txmgr.TxManager
}
Expand All @@ -53,7 +53,7 @@ func NewELChainWriter(
strategyManager strategymanager.ContractStrategyManagerTransacts,
strategyManagerAddr gethcommon.Address,
elChainReader ELReader,
ethClient eth.EthClient,
ethClient eth.Client,
logger logging.Logger,
eigenMetrics metrics.Metrics,
txMgr txmgr.TxManager,
Expand All @@ -73,7 +73,7 @@ func NewELChainWriter(
func BuildELChainWriter(
delegationManagerAddr gethcommon.Address,
avsDirectoryAddr gethcommon.Address,
ethClient eth.EthClient,
ethClient eth.Client,
logger logging.Logger,
eigenMetrics metrics.Metrics,
txMgr txmgr.TxManager,
Expand Down
43 changes: 3 additions & 40 deletions chainio/clients/eth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ package eth
import (
"context"
"math/big"
"time"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
)

type gethClient interface {
type Client interface {
ChainID(ctx context.Context) (*big.Int, error)
BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
BlockByHash(ctx context.Context, hash common.Hash) (*types.Block, error)
Expand Down Expand Up @@ -53,42 +52,6 @@ type gethClient interface {
TransactionSender(ctx context.Context, tx *types.Transaction, block common.Hash, index uint) (common.Address, error)
}

// EthClient is modified interface with additional custom methods
type EthClient interface {
gethClient

WaitForTransactionReceipt(
ctx context.Context,
txHash common.Hash,
) *types.Receipt
}

// Client is a wrapper around geth's ethclient.Client struct, that adds a WaitForTransactionReceipt convenience method.
type Client struct {
*ethclient.Client
}

var _ EthClient = (*Client)(nil)

func NewClient(rpcAddress string) (*Client, error) {
client, err := ethclient.Dial(rpcAddress)
if err != nil {
return nil, err
}
return &Client{client}, nil
}

func (e *Client) WaitForTransactionReceipt(
ctx context.Context,
txHash common.Hash,
) *types.Receipt {
for {
// verifying transaction receipt
receipt, err := e.Client.TransactionReceipt(ctx, txHash)
if err != nil {
time.Sleep(2 * time.Second)
} else {
return receipt
}
}
func NewClient(rpcAddress string) (Client, error) {
return ethclient.Dial(rpcAddress)
}
2 changes: 1 addition & 1 deletion chainio/clients/eth/instrumented_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type InstrumentedClient struct {
clientAndVersion string
}

var _ EthClient = (*InstrumentedClient)(nil)
var _ Client = (*InstrumentedClient)(nil)

func NewInstrumentedClient(rpcAddress string, rpcCallsCollector *rpccalls.Collector) (*InstrumentedClient, error) {
client, err := ethclient.Dial(rpcAddress)
Expand Down
18 changes: 10 additions & 8 deletions chainio/clients/fireblocks/list_vault_accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@ import (
"strings"
)

type Asset struct {
ID AssetID `json:"id"`
Total string `json:"total"`
Balance string `json:"balance"`
Available string `json:"available"`
}

type VaultAccount struct {
ID string `json:"id"`
Name string `json:"name"`
Assets []struct {
ID AssetID `json:"id"`
Total string `json:"total"`
Balance string `json:"balance"`
Available string `json:"available"`
} `json:"assets"`
ID string `json:"id"`
Name string `json:"name"`
Assets []Asset `json:"assets"`
}

func (f *client) ListVaultAccounts(ctx context.Context) ([]VaultAccount, error) {
Expand Down
Loading

0 comments on commit b739bb7

Please sign in to comment.