# swap — CLI manual

> Terminal CLI that races every major EVM DEX aggregator for a swap quote, ranks by token-out received, and optionally builds calldata, simulates, or hands the tx to a wallet. Single Bun-compiled binary. No daemon, no telemetry. Operator: 9summits.

HTML version: https://swap.9summits.io/docs · Machine index: https://swap.9summits.io/llms.txt · HTTP API: https://swap.9summits.io/openapi.json · Agent skill: https://swap.9summits.io/skills/swap-cli/SKILL.md

```sh
swap 1 WBTC ETH                                  # best quote across every venue
swap 1000 USDC USDT -v all                       # side-by-side comparison block
swap 100 USDC USDT --from 0xYou --simulate       # dry-run, real tokenOut
swap 0.1 WETH USDC --from 0xYou --browser        # sign & send in your wallet
swap                                             # no args: open the local dApp
```

## 01 · Install & setup

```sh
curl -fsSL https://swap.9summits.io/install.sh | bash     # macOS / Linux, arm64 + x64 → ~/.local/bin/swap
swap update                                               # self-update the curl install (no-op when current)
swap --init                                               # prompt for ALCHEMY_API_KEY or an RPC URL → ~/.swap/config
```

Installer env: `SWAP_INSTALL_DIR` (default `~/.local/bin`), `SWAP_INSTALL_BASE` (asset base), `SWAP_NO_PROGRESS=1`.

The public prebuilt binary is **hosted by default**: it quotes and builds through `https://swap.9summits.io/api/*` (`--hosted`), so every venue works with zero key configuration. Building a tx, `--browser` and `max` still need a sender address but no RPC in hosted mode; only `--simulate` and the local-only actions still call your own RPC. Pass `--local` (or set `SWAP_API_DISABLED=true`) to switch to the local engine and your own venue keys (see 10). The first-run RPC prompt only fires on an interactive terminal and only when the run actually needs an RPC; in scripts and agents nothing ever blocks on stdin.

## 02 · Usage & flags

```
swap [options] <amount> <tokenIn> [tokenOut]
```

- `amount` — human units (`1.5`, `0.001`). `max` = the sender's whole balance (needs `--from` + RPC). Denominates **tokenIn**, or **tokenOut** with `--exact-out`.
- `tokenIn` / `tokenOut` — symbol (case-insensitive) or `0x` address. Unknown symbols resolve via KyberSwap → CoinGecko → on-chain `decimals()`. Native gas token: `ETH`, `BNB`, `AVAX`, `HYPE`, `MON`, `XPL`, `POL`, `XDAI` by chain.
- `tokenOut` is optional only with `-a send`.

| Flag | Effect |
|------|--------|
| `-v, --venue <list>` | One venue, a comma list (`kyber,matcha,1inch`), or `all` (default). `--all` = `-v all`. |
| `-c, --chain <alias>` | `eth` (default), `base`, `arb`, `op`, `avax`, `bsc`, `hype`, `unichain`, `robinhood`, `arc`, `monad`, `plasma`, `polygon`, `gnosis`, `ink`. |
| `--slippage <pct>` | Percent; `0.5` = 50 bps. Default `0.1`. Same value drives quote and build. |
| `--from <addr\|alias>` | Sender and recipient. Required for `-d`, `--simulate`, `--browser`, `max`. Falls back to `$SENDER_ADDRESS`. Accepts a wallet alias. |
| `-d, --data` | Build the tx: target, calldata, value, gas params, allowance check, approve tx when needed. |
| `--simulate` / `--simu` | `eth_simulateV1` with a pranked tokenIn balance: approve + swap, actual tokenOut, revert reason. Sync venues only. |
| `--browser` | Local RainbowKit page to connect a wallet and sign/send. Exclusive with `--json` / `-s`. |
| `--allow-async` | Include intent venues (`cow`, `delta`, `uniswapx`, `fusion`, `ophis`). Output is an EIP-712 order, not a tx. |
| `--exact-out` | `amount` is tokenOut to receive; minimise tokenIn. Not for send / wrap / special actions. |
| `-a, --action <name>` | `swap` (default), `send`, `addwallet`, `unwrapwrseth`, `withdrawsparkweth`, `unstakesavax`, `claimsavax`. |
| `--to <addr\|alias>` | Recipient for `-a send`. |
| `--rpc <url>` | Override the RPC for this run (beats every env var). |
| `--json` | One structured JSON object on stdout. |
| `-s, --simple` | Print only the number: `amountOut`, or `amountIn` under `--exact-out`. |
| `--nofee` | Zero the partner fee for this run. Refused in hosted mode (fee policy is server-side); use `--local`. |
| `--leg-venue <venue>` | 9summits fxSAVE exit only: send its fxUSD / USDC swap legs through this aggregator (`kyber`, `velora`, `matcha`, `1inch`, `openocean`, `fynd`) when it quotes them all; otherwise each leg takes its best quote. The 9summits row lists the alternatives (`legs via fynd · also kyber …`). |
| `--velora-methods <list>` | Velora only: comma-separated Augustus v6.2 methods the route must use, e.g. `swapExactAmountIn` for a signer policy that whitelists one selector (`0xe3ead59e`). The chosen method is reported as `contractMethod`. Velora drops out with an error, never silently, when no route fits, when it answers with another method, or when the built calldata's selector is not listed. Unknown names are rejected. dApp: swap settings → Velora methods, one switch per method (all on = no constraint, none = Velora skipped). |
| `--debug` | With `--simulate`: list ERC-20 transfers landing at `REFERRAL_ADDRESS`. |
| `--disableodosrfq`, `--odosnotcompact` | Odos workarounds (venue discontinued; kept for reference). |
| `--hosted` | Quote and build through the hosted API (`https://swap.9summits.io`) instead of the local engine, for this run. No venue key, no RPC (except `--simulate`). Nothing is signed remotely. Mutually exclusive with `--local`. |
| `--local` | Force the local engine for this run even when `SWAP_API_URL` is set. Uses your own venue keys and RPC. |
| `--show-mode` | Print the effective mode (`hosted <base>` or `self-hosted`) on stdout and exit, without quoting. Takes no positional argument; `--hosted` / `--local` alongside it are honoured. |
| `-V, --version` | Print the version and the commit the binary was built from, e.g. `swap 0.1.0 (2c02339, 2026-09-15)`, then exit. Takes no positional argument and makes no network call. A build with no git metadata prints `swap 0.1.0 (unknown build)`. |

