LogoLogo
  • Overview
  • Learn
    • Lend
    • Borrow
    • Interest Rate
    • Liquidate
    • Flash Loans
    • NEPT Token
    • Risks
  • Develop
    • Contracts
      • Market
      • Interest Model
      • Token
      • Oracle
      • Querier
      • Flashloan Reciever
      • nToken
    • Token Addresses
  • User Guides
    • How to Lend on Neptune
    • How to Borrow on Neptune
    • How to Stake with the Neptune Validator
    • How to bridge TIA to Injective
  • Socials and Media
  • Audits
Powered by GitBook
On this page
  • Interrelation with Other Contracts
  • Query Messages
  • 1. Get Account Health
  • 2. Get Collateral Discount
  • 3. Get Liquidation Request
  • 4. Get Market Metadata
  1. Develop
  2. Contracts

Querier

PreviousOracleNextFlashloan Reciever

Last updated 2 months ago

Querier Contract Address:

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:

Account Health=Weighted Collateral Value + Weighted StakeDebt Value\text{Account Health} = \frac{\text{Weighted Collateral Value + Weighted Stake}}{\text{Debt Value}}Account Health=Debt ValueWeighted Collateral Value + Weighted Stake​

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:

{
  "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:

{
    "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 health<1\text{health} < 1health<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:

{
    "get_collateral_discounts": {
        "addr": "inj................",
        "account_index": 0
    }
}
Parameter
Type
Description
Required

addr

addr

Injetive wallet address

Yes

account_index

uint8

sub account's index ID

Yes

Query Response:

{
    "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.

Parameter
Type
Description

asset_info

AssetInfo

Object containing the type of token and either a denom or a contract address

asset_info.

type

string

"native_token" or "token"

asset_info.

denom

string

Denomination of the token (if type = native_token)

asset_info.

contract_addr

addr

Contract address of the token (if type = token)

discount

decimal256

The discount value for this particular collateral token

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:

{
    "get_liquidation_request": {
        "account_addr": "inj834l...",
        "account_index": 0,
        "collateral_priority": [
            { "type": "native_token", "denom": "inj" }
        ],
        "debt_priority": [
            { "type": "native_token", "denom": "peggy0xdAC17F958D2ee523a2206206994597C13D831ec7" }
        ]
    }
}
Parameter
Type
Description
Required

account_addr

Addr

The account address to be checked or liquidated

Yes

account_index

uint8

The sub-account index ID

Yes

collateral_priority

AssetInfo[]

Ordered list of collateral token types to be liquidated first, second, etc

No

collateral_priority.

type

string

The collateral token "type". Can be "native_token" or "token"

Yes

collateral_priority.

denom

string

The collateral token address. Can be denom or token_address

Yes

debt_priority

AssetInfo[]

Ordered list of debts to be repaid first, second, etc

No

debt_priority.

type

string

The debt token "type". Can be "native_token" or "token"

Yes

debt_priority.

denom

string

The debt token address. Can be denom or token_address

Yes

Query Response:

{
  "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

ask_assets.

denom

object

Collateral details for a specific token

ask_assets.

denom.

amount

Uint256

The amount of collateral to be liquidated

ask_assets.

denom.

min_discount

Decimal256

Any applicable discount applied to collateral value

offer_assets

NeptuneMap<AssetInfo, Uint256>

Object listing the debt to be repaid

offer_assets.

denom

Uint256

The amount of debt that must be repaid for liquidation

4. Get Market Metadata

The contract also computes key market ratios:

  • Utilization Ratio:

Utilization Ratio=Debt Pool BalanceLending Principal\text{Utilization Ratio} = \frac{\text{Debt Pool Balance}}{\text{Lending Principal}}Utilization Ratio=Lending PrincipalDebt Pool Balance​
  • Redemption Ratio:

Redemption Ratio=Lending PrincipalTotal Receipt Token Supply\text{Redemption Ratio} = \frac{\text{Lending Principal}}{\text{Total Receipt Token Supply}}Redemption Ratio=Total Receipt Token SupplyLending Principal​

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:

{
  "get_market_metadata": {
    "start_after": {
      "native_token": {
        "denom": "inj"
      }
    },
    "limit": 2
  }
}
Parameter
Type
Description
Required

start_after

AssetInfo

Object specifying which token to start after

No

start_after.

native_token

object

Token type. Can be native_token or token

Yes

start_after.

native_token.

denom

string

Token address. Can be denom or contract_address

Yes

limit

uint32

How many records to fetch starting after target token

No

Query Response:

[
  [
    {
      "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

native_token.

denom

string

Token address. Can be denom or contract_address

native_token.

utilization_ratio

Decimal256

The current utilization ratio for the tokens market

native_token.

redemption_ratio

Decimal256

The current redemption ratio from nToken<>Token

inj1kfjff5f0xjy7gece36watkqtscpycv666tqq7t