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

Rename Blue to Morpho #270

Merged
merged 2 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
86 changes: 43 additions & 43 deletions src/Blue.sol → src/Morpho.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.21;

import "./interfaces/IBlue.sol";
import "./interfaces/IBlueCallbacks.sol";
import "./interfaces/IMorpho.sol";
import "./interfaces/IMorphoCallbacks.sol";
import {IIrm} from "./interfaces/IIrm.sol";
import {IERC20} from "./interfaces/IERC20.sol";
import {IOracle} from "./interfaces/IOracle.sol";
Expand All @@ -27,52 +27,52 @@ bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(string name,uint256 c
bytes32 constant AUTHORIZATION_TYPEHASH =
keccak256("Authorization(address authorizer,address authorized,bool isAuthorized,uint256 nonce,uint256 deadline)");

/// @title Blue
/// @title Morpho
/// @author Morpho Labs
/// @custom:contact security@morpho.xyz
/// @notice The Blue contract.
contract Blue is IBlue {
/// @notice The Morpho contract.
contract Morpho is IMorpho {
using MarketLib for Market;
using SharesMathLib for uint256;
using SafeTransferLib for IERC20;
using FixedPointMathLib for uint256;

/* IMMUTABLES */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
bytes32 public immutable DOMAIN_SEPARATOR;

/* STORAGE */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
address public owner;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
address public feeRecipient;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => mapping(address => uint256)) public supplyShares;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => mapping(address => uint256)) public borrowShares;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => mapping(address => uint256)) public collateral;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public totalSupply;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public totalSupplyShares;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public totalBorrow;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public totalBorrowShares;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public lastUpdate;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(Id => uint256) public fee;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(address => bool) public isIrmEnabled;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(uint256 => bool) public isLltvEnabled;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(address => mapping(address => bool)) public isAuthorized;
/// @inheritdoc IBlue
/// @inheritdoc IMorpho
mapping(address => uint256) public nonce;

/* CONSTRUCTOR */
Expand All @@ -82,7 +82,7 @@ contract Blue is IBlue {
constructor(address newOwner) {
owner = newOwner;

DOMAIN_SEPARATOR = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("Blue"), block.chainid, address(this)));
DOMAIN_SEPARATOR = keccak256(abi.encode(DOMAIN_TYPEHASH, keccak256("Morpho"), block.chainid, address(this)));
}

