Skip to content

Commit

Permalink
🩹 market: round up fixed borrow fee
Browse files Browse the repository at this point in the history
  • Loading branch information
santichez authored and cruzdanilo committed May 25, 2024
1 parent 5d1a282 commit 20c0bfb
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 147 deletions.
5 changes: 5 additions & 0 deletions .changeset/soft-toys-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/protocol": patch
---

🩹 market: round up fixed borrow fee
272 changes: 136 additions & 136 deletions .gas-snapshot

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contracts/Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ contract Market is Initializable, AccessControlUpgradeable, PausableUpgradeable,
floatingUtilization(memFloatingAssetsAverage, memFloatingDebt),
globalUtilization(memFloatingAssetsAverage, memFloatingDebt, floatingBackupBorrowed)
);
fee = assets.mulWadDown(fixedRate.mulDivDown(maturity - block.timestamp, 365 days));
fee = assets.mulWadUp(fixedRate.mulDivDown(maturity - block.timestamp, 365 days));
}
assetsOwed = assets + fee;

Expand Down
2 changes: 1 addition & 1 deletion contracts/periphery/Previewer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ contract Previewer {
: pool.unassignedEarnings
);

uint256 fees = assets.mulWadDown(
uint256 fees = assets.mulWadUp(
market.interestRateModel().fixedBorrowRate(
maturity,
assets,
Expand Down
12 changes: 6 additions & 6 deletions test/Market.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ contract MarketTest is Test {
// ATTACKER deposits just 1 at maturity, claiming all the unassigned earnings
// by only providing 1 principal
uint256 positionAssets = market.depositAtMaturity(maturity, 1, 0, attacker);
assertEq(positionAssets, 1);
assertEq(positionAssets, 2);
}

function testBorrowFromFreeLunchShouldNotRevertWithFloatingFullUtilization() external {
Expand Down Expand Up @@ -1862,7 +1862,7 @@ contract MarketTest is Test {

vm.warp(2000);
market.deposit(100 ether, address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this));
assertApproxEqRel(market.floatingAssetsAverage(), initialBalance, 1e15);
assertEq(market.floatingAssets(), 100 ether + initialBalance);
}
Expand All @@ -1876,7 +1876,7 @@ contract MarketTest is Test {
uint256 lastFloatingAssetsAverage = market.floatingAssetsAverage();

vm.warp(250);
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this));
uint256 supplyAverageFactor = uint256(1e18 - FixedPointMathLib.expWad(-int256(market.dampSpeedUp() * (250 - 218))));
assertEq(
market.previewFloatingAssetsAverage(),
Expand All @@ -1886,7 +1886,7 @@ contract MarketTest is Test {
assertEq(market.previewFloatingAssetsAverage(), 20.521498717652997528 ether);

vm.warp(9541);
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this));
assertEq(market.previewFloatingAssetsAverage(), market.floatingAssets());
}

Expand Down Expand Up @@ -1917,7 +1917,7 @@ contract MarketTest is Test {

vm.warp(2000);
market.withdraw(5 ether, address(this), address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 1, address(this), address(this));
market.borrowAtMaturity(FixedLib.INTERVAL, 1, 2, address(this), address(this));
assertApproxEqRel(market.previewFloatingAssetsAverage(), initialBalance, 1e15);
assertEq(market.floatingAssets(), initialBalance - 5 ether);
}
Expand Down Expand Up @@ -2584,7 +2584,7 @@ contract MarketTest is Test {

// contract can cover all debt by repaying less than initial amount borrowed (93 < 100)
(uint256 principal, uint256 fee) = market.fixedBorrowPositions(FixedLib.INTERVAL, address(this));
market.repayAtMaturity(FixedLib.INTERVAL, principal + fee, 93, address(this));
market.repayAtMaturity(FixedLib.INTERVAL, principal + fee, 94, address(this));
}

function testClearMaturity() external {
Expand Down
4 changes: 2 additions & 2 deletions test/Previewer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -294,15 +294,15 @@ contract PreviewerTest is Test {
vm.warp(100 seconds);
market.deposit(5 ether, address(this));
Previewer.FixedPreview memory preview = previewer.previewBorrowAtMaturity(market, FixedLib.INTERVAL, 1);
assertEq(preview.assets, 1);
assertEq(preview.assets, 2);
}

function testPreviewBorrowAtMaturityWithFiveUnits() external {
market.deposit(5 ether, address(this));
vm.warp(100 seconds);
market.deposit(5 ether, address(this));
Previewer.FixedPreview memory preview = previewer.previewBorrowAtMaturity(market, FixedLib.INTERVAL, 5);
assertEq(preview.assets, 5);
assertEq(preview.assets, 6);
}

function testPreviewBorrowAtMaturityReturningAccurateAmountWithIntermediateOperations() external {
Expand Down
2 changes: 1 addition & 1 deletion test/hardhat/1_auditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe("Auditor from Account Space", function () {
await auditor.enterMarket(marketDAI.target);
await priceFeedDAI.setPrice(0);
await expect(
marketDAI.borrowAtMaturity(pools[0], 1, 1, account.address, account.address),
marketDAI.borrowAtMaturity(pools[0], 1, 2, account.address, account.address),
).to.be.revertedWithCustomError(auditor, "InvalidPrice");
});

Expand Down

0 comments on commit 20c0bfb

Please sign in to comment.