## 03 · Quoting

Default action: race every venue in parallel, print the winner (route tree, rate, gas, venue, router, tokens, bold summary). With `-v all` a live comparison block streams below, sorted by guaranteed `amountOut` (Fusion ranks on auction-end `minAmountOut`, shown next to the cote), `★` on the leader. When CoinGecko prices both legs the ranking is net of gas.

```sh
swap 1 WBTC ETH                                  # all venues
swap 1 WBTC ETH -v kyber                         # one venue
swap 1 WBTC ETH -v kyber,matcha,1inch            # subset
swap 1000 USDT USDC --chain bsc                  # another chain
swap 2 WETH stETH --all --allow-async            # include intent venues
swap 5000 USDC PEPE --slippage 1                 # wider tolerance
swap 1 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2 USDC   # address instead of symbol
```

Venues whose API key is missing are skipped under `-v all` (stderr names the missing env vars); selecting one explicitly errors with the signup URL.

## 04 · Build & simulate

`-d` re-quotes with the real sender and prints an **approve tx** block (only when allowance is insufficient) and a **swap tx** block: target, calldata, value, gas. The approval target is the venue's *spender*, which can differ from the tx target.

```sh
swap 100 USDC USDT --from 0xYou -d                            # calldata + allowance check
swap max USDC WETH --from 0xYou -d                            # whole balance
swap 100 USDC USDT --from 0xYou --simulate                    # dry-run
swap 2000 WETH stETH -v all --from 0xYou --simu -d            # compare + simulate + calldata
swap 100 USDC USDT --from 0xYou --simulate --rpc http://127.0.0.1:8545   # local fork
```

`--simulate` appends a **simulation** block: gas used, revert reason, tokenOut actually received. Calldata stays hidden unless `-d` is also passed. Both need an RPC.

## 05 · Browser signing

`--browser` builds as for `-d`, starts a local server on `127.0.0.1:5151` and opens a RainbowKit page: quote summary, Connect Wallet (MetaMask, Rabby, WalletConnect…), a **simulate** button, and a hard block if the connected wallet is not `--from`. The tx hash or order id is reported back to the terminal.

```sh
swap 0.1 WETH USDC --from 0xYou --browser
swap 1 ETH WETH --from 0xYou --browser                          # wrap
swap 100 USDC -a send --to 0xRecip --from 0xYou --browser
swap 2 WETH stETH --allow-async --from 0xYou --browser          # sign an intent order
```

`swap` with no arguments opens the interactive dApp. In hosted mode (the default) this opens https://swap.9summits.io directly in your browser; pass `--local` to start the same dApp server on your machine instead, with your own keys. Set `NO_BROWSER_OPEN=1` to print the URL instead of opening a browser.

## 06 · Exact-out (buy)

`--exact-out`: `amount` is the tokenOut you want; venues are ranked by least tokenIn paid. Native buy paths: `velora`, `matcha`, `uniswap`, `cow`, `ophis`. Sell-only venues are refined as exact-in at the best native pay and must still deliver ≥ the target. A sell-only venue selected alone (`-v kyber --exact-out`) is rejected.

```sh
swap 1 USDC WBTC --exact-out                     # receive exactly 1 WBTC, pay as little USDC as possible
swap 1 USDC WBTC --exact-out --from 0xYou -d
swap 1 USDC WBTC --exact-out -s                  # just the USDC to pay
```

## 07 · Wrap, send & other actions

**Wrap / unwrap** — native ↔ wrapped pair (`ETH↔WETH`, `BNB↔WBNB`, `AVAX↔WAVAX`, `HYPE↔WHYPE`, `POL↔WPOL`, `XDAI↔WXDAI`) skips the venue loop: direct `deposit()` / `withdraw()` on WETH9, no approval. The CLI prints `9summits` on its `venue` / `via` lines and the dApp shows the 9Summits label and mark; `--json` and the API keep `"venue": "wrap"`.

