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 slashable stake lookahead function #512

24 changes: 24 additions & 0 deletions chainio/clients/avsregistry/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,3 +528,27 @@ func (w *ChainWriter) SetRewardsInitiator(
}
return receipt, nil
}

// Receives the quorum number to modify and the new look ahead period to set. Sets the look ahead
// time for checking operator shares for a specific quorum, and returns the receipt of the
// transaction in case of success.
func (w *ChainWriter) SetSlashableStakeLookahead(
ctx context.Context,
quorumNumber uint8,
lookAheadPeriod uint32,
waitForReceipt bool,
) (*gethtypes.Receipt, error) {
noSendTxOpts, err := w.txMgr.GetNoSendTxOpts()
if err != nil {
return nil, err
}
tx, err := w.stakeRegistry.SetSlashableStakeLookahead(noSendTxOpts, quorumNumber, lookAheadPeriod)
if err != nil {
return nil, err
}
receipt, err := w.txMgr.Send(ctx, tx, waitForReceipt)
if err != nil {
return nil, utils.WrapError("failed to send SetSlashableStakeLookahead tx with err", err.Error())
}
return receipt, nil
}
44 changes: 44 additions & 0 deletions chainio/clients/avsregistry/writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
chainioutils "github.com/Layr-Labs/eigensdk-go/chainio/utils"
regcoordinator "github.com/Layr-Labs/eigensdk-go/contracts/bindings/RegistryCoordinator"
servicemanager "github.com/Layr-Labs/eigensdk-go/contracts/bindings/ServiceManagerBase"
stakeregistry "github.com/Layr-Labs/eigensdk-go/contracts/bindings/StakeRegistry"
"github.com/Layr-Labs/eigensdk-go/crypto/bls"
"github.com/Layr-Labs/eigensdk-go/testutils"
"github.com/Layr-Labs/eigensdk-go/testutils/testclients"
Expand Down Expand Up @@ -248,6 +249,49 @@ func TestWriterMethods(t *testing.T) {
assert.Error(t, err)
assert.Nil(t, receipt)
})

t.Run("set slashable stake lookahead", func(t *testing.T) {
// Create stakeRegistry contract
ethHttpClient, err := ethclient.Dial(anvilHttpEndpoint)
require.NoError(t, err)

contractBlsRegistryCoordinator, err := regcoordinator.NewContractRegistryCoordinator(
contractAddrs.RegistryCoordinator,
ethHttpClient,
)
require.NoError(t, err)

stakeRegistryAddr, err := contractBlsRegistryCoordinator.StakeRegistry(&bind.CallOpts{})
require.NoError(t, err)

stakeRegistry, err := stakeregistry.NewContractStakeRegistry(
stakeRegistryAddr,
ethHttpClient,
)
require.NoError(t, err)

// When not set, lookAheadPeriod is Zero
lookAheadPeriod, err := stakeRegistry.SlashableStakeLookAheadPerQuorum(&bind.CallOpts{}, 0)
require.NoError(t, err)
assert.Zero(t, lookAheadPeriod)

// Modify lookAheadPeriod, set it as 32
newLookAheadPeriod := 32
receipt, err := chainWriter.SetSlashableStakeLookahead(
context.Background(),
0,
uint32(newLookAheadPeriod),
true,
)
require.NoError(t, err)
require.NotNil(t, receipt)

// After modify, lookAheadPeriod's value is 32
lookAheadPeriod, err = stakeRegistry.SlashableStakeLookAheadPerQuorum(&bind.CallOpts{}, 0)
require.NoError(t, err)

assert.Equal(t, lookAheadPeriod, uint32(newLookAheadPeriod))
})
}

// Compliance test for BLS signature
Expand Down