Architecture
This page shows how the widget, API, wallet adapter, and settlement layers fit together.
System Overview
Data Flow
1. User Interaction → Quote
- User selects tokens and amount
- SDK sends
POST /v1/quotesto the API - API returns route options from available providers
- SDK displays routes in the UI
onQuoteReceivedcallback fires
2. Route Selection → Build
- User selects a route
- SDK sends
POST /v1/deposit/build - API returns wallet actions (approve + transfer)
- SDK prepares transaction for wallet signing
3. Wallet Signing → Submit
- SDK passes transaction to the Wallet Adapter
- Adapter calls the wallet (MetaMask, Phantom, etc.)
- User signs in the wallet popup
- SDK receives
txHash - SDK sends
PUT /v1/deposit/submitwithtxHash - API creates the order and begins tracking
4. Order Tracking → Completion
- SDK polls
GET /v1/orders/:address - Progressive polling — 1s → 2s → 3s → 5s → 10s intervals
- API returns order status updates
- SDK updates the UI (tracking progress bar)
- Order reaches
filledstatus - The matching success callback fires (
onSwapSuccessforEXACT_INPUT,onDepositSuccessforEXACT_OUTPUT)
Wallet Adapter Layer
Shadow DOM Isolation
Each widget instance creates its own Shadow DOM:
Styles inside the Shadow DOM don't leak out, and page styles don't leak in. The supported customization paths are CSS custom properties (--tf-*) and the setCustomColors() runtime method.
Caching Architecture
A single TanStack Solid Query QueryClient backs the SDK. It caches:
- Chain list (
GET /v1/chains) - Token metadata
- Wallet balances
- Quote responses
The QueryClient is shared across widget instances for the lifetime of the page. destroy() unmounts the widget instance and clears its DOM, but it does not clear the shared query cache. Multiple widget instances on the same page deduplicate API requests automatically.