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