nibiru.query_clients package

Submodules

nibiru.query_clients.spot module

class nibiru.query_clients.spot.SpotQueryClient(channel: Channel)

Bases: QueryClient

Spot allows to query the endpoints made available by the Nibiru Chain’s SPOT module.

estimate_exit_exact_amount_in(pool_id: int, num_shares: int) dict

Estimate the output of an exit pool transaction with the current level of reserves

Example Return Value:

{
    "tokensOut": [
        {
            "denom": "unibi",
            "amount": 1000.5
        },
        {
            "denom": "unusd",
            "amount": 100.2
        }
    ]
}
Parameters:
  • pool_id (int) – The id of the pool to query

  • num_shares (int) – The number of shares to provide

Returns:

The output of the query

Return type:

dict

estimate_join_exact_amount_in(pool_id: int, tokens_ins: List[Coin]) dict

Estimate the number of share given for a join pool operation

Example Return Value:

{
    "poolSharesOut": 100000000000000.0,
    "remCoins": [
        {
            "denom": "unibi",
            "amount": 0.999
        }
    ]
}
Parameters:
  • pool_id (int) – The id of the pool to query

  • tokens_ins (List[Coin]) – The amount of tokens provided

Returns:

The output of the query

Return type:

dict

estimate_swap_exact_amount_in(pool_id: int, token_in: Coin, token_out_denom: str) dict

Estimate the output of the swap with the current reserves

Example Return Value:

{
    "tokenOut": {
        "denom": "unusd",
        "amount": 0.004948999999999999
    }
}
Parameters:
  • pool_id (int) – The pool id to query

  • token_in (Coin) – The amount of tokens to provide

  • token_out_denom (str) – The denomination of the token out

Returns:

The output of the query

Return type:

dict

params() dict

Requests the parameters of the spot module.

Example Return Value:

{
    "startingPoolNumber": "1",
    "poolCreationFee": [
        {
            "denom": "unibi",
            "amount": 1000.0
        }
    ],
    "whitelistedAsset": [
        "unibi",
        "uusdc",
        "unusd",
        "stake"
    ]
}
Returns:

The parameters fo the spot module.

Return type:

dict

pools(**kwargs)

Return all available pools in the spot module.

Example Return Value:

[
    {
        "id": "1",
        "address": "nibi1w00c7pqkr5z7ptewg5z87j2ncvxd88w43ug679",
        "poolParams": {
            "swapFee": 0.02,
            "exitFee": 0.1
        },
        "poolAssets": [
            {
                "token": {
                    "denom": "unibi",
                    "amount": 0.001
                },
                "weight": "53687091200000000"
            },
            {
                "token": {
                    "denom": "unusd",
                    "amount": 0.01
                },
                "weight": "53687091200000000"
            }
        ],
        "totalWeight": "107374182400000000",
        "totalShares": {
            "denom": "nibiru/pool/1",
            "amount": 100000000000000.0
        }
    }
]
Parameters:
  • key (bytes) – The page key for the next page. Only key or offset should be set

  • offset (int) – The number of entries to skip. Only offset or key should be set

  • limit (int) – The number of max results in the page

  • count_total (bool) – Indicates if the response should contain the total number of results

  • reverse (bool) – Indicates if the results should be returned in descending order

Returns:

The output of the query

Return type:

dict

spot_price(pool_id: int, token_in_denom: str, token_out_denom: str) dict

Returns the spot price of the pool using token in as base and token out as quote

Parameters:
  • pool_id (int) – _description_

  • token_in_denom (str) – _description_

  • token_out_denom (str) – _description_

Returns:

_description_

Return type:

dict

total_liquidity() dict

Returns the total amount of liquidity for the spot module

Example Return Value:

{
    "liquidity": [
        {
            "denom": "unibi",
            "amount": 0.001
        },
        {
            "denom": "unusd",
            "amount": 0.01
        }
    ]
}
Returns:

The total liquidity of the protocol

Return type:

dict

total_pool_liquidity(pool_id: int) dict

Returns the total liquidity for a specific pool id

Example Return Value:

{
    "liquidity": [
        {
            "denom": "unibi",
            "amount": 0.001
        },
        {
            "denom": "unusd",
            "amount": 0.01
        }
    ]
}
Parameters:

pool_id (int) – the id of the pool

Returns:

The total liquidity for the pool

Return type:

dict

total_shares(pool_id: int) dict

Returns the total amount of shares for the pool specified

Example Return Value:

{
    "totalShares": {
        "denom": "nibiru/pool/1",
        "amount": 100000000000000.0
    }
}
Parameters:

pool_id (int) – The id of the pool

Returns:

The amount of shares for the pool

Return type:

dict

nibiru.query_clients.perp module

class nibiru.query_clients.perp.PerpQueryClient(channel: Channel)

Bases: QueryClient

