rotateQuotes & swaps

Quotes and Swaps

This guide shows how to get price quotes and execute swaps using the unified SDK (@whetstone-research/doppler-sdk-alpha) across Uniswap V2, V3, and V4 (including Doppler dynamic auctions).

  • Quoting uses the SDK Quoter for V2/V3/V4.

  • Executing swaps uses the Uniswap Universal Router. For convenience, we show examples with the doppler-router helpers used in the demo apparrow-up-right.

Setup

import { DopplerSDK, Quoter, getAddresses, DYNAMIC_FEE_FLAG } from '@whetstone-research/doppler-sdk'
import { createPublicClient, createWalletClient, http, parseUnits } from 'viem'
import { base } from 'viem/chains'

const publicClient = createPublicClient({ chain: base, transport: http(rpcUrl) })
const walletClient  = createWalletClient({ chain: base, transport: http(rpcUrl), account })

const sdk = new DopplerSDK({ publicClient, walletClient, chainId: base.id })
const quoter = new Quoter(publicClient, base.id)
const addresses = getAddresses(base.id)

Quoting

V3: Exact Input (Single Pool)

V3: Exact Output (Single Pool)

V2: Exact Input (Path)

V4 (Dynamic Auctions): Exact Input

For Doppler V4 dynamic auctions, build a poolKey and determine direction with zeroForOne:

Notes:

  • Use your pool’s actual tickSpacing if available from the indexer or hook config.

  • hookData is typically 0x for Doppler swaps.


Executing Swaps (Universal Router)

The SDK exposes addresses for the Uniswap Universal Router via getAddresses(chainId). To build inputs, the miniapp uses doppler-router helpers; you can do the same or craft bytes manually.

Install helpers:

V4 Dynamic Auction: Swap Exact In Single

Tips:

  • For ERC20 inputs, ensure allowance (Permit2 or token approve). See doppler-router getPermitSignature helper.

  • Use a non‑zero minAmountOut based on a prior quote and desired slippage.

V3 and V2 Swaps

The Universal Router also supports V3/V2 swaps. You can:

  • Use the CommandBuilder to add V3/V2 swap commands similarly, or

  • Call the respective pool routers directly (outside the scope of this doc).

The unified SDK’s Quoter covers price discovery for all of V2/V3/V4 regardless of which path you choose for execution.


End‑to‑End Pattern (Demo application)

The doppler-demo-app demonstrates:

Look at src/pages/PoolDetails.tsx for a complete reference implementation.

Last updated