Skip to content
Fossa

Program reference

Account types, instruction builders, state transitions, and execution rules.

Program structure

The DEX defines typed accounts, instruction arguments, and handlers. Generated Anchor account types describe account order and permissions. Generated instruction types describe argument encoding.

The Rust examples mirror fossa-dex with its no-entrypoint feature. A different client must preserve the same encoding and account relationships. Program IDs and account definitions must match the target deployment. Source build IDs alone do not establish a verified deployment.

Code areaReference
Account types and address seedsAccounts and addresses
Account records and executed actionsIndexing
Public curve initializationLaunch transactions
Quote-reference calculationLaunch pricing
Exact-input and exact-output tradesBuy and sell transactions
AMM creation and LP accountingLiquidity transactions
Message encoding, signatures, and resultsTransactions

Instruction builder

Use ToAccountMetas for account order and permissions. Use InstructionData for the instruction discriminator and serialized arguments. Both come from the generated Anchor client. Do not replace them with historical opcode bytes.

The developer pages use this shared helper. Their excerpts expect addresses and amounts from the preparation steps on each page. They are building blocks for your application, not scripts that submit transactions automatically.

Generated optional-account placeholders can also encode the client’s declared program ID. Keep that ID aligned with the target deployment when using optional accounts.

Instructions

The programs use typed instruction arguments and account constraints. Amounts use integer token units. One unit is the smallest amount supported by a token’s decimals. One basis point is 0.01%.

InstructionPurpose
initialize_curveCreate a public curve with the fixed supply and selected mode.
initialize_model_curveCreate the council-authorized model curve.
initialize_poolCreate a direct AMM from two deposits.
swapExecute an exact-input trade with a minimum output.
swap_exact_outExecute an exact-output trade with a maximum input.
graduateConvert a funded curve into an AMM.
add_liquidityMint an exact LP amount within input limits.
remove_liquidityBurn LP tokens within output limits.
collect_feesWithdraw accrued protocol or creator fees.
collect_transfer_taxCollect withheld public-token taxes for the distributor.
refresh_quoteUpdate the on-chain launch-price reference.

Swap arguments

SwapArgs contains a_to_b, amount, and limit. Read each pool’s mint_a and mint_b fields to determine token roles. Do not derive stored order from a displayed pair name.

  • For swap, amount is the gross input and limit is the minimum net output. A final curve buy can use less input.
  • For swap_exact_out, amount is the required net output and limit is the maximum gross input.
  • a_to_b = true sends mint A and receives mint B.

The pool address uses the sorted mint pair. Its authority controls the token vaults. Use the generated Anchor instruction and account types for integrations.

Authority boundaries

RoleAuthority
Trader or LP holderSigns spending from their token accounts.
CouncilApproves quote tokens, controls new-launch availability, and updates configured recipients.
Distributor signerAuthorizes graduation after the target is met.
Fee ownerSigns collection of their accrued protocol or creator fees.
Program upgrade authorityCan replace the deployed program’s code.

Disabling a quote configuration blocks new launches. Existing swap and liquidity handlers do not use that flag as a trading pause.

The council can update a pool’s treasury and distributor through update_recipients. Graduation therefore depends on the configured signer’s availability. Program rules can change through an authorized upgrade.

Common errors

The program defines named errors for rejected actions.

ErrorMeaning and next step
StaleQuoteThe launch reference is absent or expired. Refresh it and complete the required observation window.
BuyLimitOne curve buy exceeds 75% of initial supply. Reduce the buy amount.
SlippageA limit, reserve constraint, or available output failed. Obtain a new quote and review your limits.
UnavailableThe pool cannot perform this action in its current state. Check its reserves and graduation state.
UnauthorizedRequired approval or signer is missing. Check configuration and authority accounts.
InvalidAccountAn account does not match the expected mint, owner, address, or state. Rebuild with the correct accounts.
InvalidArgumentAn amount, mode, tax, or parameter is invalid. Check the instruction’s requirements.
InvalidArithmeticAn arithmetic input is invalid. Check units and amounts.