Get Swap Quote
GET/quotes/swap
Get a quote for swapping tokens when depositing into or withdrawing from a DeFi instrument. Returns the expected output amount, token information, minimum output with slippage protection, and price impact.
Request
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
instrumentId | string | Yes | The target instrument ID |
direction | string | Yes | Either deposit (USDC → token) or withdraw (token → USDC) |
amount | string | Yes | The input amount in raw units (e.g., 10000000 for 10 USDC) |
chainId | number | Yes | Chain ID (e.g., 8453 for Base mainnet) |
Response
Response Fields
| Field | Type | Description |
|---|---|---|
needsSwap | boolean | Whether a swap is required (false if input matches instrument token) |
fromToken | object | Source token information |
fromToken.address | string | Token contract address |
fromToken.symbol | string | Token symbol (e.g., “USDC”) |
fromToken.decimals | number | Token decimals (e.g., 6 for USDC) |
toToken | object | Destination token information |
toToken.address | string | Token contract address |
toToken.symbol | string | Token symbol (e.g., “GHO”) |
toToken.decimals | number | Token decimals (e.g., 18 for GHO) |
amountIn | string | Input amount in raw units |
amountOut | string | Expected output amount in raw units |
minAmountOut | string | Minimum output with 0.5% slippage protection |
priceImpact | string | Price impact as a percentage (e.g., “0.0127” = 0.0127%) |
Notes
- When
needsSwapisfalse, no swap is needed - the input amount equals output amount - The
minAmountOutapplies 0.5% slippage tolerance for transaction protection - Price impact is calculated based on current Uniswap V4 pool liquidity
- Use
toToken.decimalsto format amounts for display (e.g., divide by 10^decimals)
Examples
Deposit Quote (USDC → GHO)
- Input: 10 USDC (10000000 ÷ 10^6)
- Output: ~10.001 GHO (10001276903584562876 ÷ 10^18)
- Price: 1 USDC ≈ 1.0001 GHO
Withdraw Quote (GHO → USDC)
No Swap Needed (USDC instrument)
When depositing USDC into a USDC-based instrument:TypeScript Example
Error Responses
| Status | Error | Description |
|---|---|---|
| 400 | No swap pool configured | No Uniswap V4 pool exists for token pair |
| 400 | Pool is not initialized | Pool exists but has no liquidity |
| 400 | Instrument not found | Invalid instrument ID |