Index DEX data
Identify program accounts, process state changes, and interpret executed trades.
Identify account records
An account record contains its address, owning program, and raw data. The owning program separates DEX state from token-program state. The discriminator at the start of the data identifies the DEX account type.
This function classifies raw records with the generated discriminator constants. Classification alone does not validate an account’s fields or derived address. See account validation.
Process pool state
After validation, Pool supplies the mint pair, vault addresses, reserve accounting, lifecycle, and fee recipients. Integer wrappers expose values through .get().
The projection below receives an already decoded pool. It separates a trading curve, a curve at its target, and an AMM. It does not infer trades from reserve changes. Retain the account address and observation position with the projected values.
Related state
| Derived data | Required state |
|---|---|
| Approved pairs | Global and quote Config. reference_pool identifies the model-price reference. |
| Prices and launch progress | Pool reserves, virtual reserves, status, target, and both mint decimals. |
| Transfer taxes | Both mint owners and the active epoch’s transfer-fee schedules. |
| LP positions | User balances for pool.lp_mint, circulating LP supply, and locked_lp. |
| Token identity | Supported mint metadata and its referenced document. The pool has no name, image, or website field. |
| Backing value | Router model-group state, backing-vault balance, and current model-token supply. |
Mints and token accounts belong to their token program. They are separate records from DEX-owned state. Backing balances are separate from AMM reserves.
Build trade history
Account records describe state. They do not identify every trade. The current DEX source defines no dedicated trade-event format. An executed transaction supplies instruction data, account keys, execution status, and token-transfer results.
- Require successful execution metadata. Missing metadata means the result is unknown.
- Resolve instruction account indices, including loaded addresses.
- Identify instructions whose program ID matches the DEX. Decode their generated discriminators and arguments.
- For
swaporswap_exact_out, map the nestedTradeaccounts to the pool’s stored mints and user accounts. - Interpret
a_to_b = falseas quote-to-base andtrueas base-to-quote. - Associate the executed token transfers with that invocation. Record gross input, net output, token units, signature, slot, and instruction position.
A cross-program invocation (CPI) appears as an inner instruction. Transactions can contain several DEX calls, so the signature alone does not identify one trade. Signature plus outer and inner instruction positions distinguishes those calls.
For a clipped final buy, SwapArgs.amount can exceed executed input. Executed transfers determine volume. Transaction-wide balance changes cannot always separate several swaps. Failed transactions do not contribute successful trade volume.
Interpret state changes
| Instruction | State change to identify |
|---|---|
initialize_curve | New pool, fixed base supply, curve status, and revoked base mint authority. |
initialize_pool | New AMM, two net deposits, and minted LP supply. |
swap, swap_exact_out | Reserve changes, accrued trade fees, and user transfers. |
add_liquidity, remove_liquidity | LP supply changes and proportional reserve transfers. |
graduate | Base burn, cleared virtual reserves, locked LP units, and AMM status. |
collect_fees | Reduced fee counters and transfers to the authorized fee owner. |
collect_transfer_tax | Increased tax_collected and tokens received by the distributor. |
A reserve delta alone does not establish buy volume. Several actions can occur between account observations. Likewise, tax collection does not establish a holder payout.
A slot alone cannot order multiple writes within that slot. Preserve the execution position or account-write ordering supplied with the record. Distinguish provisional records from confirmed state. If a new account format cannot be decoded, treat it as unsupported rather than empty.