```sh
swap 1 ETH WETH -d --from 0xYou
swap 1 WETH ETH -d --from 0xYou
swap 1 BNB WBNB --chain bsc -d --from 0xYou
```

**Send (`-a send`)** — plain transfer, no DEX. ERC-20 emits `transfer(to, amount)`; native emits a value-only tx. `tokenOut` ignored.

```sh
swap 100 USDC -a send --to 0xRecip --from 0xYou -d
swap 0.5 ETH  -a send --to 0xRecip --from 0xYou --browser
swap max USDC -a send --to treasury --from main          # wallet aliases
```

**Wallet aliases (`-a addwallet`)** — stored in `~/.swap/wallets.json`, usable in `--from` / `--to`.

```sh
swap -a addwallet main 0xYourAddress
swap 1 WBTC ETH --from main -d
```

**Protocol helpers**

| Action | Chain | Builds |
|--------|-------|--------|
| `-a unwrapwrseth` | Base | Kelp wrsETH → rsETH |
| `-a withdrawsparkweth` | Ethereum | Spark spWETH → WETH |
| `-a unstakesavax` | Avalanche | BENQI sAVAX → AVAX `requestUnlock` |
| `-a claimsavax` | Avalanche | Redeem matured sAVAX unlock requests (amount positional ignored) |

## 08 · Loop (Morpho leverage)

`swap loop` opens a leveraged fxSAVE position on Morpho Blue, or adds to an open one, in a single transaction: flash-borrow USDC, turn it into fxSAVE, supply the fxSAVE as collateral, borrow USDC against it, and repay the flash loan with that borrow plus the USDC you bring. It runs on Ethereum (the default), Base, Robinhood, Monad and Arc. This section details `fxsave-usdc` (fxSAVE collateral, USDC loan, LLTV 91.5 %); `--market` also takes 19 other stable markets (`swap loop --help` lists them), which buy the collateral with one aggregator swap from the loan token. Their entry cost cap is also 25 bps of the oracle value, except `pt-fxsave-29oct2026-usdc` at 2 %: its oracle values the PT about 1.6 % under its market price, which lowers its max leverage (about 7.6x instead of 8.6x at the default max LTV). The dApp runs the same engine in its **Loop** tab (Beta).

**Chains and markets.** The 20 aliases are Ethereum markets, each fork-tested. `--market` also takes any other Morpho Blue market id (`0x` + 64 hex) on the chain `--chain` names: Ethereum, `base`, `robinhood`, `monad` or `arc`. Such a market is read from that chain (tokens, decimals, oracle) and from the Morpho API (listing, warnings), its entry is one loan token → collateral swap delivered to the chain's General Adapter, and its build is simulated with `eth_simulateV1` first: a route that reverts or delivers under the plan's floor is rebuilt through the next venue, and the build fails when none passes. Base's Morpho has Ethereum's address, so the same id can name a market on both: an id is only ever read on the chain you pass. Aggregator coverage differs per chain; a pair no venue can deliver to the adapter is refused.

```
swap loop <equity> usdc --market fxsave-usdc --leverage <x> [options]
```

```sh
swap loop 1000 usdc --market fxsave-usdc --leverage 3                                 # plan only
swap loop 1000 usdc --market fxsave-usdc --leverage 3 --from 0xYou -d                 # preflight txs + Bundler3 multicall
swap loop 1000 usdc --market fxsave-usdc --leverage 3 --from 0xYou --simulate         # dry-run, position before/after
swap loop 1000 usdc --market fxsave-usdc --leverage 3 --from 0xYou --browser          # sign & send in your wallet
swap loop max usdc --market fxsave-usdc --leverage 2.5 --from 0xYou --json            # whole USDC balance, JSON
swap loop 0 usdc --market fxsave-usdc --leverage 5 --from 0xYou -d                    # open position → 5x, flash only
swap loop 1000 usdc --market fxsave-usdc --leverage 9 --max-ltv 0.915 --from 0xYou    # past the default max LTV, up to LLTV
```

| Argument / flag | Effect |
|-----------------|--------|
| `<equity>` | USDC you bring, human units. `max` reads the sender's USDC balance. `0` levers up an open position with a flash only. |
| `<token>` | Loan token: `usdc` (or its address). |
| `--market <id>` | Required. A market alias (`swap loop --help` lists the 20, Ethereum only), or any Morpho market id on `--chain`. |
| `--leverage <x>` | Required. `3`, `1.5`, `3x`; at least 1, up to 4 decimals. On an open position, the whole position's target after the loop. |
| `--max-ltv <fraction>` | Max LTV as a fraction (`0.885`). Default LLTV − 3 % (88.5 %). Capped at LLTV (`0.915`): health factor 1, liquidatable as soon as interest accrues. |
| `--slippage-bps <bps>` | Default `10`. Bounds the entry swap's minimum out, and on `fxsave-usdc` the fxSP deposits and the fxSAVE share price. Basis points, not the swap `--slippage` percent. |
| `--chain <chain>` | `eth` (default; `mainnet` and `ethereum` too), `base`, `robinhood`, `monad` or `arc`. Any other chain is refused. |
| `--from`, `-w, --wallet` | Sender (address or alias); the position is opened on it. Falls back to `$SENDER_ADDRESS`. Required for `-d`, `--json`, `--simulate`, `--browser`, `max`. Without a sender the plan ignores any open position. |
| `-d, --data` | Print the preflight txs and the Bundler3 multicall. |
| `--json` | Plan, preflight and tx as one object (it builds, so it needs a sender). Exclusive with `--browser`. |
| `--simulate` / `--simu` | `eth_simulateV1` of approve, authorization and multicall with the sender's USDC balance set to the equity; each step's gas, collateral and borrow after. Exit 1 on a revert. |
| `--browser` | Local page that sends the preflight txs, then the multicall. |
| `--rpc <url>` | RPC of the loop's chain for this run. |
| `--nofee` | Zero the partner fee on the embedded USDC → fxUSD swap. |
| `--hosted` | Refused. Loop always runs on the local engine. |

