Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
17 changes: 9 additions & 8 deletions src/test/integration/IntegrationBase.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
function assert_BCSF_Zero(
User staker,
string memory err
) internal {
) internal view {
uint64 curBCSF = _getBeaconChainSlashingFactor(staker);
assertEq(curBCSF, 0, err);
}
Expand Down Expand Up @@ -1569,7 +1569,7 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
}
}

function assert_Snap_Expected_Staker_WithdrawableShares_Withdrawal(
function assert_Snap_Expected_Staker_WithdrawableShares_Deposit(
User staker,
User operator,
IStrategy[] memory strategies,
Expand All @@ -1582,10 +1582,11 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
uint[] memory expectedWithdrawableShares = new uint[](strategies.length);
for (uint i = 0; i < strategies.length; i++) {
if (prevShares[i] == 0 && depositSharesAdded[i] > 0){
expectedWithdrawableShares[i] = _getExpectedWithdrawableSharesFullWithdrawal(staker, operator, strategies[i], depositSharesAdded[i]);
expectedWithdrawableShares[i] = _getExpectedWithdrawableSharesDeposit(staker, operator, strategies[i], depositSharesAdded[i]);
assertEq(curShares[i], expectedWithdrawableShares[i], err);
} else {
assertEq(prevShares[i] + depositSharesAdded[i], curShares[i], err);
uint[] memory prevDepositShares = _getPrevStakerDepositShares(staker, strategies);
assertEq((prevDepositShares[i] + depositSharesAdded[i]).mulWad(_getDepositScalingFactor(staker, strategies[i])).mulWad(_getSlashingFactor(staker, strategies[i])), curShares[i], err);
}
}
}
Expand Down Expand Up @@ -2919,15 +2920,15 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
return WAD.divWad(_getBeaconChainSlashingFactor(staker));
}

function _getExpectedDSFFullWithdrawal(User staker, User operator, IStrategy strategy) internal view returns (uint expectedDepositScalingFactor) {
function _getExpectedDSFDeposit(User staker, User operator, IStrategy strategy) internal view returns (uint expectedDepositScalingFactor) {
if (strategy == BEACONCHAIN_ETH_STRAT){
return WAD.divWad(allocationManager.getMaxMagnitude(address(operator), strategy).mulWad(_getBeaconChainSlashingFactor(staker)));
} else {
return WAD.divWad(allocationManager.getMaxMagnitude(address(operator), strategy));
}
}

function _getExpectedWithdrawableSharesUndelegate(User staker, IStrategy[] memory strategies, uint[] memory shares) internal returns (uint[] memory){
function _getExpectedWithdrawableSharesUndelegate(User staker, IStrategy[] memory strategies, uint[] memory shares) internal view returns (uint[] memory){
uint[] memory expectedWithdrawableShares = new uint[](strategies.length);
for (uint i = 0; i < strategies.length; i++) {
if (strategies[i] == BEACONCHAIN_ETH_STRAT) {
Expand Down Expand Up @@ -2963,8 +2964,8 @@ abstract contract IntegrationBase is IntegrationDeployer, TypeImporter {
return expectedWithdrawableShares;
}

function _getExpectedWithdrawableSharesFullWithdrawal(User staker, User operator, IStrategy strategy, uint depositShares) internal returns (uint) {
return depositShares.mulWad(_getExpectedDSFFullWithdrawal(staker, operator, strategy)).mulWad(_getSlashingFactor(staker, strategy));
function _getExpectedWithdrawableSharesDeposit(User staker, User operator, IStrategy strategy, uint depositShares) internal view returns (uint) {
return depositShares.mulWad(_getExpectedDSFDeposit(staker, operator, strategy)).mulWad(_getSlashingFactor(staker, strategy));
}

function _getSlashingFactor(
Expand Down
20 changes: 16 additions & 4 deletions src/test/integration/IntegrationChecks.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,13 @@ contract IntegrationCheckUtils is IntegrationBase {
// and that the staker now has the expected amount of delegated shares in each strategy
assert_HasNoUnderlyingTokenBalance(staker, strategies, "staker should have transferred all underlying tokens");
assert_Snap_Added_Staker_DepositShares(staker, strategies, shares, "staker should expect shares in each strategy after depositing");
assert_Snap_Added_Staker_WithdrawableShares(staker, strategies, shares, "deposit should increase withdrawable shares");

if (delegationManager.isDelegated(address(staker))) {
User operator = User(payable(delegationManager.delegatedTo(address(staker))));
assert_Snap_Expected_Staker_WithdrawableShares_Deposit(staker, operator, strategies, shares, "staker should have received expected withdrawable shares");
} else {
assert_Snap_Added_Staker_WithdrawableShares(staker, strategies, shares, "deposit should increase withdrawable shares");
}
}

function check_Deposit_State_PartialDeposit(User staker, IStrategy[] memory strategies, uint[] memory shares, uint[] memory tokenBalances) internal {
Expand All @@ -214,7 +220,13 @@ contract IntegrationCheckUtils is IntegrationBase {
// and that the staker now has the expected amount of delegated shares in each strategy
assert_HasUnderlyingTokenBalances(staker, strategies, tokenBalances, "staker should have transferred some underlying tokens");
assert_Snap_Added_Staker_DepositShares(staker, strategies, shares, "staker should expected shares in each strategy after depositing");
assert_Snap_Added_Staker_WithdrawableShares(staker, strategies, shares, "deposit should increase withdrawable shares");

if (delegationManager.isDelegated(address(staker))) {
User operator = User(payable(delegationManager.delegatedTo(address(staker))));
assert_Snap_Expected_Staker_WithdrawableShares_Deposit(staker, operator, strategies, shares, "staker should have received expected withdrawable shares");
} else {
assert_Snap_Added_Staker_WithdrawableShares(staker, strategies, shares, "deposit should increase withdrawable shares");
}
}

function check_Delegation_State(
Expand Down Expand Up @@ -424,7 +436,7 @@ contract IntegrationCheckUtils is IntegrationBase {
assert_WithdrawalNotPending(delegationManager.calculateWithdrawalRoot(withdrawal), "staker withdrawal should no longer be pending");
assert_Snap_Unchanged_TokenBalances(staker, "staker should not have any change in underlying token balances");
assert_Snap_Added_Staker_DepositShares(staker, strategies, withdrawableShares, "staker should have received expected shares");
assert_Snap_Expected_Staker_WithdrawableShares_Withdrawal(staker, operator, strategies, withdrawableShares, "staker should have received expected withdrawable shares");
assert_Snap_Expected_Staker_WithdrawableShares_Deposit(staker, operator, strategies, withdrawableShares, "staker should have received expected withdrawable shares");
assert_Snap_Unchanged_StrategyShares(strategies, "strategies should have total shares unchanged");

// Additional checks or handling for the non-user operator scenario
Expand Down Expand Up @@ -480,7 +492,7 @@ contract IntegrationCheckUtils is IntegrationBase {
assert_Snap_Added_Staker_DepositShares(staker, strategies, withdrawableShares, "staker should have received expected shares");
assert_Snap_Unchanged_OperatorShares(operator, "operator should have shares unchanged");
assert_Snap_Unchanged_StrategyShares(strategies, "strategies should have total shares unchanged");
assert_Snap_Expected_Staker_WithdrawableShares_Withdrawal(staker, newOperator, strategies, withdrawableShares, "staker should have received expected withdrawable shares");
assert_Snap_Expected_Staker_WithdrawableShares_Deposit(staker, newOperator, strategies, withdrawableShares, "staker should have received expected withdrawable shares");
}

/*******************************************************************************
Expand Down
Loading