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 l10 #224

Merged
merged 4 commits into from
Dec 19, 2023
Merged
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
19 changes: 14 additions & 5 deletions src/Vault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ contract Vault is IVault, ERC4626, ERC20Permit {
// Free liquidity available to withdraw or borrow
// Locked profits are locked for every operation
// We do not consider negative profits since they are not true liquidity
// We subtract 1 because there is always 1 token deposited at the beginning: this will never be taken
function freeLiquidity() public view override returns (uint256) {
return super.totalAssets() - _calculateLockedProfits();
}
Expand All @@ -113,8 +112,8 @@ contract Vault is IVault, ERC4626, ERC20Permit {
uint256 supply = totalSupply();
uint256 shares = balanceOf(owner);
// super.maxWithdraw but we leverage the fact of having already computed freeLiq which contains balanceOf()
// notice that shares are always at least 1
return freeLiq.min(shares.mulDiv(freeLiq + netLoans + _calculateLockedLosses(), supply));
// notice that shares and free liquidity are always at least 1, and freeLiq cannot be withdrawn
return (freeLiq - 1).min(shares.mulDiv(freeLiq + netLoans + _calculateLockedLosses(), supply));
}

// Assets include netLoans but they are not available for withdraw
Expand All @@ -131,9 +130,9 @@ contract Vault is IVault, ERC4626, ERC20Permit {

// convertToShares using the already computed variables
// if the assets the owner can theoretically withdraw are higher than the free liquidity
// we cap them with the convertToShares of the free liquidity
// we cap them with the convertToShares of the free liquidity - 1, which is always available
if (assets >= freeLiquidityCache && assets > 0) {
maxRedeemCache = freeLiquidityCache.mulDiv(supply, totalAssetsCache);
maxRedeemCache = (freeLiquidityCache - 1).mulDiv(supply, totalAssetsCache);
}

return maxRedeemCache;
Expand All @@ -147,6 +146,16 @@ contract Vault is IVault, ERC4626, ERC20Permit {
return ERC4626.deposit(_assets, receiver);
}

function maxDeposit(address addr) public view override(IERC4626, ERC4626) returns (uint256) {
if (isLocked) return 0;
return super.maxDeposit(addr);
}

function maxMint(address) public view override(IERC4626, ERC4626) returns (uint256) {
if (isLocked) return 0;
return type(uint256).max;
}

function depositWithPermit(
uint256 assets,
address receiver,
Expand Down
2 changes: 1 addition & 1 deletion test/Vault.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ contract VaultTest is Test {
assertTrue(token.balanceOf(tokenSink) == type(uint256).max);
}

function testAccess(uint256 shares, uint256 assets, uint256 debt) public {
function testAccess(uint256 assets, uint256 debt) public {
vm.startPrank(notOwner);
vm.expectRevert(bytes4(keccak256(abi.encodePacked("RestrictedToOwner()"))));
vault.setFeeUnlockTime(1000);
Expand Down
Loading