# Overview

Neptune Protocol is a next-generation lending protocol that brings unmatched capital efficiency to decentralized finance on Injective. Through its innovative design, Neptune enables users to lend, borrow, and build with digital assets in ways that maximize returns while maintaining robust security.

## Innovations

#### PID Controlled Interest Rates

Neptune Protocol's innovative interest rate model uses a PID (Proportional-Integral-Derivative) controller to dynamically adjust lending and borrowing rates. By considering current market conditions, historical trends, and rate of change, the system maintains optimal capital efficiency while preventing rate volatility. This sophisticated approach consistently outperforms traditional DeFi models by automatically finding the most efficient rates for market participants.

#### Margin Sub Accounts

Neptune Protocol's margin sub-accounts enable users to create multiple isolated trading positions under a single wallet. This feature allows for separate risk management and distinct collateral pools for different trading strategies, preventing cross-contamination between positions while maintaining clear accounting of DeFi activities.

#### nTokens

nTokens are Neptune Protocol's interest-bearing tokens received when lending assets. They automatically accumulate interest, can be transferred between wallets, used as collateral, and integrated with other DeFi protocols - making lending positions liquid and productive while earning yields.

#### Dynamic Liquidation Discounts

Neptune Protocol innovates on traditional liquidation mechanisms by implementing dynamic liquidation discounts that scale based on account health. When a position becomes eligible for liquidation, the discount starts at a minimum value and increases as the account health deteriorates further, up to a maximum cap. This approach provides better protection for borrowers during minor market movements while ensuring sufficient liquidator incentives during severe market stress, creating a more efficient and resilient liquidation system.

#### NEPT Token Staking Feature Access

Neptune Protocol's NEPT token staking system offers users flexible options through multiple staking pools, each with unique benefits. By staking NEPT, users can access features like flashloans, boost their account health ratios, and earn governance rights. Longer staking periods provide enhanced rewards and greater feature access, while the innovative cascade mechanism allows users to maintain benefits as they transition between staking tiers. This tiered approach rewards long-term protocol engagement while providing users choice in how they interact with Neptune's features.

## User Features

#### Lending

Lend your digital assets to Neptune Protocol to earn competitive yields. Deposits are represented by nTokens which automatically accumulate interest and can be used as collateral or transferred freely. The protocol's advanced PID controller ensures optimal interest rates while maintaining strong security measures to protect user funds.

#### Borrowing

Borrow assets from Neptune Protocol to fuel your trading and DeFi activities. The protocol's flexible borrowing interface allows users to borrow against their collateralized positions, with rates dynamically adjusted based on market conditions.

#### Flashloans

Access instant liquidity with Neptune Protocol's flashloans, which allow users to borrow and repay funds in a single transaction without collateral. This feature is ideal for arbitrage, market making, and other advanced trading strategies.

#### Staking

Stake your NEPT tokens to earn governance rights and participate in protocol decision-making. The protocol's NEPT token staking system offers flexible options through multiple staking pools, each with unique benefits.

#### Analytics

Access real-time analytics and insights to monitor your lending and borrowing activities, account health, and market trends. The protocol's dashboard provides transparent and detailed information about the protocol's performance and user positions.

#### Swaps

Swap between supported assets using the protocol's advanced swap interface, which allows users to exchange digital assets at competitive rates while maintaining strong security measures to protect user funds.

## Getting Started