**Needs your RPC.** Loop reads Morpho, fxSP and Curve directly and builds the bundle locally, even in the hosted-by-default binary (with `SWAP_API_URL` set it prints a note on stderr and runs locally). Every run, a plain plan included, needs an RPC for its chain (see 10); a market resolved from its id also needs one that serves `eth_simulateV1` to build.

**What the transaction does.** On a fresh position the flash is `equity × leverage` USDC and the borrow is `flash − equity`. The multicall is one Bundler3 call to the General Adapter's `morphoFlashLoan`; its callback runs, in order:

1. The flash USDC goes into fxSP, f(x)'s stability pool, through up to two legs: a direct USDC deposit, and a USDC → fxUSD swap whose fxUSD is deposited instead, used only when it pays (see Entry).
2. All fxSP is deposited into fxSAVE (ERC-4626) under a max share price.
3. The fxSAVE is supplied as Morpho collateral for the sender.
4. USDC is borrowed on Morpho (skipped at 1x, where there is no debt).
5. The equity is pulled from the sender's wallet (skipped for 0 USDC). Borrow plus equity repays the flash exactly.

The swap pays its fxUSD to the General Adapter. The adapter hands over exactly the swap's minimum out for a deposit that must succeed, then the rest of the quoted amount for a deposit that is skipped when the swap filled short. Any fxUSD left on the adapter goes back to the sender as fxUSD, so nothing stays on Bundler3 or the adapter. LTV, health factor and liquidation price are computed on the minimum fxSAVE the must-succeed deposits guarantee under the slippage bounds.

**Entry: direct deposit or swap.** fxSP credits deposited USDC at its stable-token price. The engine checks whether the Curve USDC/fxUSD pool's marginal rate beats that credit. If it does, it bisects for the largest amount still worth swapping and keeps the swap only if the gain beats the extra leg's gas (about 170k gas) by a 50 % margin. That amount is then quoted on the aggregators whose transaction can pay the General Adapter (KyberSwap, Velora, 0x/Matcha, 1inch, OpenOcean, Fynd) and on the Curve pool itself. The best output wins, the pool on a tie. The winner is re-quoted and built with Bundler3 as the sender and the General Adapter as the recipient; if no aggregator builds, the swap goes straight through the Curve pool. When the swap does not pay, the whole flash is deposited as USDC. The plan's `entry` row names the choice and the venue.

**Leverage, LTV and health.**

- Leverage is collateral value over equity. LTV is debt over collateral value at the Morpho oracle price.
- Health factor is LLTV / LTV; at 1 the position is liquidatable. Liq. price is the fxSAVE price, in USDC, at which LTV reaches LLTV.
- Max leverage is the highest leverage that stays under max LTV and whose borrow fits the market's available USDC. The plan shows it at the current max LTV and at LLTV; roughly 1 / (1 − max LTV) before entry cost.
- APRs: borrow APY now and after this borrow; fxSAVE APR from 7 days of growth of its value at par (`convertToAssets` × fxSP redeemed with fxUSD and USDC at 1 USD), annualized; Loop APR = (collateral × fxSAVE APR − debt × borrow APY) / equity, negative when the borrow costs more than the yield.
- Refused plans (no tx built): LTV above max LTV (the error gives the max leverage), borrow above available liquidity, fxSP entry cost above 25 bps of the oracle value, `--max-ltv` above LLTV, 0 USDC without an open position, a target leverage that would need an unloop.

**Open position.** When the sender already has collateral or debt on the market, `--leverage` is the target for the whole position after the loop, not the leverage of the new USDC. With C the collateral value, E = C − debt and N the new USDC, the flash is (E + N) × L − C and the borrow is flash − N. The target cannot be below (C + N) / (E + N), the position with N added and nothing borrowed. With `0 usdc` it must be above the current leverage, so a top-up can only lever up. LTV, health, liquidation price and Loop APR are reported for the combined position, and the CLI adds `position` and `after loop` rows.

**Preflight.** The multicall needs two one-time grants, and `-d` prints only the missing ones: a USDC `approve` to Morpho's General Adapter for exactly the equity (none for 0 USDC), and Morpho `setAuthorization(GeneralAdapter1, true)` so the adapter can borrow for the sender. The multicall's `tx.to` is Bundler3 and its `tx.spender` is the General Adapter, the USDC approval target. On the authorization tx, `to` is Morpho and `spender` names the address being authorized; it is not an ERC-20 spender.

