Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add set operator set params function #539

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,32 @@ func (w *ChainWriter) EjectOperator(
return receipt, nil
}

// Sets the operator set params for the quorum which id matches the quorum number.
// Params consists in a new max operator count and operator churn parameters
// Returns the transaction receipt in case of success.
func (w *ChainWriter) SetOperatorSetParams(
ctx context.Context,
quorumNumber uint8,
operatorSetParams regcoord.ISlashingRegistryCoordinatorTypesOperatorSetParam,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("setting operator set params for quorum ", quorumNumber)

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.SetOperatorSetParams(noSendTxOpts, quorumNumber, operatorSetParams)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetOperatorSetParams tx with err", err.Error())
}
return receipt, nil
}

// Sets the churnApprover as the address received as parameter. The churnApprover's signature is required in
// churn related methods (like churn registration). Returns the receipt of the transaction in case of success.
func (w *ChainWriter) SetChurnApprover(
Expand Down
46 changes: 46 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,52 @@ func TestEjectOperator(t *testing.T) {
require.False(t, isRegisterd)
}

func TestSetOperatorSetParams(t *testing.T) {
// Test set up
clients, anvilHttpEndpoint := testclients.BuildTestClients(t)

contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)

chainWriter := clients.AvsRegistryChainWriter

registryCoordinatorAddress := contractAddrs.RegistryCoordinator
registryCoordinator, err := regcoord.NewContractRegistryCoordinator(
registryCoordinatorAddress,
clients.EthHttpClient,
)
require.NoError(t, err)

// This parameters are seted to the quorum created on reg coordinator initialization
initialParams := regcoord.ISlashingRegistryCoordinatorTypesOperatorSetParam{
MaxOperatorCount: 10000,
KickBIPsOfOperatorStake: 15000,
KickBIPsOfTotalStake: 100,
}

// At the beginning, params are the set on initialization
params, err := registryCoordinator.GetOperatorSetParams(&bind.CallOpts{}, 0)
require.NoError(t, err)
require.Equal(t, params, initialParams)

newOperatorSetParams := regcoord.ISlashingRegistryCoordinatorTypesOperatorSetParam{
MaxOperatorCount: 5,
}

receipt, err := chainWriter.SetOperatorSetParams(
context.Background(),
0,
newOperatorSetParams,
true,
)
require.NoError(t, err)
require.Equal(t, receipt.Status, gethtypes.ReceiptStatusSuccessful)

// After setting operator set params, params are the setted ones
params, err = registryCoordinator.GetOperatorSetParams(&bind.CallOpts{}, 0)
require.NoError(t, err)
require.Equal(t, params, newOperatorSetParams)
}

func TestSetChurnApprover(t *testing.T) {
// Test set up
clients, anvilHttpEndpoint := testclients.BuildTestClients(t)
Expand Down