Skip to content

Commit

Permalink
feat: morpho blue integration
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrocheleau authored Apr 18, 2024
1 parent 72b2ec4 commit 80f5257
Show file tree
Hide file tree
Showing 16 changed files with 1,556 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Install foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly-563e0624ba5a4a317202b4c9bc1d0120ed7c49f0
version: nightly-f625d0fa7c51e65b4bf1e8f7931cd1c6e2e285e9

- name: Display config
run: forge config
Expand Down
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "lib/morpho-blue"]
path = lib/morpho-blue
url = https://github.com/morpho-org/morpho-blue
[submodule "lib/openzeppelin-solc-0.6"]
path = lib/openzeppelin-solc-0.6
url = https://github.com/openzeppelin/openzeppelin-contracts
Expand All @@ -24,3 +27,4 @@
path = lib/uniswap-v3-periphery-0.8
url = https://github.com/Uniswap/v3-periphery.git
branch = 0.8

88 changes: 88 additions & 0 deletions contracts/external-interfaces/IMorphoBlue.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
This file is part of the Enzyme Protocol.
(c) Enzyme Council <council@enzyme.finance>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/

// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.6.0 <0.9.0;

/// @title IMorphoBlue Interface
/// @author Enzyme Council <security@enzyme.finance>
interface IMorphoBlue {
struct MarketParams {
address loanToken;
address collateralToken;
address oracle;
address irm;
uint256 lltv;
}

struct Position {
uint256 supplyShares;
uint128 borrowShares;
uint128 collateral;
}

struct Market {
uint128 totalSupplyAssets;
uint128 totalSupplyShares;
uint128 totalBorrowAssets;
uint128 totalBorrowShares;
uint128 lastUpdate;
uint128 fee;
}

function supply(
MarketParams memory _marketParams,
uint256 _assets,
uint256 _shares,
address _onBehalf,
bytes memory _data
) external returns (uint256 assetsSupplied_, uint256 sharesSupplied_);

function withdraw(
MarketParams memory _marketParams,
uint256 _assets,
uint256 _shares,
address _onBehalf,
address _receiver
) external returns (uint256 assetsWithdrawn_, uint256 sharesWithdrawn_);

function borrow(
MarketParams memory _marketParams,
uint256 _assets,
uint256 _shares,
address _onBehalf,
address _receiver
) external returns (uint256 assetsBorrowed_, uint256 sharesBorrowed_);

function repay(
MarketParams memory _marketParams,
uint256 _assets,
uint256 _shares,
address _onBehalf,
bytes memory _data
) external returns (uint256 assetsRepaid_, uint256 sharesRepaid_);

function supplyCollateral(MarketParams memory _marketParams, uint256 _assets, address _onBehalf, bytes memory _data)
external;

function withdrawCollateral(
MarketParams memory _marketParams,
uint256 _assets,
address _onBehalf,
address _receiver
) external;

function accrueInterest(MarketParams memory _marketParams) external;

function idToMarketParams(bytes32 _id) external view returns (MarketParams memory marketParams_);

function market(bytes32 _id) external view returns (Market memory market_);

function position(bytes32 _id, address _user) external view returns (Position memory position_);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-3.0

/*
This file is part of the Enzyme Protocol.
(c) Enzyme Foundation <council@enzyme.finance>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/

import {IExternalPosition} from "../../IExternalPosition.sol";

pragma solidity >=0.6.0 <0.9.0;

/// @title IMorphoBluePosition Interface
/// @author Enzyme Foundation <security@enzyme.finance>
interface IMorphoBluePosition is IExternalPosition {
enum Actions {
Lend,
Redeem,
AddCollateral,
RemoveCollateral,
Borrow,
Repay
}

function getMarketIds() external view returns (bytes32[] memory marketIds_);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: GPL-3.0

/*
This file is part of the Enzyme Protocol.
(c) Enzyme Foundation <council@enzyme.finance>
For the full license information, please view the LICENSE
file that was distributed with this source code.
*/

pragma solidity 0.8.19;

/// @title MorphoBluePositionDataDecoder Contract
/// @author Enzyme Foundation <security@enzyme.finance>
/// @notice Abstract contract containing data decodings for IMorphoBluePosition payloads
abstract contract MorphoBluePositionDataDecoder {
/// @dev Helper to decode args used during the AddCollateral action
function __decodeAddCollateralActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 collateralAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}

/// @dev Helper to decode args used during the Borrow action
function __decodeBorrowActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 borrowAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}

/// @dev Helper to decode args used during the Lend action
function __decodeLendActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 lendAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}

/// @dev Helper to decode args used during the Redeem action
function __decodeRedeemActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 sharesAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}

/// @dev Helper to decode args used during the RemoveCollateral action
function __decodeRemoveCollateralActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 collateralAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}

/// @dev Helper to decode args used during the Repay action
function __decodeRepayActionArgs(bytes memory _actionArgs)
internal
pure
returns (bytes32 marketId_, uint256 repayAmount_)
{
return abi.decode(_actionArgs, (bytes32, uint256));
}
}
Loading

0 comments on commit 80f5257

Please sign in to comment.