**Fees.** The flash carries a fee only when `LOOP_FLASH_FEE_BPS` is set (integer 0–1000, default 0): that share of the flash, in the loan token, goes to `REFERRAL_ADDRESS` inside the callback, and the plan reports it as `fee` / `feeBps` (a *Fees* row in the dApp). The deposits and the borrow carry none. The embedded swap, when used, pays the normal partner fee plus a loop surcharge: `REFERRAL_FEE_BPS` + `LOOP_SWAP_FEE_SURCHARGE_BPS` (default 1 bp, integer 0–1000), capped at 1000 bps, on venues that take a partner fee (KyberSwap, Velora, 0x, 1inch, OpenOcean; not Curve or Fynd). It is 0 on Curve, without `REFERRAL_ADDRESS`, and under `--nofee`. The fee is already inside the quoted fxUSD out.

**Unloop.** `swap unloop` unwinds the sender's Morpho borrow on a Loop chain (`--from` required). Without `--market` it lists that wallet's borrows. With `--market`, pass exactly one of `--leverage <x>` (partial, down to 1x) or `--close` (`--receive collateral` or `loan`). It is local only (`--hosted` is refused) and needs your RPC. The flash fee and the exit-cost cap match the Loop; `--max-exit-cost` raises the cap in the CLI only. On the fxSAVE market the sale also races `fxsave-redeem` (fxSAVE → fxSP → fxUSD + USDC through f(x)'s 1% instant redeem, then aggregator legs); the better net of gas wins, `-v fxsave-redeem` forces it, and the exit-cost cap leaves that disclosed fee out. `--leg-venue <venue>` sends that exit's fxUSD → loan leg through one aggregator when it quotes it (the plan's `legs` line lists the alternatives; dApp: the 9Summits row's "Swap leg via" picker).

**In the dApp.** The **Loop** tab sits next to Swap and Send (`/?action=loop`) and follows the header's chain. On Ethereum the **Market** pill picks one of the 20 markets, grouped by loan token with their LLTV, and links to the market on Morpho; on every Loop chain its search lists Morpho's listed markets of that chain, and a pasted market id or Morpho URL opens that market. The pick rides in the URL with its chain (`/?action=loop&market=pst-pyusd`, `/?chain=base&action=loop&market=0x…`). *You pay* is the market's loan token and starts at the connected wallet's balance of it. The leverage slider moves in 0.1x steps up to the max leverage at LLTV, with the last 5 % of its track in red; past the default max LTV the request sends `maxLtvBps` = LLTV. With an open position the slider reads *Target leverage* and marks *Now*; 0 only levers up. The plan shows the collateral's APR (*Fixed APY* and the maturity for a PT). The left pane draws the path (on `fxsave-usdc`: flash → swap and/or direct USDC → fxSP → fxSAVE → Morpho borrow; elsewhere: flash → swap to the collateral → supply → borrow), the right pane shows the position (collateral, borrow, LTV, leverage, health) as Now → After. **Loop** sends the missing approval and authorization, then the multicall, as one `wallet_sendCalls` batch when the wallet supports it, one at a time otherwise. The terminal button copies the matching `swap loop` command.

**HTTP API.** `POST /api/loop/quote` and `POST /api/loop/build`, on the public host and the local server, take the same body. `chain` is `eth` (or `mainnet`), `base`, `robinhood`, `monad` or `arc`; `market` an alias (Ethereum) or a Morpho market id on that chain. `equity` is in the market's loan-token base units (`"0"` for a top-up), leverage and LTV are in bps; `sender`, `maxLtvBps` and `slippageBps` (default 10) are optional for a quote. `GET /api/loop/markets?chain=<chain>` takes `market=<alias or id>` (the market resolved on the chain, with its APRs) or `q=<text>` (Morpho's listed markets of the chain matching the tokens); without either it lists the 20 Ethereum markets' APRs, and nothing on another chain.

```sh
curl -s https://swap.9summits.io/api/loop/quote -H 'content-type: application/json' \
  -d '{"chain":"eth","market":"fxsave-usdc","equity":"1000000000","leverageBps":30000,"slippageBps":10}'
```

Quote returns the plan, the same object as `swap loop --json` with `preflight` and `tx` null. Build requires `sender` and returns the swap `Payload` with `venue: "loop"`, `approval: null`, an ordered `preflight` list and the `plan`. A refused plan is HTTP 400 with `error` and `maxLeverageBps`. Schemas: https://swap.9summits.io/openapi.json

`POST /api/loop/unwind/quote`, `/api/loop/unwind/quote/stream` and `/api/loop/unwind/build` take `{chain, market, sender, mode, targetLeverageBps?, receive?, slippageBps?, venues?, venue?}`. `sender` is required. `mode` is `partial` (integer `targetLeverageBps` ≥ 10000, no `receive`) or `close` (`receive` `collateral` or `loan`, no target). `curve` is not a sale venue. The API does not accept a max exit cost. Quote returns the unwind plan; the stream is NDJSON (`leg`, `route` / `verror`, then `plan` or `error`); build returns the same `Payload` as the Loop build with `tokenIn` the collateral and `tokenOut` the loan token, plus `plan`. `GET /api/loop/positions?chain=<alias>&sender=<address>` returns that wallet's borrows (`{positions}`), cached 15s in-process, `cache-control: private, no-store`. A refused plan or a bad body is HTTP 400; a Morpho or RPC failure is 502.

