# Market

Market Contract Address: [inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u](https://injscan.com/contract/inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u/)

The **Market Contract** is a core component of the Neptune Protocol, responsible for handling various financial operations such as lending, borrowing, collateral management, flash loans and liquidations. It provides a robust and flexible interface for users to interact with the Neptune financial ecosystem.

## Query Messages

### 1. Get All Markets

**Query:** `get_all_markets`

**Purpose:** Returns a paginated list of all markets available in the Neptune Protocol, including their current state, interest rates, utilization metrics, and market-specific parameters. Supports pagination through start\_after and limit parameters. If pagnation is not used, returns all markets.

**Query Input:**

<pre class="language-json"><code class="lang-json">{
  "get_all_markets": {
    "start_after": {
      "native_token": {
        "denom": "inj"
<strong>      }
</strong>    },
    "limit": 2
  }
}
</code></pre>

<table><thead><tr><th width="227">Parameter</th><th width="101">Type</th><th width="256">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>start_after</code></td><td><code>object</code></td><td>Object containing information of the token to start after</td><td>No</td></tr><tr><td><p><code>start_after.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>start_after.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Denomination of native token</td><td>Yes</td></tr><tr><td><code>limit</code></td><td><code>u64</code></td><td>Number of responses to return</td><td>No</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    },
    {
      "time_last_distributed_interest": "1740443520617491324",
      "utilization_accumulator": "17052188166231954.57528721805685724",
      "lending_principal": "13161660610653173698",
      "debt_pool": {
        "balance": "7987724390439616559",
        "shares": "7626917102526772054"
      },
      "market_asset_details": {
        "receipt_addr": "inj1kehk5nvreklhylx22p3x0yjydfsz9fv3fvg5xt",
        "borrow_halt_utilization": "0.85",
        "interest_fee": "0.01",
        "borrow_cap": "180000000000000000000",
        "enabled": true
      }
    }
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    {
      "time_last_distributed_interest": "1740443389082701440",
      "utilization_accumulator": "26033903718931173.530196318587580776",
      "lending_principal": "1050352807605",
      "debt_pool": {
        "balance": "873600917508",
        "shares": "697338323165"
      },
      "market_asset_details": {
        "receipt_addr": "inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s",
        "borrow_halt_utilization": "0.95",
        "interest_fee": "0.02",
        "borrow_cap": null,
        "enabled": true
      }
    }
  ]
]
```

<table><thead><tr><th width="280">Parameter</th><th width="145">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>AssetInfo</code></td><td>Contains details about the native token</td></tr><tr><td><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination of the native token</td></tr><tr><td><code>time_last_distributed_interest</code></td><td><code>Timestamp</code></td><td>The timestamp of the last interest distribution</td></tr><tr><td><code>utilization_accumulator</code></td><td><code>Decimal256</code></td><td>The accumulated utilization value</td></tr><tr><td><code>lending_principal</code></td><td><code>Uint256</code></td><td>The principal amount currently lent</td></tr><tr><td><code>debt_pool</code></td><td><code>Pool</code></td><td>Contains details about the debt pool</td></tr><tr><td><p><code>debt_pool.</code></p><p><strong><code>balance</code></strong></p></td><td><code>Uint256</code></td><td>The balance of the debt pool</td></tr><tr><td><p><code>debt_pool.</code></p><p><strong><code>shares</code></strong></p></td><td><code>Uint256</code></td><td>The shares of the debt pool</td></tr><tr><td><code>market_asset_details</code></td><td><code>MarketAssetDetails</code></td><td>Contains details about the market asset</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>receipt_addr</code></strong></p></td><td><code>Addr</code></td><td>The receipt address for the market asset</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>borrow_halt_utilization</code></strong></p></td><td><code>Decimal256</code></td><td>The utilization level at which borrowing halts</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>interest_fee</code></strong></p></td><td><code>Decimal256</code></td><td>The interest fee applied to the market asset</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>borrow_cap</code></strong></p></td><td><code>Uint256</code></td><td>The borrowing cap for the market asset. Can be <code>null</code></td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>enabled</code></strong></p></td><td><code>boolean</code></td><td>Indicates if the market asset is enabled</td></tr></tbody></table>

### 2. Get All Collaterals

**Query:** `get_all_collaterals`

**Purpose:** Fetches a paginated list of all collateral assets available in the Neptune Protocol, including their LTV ratios, liquidation parameters, collateral caps, and current pool states. Supports pagination through start\_after and limit parameters. If pagnation is not used, returns all collaterals.

**Query Input:**

```json
{
  "get_all_collaterals": {
    "start_after": {
      "native_token": {
        "denom": "inj"
      }
    },
    "limit": 2
  }
}
```

<table><thead><tr><th width="227">Parameter</th><th width="101">Type</th><th width="256">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>start_after</code></td><td><code>object</code></td><td>Object containing information of the token to start after</td><td>No</td></tr><tr><td><p><code>start_after.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>start_after.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Denomination of native token</td><td>Yes</td></tr><tr><td><code>limit</code></td><td><code>u64</code></td><td>Number of responses to return</td><td>No</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    },
    {
      "collateral_details": {
        "collateral_type": "regular",
        "liquidation_ltv": "0.7",
        "allowable_ltv": "0.69",
        "max_discount": "0.14",
        "min_discount": "0.14",
        "collateral_cap": "160000000000000000000",
        "enabled": true
      },
      "collateral_pool": {
        "balance": "2987272506047754137",
        "shares": "2987272506047754137"
      }
    }
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    {
      "collateral_details": {
        "collateral_type": "regular",
        "liquidation_ltv": "0.78",
        "allowable_ltv": "0.77",
        "max_discount": "0.08",
        "min_discount": "0.08",
        "collateral_cap": "450000000000",
        "enabled": true
      },
      "collateral_pool": {
        "balance": "2629718706",
        "shares": "2629718706"
      }
    }
  ]
]
```

