Skip to content

Commit

Permalink
Merge pull request #176 from morpho-labs/refactor/wad-constant
Browse files Browse the repository at this point in the history
refactor(wad): remove wad constant declaration
  • Loading branch information
MerlinEgalite committed Jul 28, 2023
2 parents 7e97f75 + 8bc8926 commit 30aeb34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {FixedPointMathLib} from "src/libraries/FixedPointMathLib.sol";
import {Id, Market, MarketLib} from "src/libraries/MarketLib.sol";
import {SafeTransferLib} from "src/libraries/SafeTransferLib.sol";

uint256 constant WAD = 1e18;
uint256 constant MAX_FEE = 0.25e18;
uint256 constant ALPHA = 0.5e18;

Expand Down Expand Up @@ -75,7 +74,7 @@ contract Blue {
}

function enableLltv(uint256 lltv) external onlyOwner {
require(lltv < WAD, Errors.LLTV_TOO_HIGH);
require(lltv < FixedPointMathLib.WAD, Errors.LLTV_TOO_HIGH);
isLltvEnabled[lltv] = true;
}

Expand Down Expand Up @@ -222,7 +221,8 @@ contract Blue {
require(!_isHealthy(market, id, borrower, collateralPrice, borrowablePrice), Errors.HEALTHY_POSITION);

// The liquidation incentive is 1 + ALPHA * (1 / LLTV - 1).
uint256 incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(market.lltv) - WAD);
uint256 incentive = FixedPointMathLib.WAD
+ ALPHA.mulWadDown(FixedPointMathLib.WAD.divWadDown(market.lltv) - FixedPointMathLib.WAD);
uint256 repaid = seized.mulWadUp(collateralPrice).divWadUp(incentive).divWadUp(borrowablePrice);
uint256 repaidShares = repaid.toSharesDown(totalBorrow[id], totalBorrowShares[id]);

Expand Down
14 changes: 8 additions & 6 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ contract BlueTest is Test {
}

function testEnableLltv(uint256 newLltv) public {
newLltv = bound(newLltv, 0, WAD - 1);
newLltv = bound(newLltv, 0, FixedPointMathLib.WAD - 1);

vm.prank(OWNER);
blue.enableLltv(newLltv);
Expand All @@ -184,7 +184,7 @@ contract BlueTest is Test {
}

function testEnableLltvShouldFailWhenLltvTooHigh(uint256 newLltv) public {
newLltv = bound(newLltv, WAD, type(uint256).max);
newLltv = bound(newLltv, FixedPointMathLib.WAD, type(uint256).max);

vm.prank(OWNER);
vm.expectRevert(bytes(Errors.LLTV_TOO_HIGH));
Expand All @@ -210,7 +210,7 @@ contract BlueTest is Test {

function testSetFeeShouldRevertIfMarketNotCreated(Market memory marketFuzz, uint256 fee) public {
vm.assume(neq(marketFuzz, market));
fee = bound(fee, 0, WAD);
fee = bound(fee, 0, FixedPointMathLib.WAD);

vm.prank(OWNER);
vm.expectRevert("unknown market");
Expand All @@ -219,7 +219,7 @@ contract BlueTest is Test {

function testSetFeeShouldRevertIfNotOwner(uint256 fee, address caller) public {
vm.assume(caller != OWNER);
fee = bound(fee, 0, WAD);
fee = bound(fee, 0, FixedPointMathLib.WAD);

vm.expectRevert("not owner");
blue.setFee(market, fee);
Expand Down Expand Up @@ -486,7 +486,8 @@ contract BlueTest is Test {
uint256 borrowingPower = amountCollateral.mulWadDown(LLTV);
uint256 amountBorrowed = borrowingPower.mulWadDown(0.8e18);
uint256 toSeize = amountCollateral.mulWadDown(LLTV);
uint256 incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(LLTV) - WAD);
uint256 incentive =
FixedPointMathLib.WAD + ALPHA.mulWadDown(FixedPointMathLib.WAD.divWadDown(LLTV) - FixedPointMathLib.WAD);

borrowableAsset.setBalance(address(this), amountLent);
collateralAsset.setBalance(BORROWER, amountCollateral);
Expand Down Expand Up @@ -529,7 +530,8 @@ contract BlueTest is Test {
uint256 borrowingPower = amountCollateral.mulWadDown(LLTV);
uint256 amountBorrowed = borrowingPower.mulWadDown(0.8e18);
uint256 toSeize = amountCollateral;
uint256 incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(market.lltv) - WAD);
uint256 incentive = FixedPointMathLib.WAD
+ ALPHA.mulWadDown(FixedPointMathLib.WAD.divWadDown(market.lltv) - FixedPointMathLib.WAD);

borrowableAsset.setBalance(address(this), amountLent);
collateralAsset.setBalance(BORROWER, amountCollateral);
Expand Down

0 comments on commit 30aeb34

Please sign in to comment.