Accounts and addresses
Derive PDAs, decode account types, and read reserves, fees, and pool state.
Account types
The DEX owns three account types: Global, Config, and Pool. Token programs own mints and token accounts. Use the generated AccountDeserialize implementation for DEX state. Use the matching token program’s decoder for mints and token accounts.
| Type | Fields to read | Purpose |
|---|---|---|
Global | council, treasury, distributor, usdc_mint | Global authorities and the accepted USDC mint. |
Config | quote_mint, enabled, reference_pool, quote_per_usdc_x32, quote_price_timestamp | Approved quote token and cached launch-price reference. |
Pool | Mints, vaults, reserves, fees, mode, and status | Curve or AMM state for one mint pair. |
Derive addresses
A program-derived address (PDA) comes from seeds and a program ID. Use the DEX deployment’s ID for all derivations below. Sort mint keys by their raw 32 bytes. Base58 string order can differ.
| Account | Seeds |
|---|---|
| Global | b"protocol" |
| Quote configuration | b"config", quote mint |
| Pool | b"pool", smaller mint, larger mint |
| Pool authority | b"authority", pool |
| LP mint | b"lp_mint", pool |
Sorting determines the pool address. It does not determine stored mint_a and mint_b roles. Read those fields from Pool. Vault addresses are stored in the pool. They are caller-supplied token accounts, not DEX vault PDAs.
Decode and validate
Check the account owner before decoding. Validate the discriminator with the generated decoder. Then derive the expected pool address from its stored mints. Also check its authority bump, quote configuration, vault mints, vault authority, and token-program owners.
A discriminator identifies an account type. Global::DISCRIMINATOR, Config::DISCRIMINATOR, and Pool::DISCRIMINATOR describe the current account types. Offsets and discriminator strings from older revisions can differ.
The snippet expects the account’s owner, address, and raw data. The caller handles decoding errors.
Pool fields
| Fields | Interpretation |
|---|---|
mint_a, mint_b | Stored base and quote roles. |
vault_a, vault_b, lp_mint | Accounts to use in trades and liquidity actions. |
reserve_a, reserve_b | Real trading reserves in the respective mint’s smallest units. |
virtual_a, virtual_b | Additional pricing reserves. Zero after graduation. |
protocol_a, protocol_b, creator_a, creator_b | Accrued fees excluded from trading reserves. |
target_b, minimum_a | Net quote target and required remaining base inventory. |
initial_base | Initial curve inventory. Model curves start with the 90% curve allocation. |
locked_lp | Locked LP accounting units. Add these to circulating LP supply for share calculations. |
mode, tax_bps | Token mode and public-token transfer-tax rate in basis points. |
creator, treasury, distributor | Current fee and graduation roles stored for this pool. |
tax_collected | Cumulative public-token tax collected. It does not record holder payouts. |
price_cumulative, price_timestamp | Model-AMM price accumulator and its last update time. |
Read PodU64, PodU128, and other integer wrappers with .get(). Keep exact integers for accounting. A vault can contain accrued fees or unsolicited transfers. Its raw token balance is not the trading reserve.
Lifecycle and price units
status = 0 means curve. status = 1 means AMM. While status is curve, reserve_b < target_b permits trading. At reserve_b == target_b, the curve awaits distributor-authorized graduation. Do not label it as an AMM before status changes.
mode = 0 means standard, 1 means reward, 2 means community, and 3 means model. A direct AMM also uses standard mode. Use target_b and locked_lp to distinguish its liquidity rules from a graduated curve.
A raw B-per-A price ratio is (reserve_b + virtual_b) / (reserve_a + virtual_a). Multiply by 10^(decimals_a - decimals_b) to express whole quote tokens per whole base token.
Despite its field name, Config.quote_per_usdc_x32 stores model-token atoms per USDC atom, scaled by 2^32. The launch target is ceil(8_500_000_000 × quote_per_usdc_x32 / 2^32) quote atoms. Use integer arithmetic. See launch pricing.