Swap Program (Constant-Product)

The Swap Program is a lightweight constant-product AMM ( x · y = k ) for secondary trading once pools migrate from launchpad (and for any standard pair you list). It holds two SPL token vaults—base and quote—and prices trades along the invariant, applying standard AMM slippage and fees.

TDEXSo3FBwoMeP6gv7abqPQpEQfwd5ArkzmuGqssjtY

Core functions

  • add_liquidity — Deposit proportional amounts of base/quote to mint LP shares representing your share of the pool.

  • remove_liquidity — Burn LP shares to withdraw proportional base/quote (less any accumulated fees already reflected in pool balances).

  • buy — Swap quote → base at the current invariant price (x*y=k) with slippage protection.

  • sell — Swap base → quote at the current invariant price (x*y=k) with slippage protection.

Fees

  • Trades charge a swap fee taken from the input (or output, depending on direction) and left in the pool, benefiting LPs via higher reserves.

  • Exact fee constants and splits are documented per-network in the Utils / Constants page.

Indexing

  • On each buy/sell, the program emits an internal log_trade_internal instruction with structured fields (e.g., trader, pool, base mint, quote mint, amounts) so your indexer can reconstruct swaps reliably.


Last updated