Skip to content
Fossa

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.

TypeFields to readPurpose
Globalcouncil, treasury, distributor, usdc_mintGlobal authorities and the accepted USDC mint.
Configquote_mint, enabled, reference_pool, quote_per_usdc_x32, quote_price_timestampApproved quote token and cached launch-price reference.
PoolMints, vaults, reserves, fees, mode, and statusCurve 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.

AccountSeeds
Globalb"protocol"
Quote configurationb"config", quote mint
Poolb"pool", smaller mint, larger mint
Pool authorityb"authority", pool
LP mintb"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

FieldsInterpretation
mint_a, mint_bStored base and quote roles.
vault_a, vault_b, lp_mintAccounts to use in trades and liquidity actions.
reserve_a, reserve_bReal trading reserves in the respective mint’s smallest units.
virtual_a, virtual_bAdditional pricing reserves. Zero after graduation.
protocol_a, protocol_b, creator_a, creator_bAccrued fees excluded from trading reserves.
target_b, minimum_aNet quote target and required remaining base inventory.
initial_baseInitial curve inventory. Model curves start with the 90% curve allocation.
locked_lpLocked LP accounting units. Add these to circulating LP supply for share calculations.
mode, tax_bpsToken mode and public-token transfer-tax rate in basis points.
creator, treasury, distributorCurrent fee and graduation roles stored for this pool.
tax_collectedCumulative public-token tax collected. It does not record holder payouts.
price_cumulative, price_timestampModel-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.