COOK N/A
Last Block- HealthChecking Treasury0 COOK Head-
BT--:--
PoSOFF PoW0 H/s Nodes0/0
Gas- COOK
Cookchain Explorer

Cookchain DEX / Pool API

Pool Deploy Documentation

This page describes how third-party providers can create DEX pool templates, add initial liquidity, build swap or liquidity frontends and connect external DEX APIs to Cookchain RPC streams.

Explorer v2026.06.30.25 Pool deploy RPC: https://rpc.ldbl.net

Concept

A Cookchain DEX pool is a pair of two token contracts plus reserves, LP ownership and fee settings. The first liquidity operation creates or initializes the pool state when the target node allows it. Later liquidity and swap calls update the same pair and emit DEX events.

External providers should treat pool deployment like a Solidity router workflow: validate token contracts, convert display amounts to raw units, submit the pool transaction from a backend, then watch the pair streams until the pool appears in the explorer.

Base URLs

Pool Deploy RPChttps://rpc.ldbl.net
Fullnode / Validatorhttp://127.0.0.1:9000
Local nodehttp://127.0.0.1:9000
This explorer proxy/api/* forwards to the configured node

Public DEX apps should call their own backend first. The backend validates input, checks balances and slippage, signs or authorizes the operation, then calls https://rpc.ldbl.net. The fullnode remains the primary chain data source.

Core Endpoints

MethodPathUse
GET/api/dex/pairsList deployed pools and pair metadata.
GET/api/dex/pool?token_a=...&token_b=...Load one pool by token pair.
GET/api/dex/priceRead current DEX price data.
GET/api/dex/liquidityRead liquidity and reserve data.
GET/api/dex/tradesRead recent trades.
GET/api/dex/eventsRead DEX event history.
POST/api/dex/liquidity/addCreate or fund a pool by adding liquidity.
POST/api/dex/liquidity/removeRemove liquidity from a pool.
POST/api/dex/swapSwap one token into another token.
GET/api/stream/pairsServer-sent pair and pool updates.
GET/api/stream/liquidityServer-sent liquidity updates.
GET/api/stream/tradesServer-sent trade updates.
GET/api/stream/pricesServer-sent price updates.

Compatibility paths without /api exist for liquidity and swap on current nodes: /dex/liquidity/add, /dex/liquidity/remove and /dex/swap.

Add Initial Liquidity

Amounts are raw token units. Convert display values with raw = amount * 10^decimals. For a token with 18 decimals, 25.68 display units are submitted as 25680000000000000000 raw units.

curl -X POST "https://rpc.ldbl.net/api/dex/liquidity/add" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_OPERATOR_TOKEN" \
  -d '{
    "token_a": "CoTOKENAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "token_b": "CoTOKENBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
    "amount_a": "1000000000000000000000",
    "amount_b": "25680000000000000000000",
    "lp_owner": "Co1111111111111111111111111111111111111111"
  }'
FieldTypeExpected value
token_astringFirst Cookchain token contract/address.
token_bstringSecond Cookchain token contract/address.
amount_ainteger/stringRaw units for token A.
amount_binteger/stringRaw units for token B.
lp_ownerstringWallet receiving the LP position.

When the pool already exists, the node can reject deposits that do not match the current reserve ratio. Always quote the pool before adding more liquidity.

Swap Request

curl -X POST "https://rpc.ldbl.net/api/dex/swap" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer USER_OR_ROUTER_TOKEN" \
  -d '{
    "token_in": "CoTOKENAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
    "token_out": "CoTOKENBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB",
    "amount_in": "1000000000000000000",
    "trader": "Co2222222222222222222222222222222222222222"
  }'

External routers should calculate expected output and slippage before calling the node. Keep the final user confirmation in display units, but submit only raw units to the RPC.

Realtime Streams

const pairs = new EventSource("https://rpc.ldbl.net/api/stream/pairs");
pairs.onmessage = (event) => {
  const update = JSON.parse(event.data);
  renderPool(update);
};

const prices = new EventSource("https://rpc.ldbl.net/api/stream/prices");
prices.onmessage = (event) => {
  const tick = JSON.parse(event.data);
  updatePrice(tick);
};

Use streams for pool cards, prices, candle builders, route refreshes and explorer-style deploy history without full page reloads.

External DEX API Shape

A hosted DEX provider should expose its own stable public API and keep Cookchain RPC details behind a service layer. This allows templates, custody rules, rate limits and future router logic to change without breaking frontend clients.

GET  /v1/tokens
GET  /v1/pools?limit=20&page=1
GET  /v1/pools/:pairId
POST /v1/pools/quote
POST /v1/pools/deploy
POST /v1/liquidity/add
POST /v1/liquidity/remove
POST /v1/swap/quote
POST /v1/swap/submit
GET  /v1/stream/pools
GET  /v1/stream/trades
GET  /v1/stream/prices
  1. Resolve token contracts through /api/token/info/:contract.
  2. Normalize pair order so the same two tokens always produce one pair id.
  3. Convert every user amount to raw units once and store the conversion.
  4. Check balances, allowance model, pool ratio, fee and slippage server-side.
  5. Submit liquidity or swap calls to https://rpc.ldbl.net.
  6. Persist request id, RPC response, txid, pair id and explorer links.
  7. Subscribe to DEX streams and update your public API cache.

JavaScript Template

function toRaw(amount, decimals) {
  const [whole, fraction = ""] = String(amount).split(".");
  return BigInt(whole + fraction.padEnd(decimals, "0")).toString();
}

async function deployPool(baseUrl, pool, operatorToken) {
  const body = {
    token_a: pool.tokenA,
    token_b: pool.tokenB,
    amount_a: toRaw(pool.amountA, pool.decimalsA),
    amount_b: toRaw(pool.amountB, pool.decimalsB),
    lp_owner: pool.lpOwner
  };

  const res = await fetch(`${baseUrl}/api/dex/liquidity/add`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": `Bearer ${operatorToken}`
    },
    body: JSON.stringify(body)
  });

  if (!res.ok) throw new Error(`pool deploy failed: ${res.status}`);
  return res.json();
}

Explorer Links

  • Pool detail: /explorer/pool/:pairId
  • Token detail: /explorer/token/:contract
  • Contract detail: /explorer/contract/:id
  • Deploy overview: /deploys?tab=pairs&page=1
  • Pool logo metadata can use normal URLs or IPFS gateway URLs, same as token logos.

Security Checklist