<table><thead><tr><th width="272">Parameter</th><th width="209">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>AssetInfo</code></td><td>Contains details about the native token</td></tr><tr><td><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination of the native token</td></tr><tr><td><code>collateral_details</code></td><td><code>CollateralDetails</code></td><td>Contains details about the collateral</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>collateral_type</code></strong></p></td><td><code>AssetType</code></td><td>The type of collateral (e.g., regular)</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>liquidation_ltv</code></strong></p></td><td><code>Decimal256</code></td><td>The loan-to-value ratio for liquidation</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>allowable_ltv</code></strong></p></td><td><code>Decimal256</code></td><td>The allowable loan-to-value ratio</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>max_discount</code></strong></p></td><td><code>Decimal256</code></td><td>The maximum discount applied to the collateral</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>min_discount</code></strong></p></td><td><code>Decimal256</code></td><td>The minimum discount applied to the collateral</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>collateral_cap</code></strong></p></td><td><code>Uint256</code></td><td>The cap on the amount of collateral</td></tr><tr><td><p><code>collateral_details.</code></p><p><strong><code>enabled</code></strong></p></td><td><code>boolean</code></td><td>Indicates if the collateral is enabled</td></tr><tr><td><code>collateral_pool</code></td><td><code>Pool</code></td><td>Contains details about the collateral pool</td></tr><tr><td><p><code>collateral_pool.</code></p><p><strong><code>balance</code></strong></p></td><td><code>Uint256</code></td><td>The balance of the collateral pool</td></tr><tr><td><p><code>collateral_pool.</code></p><p><strong><code>shares</code></strong></p></td><td><code>Uint256</code></td><td>The shares of the collateral pool</td></tr></tbody></table>

### 3. Get State

**Query:** `get_state`

**Purpose:** Retrieves a comprehensive snapshot of the entire market contract state, combining both the market assets data and collateral assets data in a single query. This provides a complete view of all markets and collaterals without pagination.

**Query Input:**

```json
{
  "get_state": {}
}
```

**Query Response:**

```json
{
  "markets": [
    [
      {
        "native_token": {
          "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
        }
      },
      {
        "time_last_distributed_interest": "1740441525814418055",
        "utilization_accumulator": "914755917117089.362843672401733295",
        "lending_principal": "100066949842",
        "debt_pool": {
          "balance": "42565274086",
          "shares": "42429423999"
        },
        "market_asset_details": {
          "receipt_addr": "inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g",
          "borrow_halt_utilization": "0.95",
          "interest_fee": "0.02",
          "borrow_cap": null,
          "enabled": true
        }
      }
    ],
    ...............
  ],
  "collaterals": [
    [
      {
        "native_token": {
          "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
        }
      },
      {
        "collateral_details": {
          "collateral_type": "regular",
          "liquidation_ltv": "0.78",
          "allowable_ltv": "0.77",
          "max_discount": "0.12",
          "min_discount": "0.08",
          "collateral_cap": "300000000000",
          "enabled": true
        },
        "collateral_pool": {
          "balance": "44893",
          "shares": "44893"
        }
      }
    ],
    .................
  ]
}
```

