Leverage

The leverage function in the contract follows the below flow to leverage the position on morpho v1. This function can only be executed by the governance of the vault. The below steps explain the steps for leveraging the magETH vault from 2x to 3x.

Step 1: Borrow Flashloan from Aave of x WETH

  • In this step, the magETH vault initiates a flashloan from the Aave lending protocol, borrowing an amount of Wrapped ETH (WETH) denoted as "x." The "x" value will be determined by getborrowedAmountForleverage(). This function calculates the current supplied stETH amount and borrowed WETH amount on Morpho V1.

Step 2: Swap x WETH to x stETH through 1inch

  • The vault uses a decentralized exchange aggregator like 1inch to swap the x borrowed WETH tokens into stETH tokens. This step effectively converts the borrowed WETH into stETH.

Step 3: Supply x stETH to Morpho v1

  • With the newly acquired x stETH tokens, the vault supplies these tokens to the Morpho V1 protocol. This involves adding x stETH tokens to the liquidity pool on Morpho V1.

Step 4: Borrow x WETH from Morpho v1

  • The vault borrows an equivalent amount of WETH (x) from the Morpho V1 protocol, using the stETH tokens supplied as collateral. This step effectively increases the leverage from 2x to 3x.

Step 5: Payback the Flashloan of x WETH to Aave

  • Finally, the vault repays the flashloan taken from Aave by returning the x borrowed WETH tokens. This ensures that the flashloan is settled, and the borrowed assets are returned as per the terms of the flashloan.