---
# System prepended metadata

title: 'ITIP004 - Morpho Leverage Module[WIP]'
tags: [ITIP]

---

# ITIP004 - Morpho Leverage Module[WIP]


Discussing the scope of adding a Morpho Leverage Module for Index Protocol. 

## Motivation 
Morpho helps lenders and borrowers optimise their APYs by connecting the 2 parties P2P using a matching engine. We examined the advantages and disadvantages of building and using a Morpho Leverage Module and its impact on various Index Coop product suites. 

There are a few key motivations to implementing such a module would be to optimise and improve 

* The Leveraged liquid staking strategy product ie icETH. 
* Ratio Products ETH-BTC, BTC-ETH (subject to backtest results)
* Delta Neutral yield products that were discussed recently by the product team. (subject to backtest results)


## Key Requirements 

The leverage module provides an interface for an IndexToken to take specific actions like supply collateral, borrow, repay, and take advantage of the P2P matching engine along with monitoring account health. Additionally, the ability to include multiple collateral and debt assets within a single IndexToken would enable a variety of use cases (ex. Ratio and Delta Neutral products). The leverage module may or may not support claiming of token rewards earned on the underlying protocol positions; compatibility with the Airdop Module should be considered given the fact that $MORPHO rewards are expected to accrue and be released over time.

***Some initial ideas***
We want to explore multiversion & multiple underlying protocol support for Morpho Leverage Module, if possible. This is to avoid deploying multiple versions of the module to interact with various versions of underlying lending protocols, and abstract away the specifics to the Leverage Strategy Contracts. An example would be maintaining a collateralized debt position (CDP) in Morpho Aave v3 AND maintaining a CDP within Morpho Compound v2 at the same time within a single setToken. This may or may not be done on the final module.

The MorphoLeverageModule(s) needs to support the following functionality for the Index Protocol. 


### For Morpho Aave (Supports Aave V2)

* Supply & Withdraw Collateral from Morpho Aave V2 Protocol 
* Borrow & Repay from Morpho Aave V2
* Get Account collateral/borrow balances/health factors per SetToken
* Support multiple collateral and debt assets within one setToken



### For Morpho Compound (Supports Compound V2)

* Supply & Withdraw Collateral from Morpho Compound V2 Protocol. 
* Borrow & Repay from Morpho Compound V2 Protocol. 
* Get Account collateral/borrow balances/health factors per SetToken.
* Support multiple collateral and debt assets within one setToken



### For Morpho Aave V3 (Supports Aave V3)

Morpho Aave V3 protocol is currently configured to optimize the leveraged staking trade, so only WETH can be borrowed; however, in additon to stETH collateral, USDC, DAI, and WBTC can be used as collateral. Further collateral support and ensuing changes to the interface need to be discussed with Morpho team. 
* Supply & Withdraw Collateral from Morpho AaveV3 Protocol. 
* Borrow & Repay from Morpho Aave V3 Protocol. 
* Get Account collateral/borrow balances/health factors per SetToken.
* Support multiple collateral and debt assets within one setToken 
* Borrow in E-mode.
* Borrow in Isolation Mode. 




## Comparing Interfaces


### Morpho Aave V2 