### 4. Get User Accounts

**Query:** `get_user_accounts`

**Purpose:** Retrieves detailed information about all sub-accounts associated with a specific wallet address, including their debt positions and collateral deposits across different assets.

**Query Input:**

```json
{
  "get_user_accounts": {
    "addr": "inj.........."
  }
}
```

| Parameter | Type   | Description              |
| --------- | ------ | ------------------------ |
| `addr`    | `Addr` | Injective wallet address |

**Query Response:**

```json
[
  [
    2,
    {
      "debt_pool_accounts": [
        [
          {
            "native_token": {
              "denom": "inj"
            }
          },
          {
            "principal": "14730000000000000000",
            "shares": "14955143791342905893"
          }
        ]
      ],
      "collateral_pool_accounts": [
        [
          {
            "token": {
              "contract_addr": "inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc"
            }
          },
          {
            "principal": "27049873259216212851",
            "shares": "26907049547493586917"
          }
        ]
      ]
    }
  ]
]
```

<table><thead><tr><th width="290">Parameter</th><th width="220">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>[0]</code></td><td><code>uint8</code></td><td>sub account index number</td></tr><tr><td><code>debt_pool_accounts</code></td><td><code>array&#x3C;[AssetInfo, PoolAccount]></code></td><td>Contains details about the user's debt pools</td></tr><tr><td><p><code>debt_pool_accounts[].</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination of the native token in the debt pool</td></tr><tr><td><p><code>debt_pool_accounts[].</code></p><p><strong><code>principal</code></strong></p></td><td><code>Uint256</code></td><td>The principal amount in the debt pool</td></tr><tr><td><p><code>debt_pool_accounts[].</code></p><p><strong><code>shares</code></strong></p></td><td><code>Uint256</code></td><td>The shares in the debt pool</td></tr><tr><td><code>collateral_pool_accounts</code></td><td><code>array&#x3C;[AssetInfo, PoolAccount]></code></td><td>Contains details about the user's collateral pools</td></tr><tr><td><p><code>collateral_pool_accounts[].</code></p><p><code>token.</code></p><p><strong><code>contract_addr</code></strong></p></td><td><code>Addr</code></td><td>The contract address of the token in the collateral pool</td></tr><tr><td><p><code>collateral_pool_accounts[].</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination of the native token in the collateral pool</td></tr><tr><td><p><code>collateral_pool_accounts[].</code></p><p><strong><code>principal</code></strong></p></td><td><code>Uint256</code></td><td>The principal amount in the collateral pool</td></tr><tr><td><p><code>collateral_pool_accounts[].</code></p><p><strong><code>shares</code></strong></p></td><td><code>Uint256</code></td><td>The shares in the collateral pool</td></tr></tbody></table>

### 5. Get All Accounts

**Query:** `get_all_accounts`

**Purpose:** Returns a paginated list of all margin accounts across all users in the protocol, including their debt and collateral positions. Supports efficient pagination through \[address, index] cursor and limit parameters.

**Query Input:**

```json
{
  "get_all_accounts": {
    "start_after": ["inj...........", 0],
    "limit": 2
  }
}
```

| Parameter        | Type            | Description                                    |
| ---------------- | --------------- | ---------------------------------------------- |
| `start_after`    | `[Addr, uint8]` | The address and index to start the query after |
| `start_after[0]` | `Addr`          | The address to start after                     |
| `start_after[1]` | `uint8`         | The account index to start after               |
| `limit`          | `uint32`        | The maximum number of accounts to return       |

**Query Response:**

```json
[
  [
    ["inj.............", 0],
    {
      "debt_pool_accounts": [
        [
          {
            "native_token": {
              "denom": "inj"
            }
          },
          {
            "principal": "1000000000000000000",
            "shares": "1000000000000000000"
          }
        ]
      ],
      "collateral_pool_accounts": [
        [
          {
            "token": {
              "contract_addr": "inj1contractaddress"
            }
          },
          {
            "principal": "2000000000000000000",
            "shares": "2000000000000000000"
          }
        ]
      ]
    }
  ],
  [
    ["inj...........", 1],
    {
      "debt_pool_accounts": [],
      "collateral_pool_accounts": [
        [
          {
            "native_token": {
              "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
            }
          },
          {
            "principal": "3000000000000000000",
            "shares": "3000000000000000000"
          }
        ]
      ]
    }
  ]
]
```

