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

🦺 market: prevent zero floating borrows #719

Closed
wants to merge 1 commit into from
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
319 changes: 160 additions & 159 deletions .gas-snapshot

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
address receiver,
address borrower
) external whenNotPaused whenNotFrozen returns (uint256 borrowShares) {
if (assets == 0) revert ZeroBorrow();
spendAllowance(borrower, assets);

RewardsController memRewardsController = rewardsController;
Expand Down
4 changes: 3 additions & 1 deletion test/InterestRateModel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ contract InterestRateModelTest is Test {
asset.approve(address(market), type(uint128).max);
if (floatingAssets != 0) market.deposit(floatingAssets, address(this));
vm.warp(timestamp);
market.borrow(floatingDebt, address(this), address(this));
if (floatingDebt != 0) {
market.borrow(floatingDebt, address(this), address(this));
}

Vars memory v;
v.backupBorrowed = 0;
Expand Down
5 changes: 5 additions & 0 deletions test/Market.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ contract MarketTest is Test {
market.borrowAtMaturity(FixedLib.INTERVAL, 0, 0, address(this), address(this));
}

function testBorrowWithZeroAssets() external {
vm.expectRevert(ZeroBorrow.selector);
market.borrow(0, address(this), BOB);
}

function testDepositAtMaturityWithZeroAssets() external {
vm.expectRevert(ZeroDeposit.selector);
market.depositAtMaturity(FixedLib.INTERVAL, 0, 0, address(this));
Expand Down
2 changes: 1 addition & 1 deletion test/Previewer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ contract PreviewerTest is Test {
market.deposit(10_000 ether, address(this));
market.borrow(2_000 ether, address(this), address(this));
vm.warp(block.timestamp + 1 weeks);
market.borrow(0, address(this), address(this));
market.borrow(1, address(this), address(this));
Previewer.MarketAccount[] memory data = previewer.exactly(address(this));
assertEq(data[0].rewardRates.length, 1);
assertEq(data[0].rewardRates[0].maturities.length, 12);
Expand Down
4 changes: 3 additions & 1 deletion test/Protocol.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ contract ProtocolTest is Test {
uint256 expectedShares = market.previewBorrow(assets);
(uint256 collateral, uint256 debt) = previewAccountLiquidity(account, market, assets, expectedShares);

if (
if (assets == 0) {
vm.expectRevert(ZeroBorrow.selector);
} else if (
market.floatingBackupBorrowed() + market.totalFloatingBorrowAssets() + assets >
(market.floatingAssets() + previewNewFloatingDebt(market)).mulWadDown(1e18 - RESERVE_FACTOR)
) {
Expand Down
Loading