# Leverage / Deleverage function

### Overview

The **IOLend** provides a unique leverage trading functionality integrated with the **MagicSea DEX**. This enables users to leverage long their assets with a series of automated transactions, enhancing their exposure to the market without requiring direct management of each step. This documentation will cover the mechanics of the leverage and deleverage functions, as well as the utilization of flash loans for advanced leverage strategies.

### Leverage Function

#### Step-by-Step Mechanics

The leverage function on IOLend follows a sequence of deposit, borrowing, and swapping operations to maximize the user’s position. The process works as follows:

1. **Deposit**: The user deposits their base asset into the IOLend platform. This initial deposit serves as collateral for borrowing additional assets.
2. **Borrow**: The platform borrows an additional asset against the collateralized deposit, allowing the user to gain exposure beyond their initial capital.
3. **Swap**: The borrowed asset is then swapped on the MagicSea DEX for the target asset, increasing the user’s leveraged position.
4. **Deposit**: The swapped asset is deposited back into the platform as additional collateral.
5. **Borrow Again**: The platform borrows more assets against the newly deposited collateral.
6. **Swap Again**: The borrowed asset is swapped for the target asset again.
7. **Repeat**: This cycle of deposit-borrow-swap-deposit can continue based on the desired leverage level and the platform’s risk parameters.

#### Example Workflow

1. User deposits **1 ETH** as collateral.
2. The platform borrows **1000 USDT** against the ETH.
3. The borrowed USDT is swapped for **IOTA**.
4. The acquired IOTA is deposited as additional collateral.
5. The platform borrows more USDT against the IOTA collateral.
6. The cycle continues based on user preferences and leverage limits.

#### Supported Leverage Pairs

Users can leverage long on the following asset pairs:

* **USDT against IOTA/ETH**
* **IOTA against USDT/WETH**
* **ETH against USDT/IOTA**

> Note: Users cannot leverage long the same asset against itself, i.e., USDT against USDT, IOTA against IOTA, or ETH against ETH.

### Deleverage Function

#### Step-by-Step Mechanics

The deleverage function reverses the leverage process, reducing the user’s exposure and repaying borrowed assets in the following steps:

1. **Withdraw Collateral**: The user’s leveraged asset is withdrawn from the platform.
2. **Swap**: The withdrawn asset is swapped on the MagicSea DEX back into the borrowed asset.
3. **Repay**: The swapped asset is used to repay the borrowed asset.
4. **Withdraw Again**: The process is repeated until the desired leverage level is achieved or the position is fully deleveraged.

#### Example Workflow

1. User has **2 ETH** leveraged long with borrowed **2000 USDT**.
2. Withdraw 1 ETH and swap it for USDT.
3. Repay 1000 USDT.
4. Repeat the process until the leverage position is reduced or closed.

### Flash Loan Leverage Function

The flash loan leverage function enables more complex leverage strategies by utilizing a flash loan to temporarily increase capital for leveraged positions.

#### Step-by-Step Mechanics

1. **Deposit**: The user deposits their base asset as collateral.
2. **Flash Loan**: The platform takes out a flash loan to temporarily increase the available capital.
3. **Deposit**: The flash loaned asset is deposited into the platform as additional collateral.
4. **Borrow**: The platform borrows additional assets against the total collateral.
5. **Swap**: The borrowed asset is swapped for the target asset on the MagicSea DEX.
6. **Repay Flash Loan**: The flash loan is repaid using the swapped assets or remaining collateral.

#### Example Workflow

1. User deposits **1000 USDT** as collateral.
2. A flash loan of **5000 USDT** is taken.
3. The total of **6000 USDT** is deposited as collateral.
4. The platform borrows **2000 IOTA** against the USDT collateral.
5. The borrowed IOTA is swapped for **ETH**.
6. The flash loan is repaid with the available collateral or swapped assets.

### User Guidelines

#### Deposits

* Users can deposit **USDT, IOTA, or WETH** as collateral.
* Deposited assets must be different from the target leverage asset, e.g., you cannot leverage long USDT against USDT.

#### Borrowing Limits

* The borrowing capacity is determined by the deposited collateral value and the platform's risk management parameters.
* Users should be aware of potential liquidation risks when using high leverage.

#### Asset Pairs

Users can only leverage long on supported asset pairs:

* **USDT** → **IOTA/ETH**
* **IOTA** → **USDT/WETH**
* **ETH** → **USDT/IOTA**

#### Risk Management

* Users are advised to monitor their leveraged positions regularly due to the volatility in asset prices.
* Liquidations can occur if the value of the collateral falls below the platform’s minimum collateralization ratio.

### Conclusion

The IOLend leverage function via MagicSea DEX provides powerful tools for users to amplify their positions and potentially increase their returns. By automating the leverage process with cycles of deposit, borrowing, and swapping, users can easily engage in complex trading strategies. Flash loans further enhance the leverage capabilities, offering additional capital for advanced maneuvers. As always, users should remain mindful of the inherent risks and manage their positions accordingly.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://iolend.gitbook.io/iolend/leverage-deleverage-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
