From 1664135e1d229a37e3daa9d1df05499d51d5bcac Mon Sep 17 00:00:00 2001 From: Hayden Shively <17186559+haydenshively@users.noreply.github.com> Date: Thu, 15 Aug 2024 23:53:45 -0500 Subject: [PATCH] Require initial deposit to be larger than 1e5 units (#240) --- core/src/Lender.sol | 1 + core/test/Lender.t.sol | 12 ++++++++++-- core/test/LenderReferrals.t.sol | 16 ++++++++-------- core/test/invariants/ERC4626Harness.sol | 3 ++- core/test/invariants/LenderHarness.sol | 3 ++- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/core/src/Lender.sol b/core/src/Lender.sol index 1449e46..1fab04b 100644 --- a/core/src/Lender.sol +++ b/core/src/Lender.sol @@ -144,6 +144,7 @@ contract Lender is Ledger { // Mint shares, track rewards, and (if applicable) handle courier accounting cache.totalSupply = _mint(beneficiary, shares, amount, cache.totalSupply, courierId); + require(cache.totalSupply > 1e5); // Assume tokens are transferred cache.lastBalance += amount; diff --git a/core/test/Lender.t.sol b/core/test/Lender.t.sol index 06c1747..afa484a 100644 --- a/core/test/Lender.t.sol +++ b/core/test/Lender.t.sol @@ -148,7 +148,7 @@ contract LenderTest is Test { } function test_cannotDepositWithoutERC20Transfer(uint112 amount, address to) public { - if (amount == 0) amount++; + if (amount <= 1e5) amount = 1e5 + 1; deal(address(asset), address(lender), amount - 1); vm.expectRevert(bytes("TRANSFER_FROM_FAILED")); @@ -156,7 +156,7 @@ contract LenderTest is Test { } function test_previewAndDeposit(uint112 amount, address to) public { - if (amount == 0) amount++; + if (amount <= 1e5) amount = 1e5 + 1; uint256 expectedShares = lender.previewDeposit(amount); uint256 totalSupply = lender.totalSupply(); @@ -186,11 +186,19 @@ contract LenderTest is Test { if (amountA == 0) { vm.expectRevert(bytes("Aloe: zero impact")); lender.deposit(amountA, toA); + } else if (amountA <= 1e5) { + vm.expectRevert(bytes("")); + lender.deposit(amountA, toA); + return; } else lender.deposit(amountA, toA); if (amountB == 0) { vm.expectRevert(bytes("Aloe: zero impact")); lender.deposit(amountB, toB); + } else if (lender.totalSupply() + amountB <= 1e5) { + vm.expectRevert(bytes("")); + lender.deposit(amountB, toB); + return; } else lender.deposit(amountB, toB); assertEq(lender.underlyingBalance(toA), amountA); diff --git a/core/test/LenderReferrals.t.sol b/core/test/LenderReferrals.t.sol index ca7e173..a2f2a6f 100644 --- a/core/test/LenderReferrals.t.sol +++ b/core/test/LenderReferrals.t.sol @@ -95,9 +95,9 @@ contract LenderReferralsTest is Test { (id, wallet, cut) = _enroll(id, wallet, cut); vm.assume(wallet != address(this)); - deal(address(asset), address(lender), 1); + deal(address(asset), address(lender), 1e5 + 1); - lender.deposit(1, address(this), id); + lender.deposit(1e5 + 1, address(this), id); assertEq(lender.courierOf(address(this)), id); } @@ -106,11 +106,11 @@ contract LenderReferralsTest is Test { vm.assume(wallet != account && account != lender.RESERVE()); vm.prank(account); - lender.approve(address(this), 1); + lender.approve(address(this), 1e5 + 1); - deal(address(asset), address(lender), 1); + deal(address(asset), address(lender), 1e5 + 1); - lender.deposit(1, account, id); + lender.deposit(1e5 + 1, account, id); assertEq(lender.courierOf(account), id); } @@ -153,9 +153,9 @@ contract LenderReferralsTest is Test { lender.approve(address(this), 1); deal(address(lender), account, 1); - deal(address(asset), address(lender), 1); + deal(address(asset), address(lender), 1e5 + 1); - lender.deposit(1, account, id); + lender.deposit(1e5 + 1, account, id); assertEq(lender.courierOf(account), 0); } @@ -166,7 +166,7 @@ contract LenderReferralsTest is Test { address caller, uint112 amount ) public { - vm.assume(amount > 1); + vm.assume(amount > 1e6); (id, wallet, cut) = _enroll(id, wallet, cut); address to = caller; diff --git a/core/test/invariants/ERC4626Harness.sol b/core/test/invariants/ERC4626Harness.sol index ea43833..d26084e 100644 --- a/core/test/invariants/ERC4626Harness.sol +++ b/core/test/invariants/ERC4626Harness.sol @@ -79,6 +79,7 @@ contract ERC4626Harness { // MUST return as close to and no more than the exact amount of shares that would be minted in a `deposit` call shares = VAULT.previewDeposit(amount); + if (shares <= 1e5) return 0; // Make sure `msg.sender` has enough assets to deposit if (amount > balance) { @@ -132,7 +133,7 @@ contract ERC4626Harness { } function mint(uint256 shares, address receiver, bool shouldPrepay) public returns (uint256 amount) { - shares = shares % (VAULT.maxMint(msg.sender) + 1); // TODO: if remove this, could run with reverts allowed + shares = 1e5 + 1 + (shares % (VAULT.maxMint(msg.sender) - 1e5)); // TODO: if remove this, could run with reverts allowed ERC20 asset = VAULT.asset(); uint256 balance = asset.balanceOf(msg.sender); diff --git a/core/test/invariants/LenderHarness.sol b/core/test/invariants/LenderHarness.sol index 5efc8e9..fd87931 100644 --- a/core/test/invariants/LenderHarness.sol +++ b/core/test/invariants/LenderHarness.sol @@ -115,7 +115,7 @@ contract LenderHarness { return; } - uint256 amount = LENDER.convertToAssets(1) + 1; + uint256 amount = LENDER.convertToAssets(1e5 + 1) + 1; MockERC20 mock = MockERC20(address(LENDER.asset())); mock.mint(address(LENDER), amount); @@ -163,6 +163,7 @@ contract LenderHarness { /// @notice Deposits `amount` and sends new `shares` to `beneficiary` function deposit(uint112 amount, address beneficiary) public returns (uint256 shares) { amount = uint112(amount % (LENDER.maxDeposit(msg.sender) + 1)); + if (amount <= 1e5) amount = 1e5 + 1; ERC20 asset = LENDER.asset(); uint256 free = asset.balanceOf(address(LENDER)) - LENDER.lastBalance();