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 area | Reference |
|---|---|
| Account types and address seeds | Accounts and addresses |
| Account records and executed actions | Indexing |
| Public curve initialization | Launch transactions |
| Quote-reference calculation | Launch pricing |
| Exact-input and exact-output trades | Buy and sell transactions |
| AMM creation and LP accounting | Liquidity transactions |
| Message encoding, signatures, and results | Transactions |
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%.
| Instruction | Purpose |
|---|---|
initialize_curve | Create a public curve with the fixed supply and selected mode. |
initialize_model_curve | Create the council-authorized model curve. |
initialize_pool | Create a direct AMM from two deposits. |
swap | Execute an exact-input trade with a minimum output. |
swap_exact_out | Execute an exact-output trade with a maximum input. |
graduate | Convert a funded curve into an AMM. |
add_liquidity | Mint an exact LP amount within input limits. |
remove_liquidity | Burn LP tokens within output limits. |
collect_fees | Withdraw accrued protocol or creator fees. |
collect_transfer_tax | Collect withheld public-token taxes for the distributor. |
refresh_quote | Update 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,amountis the gross input andlimitis the minimum net output. A final curve buy can use less input. - For
swap_exact_out,amountis the required net output andlimitis the maximum gross input. a_to_b = truesends 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
| Role | Authority |
|---|---|
| Trader or LP holder | Signs spending from their token accounts. |
| Council | Approves quote tokens, controls new-launch availability, and updates configured recipients. |
| Distributor signer | Authorizes graduation after the target is met. |
| Fee owner | Signs collection of their accrued protocol or creator fees. |
| Program upgrade authority | Can 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.
| Error | Meaning and next step |
|---|---|
StaleQuote | The launch reference is absent or expired. Refresh it and complete the required observation window. |
BuyLimit | One curve buy exceeds 75% of initial supply. Reduce the buy amount. |
Slippage | A limit, reserve constraint, or available output failed. Obtain a new quote and review your limits. |
Unavailable | The pool cannot perform this action in its current state. Check its reserves and graduation state. |
Unauthorized | Required approval or signer is missing. Check configuration and authority accounts. |
InvalidAccount | An account does not match the expected mint, owner, address, or state. Rebuild with the correct accounts. |
InvalidArgument | An amount, mode, tax, or parameter is invalid. Check the instruction’s requirements. |
InvalidArithmetic | An arithmetic input is invalid. Check units and amounts. |