A Meteora DAMM v2 SDK example calculated a quote for selling token B, then used that quote's minimum output in a transaction selling token A. The code connected two opposite trades.

I reproduced the resulting failure locally, reported it in issue #119, and submitted PR #120. The fix made the documentation example use one input mint for both the quote and the transaction. It merged on October 27, 2026, UTC.

The interesting part was the failure behind the small edit. The SDK calculated the requested quotes correctly. The example passed a limit from one trade into another, and the program rejected the swap.

Meteora swaps and minimum output

Meteora builds liquidity protocols on Solana. DAMM v2 is an automated market maker: users trade against liquidity in a pool. Its TypeScript SDK, @meteora-ag/cp-amm-sdk, helps applications calculate quotes and construct swap transactions. SDK overview

The pool identifies its two tokens as A and B. Those labels describe the pool's token ordering. The input mint selects which token a particular trade spends: input B means B to A; input A means A to B.

A quote estimates a trade using the supplied pool state and parameters. Its minimum output is the lowest output the transaction may accept after applying the chosen slippage tolerance. The amount belongs to the trade's output token.

For an A-to-B trade, minimumAmountOut is therefore an amount of B. A minimum calculated for B to A is an amount of A. Both can use the same integer representation in code while carrying different meanings.

The affected example used SwapMode.PartialFill. This mode permits execution to stop at the pool's price bounds before spending the whole input budget, while still enforcing the minimum output. That makes the amount limit part of the partial-fill request. DAMM v2 swap modes

The example changed direction between two calls

The original docs.md example used poolState.tokenBMint in getQuote2, but poolState.tokenAMint in swap2. This abbreviated excerpt keeps the fields that caused the mismatch:

ts
const quote = await cpAmm.getQuote2({
  // Other quote parameters omitted.
  inputTokenMint: poolState.tokenBMint,
});

const swap2Tx = await cpAmm.swap2({
  // Other transaction parameters omitted.
  inputTokenMint: poolState.tokenAMint,
  outputTokenMint: poolState.tokenBMint,
  minimumAmountOut: quote.minimumAmountOut,
});

The first call asks how much A a B-to-A trade can receive. The second constructs an A-to-B trade and applies that result as its minimum B output. Original example

A developer copying this flow could receive an ExceededSlippage error even when a quote calculated for the intended trade would allow it to succeed. Reading only the error could send the investigation toward price movement or slippage settings. Here, the first thing to compare was the direction supplied to each call.

Increasing the slippage tolerance would obscure that mismatch. The minimum needs to describe the intended trade before its tolerance can provide useful protection.

Reproducing the mismatch with program execution

I used Bankrun, a local Solana program testing environment, with the repository's checked-in cp_amm.so. The reproduction ran against SDK commit 79ebbfe59a225e641a2f37cd03404f26de1b0c8e.

The pool used two classic SPL tokens, both with six decimals. I deposited 1,000,000,000 raw units of each token, configured a fixed 100-basis-point trading fee, and selected CollectFeeMode.OnlyB, which collects fees in token B. Dynamic fees and referrals were disabled.

One basis point is 0.01%, so the trading fee was 1%. The quote used a 5,000,000,000-unit partial-fill input budget and 50 basis points, or 0.5%, of slippage. Its square-root-price bounds were floor(Q64 × 99 / 100) and floor(Q64 × 101 / 100), where Q64 = 2^64. These were controlled local pool settings. Reproduction configuration

The two quote directions returned different amounts:

Quote directionOutput tokenQuoted output in raw unitsMinimum output in raw units
B to A, as in the original quote exampleA999,999,999994,999,999
A to B, matching the transactionB989,999,999985,049,999

These values are results from the local reproduction. Matching decimals make them easy to compare, but an amount of A still cannot serve as an amount of B merely because both are integers.

The matching A-to-B quote predicted 989,999,999 raw units of B. Passing the reverse quote's integer into minimumAmountOut demanded more than that output:

text
A-to-B quoted output:            989,999,999
Minimum taken from B-to-A quote: 994,999,999

989,999,999 < 994,999,999 → ExceededSlippage

The transaction failed with error 6002, ExceededSlippage. The user token accounts, pool vaults, and pool data remained unchanged after the failed execution.

Using the minimum from the A-to-B quote made the transaction succeed. It credited the user with 989,999,999 raw units of B, above the matching minimum of 985,049,999. Observed quotes, failure, and successful control

Before the fix, a B-to-A quote supplies 994,999,999 as the minimum for an A-to-B swap whose quoted B output is 989,999,999, so it fails. After the fix, the matching A-to-B minimum is 985,049,999 and the swap succeeds, crediting 989,999,999 B units.

The transaction receives an integer limit. The application must ensure that the limit belongs to the correct trade and output token.

This comparison isolated the direction mismatch. The intended swap could execute from the prepared pool state; the reverse quote supplied an incompatible threshold. The program's output check rejected that threshold as instructed.

Define the intended input once

My patch introduced one value:

ts
const inputTokenMint = poolState.tokenAMint;

Both getQuote2 and swap2 then used that value. The transaction retained poolState.tokenBMint as its output mint, so the quote and transaction consistently described A to B. Documentation patch

Sharing the input mint makes the example's intent easier to follow. A reader no longer has to notice that two similar argument lists independently select different sides of the pool.

The contribution changed only docs.md. Validation included 21 existing quote and swap tests, the separate Bankrun reproduction, and TypeScript checking. The Bankrun check matters because it connected the quote values to the program's actual acceptance condition and resulting token balance.

The slippage-unit and quote-signature documentation corrections belonged to another contributor's PR #117. My reproduction used an explicit 50-basis-point setting to isolate direction, and #120 addressed that direction mismatch. Contribution scope and validation

What I check before changing slippage

I now read a quote and its transaction as one trade description. Their pool, input token, output token, mode, amount, and limits need to agree. A plausible number from the quote is useful only if the transaction interprets it the same way.

For this example, the decisive check was small: which token did each call say it was spending? Following that value exposed the error before changing the pool math or loosening the execution limit.

The merged fix makes the example consistent. The local program test explains why that consistency matters: the same intended swap failed with the reverse trade's minimum and succeeded with its own.

✳

Thanks for reading. Keep following your curiosity.

NEXT NOTE ↗

How One Payment Authorized Multiple Jobs in Solana Pay Kit