Skip to content

Commit

Permalink
Merge branch 'main' of github.com:morpho-labs/morpho-blue into refact…
Browse files Browse the repository at this point in the history
…or/blue-to-morpho
  • Loading branch information
MerlinEgalite committed Aug 11, 2023
2 parents 880a662 + 72b32d5 commit 6a7513a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/Morpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ contract Morpho is IMorpho {
/// @inheritdoc IMorpho
function supply(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
external
returns (uint256, uint256)
{
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -177,11 +178,14 @@ contract Morpho is IMorpho {
if (data.length > 0) IMorphoSupplyCallback(msg.sender).onMorphoSupply(amount, data);

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

return (amount, shares);
}

/// @inheritdoc IMorpho
function withdraw(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external
returns (uint256, uint256)
{
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -204,13 +208,16 @@ contract Morpho is IMorpho {
require(totalBorrow[id] <= totalSupply[id], ErrorsLib.INSUFFICIENT_LIQUIDITY);

IERC20(market.borrowableAsset).safeTransfer(receiver, amount);

return (amount, shares);
}

/* BORROW MANAGEMENT */

/// @inheritdoc IMorpho
function borrow(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external
returns (uint256, uint256)
{
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -234,11 +241,14 @@ contract Morpho is IMorpho {
require(totalBorrow[id] <= totalSupply[id], ErrorsLib.INSUFFICIENT_LIQUIDITY);

IERC20(market.borrowableAsset).safeTransfer(receiver, amount);

return (amount, shares);
}

/// @inheritdoc IMorpho
function repay(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes calldata data)
external
returns (uint256, uint256)
{
Id id = market.id();
require(lastUpdate[id] != 0, ErrorsLib.MARKET_NOT_CREATED);
Expand All @@ -259,6 +269,8 @@ contract Morpho is IMorpho {
if (data.length > 0) IMorphoRepayCallback(msg.sender).onMorphoRepay(amount, data);

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

return (amount, shares);
}

/* COLLATERAL MANAGEMENT */
Expand Down
20 changes: 16 additions & 4 deletions src/interfaces/IMorpho.sol
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,11 @@ interface IMorpho is IFlashLender {
/// @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 `onMorphoSupply` callback. Pass empty data if not needed.
/// @return amountSupplied The amount of assets supplied.
/// @return sharesSupplied The amount of shares supplied.
function supply(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes memory data)
external;
external
returns (uint256 amountSupplied, uint256 sharesSupplied);

/// @notice Withdraws the given `amount` of assets or `shares` from the given `market` on behalf of `onBehalf`.
/// @dev Either `amount` or `shares` should be zero.
Expand All @@ -126,8 +129,11 @@ interface IMorpho is IFlashLender {
/// @param shares The amount of shares to burn.
/// @param onBehalf The address of the owner of the withdrawn assets.
/// @param receiver The address that will receive the withdrawn assets.
/// @return amountWithdrawn The amount of assets withdrawn.
/// @return sharesWithdrawn The amount of shares withdrawn.
function withdraw(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external;
external
returns (uint256 amountWithdrawn, uint256 sharesWithdrawn);

/// @notice Borrows the given `amount` of assets or `shares` from the given `market` on behalf of `onBehalf`.
/// @dev Either `amount` or `shares` should be zero.
Expand All @@ -141,8 +147,11 @@ interface IMorpho is IFlashLender {
/// @param shares The amount of shares to mint.
/// @param onBehalf The address of the owner of the debt.
/// @param receiver The address that will receive the debt.
/// @return amountBorrowed The amount of assets borrowed.
/// @return sharesBorrowed The amount of shares borrowed.
function borrow(Market memory market, uint256 amount, uint256 shares, address onBehalf, address receiver)
external;
external
returns (uint256 amountBorrowed, uint256 sharesBorrowed);

/// @notice Repays the given `amount` of assets or `shares` to the given `market` on behalf of `onBehalf`,
/// optionally calling back the caller's `onMorphoReplay` function with the given `data`.
Expand All @@ -153,8 +162,11 @@ interface IMorpho is IFlashLender {
/// @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 `onMorphoRepay` callback. Pass empty data if not needed.
/// @return amountRepaid The amount of assets repaid.
/// @return sharesRepaid The amount of shares repaid.
function repay(Market memory market, uint256 amount, uint256 shares, address onBehalf, bytes memory data)
external;
external
returns (uint256 amountRepaid, uint256 sharesRepaid);

/// @notice Supplies the given `amount` of collateral to the given `market` on behalf of `onBehalf`,
/// optionally calling back the caller's `onMorphoSupplyCollateral` function with the given `data`.
Expand Down

0 comments on commit 6a7513a

Please sign in to comment.