Skip to content

Commit

Permalink
feat: add set slashable stake lookahead function (#512)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximopalopoli authored Feb 6, 2025
1 parent 3c89e44 commit 6be70db
Show file tree
Hide file tree
Showing 2 changed files with 68 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 @@ -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

0 comments on commit 6be70db

Please sign in to comment.