# Concepts

## Supply

Users can deposit their assets as collateral into the protocol and receive **tTokens** as proof of deposit (for example, depositing 100 USDC will mint 100 tUSDC).

**Developer Reference**

```
function deposit(
    address asset,
    uint256 amount,
    address onBehalfOf,
    uint16 referralCode
) external;
```

* **asset**: The address of the token being deposited.
* **amount**: The quantity of the token to deposit.
* **onBehalfOf**: The address that will receive the corresponding tTokens.
* **referralCode**: A code emitted in the Deposit event, typically used by third-party integrators.

**Example**:

If you deposit `100 USDC`, the pool receives `100 USDC` and mints `100 tUSDC` to the `onBehalfOf` address.

## Withdraw

Users can redeem their deposited assets based on the amount of **tTokens** they hold. For example, holding 100 tUSDC allows a user to withdraw 100 USDC.

**Developer Reference**

```
function withdraw(
    address asset,
    uint256 amount,
    address to,
    bool returnNative
) external;
```

* **asset**: The address of the token to withdraw.
* **amount**: The amount of the token to withdraw (corresponding to the same amount of tTokens).
* **to**: The address that will receive the withdrawn asset.
* **returnNative**: Set to true if you want to withdraw wrapped native tokens (e.g. WETH) and unwrap them into the native asset (e.g. ETH) before transfer.

**Example 1**:\
You hold `100 tUSDC` and want to withdraw these tokens to `Alice`. The pool burns `100 tUSDC` and transfers `100 USDC` to `Alice`.

**Example 2**:\
You hold `100 tWETH` and want to send 100 ETH to `Alice`. Set `returnNative` to `true`. The pool burns `100 tWETH`, unwraps `100 WETH` into `100 ETH`, and transfers `100 ETH` to `Alice`.

## Borrow

Users can borrow assets against the collateral they have supplied. When borrowing, they receive the requested asset along with **debtTokens** that represent the borrowed position (for example, borrowing 100 USDC results in receiving 100 USDC plus minting 100 debtUSDC).

**Developer Reference**

```
function borrow(
    address asset,
    uint256 amount,
    address onBehalfOf,
    bool returnNative,
    uint16 referralCode
) external;
```

* **asset**: The address of the token to borrow.
* **amount**: The quantity of the token to borrow.
* **onBehalfOf**: The address whose collateral will be used for the loan. The pool will mint the corresponding debtTokens to this address.
* **returnNative**: Set to true to unwrap wrapped native tokens (e.g. WETH to ETH) before transferring them to the borrower.
* **referralCode**: A code emitted in the Borrow event, typically used by third-party integrators.

**Delegated Borrowing**:\
To borrow using another address’s collateral (`onBehalfOf`), the borrower must first be granted a borrowing allowance from that address. This is done via the approveDelegation function on the relevant `debtToken`:

```
function approveDelegation(address delegatee, uint256 amount) external;
// The onBehalfOf address calls this function on the variableDebtToken contract, 
// specifying the borrower as the delegatee.
```

## Repay

Users can repay their outstanding loans, which results in the protocol burning the corresponding amount of **debtTokens**. For example, repaying 100 USDC burns 100 debtUSDC. If the remaining debt is only 36 USDC, the pool collects 36 USDC and burns 36 debtUSDC accordingly.

**Developer Reference**

```
function repay(
    address asset,
    uint256 amount,
    address onBehalfOf
) external;
```

* **asset**: The address of the token to repay.
* **amount**: The amount of the token being repaid.
* **onBehalfOf**: The address whose debt will be reduced (the pool transfers the `amount` of `asset` from the caller and burns the same `amount` of `debtTokens` for this address).

This function allows a user to repay their own loan or repay on behalf of another borrower.

* Set as collateral

Users can choose whether or not to designate an asset as collateral.

* **When an asset is enabled as collateral**, it increases the user’s borrowing capacity. However, the asset becomes subject to liquidation risk if the user’s health factor falls below the liquidation threshold.
* **When an asset is not used as collateral**, it is protected from liquidation but cannot be used to back new loans.

By default, assets supplied for the first time are automatically set as collateral. Users can later opt out and disable the collateral status for a given asset.

**Developer Reference**

```
function setUserUseReserveAsCollateral(
    address asset, 
    bool useAsCollateral
) external;
```

* **asset**: The address of the asset to enable or disable as collateral.
* **useAsCollateral**: Set to true to enable the asset as collateral, or false to disable it.

This function allows users to actively manage their collateral configuration and control which assets are at risk of liquidation.

* Liquidation

When a user’s **Health Factor** drops below 1, their position becomes subject to liquidation in order to protect the protocol.

**Requirements for Liquidators**

To execute a liquidation, you must prepare assets and gas on the relevant chains:

* **Collateral and Debt Assets**:
  * Hold ETH (or the native gas token) on **two chains**:
    * The chain where the liquidated user’s **collateral asset** resides.
    * The chain where the liquidated user’s **debt asset** resides.
  * Hold a sufficient amount of the **debt asset** to cover the portion of the loan you intend to repay.
* **ZetaChain Gas**:
  * Deposit ETH into the Zeta gateway on both the collateral chain and the debt chain to obtain gas on ZetaChain.
  * Typically, about **0.0001 ETH per chain** is sufficient.
  * Deposits on each chain are converted to the corresponding ZRC20 token on ZetaChain (e.g., depositing from Base yields ZRC20-Base, depositing from Arbitrum yields ZRC20-Arbitrum).
* **Approvals and Deposits**:

  Approve your ZRC20 tokens for our universal contract on ZetaChain, then call:\
  `depositGasBalance(uint256 chainId, uint256 amount, address onBehalfOf)`

  * &#x20;This records your gas balance in our universal contract. You may withdraw your ZRC20 tokens from the universal contract at any time.
  * Additionally, approve the protocol’s pool contract on the **debt chain** so it can pull the `debtAsset` you will use to repay the borrower’s debt.

**Executing the Liquidation**

Once all requirements are met, call the following function on the controller contract deployed on ZetaChain:

`liquidationCallPhase1(...)`&#x20;

This initiates the liquidation process.


---

# 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://docs.aimstrong.ai/technical-overview/omni-lending-protocol/concepts.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.
