Skip to main content

Query a liquidity pool

Learn how to query pool information from the Balanced DEX contract.

You can query the Balanced DEX contract to retrieve information about a specific liquidity pool, like the pool ID, price, and total supply.

1. Find the pool ID

Before you can fetch data for a specific liquidity pool, you’ll need to find its pool ID.

Find the token contract addresses, then call the getPoolId method on the DEX contract (cxa0af3165c08318e988cb30993b3048335b94af6c) to get the pool ID.

2. Call the getPoolStats method

Once you have the pool ID, you can use the getPoolStats method to fetch more info.

Here’s an example that requests information for pool ID 0x2 (sICX / bnUSD):

Request:

curl -X POST --data '{"jsonrpc":"2.0","method":"icx_call","id":604,"params":{"to":"cxa0af3165c08318e988cb30993b3048335b94af6c","dataType":"call","data":{"method":"getPoolStats", "params": {"_id": "0x2"}}}}' https://ctz.solidwallet.io/api/v3 | jq

Response:

{
"jsonrpc": "2.0",
"result": {
"base": "0x4e11d9b13bd940132255a",
"base_decimals": "0x12",
"base_token": "cx2609b924e33ef00b648a409245c7ea394c467824",
"min_quote": "0x8ac7230489e80000",
"name": "sICX/bnUSD",
"price": "0x27e882e8bcdc538",
"quote": "0xe08127eca743ec852241",
"quote_decimals": "0x12",
"quote_token": "cx88fd7df7ddff82f7cc735c871dc519838cb235bb",
"total_supply": "0x1aea37f3cfab9549026bd"
},
"id": 604
}

The response contains a price field: this is the current pool price in loop units, expressed as a hexadecimal value. To obtain the actual price, convert the value to a decimal format and divide it by 10^18.

> const a = "0x27e882e8bcdc538"
> a.ToString('16')/10**18
0.17973076863679008