| Chain | Morpho Blue | Bundler3 (`tx.to`) | GeneralAdapter1 (approve, authorize) |
|-------|-------------|--------------------|--------------------------------------|
| Ethereum | `0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb` | `0x6566194141eefa99Af43Bb5Aa71460Ca2Dc90245` | `0x4A6c312ec70E8747a587EE860a0353cd42Be0aE0` |
| Base | `0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb` | `0x6BFd8137e702540E7A42B74178A4a49Ba43920C4` | `0xb98c948CFA24072e58935BC004a8A7b376AE746A` |
| Robinhood | `0x9D53d5E3bd5E8d4Cbfa6DB1ca238AEA02E651010` | `0x6478e9393d4C5bB4d53ee881d1DE78786A0344a6` | `0xc5E188541D107e8B79e43478bDE365F1406665D6` |
| Monad | `0xD5D960E8C380B724a48AC59E2DfF1b2CB4a1eAee` | `0x82b684483e844422FD339df0b67b3B111F02c66E` | `0x725AB8CAd931BCb80Fdbf10955a806765cCe00e5` |
| Arc | `0x34CD04070dD72b14E241112F6d83812Df5Af7fCD` | `0x855dbe13C409Df75CAF6a985Cf6993a4D0319Feb` | `0x0AF5BE7BD7B615e94e1d9275414482D028952466` |

`fxsave-usdc` (Ethereum):

| Contract | Address |
|----------|---------|
| fxSAVE (collateral) | `0x7743e50F534a7f9F1791DdE7dCD89F7783Eefc39` |
| fxSP | `0x65C9A641afCEB9C0E6034e558A319488FA0FA3be` |
| USDC (loan) | `0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48` |
| fxUSD | `0x085780639CC2cACd35E474e71f4d000e2405d8f6` |
| Curve USDC/fxUSD | `0x5018BE882DccE5E3F2f3B0913AE2096B9b3fB61f` |
| Market id | `0x17f7ae1b52670010976b3fe41324cbb2b1eb7dd8f492e51764b2828371b86b84` |

## 09 · Venues & chains

| Venue | Kind | Exact-out | Key |
|-------|------|-----------|-----|
| `kyber` | sync | refine | optional `KYBER_API_KEY` |
| `velora` | sync | native | — |
| `matcha` | sync | native | `ZEROEX_API_KEY` |
| `1inch` | sync | refine | `ONEINCH_API_KEY` |
| `curve` | sync | refine | — (needs RPC) |
| `uniswap` | sync | native | `UNISWAP_API_KEY` |
| `openocean` | sync | refine | optional `OPENOCEAN_API_KEY` |
| `fynd` | sync | refine | `FYND_API_KEY` |
| `9summits` | sync | refine | — (needs RPC) |
| `cow` | intent | native | — |
| `ophis` | intent | native | `OPHIS_REFERRAL_CODE` |
| `delta` | intent | refine | — |
| `uniswapx` | intent | refine | `UNISWAP_API_KEY` |
| `fusion` | intent | refine | `ONEINCH_API_KEY` |
| `odos`, `odosv2` | disabled | — | API discontinued 2026-07-30 |

Sync venues return a broadcastable tx. Intent venues return an EIP-712 order you sign and POST off-chain; a solver settles it within the validity window. They require `--allow-async`.