| Parameter                                                                                                                       | Type                              | Description                                                 |
| ------------------------------------------------------------------------------------------------------------------------------- | --------------------------------- | ----------------------------------------------------------- |
| `debt_pool_accounts`                                                                                                            | `array<[AssetInfo, PoolAccount]>` | Contains details about the account's debt pools             |
| <p><code>debt\_pool\_accounts\[].</code></p><p><code>native\_token.</code></p><p><strong><code>denom</code></strong></p>        | `string`                          | The denomination of the native token in the debt pool       |
| <p><code>debt\_pool\_accounts\[].</code></p><p><strong><code>principal</code></strong></p>                                      | `Uint256`                         | The principal amount in the debt pool                       |
| <p><code>debt\_pool\_accounts\[].</code></p><p><strong><code>shares</code></strong></p>                                         | `Uint256`                         | The shares in the debt pool                                 |
| `collateral_pool_accounts`                                                                                                      | `array<[AssetInfo, PoolAccount]>` | Contains details about the account's collateral pools       |
| <p><code>collateral\_pool\_accounts\[].</code></p><p><code>token.</code></p><p><strong><code>contract\_addr</code></strong></p> | `Addr`                            | The contract address of the token in the collateral pool    |
| <p><code>collateral\_pool\_accounts\[].</code></p><p><code>native\_token.</code></p><p><strong><code>denom</code></strong></p>  | `string`                          | The denomination of the native token in the collateral pool |
| <p><code>collateral\_pool\_accounts\[].</code></p><p><strong><code>principal</code></strong></p>                                | `Uint256`                         | The principal amount in the collateral pool                 |
| <p><code>collateral\_pool\_accounts\[].</code></p><p><strong><code>shares</code></strong></p>                                   | `Uint256`                         | The shares in the collateral pool                           |

### 6. Get Params

**Query:** `get_params`

**Purpose:** Retrieves the protocol's global configuration parameters, including liquidation settings, staking parameters, fee structures, flash loan settings, and core token addresses (hINJ and NEPT).

**Query Input:**

```json
{
  "get_params": {}
}
```

**Query Response:**

```json
{
  "time_window_nanos": 3600000000000,
  "partial_liquidation_threshold": "1000000000000000000000",
  "staking_health_modifier": "0.03",
  "stake_collateral_ratio": "0.1",
  "stake_flash_loan_ratio": "0.1",
  "target_liquidation_health": "1.03",
  "dynamic_discount_width": "0.01",
  "liquidation_fee": "0",
  "flash_loan_fee": "0",
  "flash_loans_enabled": true,
  "hinj": {
    "token": {
      "contract_addr": "inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc"
    }
  },
  "nept": {
    "native_token": {
      "denom": "factory/inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva/nept"
    }
  }
}
```

<table><thead><tr><th width="337">Parameter</th><th width="148">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>time_window_nanos</code></td><td><code>uint64</code></td><td>Number of nanoseconds that an oracle price is valid for</td></tr><tr><td><code>partial_liquidation_threshold</code></td><td><code>Uint256</code></td><td>Minimum account value to avoid complete liquidation. Represented in USD with 18 decimal precision</td></tr><tr><td><code>staking_health_modifier</code></td><td><code>Decimal256</code></td><td>The maximum health increase provided by NEPT staking</td></tr><tr><td><code>stake_collateral_ratio</code></td><td><code>Decimal256</code></td><td>The required ratio of weighted staked NEPT to collateral value</td></tr><tr><td><code>stake_flash_loan_ratio</code></td><td><code>Decimal256</code></td><td>The required ratio of weighted staked NEPT to flash loan value</td></tr><tr><td><code>target_liquidation_health</code></td><td><code>Decimal256</code></td><td>The account health target to bring an account up to from a liquidation action</td></tr><tr><td><code>dynamic_discount_width</code></td><td><code>Decimal256</code></td><td>The required change in account health below 1.0 to achieve the maximum discount on a collateral asset</td></tr><tr><td><code>liquidation_fee</code></td><td><code>Decimal256</code></td><td>The coefficient used to calculate the liquidation protocol fee</td></tr><tr><td><code>flash_loan_fee</code></td><td><code>Decimal256</code></td><td>The coefficient used to calculate the flash loan fee</td></tr><tr><td><code>flash_loans_enabled</code></td><td><code>boolean</code></td><td>Whether flash loans are enabled</td></tr><tr><td><code>hinj</code></td><td><code>AssetInfo</code></td><td>AssetInfo for the hINJ token</td></tr><tr><td><p><code>hinj.</code></p><p><code>token.</code></p><p><strong><code>contract_addr</code></strong></p></td><td><code>Addr</code></td><td>The contract address of the hINJ token</td></tr><tr><td><code>nept</code></td><td><code>AssetInfo</code></td><td>AssetInfo for the NEPT token</td></tr><tr><td><p><code>nept.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination of NEPT native token</td></tr></tbody></table>

