1. Pick the pool
A pair can have one pool per fee tier. Use the deepest one:
2. Work out the direction
Direction is defined on the sorted pair: selling token0 is zeroForOne = true.
3. Simulate and quote
simulateSwap makes one node call and returns the tick-by-tick liquidity curve. offlineSwap replays it locally, so you can re-quote nearby amounts without another round trip, as long as the amount doesn’t walk past the last simulated row.
Price before and after:
4. Execute
In ClmmSwapRequest, token0 / token1 mean input / output, not sorted order.
Slippage becomes a sqrtPriceLimitX96: the swap fails if filling the full amount would move the price more than the tolerance. See CLMM: slippage on price.
clmm.swap() requires a full fill. If the price limit is reached before the whole amount is swapped, the transaction reverts with contract error 501 and no tokens move. Retry with a higher slippage or a smaller amount. (swapTo() is different: it stops at the target price and can fill partially by design.)
Multi-hop quotes
To quote A → B → C across two pools in the same fee tier, chain the simulations. The output of hop 1 becomes the exact-in amount of hop 2:
To simulate the whole path in one call, pass data: powfi.clmm.buildSwapPath(C, configIndex) and the second pool’s address in interestedContracts. clmm.swap() executes single-pool swaps only. For multi-hop execution, call the SwapWithoutAccount script from ClmmScripts with the same data.
Swap to a target price
The target must be on the correct side: selling token0 lowers the price, and selling token1 raises it.