Skip to content

Commit

Permalink
separate operator details and metadata uri update (#269)
Browse files Browse the repository at this point in the history
* refactor writer functions

* mocks and format
  • Loading branch information
shrimalmadhur authored Jun 19, 2024
1 parent d74457d commit a6f77e8
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
3 changes: 2 additions & 1 deletion chainio/clients/avsregistry/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
35 changes: 24 additions & 11 deletions chainio/clients/elcontracts/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions chainio/mocks/elContractsWriter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/egnkey/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
11 changes: 9 additions & 2 deletions signerv2/kms_signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit a6f77e8

Please sign in to comment.