***

### Execute Messages

### 1. Receive

**Execute:** `receive`

**Purpose:** Handles incoming CW20 token transfers through the CW20 hook mechanism, allowing the contract to process token-specific operations based on the encoded instructions in the message.

```json
{
  "receive": {}
}
```

### 2. Lend

**Execute:** `lend`

**Purpose:** Allows users to provide assets to the lending pool, which increases the pool's liquidity and enables the lender to receive nTokens representing their lending position.

```json
{ 
    "lend": {}
},
"funds": "1000000peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
```

| Parameter | Type   | Description                                   | Required |
| --------- | ------ | --------------------------------------------- | -------- |
| `funds`   | `Coin` | The amount and denomination of tokens to lend | Yes      |

### 3. Redeem

**Execute:** `redeem`

**Purpose:** Allows users to withdraw their lending deposits by burning their nTokens in exchange for the underlying asset plus any accrued interest.

```json
{
  "sender": "inj142aemh62w2fpqjws0yre5936ts9x9e93fj8322",
  "contract": "inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s",
  "msg": {
    "send": {
      "amount": "829841",
      "contract": "inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u",
      "msg": "eyJyZWRlZW0iOnt9fQ==" //{"redeem":{}}
    }
  },
  "funds": "0"
}
```

<table><thead><tr><th>Parameter</th><th width="178">Type</th><th width="268">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>sender</code></td><td><code>Addr</code></td><td>Wallet address of the user redeeming tokens</td><td>Yes</td></tr><tr><td><code>contract</code></td><td><code>Addr</code></td><td>nToken contract address that is initiating the redeem operation</td><td>Yes</td></tr><tr><td><code>msg</code></td><td><code>Cw20ReceiveMsg</code></td><td>CW20 hook message wrapping the redeem instruction</td><td>Yes</td></tr><tr><td><code>msg.send</code></td><td><code>object</code></td><td>Nested message instructing the market contract regarding the redeem sub-message</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>amount</code></strong></p></td><td><code>Uint128</code></td><td>The amount of nTokens to be redeemed</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>contract</code></strong></p></td><td><code>Addr</code></td><td>Market contract address that should process the redeem sub-message</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>msg</code></strong></p></td><td><code>Binary</code></td><td>Base64 encoded sub-message (which decodes to <code>{ "redeem": {} }</code>)</td><td>Yes</td></tr><tr><td><code>funds</code></td><td><code>Coin</code></td><td>Not used in this operation. Must be set to <code>"0"</code></td><td>Yes</td></tr></tbody></table>

### 3.1 Deposit Collateral (Native Token)

**Execute:** `deposit_collateral`

**Purpose:** Enables users to deposit native tokens as collateral into a specified margin account, which can then be used to secure borrowed positions.

```json
{
  "deposit_collateral": {
    "account_index": 0
  }
},
"funds": "1000000peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
```

<table><thead><tr><th width="183">Parameter</th><th width="128">Type</th><th width="304">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The index of the account to deposit collateral into</td><td>Yes</td></tr><tr><td><code>funds</code></td><td><code>Coin</code></td><td>The amount and denomination of tokens to deposit as collateral</td><td>Yes</td></tr></tbody></table>

### 3.2 Deposit Collateral (CW20 Token)

**Execute:** `deposit_collateral`

**Purpose:** Enables users to deposit CW20 tokens as collateral into a specified margin account, which can then be used to secure borrowed positions.

*Example: Applicable to* `hINJ` *token*

```json
{
  "sender": "inj...........",
  "contract": "inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc",
  "msg": {
    "send": {
      "amount": "1000000000000000000",
      "contract": "inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u",
      "msg": "eyJkZXBvc2l0X2NvbGxhdGVyYWwiOnsiYWNjb3VudF9pbmRleCI6Mn19" //{"deposit_collateral":{"account_index":2}}
    }
  },
  "funds": "0"
}
```

