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

fix: sherlock-audit/2024-06-leveraged-vaults-judging#56 #95

Closed
Closed
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
4 changes: 2 additions & 2 deletions contracts/vaults/staking/BaseStakingVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -247,14 +247,14 @@ abstract contract BaseStakingVault is WithdrawRequestBase, BaseStrategyVault {

/// @notice Allows an account to initiate a withdraw of their vault shares
function initiateWithdraw() external {
_initiateWithdraw({account: msg.sender, isForced: false});

(VaultAccountHealthFactors memory health, /* */, /* */) = NOTIONAL.getVaultAccountHealthFactors(
msg.sender, address(this)
);
VaultConfig memory config = NOTIONAL.getVaultConfig(address(this));
// Require that the account is collateralized
require(config.minCollateralRatio <= health.collateralRatio, "Insufficient Collateral");

_initiateWithdraw({account: msg.sender, isForced: false});
}

/// @notice Allows the emergency exit role to force an account to withdraw all their vault shares
Expand Down
17 changes: 16 additions & 1 deletion tests/Staking/BaseStakingTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.24;
import "../MockOracle.sol";
import "../BaseAcceptanceTest.sol";
import "./harness/BaseStakingHarness.sol";
import "@contracts/vaults/staking/protocols/PendlePrincipalToken.sol";
import "@deployments/Deployments.sol";
import "@contracts/vaults/staking/BaseStakingVault.sol";
import "@contracts/proxy/nProxy.sol";
Expand Down Expand Up @@ -446,7 +447,21 @@ abstract contract BaseStakingTest is BaseAcceptanceTest {
uint256 maturity = maturities[maturityIndex];
uint256 vaultShares = enterVaultLiquidation(account, maturity);

_changeCollateralRatio();
// Depending on the vault type, we need to change the price of different tokens.
try PendlePrincipalToken(payable(address(v()))).TOKEN_OUT_SY() returns (address tokenOutSY) {
// Pendle PT tokens have the PT token as the staking token. That will be sold during the
// withdraw so we need to change the price of the TOKEN_OUT_SY token.
_changeTokenPrice(withdrawLiquidationDiscount, tokenOutSY);
} catch {
if (address(v().REDEMPTION_TOKEN()) == 0x4c9EDD5852cd905f086C759E8383e09bff1E68B3) {
// If USDe then we need to change the price of the redemption token since the
// method does not depend on the value of the staking token.
_changeTokenPrice(withdrawLiquidationDiscount, v().REDEMPTION_TOKEN());
} else {
_changeTokenPrice(withdrawLiquidationDiscount, v().STAKING_TOKEN());
}
}

// attempt to account withdraw
vm.prank(account);
vm.expectRevert("Insufficient Collateral");
Expand Down