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: remove interfaces from Market #213

Merged
merged 1 commit into from
Aug 2, 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
15 changes: 8 additions & 7 deletions src/Blue.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
import {Id, Market, Signature, IBlue} from "./interfaces/IBlue.sol";
import {IIrm} from "./interfaces/IIrm.sol";
import {IERC20} from "./interfaces/IERC20.sol";
import {IOracle} from "./interfaces/IOracle.sol";
import {IFlashBorrower} from "./interfaces/IFlashBorrower.sol";

import {Errors} from "./libraries/Errors.sol";
Expand Down Expand Up @@ -63,7 +64,7 @@ contract Blue is IBlue {
// Fee.
mapping(Id => uint256) public fee;
// Enabled IRMs.
mapping(IIrm => bool) public isIrmEnabled;
mapping(address => bool) public isIrmEnabled;
// Enabled LLTVs.
mapping(uint256 => bool) public isLltvEnabled;
// User's authorizations. Note that by default, msg.sender is authorized by themself.
Expand Down Expand Up @@ -92,7 +93,7 @@ contract Blue is IBlue {
owner = newOwner;
}

function enableIrm(IIrm irm) external onlyOwner {
function enableIrm(address irm) external onlyOwner {
Rubilmax marked this conversation as resolved.
Show resolved Hide resolved
isIrmEnabled[irm] = true;
}

Expand Down Expand Up @@ -246,8 +247,8 @@ contract Blue is IBlue {

_accrueInterests(market, id);

uint256 collateralPrice = market.collateralOracle.price();
uint256 borrowablePrice = market.borrowableOracle.price();
uint256 collateralPrice = IOracle(market.collateralOracle).price();
uint256 borrowablePrice = IOracle(market.borrowableOracle).price();

require(!_isHealthy(market, id, borrower, collateralPrice, borrowablePrice), Errors.HEALTHY_POSITION);

Expand Down Expand Up @@ -330,7 +331,7 @@ contract Blue is IBlue {
uint256 marketTotalBorrow = totalBorrow[id];

if (marketTotalBorrow != 0) {
uint256 borrowRate = market.irm.borrowRate(market);
uint256 borrowRate = IIrm(market.irm).borrowRate(market);
uint256 accruedInterests = marketTotalBorrow.mulWadDown(borrowRate * elapsed);
totalBorrow[id] = marketTotalBorrow + accruedInterests;
totalSupply[id] += accruedInterests;
Expand All @@ -352,8 +353,8 @@ contract Blue is IBlue {
function _isHealthy(Market memory market, Id id, address user) internal view returns (bool) {
if (borrowShare[id][user] == 0) return true;

uint256 collateralPrice = market.collateralOracle.price();
uint256 borrowablePrice = market.borrowableOracle.price();
uint256 collateralPrice = IOracle(market.collateralOracle).price();
uint256 borrowablePrice = IOracle(market.borrowableOracle).price();

return _isHealthy(market, id, user, collateralPrice, borrowablePrice);
}
Expand Down
12 changes: 5 additions & 7 deletions src/interfaces/IBlue.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0;

import {IIrm} from "./IIrm.sol";
import {IOracle} from "./IOracle.sol";
import {IFlashLender} from "./IFlashLender.sol";
import {IFlashBorrower} from "./IFlashBorrower.sol";

Expand All @@ -11,9 +9,9 @@ type Id is bytes32;
struct Market {
address borrowableAsset;
address collateralAsset;
IOracle borrowableOracle;
IOracle collateralOracle;
IIrm irm;
address borrowableOracle;
address collateralOracle;
address irm;
uint256 lltv;
}

Expand All @@ -40,13 +38,13 @@ interface IBlue is IFlashLender {
function lastUpdate(Id) external view returns (uint256);
function fee(Id) external view returns (uint256);

function isIrmEnabled(IIrm) external view returns (bool);
function isIrmEnabled(address) external view returns (bool);
function isLltvEnabled(uint256) external view returns (bool);
function isAuthorized(address, address) external view returns (bool);
function nonce(address) external view returns (uint256);

function setOwner(address newOwner) external;
function enableIrm(IIrm irm) external;
function enableIrm(address irm) external;
function enableLltv(uint256 lltv) external;
function setFee(Market memory market, uint256 newFee) external;
function setFeeRecipient(address recipient) external;
Expand Down
20 changes: 13 additions & 7 deletions test/forge/Blue.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@ contract BlueTest is

irm = new Irm(blue);

market =
Market(address(borrowableAsset), address(collateralAsset), borrowableOracle, collateralOracle, irm, LLTV);
market = Market(
address(borrowableAsset),
address(collateralAsset),
address(borrowableOracle),
address(collateralOracle),
address(irm),
LLTV
);
id = market.id();

vm.startPrank(OWNER);
blue.enableIrm(irm);
blue.enableIrm(address(irm));
blue.enableLltv(LLTV);
blue.createMarket(market);
vm.stopPrank();
Expand Down Expand Up @@ -145,15 +151,15 @@ contract BlueTest is
blue2.setOwner(newOwner);
}

function testEnableIrmWhenNotOwner(address attacker, IIrm newIrm) public {
function testEnableIrmWhenNotOwner(address attacker, address newIrm) public {
vm.assume(attacker != blue.owner());

vm.prank(attacker);
vm.expectRevert(bytes(Errors.NOT_OWNER));
blue.enableIrm(newIrm);
}

function testEnableIrm(IIrm newIrm) public {
function testEnableIrm(address newIrm) public {
vm.prank(OWNER);
blue.enableIrm(newIrm);

Expand All @@ -170,7 +176,7 @@ contract BlueTest is
}

function testCreateMarketWithNotEnabledIrm(Market memory marketFuzz) public {
vm.assume(marketFuzz.irm != irm);
vm.assume(marketFuzz.irm != address(irm));

vm.prank(OWNER);
vm.expectRevert(bytes(Errors.IRM_NOT_ENABLED));
Expand Down Expand Up @@ -291,7 +297,7 @@ contract BlueTest is

function testCreateMarketWithNotEnabledLltv(Market memory marketFuzz) public {
vm.assume(marketFuzz.lltv != LLTV);
marketFuzz.irm = irm;
marketFuzz.irm = address(irm);

vm.prank(OWNER);
vm.expectRevert(bytes(Errors.LLTV_NOT_ENABLED));
Expand Down