<table><thead><tr><th>Parameter</th><th width="176">Type</th><th width="287">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>sender</code></td><td><code>addr</code></td><td>Wallet address of the user depositing tokens (CW20 sender)</td><td>Yes</td></tr><tr><td><code>contract</code></td><td><code>addr</code></td><td>CW20 token contract address initiating the deposit operation</td><td>Yes</td></tr><tr><td><code>msg</code></td><td><code>Cw20ReceiveMsg</code></td><td>Container for the CW20 hook message payload</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><strong><code>send</code></strong></p></td><td><code>object</code></td><td>The CW20 hook message instructing the market contract on how to process the collateral deposit</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>amount</code></strong></p></td><td><code>uint128</code></td><td>The amount of tokens to be deposited as collateral</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>contract</code></strong></p></td><td><code>addr</code></td><td>The market contract address that will process the deposit collateral request</td><td>Yes</td></tr><tr><td><p><code>msg.</code></p><p><code>send.</code></p><p><strong><code>msg</code></strong></p></td><td><code>binary</code></td><td>A Base64-encoded sub-message instructing the market contract to execute the deposit collateral operation</td><td>Yes</td></tr><tr><td><code>funds</code></td><td><code>coin</code></td><td>Not used for this operation. Must be set to <code>"0"</code></td><td>Yes</td></tr></tbody></table>

### 4. Withdraw Collateral

**Execute:** `withdraw_collateral`

**Purpose:** Allows users to withdraw their deposited collateral from a margin account, provided the withdrawal doesn't violate the account's minimum collateralization requirements.

```json
{
  "withdraw_collateral": {
    "account_index": 0,
    "asset_info": {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    "shares": "1000000"
  }
}
```

<table><thead><tr><th width="183">Parameter</th><th>Type</th><th width="275">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The index of the account to withdraw collateral from</td><td>Yes</td></tr><tr><td><code>asset_info</code></td><td><code>AssetInfo</code></td><td>Information about the asset being withdrawn</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr><tr><td><code>shares</code></td><td><code>Uint256</code></td><td>The number of shares to withdraw</td><td>Yes</td></tr></tbody></table>

### 5. Borrow

**Execute:** `borrow`

**Purpose:** Enables users to borrow assets against their deposited collateral, subject to the account's collateralization ratio requirements and market's borrowing limits.

```json
{
  "borrow": {
    "account_index": 0,
    "amount": "1000000",
    "asset_info": {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    }
  }
}
```

<table><thead><tr><th width="184">Parameter</th><th width="145">Type</th><th width="288">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The index of the account to withdraw collateral from</td><td>Yes</td></tr><tr><td><code>amount</code></td><td><code>Uint256</code></td><td>Amount of tokens to borrow</td><td>Yes</td></tr><tr><td><code>asset_info</code></td><td><code>AssetInfo</code></td><td>Information about the asset being withdrawn</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr></tbody></table>

### 6. Return

**Execute:** `return`

**Purpose:** Allows users to repay borrowed assets to their margin account, reducing their debt position and associated interest accrual.

```json
{
    "return": {
      "account_index": 0
    }
},
"funds": "1000001peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
```

<table><thead><tr><th width="185">Parameter</th><th width="131">Type</th><th width="297">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The index of the account to return tokens to</td><td>Yes</td></tr><tr><td><code>funds</code></td><td><code>Coin</code></td><td>The amount and denomination of tokens to return</td><td>Yes</td></tr></tbody></table>

### 7. Inject

**Execute:** `inject`

**Purpose:** Enables privileged addresses to inject liquidity into market pools (lending, borrowing, or collateral) to manage pool balances, compound rewards, or adjust yields. Injecting into lending or collateral pools increases their value, while injecting into borrow pools decreases the system's debt.

```json
{
    "inject": {
      "injection_type": "lend"
  }
},
"funds": "1000000peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
```

<table><thead><tr><th width="194">Parameter</th><th width="151">Type</th><th width="290">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>injection_type</code></td><td><code>RewardType</code></td><td>Target market pool to inject liquidty to. Can <code>lend</code>, <code>borrow</code>, or <code>collateral</code></td><td>Yes</td></tr><tr><td><code>funds</code></td><td><code>Coin</code></td><td>The amount and denomination of tokens to inject</td><td>Yes</td></tr></tbody></table>

### 8. Borrow Flashloan

**Execute:** `borrow_flash_loan`

**Purpose:** Initiates a flash loan operation, allowing a user to temporarily borrow specified assets for short-lived, atomic operations (e.g., arbitrage, liquidation, or other custom strategies). The borrowed funds are sent directly to a designated flash loan receiver contract along with an array of messages (`msgs`) that instruct the receiver on how to utilize the funds. The entire operation must be completed within one transaction, with the borrowed funds being returned prior to the execution of the final protocol checks.