/* MODIFIERS */
Expand All @@ -95,29 +95,29 @@ contract Blue is IBlue {

/* ONLY OWNER FUNCTIONS */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function setOwner(address newOwner) external onlyOwner {
owner = newOwner;

emit EventsLib.SetOwner(newOwner);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function enableIrm(address irm) external onlyOwner {
isIrmEnabled[irm] = true;

emit EventsLib.EnableIrm(address(irm));
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function enableLltv(uint256 lltv) external onlyOwner {
require(lltv < WAD, ErrorsLib.LLTV_TOO_HIGH);
isLltvEnabled[lltv] = true;

emit EventsLib.EnableLltv(lltv);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function setFee(Market memory market, uint256 newFee) external onlyOwner {
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -131,7 +131,7 @@ contract Blue is IBlue {
emit EventsLib.SetFee(id, newFee);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function setFeeRecipient(address recipient) external onlyOwner {
feeRecipient = recipient;

Expand All @@ -140,7 +140,7 @@ contract Blue is IBlue {

/* MARKET CREATION */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function createMarket(Market memory market) external {
Id id = market.id();
require(isIrmEnabled[market.irm], ErrorsLib.IRM_NOT_ENABLED);
Expand All @@ -154,7 +154,7 @@ contract Blue is IBlue {

/* SUPPLY MANAGEMENT */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function supply(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
external
{
Expand All @@ -174,12 +174,12 @@ contract Blue is IBlue {

emit EventsLib.Supply(id, msg.sender, onBehalf, amount, shares);

if (data.length > 0) IBlueSupplyCallback(msg.sender).onBlueSupply(amount, data);
if (data.length > 0) IMorphoSupplyCallback(msg.sender).onMorphoSupply(amount, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), amount);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function withdraw(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external
{
Expand Down Expand Up @@ -208,7 +208,7 @@ contract Blue is IBlue {

/* BORROW MANAGEMENT */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function borrow(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external
{
Expand Down Expand Up @@ -236,7 +236,7 @@ contract Blue is IBlue {
IERC20(market.borrowableAsset).safeTransfer(receiver, amount);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function repay(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
external
{
Expand All @@ -256,14 +256,14 @@ contract Blue is IBlue {

emit EventsLib.Repay(id, msg.sender, onBehalf, amount, shares);

if (data.length > 0) IBlueRepayCallback(msg.sender).onBlueRepay(amount, data);
if (data.length > 0) IMorphoRepayCallback(msg.sender).onMorphoRepay(amount, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), amount);
}

/* COLLATERAL MANAGEMENT */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function supplyCollateral(Market memory market, uint256 amount, address onBehalf, bytes calldata data) external {
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -276,12 +276,12 @@ contract Blue is IBlue {

emit EventsLib.SupplyCollateral(id, msg.sender, onBehalf, amount);

if (data.length > 0) IBlueSupplyCollateralCallback(msg.sender).onBlueSupplyCollateral(amount, data);
if (data.length > 0) IMorphoSupplyCollateralCallback(msg.sender).onMorphoSupplyCollateral(amount, data);

IERC20(market.collateralAsset).safeTransferFrom(msg.sender, address(this), amount);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function withdrawCollateral(Market memory market, uint256 amount, address onBehalf, address receiver) external {
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -303,7 +303,7 @@ contract Blue is IBlue {

/* LIQUIDATION */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function liquidate(Market memory market, address borrower, uint256 seized, bytes calldata data) external {
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand Down Expand Up @@ -341,7 +341,7 @@ contract Blue is IBlue {

emit EventsLib.Liquidate(id, msg.sender, borrower, repaid, repaidShares, seized, badDebtShares);

if (data.length > 0) IBlueLiquidateCallback(msg.sender).onBlueLiquidate(repaid, data);
if (data.length > 0) IMorphoLiquidateCallback(msg.sender).onMorphoLiquidate(repaid, data);

IERC20(market.borrowableAsset).safeTransferFrom(msg.sender, address(this), repaid);
}
Expand All @@ -354,21 +354,21 @@ contract Blue is IBlue {

emit EventsLib.FlashLoan(msg.sender, token, amount);

IBlueFlashLoanCallback(msg.sender).onBlueFlashLoan(amount, data);
IMorphoFlashLoanCallback(msg.sender).onMorphoFlashLoan(amount, data);

IERC20(token).safeTransferFrom(msg.sender, address(this), amount);
}

/* AUTHORIZATION */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function setAuthorization(address authorized, bool newIsAuthorized) external {
isAuthorized[msg.sender][authorized] = newIsAuthorized;

emit EventsLib.SetAuthorization(msg.sender, msg.sender, authorized, newIsAuthorized);
}

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
/// @dev The signature is malleable, but it has no impact on the security here.
function setAuthorizationWithSig(
address authorizer,
Expand Down Expand Up @@ -454,7 +454,7 @@ contract Blue is IBlue {

/* STORAGE VIEW */

/// @inheritdoc IBlue
/// @inheritdoc IMorpho
function extsload(bytes32[] calldata slots) external view returns (bytes32[] memory res) {
uint256 nSlots = slots.length;

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/IFlashLender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ interface IFlashLender {
/// @notice Executes a flash loan.
/// @param token The token to flash loan.
/// @param amount The amount to flash loan.
/// @param data Arbitrary data to pass to the `onBlueFlashLoan` callback.
/// @param data Arbitrary data to pass to the `onMorphoFlashLoan` callback.
function flashLoan(address token, uint256 amount, bytes calldata data) external;
}
4 changes: 2 additions & 2 deletions src/interfaces/IIrm.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.5.0;

import {Market} from "./IBlue.sol";
import {Market} from "./IMorpho.sol";

/// @title IIrm
/// @author Morpho Labs
/// @custom:contact security@morpho.xyz
/// @notice Interface that IRMs used by Blue must implement.
/// @notice Interface that IRMs used by Morpho must implement.
interface IIrm {
/// @notice Returns the borrow rate of a `market`.
function borrowRate(Market memory market) external returns (uint256);
Expand Down
22 changes: 11 additions & 11 deletions src/interfaces/IBlue.sol → src/interfaces/IMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ struct Signature {
bytes32 s;
}

/// @title IBlue
/// @title IMorpho
/// @author Morpho Labs
/// @custom:contact security@morpho.xyz
/// @notice Interface of Blue.
interface IBlue is IFlashLender {
/// @notice Interface of Morpho.
interface IMorpho is IFlashLender {
/// @notice The EIP-712 domain separator.
function DOMAIN_SEPARATOR() external view returns (bytes32);

Expand Down Expand Up @@ -103,7 +103,7 @@ interface IBlue is IFlashLender {
function createMarket(Market memory market) external;

/// @notice Supplies the given `amount` of assets or `shares` to the given `market` on behalf of `onBehalf`,
/// optionally calling back the caller's `onBlueSupply` function with the given `data`.
/// optionally calling back the caller's `onMorphoSupply` function with the given `data`.
/// @dev Either `amount` or `shares` should be zero.
/// Most usecases should rely on `amount` as an input so the caller
/// is guaranteed to have `amount` tokens pulled from their balance,
Expand All @@ -113,7 +113,7 @@ interface IBlue is IFlashLender {
/// @param amount The amount of assets to supply.
/// @param shares The amount of shares to mint.
/// @param onBehalf The address that will receive the position.
/// @param data Arbitrary data to pass to the `onBlueSupply` callback. Pass empty data if not needed.
/// @param data Arbitrary data to pass to the `onMorphoSupply` callback. Pass empty data if not needed.
function supply(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes memory data)
external;

Expand Down Expand Up @@ -145,24 +145,24 @@ interface IBlue is IFlashLender {
external;

/// @notice Repays the given `amount` of assets or `shares` to the given `market` on behalf of `onBehalf`,
/// optionally calling back the caller's `onBlueReplay` function with the given `data`.
/// optionally calling back the caller's `onMorphoReplay` function with the given `data`.
/// @dev Either `amount` or `shares` should be zero.
/// To repay the whole debt, pass the `shares`'s balance of `onBehalf`.
/// @param market The market to repay assets to.
/// @param amount The amount of assets to repay.
/// @param shares The amount of shares to burn.
/// @param onBehalf The address of the owner of the debt.
/// @param data Arbitrary data to pass to the `onBlueRepay` callback. Pass empty data if not needed.
/// @param data Arbitrary data to pass to the `onMorphoRepay` callback. Pass empty data if not needed.
function repay(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes memory data)
external;

/// @notice Supplies the given `amount` of collateral to the given `market` on behalf of `onBehalf`,
/// optionally calling back the caller's `onBlueSupplyCollateral` function with the given `data`.
/// optionally calling back the caller's `onMorphoSupplyCollateral` function with the given `data`.
/// @dev Interests are not accrued since it's not required and it saves gas.
/// @param market The market to supply collateral to.
/// @param amount The amount of collateral to supply.
/// @param onBehalf The address that will receive the collateral.
/// @param data Arbitrary data to pass to the `onBlueSupplyCollateral` callback. Pass empty data if not needed.
/// @param data Arbitrary data to pass to the `onMorphoSupplyCollateral` callback. Pass empty data if not needed.
function supplyCollateral(Market memory market, uint256 amount, address onBehalf, bytes memory data) external;

/// @notice Withdraws the given `amount` of collateral from the given `market` on behalf of `onBehalf`.
Expand All @@ -174,11 +174,11 @@ interface IBlue is IFlashLender {
function withdrawCollateral(Market memory market, uint256 amount, address onBehalf, address receiver) external;

/// @notice Liquidates the given `seized` amount to the given `market` of the given `borrower`'s position,
/// optionally calling back the caller's `onBlueLiquidate` function with the given `data`.
/// optionally calling back the caller's `onMorphoLiquidate` function with the given `data`.
/// @param market The market of the position.
/// @param borrower The owner of the position.
/// @param seized The amount of collateral to seize.
/// @param data Arbitrary data to pass to the `onBlueLiquidate` callback. Pass empty data if not needed
/// @param data Arbitrary data to pass to the `onMorphoLiquidate` callback. Pass empty data if not needed
function liquidate(Market memory market, address borrower, uint256 seized, bytes memory data) external;

/// @notice Sets the authorization for `authorized` to manage `msg.sender`'s positions.
Expand Down
Loading