From a6f77e8c242d487466c0bbc1409f672241b6fa53 Mon Sep 17 00:00:00 2001 From: Madhur Shrimal Date: Tue, 18 Jun 2024 22:00:47 -0500 Subject: [PATCH] separate operator details and metadata uri update (#269) * refactor writer functions * mocks and format --- chainio/clients/avsregistry/reader.go | 3 ++- chainio/clients/elcontracts/writer.go | 35 ++++++++++++++++++--------- chainio/mocks/elContractsWriter.go | 15 ++++++++++++ cmd/egnkey/main.go | 2 +- signerv2/kms_signer.go | 11 +++++++-- 5 files changed, 51 insertions(+), 15 deletions(-) diff --git a/chainio/clients/avsregistry/reader.go b/chainio/clients/avsregistry/reader.go index 20e2fead..a7976ff0 100644 --- a/chainio/clients/avsregistry/reader.go +++ b/chainio/clients/avsregistry/reader.go @@ -21,7 +21,8 @@ import ( stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry" ) -// different node providers have different eth_getLogs range limits. 10k is an arbitrary choice that should work for most +// DefaultQueryBlockRange different node providers have different eth_getLogs range limits. +// 10k is an arbitrary choice that should work for most var DefaultQueryBlockRange = big.NewInt(10_000) type AvsRegistryReader interface { diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index 4671590f..06396b56 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -5,27 +5,32 @@ import ( "errors" "math/big" - "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" "github.com/ethereum/go-ethereum/accounts/abi/bind" gethcommon "github.com/ethereum/go-ethereum/common" gethtypes "github.com/ethereum/go-ethereum/core/types" "github.com/Layr-Labs/eigensdk-go/chainio/clients/eth" + "github.com/Layr-Labs/eigensdk-go/chainio/txmgr" chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils" - "github.com/Layr-Labs/eigensdk-go/logging" - "github.com/Layr-Labs/eigensdk-go/metrics" - "github.com/Layr-Labs/eigensdk-go/types" - delegationmanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/DelegationManager" slasher "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ISlasher" strategymanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StrategyManager" + "github.com/Layr-Labs/eigensdk-go/logging" + "github.com/Layr-Labs/eigensdk-go/metrics" + "github.com/Layr-Labs/eigensdk-go/types" ) type ELWriter interface { + // RegisterAsOperator registers an operator onchain. RegisterAsOperator(ctx context.Context, operator types.Operator) (*gethtypes.Receipt, error) + // UpdateOperatorDetails updates the operator details onchain. + // This doesn't update the metadata URI. Use UpdateMetadataURI for that. UpdateOperatorDetails(ctx context.Context, operator types.Operator) (*gethtypes.Receipt, error) + // UpdateMetadataURI updates the operator metadata URI onchain + UpdateMetadataURI(ctx context.Context, uri string) (*gethtypes.Receipt, error) + // DepositERC20IntoStrategy deposits ERC20 tokens into a strategy contract. DepositERC20IntoStrategy( ctx context.Context, @@ -162,28 +167,36 @@ func (w *ELChainWriter) UpdateOperatorDetails( return nil, errors.New("failed to send tx with err: " + err.Error()) } w.logger.Info( - "successfully updated operator metadata URI", + "successfully updated operator details", "txHash", receipt.TxHash.String(), "operator", operator.Address, ) - tx, err = w.delegationManager.UpdateOperatorMetadataURI(noSendTxOpts, operator.MetadataUrl) + return receipt, nil +} + +func (w *ELChainWriter) UpdateMetadataURI(ctx context.Context, uri string) (*gethtypes.Receipt, error) { + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() + if err != nil { + return nil, err + } + + tx, err := w.delegationManager.UpdateOperatorMetadataURI(noSendTxOpts, uri) if err != nil { return nil, err } - receipt, err = w.txMgr.Send(ctx, tx) + receipt, err := w.txMgr.Send(ctx, tx) if err != nil { return nil, errors.New("failed to send tx with err: " + err.Error()) } w.logger.Info( - "successfully updated operator details", + "successfully updated operator metadata uri", "txHash", receipt.TxHash.String(), - "operator", - operator.Address, ) + return receipt, nil } diff --git a/chainio/mocks/elContractsWriter.go b/chainio/mocks/elContractsWriter.go index cd773d00..5b5af23d 100644 --- a/chainio/mocks/elContractsWriter.go +++ b/chainio/mocks/elContractsWriter.go @@ -73,6 +73,21 @@ func (mr *MockELWriterMockRecorder) RegisterAsOperator(arg0, arg1 any) *gomock.C return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "RegisterAsOperator", reflect.TypeOf((*MockELWriter)(nil).RegisterAsOperator), arg0, arg1) } +// UpdateMetadataURI mocks base method. +func (m *MockELWriter) UpdateMetadataURI(arg0 context.Context, arg1 string) (*types0.Receipt, error) { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "UpdateMetadataURI", arg0, arg1) + ret0, _ := ret[0].(*types0.Receipt) + ret1, _ := ret[1].(error) + return ret0, ret1 +} + +// UpdateMetadataURI indicates an expected call of UpdateMetadataURI. +func (mr *MockELWriterMockRecorder) UpdateMetadataURI(arg0, arg1 any) *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "UpdateMetadataURI", reflect.TypeOf((*MockELWriter)(nil).UpdateMetadataURI), arg0, arg1) +} + // UpdateOperatorDetails mocks base method. func (m *MockELWriter) UpdateOperatorDetails(arg0 context.Context, arg1 types.Operator) (*types0.Receipt, error) { m.ctrl.T.Helper() diff --git a/cmd/egnkey/main.go b/cmd/egnkey/main.go index bc2bb284..956a0f68 100644 --- a/cmd/egnkey/main.go +++ b/cmd/egnkey/main.go @@ -4,8 +4,8 @@ import ( "fmt" "os" - "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/operatorid" "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/generate" + "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/operatorid" "github.com/Layr-Labs/eigensdk-go/cmd/egnkey/store" "github.com/urfave/cli/v2" ) diff --git a/signerv2/kms_signer.go b/signerv2/kms_signer.go index 72dcb9f3..93c33f5f 100644 --- a/signerv2/kms_signer.go +++ b/signerv2/kms_signer.go @@ -28,11 +28,18 @@ func NewKMSSigner(ctx context.Context, svc *kms.Client, pk *ecdsa.PublicKey, key // KMSSignerFn returns a SignerFn that uses a KMS key to sign transactions // Heavily taken from https://github.com/welthee/go-ethereum-aws-kms-tx-signer -// It constructs R and S values from KMS, and constructs the recovery id (V) by trying to recover with both 0 and 1 values: +// It constructs R and S values from KMS, and constructs the recovery id (V) by trying to recover with both 0 and 1 +// values: // ref: https://github.com/aws-samples/aws-kms-ethereum-accounts?tab=readme-ov-file#the-recovery-identifier-v // // Its V value is 0/1 instead of 27/28 because `types.LatestSignerForChainID` expects 0/1 which turns it into 27/28 -func KMSSignerFn(ctx context.Context, svc *kms.Client, pk *ecdsa.PublicKey, keyId string, chainID *big.Int) (bind.SignerFn, error) { +func KMSSignerFn( + ctx context.Context, + svc *kms.Client, + pk *ecdsa.PublicKey, + keyId string, + chainID *big.Int, +) (bind.SignerFn, error) { if chainID == nil { return nil, errors.New("chainID is required") }