Swap CLI
Use fynd-swap-cli to dry-run and execute swaps against a running Fynd server.
fynd-swap-cli is a CLI binary for quoting, simulating, and executing swaps. It's useful for quick testing from the terminal without writing any code.
Setup
Prerequisites:
Docker: install Docker
Tycho API key: get one here
Get the docker-compose.swap.yml file:
curl -o docker-compose.swap.yml https://raw.githubusercontent.com/propeller-heads/fynd/main/docker-compose.swap.ymlStart the server and drop into a shell with fynd-swap-cli pre-installed:
export TYCHO_API_KEY=your_tycho_api_key
docker compose -f docker-compose.swap.yml run --rm fynd-shellThis also starts fynd-serve automatically. Run swaps with:
# Inside the fynd-shell container:
fynd-swap-cliWhen done, stop and remove the server container:
docker compose -f docker-compose.swap.yml downPrerequisites: A running Fynd server — start fynd serve first. See the Quickstart if you haven't.
cargo install --locked --path tools/fynd-swap-cliDry-run a swap (ERC-20)
By default, fynd-swap-cli runs a dry-run: it uses a well-funded sender address and injects ERC-20 storage overrides so the simulation succeeds without any real funds or wallet approvals.
This sells 1 WETH for USDC using the defaults. Pass explicit tokens and amounts to customise:
The output prints the quote (amount_in, amount_out, gas estimate, route) followed by the simulation result.
Dry-run a swap (Permit2)
Add --transfer-type transfer-from-permit2. The dry-run uses nonce 0 and maximum deadlines, so no chain reads are needed.
Execute on-chain (ERC-20)
Add --execute and set PRIVATE_KEY. The CLI checks the router allowance automatically and submits an approval transaction first if one is needed.
Execute on-chain (Permit2)
Add --execute --transfer-type transfer-from-permit2. The CLI checks whether the ERC-20 allowance to the Permit2 contract is sufficient for the swap. If not, it approves the maximum amount so subsequent swaps do not require re-approval. It then reads the current nonce, builds the EIP-712 permit, signs it, and submits the swap.
Swap using vault funds
If tokens are already deposited in the Tycho Router vault, use --transfer-type use-vaults-funds. No ERC-20 approval or Permit2 signature is needed.
CLI Reference
--sell-token
—
WETH (mainnet)
Token address to sell
--buy-token
—
USDC (mainnet)
Token address to buy
--sell-amount
—
1000000000000000000 (1 WETH)
Amount to sell in raw atomic units
--slippage-bps
—
50 (0.5%)
Slippage tolerance in basis points
--fynd-url
FYND_URL
http://localhost:3000
Fynd server URL
--transfer-type
—
transfer-from
transfer-from, transfer-from-permit2, or use-vaults-funds
--execute
—
false (dry-run)
Submit the swap on-chain. Requires PRIVATE_KEY.
--permit2
—
0x000000000022D473030F116dDEE9F6B43aC78BA3
Permit2 contract address
--rpc-url
RPC_URL
https://reth-ethereum.ithaca.xyz/rpc
Ethereum RPC endpoint (must support eth_call state overrides)
Security Notes
Never expose your private key. Use the
PRIVATE_KEYenvironment variable, never a CLI argument. Rununset HISTFILEbefore setting it to prevent it from being saved to your shell history.Dry-run first. The default mode (no
--execute) simulates the full swap with storage overrides — no funds needed. Confirm the output looks correct before adding--execute.Slippage protection. The default 0.5% slippage may not be sufficient for large trades or volatile markets. Adjust
--slippage-bpsaccordingly.Mainnet warning.
--executemay send multiple transactions (approval + swap). Start with small amounts. All routes execute through the Tycho Router contract.Verify routes. The CLI prints the full route before executing. Multi-hop routes through low-liquidity pools can result in worse execution.
Prices are indicative. Quotes reflect the best route at query time but are not guaranteed on-chain. Pool states change every block, and the longer you wait to execute, the more the price may drift.
Troubleshooting
"Solver is not healthy": Wait for the solver to finish loading market data. Check the fynd serve terminal for progress, or poll curl http://localhost:3000/v1/health.
"Sell/buy token not found": Ensure the token address is correct and the token exists on Tycho's indexer.
"No route found": Fynd couldn't find a path between your tokens. Check that both tokens have enough on-chain liquidity.
Last updated