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

refactor(wad): remove wad constant declaration #176

Merged
merged 3 commits into from
Jul 28, 2023
Merged
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
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);
MerlinEgalite marked this conversation as resolved.
Show resolved Hide resolved
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