> ## Documentation Index
> Fetch the complete documentation index at: https://docs.oneswap.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Types

> TypeScript shapes used by the OneSwap SDK.

## Client options

Options passed to the `OneSwap` constructor.

```typescript theme={null}
interface OneSwapConfig {
  apiKey: string                          // 'sk_live_...' — sent as the x-sdk-key header
  environment?: 'mainnet' | 'devnet'      // default 'mainnet'; the SDK resolves the URL itself
  timeout?: number                        // per-request timeout in ms (default 30000)
}
```

## `CreateSwapArgs`

The argument to `oneswap.swaps.createSwap`.

```typescript theme={null}
interface CreateSwapArgs {
  userRef: string      // your stable id for the end-user (one open swap per userRef at a time)
  inSymbol: string     // token the user deposits, e.g. 'CBTC'
  amountIn: number     // decimal amount of inSymbol to swap
  outSymbol: string    // token to return to the user, e.g. 'HTEST'
  poolId?: string      // pin the pool returned by a quote (SDK 1.3.0+)
  minOut?: number      // optional hard floor on output; below it the swap is refunded
  slippageBps?: number // optional; default 200 (2%)
}
```

When you quote first, pass the quote's `poolId` to `createSwap` so both operations use the same
pool.

## `WaitForSwapOptions`

The optional second argument to `oneswap.swaps.waitForSwap`.

```typescript theme={null}
interface WaitForSwapOptions {
  pollMs?: number    // default 3000
  timeoutMs?: number // default 900000 (15 min)
}
```

## `SwapStatus`

The lifecycle status of a swap. Terminal statuses are `returned`, `refunded`, `expired`, `failed`, and `cancelled`.

```typescript theme={null}
type SwapStatus =
  | 'awaiting_deposit'
  | 'deposit_detected'
  | 'swapping'
  | 'recovering'
  | 'needs_review'
  | 'returned'
  | 'refunded'
  | 'expired'
  | 'failed'
  | 'cancelled'
```

> [!NOTE]
>
> SDK 1.2.0 added `cancelled`, and added `recovering` and `needs_review` to the union — those
> two were always reachable, but were missing from the published type. Both are **non-terminal**:
> the funds are in motion and `waitForSwap` keeps polling. If you `switch` exhaustively over
> `SwapStatus`, you may need new cases.

## `Swap`

Returned by `createSwap`, `getSwap`, and `waitForSwap`.

```typescript theme={null}
interface Swap {
  id: string                    // 'esc_...'
  status: SwapStatus
  poolId: string
  inSymbol: string
  outSymbol: string
  amountIn: number
  minOut: number | null
  depositParty: string          // the Canton party id the end-user must fund
  deadline: string              // ISO timestamp; deposit must arrive before this
  amountOut?: number | null     // set once returned
  senderParty?: string | null   // the party that funded (output is returned here)
  error?: string | null
}
```

