Documentation Index
Fetch the complete documentation index at: https://flashnet-build.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
TradingClient wraps ExecutionClient and handles the full DEX path: pulling assets in from Spark, calling the Conductor swap, and sweeping the output back. One signed intent per swap on the EIP-2612 (useAvailableBalance) and Permit2 paths; two on the default exact approval path (one to approve, one to swap).
Setup
TradingConfig accepts conductorAddress (required), and optional permit2Address, approvalMode, swapGasLimit, approveGasLimit. See Approval modes below.
Swap from Spark balance
The most common flow: input asset is sitting in the user’s Spark wallet, output should land back in the same Spark wallet.useAvailableBalance: true makes the SDK send the Spark transfer to the gateway and bundle the resulting transferId into the same intent that runs the swap. Nothing is expected to sit on the EVM address before or after.
For ERC20 inputs, set assetInSparkTokenId to the Spark-side tokenIdentifier (bech32m form) corresponding to assetInAddress so the SDK can issue the matching Spark transfer. The token contract must implement EIP-2612 Permit (SparkToken does), so no prior on-chain approve is required. The output side never needs a token id — it’s derived from the contract address.
Swap from existing EVM balance
If the assets are already on the Execution side (deposited earlier or held from a previous swap), skipuseAvailableBalance:
Approval modes
The non-useAvailableBalance path needs to authorize the Conductor to pull input tokens. Configure on the TradingClient:
approvalMode | Behavior |
|---|---|
"exact" (default) | Submit a one-off approve(conductor, amountIn) intent before the swap, poll until it lands. Two intents per swap. |
"permit2" | Sign an EIP-712 PermitTransferFrom and pass it to swap*WithPermit2. One intent per swap. Requires permit2Address on TradingConfig (Uniswap canonical is 0x000000000022D473030F116dDEE9F6B43aC78BA3; localnet deploys its own). |
useAvailableBalance path uses EIP-2612 Permit on the SparkToken directly and bypasses both modes.
Slippage
minAmountOut is yours to compute. The SDK does not fetch quotes. Get a quote off-chain (or simulate via a static call) and apply your slippage tolerance:
"0" disables slippage protection. Don’t ship that to production.
Fee tiers
Match the tier of the pool you intend to trade against:| Tier | Use case |
|---|---|
500 | Stablecoin pairs |
3000 | Most pairs |
10000 | Long-tail / volatile pairs |
Integrator fees
PassintegratorFeeRateBps and integratorPublicKey to take a basis-point cut of the swap that the Conductor routes to your Spark address.
What the result tells you
finalized, the output asset has been dispatched back to your Spark wallet. Poll the gateway for status or subscribe to your Spark wallet’s transfer events on the receiving side. See Intents → Status lifecycle for the full lifecycle.
Failure modes
The intent admits but the swap can still revert on-chain. The most common reasons:- Slippage exceeded. Output below
minAmountOut. Tighten or widen the bound and retry. - Pool missing. Wrong
feetier, or the pool hasn’t been created yet. - Insufficient input. The deposit didn’t fund what the swap expected. Recheck
amountInand Spark transfer amount.
statusMessage. Use decodeRevertReason() from @flashnet/sdk to translate it.
Two-intent fallback
For tokens that don’t implement Permit (andapprovalMode: "exact"), the SDK splits the flow into one approval intent followed by the swap intent. You call swap() once and the SDK handles the sequencing. The tradeoff is the time it takes for the approval intent to finalize before the swap fires (typically sub-second on Flashnet sequencer policy, capped at a 30s SDK timeout).
Cross-references
- Conductor reference for raw calldata if you need to call the contract directly.
- Reading state for token info and balance helpers.
- Spark tokens for how Spark assets map to EVM addresses.