Skip to content

Commit

Permalink
fix: if paused, the depositable and withdrawable amount must be zero
Browse files Browse the repository at this point in the history
  • Loading branch information
junkim012 committed May 11, 2024
1 parent 0f78d89 commit 971e8f6
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/vault/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { Multicall } from "@openzeppelin/contracts/utils/Multicall.sol";
import { ReentrancyGuard } from "openzeppelin-contracts/contracts/utils/ReentrancyGuard.sol";
import { AccessControlDefaultAdminRules } from
"@openzeppelin/contracts/access/extensions/AccessControlDefaultAdminRules.sol";

/**
* @title Ion Lending Vault
* @author Molecular Labs
Expand All @@ -28,6 +27,7 @@ import { AccessControlDefaultAdminRules } from
*
* @custom:security-contact [email protected]
*/

contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, ReentrancyGuard {
using EnumerableSet for EnumerableSet.AddressSet;
using Math for uint256;
Expand Down Expand Up @@ -752,7 +752,6 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy
newTotalSupply = totalSupply() + feeShares;

assets = _convertToAssetsWithTotals(balanceOf(owner), newTotalSupply, newTotalAssets, Math.Rounding.Floor);

assets -= _simulateWithdrawIon(assets);
}

Expand Down Expand Up @@ -897,9 +896,10 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy
* @return The max amount of assets withdrawable from this IonPool.
*/
function _withdrawable(IIonPool pool) internal view returns (uint256) {
if (pool.paused()) return 0;

uint256 currentSupplied = pool.getUnderlyingClaimOf(address(this));
uint256 availableLiquidity = uint256(pool.extsload(ION_POOL_LIQUIDITY_SLOT));

return Math.min(currentSupplied, availableLiquidity);
}

Expand All @@ -910,6 +910,8 @@ contract Vault is ERC4626, Multicall, AccessControlDefaultAdminRules, Reentrancy
* @return The max amount of assets depositable to this IonPool.
*/
function _depositable(IIonPool pool) internal view returns (uint256) {
if (pool.paused()) return 0;

uint256 allocationCapDiff = _zeroFloorSub(caps[pool], pool.getUnderlyingClaimOf(address(this)));
uint256 supplyCapDiff =
_zeroFloorSub(uint256(pool.extsload(ION_POOL_SUPPLY_CAP_SLOT)), pool.getTotalUnderlyingClaims());
Expand Down
58 changes: 58 additions & 0 deletions test/unit/concrete/vault/Vault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1496,6 +1496,64 @@ contract VaultERC4626ExternalViews is VaultSharedSetup {

function test_MaxRedeem() public { }

function test_MaxWithdrawWithPausedPools() public {
uint256[] memory allocationCaps = new uint256[](3);
allocationCaps[0] = 10e18;
allocationCaps[1] = 20e18;
allocationCaps[2] = 30e18;

vm.prank(OWNER);
vault.updateAllocationCaps(markets, allocationCaps);

uint256 depositAmt = 35e18;
setERC20Balance(address(BASE_ASSET), address(this), depositAmt);
vault.deposit(depositAmt, address(this));

uint256 maxWithdrawBeforePause = vault.maxWithdraw(address(this));

weEthIonPool.pause();
uint256 maxWithdrawAfterPause = vault.maxWithdraw(address(this));

rsEthIonPool.pause();
uint256 maxWithdrawAfterSecondPause = vault.maxWithdraw(address(this));

rswEthIonPool.pause();
uint256 maxWithdrawAfterThirdPause = vault.maxWithdraw(address(this));

assertEq(maxWithdrawBeforePause, depositAmt, "max withdraw before pause");
assertEq(maxWithdrawAfterPause, depositAmt - 10e18, "max withdraw after pause");
assertEq(maxWithdrawAfterSecondPause, depositAmt - 30e18, "max withdraw after second pause");
assertEq(maxWithdrawAfterThirdPause, 0, "max withdraw after third pause");
}

function test_MaxDepositWithPausedPools() public {
uint256[] memory allocationCaps = new uint256[](3);
allocationCaps[0] = 10e18;
allocationCaps[1] = 20e18;
allocationCaps[2] = 30e18;

vm.prank(OWNER);
vault.updateAllocationCaps(markets, allocationCaps);

uint256 maxDepositBeforePause = vault.maxDeposit(NULL);

weEthIonPool.pause();
uint256 maxDepositAfterPause = vault.maxDeposit(NULL);

rsEthIonPool.pause();
uint256 maxDepositAfterSecondPause = vault.maxDeposit(NULL);

rswEthIonPool.pause();
uint256 maxDepositAfterThirdPause = vault.maxDeposit(NULL);

assertEq(maxDepositBeforePause, 60e18, "max deposit before pause");
assertEq(maxDepositAfterPause, 50e18, "max deposit after pause");
assertEq(maxDepositAfterSecondPause, 30e18, "max deposit after second pause");
assertEq(maxDepositAfterThirdPause, 0, "max deposit after third pause");
}

function test_WithdrawWithPausedPools() public { }

// --- Previews ---

// Check the difference between preview and actual
Expand Down

0 comments on commit 971e8f6

Please sign in to comment.