Skip to content

Commit

Permalink
Require initial deposit to be larger than 1e5 units (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenshively authored Aug 16, 2024
1 parent e384e90 commit 1664135
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
1 change: 1 addition & 0 deletions core/src/Lender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 10 additions & 2 deletions core/test/Lender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,15 @@ 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"));
lender.deposit(amount, to);
}

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();
Expand Down Expand Up @@ -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);
Expand Down
16 changes: 8 additions & 8 deletions core/test/LenderReferrals.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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;

Expand Down
3 changes: 2 additions & 1 deletion core/test/invariants/ERC4626Harness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 2 additions & 1 deletion core/test/invariants/LenderHarness.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1664135

Please sign in to comment.