Skip to content

Commit a32af54

Browse files
committed
refactor: review changes
1 parent 1b7438d commit a32af54

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed

src/test/integration/IntegrationBase.t.sol

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,29 @@ abstract contract IntegrationBase is IntegrationDeployer {
540540
}
541541
}
542542

543+
function assert_Snap_StakerWithdrawableShares_AfterSlash(
544+
User staker,
545+
IAllocationManagerTypes.AllocateParams memory allocateParams,
546+
IAllocationManagerTypes.SlashingParams memory slashingParams,
547+
string memory err
548+
) internal {
549+
uint[] memory curShares = _getWithdrawableShares(staker, allocateParams.strategies);
550+
uint[] memory prevShares = _getPrevWithdrawableShares(staker, allocateParams.strategies);
551+
552+
for (uint i = 0; i < allocateParams.strategies.length; i++) {
553+
IStrategy strat = allocateParams.strategies[i];
554+
555+
uint256 slashedShares = 0;
556+
557+
if (slashingParams.strategies.contains(strat)) {
558+
uint wadToSlash = slashingParams.wadsToSlash[slashingParams.strategies.indexOf(strat)];
559+
slashedShares = prevShares[i].mulWadRoundUp(allocateParams.newMagnitudes[i].mulWadRoundUp(wadToSlash));
560+
}
561+
562+
assertApproxEqAbs(prevShares[i] - slashedShares, curShares[i], 1, err);
563+
}
564+
}
565+
543566
// TODO: slashable stake
544567

545568
/*******************************************************************************
@@ -1547,6 +1570,14 @@ abstract contract IntegrationBase is IntegrationDeployer {
15471570
return shares;
15481571
}
15491572

1573+
function _getPrevWithdrawableShares(User staker, IStrategy[] memory strategies) internal timewarp() returns (uint[] memory) {
1574+
return _getWithdrawableShares(staker, strategies);
1575+
}
1576+
1577+
function _getWithdrawableShares(User staker, IStrategy[] memory strategies) internal view returns (uint[] memory withdrawableShares) {
1578+
(withdrawableShares, ) = delegationManager.getWithdrawableShares(address(staker), strategies);
1579+
}
1580+
15501581
function _getActiveValidatorCount(User staker) internal view returns (uint) {
15511582
EigenPod pod = staker.pod();
15521583
return pod.activeValidatorCount();

src/test/integration/tests/Deposit_Delegate_Allocate.t.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
121121
_randStrategiesAndWadsToSlash(operatorSet);
122122
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
123123
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
124+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
125+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, allocateParams, slashingParams, "staker deposit shares should be slashed");
124126
}
125127

126128
// 5. Undelegate from an operator
@@ -188,6 +190,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
188190
_randStrategiesAndWadsToSlash(operatorSet);
189191
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
190192
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
193+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
194+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, allocateParams, slashingParams, "staker deposit shares should be slashed");
191195
}
192196

193197
// 5. Undelegate from an operator
@@ -250,6 +254,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
250254
_randStrategiesAndWadsToSlash(operatorSet);
251255
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
252256
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
257+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
258+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, allocateParams, slashingParams, "staker deposit shares should be slashed");
253259
}
254260

255261
// 6. Complete withdrawal
@@ -318,6 +324,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
318324
_randStrategiesAndWadsToSlash(operatorSet);
319325
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
320326
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
327+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
328+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, allocateParams, slashingParams, "staker deposit shares should be slashed");
321329
}
322330

323331
// 4. Complete withdrawal
@@ -365,12 +373,10 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
365373
assert_Snap_Allocations_Modified(
366374
operator, allocateParams, true, "operator allocations should be updated after delay"
367375
);
368-
console.log("block allocation complete", block.number);
369376

370377
// 4. Deallocate all.
371-
operator.deallocateAll(operatorSet);
378+
IAllocationManagerTypes.AllocateParams memory deallocateParams = operator.deallocateAll(operatorSet);
372379
_rollBlocksForCompleteAllocation(operator, operatorSet, strategies);
373-
console.log("block deallocation complete", block.number);
374380

375381
// 5. Slash operator
376382
IAllocationManagerTypes.SlashingParams memory slashingParams;
@@ -379,6 +385,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
379385
_randStrategiesAndWadsToSlash(operatorSet);
380386
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
381387
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
388+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
389+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, deallocateParams, slashingParams, "staker deposit shares should be slashed");
382390
}
383391

384392
// 6. Queue withdrawals
@@ -447,6 +455,8 @@ contract Integration_Deposit_Delegate_Allocate is IntegrationCheckUtils {
447455
_randStrategiesAndWadsToSlash(operatorSet);
448456
slashingParams = avs.slashOperator(operator, operatorSet.id, strategiesToSlash, wadsToSlash);
449457
assert_Snap_Allocations_Slashed(slashingParams, operatorSet, true, "operator allocations should be slashed");
458+
assert_Snap_Unchanged_StakerDepositShares(staker, "staker deposit shares should be unchanged after slashing");
459+
assert_Snap_StakerWithdrawableShares_AfterSlash(staker, allocateParams, slashingParams, "staker deposit shares should be slashed");
450460
}
451461
}
452462
}

0 commit comments

Comments
 (0)