`9summits` is the in-house route. It only quotes USDC → fxSAVE, fxUSD → fxSAVE and fxSAVE → any token on Ethereum; on any other pair it is absent from the race with no error row, and `-v 9summits` exits with "9summits only quotes USDC or fxUSD → fxSAVE, or fxSAVE → any token, on Ethereum". It mints fxSAVE in one Bundler3 multicall. fxUSD goes straight into the f(x) stability pool (fxSP). USDC is split the way `swap loop` splits its deposit. The engine sizes a USDC → fxUSD swap where the Curve USDC/fxUSD pool's marginal rate meets fxSP's USDC credit, keeps it only when the gain beats its gas, and runs it on the best of KyberSwap, Velora, 0x/Matcha, 1inch, OpenOcean, Fynd and the Curve pool itself. The rest of the USDC goes into fxSP directly. All the fxSP becomes fxSAVE for the sender, and any fxUSD the swap delivers above what was deposited goes back to the sender as fxUSD. `tx.to` is Bundler3, `tx.spender` (the approval target) is Morpho's GeneralAdapter1, and `value` is 0. Only the swap leg pays a partner fee, at the leg venue's normal `REFERRAL_FEE_BPS` (0 on the Curve pool); the direct deposit and the mint carry none, and the loop surcharge does not apply. The reverse, fxSAVE → any token (native ETH included) except fxSP, redeems through fxSP's instant redeem and sells the fxUSD and USDC it returns on aggregators only (never the Curve pool), in one multicall. f(x) charges a 1% instant-redemption fee, shown on the row as `Incl. 1% f(x) redemption fee — 1h cooldown avoids it`; ranking is net of gas. Each leg takes its best aggregator by default; the row lists the aggregators that could take every leg with the route's output through each (`legs via fynd · also kyber …`), and `--leg-venue <venue>` (dApp: the row's "Swap leg via" picker) sends the legs through one of them. The route tree shows each leg's own pools, labelled `venue · pool`.

### Availability by chain

Under `-v all` the CLI only races the venues that serve the selected chain; the others are skipped silently. Async venues still need `--allow-async`; `curve` and `9summits` need an RPC, and `9summits` also needs one of its two pairs. ✓ served, · not served. Snapshot of the adapters' chain tables; the live set for a deployment is `GET /api/mode`.

| Venue | eth | base | arb | op | unichain | bsc | avax | hype | robinhood | arc | monad | plasma | polygon | gnosis | ink |
|---|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|:-:|
| `kyber` (sync) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | · |
| `velora` (sync) | ✓ | ✓ | ✓ | ✓ | · | ✓ | ✓ | · | · | · | · | · | ✓ | ✓ | · |
| `matcha` (sync) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ |
| `1inch` (sync) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ | ✓ | · |
| `curve` (sync) | ✓ | ✓ | ✓ | ✓ | · | · | ✓ | · | · | · | · | · | · | ✓ | · |
| `uniswap` (sync) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ | ✓ | ✓ | · | ✓ | · | ✓ |
| `openocean` (sync) | ✓ | ✓ | ✓ | · | · | ✓ | ✓ | · | ✓ | ✓ | · | · | ✓ | ✓ | · |
| `fynd` (sync) | ✓ | ✓ | ✓ | · | ✓ | ✓ | · | · | ✓ | · | · | · | ✓ | · | · |
| `9summits` (sync) | ✓ | · | · | · | · | · | · | · | · | · | · | · | · | · | · |
| `cow` (intent) | ✓ | ✓ | ✓ | · | · | · | · | · | · | · | · | · | ✓ | ✓ | ✓ |
| `ophis` (intent) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ | · | · | ✓ | ✓ | ✓ | ✓ |
| `delta` (intent) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | · | · | · | · | ✓ | · | · |
| `uniswapx` (intent) | ✓ | ✓ | ✓ | · | ✓ | · | · | · | · | · | · | · | · | · | · |
| `fusion` (intent) | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | · | ✓ | · | ✓ | · | ✓ | ✓ | · |
| *venues per chain* | 14 | 13 | 13 | 9 | 9 | 10 | 10 | 2 | 8 | 5 | 5 | 3 | 11 | 7 | 4 |

| Alias | Chain | Native |
|-------|-------|--------|
| `eth` | Ethereum (default) | ETH |
| `base` | Base | ETH |
| `arb` | Arbitrum One | ETH |
| `op` | Optimism | ETH |
| `unichain` | Unichain | ETH |
| `bsc` | BNB Chain | BNB |
| `avax` | Avalanche | AVAX |
| `hype` | HyperEVM | HYPE |
| `robinhood` | Robinhood Chain | ETH |
| `arc` | Arc | USDC |
| `monad` | Monad | MON |
| `plasma` | Plasma | XPL |
| `polygon` | Polygon | POL |
| `gnosis` | Gnosis | XDAI |
| `ink` | Ink | ETH |

## 10 · RPC, keys & config

RPC is needed for `-d`, `--simulate`, `--browser`, `max`, the `curve` venue, unknown-token decimals and every `swap loop` run. Resolution order, first match wins:

1. `--rpc <url>`
2. `RPC_URL_<chainId>` (e.g. `RPC_URL_1`)
3. `<ALIAS>_RPC_URL` (e.g. `ETH_RPC_URL`, `BASE_RPC_URL`)
4. `ALCHEMY_API_KEY` — one key covers every supported chain (free tier is enough)

The CLI has **no public RPC fallback**: missing config is a hard failure naming the exact variable to set. The interactive dApp server last-resorts to the shared PublicNode table when Alchemy and per-chain overrides are unset.

Config precedence: shell env → `.env` in the current directory → `~/.swap/config` (written by `--init`) → values embedded in the binary at build time. Prebuilt binaries ship venue keys and referral settings; your RPC key is always yours.

| Variable | Unlocks |
|----------|---------|
| `ZEROEX_API_KEY` | `matcha` (https://dashboard.0x.org) |
| `ONEINCH_API_KEY` | `1inch`, `fusion` (https://portal.1inch.dev) |
| `UNISWAP_API_KEY` | `uniswap`, `uniswapx` (https://hub.uniswap.org) |
| `FYND_API_KEY` | `fynd` (@fynd_portal_bot on Telegram) |
| `KYBER_API_KEY` | `kyber` API gateway, higher rate limits (optional; from business@kyber.network). `KYBER_SOURCE` / `KYBER_REFERRAL` add on-chain attribution |
| `OPENOCEAN_API_KEY` | `openocean` pro host, higher limits (optional; public host is keyless, 2 rps) |
| `OPHIS_REFERRAL_CODE` | `ophis` (skipped without it) |
| `SENDER_ADDRESS` | default for `--from` |
| `WALLETCONNECT_PROJECT_ID` | WalletConnect in `--browser` (injected wallets work without it) |
| `REFERRAL_ADDRESS`, `REFERRAL_FEE_BPS` | partner fee attribution; `--nofee` zeroes it for one run |
| `NO_BROWSER_OPEN=1` | `--browser` / `swap` start the local server without launching a browser |

### Hosted mode

By default the public binary quotes and builds through `https://swap.9summits.io/api/*` instead of the local venue engine: no venue key and no RPC needed for a plain quote or a `-d` build, and every key-gated venue (1inch, Fusion, Matcha/0x, Uniswap, UniswapX) works out of the box. `--simulate` and the local-only actions (`send`, `unwrapwrseth`, `withdrawsparkweth`, `unstakesavax`, `claimsavax`), and `swap loop`, still run against your own RPC.

Resolution order: `--local` > `--hosted` > `SWAP_API_DISABLED=true` > `SWAP_API_URL` env var > local engine. The public prebuilt binary embeds `SWAP_API_URL=https://swap.9summits.io`. To self-host: pass `--local` for one run, set `SWAP_API_DISABLED=true`, or clear `SWAP_API_URL` (unset it in the shell, `.env`, or `~/.swap/config`), and configure your own venue keys and RPC.

`swap --show-mode` prints which backend the current configuration resolves to, one line on stdout: `hosted https://swap.9summits.io` or `self-hosted`. It never quotes, and `swap --show-mode --local` prints `self-hosted`.

| Variable | Default | Effect |
|----------|---------|--------|
| `SWAP_API_URL` | `https://swap.9summits.io` (embedded in the public binary) | Base URL of the `/api/*` deployment the CLI quotes and builds through. Empty/unset disables hosted mode |
| `SWAP_API_DISABLED` | `false` | `true` forces the local engine with your own keys and RPC even when `SWAP_API_URL` is set, so the embedded URL can be opted out of without clearing it. Accepts `1`/`true`/`yes`/`on` and `0`/`false`/`no`/`off`; any other value is an error |

Hosted specifics: `--nofee` is refused (fee policy is server-side); the offered venue list comes from `GET /api/mode` and omits `curve`; a rate-limited request (429) reports the retry delay; an unreachable API fails loud and suggests `--local` rather than falling back silently; a stale binary whose `apiVersion` no longer matches the deployment fails with `hosted API contract mismatch … run swap update`. No telemetry is added by hosted mode (the CLI still never calls `/done`), but the server does see the caller's IP, the pair, the amounts, and the `--from` address on a build, the same as the web dApp.

## 11 · Output & scripting

- **default** — route tree, rate / gas / venue / router rows, bold summary, live venue comparison under `-v all`.
- **`--json`** — one object. Multi-venue: `best` (venue name), `quotes` (object keyed by venue; each has `amountIn` / `amountOut` as `{raw, human, usd}`, optional `minAmountOut` for Fusion's auction floor, or `{error}`), `chain`, `tokenIn`, `tokenOut`, plus `approval`, `tx`, `order`, `permitTx`, `simulation` when built. Errors: `{"error": "…"}` and exit code 1.
- **`-s` / `--simple`** — just the human-units number: `amountOut`, or `amountIn` under `--exact-out`.

```sh
RATE=$(swap 1 WBTC ETH -s)
swap 1 WBTC ETH --all --json | jq -r '.best'
swap 1 WBTC ETH --all --json | jq '.quotes[.best]'
swap 100 USDC USDT --from 0xYou -d --json | jq -r '.tx.data'
swap 1000 USDC USDT --json | jq -r '.quotes | to_entries[] | select(.value.amountOut) | "\(.key)\t\(.value.amountOut.human)"' | sort -k2 -gr
```

Human-readable output goes to stdout; warnings and progress go to stderr, so `--json` and `-s` pipe cleanly.

## 12 · Unattended use (scripts, CI, agents)

- **Never prompts without a TTY.** The first-run RPC prompt is skipped when stdin or stderr is not a terminal; `--init` exits 1 instead of hanging. `--json` / `-s` also suppress it.
- **Exit codes:** `0` success, `1` any error (message on stderr; with `--json` also `{"error"}` on stdout).
- **Configure via env, not prompts:** `ALCHEMY_API_KEY` (or `RPC_URL_<chainId>`), `SENDER_ADDRESS`, venue keys as needed. A `.env` in the working directory is read too.
- **Set `NO_BROWSER_OPEN=1`** when starting `swap` / `--browser` on a headless machine; the URL is printed to stderr.
- **Local HTTP API:** `swap` (no args) serves the same stateless `/api/*` contract as the public host on `127.0.0.1:5151`, gated by `?id=<sid>` (printed at startup) or ungated with `SWAP_NO_AUTH=1`. Spec: https://swap.9summits.io/openapi.json
- **Public host limits:** per-IP token buckets per minute — quote-class 60, build 12, submit 6, everything else 120; HTTP 429 with `Retry-After` when drained. These calls spend the operator's venue keys: cache, and prefer the NDJSON stream.
- **Safety:** never coerce token decimals to 18; approve `tx.spender`, not `tx.to`; quote and build at the same slippage; never put the quote-only dEaD placeholder in a signed order (CoW stamps the real sender on the reused envelope; other async venues re-quote).

---
Disclaimer: https://swap.9summits.io/disclaimer.html · Contact: contact@9summits.io
