Skip to content

Commit

Permalink
feat: track total slashable stake and total delegated stake per quorum (
Browse files Browse the repository at this point in the history
#317)

* feat: remove both option

* feat: total delegated stake and total slashable stake per quorum config

* test: resolve some breaking changes to tests

* chore: move stake type to file level definition

* chore: refactor loop

* test: add unit test for slashble stake quorum init

* test: assert on state and event

* test: delegated stake quorum and assertions
  • Loading branch information
stevennevins authored Nov 20, 2024
1 parent fa04f06 commit 388e9f9
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 216 deletions.
4 changes: 1 addition & 3 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ ffi = true
no-match-contract = "FFI"

# Enables or disables the optimizer
optimizer = true
# The number of optimizer runs
optimizer_runs = 200
optimizer = false
# Whether or not to use the Yul intermediate representation compilation pipeline
via_ir = false
# Override the Solidity version (this overrides `auto_detect_solc`)
Expand Down
38 changes: 30 additions & 8 deletions src/RegistryCoordinator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {ISignatureUtils} from "eigenlayer-contracts/src/contracts/interfaces/ISi
import {IAVSDirectory, OperatorSet} from "eigenlayer-contracts/src/contracts/interfaces/IAVSDirectory.sol";
import {ISocketUpdater} from "./interfaces/ISocketUpdater.sol";
import {IBLSApkRegistry} from "./interfaces/IBLSApkRegistry.sol";
import {IStakeRegistry} from "./interfaces/IStakeRegistry.sol";
import {IStakeRegistry, StakeType} from "./interfaces/IStakeRegistry.sol";
import {IIndexRegistry} from "./interfaces/IIndexRegistry.sol";
import {IServiceManager} from "./interfaces/IServiceManager.sol";
import {IRegistryCoordinator} from "./interfaces/IRegistryCoordinator.sol";
Expand Down Expand Up @@ -87,11 +87,15 @@ contract RegistryCoordinator is
uint256 _initialPausedStatus,
OperatorSetParam[] memory _operatorSetParams,
uint96[] memory _minimumStakes,
IStakeRegistry.StrategyParams[][] memory _strategyParams
IStakeRegistry.StrategyParams[][] memory _strategyParams,
StakeType[] memory _stakeTypes,
uint32[] memory _lookAheadPeriods
) external initializer {
require(
_operatorSetParams.length == _minimumStakes.length
&& _minimumStakes.length == _strategyParams.length,
&& _minimumStakes.length == _strategyParams.length
&& _strategyParams.length == _stakeTypes.length
&& _stakeTypes.length == _lookAheadPeriods.length,
"RegistryCoordinator.initialize: input length mismatch"
);

Expand All @@ -108,7 +112,7 @@ contract RegistryCoordinator is

// Create quorums
for (uint256 i = 0; i < _operatorSetParams.length; i++) {
_createQuorum(_operatorSetParams[i], _minimumStakes[i], _strategyParams[i]);
_createQuorum(_operatorSetParams[i], _minimumStakes[i], _strategyParams[i], _stakeTypes[i], _lookAheadPeriods[i]);
}
}

Expand Down Expand Up @@ -404,12 +408,21 @@ contract RegistryCoordinator is
* @param strategyParams a list of strategies and multipliers used by the StakeRegistry to
* calculate an operator's stake weight for the quorum
*/
function createQuorum(
function createTotalDelegatedStakeQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IStakeRegistry.StrategyParams[] memory strategyParams
) external virtual onlyOwner {
_createQuorum(operatorSetParams, minimumStake, strategyParams);
_createQuorum(operatorSetParams, minimumStake, strategyParams, StakeType.TOTAL_DELEGATED, 0);
}

function createSlashableStakeQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IStakeRegistry.StrategyParams[] memory strategyParams,
uint32 lookAheadPeriod
) external virtual onlyOwner {
_createQuorum(operatorSetParams, minimumStake, strategyParams, StakeType.TOTAL_SLASHABLE, lookAheadPeriod);
}

/**
Expand Down Expand Up @@ -809,7 +822,9 @@ contract RegistryCoordinator is
function _createQuorum(
OperatorSetParam memory operatorSetParams,
uint96 minimumStake,
IStakeRegistry.StrategyParams[] memory strategyParams
IStakeRegistry.StrategyParams[] memory strategyParams,
StakeType stakeType,
uint32 lookAheadPeriod
) internal {
// Increment the total quorum count. Fails if we're already at the max
uint8 prevQuorumCount = quorumCount;
Expand All @@ -824,7 +839,14 @@ contract RegistryCoordinator is

// Initialize the quorum here and in each registry
_setOperatorSetParams(quorumNumber, operatorSetParams);
stakeRegistry.initializeQuorum(quorumNumber, minimumStake, strategyParams);

// Initialize stake registry based on stake type
if (stakeType == StakeType.TOTAL_DELEGATED) {
stakeRegistry.initializeDelegatedStakeQuorum(quorumNumber, minimumStake, strategyParams);
} else if (stakeType == StakeType.TOTAL_SLASHABLE) {
stakeRegistry.initializeSlashableStakeQuorum(quorumNumber, minimumStake, lookAheadPeriod, strategyParams);
}

indexRegistry.initializeQuorum(quorumNumber);
blsApkRegistry.initializeQuorum(quorumNumber);
// Check if the AVS has migrated to operator sets
Expand Down
Loading

0 comments on commit 388e9f9

Please sign in to comment.