*NOTE: A user's access to use flash loans, and the flash loan capacity, is gated by the value of their staked NEPT tokens.*

**Execute JSON:**

```json
{
  "borrow_flash_loan": {
    "assets": [
      [
        {
          "native_token": {
            "denom": "inj"
          }
        },
        "1000000"
      ]
    ],
    "msgs": [
      {
        "msg_data": {
          "execute": {
            "custom_operation": {
              "detail": "operation details"
            }
          }
        },
        "route": "custom"
      }
    ],
    "receiver": "inj1wmtzan6tgzg0zyauknuxdnnfjwn350yewjf6fq"
  }
}
```

<table><thead><tr><th width="176">Parameter</th><th width="208">Type</th><th width="254">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>array&#x3C;[AssetInfo, Uint256]></code></td><td>A list of asset-amount pairs representing the tokens to be borrowed</td><td>Yes</td></tr><tr><td><p><code>assets[0].</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>assets[0].</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr><tr><td><code>assets[1]</code></td><td><code>Uint256</code></td><td>Amount of tokens to be flashloaned</td><td>Yes</td></tr><tr><td><code>msgs</code></td><td><code>array&#x3C;CosmosMsg_for_InjectiveMsgWrapper></code></td><td>A list of sub messages to be forwarded and executed by the receiver address</td><td>Yes</td></tr><tr><td><code>receiver</code></td><td><code>Addr</code></td><td>The Flashloan Receiver address</td><td>Yes</td></tr></tbody></table>

### 9. Return Flashloan

**Execute:** `return_flash_loan`

**Purpose:** Used to repay the funds borrowed via a flash loan. Once the flash loan receiver (or borrower) completes its operations utilizing the temporarily provided liquidity, this call returns the exact borrowed amount(s) back to the market contract. The returned funds are then verified by a subsequent check to ensure the entire flash loan is repaid within the same transaction.

*NOTE: The total amount of tokens to be repaid is equal to amount\_borrowed + floashloan\_fee*

**Execute JSON:**

```json
{
  "return_flash_loan": {
    "assets": [
      [
        {
          "native_token": {
            "denom": "inj"
          }
        },
        "1000000"
      ]
    ]
  }
}
```

<table><thead><tr><th width="174">Parameter</th><th>Type</th><th width="322">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>array&#x3C;[AssetInfo, Uint256]></code></td><td>A list of asset-amount pairs representing the tokens to be repaid</td><td>Yes</td></tr><tr><td><p><code>assets[0].</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>assets[0].</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr><tr><td><code>assets[1]</code></td><td><code>Uint256</code></td><td>Amount of tokens to be repaid</td><td>Yes</td></tr></tbody></table>

### 10. Assert Flashloan Repaid

**Execute:** `assert_flash_loan_repaid`

**Purpose:** Ensures that all funds borrowed via a flashloan have been fully repaid within the same transaction. This check is executed after the corresponding `return_flash_loan` call, and if the repayment is incomplete, the entire transaction will revert.

**Execute JSON:**

```json
{
  "assert_flash_loan_repaid": {}
}
```

### 11. Liquidate

**Execute:** `liquidate`

**Purpose:** Performs the liquidation of an undercollateralized margin account. This call allows a liquidator to repay a portion of the outstanding debt in a margin account that has fallen below the required collateralization threshold. In exchange, the liquidator seizes a discounted share of the account's collateral. The parameters ensure that the repaid amount does not exceed the account's outstanding debt and that the collateral received reflects the value of the repaid debt adjusted by the liquidation discount.

**Execute JSON:**

```json
{
  "liquidate": {
    "account_index": 0,
    "repayment_amount": "1000000",
    "asset_info": {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    }
  }
}
```

<table><thead><tr><th width="212">Parameter</th><th width="148">Type</th><th width="293">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The index of the margin account to be liquidated</td><td>Yes</td></tr><tr><td><code>repayment_amount</code></td><td><code>Uint256</code></td><td>The amount of debt to be repaid by the liquidator</td><td>Yes</td></tr><tr><td><code>asset_info</code></td><td><code>AssetInfo</code></td><td>The asset information representing the collateral type</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr></tbody></table>

### 12. Update Market Asset

**Execute:** `update_market_asset`

**Purpose:** Allows privileged addresses to modify market-specific parameters such as interest rates, utilization caps, and operational status for a given asset market.

*NOTE: Only whitelisted addresses can execute* `update_market_asset`

**Execute JSON:**