Visit [app.nept.finance](https://app.nept.finance/) to start using Neptune Protocol.

#### Network

Neptune operates on the Injective blockchain, requiring a small amount of INJ for network fees.

#### Wallet Access

Connect using popular wallets:

* Keplr
* Metamask
* Cosmostation
* Leap
* OKX

#### **Supported Assets**

Currently supported assets include:

<table><thead><tr><th>Crypto Asset</th><th data-type="checkbox">Lend and Borrow</th><th data-type="checkbox">Collateral</th></tr></thead><tbody><tr><td>hINJ</td><td>false</td><td>true</td></tr><tr><td>USDT</td><td>true</td><td>true</td></tr><tr><td>USDC</td><td>true</td><td>true</td></tr><tr><td>AUSD</td><td>true</td><td>true</td></tr><tr><td>INJ</td><td>true</td><td>true</td></tr><tr><td>ATOM</td><td>true</td><td>true</td></tr><tr><td>TIA</td><td>true</td><td>true</td></tr><tr><td>WETH</td><td>true</td><td>true</td></tr><tr><td>SOL</td><td>true</td><td>true</td></tr><tr><td>nUSDT</td><td>false</td><td>true</td></tr><tr><td>nUSDC</td><td>false</td><td>true</td></tr><tr><td>nASUD</td><td>false</td><td>true</td></tr><tr><td>nINJ</td><td>false</td><td>true</td></tr><tr><td>nATOM</td><td>false</td><td>true</td></tr><tr><td>nTIA</td><td>false</td><td>true</td></tr><tr><td>nWETH</td><td>false</td><td>true</td></tr><tr><td>nSOL</td><td>false</td><td>true</td></tr></tbody></table>

## Learn Docs: [Learn](/learn)

The Learn section provides comprehensive documentation about Neptune Protocol's features, mechanics, and risk considerations. Here you'll find detailed explanations of lending, borrowing, interest rates, liquidations, flash loans, and the NEPT token system. These docs help users understand how to effectively and safely interact with the protocol.

## Developer Docs: [Developer](/develop)

Neptune Protocol's Developer Documentation provides comprehensive technical resources for integrating with and building on top of the protocol. Here you'll find detailed smart contract specifications, integration guides, API references, and code examples to help developers effectively interact with Neptune's lending markets and features.

## Community

Join the Neptune Protocol community to stay updated on the latest news, events, and developments.

* [Discord](https://discord.com/invite/xj6tpkdk7k)
* [X](https://x.com/neptune_finance)
* [Telegram](https://t.me/neptunefinance)
* [Website](https://nept.finance)
* [Medium](https://articles.nept.finance/)


# Learn

Welcome to the Neptune Protocol documentation. Here you'll find comprehensive guides and documentation to help you understand how Neptune works and how to use it effectively.

## Core Features

* [Lend](/learn/lend) - Learn how to earn yield by lending assets through Neptune's lending pools
* [Borrow](/learn/borrow) - Learn how to borrow assets using collateral with configurable risk parameters
* [Interest Rate](/learn/interest-rate) - Understand how Neptune's dynamic PID-controlled interest rates work

## Advanced Features

* [Flash Loans](/learn/flash-loans) - Understand how to use Neptune's flash loans for advanced trading strategies
* [Liquidate](/learn/liquidate) - Learn about the liquidation process and how to participate in liquidations

## Native Token

* [NEPT Token](/learn/nept-token) - Learn about the protocol's native token, staking, and governance

## Risks

* [Risks](/learn/risks) - Understand the risks of using the protocol and how to manage them

Each section provides detailed information about different aspects of the protocol. If you're new to Neptune, we recommend starting with the Core Features section before moving on to Advanced Features.


# Lend

Lending in the Neptune Protocol offers a way for users to earn yield on crypto assets which is generated by borrowers. Lending deposits in Neptune are represented by nTokens, a liquid receipt token which can be transferred, used as collateral and utilized in third party protocols. A users lending deposits can be redeemed by returning nTokens to the protocol.

## How Lending Works

Lending in the Neptune Protocol allows users to deposit their digital assets into a lending pool. In return, they receive nTokens, which represent their share of the pool. These nTokens automatically accumulate interest over time.

### Steps to Lend

1. **Deposit Assets**: Users deposit their assets into the Neptune lending pool.
2. **Receive nTokens**: In exchange, users receive nTokens, which are CW20-compliant tokens representing their share of the pool.
3. **Accumulate Interest**: As the pool generates interest, the value of nTokens increases, allowing users to redeem more of the underlying asset than they initially deposited.

### Lending Equation

The value of nTokens increases as interest accrues. The relationship can be expressed as:

$$
\text{nToken Value} = \text{Initial Deposit} \times (1 + \text{Interest Rate})^t
$$

Where:

* `Initial Deposit` is the amount of assets initially deposited.
* `Interest Rate` is the rate at which interest is accrued.
* `t` is the time period over which interest is calculated.

## Understanding nTokens

nTokens are a crucial component of the Neptune Protocol. They serve as proof of a user's lending position and can be used as collateral for borrowing.

### Key Features of nTokens

* **Interest Accumulation**: nTokens automatically accumulate interest, increasing in value over time.
* **Transferability**: nTokens can be transferred between users, maintaining the underlying lending position.
* **Collateral Use**: nTokens can be used as collateral in Neptune markets, allowing users to borrow against their lending positions.

## Redeeming Assets

Redeeming is the process of exchanging nTokens back for the underlying assets. As nTokens accumulate interest, users can redeem them for more assets than they initially deposited.

### Steps to Redeem

1. **Burn nTokens**: Users initiate the redemption process by burning their nTokens.
2. **Receive Assets**: In return, users receive the underlying assets plus any accrued interest.

### Redemption Equation

The amount of assets received upon redemption is calculated as:

$$
\text{Redeemed Assets} = \text{nTokens Burned} \times \text{Current nToken Value}
$$


# Borrow

The Neptune Protocol enables users to borrow digital assets by depositing collateral. Through a sophisticated risk management system, users can create multiple margin accounts, each with configurable risk parameters and isolation settings. The protocol continuously monitors account health and enforces borrowing limits through dynamic interest rates and multi-stage liquidation mechanisms.

## How Borrowing Works

Borrowing in Neptune Protocol follows these key steps:

1. **Deposit Collateral**: Users deposit supported assets as collateral into their chosen margin account
2. **Borrow Assets**: Users can borrow assets up to their account's borrowing capacity
3. **Maintain Health**: Account health must stay above 1.0 to avoid liquidation
4. **Repay Debt**: Users can repay borrowed assets plus accrued interest at any time

A users borrowing capacity depends on the collateral value, debt value and asset-specific parameters.

## Advantages of Borrowing

Borrowing in DeFi offers several key benefits to users. It enables access to liquidity without selling assets, allowing users to maintain their long-term positions while accessing capital for other opportunities. Users can leverage their existing crypto holdings to obtain working capital, take advantage of trading opportunities, or manage short-term expenses. Additionally, borrowing can be used for tax-efficient lending strategies, as borrowing against assets doesn't typically trigger taxable events like selling would. The permissionless and transparent nature of DeFi borrowing also means users can access loans 24/7 without traditional credit checks or lengthy approval processes.

## Margin Sub Accounts

Neptune empowers users with the ability to create multiple isolated margin accounts, each serving as a separate risk container. This powerful feature enables users to:

* Implement different trading strategies without cross-contamination of risk
* Maintain distinct collateral ratios for different purposes
* Isolate high-risk positions from conservative positions
* Organize borrowing activities by purpose (e.g., trading, yield farming, or long-term holdings)

Each sub-account operates independently, ensuring that the performance and health of one account has no impact on the others, providing users with maximum flexibility and risk management control.

## Collateral

To open a margin account and start borrow, a user must first supply a crypto asset as collateral. Collateral is used in the protocol to ensure that outstanding debts can be repaid and maintain system solvency. This means Neptune is an over-collateralized borrowing platform, meaning the value of the collateral must maintain a higher value of the outstanding debt.

Collateral assets have two main parameters that determine the maximum a user can borrow against them and when they would be liquidated;

* `allowable_LTV`
* `liquidation_LTV`

The maximum a user can borrow against a collateral is equal to the allowable\_LTV parameter of the collateral asset

$$
\text{Max Borrow} = \text{Collateral Value} \times \text{Allowable LTV}
$$

Where:

* `Collateral Value`: The USD value of the deposited collateral asset
* `Allowable LTV`: The maximum loan-to-value ratio permitted for this collateral type (e.g., 0.8 for 80%)

A margin account can be liquidated if the account health falls below the liquidation\_LTV parameter of the collateral asset.

$$
\text{Liquidation Value} = \text{Collateral Value} \times \text{Liquidation LTV}
$$

Where:

* `Collateral Value`: The USD value of the deposited collateral asset
* `Liquidation LTV`: The loan-to-value ratio at which the collateral can be liquidated (e.g., 0.7 for 70%)

Multiple collaterals can be used in a margin account, which would then be considered 'cross margin'. Using multiple collaterals can help offset the volatility of any one collateral and protect the account from liquidation.

The value a user can borrow against a basket of mixed collaterals is:

$$
\text{Max Borrow} = \sum\_{i=1}^{n} (\text{Collateral Value}\_i \times \text{Allowable LTV}\_i)
$$

Where:

* `i`: Represents each individual collateral asset in the account
* `n`: The total number of different collateral assets
* `Collateral Value_i`: The USD value of the i-th collateral asset
* `Allowable LTV_i`: The maximum loan-to-value ratio for the i-th collateral type

### Collateral Types

Neptune's advanced configuration allows a user to choose how they use assets as collateral for different risk configurations. The following are a few of the different collateral types that can be used;

#### Tokens

Tokens are common crypto assets such as ETH, USDC or INJ. Their value is derived from the price they trade at on open markets.

#### LSTs

LSTs (Liquid Staking Tokens) are derivatives of tokens that can be staked to earn yield. They are commonly interest bearing and compound in value over time. Their value is derived from their underlying asset value plus the interest they accrue over time.

#### nTokens

nTokens are interest bearing receipt token representing a users lending deposits in Neptune. nTokens compound in value over time and can be redeemed for their underlying assets. Using nTokens allows a user to borrow against their lending positions.

## Borrowing

Once a user has collateral in a margin account they can now borrow any available crypto asset(s) they choose. The amount a user can borrow is determined by the value of their collateral.

Borrowing assets from Neptune incurs a cost, know as the borrow interest, which grows over time and compounds to the debt position. The cost to borrow is dynamic and is set by the Neptune interest rate controller.

$$
\text{Borrow Interest} = \text{Borrow Rate} \times \text{Borrowed Amount}
$$

Where:

* `Borrow Rate`: The annual interest rate charged for borrowing (expressed as a decimal, e.g., 0.05 for 5% APR)
* `Borrowed Amount`: The USD value of the assets borrowed from the protocol

## Account Health

Account health is a metric used in Neptune to represent the risk of a select margin account. It is calculated based on the value of margin account's collateral and debt values

$$
\text{Account Health} = \frac{\text{Weighted Collateral Value}}{\text{Total Debt Value}}
$$

Where:

* `Weighted Collateral Value`: The sum of all USD collateral values multiplied by their respective liquidation\_LTV
* `Total Debt Value`: The total USD value of all borrowed assets plus accrued interest

An account health of great than 1 mean the account is in a healthy state. An account health below 1 means the account is now subject to liquidation, where a user's collateral can be seized by a third party who repays their outstanding debt.


# Interest Rate

The Neptune Protocol uses an advanced interest rate model powered by a PID (Proportional-Integral-Derivative) controller to dynamically adjust lending and borrowing rates. This system aims to maintain optimal capital efficiency while ensuring market stability.

## How Interest Rates Work

Neptune's interest rates automatically adjust based on market conditions, primarily the utilization ratio of each lending pool. When more users borrow from a pool, rates increase to encourage lending. When borrowing decreases, rates lower to stimulate borrowing activity.

The protocol targets an optimal utilization ratio for each asset. This "sweet spot" balances capital efficiency with maintaining sufficient liquidity for withdrawals and helps the market find the ideal natural rates for lenders and borrowers.

The dynamic nature of Neptune's interest rates continually out performs competition by adjusting to real time market conditions and demand.

## The PID Controller

Neptune employs a PID controller - a sophisticated feedback mechanism used in industrial control systems - to manage interest rates. The controller continuously monitors the market's utilization ratio and adjusts rates by considering three components:

### Proportional Component (P)

Responds to the current deviation from the target utilization ratio. If utilization is too high, this component increases rates proportionally to the deviation.

### Integral Component (I)

Accounts for historical deviations, helping eliminate persistent offsets from the target utilization. This ensures long-term stability of the market.

### Derivative Component (D)

Responds to the rate of change in utilization, helping prevent rapid swings by dampening sudden movements.

## Interest Rate Equation

The base interest rate for any asset is calculated as:

$$
\text{Rate} = \text{Output}*{\text{PID}} \times \text{Polynomial}*{\text{curve}}
$$

Where:

* $$\text{Output}\_{\text{PID}}$$ is the controller's output based on utilization
* $$\text{Polynomial}\_{\text{curve}}$$ is an asset-specific curve that can amplify or dampen the rate response

## Market-Specific Parameters

Each asset market has configurable parameters that influence its interest rate behavior:

* **Target Utilization**: The optimal utilization ratio (typically 65-80%)
* **PID Coefficients**: (K\_p), (K\_i), and (K\_d) values that determine the controller's response
* **Rate Limits**: Maximum and minimum bounds for interest rates
* **Sample Period**: How frequently the controller updates rates

## Example Rate Adjustment

Consider a market with 70% target utilization:

1. Current utilization rises to 85%
2. PID controller detects this +15% deviation
3. Controller increases rates based on:
   * Immediate response to the 15% gap (P)
   * Accumulated time above target (I)
   * Speed of utilization increase (D)
4. Higher rates incentivize more lenders and fewer borrowers
5. Market gradually returns to target utilization

## Advantages of PID Control

Neptune's PID-based interest rate model offers several benefits:

* **Precise Control**: Maintains utilization close to optimal targets
* **Smooth Adjustments**: Prevents sudden rate spikes that could destabilize markets
* **Market Adaptability**: Automatically responds to changing market conditions
* **Customization**: Parameters can be tuned per asset based on market characteristics


# Liquidate

Liquidations are a crucial risk management mechanism in the Neptune Protocol that helps maintain the overall health and solvency of the lending markets. When a borrower's account health falls below 1.0, their collateral becomes eligible for liquidation, allowing other users to repay a portion of their debt in exchange for their collateral at a discount.

## How Liquidations Work

The liquidation process in Neptune follows these key steps:

1. **Monitor Account Health**: A margin account health must stay above 1.0 to avoid liquidation
2. **Liquidation Trigger**: When health drops below 1.0, the account becomes eligible for liquidation
3. **Liquidation Calculation**: Liquidators queries the market to verify debts to repay
4. **Liquidator Action**: Any user can act as a liquidator by repaying some of the borrower's debt
5. **Collateral Transfer**: The liquidator receives discounted collateral in exchange for debt repayment

## Race Conditions

The Neptune liquidation market is a first-come-first-serve implementation. Meaning when a liquidation opportunity becomes available, it is the liquidator who executes the transaction first who will capture the profits.

## Account Health Calculation

A liquidator can monitor the Neptune market for accounts with low Account Health values that may soon be subject to liquidation. They can query the market and calculate the various margin Account Health values.

Account health is calculated using the following formula:

$$
\text{Account Health} = \frac{\text{Weighted Collateral Value}}{\text{Total Debt Value}}
$$

Where:

* `Weighted Collateral Value`: Sum of all USD collateral values multiplied by their respective liquidation\_LTV
* `Total Debt Value`: Total USD value of all borrowed assets plus accrued interest

## Partial Liquidations

A margin account can be either be fully or partially liquidated. A Partial liquidation means that only part of the accounts debt is repaid and collateral seized, where as a full liquidation pays back all the debt, seizes all of the collateral and closes the margin account.

If an account is to be fully or partially liquidated is determined by the `partial_liquidation_threshold` parameter set in the market contract. This parameter is set as a USD value, and any account with net collateral values below this value will be fully liquidated.

## Dynamic Liquidation Discounts

When a margin account is subject to liquidation, its collateral is offered at a discount from the oracle price to incentivize third parties to participate in liquidations. Discounted collateral ensures a liquidator can capture a profitable trade in a timely manner.

Neptune innovates on the standard liquidation discounts by offering a dynamic discount range. This allows the protocol to set a `min_discount and max_discount` on each available collateral asset. The `min_discount` first becomes available when a margin account has an account health just below 1. As the account health grows further below 1, the applied discount grows until it reaches the `max_discount` value. The rate at which the discount grows is set by the `dynamic_discount_width` parameter set by the protocol.

In affect the dynamic discounts allow for reduced impact on a user's margin account position during a partial liquidation, and offers more opportunity for liquidators to make profitable trades when markets are more volatile, keeping Neptune markets solvent.

$$
\text{Discount} = \text{min discount} + (\text{max discount} - \text{min discount}) \times \min(1, \frac{1 - \text{Account Health}}{\text{dynamic discount width}})
$$

Where:

* `min_discount` is the minimum discount applied when account health is just below 1.0
* `max_discount` is the maximum possible discount that can be applied
* `Account Health` is the current health ratio of the margin account
* `dynamic_discount_width` is the protocol parameter that controls how quickly the discount scales (typically \~0.02)

The formula ensures the discount scales linearly from min to max as account health deteriorates, capped at the maximum discount.

## Target Account Health

During a partial liquidation, the market calculates the required debt to be repaid to bring the account back to a targeted Account Health Value. This target value is set the protocol parameter `target_liquidation_health`. From this calculation the liquidator will be able to determine the amount of collateral that will be seized.

$$
\text{Target Repayment Amount} = \text{Total Debt Value} \times (1 - \frac{\text{Weighted Collateral Value}}{\text{Total Debt Value} \times \text{Target Liquidation Health}})
$$

Where:

* `Total Debt Value` is the current total borrowed amount plus accrued interest
* `Weighted Collateral Value` is the sum of all collateral values multiplied by their respective liquidation\_LTV
* `Target Liquidation Health` is the protocol parameter (typically > 1.0) representing the desired health ratio after liquidation

This formula calculates how much debt needs to be repaid to restore the account's health ratio to the target level.

## NEPT Staking Account Health Modifier

Through the process of staking NEPT to the protocol in certain bonding pools, a user may allocate the value of their stake against one or multiple of their margin accounts. Doing this will award the margin account with a boosted Account Health value, providing the user with the benefit for greater risk management.

A liquidator may need to account for the a users stake positions when identifying at risk margin accounts. Read more about it in the [NEPT Token](/learn/nept-token) doc.

## Liquidation Process

When an account becomes eligible for liquidation:

1. **Liquidation Request**
   * System calculates repayable debt amounts
   * Identifies available collateral for liquidation
   * Determines collateral discounts
2. **Collateral Pricing**
   * Collateral value is determined by oracle prices
   * Liquidators receive a discount on the collateral
   * Discount varies by asset
3. **Execution**
   * Liquidator repays a portion of the borrower's debt
   * Receives discounted collateral in return
   * Transaction must complete atomically

## nToken Rebasing

In an unlikely event that a liquidation would occur where a margin accounts collateral value is less than the outstanding debt, a liquidator would only repay an amount of debt which is equivalent to the collateral value. This would create a bad debt balance in the Neptune market as the margin account now has no collateral value to cover the outstanding debt.

When a bad debt situation occurs, to avoid a run on the bank scenario, the protocol rebases the redemption rate for the nToken of the market the bad debt is related to. The rebasing of the redemption rate now accurately reflects the available underlying principle of the target market, making the market solvent again.

After a rebasing event occurs, protocol governance or third parties can elect to inject more capital into the target market to bring the nToken redemption rate back to its original value.

$$
\text{New Redemption Rate} = \frac{\text{Total Available Assets}}{\text{Total nToken Supply}} = \frac{\text{Total Lending Principal} - \text{Bad Debt}}{\text{Total nToken Supply}}
$$

Where:

* `Total Available Assets` is the remaining assets after accounting for bad debt
* `Total Lending Principal` is the original amount of assets in the lending pool
* `Bad Debt` is the uncovered portion of defaulted loans
* `Total nToken Supply` is the total supply of nTokens in circulation

## Best Practices

For borrowers to avoid liquidation:

1. **Monitor Account Health**: Regularly check account health metrics
2. **Maintain Buffer**: Keep health ratio well above 1.0
3. **Risk Management**: Use multiple collateral types to reduce volatility
4. **Quick Action**: Add collateral or repay debt if health approaches 1.0

For liquidators:

1. **Monitor Opportunities**: Watch for accounts near liquidation
2. **Gas Optimization**: Prepare efficient liquidation transactions
3. **Price Impact**: Consider market depth when liquidating large positions


# Flash Loans

Flash loans in the Neptune Protocol allow users to borrow assets without collateral, as long as the borrowed amount is returned within the same transaction. This powerful feature enables sophisticated trading strategies, arbitrage opportunities, and efficient debt refinancing.

## How Flash Loans Work

When executing a flash loan, the protocol:

1. Lends the requested assets to the borrower
2. Executes the borrower's specified series of operations
3. Verifies the borrowed amount plus fees are returned
4. Completes or reverts the entire transaction

All of these steps occur atomically - either all succeed together, or the entire transaction is rolled back, ensuring the protocol's safety.

## Accessing Flashloans

Flashloan access in Neptune in gated by NEPT token staking, where the amount and value of your NEPT token stake determines the amount of value a user can Flashloan from the protocol.

For a users to be able to access Flashloans from the Neptune protocol, they must first stake NEPT into staking pool 3. The amount of NEPT staked to this pool, and the market value of NEPT is used in conjunction with the Flasloan Multiplier to determine the maximum value the user can utilise in a single Flashloan process.

This token gating feature was introduced to mitigate against misuse of Flashloans. Where in the past Flashloans have been utilized in malicious trading strategies to exploit vulnerabilities in third party protocols. Having to stake NEPT to first access Flashloans, requires the user to put up their own capital, increasing the cost of malicious behaviour and a potential loss to the user if protocol governance determines they are a bad actor.

## Flash Loan Components

### Borrowing and Fees

Flash loans in Neptune incur a small fee (typically 0.1%) on the borrowed amount. The total repayment amount is calculated as:

$$
\text{Repayment Amount} = \text{Borrowed Amount} \times (1 + \text{Flash Loan Fee})
$$

### Flash Loan Receiver

The Flash Loan Receiver contract acts as an intermediary that:

* Receives the borrowed funds
* Executes the user's specified operations
* Ensures proper repayment
* Handles any remaining asset management

## Common Use Cases

Flash loans enable several powerful strategies:

1. **Arbitrage**
   * Exploit price differences across exchanges
   * Execute trades with zero initial capital
   * Return loan plus fees from arbitrage profits
2. **Collateral Swaps**
   * Refinance existing loans
   * Switch collateral types efficiently
   * Optimize borrowing positions
3. **Liquidations**
   * Access capital for liquidation opportunities
   * Execute liquidations without holding reserves
   * Profit from discounted collateral sales

## Safety Mechanisms

Neptune's flash loans incorporate several safety features:

1. **Atomic Execution**
   * All operations must succeed, or everything reverts
   * No partial execution possible
   * Protocol assets always protected
2. **Validation Checks**
   * Verification of full repayment
   * Fee calculation and collection
   * Asset balance reconciliation
3. **Access Controls**
   * Whitelisted receiver contracts
   * Validated operation sequences
   * Protected callback functions


# NEPT Token

The NEPT token is the native governance and utility token of the Neptune Protocol. It serves multiple purposes within the ecosystem, including protocol governance, incentive distribution, risk management, and feature access.

## Token Utility

NEPT tokens have several key utilities within the Neptune Protocol:

1. **Protocol Governance**
   * Staked NEPT tokens grant voting power in protocol governance
   * Different staking durations provide varying governance weights
   * Enables community-driven decision making
2. **Staking Rewards**
   * Users can stake NEPT tokens to earn protocol emissions
   * Rewards are distributed based on staking duration and amount
   * Longer staking periods earn higher reward weights
3. **Risk Management**
   * Staked NEPT can contribute to account health calculations
   * Health-weighted stake helps secure protocol positions
   * Provides additional stability to the protocol
4. **Flashloan Access**
   * Staked NEPT grants a user access to the flashloan feature
   * Flashloans can be used for advanced atomic trading stragies
   * Zero collateral required to used flashloans

## Staking Mechanics

NEPT tokens can be staked (bonded) to the protocol for different durations, each with unique properties. When a user stakes to a select staking pool, their tokens immediately earn staking rewards and grants the user additional benefits of the selected staking pool.

Each staking pool has the following traits set at different values;

* `Bonding Duration:` Determines if a user was to unstake their NEPT, how long it would take for those tokens to become claimable.
* `Reward Multiplier:` The amount of weighted staking rewards the pool receives
* `Governance Weight Multiplier:` The governance weight allocated to the user based on the amount of NEPT staked to that pool
* `Health Boost Multiplier:` The maximum Account Health boost provided to a users selected margin account when staking their NEPT to that targeted pool and margin account.

$$
\text{Account Health Boost} = \text{Account Health} \times (1 + (\text{NEPT Stake Value} \times \text{Health Boost Multiplier}))
$$

* `Flashloan Multiplier:` The amount of value a user can flashloan from the protocol based on the value of their staked NEPT.

With each staking pool, the longer the Bonding Duration, grants the user with greater the rewards, multipliers and feature access.

### Staking Pools

#### **Staking Pool 1**

* **Bonding Duration:** 7 days
* **Reward Weight Multiplier:** 1x
* **Governance Weight Multiplier:** 1x
* **Health Boost Multiplier:** 0
* **Flashloan Multiplier:** 0

#### **Staking Pool 2**

* **Bonding Duration:** 30 days
* **Reward Weight Multiplier:** 2x
* **Governance Weight Multiplier:** 2x
* **Health Boost Multiplier:** 3%
* **Flashloan Multiplier:** 0

#### **Staking Pool 3**

* **Bonding Duration:** 90 days
* **Reward Weight Multiplier:** 3x
* **Governance Weight Multiplier: 3x**
* **Health Boost Multiplier:** 3%
* **Flashloan Multiplier:** 10x

### Staking to a Margin Account

When a user stakes NEPT to any pool, they have the option to allocate the value of the stake NEPT to any of their active margin accounts. Doing this can provide a Health Boost to the selected margin account, which increases the overall Account Health to the margin account and helps protect the account from liquidation.

A user can choose to allocate all their NEPT to a single margin account or spread it across multiple accounts. The user can also choose to reallocate their staked NEPT to another margin account at any time, without having to unstake and restake, using the rebonding process.

If an margin account with an allocated NEPT stake were to be liquidated, the NEPT is not claimed in the liquidation process, and it still protected and allocated in the staking pool for the user.

### Unbonding Process

A user can choose to unstake (unbond) their NEPT tokens from the staking pools at any time. When they do a cooldown timer is allplied to the amount of NEPT they choose to unstake, which is determined by the bond duration of the staking pool they unstaked the tokens from.

Once the cooldown period has ended for any unbonding NEPT, the user can now claim their NEPT to their wallet.

During the unbonding and cooldown process, the NEPT currently unbonding does not earn any staking rewards and removes any benefits granted to the user via the selected staking pool. If a user is unbonding from a staking pool greater than Staking Pool 1, they can utilize the Cascade Mechanism to transition their staked NEPT through the staking pools and earn rewards while they wait for their NEPT to fully unbond.

### Cascade Mechanism

The Cascade Mechanism is a unique feature to NEPT staking that allows a user to transition their staked NEPT from one staking pool to a lower staking pool during an unbonding process. This allows the user to earn the staking rewards and feature access of the lower pools as their NEPT moves through the unbonding process.

Once an cascade unbonding process has started, it moves the staked NEPT from the current staking pool, to the next lower staking pool and starts the cooldown timer based on the previous pool. The NEPT stays in this new pool until the cooldown timer is equivalent to the bonding period of the new pool, which then it can now cascade the NEPT down to the next staking pool.\
\
**Example:** A user has NEPT staked in Staking Pool 3 with a 90 day unbonding period. When the user starts the unbonding cascade mechanism, the NEPT is moved to Staking Pool 2 and the cooldown timer starts with a 90 day cooldown period.\
Once the cooldown timer reaches 30 days (the bond duration for Staking Pool 2), the cascade mechanism now transitions the NEPT from Staking Pool 2 to Staking Pool 1, and continues the process.

### Rebonding

Rebond allows a user to move their staked NEPT from one staking pool to another, or allows them to reallocated the NEPT against any of their active margin accounts for Health Boost benefits.

A user can rebond, if they already have an active NEPT stake in any of the staking pools.

Rebonding from a lower pool to a higher pool can be done at any time, even if there is an active cooldown timer on the current NEPT stake, as long as the current cooldown timer is lower the bonding duration of the selected pool.

Rebonding from a higher pool to a lower pool actives the cooldown timer, and if they user wants to rebond again to a lower pool, they must wait until the cooldown timer is equal to the bonding duration of the lower pool.

## Staking Rewards

Staking rewards are generated through token emission where new NEPT tokens are minted and distributed to the staking pools based on the total NEPT staked to each pool. Protocol governance can decide to increase or decrease token emissions to incentivize staking activity.

New NEPT tokens being minted via emission is capped by the maximum token supply, meaning the amount of NEPT that can be minted in not infinite.

NEPT rewards are issued continuously and can be claimed by a user staking NEPT at any time.

Future protocol upgrades will allocate protocol fees towards NEPT stakers for additional rewards.


# Flash Swaps

Flash Swaps in the Neptune Protocol allow users to atomically swap their collateral or debt positions without needing to manually unwind and rebuild their margin accounts. By leveraging Neptune's [flash loan](/learn/flash-loans) infrastructure, Flash Swaps execute complex multi-step operations in a single transaction, ensuring that users can efficiently restructure their positions with minimal risk and no intermediate exposure.

## How Flash Swaps Work

Flash Swaps utilise Neptune flash loans to temporarily access the liquidity needed to restructure a user's margin account. The entire process is atomic, meaning all steps either succeed together or the transaction is fully reverted, protecting both the user and the protocol.

Neptune supports two types of Flash Swaps:

* **Collateral Swaps**: Change the collateral asset in a margin account from one asset to another
* **Debt Swaps**: Change the debt asset in a margin account from one asset to another

Both operations require the user to have an active margin account on Neptune and to have granted the Flash Swap contract authorization to execute operations on their behalf.

## Collateral Swaps

A collateral swap allows a user to replace the collateral backing their margin account with a different asset, all within a single transaction. This is useful when a user wants to rotate into a more favourable collateral type, reduce exposure to a specific asset, or take advantage of yield opportunities without closing their borrowing position.

### Collateral Swap Flow

1. **Initiate Flash Loan**: The user initiates a flash loan from Neptune Market for the target collateral asset
2. **Deposit New Collateral**: The flash-loaned target asset is deposited as collateral into the user's margin account
3. **Withdraw Old Collateral**: The original collateral is withdrawn from the user's margin account
4. **Swap Assets**: The withdrawn collateral is swapped on the DEX for the target asset
5. **Repay Flash Loan**: The flash loan is repaid from the swap proceeds, including all applicable fees
6. **Verify Position**: The protocol verifies the margin account remains healthy with the new collateral

### Supported Collateral Paths

Flash Swaps support multiple collateral types and automatically handle the conversion paths between them:

* **Token to Token**: A direct swap on the DEX (e.g., INJ to USDT)
* **Token to nToken**: A DEX swap followed by lending the target asset to receive the nToken (e.g., INJ to nUSDT)
* **nToken to Token**: Redeeming the nToken for the underlying asset, then swapping on the DEX (e.g., nINJ to USDT)
* **nToken to nToken**: Redeeming the source nToken, swapping the underlying assets, and lending to receive the target nToken (e.g., nINJ to nUSDT)
* **Same Underlying Conversions**: When the source and target share the same underlying asset, no DEX swap is required. The contract converts directly by redeeming or lending (e.g., INJ to nINJ or nINJ to INJ)

## Debt Swaps

A debt swap allows a user to change the asset they have borrowed, without needing to source the repayment asset externally. This is useful when a user wants to switch their debt to a lower interest rate asset, reduce exposure to a volatile borrowed asset, or restructure their position to optimize account health.

### Debt Swap Flow

1. **Initiate Flash Loan**: The user initiates a flash loan for the target debt asset
2. **Swap to Source Debt**: The flash-loaned target asset is swapped on the DEX for the current debt asset
3. **Repay Original Debt**: The original debt is repaid in the user's margin account
4. **Borrow Target Asset**: The target asset is borrowed against the user's existing collateral
5. **Repay Flash Loan**: The newly borrowed target asset is used to repay the flash loan, including all applicable fees

Debt swaps are currently supported for native tokens only.

## Accessing Flash Swaps

### NEPT Staking Requirement

Flash Swaps are built on top of Neptune's flash loan infrastructure and therefore require the same access. Users must have NEPT tokens staked in Staking Pool 3 to access flash loans. The maximum value a user can utilize in a Flash Swap is determined by the value of their staked NEPT and the Flashloan Multiplier. See [NEPT Token](/learn/nept-token) for details on staking requirements.

### Authz Grants

Users must grant the Flash Swap contract authorization to execute Neptune Market operations on their behalf. This is done through Injective's authz module, which allows the contract to deposit, withdraw, borrow, and repay assets in the user's margin account during the atomic swap process. The grant provided to the contract is used exclusively to execute flash swap transactions.

## Slippage Protection

When estimating flash swap execution, output amounts are determined by the available prices and liquidity of Injective CLOB exchange. Large spreads and inefficient markets can contribute to losses when executing swaps. Users can specify a slippage tolerance parameter when initiating a flash swap, which sets the minimum acceptable output from the DEX swap. If the swap output falls below this threshold, the entire transaction reverts, protecting the user from unfavourable price movements.

## Minimum Swap Quantities

Due to the functionality and parameter design of the Injective CLOB exchange, every swappable asset is limited by;

* minimum trade quantity (the amount which is being swapped)
* minimum notional value of a swap (value of tokens being swapped, typically $1 minimum)

The Flash Swap contract accounts for these minimums and rounds tokens values where needed to meet the minimum execution parameters for spot market swaps. This rounding can cause dust to accumulate in a users margin account and ensures swaps can execute without failure.

Limitation on minimum execution are usually only an issue when attempting to swap very small amounts of tokens.

## Fees

Flash Swaps incur the following fees during execution:

* **Flash Loan Fee**: A fee charged by Neptune Market for accessing the flash loan (typically 0.1%). See [Flash Loans](/learn/flash-loans) for details.
* **Protocol Fee**: A fee charged by the Flash Swap contract on the swap output amount. This fee is sent to the protocol fee recipient.
* **DEX Swap Fee**: Standard trading fees incurred when swapping assets on the decentralized exchange.

The protocol fee is calculated as:

$$
\text{Protocol Fee} = \text{Swap Output} \times \text{Flash Swap Fee Rate}
$$

The total cost to the user is the sum of all three fees, which are deducted from the swap proceeds before the final position is settled.

## Safety Mechanisms

Flash Swaps incorporate several layers of protection to ensure the security of user funds and protocol solvency:

1. **Atomic Execution**
   * All steps in a Flash Swap execute within a single transaction
   * If any step fails, the entire operation reverts with no partial state changes
   * User positions are never left in an intermediate or vulnerable state
2. **Reentrancy Protection**
   * The contract enforces that only one swap operation can be in progress at a time
   * Concurrent swap attempts are rejected to prevent reentrancy attacks
3. **Caller Validation**
   * Flash loan callbacks are restricted to the Neptune Market contract
   * Internal processing messages can only be invoked by the Flash Swap contract itself
   * All callback data is validated before execution
4. **Token Whitelisting**
   * Only whitelisted tokens with verified configurations can be used in Flash Swaps
   * Each whitelisted token has a minimum swap amount configured to comply with DEX tick sizes
5. **Pause Functionality**
   * Protocol administrators can pause Flash Swap operations in the event of an emergency
   * Pausing prevents all new swap operations while existing state remains intact

## Common Use Cases

Flash Swaps enable several strategies for managing positions on Neptune:

1. **Collateral Rotation**: Swap volatile collateral for stable assets to protect a margin account from liquidation, or swap into a higher-yield collateral to earn more on lending positions
2. **Debt Optimization**: Switch borrowed assets to take advantage of lower interest rates on a different asset, reducing ongoing borrowing costs
3. **Risk Reduction**: Replace concentrated collateral exposure with a more diversified or less volatile asset without closing the borrowing position
4. **Yield Maximization**: Convert standard token collateral into nToken collateral to earn lending yield while maintaining the same borrowing position


# Risks

The Neptune Protocol, like all DeFi protocols, carries inherent risks that users should carefully consider before participating. Understanding these risks is essential for making informed decisions about using the protocol.

## Smart Contract Risk

Smart contract risk refers to potential vulnerabilities or bugs in the protocol's code that could lead to unexpected behavior or loss of funds. While Neptune's smart contracts have undergone thorough auditing and testing, no code is entirely risk-free. To mitigate these risks:

* All protocol smart contracts are audited by reputable security firms
* The protocol implements time-locks on critical parameter changes
* Emergency pause functionality exists for extreme scenarios

## Oracle Risk

Neptune relies on price oracles to determine asset values, collateral ratios, and liquidation triggers. Oracle-related risks include:

* Delayed price updates during high volatility
* Potential manipulation of price feeds
* Technical failures in oracle infrastructure
* Network congestion affecting price updates

To minimize oracle risks, Neptune:

* Uses multiple high-quality oracle providers
* Implements price deviation checks
* Maintains fallback oracle mechanisms
* Monitors oracle health in real-time

## Market Risk

Market risk encompasses the potential for losses due to asset price volatility and market conditions. Key considerations include:

* Sudden price movements triggering liquidations
* Market-wide volatility affecting collateral values
* Correlation risk between different assets
* Limited liquidity during market stress

The protocol manages market risk through:

* Conservative collateral ratios
* Dynamic liquidation thresholds
* Multi-stage liquidation processes
* Diversified collateral options

## Liquidation Risk

Users who borrow assets face the risk of liquidation if their account health falls below required thresholds. Liquidation risks include:

* Loss of collateral at discount prices
* Partial or complete position closure
* Market impact during liquidation

Users can manage liquidation risk by:

* Maintaining healthy collateral ratios
* Monitoring account health regularly
* Using multiple collateral types
* Setting up safety buffers

## Governance Risk

Governance-related risks involve protocol decision-making and parameter changes:

* Misaligned incentives
* Contentious proposals
* Parameter optimization challenges
* Voting power concentration

To address governance risks, Neptune:

* Implements timelocks on changes
* Requires quorum for decisions
* Maintains transparent governance
* Encourages community participation

## Risk Mitigation

Users can take several steps to manage their risk exposure:

1. **Diversification**
   * Use multiple collateral types
   * Maintain positions across different protocols
   * Balance risk exposure
2. **Monitoring**
   * Regular account health checks
   * Market condition awareness
   * Protocol parameter updates
3. **Conservative Positioning**
   * Maintain safe collateral ratios
   * Plan for market volatility
4. **Education**
   * Understand protocol mechanics
   * Stay informed about updates
   * Participate in governance

Remember that while Neptune implements various risk management measures, users are ultimately responsible for understanding and accepting the risks involved in using the protocol.


# Develop

The Neptune lending market integrates a variety of modules—each addressing critical aspects of decentralized finance—to create an ecosystem that supports lending, borrowing, staking, collateral manage


# Contracts

The Neptune Protocol consists of several core smart contracts that work together to provide lending, borrowing, and other DeFi functionality:

## Core Contracts

### Market Contract

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

Core component responsible for handling lending, borrowing, collateral management, flash loans and liquidations.

### Interest Model Contract

**Address:** [inj1ftech0pdjrjawltgejlmpx57cyhsz6frdx2dhq](https://injscan.com/contract/inj1ftech0pdjrjawltgejlmpx57cyhsz6frdx2dhq/)

Manages and computes interest rates using a configurable PID controller based on market utilization.

### Token Contract

**Address:** [inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva](https://injscan.com/contract/inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva)

Manages the NEPT token, including minting, bonding, unbonding, and staking functionality.

### Oracle Contract

**Address:** [inj1u6cclz0qh5tep9m2qayry9k97dm46pnlqf8nre](https://injscan.com/contract/inj1u6cclz0qh5tep9m2qayry9k97dm46pnlqf8nre/)

Provides accurate and timely asset pricing data by aggregating from multiple sources like Pyth, Ojo, and on-chain feeds.

### Querier Contract

**Address:** [inj1kfjff5f0xjy7gece36watkqtscpycv666tqq7t](https://injscan.com/contract/inj1kfjff5f0xjy7gece36watkqtscpycv666tqq7t/)

Quality of life service that provides simplified protocol queries by aggregating data from various contracts.

### Flashloan Receiver Contract

**Address:** [inj1wmtzan6tgzg0zyauknuxdnnfjwn350yewjf6fq](https://injscan.com/contract/inj1wmtzan6tgzg0zyauknuxdnnfjwn350yewjf6fq/)

Base contract for implementing flashloan receivers that can borrow assets from the protocol and repay them within the same transaction.

## Receipt Tokens (nTokens)

nTokens are CW20-compliant tokens issued to lenders representing their share of the lending pool. They:

* Automatically accumulate lending yields
* Can be used as collateral
* Can be transferred while maintaining the underlying position

See the [nToken documentation](/develop/contracts/ntoken) for a complete list of deployed nToken contracts.

Each contract's detailed documentation can be found in its respective markdown file in this directory.


# 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>


# Interest Model

Interest Model Contract Address: [inj1ftech0pdjrjawltgejlmpx57cyhsz6frdx2dhq](https://injscan.com/contract/inj1ftech0pdjrjawltgejlmpx57cyhsz6frdx2dhq/)

The **Interest Model** **Contract** is a core component of the Neptune protocol. It is responsible for managing and computing the interest rates applied to borrowing assets. Using a configurable PID controller, the contract accrues and updates per-asset interest parameters based on market utilization and other metrics. This data is then used by the Market contract to properly adjust borrowing and lending rates.

## Query Messages

### 1. Get Borrow Rate

**Query:** `get_borrow_rate`

**Purpose:** Retrieves the current borrow rate for a specified asset.

**Query Input:**

```json
{
  "get_borrow_rate": {
    "asset": {
      "native_token": { "denom": "inj" }
    }
  }
}
```

| Parameter                                                                                              | Type     | Description                                    | Required |
| ------------------------------------------------------------------------------------------------------ | -------- | ---------------------------------------------- | -------- |
| `asset`                                                                                                | `object` | The asset for which the borrow rate is queried | Yes      |
| <p><code>asset.</code></p><p><strong><code>native\_token</code></strong></p>                           | `object` | The token type for the target token            | Yes      |
| <p><code>asset.</code></p><p><code>native\_token.</code></p><p><strong><code>denom</code></strong></p> | `string` | The denomination of the native token           | Yes      |

**Query Response:**

```json
"0.032602136599636308"
```

| Parameter | Type         | Description                                        |
| --------- | ------------ | -------------------------------------------------- |
| `rate`    | `decimal256` | The computed borrow rate with 18 decimal precision |

***

### 2. Get Borrow Rates

**Query:** `get_borrow_rates`

**Purpose:** Retrieves borrow rates for multiple assets.

**Query Input:**

```json
{
  "get_borrow_rates": {
    "assets": [
      { "native_token": { "denom": "inj" } },
      { "native_token": { "denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9" } }
    ]
  }
}
```

<table><thead><tr><th>Parameter</th><th>Type</th><th width="233">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>array</code></td><td>List of assets for which to fetch rates</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>Target 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>The denomination of the native token for each asset</td><td>Yes</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "inj"
      }
    },
    "0.032602136599636308"
  ],
  [
    {
      "native_token": {
        "denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
      }
    },
    "0.028516145899841711"
  ]
]
```

<table><thead><tr><th width="274">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>object</code></td><td>Token type</td></tr><tr><td><code>native_token.</code><strong><code>denom</code></strong></td><td><code>string</code></td><td>The denomination of the native token</td></tr><tr><td><code>rate</code></td><td><code>deciaml256</code></td><td>The computed borrow rate with 18 decimal precision</td></tr></tbody></table>

***

### 3. Get All Borrow Rates

**Query:** `get_all_borrow_rates`

**Purpose:** Retrieves borrow rates for all assets with optional pagination.

**Query Input:**

```json
{
  "get_all_borrow_rates": {
    "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"
      }
    },
    "0.024581462271495318"
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    "0.122192747997619433"
  ]
]
```

<table><thead><tr><th width="274">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>object</code></td><td>Token type</td></tr><tr><td><code>native_token.</code><strong><code>denom</code></strong></td><td><code>string</code></td><td>The denomination of the native token</td></tr><tr><td><code>rate</code></td><td><code>string</code></td><td>The computed borrow rate with 18 decimal precision</td></tr></tbody></table>

***

### 4. Get All Lending Rates

**Query:** `get_all_lending_rates`

**Purpose:** Retrieves lending rates for all assets with optional pagination.

**Query Input:**

```json
{
  "get_all_lending_rates": {
    "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"
      }
    },
    "0.008849338568075437"
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    "0.088057634299353907"
  ]
]
```

<table><thead><tr><th width="274">Parameter</th><th>Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>object</code></td><td>Token type</td></tr><tr><td><code>native_token.</code><strong><code>denom</code></strong></td><td><code>string</code></td><td>The denomination of the native token</td></tr><tr><td><code>rate</code></td><td><code>string</code></td><td>The computed lending rate with 18 decimal precision</td></tr></tbody></table>

***

### 6. Get All Assets

**Query:** `get_all_assets`

**Purpose:** Retrieves detailed interest model information (i.e., both the asset state and its parameters) for all assets with optional pagination.

**Query Input:**

```json
{
  "get_all_assets": {
    "start_after": {
      "native_token": { "denom": "inj" }
    },
    "limit": 1
  }
}
```

<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:**

<pre class="language-json"><code class="lang-json"><strong>[
</strong>  [
<strong>    {
</strong>      "native_token": {
        "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    },
    {
      "state": {
        "time_last_updated": "1740431284262579521",
        "last_utilization_accumulator": "17044762049054025.396573887122519963",
        "last_control_output": "0.33",
        "pid_state": {
          "prev_measurement": "0.60686996262975328",
          "integral_term": "0.33"
        }
      },
      "params": {
        "pid_params": {
          "kp": "0",
          "ki": "-0.1",
          "kd": "-0.1",
          "upper_p_limit": "0",
          "lower_p_limit": "0",
          "upper_i_limit": "3",
          "lower_i_limit": "0.33",
          "upper_d_limit": "1",
          "lower_d_limit": "-1",
          "upper_output_limit": "3",
          "lower_output_limit": "0.33",
          "setpoint": "0.65"
        },
        "sample_period_min_nanos": 18000000000000,
        "sample_period_max_nanos": 28800000000000,
        "curve": {
          "polynomial": [
            [
              1,
              "0.03"
            ],
            [
              6,
              "0.47"
            ],
            [
              12,
              "1"
            ]
          ]
        }
      }
    }
  ]
]
</code></pre>

<table><thead><tr><th width="285">Parameter</th><th width="176">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>native_token</code></td><td><code>object</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 identifier of the native token</td></tr><tr><td><code>state</code></td><td><code>object</code></td><td>Contains the state details of the asset</td></tr><tr><td><p><code>state.</code></p><p><strong><code>time_last_updated</code></strong></p></td><td><code>string</code></td><td>Timestamp of the last update in nanoseconds</td></tr><tr><td><p><code>state.</code></p><p><strong><code>last_utilization_accumulator</code></strong></p></td><td><code>string</code></td><td>Accumulated utilization value</td></tr><tr><td><p><code>state.</code></p><p><strong><code>last_control_output</code></strong></p></td><td><code>string</code></td><td>Last computed control output for interest calculations</td></tr><tr><td><p><code>state.</code></p><p><strong><code>pid_state</code></strong></p></td><td><code>object</code></td><td>Contains PID controller state values</td></tr><tr><td><p><code>state.pid_state.</code></p><p><strong><code>prev_measurement</code></strong></p></td><td><code>string</code></td><td>Previous measurement value</td></tr><tr><td><p><code>state.pid_state.</code></p><p><strong><code>integral_term</code></strong></p></td><td><code>string</code></td><td>Integral term for PID computation</td></tr><tr><td><code>params</code></td><td><code>object</code></td><td>Contains interest model parameters</td></tr><tr><td><p><code>params.</code></p><p><strong><code>pid_params</code></strong></p></td><td><code>object</code></td><td>PID controller parameters for interest rate adjustments</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>kp</code></strong></p></td><td><code>string</code></td><td>Proportional gain of the PID controller</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>ki</code></strong></p></td><td><code>string</code></td><td>Integral gain of the PID controller</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>kd</code></strong></p></td><td><code>string</code></td><td>Derivative gain of the PID controller</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>upper_p_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the proportional component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>lower_p_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the proportional component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>upper_i_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the integral component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>lower_i_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the integral component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>upper_d_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the derivative component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>lower_d_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the derivative component</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>upper_output_limit</code></strong></p></td><td><code>string</code></td><td>Maximum allowed output from the PID controller</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>lower_output_limit</code></strong></p></td><td><code>string</code></td><td>Minimum allowed output from the PID controller</td></tr><tr><td><p><code>params.pid_params.</code></p><p><strong><code>setpoint</code></strong></p></td><td><code>string</code></td><td>Target setpoint value for the PID controller</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_min_nanos</code></strong></p></td><td><code>u64</code></td><td>Minimum time interval for sampling in nanoseconds</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_max_nanos</code></strong></p></td><td><code>u64</code></td><td>Maximum time interval for sampling in nanoseconds</td></tr><tr><td><p><code>params.</code></p><p><strong><code>curve</code></strong></p></td><td><code>object</code></td><td>Polynomial curve defining interest rate adjustments</td></tr><tr><td><p><code>params.curve.</code></p><p><strong><code>polynomial</code></strong></p></td><td><code>array</code></td><td>List of exponent-coefficient pairs defining the curve</td></tr></tbody></table>

***

## Execute Messages

### 1. Add Asset

**Execute:** `add_asset`

**Purpose:** Adds a new asset to the Interest Model. This initializes the asset's interest state with the current block time, an initial control output, and an integral term. It also stores the provided (unvalidated) interest parameters.

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

**Execute Input:**

```json
{
  "add_asset": {
    "asset": {
      "native_token": {
        "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
      }
    },
    "integral_term": "1",
    "last_control_output": "1",
    "params": {
      "curve": {
        "polynomial": [
          [1, "0.15"],
          [20, "1.46"]
        ]
      },
      "pid_params": {
        "kd": "-0.15",
        "ki": "-0.1",
        "kp": "0",
        "lower_d_limit": "-1",
        "lower_i_limit": "0.33",
        "lower_output_limit": "0.33",
        "lower_p_limit": "0",
        "setpoint": "0.8",
        "upper_d_limit": "1",
        "upper_i_limit": "3",
        "upper_output_limit": "3",
        "upper_p_limit": "0"
      },
      "sample_period_max_nanos": 28800000000000,
      "sample_period_min_nanos": 18000000000000
    }
  }
}
```

<table><thead><tr><th width="182">Parameter</th><th width="129">Type</th><th width="372">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset</code></td><td><code>object</code></td><td>The asset to be added to the interest model</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>The token type for the target token</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>The denomination of the native token</td><td>Yes</td></tr><tr><td><code>integral_term</code></td><td><code>string</code></td><td>Initial value for the integral term of the PID controller</td><td>Yes</td></tr><tr><td><code>last_control_output</code></td><td><code>string</code></td><td>Initial value for the control output</td><td>Yes</td></tr><tr><td><code>params</code></td><td><code>object</code></td><td>The interest model parameters for the asset</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>curve</code></strong></p></td><td><code>object</code></td><td>The polynomial curve defining interest rate adjustments</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>curve.</code></p><p><strong><code>polynomial</code></strong></p></td><td><code>array</code></td><td>List of exponent-coefficient pairs defining the curve</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>pid_params</code></strong></p></td><td><code>object</code></td><td>PID controller parameters for interest rate adjustments</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>kp</code></strong></p></td><td><code>string</code></td><td>Proportional gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>ki</code></strong></p></td><td><code>string</code></td><td>Integral gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>kd</code></strong></p></td><td><code>string</code></td><td>Derivative gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_p_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the proportional component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_p_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the proportional component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_i_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the integral component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_i_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the integral component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_d_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the derivative component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_d_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the derivative component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_output_limit</code></strong></p></td><td><code>string</code></td><td>Maximum allowed output from the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_output_limit</code></strong></p></td><td><code>string</code></td><td>Minimum allowed output from the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>setpoint</code></strong></p></td><td><code>string</code></td><td>Target setpoint value for the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_min_nanos</code></strong></p></td><td><code>u64</code></td><td>Minimum time interval for sampling in nanoseconds</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_max_nanos</code></strong></p></td><td><code>u64</code></td><td>Maximum time interval for sampling in nanoseconds</td><td>Yes</td></tr></tbody></table>

***

### 2. Update Asset

**Execute:** `update_asset`

**Purpose:** Updates the interest model parameters for an existing asset. This allows changes to the PID parameters, sample period, or polynomial curve based on current market conditions.

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

**Execute Input:**

```json
{
  "update_asset": {
    "asset": {
      "native_token": {
        "denom": "inj"
      }
    },
    "params": {
      "curve": {
        "polynomial": [
          [1, "0.04"],
          [20, "1.0"]
        ]
      },
      "pid_params": {
        "kd": "-0.15",
        "ki": "-0.1",
        "kp": "0",
        "lower_d_limit": "-1",
        "lower_i_limit": "0.33",
        "lower_output_limit": "0.33",
        "lower_p_limit": "0",
        "setpoint": "0.8",
        "upper_d_limit": "1",
        "upper_i_limit": "3",
        "upper_output_limit": "3",
        "upper_p_limit": "0"
      },
      "sample_period_max_nanos": 28800000000000,
      "sample_period_min_nanos": 18000000000000
    }
  }
}
```

<table><thead><tr><th width="183">Parameter</th><th width="112">Type</th><th width="354">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset</code></td><td><code>object</code></td><td>The asset for which to update interest model parameters</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>The token type for the target token</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>The denomination of the native token</td><td>Yes</td></tr><tr><td><code>params</code></td><td><code>object</code></td><td>The updated interest model parameters</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>curve</code></strong></p></td><td><code>object</code></td><td>The polynomial curve defining interest rate adjustments</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>curve.</code></p><p><strong><code>polynomial</code></strong></p></td><td><code>array</code></td><td>List of exponent-coefficient pairs defining the curve</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>pid_params</code></strong></p></td><td><code>object</code></td><td>PID controller parameters for interest rate adjustments</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>kp</code></strong></p></td><td><code>string</code></td><td>Proportional gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>ki</code></strong></p></td><td><code>string</code></td><td>Integral gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>kd</code></strong></p></td><td><code>string</code></td><td>Derivative gain of the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_p_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the proportional component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_p_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the proportional component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_i_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the integral component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_i_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the integral component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_d_limit</code></strong></p></td><td><code>string</code></td><td>Upper limit for the derivative component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_d_limit</code></strong></p></td><td><code>string</code></td><td>Lower limit for the derivative component</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>upper_output_limit</code></strong></p></td><td><code>string</code></td><td>Maximum allowed output from the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>lower_output_limit</code></strong></p></td><td><code>string</code></td><td>Minimum allowed output from the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><code>pid_params.</code></p><p><strong><code>setpoint</code></strong></p></td><td><code>string</code></td><td>Target setpoint value for the PID controller</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_min_nanos</code></strong></p></td><td><code>u64</code></td><td>Minimum time interval for sampling in nanoseconds</td><td>Yes</td></tr><tr><td><p><code>params.</code></p><p><strong><code>sample_period_max_nanos</code></strong></p></td><td><code>u64</code></td><td>Maximum time interval for sampling in nanoseconds</td><td>Yes</td></tr></tbody></table>

### 3. Next Control Outputs

**Execute:** `next_control_outputs`

**Purpose:** Used to **calculate the next control output values for all assets** using the PID controller. This is part of the interest rate model's dynamic adjustment mechanism.

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

**Execute Input:**

```json
{
  "next_control_outputs": {
    "assets": [
      {
        "native_token": {
          "denom": "inj"
        }
      },
      {
        "native_token": {
          "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
        }
      }
    ]
  }
}
```

| Parameter                                                                                               | Type     | Description                                                 | Required |
| ------------------------------------------------------------------------------------------------------- | -------- | ----------------------------------------------------------- | -------- |
| `assets`                                                                                                | `array`  | List of assets for which control outputs are to be computed | Yes      |
| <p><code>assets.</code></p><p><strong><code>native\_token</code></strong></p>                           | `object` | Token type for target token to update                       | Yes      |
| <p><code>assets.</code></p><p><code>native\_token.</code></p><p><strong><code>denom</code></strong></p> | `string` | The denomination identifier for the native token            | Yes      |


# Token

Token Contract Address: [inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva](https://injscan.com/contract/inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva)

The **Token Contract** is a core component of the Neptune Protocol, responsible for managing the NEPT token. It handles token minting, bonding, unbonding, and various queries related to token state and user interactions.

## Query Messages

The Token Contract supports several queries to retrieve information about the token state, user stakes, and unlock schedules.

### 1. Get Params

**Query:** `get_params`

**Purpose:** Returns the current state of the token contract variables

**Query Input:**

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

**Query Response:**

```json
{
  "emission_rate": "50000000000",
  "bond_duration_settings": [
    [
      604800000000000,
      {
        "reward_weight": "1",
        "gov_weight": "1",
        "health_weight": "0",
        "flash_loan_weight": "0"
      }
    ],
    [
      2592000000000000,
      {
        "reward_weight": "2",
        "gov_weight": "2",
        "health_weight": "1",
        "flash_loan_weight": "0"
      }
    ],
    [
      7776000000000000,
      {
        "reward_weight": "3",
        "gov_weight": "3",
        "health_weight": "1",
        "flash_loan_weight": "1"
      }
    ]
  ],
  "tokens_per_weight": 1000
}
```

| Parameters                     | Type                  | Description                                                                 |
| ------------------------------ | --------------------- | --------------------------------------------------------------------------- |
| `emission_rate`                | `string (uint256)`    | The rate at which tokens are emitted and allocated to staking rewards       |
| `bond_duration_settings`       | `array`               | Array contain staking pool parameters                                       |
| `bond_duration_settings.[].[]` | `integer (uint64)`    | The duration of the staking pool bonding period in nanoseconds              |
| `reward_weight`                | `string (decimal256)` | The weight assigned to rewards for the given bond duration                  |
| `gov_weight`                   | `string (decimal256)` | The weight assigned to governance power for the given bond duration         |
| `health_weight`                | `string (decimal256)` | The weight assigned to health calculations for the given bond duration      |
| `flash_loan_weight`            | `string (decimal256)` | The weight assigned to flashloan calculations for the given bond duration   |
| `tokens_per_weight`            | `integer (uint64)`    | The number of tokens assigned per weight unit, used in staking calculations |

This table provides a structured overview of the parameters found in the JSON, including their types and descriptions.

### 2. Get State

**Query:** `get_state`

**Purpose:** Returns the current state of the token contract variables

**Query Input:**

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

**Query Response:**

```json
{
  "bonded": [
    [
      604800000000000,
      "31290473171"
    ],
    [
      2592000000000000,
      "44644356919"
    ],
    [
      7776000000000000,
      "298450211419"
    ]
  ],
  "stake_acc": "0.220433595000408612",
  "time_last_distributed": "1740513832459201021",
  "total_issued": "19008699867843",
  "total_claimed": "19004686162561",
  "total_locked": "5737867114162",
  "total_supply": "20000000000000"
}
```

| Parameters              | Type                  | Description                                               |
| ----------------------- | --------------------- | --------------------------------------------------------- |
| `bonded`                | `array`               | Array of the available staking pools                      |
| `bonded.[].[0]`         | `integer (uint64)`    | Duration of bond for the staking pool in nanoseconds      |
| `bonded.[].[1]`         | `string (uint256)`    | Amount of NEPT tokens staked to pool                      |
| `stake_acc`             | `string (decimal256)` | The accumulated stake value                               |
| `time_last_distributed` | `string (uint64)`     | The timestamp of the last emissions distribution event    |
| `total_issued`          | `string (uint256)`    | The total number of NEPT tokens that have been issued     |
| `total_claimed`         | `string (uint256)`    | The total number of tokens that have been claimed         |
| `total_locked`          | `string (uint256)`    | The total number of NEPT tokens that are currently locked |
| `total_supply`          | `string (uint256)`    | The total supply of NEPT tokens                           |

### 3. Get User Token Unlocks

**Query:** `get_user_token_unlocks`

**Purpose:** Retrieves token unlock schedules and their claimable amounts for a user, if any apply.

**Query Input:**

```json
{
  "get_user_token_unlocks": {
    "account_addr": "inj142aemh62w2fpqjws0yre5936ts9x9e93fj8322"
  }
}
```

**Query Response:**

```json
{
  "token_unlocks": [
    {
      "amount": "66340451",
      "start": "1736971200000000000",
      "last_claim": "1736971240955753058",
      "expiration": "1744747200000000000",
      "schedule": "lump_sum",
      "admin": {
        "addr": "inj196lzdc3cak5q4fqgtvmqs8vc42dym00frmwpsw",
        "reclaimed": false
      }
    }
  ],
  "claimable_unlocks": "0"
}
```

| Parameters          | Type               | Description                                                                 |
| ------------------- | ------------------ | --------------------------------------------------------------------------- |
| `token_unlocks`     | `array`            | An array of objects, each representing a token unlock schedule with details |
| `amount`            | `string (uint256)` | The amount of tokens scheduled to be unlocked                               |
| `start`             | `string (uint64)`  | The start time of the unlock schedule, unix epoch in nanoseconds            |
| `last_claim`        | `string (uint64)`  | The timestamp of the last claim made, unix epoch in nanoseconds             |
| `expiration`        | `string (uint64)`  | The expiration time of the unlock schedule, unix epoch in nanoseconds       |
| `schedule`          | `UnlockSchedule`   | Either "lump\_sum" or {"linear": {"duration": uint64}}                      |
| `admin`             | `object`           | An object containing administrative details related to the unlock schedule  |
| `admin.addr`        | `string`           | The address of the admin responsible for the unlock schedule                |
| `admin.reclaimed`   | `boolean`          | A flag indicating whether the unlock schedule has been reclaimed            |
| `claimable_unlocks` | `string (uint256)` | The amount of tokens that are currently claimable from the unlock schedule  |

### 4. Get User Staked

**Query:** `get_user_staked`

**Purpose:** Retrieves staking data for a user, including bonded tokens, unbonding tokens, unclaimed rewards, and claimable rewards.

**Query Input:**

```json
{
  "get_user_staked": {
    "account_addr": "inj1exampleaddress"
  }
}
```

**Query Response:**

```json
{
  "bonded": [
    {
      "account_index": 0,
      "duration": 604800000000000,
      "bonded": []
    },
    {
      "account_index": 0,
      "duration": 7776000000000000,
      "bonded": [
        {
          "cooldown": null,
          "cascade": false,
          "last_stake_acc": "0.219795491591127008",
          "amount": "69922202"
        }
      ]
    },
    {
      "account_index": 2,
      "duration": 604800000000000,
      "bonded": []
    },
    {
      "account_index": 2,
      "duration": 7776000000000000,
      "bonded": []
    }
  ],
  "unbonding": [],
  "unclaimed": "1349271",
  "claimable_rewards": "1487805",
  "claimable_unbonding": "0"
}
```

| Parameters                                                                                                      | Type                | Description                                                                                                 |
| --------------------------------------------------------------------------------------------------------------- | ------------------- | ----------------------------------------------------------------------------------------------------------- |
| `bonded`                                                                                                        | `array`             | An array of objects, each representing a bond with details about account index, duration, and bonded tokens |
| <p><code>bonded.\[].</code></p><p><strong><code>account\_index</code></strong></p>                              | `u64`               | The index of a users margin account associated with the token bond                                          |
| <p><code>bonded.\[].</code></p><p><strong><code>duration</code></strong></p>                                    | `u64 (nanoseconds)` | The duration of the staking pool bond in nanoseconds                                                        |
| <p><code>bonded.\[].</code></p><p><strong><code>bonded</code></strong></p>                                      | `array`             | An array of objects representing individual bond details                                                    |
| <p><code>bonded.\[].</code></p><p><code>bonded.</code></p><p><strong><code>cooldown</code></strong></p>         | `null` or `string`  | The cooldown (unlock) period for the bond, null if not applicable                                           |
| <p><code>bonded.\[].</code></p><p><code>bonded.</code></p><p><strong><code>cascade</code></strong></p>          | `boolean`           | A flag indicating whether the cooldown is part of a cascade operation                                       |
| <p><code>bonded.\[].</code></p><p><code>bonded.</code></p><p><strong><code>last\_stake\_acc</code></strong></p> | `string (u64)`      | The last recorded stake accumulator value for the bond.                                                     |
| <p><code>bonded.\[].</code></p><p><code>bonded.</code></p><p><strong><code>amount</code></strong></p>           | `string (u64)`      | The amount of tokens bonded.                                                                                |
| `unbonding`                                                                                                     | `array`             | An array representing tokens that are in the process of unbonding.                                          |
| `unclaimed`                                                                                                     | `string (u64)`      | The amount of staking rewards that have been accumulated but not yet claimed                                |
| `claimable_rewards`                                                                                             | `string (u64)`      | The amount of staking rewards that are currently claimable                                                  |
| `claimable_unbonding`                                                                                           | `string (u64)`      | The amount of unbonding tokens that are currently claimable                                                 |

### 5. Get Health Weighted Stake

**Query:** `get_health_weighted_stake`

**Purpose:** Calculates the health-weighted stake for a specific staking position, used by the market contract for account health calculations.

**Query Input:**

```json
{
  "get_health_weighted_stake": {
    "account_addr": "inj1exampleaddress",
    "account_index": 0
  }
}
```

**Query Response:**

```json
"69922202"
```

| Parameters | Type               | Description                                                           |
| ---------- | ------------------ | --------------------------------------------------------------------- |
| `response` | `string (uint256)` | The health-weighted stake for the specified account address and index |

### 5. Get Gov Weighted Stake

**Query:** `get_gov_weighted_stake`

**Purpose:** Calculates the governance-weighted stake for a user, determining voting power in protocol governance.

**Query Input:**

```json
{
  "get_gov_weighted_stake": {
    "account_addr": "inj1exampleaddress"
  }
}
```

**Query Response:**

```
"209766606"
```

| Parameters | Type               | Description                               |
| ---------- | ------------------ | ----------------------------------------- |
| `response` | `string (uint256)` | The governance weight for a given address |

### 6. Get Flash Loan Weighted Stake

**Query:** `get_flash_loan_weighted_stake`

**Purpose:** Calculates the flashloan-weighted stake for a user, used in flashloan operations to determine the amount of assets a user can borrow in a flashloan.

**Query Input:**

```json
{
  "get_flash_loan_weighted_stake": {
    "account_addr": "inj1exampleaddress"
  }
}
```

**Query Response:**

```
"209766606"
```

| Parameters | Type               | Description                                                                                   |
| ---------- | ------------------ | --------------------------------------------------------------------------------------------- |
| `response` | `string (uint256)` | The flashloan weight staked used to calculate the amount a user can flashloan from the market |

### 7. Get Health Weighted Stake Range

**Query:** `get_health_weighted_stake_range`

**Purpose:** Retrieves the health-weighted stake for a range of account positions.

**Query Input:**

```json
{
  "get_health_weighted_stake_range": {
    "from": ["inj1exampleaddress", 0],
    "to": ["inj1exampleaddress", 1]
  }
}
```

**Query Response:**

```json
[
  [
    ["inj1exampleaddress", 0],
    "1000000"
  ],
  [
    ["inj1exampleaddress", 1],
    "2000000"
  ]
]
```

| Parameters  | Type               | Description                                               |
| ----------- | ------------------ | --------------------------------------------------------- |
| `[]`        | `array`            | Array of account indexes and their health weighted stakes |
| `[].[].[1]` | `string (uint256)` | Health weighted stake value                               |

### 8. Get Cascade

**Query:** `get_cascade`

**Purpose:** Checks if there are any pending cascade operations. Cascading is used to transition bonds from one duration phase to another.

**Query Input:**

```json
{
  "get_cascade": {}
}
```

**Query Response:**

```
true
```

| Parameters | Type      | Description                                                            |
| ---------- | --------- | ---------------------------------------------------------------------- |
| `response` | `boolean` | Returns `true` if at least one cascade entry exists, `false` otherwise |

## Execute Messages

The Token Contract supports several execute messages for managing token bonding, unbonding, rewards, and token unlocks.

### 1. Bond

**Execute:** `bond`

**Purpose:** Bonds (stakes) NEPT tokens to a specified staking pool for a specified duration, enabling participation in protocol governance and earning staking rewards.

**Execute Input:**

```json
{
  "bond": {
    "account_index": 0,
    "duration": 604800000000000
  }
}
```

| Parameters      | Type               | Description                                                                                  |
| --------------- | ------------------ | -------------------------------------------------------------------------------------------- |
| `account_index` | `integer (uint8)`  | The index of the margin account to associate with the bond                                   |
| `duration`      | `integer (uint64)` | The duration to bond tokens for, must match one of the durations in bond\_duration\_settings |

**Note:** This message must be sent with exactly one non-zero amount of NEPT tokens to bond.

### 2. Unbond

**Execute:** `unbond`

**Purpose:** Initiates the unbonding of staked NEPT tokens, starting the cooldown period before tokens can be claimed.

**Execute Input:**

```json
{
  "unbond": {
    "account_index": 0,
    "amount": "1000000",
    "duration": 604800000000000
  }
}
```

| Parameters      | Type               | Description                                    |
| --------------- | ------------------ | ---------------------------------------------- |
| `account_index` | `integer (uint8)`  | The index of the margin account to unbond from |
| `amount`        | `string (uint256)` | The amount of NEPT tokens to unbond            |
| `duration`      | `integer (uint64)` | The duration pool to unbond from               |

### 3. Rebond

**Execute:** `rebond`

**Purpose:** Rebonds tokens that are currently unbonding back into a staking position, optionally enabling cascading.

**Execute Input:**

```json
{
  "rebond": {
    "account_index": 0,
    "amount": "1000000",
    "duration": 604800000000000,
    "cascade": true
  }
}
```

| Parameters      | Type               | Description                                  |
| --------------- | ------------------ | -------------------------------------------- |
| `account_index` | `integer (uint8)`  | The index of the margin account to rebond to |
| `amount`        | `string (uint256)` | The amount of NEPT tokens to rebond          |
| `duration`      | `integer (uint64)` | The duration to rebond for                   |
| `cascade`       | `boolean`          | Whether to enable cascading for this bond    |

### 4. Claim Unbonded

**Execute:** `claim_unbonded`

**Purpose:** Claims NEPT tokens that have completed their unbonding period.

**Execute Input:**

```json
{
  "claim_unbonded": {}
}
```

### 5. Claim Rewards

**Execute:** `claim_rewards`

**Purpose:** Claims accumulated staking rewards from all bonded positions.

**Execute Input:**

```json
{
  "claim_rewards": {}
}
```

### 6. Claim Token Unlock

**Execute:** `claim_token_unlock`

**Purpose:** Claims tokens that have been unlocked according to the unlock schedule.

**Execute Input:**

```json
{
  "claim_token_unlock": {}
}
```

### 7. Reclaim Token Unlock

**Execute:** `reclaim_token_unlock`

**Purpose:** Allows an admin to reclaim tokens from an unlock schedule they control.

**Execute Input:**

```json
{
  "reclaim_token_unlock": {
    "addr": "inj1...",
    "index": 0,
    "recipient": "inj1..."
  }
}
```

| Parameters  | Type               | Description                                         |
| ----------- | ------------------ | --------------------------------------------------- |
| `addr`      | `string`           | The address that owns the unlock schedule           |
| `index`     | `integer (uint64)` | The index of the unlock schedule to reclaim         |
| `recipient` | `string`           | Optional recipient address for the reclaimed tokens |

### 8. Cascade

**Execute:** `cascade`

**Purpose:** Processes bonds that are ready to cascade to lower duration pools.

**Execute Input:**

```json
{
  "cascade": {
    "limit": 10
  }
}
```

| Parameters | Type               | Description                                  |
| ---------- | ------------------ | -------------------------------------------- |
| `limit`    | `integer (uint16)` | Maximum number of cascade entries to process |

### 9. Create Token Unlock

**Execute:** `create_token_unlock`

**Purpose:** Creates a new token unlock schedule for gradual or lump-sum token distribution.

**Execute Input:**

```json
{
  "create_token_unlock": {
    "addr": "inj1...",
    "start": "1736971200000000000",
    "expiration": "1744747200000000000",
    "schedule": {
      "linear": {
        "duration": 7776000000000000
      }
    },
    "admin": "inj1..."
  }
}
```

| Parameters   | Type              | Description                                            |
| ------------ | ----------------- | ------------------------------------------------------ |
| `addr`       | `string`          | The address that will receive the unlocked tokens      |
| `start`      | `string (uint64)` | The timestamp when the unlock schedule begins          |
| `expiration` | `string (uint64)` | Optional timestamp when the unlock schedule expires    |
| `schedule`   | `UnlockSchedule`  | Either "lump\_sum" or {"linear": {"duration": uint64}} |
| `admin`      | `string`          | Optional admin address that can reclaim tokens         |

**Note:** This message must be sent with the NEPT tokens to be unlocked.

### 10. Set Params

**Execute:** `set_params`

**Purpose:** Updates the contract parameters, including emission rate and bond duration settings.

**Execute Input:**

```json
{
  "set_params": {
    "params": {
      "emission_rate": "50000000000",
      "bond_duration_settings": [
        [
          604800000000000,
          {
            "reward_weight": "1",
            "gov_weight": "1",
            "health_weight": "0",
            "flash_loan_weight": "0"
          }
        ]
      ]
    }
  }
}
```

| Parameters               | Type               | Description                                   |
| ------------------------ | ------------------ | --------------------------------------------- |
| `emission_rate`          | `string (uint256)` | The new emission rate of NEPT tokens per year |
| `bond_duration_settings` | `array`            | Array of duration and weight settings         |

**Note:** Cannot modify governance or reward weights for existing durations.


# Oracle

Oracle Contract Address: [inj1u6cclz0qh5tep9m2qayry9k97dm46pnlqf8nre](https://injscan.com/contract/inj1u6cclz0qh5tep9m2qayry9k97dm46pnlqf8nre/)

The **Oracle Contract** is service developed to provide accurate and timely asset pricing data. It aggregates pricing information from multiple sources (e.g., Pyth, Ojo, and on-chain feeds) and supplies these data to other protocol modules such as the market and querier contracts. This ensures that collateral values and debt positions are evaluated based on current market prices.

***

## Price Feeds

Multiple price feeds can be utilised in the oracle contract to retrieve a source of truth for asset price data, including external sources like Pyth that push price updates to chain or utilising on-chain markets to aggregate asset price.

***

## Query Messages

### 1. Get Single Asset Price

The Oracle contract retrieves the current price information for a specified asset.

Query: `get_price`

**Purpose:**\
Retrieves the latest price data for a given asset.

**Query Input:**

```json
{
  "get_price": {
    "asset": {
      "native_token": {
        "denom": "inj"
      }
    }
  }
}
```

<table><thead><tr><th width="177">Parameter</th><th width="130">Type</th><th width="331">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset</code></td><td><code>AssetInfo</code></td><td>Object specifying the asset to retrieve price data for. Must be either <code>native_token</code> or <code>token</code> object</td><td>Yes</td></tr><tr><td><code>native_token</code></td><td><code>object</code></td><td>Object containing native token information</td><td>Yes</td></tr><tr><td><code>denom</code></td><td><code>string</code></td><td>Token denomination (if using <code>native_token</code>) or contract address (if using <code>token</code>)</td><td>Yes</td></tr></tbody></table>

**Query Response:**

```json
{
  "price": "15.57740357",
  "decimals": 18,
  "time_last_updated": "1740100674000000000",
  "confidence": "0.01633254"
}
```

<table><thead><tr><th width="225">Parameter</th><th width="139">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>price</code></td><td><code>Decimal256</code></td><td>The reported asset price</td></tr><tr><td><code>decimals</code></td><td><code>u8</code></td><td>The number of decimals the price uses</td></tr><tr><td><code>time_last_updated</code></td><td><code>Timestamp</code></td><td>The timestamp indicating when the price was last updated</td></tr><tr><td><code>confidence</code></td><td><code>Decimal256</code></td><td>A measure of uncertainty associated with the reported price, as provided by Pyth</td></tr></tbody></table>

***

### 2. Get Multiple Asset Prices

This query retrieves pricing data for a list of specified assets simultaneously.

Query: `get_prices`

**Purpose:**\
Retrieves the price information for multiple assets in a single query.

**Query Input:**

```json
{
  "get_prices": {
    "assets": [
      {
        "native_token": {
          "denom": "inj"
        }
      },
      {
        "token": {
          "contract_addr": "inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s"
        }
      }
    ]
  }
}
```

<table><thead><tr><th width="190">Parameter</th><th width="197">Type</th><th width="260">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>Array&#x3C;AssetInfo></code></td><td>An array of asset information objects to query prices for</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>Object representing a native token asset</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>The denomination of the native token</td><td>Yes</td></tr><tr><td><p><code>assets.</code></p><p><strong><code>token</code></strong></p></td><td><code>object</code></td><td>Object representing a CW20 token asset</td><td>Yes</td></tr><tr><td><p><code>assets.token.</code></p><p><strong><code>contract_addr</code></strong></p></td><td><code>Addr</code></td><td>The contract address of the token</td><td>Yes</td></tr></tbody></table>

\*Note: For each asset in the `assets` array, you should use *either* the `native_token` object (with its `denom`) *or* the `token` object (with its `contract_addr`), depending on the asset type.

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "inj"
      }
    },
    {
      "price": "15.53999517",
      "decimals": 18,
      "time_last_updated": "1740101464000000000",
      "confidence": "0.01621974"
    }
  ],
  [
    {
      "token": {
        "contract_addr": "inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s"
      }
    },
    {
      "price": "175.038099535824850751",
      "decimals": 8,
      "time_last_updated": "1740101464000000000",
      "confidence": "0.082077403813169304"
    }
  ]
]
```

<table><thead><tr><th width="225">Parameter</th><th width="141">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>price</code></td><td><code>Decimal256</code></td><td>The reported asset price</td></tr><tr><td><code>decimals</code></td><td><code>u8</code></td><td>The number of decimals the price uses</td></tr><tr><td><code>time_last_updated</code></td><td><code>Timestamp</code></td><td>The timestamp indicating when the price was last updated</td></tr><tr><td><code>confidence</code></td><td><code>Decimal256</code></td><td>A measure of uncertainty associated with the reported price, as provided by Pyth</td></tr></tbody></table>

***

### 3. Get All Asset Prices

The query supports pagination to retrieve pricing data for all registered assets.

Query: `get_all_prices`

**Purpose:**\
Retrieves price information for all supported assets, with optional pagination.

**Query Input:**

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

<table><thead><tr><th width="168">Parameter</th><th width="119">Type</th><th width="363">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>start_after</code></td><td><code>AssetInfo</code></td><td>Object specifying which token to start after. If not used, returns all price data</td><td>No</td></tr><tr><td><code>limit</code></td><td><code>u32</code></td><td>How many records to fetch starting after target token</td><td>No</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    },
    {
      "price": "2739.45",
      "decimals": 18,
      "time_last_updated": "1740101929000000000",
      "confidence": "1.52228659"
    }
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    {
      "price": "1.0002227",
      "decimals": 6,
      "time_last_updated": "1740101929000000000",
      "confidence": "0.00124156"
    }
  ]
]
```

<table><thead><tr><th width="225">Parameter</th><th width="142">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>price</code></td><td><code>Decimal256</code></td><td>The reported asset price</td></tr><tr><td><code>decimals</code></td><td><code>u8</code></td><td>The number of decimals the price uses</td></tr><tr><td><code>time_last_updated</code></td><td><code>Timestamp</code></td><td>The timestamp indicating when the price was last updated</td></tr><tr><td><code>confidence</code></td><td><code>Decimal256</code></td><td>A measure of uncertainty associated with the reported price, as provided by Pyth</td></tr></tbody></table>

***

### 4. Get Asset Details

This query retrieves detailed oracle asset information, including metadata about the price source or asset type.

Query: `get_all_asset_details`

**Purpose:**\
Retrieves detailed configurations of all asset entries stored in the Oracle, such as the oracle type (e.g., Pyth, Ojo, Regular, or Receipt Token).

**Query Input:**

```json
{
  "get_all_asset_details": {
    "start_after": {
      "native_token": {
        "denom": "inj"
      }
    },
    "limit": 10
  }
}
```

<table><thead><tr><th width="185">Parameter</th><th width="102">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td><code>start_after</code></td><td><code>object</code></td><td>Object specifying which token to start after. If not used, returns all asset details</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.<br>Can be <code>native_token</code> or <code>token</code></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>object</code></td><td>Token address.<br>Can be <code>denom</code> (IF <code>native_token</code>) or <code>contract_address</code> (IF <code>token</code>)</td><td>Yes</td></tr><tr><td><code>limit</code></td><td><code>object</code></td><td>How many records to fetch starting after target token</td><td>No</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
      }
    },
    {
      "pyth": {
        "price_id": "0xd9912df360b5b7f21a122f15bdd5e27f62ce5e72bd316c291f7c86620e07fb2a",
        "decimals": 6
      }
    }
  ],
  [
    {
      "native_token": {
        "denom": "factory/inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva/nept"
      }
    },
    {
      "regular": {
        "price_info": {
          "price": "0.373738907677827617",
          "decimals": 6,
          "time_last_updated": "1740102142889585199",
          "confidence": "0"
        }
      }
    }
  ],
  [
    {
      "token": {
        "contract_addr": "inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780"
      }
    },
    {
      "receipt_token": {
        "origin_info": {
          "native_token": {
            "denom": "ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9"
          }
        }
      }
    }
  ]
]
```

*In this response, each asset is mapped to its detailed oracle configuration. For example, a "Regular" asset directly contains its current `price_info`, while tokens relying on an external feed (e.g., Pyth) include details like the symbol and decimal precision.*

***

## Execute Messages

### 1.1 Update Asset

Execute: `update_asset`

**Purpose:** Adds a new asset or updates the details of an existing asset in the Oracle. This message registers asset metadata—including the source of pricing data (e.g., Regular, Pyth, Ojo, or Receipt Token)—and, when applicable, its current price information.

**Execute Input:**

```json
{
  "update_asset": {
    "asset_details": {
      "pyth": {
        "decimals": 6,
        "price_id": "0xd9912df360b5b7f21a122f15bdd5e27f62ce5e72bd316c291f7c86620e07fb2a"
      }
    },
    "asset_info": {
      "native_token": {
        "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
      }
    }
  }
}
```

<table><thead><tr><th width="206">Parameter</th><th width="144">Type</th><th width="297">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset_details</code></td><td><code>OracleAssetDetails</code></td><td>An object that contains the asset configuration</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><strong><code>pyth</code></strong></p></td><td><code>object</code></td><td><p>Oracle source feed type.</p><p>Can be <code>Pyth</code>, <code>Ojo</code>, <code>Regular</code>, or <code>ReceiptToken</code></p></td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><code>pyth.</code></p><p><strong><code>decimals</code></strong></p></td><td><code>u8</code></td><td>Decimal precision of target token</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><strong><code>price_id</code></strong></p></td><td><code>string</code></td><td>The price ID string provided by the oracle source</td><td>Yes</td></tr><tr><td><code>asset_info</code></td><td><code>AssetInfo</code></td><td>An object that uniquely identifies the asset. Use either the <code>native_token</code> field (with its <code>denom</code>) or the <code>token</code> field (with its <code>contract_addr</code>).</td><td>Yes</td></tr></tbody></table>

### 1.2 Update Asset (nToken)

Execute: <kbd>update\_asset</kbd>

**Purpose:** Adding a receipt token, nToken, to the oracle requires the origin path to its original token

**Execute Input:**

```json
{
  "update_asset": {
    "asset_details": {
      "receipt_token": {
        "origin_info": {
          "native_token": {
            "denom": "factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd"
          }
        }
      }
    },
    "asset_info": {
      "token": {
        "contract_addr": "inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g"
      }
    }
  }
}
```

<table><thead><tr><th width="203">Parameter</th><th width="105">Type</th><th width="321">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>asset_details</code></td><td><code>object</code></td><td>Contains details of the asset</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><strong><code>receipt_token</code></strong></p></td><td><code>object</code></td><td>Specifies receipt token information</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><code>receipt_token.</code></p><p><strong><code>origin_info</code></strong></p></td><td><code>object</code></td><td>Origin details of the receipt token</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><code>receipt_token.</code></p><p><code>origin_info.</code></p><p><strong><code>native_token</code></strong></p></td><td><code>object</code></td><td>Native token details</td><td>Yes</td></tr><tr><td><p><code>asset_details.</code></p><p><code>receipt_token.</code></p><p><code>origin_info.</code></p><p><code>native_token.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The denomination identifier for the native token</td><td>Yes</td></tr><tr><td><code>asset_info</code></td><td><code>object</code></td><td>Contains asset identification details</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>token</code></strong></p></td><td><code>object</code></td><td>Token contract details</td><td>Yes</td></tr><tr><td><p><code>asset_info.</code></p><p><code>token.</code></p><p><strong><code>contract_addr</code></strong></p></td><td><code>string</code></td><td>The contract address of the token</td><td>Yes</td></tr></tbody></table>

### 2. Update Prices

Execute: `update_prices`

**Purpose:** Updates the prices of multiple assets in a single transaction. This message is useful for batch-updating price information for various assets. The block's timestamp is automatically used to update the `time_last_updated` field.

**Execute Input:**

```json
{
  "update_prices": {
    "assets": [
      [
        {
          "native_token": {
            "denom": "inj"
          }
        },
        {
          "price": "15.53999517",
          "confidence": "0.01621974"
        }
      ],
      [
        {
          "token": {
            "contract_addr": "inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s"
          }
        },
        {
          "price": "175.038099535824850751",
          "confidence": "0.082077403813169304"
        }
      ]
    ]
  }
}
```

<table><thead><tr><th width="175">Parameter</th><th width="140">Type</th><th width="297">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>assets</code></td><td><code>Array&#x3C;[AssetInfo, UpdatePrice]></code></td><td>An array of tuples containing asset info and price update information</td><td>Yes</td></tr><tr><td><p><code>assets[].</code></p><p><strong><code>price</code></strong></p></td><td><code>Decimal256</code></td><td>New price for target token</td><td>Yes</td></tr><tr><td><p><code>assets[].</code></p><p><strong><code>confidence</code></strong></p></td><td><code>Decimal256</code></td><td>New confidence value for target token</td><td>Yes</td></tr></tbody></table>

**Note:**

* For each asset entry in the `assets` array, the first element identifies the asset and the second element provides the new price data.
* The `time_last_updated` field is automatically set to the current block time.


# Querier

Querier Contract Address: [inj1kfjff5f0xjy7gece36watkqtscpycv666tqq7t](https://injscan.com/contract/inj1kfjff5f0xjy7gece36watkqtscpycv666tqq7t/)

The **Querier Contract** is a quality of life service developed to provide simplified protocol queries. It provides advanced, aggregated query functionality by interacting with various on-chain modules such as the token, market, and price oracle contracts.

## Interrelation with Other Contracts

The Neptune Querier contract depends on and interacts with:

* **Token Contract:**\
  Queries the weighted stake essential for account health calculations.
* **Market Contract:**\
  Provides account states, collateral, debt information, and market parameters.
* **Price Oracle Contract:**\
  Supplies current asset pricing data required for evaluating collateral and debt.

## Query Messages

### 1. Get Account Health

The querier contract calls the token contract via a smart query (`GetHealthWeightedStake`) to obtain the **weighted stake** of an account. This value is fundamental for computing the account's overall health.

The **Account Health** is conceptually computed as:

$$
\text{Account Health} = \frac{\text{Weighted Collateral Value + Weighted Stake}}{\text{Debt Value}}
$$

A value of less than 1 indicates that the account is **undercollateralized** and may require liquidation.

Query: `get_account_health`

**Purpose:**\
Retrieves the health of a specified account by aggregating collateral, debt, and weighted stake information.

**Query Input:**

```json
{
  "get_account_health": {
    "addr": "inj................",
    "account_index": 2
  }
}
```

| Parameter       | Type    | Description             | Required |
| --------------- | ------- | ----------------------- | -------- |
| `addr`          | `Addr`  | Injetive wallet address | Yes      |
| `account_index` | `uint8` | sub account's index ID  | Yes      |

**Query Response:**

```json
{
    "0.98"
}
```

*Here, a result of "0.98" indicates that the account health is 98% of the safe threshold. Values below 1 denote undercollateralization and places the account in a liquidable state.*

| Parameter | Type         | Description            |
| --------- | ------------ | ---------------------- |
| response  | `Decimal256` | Current account health |

### 2. Get Collateral Discount

For accounts with health below 1, the protocol applies discounts on collateral assets. The discount calculation is based on:

* Protocol parameters from the market configuration.
* The specific collateral state.
* The computed account health.

This process is encapsulated in the `get_discount` function. Only accounts with $$\text{health} < 1$$ qualify, as healthy accounts (with health ≥ 1) do not receive discounts.

Query: `get_collateral_discount`

**Purpose:** Calculates the applicable discounts for collateral assets held by an undercollateralized account.

**Query Input:**

```json
{
    "get_collateral_discounts": {
        "addr": "inj................",
        "account_index": 0
    }
}
```

<table><thead><tr><th>Parameter</th><th width="145">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td><code>addr</code></td><td><code>addr</code></td><td>Injetive wallet address</td><td>Yes</td></tr><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>sub account's index ID</td><td>Yes</td></tr></tbody></table>

**Query Response:**

```json
{
    "result": [
        {
            "asset_info": { "type": "native_token", "denom": "inj" },
            "discount": "0.10"
        },
        {
            "asset_info": { "type": "token", "contract_addr": "inj834l..." },
            "discount": "0.05"
        }
    ]
}
```

*This indicates that the native `inj` asset receives a 10% discount, while the specified CW20 token receives a 5% discount.*

<table><thead><tr><th>Parameter</th><th width="159">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>asset_info</code></td><td><code>AssetInfo</code></td><td>Object containing the type of token and either a denom or a contract address</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>type</code></strong></p></td><td><code>string</code></td><td><code>"native_token"</code> or <code>"token"</code></td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>Denomination of the token (if <code>type</code> = <code>native_token</code>)</td></tr><tr><td><p><code>asset_info.</code></p><p><strong><code>contract_addr</code></strong></p></td><td><code>addr</code></td><td>Contract address of the token (if <code>type</code> = <code>token</code>)</td></tr><tr><td><code>discount</code></td><td><code>decimal256</code></td><td>The discount value for this particular collateral token</td></tr></tbody></table>

### 3. Get Liquidation Request

When an account is undercollateralized (account health is < 1), a **liquidation request** is computed to determine the amount of debt to be repaid and collateral to be received. This involves:

* Determining the accounts repayable debt.
* Identifying which collaterals are available for liquidation.
* Calculating:
  * **Ask Assets:** The collateral assets to be liquidated.
  * **Offer Assets:** The corresponding debt amounts to be repaid.

The final liquidation request, if valid, contains both mappings and only returns a result if:

* There is a non-zero debt to be repaid.
* There is a non-zero collateral liquidation amount.

Query: `get_liquidation_request`

**Purpose:** Generates a liquidation request for an account that is determined to be undercollateralized. This request details both the collateral (ask assets) to be liquidated and the debt (offer assets) to be repaid.

**Query Input:**

```json
{
    "get_liquidation_request": {
        "account_addr": "inj834l...",
        "account_index": 0,
        "collateral_priority": [
            { "type": "native_token", "denom": "inj" }
        ],
        "debt_priority": [
            { "type": "native_token", "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7" }
        ]
    }
}
```

<table><thead><tr><th width="241">Parameter</th><th width="151">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td><code>account_addr</code></td><td><code>Addr</code></td><td>The account address to be checked or liquidated</td><td>Yes</td></tr><tr><td><code>account_index</code></td><td><code>uint8</code></td><td>The sub-account index ID</td><td>Yes</td></tr><tr><td><code>collateral_priority</code></td><td><code>AssetInfo[]</code></td><td>Ordered list of collateral token types to be liquidated first, second, etc</td><td>No</td></tr><tr><td><p><code>collateral_priority.</code></p><p><strong><code>type</code></strong></p></td><td><code>string</code></td><td>The collateral token "type". Can be <code>"native_token"</code> or <code>"token"</code></td><td>Yes</td></tr><tr><td><p><code>collateral_priority.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The collateral token address. Can be <code>denom</code> or <code>token_address</code></td><td>Yes</td></tr><tr><td><code>debt_priority</code></td><td><code>AssetInfo[]</code></td><td>Ordered list of debts to be repaid first, second, etc</td><td>No</td></tr><tr><td><p><code>debt_priority.</code></p><p><strong><code>type</code></strong></p></td><td><code>string</code></td><td>The debt token "type". Can be <code>"native_token"</code> or <code>"token"</code></td><td>Yes</td></tr><tr><td><p><code>debt_priority.</code></p><p><strong><code>denom</code></strong></p></td><td><code>string</code></td><td>The debt token address. Can be <code>denom</code> or <code>token_address</code></td><td>Yes</td></tr></tbody></table>

**Query Response:**

```json
{
  "ask_assets": {
    "inj": {
      "amount": "1000000000000000000",
      "min_discount": "0.10"
    }
  },
  "offer_assets": {
    "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7": "500000000000000000"
  }
}
```

*If the account is healthy or no liquidation is triggered, the query returns `null`.*

| Parameter                                                                                                    | Type                                        | Description                                            |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------- | ------------------------------------------------------ |
| `ask_assets`                                                                                                 | `NeptuneMap<AssetInfo, LiquidationAmounts>` | Object listing the collateral assets to be liquidated  |
| <p><code>ask\_assets.</code></p><p><strong><code>denom</code></strong></p>                                   | `object`                                    | Collateral details for a specific token                |
| <p><code>ask\_assets.</code></p><p><code>denom.</code></p><p><strong><code>amount</code></strong></p>        | `Uint256`                                   | The amount of collateral to be liquidated              |
| <p><code>ask\_assets.</code></p><p><code>denom.</code></p><p><strong><code>min\_discount</code></strong></p> | `Decimal256`                                | Any applicable discount applied to collateral value    |
| `offer_assets`                                                                                               | `NeptuneMap<AssetInfo, Uint256>`            | Object listing the debt to be repaid                   |
| <p><code>offer\_assets.</code></p><p><strong><code>denom</code></strong></p>                                 | `Uint256`                                   | The amount of debt that must be repaid for liquidation |

### 4. Get Market Metadata

The contract also computes key market ratios:

* **Utilization Ratio:**

$$
\text{Utilization Ratio} = \frac{\text{Debt Pool Balance}}{\text{Lending Principal}}
$$

* **Redemption Ratio:**

$$
\text{Redemption Ratio} = \frac{\text{Lending Principal}}{\text{Total Receipt Token Supply}}
$$

These ratios are essential for monitoring market performance and liquidity.

Query: `get_market_metadata`

**Purpose:** Retrieves metadata for available markets, including the utilization and redemption ratios.

**Query Input:**

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

<table><thead><tr><th width="182">Parameter</th><th>Type</th><th width="296">Description</th><th>Required</th></tr></thead><tbody><tr><td><code>start_after</code></td><td><code>AssetInfo</code></td><td>Object specifying which 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. Can be <code>native_token</code> or <code>token</code></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>Token address. Can be <code>denom</code> or <code>contract_address</code></td><td>Yes</td></tr><tr><td><code>limit</code></td><td><code>uint32</code></td><td>How many records to fetch starting after target token</td><td>No</td></tr></tbody></table>

**Query Response:**

```json
[
  [
    {
      "native_token": {
        "denom": "peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"
      }
    },
    {
      "utilization_ratio": "0.434835991165652783",
      "redemption_ratio": "1.029245984846468095"
    }
  ],
  [
    {
      "native_token": {
        "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7"
      }
    },
    {
      "utilization_ratio": "0.836150542983626702",
      "redemption_ratio": "1.203947857769176135"
    }
  ]
]
```

| Parameter                                                                                 | Type         | Description                                         |
| ----------------------------------------------------------------------------------------- | ------------ | --------------------------------------------------- |
| `native_token`                                                                            | `AssetInfo`  | Object specifying token denom and market metadata   |
| <p><code>native\_token.</code></p><p><strong><code>denom</code></strong></p>              | `string`     | Token address. Can be `denom` or `contract_address` |
| <p><code>native\_token.</code></p><p><strong><code>utilization\_ratio</code></strong></p> | `Decimal256` | The current utilization ratio for the tokens market |
| <p><code>native\_token.</code></p><p><strong><code>redemption\_ratio</code></strong></p>  | `Decimal256` | The current redemption ratio from nToken<>Token     |


# Flashloan Reciever

Flashloan Receiver Contract Addres&#x73;**:** [inj1wmtzan6tgzg0zyauknuxdnnfjwn350yewjf6fq](https://injscan.com/contract/inj1wmtzan6tgzg0zyauknuxdnnfjwn350yewjf6fq/)

The **Flash Loan Receiver Contract** is a component of the Neptune protocol designed to handle flash loan operations. It is a utility which allows users to execute multiple messages related to a trading strategy utilising flashloans. Upon a borrow\_flash\_loan excution call, the borrowed funds and messages are forwarded to the Flashloan Receiver to be executed.

## Execute Messages

### 1. Receive Flash Loan

**Execute:** `receive_flash_loan`

**Purpose:** Authorizes the sender and processes subsequent flash loan messages.

**Execute Input:**

```json
{
  "receive_flash_loan": {
    "flash_loan_receive_msg": {
      "msgs": [
        {
          "bank": {
            "send": {
              "amount": [
                {
                  "denom": "inj",
                  "amount": "1000000"
                }
              ],
              "to_address": "inj1exampleaddress"
            }
          }
        }
      ],
      "sender": "inj1senderaddress"
    }
  }
}
```

| Parameter                | Type                  | Description                                                    | Required |
| ------------------------ | --------------------- | -------------------------------------------------------------- | -------- |
| `flash_loan_receive_msg` | `FlashLoanReceiveMsg` | Contains the messages to be processed and the sender's address | Yes      |

### 2. Withdraw Assets

**Execute:** `withdraw_assets`

**Purpose:** Withdraws specified assets to a designated recipient.

**Execute Input:**

```json
{
  "withdraw_assets": {
    "assets": [
      {
        "native_token": {
          "denom": "inj"
        }
      }
    ],
    "recipient": "inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u"
  }
}
```

| Parameter   | Type             | Description                                | Required |
| ----------- | ---------------- | ------------------------------------------ | -------- |
| `assets`    | `Vec<AssetInfo>` | List of assets to withdraw                 | Yes      |
| `recipient` | `Addr`           | Recipient address, Neptune Market contract | Yes      |


# nToken

The **nToken Contracts** represent receipt tokens issued to lenders when they provide assets to the Neptune Protocol. Each supported market asset has its own nToken contract that tracks lending positions and handles the distribution of lending yields.

## Available nTokens

<table><thead><tr><th width="183">Asset</th><th>nToken Contract Address</th></tr></thead><tbody><tr><td>nAUSD</td><td><a href="https://injscan.com/contract/inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g">inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g</a></td></tr><tr><td>nSOL</td><td><a href="https://injscan.com/contract/inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s">inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s</a></td></tr><tr><td>nTIA</td><td><a href="https://injscan.com/contract/inj1fzquxxxam59z6fzewy2hvvreeh3m04x83zg4vv">inj1fzquxxxam59z6fzewy2hvvreeh3m04x83zg4vv</a></td></tr><tr><td>nUSDC</td><td><a href="https://injscan.com/contract/inj1dafy7fv7qczzatd98dv8hekx6ssckrflswpjaz">inj1dafy7fv7qczzatd98dv8hekx6ssckrflswpjaz</a></td></tr><tr><td>nWETH</td><td><a href="https://injscan.com/contract/inj1kehk5nvreklhylx22p3x0yjydfsz9fv3fvg5xt">inj1kehk5nvreklhylx22p3x0yjydfsz9fv3fvg5xt</a></td></tr><tr><td>nUSDT</td><td><a href="https://injscan.com/contract/inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s">inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s</a></td></tr><tr><td>nATOM</td><td><a href="https://injscan.com/contract/inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780">inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780</a></td></tr><tr><td>nINJ</td><td><a href="https://injscan.com/contract/inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f">inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f</a></td></tr></tbody></table>

***

## Overview

nTokens (Neptune Receipt Tokens) are CW20-compliant tokens that:

* Are minted when users deposit assets into Neptune lending markets
* Represent a user's share of the lending pool
* Automatically accumulate lending yields
* Can be used as collateral in Neptune markets
* Can be transferred between users while maintaining the underlying position

The redemption value of nTokens increases over time as lending interest accrues, allowing holders to redeem for more of the underlying asset than they initially deposited.

***

## Query Messages

### 1. Token Info

**Query:** `token_info`

**Purpose:**\
Retrieves basic information about the nToken including name, symbol, decimals, and total supply.

**Query Input:**

```json
{
  "token_info": {}
}
```

**Query Response:**

```json
{
  "name": "Neptune USDT",
  "symbol": "nUSDT",
  "decimals": 6,
  "total_supply": "873600917508"
}
```

| Parameter      | Type      | Description                        |
| -------------- | --------- | ---------------------------------- |
| `name`         | `string`  | The name of the nToken             |
| `symbol`       | `string`  | The symbol of the nToken           |
| `decimals`     | `u8`      | Number of decimal places           |
| `total_supply` | `unit256` | Current total supply of the nToken |

### 2. Balance

**Query:** `balance`

**Purpose:**\
Returns the nToken balance of a specified address.

**Query Input:**

```json
{
  "balance": {
    "address": "inj1..."
  }
}
```

**Query Response:**

```json
{
  "balance": "1000000"
}
```

| Parameter | Type      | Description                                 |
| --------- | --------- | ------------------------------------------- |
| `balance` | `unit128` | The nToken balance of the specified address |

***

## Execute Messages

### 1. Transfer

**Execute:** `transfer`

**Purpose:**\
Transfers nTokens from the sender to a specified recipient.

**Execute Input:**

```json
{
  "transfer": {
    "recipient": "inj1...",
    "amount": "1000000"
  }
}
```

| Parameter   | Type      | Description                    | Required |
| ----------- | --------- | ------------------------------ | -------- |
| `recipient` | `addr`    | Address to receive the nTokens | Yes      |
| `amount`    | `unit128` | Amount of nTokens to transfer  | Yes      |

### 2. Send

**Execute:** `send`

**Purpose:**\
Transfers nTokens from the sender to a contract, triggering a receive hook on the receiving contract. This is used for operations like redeeming nTokens for the underlying asset through the Market contract.

**Execute Input:**

```json
{
  "send": {
    "contract": "inj1nc7gjkf2mhp34a6gquhurg8qahnw5kxs5u3s4u",
    "amount": "1000000",
    "msg": "eyJyZWRlZW0iOnt9fQ==" // Base64 encoded message: {"redeem":{}}
  }
}
```

<table><thead><tr><th width="143">Parameter</th><th width="128">Type</th><th>Description</th><th>Required</th></tr></thead><tbody><tr><td><code>contract</code></td><td><code>addr</code></td><td>Contract address to receive the nTokens</td><td>Yes</td></tr><tr><td><code>amount</code></td><td><code>unit128</code></td><td>Amount of nTokens to send</td><td>Yes</td></tr><tr><td><code>msg</code></td><td><code>binary</code></td><td>Base64 encoded message to pass to the receiving contract</td><td>Yes</td></tr></tbody></table>

***

## Usage as Collateral

nTokens can be used as collateral in Neptune markets, allowing users to maintain their lending positions while borrowing against them. When used as collateral, nTokens are valued based on:

1. The current market price of the underlying asset
2. The current redemption rate of the nToken
3. The collateral parameters set for the specific nToken

This enables strategies like:

* Leveraging lending positions
* Maintaining exposure to lending yields while accessing liquidity
* Complex yield strategies combining lending and borrowing


# Token Addresses

A list of tokens used in the Neptune Protocol

<table><thead><tr><th width="114">Ticker</th><th>Address</th></tr></thead><tbody><tr><td>INJ</td><td>inj</td></tr><tr><td>nINJ</td><td>inj1rmzufd7h09sqfrre5dtvu5d09ta7c0t4jzkr2f</td></tr><tr><td>USDT</td><td>peggy0xdAC17F958D2ee523a2206206994597C13D831ec7</td></tr><tr><td>nUSDT</td><td>inj1cy9hes20vww2yr6crvs75gxy5hpycya2hmjg9s</td></tr><tr><td>USDCnb</td><td>ibc/2CBC2EA121AE42563B08028466F37B600F2D7D4282342DE938283CC3FB2BC00E</td></tr><tr><td>nUSDCnb</td><td>inj1dafy7fv7qczzatd98dv8hekx6ssckrflswpjaz</td></tr><tr><td>USDC</td><td>erc20:0xa00C59fF5a080D2b954d0c75e46E22a0c371235a</td></tr><tr><td>nUSDC</td><td>inj1zw9n3xnpxnv72ge2hvjzphujas2hk6c338ut0n</td></tr><tr><td>ATOM</td><td>ibc/C4CFF46FD6DE35CA4CF4CE031E643C8FDC9BA4B99AE598E9B0ED98FE3A2319F9</td></tr><tr><td>nATOM</td><td>inj16jf4qkcarp3lan4wl2qkrelf4kduvvujwg0780</td></tr><tr><td>stATOM</td><td>ibc/A8F39212ED30B6A8C2AC736665835720D3D7BE4A1D18D68566525EC25ECF1C9B</td></tr><tr><td>SOL</td><td>ibc/A8B0B746B5AB736C2D8577259B510D56B8AF598008F68041E3D634BCDE72BE97</td></tr><tr><td>nSOL</td><td>inj1zcwr03uqw57g88nqvgpwfkazwutpqz9kplny4s</td></tr><tr><td>TIA</td><td>ibc/F51BB221BAA275F2EBF654F70B005627D7E713AFFD6D86AFD1E43CAA886149F4</td></tr><tr><td>nTIA</td><td>inj1fzquxxxam59z6fzewy2hvvreeh3m04x83zg4vv</td></tr><tr><td>WETH</td><td>peggy0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2</td></tr><tr><td>nWETH</td><td>inj1kehk5nvreklhylx22p3x0yjydfsz9fv3fvg5xt</td></tr><tr><td>WBTC</td><td>ibc/0E293A7622DC9A6439DB60E6D234B5AF446962E27CA3AB44D0590603DFF6968E</td></tr><tr><td>AUSD</td><td>factory/inj1n636d9gzrqggdk66n2f97th0x8yuhfrtx520e7/ausd</td></tr><tr><td>nAUSD</td><td>inj1tkuemghm734h9qy8fh2eu0qp9hyfdlws0llt8g</td></tr><tr><td>NEPT</td><td>factory/inj1v3a4zznudwpukpr8y987pu5gnh4xuf7v36jhva/nept</td></tr><tr><td>hINJ</td><td>inj18luqttqyckgpddndh8hvaq25d5nfwjc78m56lc</td></tr></tbody></table>


# User Guides


# How to Lend on Neptune

This guide steps you through how to connect to the Neptune Finance application and lend your desired assets to start earning yield immediately.

1\. On the Neptune Finance application, first connect your wallet by clicking connect wallet.

![](/files/6IA71v8xxHsx6DJTILQq)

2\. Select your preferred wallet.

![](/files/AxpunOByGy10MQgqa1ge)

3\. With my wallet connected, you can now see the available assets you can use in Neptune.

![](/files/EI87wo2UNhScJRC0UVyT)

4\. Click in the 'Lend' tab to go the lending page

![](/files/HnqgachXZsZB4SsSEGgO)

5\. Click the 'lend' button on the asset you want to lend.

![](/files/Z1CZf1EtbL7q1SZky4EE)

6\. Enter the amount of tokens you want to lend. You can type the exact amount you want, use the '1/4, 1/2,...max' buttons, or use the slide bar to enter an amount.

![](/files/ZUF8wqRPJK24gtJ3WXma)

7\. Once you've entered your amount click the 'lend' button to execute the lend transaction.

![](/files/CTo0terc0p0nZrnfZaZd)

8\. Confirm the transaction with your wallet.

![](/files/Y1RKE86a4TwVG42nkSxo)

9\. With the transactions being confirmed, you can now see the 100 USDT deposited, and in your wallet view you can also see the nUSDT receipt tokens which have been sent to your wallet.\
These nToken represent your lending deposits and need to be returned to the protocol when withdrawing your original principal plus interest.

![](/files/TK6qr85e8Z34JPFAi7DQ)


# How to Borrow on Neptune

This guide steps you through how to connect to the Neptune Finance application and open a margin account to start borrowing assets for your defi strategies.

1\. On Neptune Finance application, first connect your wallet by clicking connect wallet.

![](/files/SoTdSnjq7dPpZeRrIvOB)

2\. Select your preferred wallet.

![](/files/eENrBfZDMstedrHGwFFV)

3\. With your wallet connected, you can now see the available assets you can use in Neptune.

![](/files/Rma2JHC0ceF2kCL5oR3V)

4\. Click the 'Borrow' tab to go to the borrow page.

![](/files/HDuPYkyhQM8DbddWA2kE)

5\. In the borrow page, you can deposit the assets you have available as collateral.

![](/files/OIQDVAGw58QZqie7aOW8)

6\. Enter the amount of tokens you want to deposit as collateral.

![](/files/0UZPwogRHbeXqfHZgKVN)

7\. Click the 'add collateral' button to execute the add collateral transaction.

![](/files/8sawENkbQO5hs8dhJS1H)

8\. Approve the transaction in your wallet.

![](/files/mGKUefpq3ltCXT7hYaqV)

9\. Now you have a new margin account with the collateral you just deposited.

![](/files/FK87npYKNxnSNQLM4Pw2)

10\. You now have collateral in your first margin account. Now you can borrow an asset. Click 'borrow' on the asset that you want to borrow in your margin account.

![](/files/CXmdqSLH1PPt8pYcavCQ)

11\. Enter the amount of tokens you want to borrow.\
The account health visual will update automatically to show your estimated account health with the amount of tokens you have entered.

![](/files/a5Q1pPH3IN1qXGxrALNe)

12\. Once you've entered your amount click the 'borrow' button to execute the borrow transaction.

![](/files/aCgwsvSKQdhUSS4dlV2X)

13\. Approve the transaction in your wallet.

![](/files/DsuChZJoqd906rkuoYrt)

14\. You now have an active borrower position.\
You can see more information about your borrower position if you click the dropdown details of your subaccount.

![](/files/nGvhyGco7LF6FRk9vCbr)

15\. You can edit the name of your margin account for easier personal tracking.

![](/files/NUFDibG8OBd0wdMLXCnX)

16\. Now that your margin account is set up, be sure to monitor your collateral, debt and account account health values.\
If your account health ever goes below 1, your margin account would be subject to liquidation.

![](/files/bzh8N7Gf3AJYHJSKy9pC)


# How to Stake with the Neptune Validator

This is a guide on how to stake your Injective tokens (INJ) to the Neptune Foundation validator.\
The Neptune Foundation validator supports the developments of Neptune and participates in the Injective chain governance.\
Staking your INJ allows to to earning staking rewards.

1\. Go to Injective Hub application at <https://hub.injective.network/> and navigate to the stake page.

![](/files/qILrRHMJky9W0qGKFktX)

2\. Click connect wallet.

![](/files/yLODVKpHuCYfGNq3aZod)

3\. Accept the terms and conditions.

![](/files/j1sxVNXO4xGEhy8Umgsc)

4\. Select your preferred wallet.

![](/files/VOvCDGpQxOtEqPvcRD1i)

5\. With your wallet connected, you can now search for the Neptune validator

![](/files/Dko9is40a94jsBOhL6rG)

6\. Click on the Neptune Foundation validator.

![](/files/LJT2yjlBWsJs4fMQmw18)

7\. Once you're on the validator page, click stake now.

![](/files/NQbrI2wmvPDBXr3xjJ7S)

8\. Enter the amount of INJ you want to stake.

![](/files/h9oYgNwqY9LoMbASZKh2)

9\. Click the checkbox, then click stake to create the transaction.

![](/files/1dCu3LHJzb28PBusi99O)

10\. Approve the transaction in your wallet.

![](/files/85IpeGHBHH1DYQnWJSbJ)

11\. You have now successfully staked to the Neptune Foundation validator!

![](/files/fXBzLk0BFJNJUgq9FdSg)


# How to bridge TIA to Injective

This guide will show you how to bridge TIA to Injective chain so that you can start using it in Neptune

1\. Go to the Injective Bridge app at [bridge.injective.network](https://bridge.injective.network/)

<figure><img src="/files/G496rfaqnGPs4oI7gOiv" alt=""><figcaption></figcaption></figure>

2\. Click 'Connect' to connect your wallet. Select your wallet.

<figure><img src="/files/Y2MGNJw2DzJycnzb0ruK" alt=""><figcaption></figcaption></figure>

3\. Select your preferred wallet

<figure><img src="/files/y7oMWA9WoTUgPYkE4uoI" alt=""><figcaption></figcaption></figure>

4\. Click the dropdown menu to view the chain options.

<figure><img src="/files/t35l2s6jtXya2beKXg3E" alt=""><figcaption></figcaption></figure>

5\. Select the Celestia blockchain.

<figure><img src="/files/0ERT9bA1Jp5ZBjRmFKg6" alt=""><figcaption></figcaption></figure>

6\. Select TIA as the asset to bridge.

<figure><img src="/files/DclxBdv4iyD4Ov8fYeGA" alt=""><figcaption></figcaption></figure>

7\. Enter the amount of TIA tokens you want to bridge

<figure><img src="/files/FE0tI1jVhnJ8fAPZvDF5" alt=""><figcaption></figcaption></figure>

8\. Click 'Review Deposit'.

<figure><img src="/files/nEEyzBEGMyPr89zq3nsx" alt=""><figcaption></figcaption></figure>

9\. Click 'Confirm' to create the transaction.

<figure><img src="/files/TusdUVMo4ezdI1Zi9dZd" alt=""><figcaption></figcaption></figure>

10\. Sign the transaction in your wallet.

<figure><img src="/files/1a36w06jr38bLjVFrbZB" alt=""><figcaption></figcaption></figure>

11\. The bridging process is now complete

<figure><img src="/files/gUanrGUpld2dnkIZ1mFm" alt=""><figcaption></figcaption></figure>


# Neptune Alerts

Neptune Alerts is a background service that allows you to set up custom conditions to receive alerts directly to your preferred messaging service. Giving a user the ability to more passive manage their Neptune positions with the need to constantly check the webapp.\
\\


# Register a Alerts Account

To start using Neptune Alerts you must first register an account using your email address.

1. Navigate to <https://alerts.nept.finance/auth/login> and click the "Register" button\
   \
   ![](/files/mHQg52scSfywOCIkMh8n)
2. Enter your email and new password, then click "Register"\
   \
   ![](/files/xO6X3QQbZ1kZ4hrIMP9E)
3. A confirmation email will be sent to your account to confirm your email address. Once you've confirmed your email address, you will be redirected to the login page where you can login with the credentials you just created


# Register your wallets

Certain alerting conditions in Neptune alerts require you to connect your wallet so that the application knows which Neptune accounts and positions are yours.

1. Once you've logged into Neptune Alerts, navigate to the "Integrations" page

<figure><img src="/files/KNVy5S9LLQGSCsFsz9Fp" alt=""><figcaption></figcaption></figure>

2. On the integrations page, click "ADD WALLET"

<figure><img src="/files/jbYRNkkUiVDfZoocuLSy" alt=""><figcaption></figcaption></figure>

3. Select the wallet you want to connect, and approve the connection when prompted by your wallet

<figure><img src="/files/kgMLSzG0X23NtiHEMRv6" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3wueIiLtjaWS73rilrQB" alt=""><figcaption></figcaption></figure>

4. Now that you have approved wallet connection to the application, you must prove ownership of you wallet.\
   Click connect wallet again and select the wallet you you just connected. You will now see your wallet address. Click your address and approve ownership once prompted by your wallet.

<figure><img src="/files/AEvFrY9LPAeWf6dtNQb6" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/Hn1V9uPFWc3fF9sNsiEc" alt=""><figcaption></figcaption></figure>

5. You can now add a descriptive name for the wallet you just connected and click "save"\\

<figure><img src="/files/lgezYOIVK4O6Ox5Qg9Mk" alt=""><figcaption></figcaption></figure>

6. Your wallet is not connected and registered to your account. You can add more wallets or delete old ones at any time

<figure><img src="/files/MXyc7V1w7GIsutf8PJ1a" alt=""><figcaption></figcaption></figure>


# Create a Alerting Rule


# Socials and Media

## Socials

Stay up to date with the latest Neptune new by following us on [X](https://x.com/neptune_finance)

Join the community discussion in the Neptune [Discord](https://discord.com/invite/xj6tpkdk7k)

Get the latest community announcements alerts on [Telegram](https://t.me/neptunefinance)

## Articles

Read in depth articles about Neptune's features and develops on [Medium](https://articles.nept.finance/)

## Website

Explore all the benefits of Neptune on our [Website](https://nept.finance/)

Start using Neptune to advance your yields and defi strategies on our [App](https://app.nept.finance/)

## Media

Neptune logo, png 200px

<figure><img src="/files/Bvmhlvln3dXfIbn2Gjug" alt=""><figcaption></figcaption></figure>

Neptune Header, png

<figure><img src="/files/qulovmy0gScvMaEEeSQZ" alt=""><figcaption></figcaption></figure>


# Audits

Overview of security audits performed on the Neptune protocol, including reports from Oak Security covering core protocol functionality, token features, and staking mechanisms.

## Neptune V1

Coverage - Core protocol

Auditor - Oak Security

[Audit Report](https://github.com/oak-security/audit-reports/blob/main/Neptune/2024-01-09%20Audit%20Report%20-%20Neptune%20Updates%20v1.0.pdf)

## Neptune V2

Coverage - Token and Staking Features

Auditor - Oak Security

[Audit Report](https://github.com/oak-security/audit-reports/blob/main/Neptune/2024-12-06%20Audit%20Report%20-%20Neptune%20Updates%202%20v1.0.pdf)