Perp allows to query the endpoints made available by the Nibiru Chain’s PERP module.

all_positions(trader: str) Dict[str, dict]
Parameters:

trader (str) – Address of the owner of the positions

Returns:

All of the open positions for the ‘trader’.

Return type:

Dict[str, dict]

Example Return Value:

```json {

“ubtc:unusd”: {

“block_number”: 1137714, “margin_ratio_index”: 0.0, “margin_ratio_mark”: 0.09999999999655101, “position”: { “block_number”: 1137714, “latest_cumulative_premium_fraction”: 17233.436302191654, “margin”: 10.0, “open_notional”: 100.0, “pair”: “ubtc:unusd”, “size”: -0.00545940925278242, “trader_address”: “nibi10gm4kys9yyrlqpvj05vqvjwvje87gln8nsm8wa” }, “position_notional”: 100.0, “unrealized_pnl”: -5.079e-15

}

}

markets()

Get the all markets infromation.

params()

Get the parameters of the perp module.

Example Return Value:

```json
{

“feePoolFeeRatio”: 0.001, “ecosystemFundFeeRatio”: 0.001, “liquidationFeeRatio”: 0.025, “partialLiquidationRatio”: 0.25, “epochIdentifier”: “30 min”, “twapLookbackWindow”: “900s”

}

returns:

The current parameters for the perpetual module

rtype:

dict

position(pair: str, trader: str) dict

Get the trader position. Returns information about position notional, margin ratio unrealized pnl, size of the position etc.

Parameters:
  • pair (str) – The token pair

  • trader (str) – The trader address

Example Return Value:

```json
{
“position”: {

“traderAddress”: “nibi1zaavvzxez0elund”, “pair”: “ubtc:unusd”, “size”: 11.241446725317692, “margin”: 45999.99999999999, “openNotional”: 230000.0, “lastUpdateCumulativePremiumFraction”: “0”, “blockNumber”: “278”

}, “positionNotional”: 230000.0, “unrealizedPnl”: 1.024e-20, “marginRatioMark”: 0.2, “marginRatioIndex”: 0.2

}

returns:

The output of the query

rtype:

dict

nibiru.query_clients.util module

nibiru.query_clients.util.PROTOBUF_MSG_BASE_ATTRS: List[str] = ['ByteSize', 'Clear', 'ClearExtension', 'ClearField', 'CopyFrom', 'DESCRIPTOR', 'DiscardUnknownFields', 'FromString', 'HasExtension', 'HasField', 'IsInitialized', 'ListFields', 'MergeFrom', 'MergeFromString', 'ParseFromString', 'RegisterExtension', 'SerializePartialToString', 'SerializeToString', 'SetInParent', 'UnknownFields', 'WhichOneof', '_SetListener', '__class__', '__deepcopy__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__unicode__', 'Extensions', 'FindInitializationErrors', '_CheckCalledFromGeneratedFile', '_extensions_by_name', '_extensions_by_number']

The default attributes and methods of an instance of the ‘protobuf.message.Message’ class.

Type:

PROTOBUF_MSG_BASE_ATTRS (List[str])

class nibiru.query_clients.util.QueryClient

Bases: object

query(api_callable: UnaryUnaryMultiCallable, req: Message, should_deserialize: bool = True, height: int | None = None) dict | Message
nibiru.query_clients.util.camel_to_snake(camel: str)
nibiru.query_clients.util.deserialize(pb_msg: Message, no_sdk_transformation: bool = False) dict

Deserializes a proto message into a dictionary.

  • sdk.Dec values are converted to floats.

  • sdk.Int values are converted to ints.

  • Missing fields become blank strings.

Parameters:
  • pb_msg (protobuf.message.Message) –

  • no_sdk_transformation (bool) – Wether to bypass the sdk transformation. Default to False

Returns:

‘pb_msg’ as a JSON-able dictionary.

Return type:

dict

nibiru.query_clients.util.deserialize_exp(proto_message: Message) dict

Take a proto message and convert it into a dictionnary. sdk.Dec values are converted to be consistent with txs.

Parameters:

proto_message (protobuf.message.Message) –

Returns:

dict

nibiru.query_clients.util.dict_keys_from_camel_to_snake(d)

Transform all keys from the dictionary from camelcase to snake case.

Parameters:

d (dict) – The dictionary to transform

Returns:

The dictionary transformed

Return type:

dict

nibiru.query_clients.util.get_block_messages(block: Block) List[dict]

Rerurns block messages as a list of dicts. Matches corresponding messages types by type_url.

nibiru.query_clients.util.get_msg_pb_by_type_url(type_url: str) Message | None

Tries loading protobuf class by type url. Examples type urls:

/cosmos.bank.v1beta1.MsgSend /nibiru.perp.v1.MsgOpenPosition

nibiru.query_clients.util.get_page_request(kwargs)

nibiru.query_clients.vpool module

Module contents