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: remove strategies param #855

Open
wants to merge 4 commits into
base: feat/restricted-strategy-list-2
Choose a base branch
from
Open
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
27 changes: 14 additions & 13 deletions src/contracts/core/AllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,21 @@ contract AllocationManager is
require(0 < params.wadToSlash && params.wadToSlash <= WAD, InvalidWadToSlash());

OperatorSet memory operatorSet = OperatorSet({avs: msg.sender, operatorSetId: params.operatorSetId});
IStrategy[] memory strategies = avsDirectory.getStrategiesInOperatorSet(operatorSet);

// Assert that the provided strategies are all whitelisted for the given operator set.
require(avsDirectory.isOperatorSetStrategyBatch(operatorSet, params.strategies), InvalidStrategy());
require(avsDirectory.isOperatorSetStrategyBatch(operatorSet, strategies), InvalidStrategy());
// Assert that the operator is slashable for the given operator set.
require(avsDirectory.isOperatorSlashable(params.operator, operatorSet), InvalidOperator());

bytes32 operatorSetKey = _encodeOperatorSet(operatorSet);
uint256 strategiesLength = strategies.length;

// Record the proportion of 1e18 that the operator's total shares that are being slashed
uint256[] memory wadSlashed = new uint256[](params.strategies.length);
uint256[] memory wadSlashed = new uint256[](strategiesLength);

for (uint256 i = 0; i < params.strategies.length; ++i) {
PendingMagnitudeInfo memory info =
_getPendingMagnitudeInfo(params.operator, params.strategies[i], operatorSetKey);
for (uint256 i = 0; i < strategiesLength; ++i) {
PendingMagnitudeInfo memory info = _getPendingMagnitudeInfo(params.operator, strategies[i], operatorSetKey);

require(info.currentMagnitude > 0, OperatorNotAllocated());

Expand All @@ -88,7 +89,7 @@ contract AllocationManager is
emit OperatorSetMagnitudeUpdated(
params.operator,
operatorSet,
params.strategies[i],
strategies[i],
_addInt128(info.currentMagnitude, info.pendingDiff),
info.effectTimestamp
);
Expand All @@ -97,28 +98,28 @@ contract AllocationManager is
// 3. Update the operator's allocation in storage
_updateMagnitudeInfo({
operator: params.operator,
strategy: params.strategies[i],
strategy: strategies[i],
operatorSetKey: operatorSetKey,
info: info
});

emit OperatorSetMagnitudeUpdated(
params.operator, operatorSet, params.strategies[i], info.currentMagnitude, uint32(block.timestamp)
params.operator, operatorSet, strategies[i], info.currentMagnitude, uint32(block.timestamp)
);

// 4. Reduce the operator's max magnitude
uint64 maxMagnitudeBeforeSlash = _maxMagnitudeHistory[params.operator][params.strategies[i]].latest();
uint64 maxMagnitudeBeforeSlash = _maxMagnitudeHistory[params.operator][strategies[i]].latest();
uint64 maxMagnitudeAfterSlash = maxMagnitudeBeforeSlash - slashedMagnitude;
_maxMagnitudeHistory[params.operator][params.strategies[i]].push({
_maxMagnitudeHistory[params.operator][strategies[i]].push({
key: uint32(block.timestamp),
value: maxMagnitudeAfterSlash
});
emit MaxMagnitudeUpdated(params.operator, params.strategies[i], maxMagnitudeAfterSlash);
emit MaxMagnitudeUpdated(params.operator, strategies[i], maxMagnitudeAfterSlash);

// 5. Decrease operators shares in the DelegationManager
delegation.decreaseOperatorShares({
operator: params.operator,
strategy: params.strategies[i],
strategy: strategies[i],
previousTotalMagnitude: maxMagnitudeBeforeSlash,
newTotalMagnitude: maxMagnitudeAfterSlash
});
Expand All @@ -127,7 +128,7 @@ contract AllocationManager is
wadSlashed[i] = uint256(slashedMagnitude).divWad(maxMagnitudeBeforeSlash);
}

emit OperatorSlashed(params.operator, operatorSet, params.strategies, wadSlashed, params.description);
emit OperatorSlashed(params.operator, operatorSet, strategies, wadSlashed, params.description);
}

/// @inheritdoc IAllocationManager
Expand Down
2 changes: 0 additions & 2 deletions src/contracts/interfaces/IAllocationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,13 @@ interface IAllocationManagerTypes {
* @notice Struct containing parameters to slashing
* @param operator the address to slash
* @param operatorSetId the ID of the operatorSet the operator is being slashed on behalf of
* @param strategies the set of strategies to slash
* @param wadToSlash the parts in 1e18 to slash, this will be proportional to the operator's
* slashable stake allocation for the operatorSet
* @param description the description of the slashing provided by the AVS for legibility
*/
struct SlashingParams {
address operator;
uint32 operatorSetId;
IStrategy[] strategies;
uint256 wadToSlash;
string description;
}
Expand Down
4 changes: 0 additions & 4 deletions src/test/DevnetLifecycle.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,9 @@ contract Devnet_Lifecycle_Test is Test {
}

function _slashOperator() public {
// Get slashing params
IStrategy[] memory strategies = new IStrategy[](1);
strategies[0] = wethStrategy;
IAllocationManagerTypes.SlashingParams memory slashingParams = IAllocationManagerTypes.SlashingParams({
operator: operator,
operatorSetId: 1,
strategies: strategies,
wadToSlash: 5e17,
description: "test"
});
Expand Down
32 changes: 7 additions & 25 deletions src/test/unit/AllocationManagerUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,9 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag
) internal view returns (IAllocationManagerTypes.SlashingParams memory) {
r = uint256(keccak256(abi.encodePacked(r, salt)));

IStrategy[] memory strategies = new IStrategy[](1);
strategies[0] = strategyMock;

return IAllocationManagerTypes.SlashingParams({
operator: operator,
operatorSetId: uint32(r),
strategies: strategies,
wadToSlash: bound(r, 1, 1e18),
description: "test"
});
Expand All @@ -193,13 +189,9 @@ contract AllocationManagerUnitTests is EigenLayerUnitTestSetup, IAllocationManag
) internal view returns (IAllocationManagerTypes.SlashingParams memory) {
r = uint256(keccak256(abi.encodePacked(r, salt)));

IStrategy[] memory strategies = new IStrategy[](1);
strategies[0] = strategyMock;

return IAllocationManagerTypes.SlashingParams({
operator: operator,
operatorSetId: operatorSetId,
strategies: strategies,
wadToSlash: bound(r, 1, 1e18),
description: "test"
});
Expand Down Expand Up @@ -608,7 +600,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 1e18,
description: "test"
});
Expand Down Expand Up @@ -643,7 +634,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 25e16,
description: "test"
});
Expand All @@ -664,7 +654,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
emit OperatorSlashed(
slashingParams.operator,
_operatorSet(defaultAVS, slashingParams.operatorSetId),
slashingParams.strategies,
_strategyMockArray(),
wadSlashed,
slashingParams.description
);
Expand Down Expand Up @@ -730,7 +720,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
emit OperatorSlashed(
slashingParams.operator,
_operatorSet(defaultAVS, slashingParams.operatorSetId),
slashingParams.strategies,
_strategyMockArray(),
wadSlashed,
slashingParams.description
);
Expand Down Expand Up @@ -782,7 +772,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 50e16,
description: "test"
});
Expand All @@ -801,7 +790,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
cheats.expectEmit(true, true, true, true, address(allocationManager));
emit MaxMagnitudeUpdated(defaultOperator, strategyMock, maxMagnitudeAfterSlash);
cheats.expectEmit(true, true, true, true, address(allocationManager));
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description);
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId),_strategyMockArray(), wadSlashed, slashingParams.description);
cheats.prank(defaultAVS);
allocationManager.slashOperator(slashingParams);

