Get Pools Info
This page shows how to retrieve pool data from Aquarius AMM.
You can retrieve information about pools in two ways: by calling smart contract methods or by using the Aquarius backend API.
Pool details are also displayed on the Aquarius website, on pool info page - e.g. https://aqua.network/pools/CCY2PXGMKNQHO7WNYXEWX76L2C5BH3JUW3RCATGUYKY7QQTRILBZIFWV/
Using smart contracts: Step by Step Guide
Since calling contract methods does not alter the Stellar network and is executed through transaction simulation, a transaction signature is not required, and the call can be made using a public key. Scroll here to see the complete code.
Specify user public key and tokens
# AQUA issuer - we don't call user related information in our simulations, so any public key is fine
USER_PUBLIC_KEY = 'GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA'
# XLM
TOKEN_A = Asset.native()
# AQUA
TOKEN_B = Asset('AQUA', 'GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA')
Retrieve a list of pools with specified tokens.
def get_pools(server, address, router_contract_id, tokens: list[Asset]) -> dict:
tx_builder = TransactionBuilder(
source_account=server.load_account(address),
network_passphrase=NETWORK_PASSPHRASE,
base_fee=1000000 # Set base fee; adjust as necessary
).set_timeout(3600) # Set transaction timeout
tx = (
tx_builder
.append_invoke_contract_function_op(
contract_id=router_contract_id,
function_name="get_pools",
parameters=[
scval.to_vec(order_token_ids([
Address(token.contract_id(NETWORK_PASSPHRASE)).to_xdr_sc_val()
for token in tokens
])),
],
)
.build()
)
simulation = server.simulate_transaction(tx)
tx_result = [xdr.SCVal.from_xdr(r.xdr) for r in simulation.results][0]
if not tx_result:
raise RuntimeError
return {
entry.key.bytes.sc_bytes.hex(): StrKey.encode_contract(binascii.unhexlify(entry.val.address.contract_id.hash.hex()))
for entry in tx_result.map.sc_map
}
Retrieve information about each pool obtained in the previous step.
def get_pools_info():
server = SorobanServer(SOROBAN_SERVER_RPC)
pools = get_pools(
server,
USER_PUBLIC_KEY,
ROUTER_CONTRACT_ID,
[TOKEN_A, TOKEN_B],
)
for pool_hash, pool_id in pools.items():
print(f"pool '{pool_hash}', '{pool_id}'")
tx = (
TransactionBuilder(
source_account=server.load_account(USER_PUBLIC_KEY),
network_passphrase=NETWORK_PASSPHRASE,
base_fee=1000000
).set_timeout(3600)
.append_invoke_contract_function_op(
contract_id=ROUTER_CONTRACT_ID,
function_name="get_info",
parameters=[
scval.to_vec(order_token_ids([
Address(TOKEN_A.contract_id(NETWORK_PASSPHRASE)).to_xdr_sc_val(),
Address(TOKEN_B.contract_id(NETWORK_PASSPHRASE)).to_xdr_sc_val()
])),
scval.to_bytes(bytes.fromhex(pool_hash)), # Known pool hash as bytes
],
)
.build()
)
simulation = server.simulate_transaction(tx)
tx_result = [xdr.SCVal.from_xdr(r.xdr) for r in simulation.results][0]
if not tx_result:
raise RuntimeError
pool_info = {
entry.key.sym.sc_symbol.decode(): entry.val
for entry in tx_result.map.sc_map
}
pool_info['pool_type'] = pool_info['pool_type'].sym.sc_symbol.decode()
pool_info['fee'] = "{0}%".format(str(int(pool_info['fee'].u32.uint32) / 10_000 * 100))
if 'a' in pool_info:
pool_info['a'] = u128_to_int(pool_info['a'].u128)
if 'n_tokens' in pool_info:
pool_info['n_tokens'] = int(pool_info['n_tokens'].u32.uint32)
print('pool hash', pool_hash)
for key, value in pool_info.items():
print(key, value)
print('-------')
Complete Code Examples
Using backend API
import requests
base_api = 'https://amm-api.aqua.network/api/external/v1';
# You can skip using the address__in filter and retrieve a list of all pools with pagination.
def get_pools_info(base_api: str, pools: list[str]) -> dict:
return requests.get(f"{base_api}/pools/?address__in={','.join(pools)}").json()
print(
get_pools_info(
base_api,
[
'CDE57N6XTUPBKYYDGQMXX7E7SLNOLFY3JEQB4MULSMR2AKTSAENGX2HC'
],
)
)
"""
{
'count': 1,
'next': None,
'previous': None,
'results': [
{
'index': 'b2e02fcfca6c96f8ad5cbd84e7784a777b36d9c96a2459402c4f458462aab7f0',
'address': 'CDE57N6XTUPBKYYDGQMXX7E7SLNOLFY3JEQB4MULSMR2AKTSAENGX2HC',
'tokens_addresses': [
'CAS3J7GYLGXMF6TDJBBYYSE3HQ6BBSMLNUQ34T6TZMYMW2EVH34XOWMA',
'CAUIKL3IYGMERDRUN6YSCLWVAKIFG5Q4YJHUKM4S4NJZQIA3BAS6OJPK'
],
'tokens_str': [
'native',
'AQUA:GBNZILSTVQZ4R7IKQDGHYGY2QXL5QOFJYQMXPKWRRM5PAV7Y4M67AQUA'
],
'pool_type': 'constant_product',
'fee': '0.0010',
'a': None
}
]
}
"""
Last updated