Skip to content

Commit

Permalink
Merge pull request #119 from Instadapp/metamorpho-resolver
Browse files Browse the repository at this point in the history
Setup metamorpho resolver
  • Loading branch information
shriyatyagii authored Jan 28, 2024
2 parents 6c69300 + 5b99780 commit fd787b0
Show file tree
Hide file tree
Showing 22 changed files with 2,454 additions and 0 deletions.
69 changes: 69 additions & 0 deletions contracts/protocols/mainnet/metamorpho/interface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.19;

import {Id} from "./interfaces/IMorpho.sol";

interface TokenInterface {
function balanceOf(address) external view returns (uint256);

function allowance(address owner, address spender) external view returns (uint256);

function decimals() external view returns (uint256);

function name() external view returns (string memory);

function symbol() external view returns (string memory);
}

interface VaultInterface {
function decimals() external view returns (uint256);

function name() external view returns (string memory);

function symbol() external view returns (string memory);

function asset() external view returns (address);

function totalAssets() external view returns (uint256);

function totalSupply() external view returns (uint256);

function balanceOf(address) external view returns (uint256);

function allowance(address owner, address spender) external view returns (uint256);

function nonces(address) external view returns (uint256);

function convertToShares(uint256 assets) external view returns (uint256);

function convertToAssets(uint256 shares) external view returns (uint256);

function previewDeposit(uint256 assets) external view returns (uint256);

function previewMint(uint256 shares) external view returns (uint256);

function previewWithdraw(uint256 assets) external view returns (uint256);

function previewRedeem(uint256 shares) external view returns (uint256);

function maxDeposit(address) external view returns (uint256);

function maxMint(address) external view returns (uint256);

function maxWithdraw(address owner) external view returns (uint256);

function maxRedeem(address owner) external view returns (uint256);
}

interface MorphoBlueInterface {
function idToMarketParams(Id id)
external
view
returns (address loanToken, address collateralToken, address oracle, address irm, uint256 lltv);
}

interface MetaMorphoInterface {
function fee() external view returns (uint96);
function supplyQueue(uint256) external view returns (Id);
function config(Id) external view returns (uint184 cap, bool enabled, uint64 removableAt);
}
9 changes: 9 additions & 0 deletions contracts/protocols/mainnet/metamorpho/interfaces/IERC20.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

/// @title IERC20
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @dev Empty because we only call library functions. It prevents calling transfer (transferFrom) instead of
/// safeTransfer (safeTransferFrom).
interface IERC20 {}
19 changes: 19 additions & 0 deletions contracts/protocols/mainnet/metamorpho/interfaces/IIrm.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {MarketParams, Market} from "./IMorpho.sol";

/// @title IIrm
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @notice Interface that Interest Rate Models (IRMs) used by Morpho must implement.
interface IIrm {
/// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams`.
/// @dev Assumes that `market` corresponds to `marketParams`.
function borrowRate(MarketParams memory marketParams, Market memory market) external returns (uint256);

/// @notice Returns the borrow rate per second (scaled by WAD) of the market `marketParams` without modifying any
/// storage.
/// @dev Assumes that `market` corresponds to `marketParams`.
function borrowRateView(MarketParams memory marketParams, Market memory market) external view returns (uint256);
}
89 changes: 89 additions & 0 deletions contracts/protocols/mainnet/metamorpho/interfaces/IMetaMorpho.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;

import {IMorpho, Id, MarketParams} from "./IMorpho.sol";

struct MarketConfig {
/// @notice The maximum amount of assets that can be allocated to the market.
uint192 cap;
/// @notice Whether the market is in the withdraw queue.
bool enabled;
/// @notice The timestamp at which the market can be instantly removed from the withdraw queue.
uint56 removableAt;
}

/// @dev Either `assets` or `shares` should be zero.
struct MarketAllocation {
/// @notice The market to allocate.
MarketParams marketParams;
/// @notice The amount of assets to allocate.
uint256 assets;
}

/// @dev This interface is used for factorizing IMetaMorphoStaticTyping and IMetaMorpho.
/// @dev Consider using the IMetaMorpho interface instead of this one.
interface IMetaMorphoBase {
function MORPHO() external view returns (IMorpho);

function curator() external view returns (address);
function isAllocator(address target) external view returns (bool);
function guardian() external view returns (address);

function fee() external view returns (uint96);
function feeRecipient() external view returns (address);
function skimRecipient() external view returns (address);
function timelock() external view returns (uint256);
function supplyQueue(uint256) external view returns (Id);
function supplyQueueLength() external view returns (uint256);
function withdrawQueue(uint256) external view returns (Id);
function withdrawQueueLength() external view returns (uint256);

function lastTotalAssets() external view returns (uint256);

function submitTimelock(uint256 newTimelock) external;
function acceptTimelock() external;
function revokePendingTimelock() external;

function submitCap(MarketParams memory marketParams, uint256 supplyCap) external;
function acceptCap(Id id) external;
function revokePendingCap(Id id) external;

function submitMarketRemoval(Id id) external;
function revokePendingMarketRemoval(Id id) external;

function submitGuardian(address newGuardian) external;
function acceptGuardian() external;
function revokePendingGuardian() external;

function skim(address) external;

function setIsAllocator(address newAllocator, bool newIsAllocator) external;
function setCurator(address newCurator) external;
function setFee(uint256 newFee) external;
function setFeeRecipient(address newFeeRecipient) external;
function setSkimRecipient(address) external;

function setSupplyQueue(Id[] calldata newSupplyQueue) external;
function updateWithdrawQueue(uint256[] calldata indexes) external;
function reallocate(MarketAllocation[] calldata allocations) external;
}

/// @dev This interface is inherited by MetaMorpho so that function signatures are checked by the compiler.
/// @dev Consider using the IMetaMorpho interface instead of this one.
interface IMetaMorphoStaticTyping is IMetaMorphoBase {
function config(Id) external view returns (uint192 cap, bool enabled, uint56 removableAt);
function pendingGuardian() external view returns (address guardian, uint56 validAt);
function pendingCap(Id) external view returns (uint192 value, uint56 validAt);
function pendingTimelock() external view returns (uint192 value, uint56 validAt);
}

/// @title IMetaMorpho
/// @author Morpho Labs
/// @custom:contact [email protected]
/// @dev Use this interface for MetaMorpho to have access to all the functions with the appropriate function signatures.
interface IMetaMorpho is IMetaMorphoBase {
function config(Id) external view returns (MarketConfig memory);

// From IERC4626
function totalAssets() external view returns (uint256);
}
Loading

0 comments on commit fd787b0

Please sign in to comment.