```json
{
  "update_market_asset": {
    "asset": {
      "native_token": {
        "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
      }
    },
    "market_asset_details": {
      "borrow_cap": null,
      "borrow_halt_utilization": "0.95",
      "enabled": true,
      "interest_fee": "0.02",
      "receipt_addr": "inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g"
    }
  }
}
```

<table><thead><tr><th width="252">Parameter</th><th>Type</th><th width="250">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset</code></td><td><code>AssetInfo</code></td><td>Describes the asset for which the market configuration is to be updated</td><td>Yes</td></tr><tr><td><p><code>asset.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>asset.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr><tr><td><code>market_asset_details</code></td><td><code>MarketAssetDetails</code></td><td>Contains the updated market asset parameters</td><td>Yes</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>receipt_addr</code></strong></p></td><td><code>Addr</code></td><td>The matching CW20 nToken address</td><td>Yes</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>borrow_halt_utilization</code></strong></p></td><td><code>Decimal256</code></td><td>Utilization threshold to halt borrowing</td><td>Yes</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>interest_fee</code></strong></p></td><td><code>Decimal256</code></td><td>The interest fee applied on borrows</td><td>Yes</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>borrow_cap</code></strong></p></td><td><code>Uint256</code></td><td>The borrowing cap for the asset. Can be null</td><td>Yes</td></tr><tr><td><p><code>market_asset_details.</code></p><p><strong><code>enabled</code></strong></p></td><td><code>boolean</code></td><td>Indicates if the market asset is active</td><td>Yes</td></tr></tbody></table>

### 13. Update Collateral Asset

**Execute:** `update_collateral_asset`

**Purpose:** Allows privileged addresses to modify collateral-specific parameters such as LTV ratios, liquidation thresholds, and collateral caps for a given asset.

*NOTE: Only whitelisted addresses can execute* `update_collateral_asset`

**Execute JSON:**

```json
{
  "update_collateral_asset": {
    "asset": {
      "native_token": {
        "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
      }
    },
    "collateral_asset_info": {
      "allowable_ltv": "0.77",
      "collateral_cap": "300000000000",
      "collateral_type": "regular",
      "enabled": true,
      "liquidation_ltv": "0.78",
      "max_discount": "0.12",
      "min_discount": "0.08"
    }
  }
}
```

<table><thead><tr><th width="258">Parameter</th><th>Type</th><th width="232">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset</code></td><td><code>AssetInfo</code></td><td>Describes the asset for which the collateral configuration is to be updated</td><td>Yes</td></tr><tr><td><p><code>asset.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>asset.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr><tr><td><code>collateral_asset_info</code></td><td><code>CollateralDetails</code></td><td>Contains the updated collateral asset parameters</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>allowable_ltv</code></strong></p></td><td><code>Decimal256</code></td><td>The allowable loan-to-value ratio for the collateral asset</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>collateral_cap</code></strong></p></td><td><code>Uint256</code></td><td>The cap on the amount of collateral that can be used in the market</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>collateral_type</code></strong></p></td><td><code>AssetType</code></td><td>The type of collateral (regular or receipt_token)</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>enabled</code></strong></p></td><td><code>boolean</code></td><td>Indicates if the collateral asset is enabled</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>liquidation_ltv</code></strong></p></td><td><code>Decimal256</code></td><td>The loan-to-value ratio at which the collateral is subject to liquidation</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>max_discount</code></strong></p></td><td><code>Decimal256</code></td><td>The maximum discount applied to the collateral during liquidation</td><td>Yes</td></tr><tr><td><p><code>collateral_asset_info.</code></p><p><strong><code>min_discount</code></strong></p></td><td><code>Decimal256</code></td><td>The minimum discount applied to the collateral during liquidation</td><td>Yes</td></tr></tbody></table>

### 14. Distribute Interest

**Execute:** `distribute_interest`

**Purpose:** Updates the protocol's interest rate calculations and distributes accrued interest from borrowers to lenders, maintaining accurate accounting of lending and borrowing positions.

**Execute JSON:**

```json
{
  "distribute_interest": {
    "assets": [
      {
        "native_token": {
          "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
        }
      },
      {
        "native_token": {
          "denom": "inj"
        }
      }
    ]
  }
}
```

<table><thead><tr><th width="176">Parameter</th><th width="197">Type</th><th width="287">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>array&#x3C;AssetInfo></code></td><td>A list of asset information for which interest is to be distributed</td><td>Yes</td></tr><tr><td><p><code>assets[].</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Token type</td><td>Yes</td></tr><tr><td><p><code>assets[].</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Token address</td><td>Yes</td></tr></tbody></table>
