Skip to content

Commit

Permalink
🦺 market: prevent zero floating borrows
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez committed May 24, 2024
1 parent 25d0fe7 commit 4b4d6c5
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 162 deletions.
5 changes: 5 additions & 0 deletions .changeset/strange-cows-destroy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

🦺 market: prevent zero floating borrows
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

0 comments on commit 4b4d6c5

Please sign in to comment.