Skip to content

Commit 30aeb34

Browse files
Merge pull request #176 from morpho-labs/refactor/wad-constant
refactor(wad): remove wad constant declaration
2 parents 7e97f75 + 8bc8926 commit 30aeb34

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/Blue.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {FixedPointMathLib} from "src/libraries/FixedPointMathLib.sol";
1010
import {Id, Market, MarketLib} from "src/libraries/MarketLib.sol";
1111
import {SafeTransferLib} from "src/libraries/SafeTransferLib.sol";
1212

13-
uint256 constant WAD = 1e18;
1413
uint256 constant MAX_FEE = 0.25e18;
1514
uint256 constant ALPHA = 0.5e18;
1615

@@ -75,7 +74,7 @@ contract Blue {
7574
}
7675

7776
function enableLltv(uint256 lltv) external onlyOwner {
78-
require(lltv < WAD, Errors.LLTV_TOO_HIGH);
77+
require(lltv < FixedPointMathLib.WAD, Errors.LLTV_TOO_HIGH);
7978
isLltvEnabled[lltv] = true;
8079
}
8180

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

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

test/forge/Blue.t.sol

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ contract BlueTest is Test {
175175
}
176176

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

180180
vm.prank(OWNER);
181181
blue.enableLltv(newLltv);
@@ -184,7 +184,7 @@ contract BlueTest is Test {
184184
}
185185

186186
function testEnableLltvShouldFailWhenLltvTooHigh(uint256 newLltv) public {
187-
newLltv = bound(newLltv, WAD, type(uint256).max);
187+
newLltv = bound(newLltv, FixedPointMathLib.WAD, type(uint256).max);
188188

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

211211
function testSetFeeShouldRevertIfMarketNotCreated(Market memory marketFuzz, uint256 fee) public {
212212
vm.assume(neq(marketFuzz, market));
213-
fee = bound(fee, 0, WAD);
213+
fee = bound(fee, 0, FixedPointMathLib.WAD);
214214

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

220220
function testSetFeeShouldRevertIfNotOwner(uint256 fee, address caller) public {
221221
vm.assume(caller != OWNER);
222-
fee = bound(fee, 0, WAD);
222+
fee = bound(fee, 0, FixedPointMathLib.WAD);
223223

224224
vm.expectRevert("not owner");
225225
blue.setFee(market, fee);
@@ -486,7 +486,8 @@ contract BlueTest is Test {
486486
uint256 borrowingPower = amountCollateral.mulWadDown(LLTV);
487487
uint256 amountBorrowed = borrowingPower.mulWadDown(0.8e18);
488488
uint256 toSeize = amountCollateral.mulWadDown(LLTV);
489-
uint256 incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(LLTV) - WAD);
489+
uint256 incentive =
490+
FixedPointMathLib.WAD + ALPHA.mulWadDown(FixedPointMathLib.WAD.divWadDown(LLTV) - FixedPointMathLib.WAD);
490491

491492
borrowableAsset.setBalance(address(this), amountLent);
492493
collateralAsset.setBalance(BORROWER, amountCollateral);
@@ -529,7 +530,8 @@ contract BlueTest is Test {
529530
uint256 borrowingPower = amountCollateral.mulWadDown(LLTV);
530531
uint256 amountBorrowed = borrowingPower.mulWadDown(0.8e18);
531532
uint256 toSeize = amountCollateral;
532-
uint256 incentive = WAD + ALPHA.mulWadDown(WAD.divWadDown(market.lltv) - WAD);
533+
uint256 incentive = FixedPointMathLib.WAD
534+
+ ALPHA.mulWadDown(FixedPointMathLib.WAD.divWadDown(market.lltv) - FixedPointMathLib.WAD);
533535

534536
borrowableAsset.setBalance(address(this), amountLent);
535537
collateralAsset.setBalance(BORROWER, amountCollateral);

0 commit comments

Comments
 (0)