From 9985122d81feec92fb3970dd7fadf0a592b7d226 Mon Sep 17 00:00:00 2001 From: gpabst Date: Thu, 12 Dec 2024 14:09:47 -0500 Subject: [PATCH] feat: convenience methods to get/set operator PI split --- chainio/clients/elcontracts/reader.go | 17 +++++++++++++++++ chainio/clients/elcontracts/writer.go | 27 +++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/chainio/clients/elcontracts/reader.go b/chainio/clients/elcontracts/reader.go index 9cff4d93..410c972f 100644 --- a/chainio/clients/elcontracts/reader.go +++ b/chainio/clients/elcontracts/reader.go @@ -354,3 +354,20 @@ func (r *ChainReader) GetOperatorAVSSplit( return split, nil } + +func (r *ChainReader) GetOperatorPISplit( + ctx context.Context, + operator gethcommon.Address, +) (uint16, error) { + if r.rewardsCoordinator == nil { + return 0, errors.New("RewardsCoordinator contract not provided") + } + + split, err := r.rewardsCoordinator.GetOperatorPISplit(&bind.CallOpts{Context: ctx}, operator) + + if err != nil { + return 0, err + } + + return split, nil +} diff --git a/chainio/clients/elcontracts/writer.go b/chainio/clients/elcontracts/writer.go index e8b43cf2..a4e45a81 100644 --- a/chainio/clients/elcontracts/writer.go +++ b/chainio/clients/elcontracts/writer.go @@ -385,6 +385,33 @@ func (w *ChainWriter) SetOperatorAVSSplit( return receipt, nil } +func (w *ChainWriter) SetOperatorPISplit( + ctx context.Context, + operator gethcommon.Address, + split uint16, + waitForReceipt bool, +) (*gethtypes.Receipt, error) { + if w.rewardsCoordinator == nil { + return nil, errors.New("RewardsCoordinator contract not provided") + } + + noSendTxOpts, err := w.txMgr.GetNoSendTxOpts() + if err != nil { + return nil, utils.WrapError("failed to get no send tx opts", err) + } + + tx, err := w.rewardsCoordinator.SetOperatorPISplit(noSendTxOpts, operator, split) + if err != nil { + return nil, utils.WrapError("failed to create SetOperatorAVSSplit tx", err) + } + receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt) + if err != nil { + return nil, utils.WrapError("failed to send tx", err) + } + + return receipt, nil +} + func (w *ChainWriter) ProcessClaims( ctx context.Context, claims []rewardscoordinator.IRewardsCoordinatorRewardsMerkleClaim,