| Field | Notes |
| - | - |
| `id` | Swap id, `esc_...`. Store it against your `userRef`. |
| `status` | See [`SwapStatus`](#swapstatus) and the [status reference](https://docs.oneswap.cc/guides/swaps.md#status-reference). |
| `poolId` | The pool the `{ inSymbol, outSymbol }` pair resolved to. |
| `amountIn` | The amount the user must deposit — within **1%** tolerance. |
| `minOut` | The hard output floor, or `null` if none was set. |
| `depositParty` | The Canton party id the end-user sends `amountIn` of `inSymbol` to. |
| `deadline` | ISO timestamp, 60 minutes from creation. Deposit before this or the swap expires. |
| `amountOut` | The returned amount of `outSymbol`; set once `status` is `returned`. |
| `senderParty` | The party that funded the deposit; the output is returned here. |
| `error` | Set when `status` is `failed`. |

## `GetQuoteArgs`

The argument to `oneswap.quotes.get`.

```typescript theme={null}
interface GetQuoteArgs {
  from: string      // symbol of the token you pay with, e.g. 'CC'
  to: string        // symbol of the token you receive, e.g. 'CBTC'
  amount: number    // amount of `from` to swap (positive)
  poolId?: string   // pin a pool instead of resolving from symbols
  walletId?: string // custodial wallet id — adds walletBalanceIn/sufficientBalance
}
```

## `Quote`

A swap quote. Amounts are numbers denominated in the input/output token.

```typescript theme={null}
interface Quote {
  amountOut: number            // expected output in the `to` token
  priceImpactPct: number       // price impact of this trade size, in percent
  networkFeeIn: number         // per-swap network fee carved from the input. Priced with the
                               // settlement fee model when quoting with your SDK key
                               // (feeModel 'deposit'); 0 under the 'prepaid' model
  swapFeeBps: number           // the pool's configured fee, in basis points
  effFeeBps: number            // effective fee after any discount
  discountBps: number          // discount applied to the platform slice, in bps
  newReserveX: number          // pool reserve X after this swap
  newReserveY: number          // pool reserve Y after this swap
  effInput: number             // input actually swapped (amount − networkFeeIn)
  inputCredit: number          // input credited to the pool reserve (effInput − platformFee)
  platformFee: number          // platform slice of the pool fee, in the input token
  lpFee: number                // LP slice of the pool fee, in the input token
  inSym: string                // symbol of the input token
  lpShare: number              // LP share of the pool fee (fraction)
  platformShare: number        // platform share of the pool fee (fraction)
  effectiveFeeRate: number     // effFeeBps as a fraction
  chargedPlatformRate: number  // platform rate actually charged, as a fraction
  walletBalanceIn?: number     // only when walletId was passed: spendable input balance
  sufficientBalance?: boolean  // only when walletId was passed: balance covers `amount`
  feeModel?: 'deposit' | 'prepaid' // how the network fee was priced: 'deposit' (carved from
                               // the input — the model your SDK-keyed quotes use, matching
                               // settlement) or 'prepaid' (fee charged outside the input)
}
```

## `QuoteResult`

What `quotes.get` returns: the [`Quote`](#quote) plus the resolution the SDK did for you.

```typescript theme={null}
interface QuoteResult extends Quote {
  poolId: string  // the pool the pair resolved to
  xToY: boolean   // direction within that pool (true = paying with assetX)
}
```

## `Token`

One entry from `tokens.list()`.

```typescript theme={null}
interface Token {
  symbol: string       // display symbol, e.g. 'CC'
  admin: string        // on-ledger instrument admin party
  id: string           // on-ledger instrument id, e.g. 'Amulet'
  registryUrl?: string // registrar base URL, when the token needs a dedicated one
}
```

## `Pool`

One entry from `pools.list()` (and the `pool` field of [`PoolDetail`](#pooldetail)).

```typescript theme={null}
interface PoolAsset {
  symbol: string
  admin: string
  id: string
}

interface Pool {
  id: string                        // 'rt-...'
  name: string | null
  assetX: PoolAsset
  assetY: PoolAsset
  reserveX: number                  // live reserve of assetX
  reserveY: number                  // live reserve of assetY
  feeBps: number                    // total swap fee in basis points
  totalLpTokens: number
  visible?: boolean
  swapsEnabled?: boolean            // false = liquidity-only mode (quotes/swaps rejected)
  asyncSettlement?: boolean
  lpFeeShare?: number | null
  platformFeeShare?: number | null
  createdAt?: string
  primary?: boolean                 // pools.list() only: the operator-designated default pool
  swaps?: number                    // pools.list() only: settled-swap count
}
```

## `PoolDetail`

What `pools.get(id)` returns.

```typescript theme={null}
interface PoolDetail {
  pool: Pool
  swaps: PoolSwap[]  // full settled-swap history, oldest first
}

// A settled swap as recorded by the backend. Wire shape is the raw ledger row:
// snake_case keys, numeric columns serialized as strings.
interface PoolSwap {
  id: string
  pool_id: string
  at: string              // ISO timestamp
  update_id: string | null
  trader: string
  x_to_y: boolean
  amount_in: string
  amount_out: string
  network_fee_in: string
  swap_fee: string
  new_reserve_x: string
  new_reserve_y: string
}
```

## `PoolTicker`

What `pools.getTicker(id)` returns. Formatted figures are strings; `null` means "not derivable right now".

```typescript theme={null}
interface PoolTicker {
  poolId: string
  pair: string           // e.g. 'CC/CBTC' — assetX/assetY as configured on the pool
  base: string | null    // the asset being priced (e.g. 'CBTC'); null when un-priceable
  pricedVia: string      // how the USD value was derived (e.g. 'CC/USDCx')
  price: { usd: string | null }
  priceChange24h: {
    pct: string | null   // percent change vs ~24h ago; null during warm-up
    from: string | null  // USD price ~24h ago
    to: string | null    // USD price now
  }
  volume24h: {
    usd: string | null   // 24h volume at current USD prices
    swaps: number        // number of swaps in the window
  }
  asOf: string           // ISO timestamp the ticker was computed
}
```

`priceChange24h` fields are `null` until the pool's hourly price history is at least 24h old (warm-up), and `price.usd` is `null` when the pool cannot be USD-priced (e.g. unseeded).

## `PoolPairCandidate`

Carried by `AmbiguousPoolPairError.candidates` when several pools trade a requested pair.

```typescript theme={null}
interface PoolPairCandidate {
  poolId: string
  name: string | null
  assetX: string  // symbol
  assetY: string  // symbol
}
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.