[AaveV2/IMorpho.sol](https://github.com/morpho-org/morpho-v1/blob/main/src/aave-v2/interfaces/IMorpho.sol)

#### Supply
```
function supply(address _poolToken, uint256 _amount) external;
function supply(address _poolToken, address _onBehalf, uint256 _amount) external;
function supply(address _poolToken, address _onBehalf, uint256 _amount, uint256 _maxGasForMatching) external;
```
#### Withdraw 

```
function withdraw(address _poolToken, uint256 _amount) external;
function withdraw(address _poolToken, uint256 _amount, address _receiver) external;
```

#### Borrow

```
function borrow(address _poolToken, uint256 _amount) external;
function borrow(address _poolToken, uint256 _amount, uint256 _maxGasForMatching) external;
```

#### Repay

```
function repay(address _poolToken, uint256 _amount) external;
function repay(address _poolToken, address _onBehalf, uint256 _amount) external;
```

Other important memory functions include - 

```
function supplyBalanceInOf(address, address) external view returns (Types.SupplyBalance memory);
function borrowBalanceInOf(address, address) external view returns (Types.BorrowBalance memory);
```





### Morpho Compound V2 

[Compound/IMorpho.sol](https://github.com/morpho-org/morpho-v1/blob/main/src/compound/interfaces/IMorpho.sol)



#### Supply

```
function supply(address _poolToken, uint256 _amount) external;
function supply(address _poolToken, address _onBehalf, uint256 _amount) external;
function supply(address _poolToken, address _onBehalf, uint256 _amount, uint256 _maxGasForMatching) external;
    
```    
#### Withdraw    
```

function withdraw(address _poolToken, uint256 _amount) external;
function withdraw(address _poolToken, uint256 _amount, address _receiver) external;
    
```
#### Borrow

```
function borrow(address _poolToken, uint256 _amount) external;
function borrow(address _poolToken, uint256 _amount, uint256 _maxGasForMatching) external;
```




#### Repay
```
function repay(address _poolToken, uint256 _amount) external;
function repay(address _poolToken, address _onBehalf, uint256 _amount) external;
```

Other important memory functions 
```
function supplyBalanceInOf(address, address) external view returns (Types.SupplyBalance memory);
function borrowBalanceInOf(address, address) external view returns (Types.BorrowBalance memory);
```

### Morpho Aave V3

[AaveV3/IMorpho.sol](https://github.com/morpho-org/morpho-aave-v3/blob/main/src/interfaces/IMorpho.sol)


#### Supply 
```
  function supply(address underlying, uint256 amount, address onBehalf, uint256 maxIterations)
        external
        returns (uint256 supplied);
```
#### Withdraw 

```
function withdraw(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
        external
        returns (uint256 withdrawn);
```
There are alternate versions of the Supply and Withdraw functions ie `supplycollateral ` and `withdrawCollateral`, details of which we will discuss later in this document. 


Morpho 
#### Borrow

```
function borrow(address underlying, uint256 amount, address onBehalf, address receiver, uint256 maxIterations)
        external
        returns (uint256 borrowed);
```


#### Repay

```
function repay(address underlying, uint256 amount, address onBehalf) external returns (uint256 repaid);
```


Other important memory functions 
```
function supplyBalanceInOf(address, address) external view returns (Types.SupplyBalance memory);
function borrowBalanceInOf(address, address) external view returns (Types.BorrowBalance memory);
```

The similarity in the interfaces and other key principles in Morpho's AaveV2/V3 and Compound protocols might make it possible to combine support for all protocols within a single module. 
## Morpho Leverage Strategy Contract(s)

The Morpho Leverage Strategy contracts executes a leverage strategy on top on Morpho based on certain parameters and interfaces with the Morpho Leverage Module to do so.

For standard leveraged tokens with one collateral asset and one debt asset, the traditional strategy extension functionality should be adequate. For tokens with multiple collateral and debt assets, there must be a method for designating which asset(s) ought to be traded during a rebalance. For example, if a token has USDC and stETH as collateral and WETH as debt, only stETH should be sold for WETH in order to de-lever. In the case of the Delta Neutral products, there may need to be a "take profit" or "reinvest" function where interest earned on the stETH collateral is periodically sold for USDC and then added to existing USDC collateral; this could be triggered when the overall LR for the product falls below a certain point or on a time-based interval (ex. monthly).

We may also want to consider integrating the [required functions for Chainlink Upkeep](https://docs.chain.link/chainlink-automation/compatible-contracts); this could allow us to eventually outsource keeper operations and rely on Chainlink's keeper network to monitor and adapt positions associated with the Morpho LM over time. The use of Upkeep is currently being researched, so it is not currently a "need-to-have" within future strategyExtension contracts.


### Requirements (WIP)


## Product-Specific Requirements

#### Delta Neutral - [Draft PRD](https://docs.google.com/document/d/1QHfVp9aydpR5MK3Dvj5Ui8gxGrscAbuTMe7k8nsuc44/edit?usp=sharing)
- multi-collateral support; example product compositions include DAI + stETH collateral and WETH debt, USDC + stETH collateral and WETH debt, wBTC + stETH collateral and WETH debt
- E-mode in Aave v3 for stETH <> ETH position
- ability to designate which collateral asset should be acted upon in specified situations; ex. when the current LR exceeds the max LR, sell stETH collateral (not *USDC* collateral) to pay down WETH debt
- accounting for the overall, or "effective", LTV for the product; different collateral assets may have different LTV ratios and liquidation thresholds (ex. USDC = 74% Max LTV versus wBTC = 70% Max LTV in Aave v3), so it is critical for the risk parameters and methdology settings to reflect this effective LTV and adapt the underlying positions accordingly
- publicly callable ripcord function


#### ETH<>BTC Ratio
- Multi-collateral support; example product compositions include USDC + ETH collateral and wBTC debt or USDC + wBTC collateral and WETH debt
- ability to designate which collateral asset should be acted upon in specified situations; ex. when the current LR exceeds the max LR, sell ETH collateral (not *USDC* collateral) to pay down wBTC debt
- accounting for the overall, or "effective", LTV for the product; different collateral assets may have different LTV ratios and liquidation thresholds (ex. USDC = 74% Max LTV versus wBTC = 70% Max LTV in Aave v3), so it is critical for the risk parameters and methdology settings to reflect this effective LTV and adapt the underlying positions accordingly
- publicly callable ripcord function


#### icETH V2
- E-mode in Aave v3 for LST <> WETH position
- publicly callable ripcord function
- (nice to have) multi-collateral support; stETH + rETH + sfrxETH collateral and WETH debt
- (nice to have) multiple collateralized debt positions (CDPs) accross Morpho-enabled protocols inside of a single setToken; ex. maintain a CDP in Morpho Compound v2 and also in Morpho Aave v3 inside of one setToken