Expand Down Expand Up @@ -852,7 +841,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 25e16,
description: "test"
});
Expand All @@ -875,7 +863,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
cheats.expectEmit(true, true, true, true, address(allocationManager));
uint256[] memory wadSlashed = new uint256[](1);
wadSlashed[0] = 25e16;
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description);
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description);
cheats.prank(defaultAVS);
allocationManager.slashOperator(slashingParams);

Expand Down Expand Up @@ -911,7 +899,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 1e18,
description: "test"
});
Expand Down Expand Up @@ -951,7 +938,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 1e18,
description: "test"
});
Expand All @@ -969,7 +955,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
cheats.expectEmit(true, true, true, true, address(allocationManager));
uint256[] memory wadSlashed = new uint256[](1);
wadSlashed[0] = 1e18;
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description);
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description);

cheats.prank(defaultAVS);
allocationManager.slashOperator(slashingParams);
Expand Down Expand Up @@ -1016,7 +1002,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 25e16,
description: "test"
});
Expand All @@ -1035,7 +1020,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
cheats.expectEmit(true, true, true, true, address(allocationManager));
uint256[] memory wadSlashed = new uint256[](1);
wadSlashed[0] = 125e15;
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description);
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description);
cheats.prank(defaultAVS);
allocationManager.slashOperator(slashingParams);

Expand Down Expand Up @@ -1102,7 +1087,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 5e17,
description: "test"
});
Expand Down Expand Up @@ -1168,7 +1152,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: strategiesToSlash,
wadToSlash: 6e17,
description: "test"
});
Expand Down Expand Up @@ -1201,7 +1184,7 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
wadSlashed[0] = 3e17;
wadSlashed[1] = 6e17;
cheats.expectEmit(true, true, true, true, address(allocationManager));
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), slashingParams.strategies, wadSlashed, slashingParams.description);
emit OperatorSlashed(slashingParams.operator, _operatorSet(defaultAVS, slashingParams.operatorSetId), _strategyMockArray(), wadSlashed, slashingParams.description);

// Slash Operator
cheats.prank(defaultAVS);
Expand Down Expand Up @@ -1252,7 +1235,6 @@ contract AllocationManagerUnitTests_SlashOperator is AllocationManagerUnitTests
SlashingParams memory slashingParams = SlashingParams({
operator: defaultOperator,
operatorSetId: allocations[0].operatorSets[0].operatorSetId,
strategies: _strategyMockArray(),
wadToSlash: 5e17,
description: "test"
});
Expand Down
Loading