Skip to main content

Client config

interface OneSwapConfig {
  apiKey: string
  timeout?: number
  walletToken?: string | (() => string | Promise<string | undefined> | undefined)
}
Pass Amulet in SDK params when you mean CC (Amulet).

Quote

interface QuoteParams {
  from: string
  to: string
  amount: string
  receiverParty?: string
  poolId?: string
  fromAdmin?: string
  toAdmin?: string
}

interface TrafficCostEstimate {
  bytes: number
  usd: string
  cc: string
  extraTrafficPricePerMb: string
  amuletPrice: string
}

interface Quote {
  inputToken: string
  inputTokenAdmin: string
  outputToken: string
  outputTokenAdmin: string
  inputAmount: string             // gross amount the user sends
  outputAmount: string            // quoted from inputAmountAfterTrafficFee
  rate: string
  priceImpact: string
  fee: number                     // swap fee rate, e.g. 0.01 for 1%
  poolId: string
  expiresIn: number               // seconds
  maxPriceImpact?: number         // server-enforced cap (e.g. 15)
  estimatedTrafficCost?: TrafficCostEstimate
  trafficFeeInInput?: string      // traffic recovery converted into the input token
  inputAmountAfterTrafficFee?: string
}

Pool

interface PoolToken {
  name: string
  admin: string
  reserve: string
}

interface Pool {
  id: string
  tokenA: PoolToken
  tokenB: PoolToken
  fee: number
  lpTokens: string
}

interface PoolDetail extends Pool {
  swapAddress: string
  lpAddress: string
}

interface PoolListResponse {
  count: number
  pools: Pool[]
}

interface PoolStats {
  apr: string
  apy: string
  volume24h: string
  fees24h: string
  lpFees24h: string
  tvl: string
  swapCount24h: number
  aprSupported?: boolean
  aprQuoteToken?: string | null
  aprLookbackDays?: number
}

interface PoolStatsParams {
  days?: number
}

interface Token {
  name: string
  admin: string
}

interface TokenListResponse {
  tokens: Token[]
}

interface AmbiguousPoolCandidate {
  poolId: string
  tokenA: Token
  tokenB: Token
}

interface AmbiguousPoolPairResponse {
  error: string
  code: 'ambiguous_pool_pair'
  candidates: AmbiguousPoolCandidate[]
}
tokenA.reserve, tokenB.reserve, and tvl use effective reserves. Pending platform, developer, and traffic-fee collections are excluded so LP value is not overstated. aprSupported is false when OneSwap cannot value both sides of a pool in a shared quote token honestly. Today that mainly affects pools without a stable-quoted side.

Swap

type SwapStatus =
  | 'pending'
  | 'matched'
  | 'deposit_received'
  | 'forwarded'
  | 'processing'
  | 'sending_output'
  | 'completed'
  | 'slippage_failed'
  | 'price_impact_exceeded'
  | 'insufficient_liquidity'
  | 'insufficient_amount'
  | 'output_failed'
  | 'no_output_holdings'
  | 'failed'
  | 'refund_failed'
  | 'expired'
  | 'cancelled'

interface CreateSwapParams {
  fromToken: string
  toToken: string
  amount: string
  walletAddress?: string
  slippageTolerance?: number
  poolId?: string
  fromAdmin?: string
  toAdmin?: string
  outputAddress?: string
}

interface SwapIntentResponse {
  intentId: string
  poolId: string
  depositAddress: string
  swapAddress: string
  depositReference: string
  inputToken: string
  inputTokenAdmin: string
  outputToken: string
  outputTokenAdmin: string
  expectedAmount: string
  expectedOutput: string | null
  minOutput: string | null
  slippageTolerance: number
  outputAddress: string | null
  expiresAt: string
  instructions: Record<string, string>
}

interface SwapStatusResponse {
  intentId: string
  poolId: string
  status: SwapStatus
  inputToken: string
  outputToken: string
  expectedAmount: string
  expectedOutput: string | null
  actualOutput: string | null
  minOutput: string | null
  slippageTolerance: number
  depositReference: string | null
  outputAddress: string | null
  matchedAt: string | null
  createdAt: string
  expiresAt: string
}

interface CancelSwapResponse {
  success: boolean
}
walletAddress is optional in CreateSwapParams, but if you send it, it must match the wallet token supplied in OneSwapConfig.walletToken. outputAddress is deprecated in CreateSwapParams. Current OneSwap execution resolves swap output back to the same party that made the deposit. depositReference is recommended when your wallet flow supports Canton reason/reference metadata. Standard 1-step sender attribution does not depend on it.

Wallet auth

interface WalletChallengeResponse {
  partyId: string
  nonce: string
  message: string
  expiresIn: number
}

interface VerifyWalletChallengeParams {
  partyId: string
  nonce: string
  signature: string
  publicKey: string
}

interface VerifyWalletChallengeResponse {
  partyId: string
  token: string
}

Track

interface TrackResponse {
  partyId: string
  swaps: TrackSwapItem[]
}

// Track swap items — a subset of SwapStatusResponse
interface TrackSwapItem {
  intentId: string
  poolId: string
  status: SwapStatus
  inputToken: string
  outputToken: string
  expectedAmount: string
  expectedOutput: string | null
  actualOutput: string | null
  matchedAt: string | null
  createdAt: string
  expiresAt: string
}

interface WaitOptions {
  pollInterval?: number
  timeout?: number
}
TrackResponse is swap-only. Liquidity intents and LP positions are website-only and are not returned by the public SDK. Developer earnings, collections, and account analytics stay on the wallet-authenticated OneSwap developer portal instead of the public SDK.

Errors

class OneSwapError extends Error {
  statusCode: number
  response: unknown
}

class AuthError extends OneSwapError {}        // 401
class ValidationError extends OneSwapError {}  // 400
class NotFoundError extends OneSwapError {}    // 404
class RateLimitError extends OneSwapError {}   // 429
class ConflictError extends OneSwapError {}    // 409
class AmbiguousPoolPairError extends ConflictError {
  candidates: AmbiguousPoolPairResponse['candidates']
}
class SlippageError extends OneSwapError {}    // swap refunded
class PriceImpactError extends OneSwapError {}  // price impact exceeded server cap
class InsufficientLiquidityError extends OneSwapError {}
class InsufficientAmountError extends OneSwapError {}
class OutputFailedError extends OneSwapError {}
class SwapFailedError extends OneSwapError {}
class RefundFailedError extends OneSwapError {}
class ExpiredError extends OneSwapError {}     // intent timed out or was cancelled
class ServerError extends OneSwapError {}      // 500
class NetworkError extends OneSwapError {}
class TimeoutError extends OneSwapError {}