Skip to content

Commit

Permalink
feat: add set ejector function (#540)
Browse files Browse the repository at this point in the history
Co-authored-by: Tomás Grüner <[email protected]>
  • Loading branch information
maximopalopoli and MegaRedHand authored Feb 7, 2025
1 parent d729fcd commit f49eaf0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
24 changes: 24 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,3 +697,27 @@ func (w *ChainWriter) SetChurnApprover(
}
return receipt, nil
}

// Sets the ejector address to the one received by parameter. This address is the only one
// that can eject operators. Returns the receipt of the transaction in case of success.
func (w *ChainWriter) SetEjector(
ctx context.Context,
ejectorAddress gethcommon.Address,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
w.logger.Info("setting ejector with address ", ejectorAddress)

noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.registryCoordinator.SetEjector(noSendTxOpts, ejectorAddress)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetEjector tx with err", err.Error())
}
return receipt, nil
}
34 changes: 34 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,37 @@ func TestSetChurnApprover(t *testing.T) {
require.NoError(t, err)
assert.Equal(t, newApprover.String(), testutils.ANVIL_SECOND_ADDRESS)
}

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

contractAddrs := testutils.GetContractAddressesFromContractRegistry(anvilHttpEndpoint)

chainWriter := clients.AvsRegistryChainWriter

ejectorAddress := gethcommon.HexToAddress(testutils.ANVIL_SECOND_ADDRESS)

ethHttpClient := clients.EthHttpClient

registryCoordinatorContract, err := regcoord.NewContractRegistryCoordinator(
contractAddrs.RegistryCoordinator,
ethHttpClient,
)
require.NoError(t, err)

// At first, ejector is anvil first address
ejector, err := registryCoordinatorContract.Ejector(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, ejector.String(), testutils.ANVIL_FIRST_ADDRESS)

// Set a new ejector
receipt, err := chainWriter.SetEjector(context.Background(), ejectorAddress, true)
require.NoError(t, err)
require.Equal(t, receipt.Status, gethtypes.ReceiptStatusSuccessful)

// After change, ejector is the setted value
newEjector, err := registryCoordinatorContract.Ejector(&bind.CallOpts{})
require.NoError(t, err)
assert.Equal(t, newEjector.String(), testutils.ANVIL_SECOND_ADDRESS)
}

0 comments on commit f49eaf0

Please sign in to comment.