Skip to main content

Swap flow

  1. Create a swap intent specifying input/output tokens, amount, and slippage tolerance.
  2. The SDK returns a depositAddress and expectedOutput.
  3. Deposit the input token to the deposit address on Canton.
  4. OneSwap detects the deposit and executes the swap automatically.
  5. Output token is sent to the user’s wallet (or a specified outputAddress).

Status lifecycle

pendingmatchedcompleted | slippage_failed | expired
  • pending: intent created, waiting for deposit
  • matched: deposit detected on-chain
  • completed: swap executed, output sent
  • slippage_failed: output fell below minOutput, tokens refunded
  • expired: no deposit within 30 minutes

Example

const intent = await client.swaps.create({
  fromToken: 'Amulet',
  toToken: 'USDCx',
  amount: '100',
  slippageTolerance: 0.01
})

// Send tokens to intent.depositAddress on Canton

intent.on('matched', () => console.log('Deposit detected'))
intent.on('completed', (s) => console.log(`Got ${s.actualOutput} USDCx`))

const result = await intent.wait()

Slippage protection

minOutput = expectedOutput × (1 - slippageTolerance)
Tolerance range: 0.001 (0.1%) to 0.5 (50%), default 0.01 (1%).

Liquidity flow

  1. Create an LP intent specifying the pool and amounts for both tokens.
  2. The SDK returns a depositAddress.
  3. Send both tokens to the deposit address (two separate deposits, any order).
  4. OneSwap pairs deposits by sender. Status moves to partial after one token arrives.
  5. Once both are received, LP tokens are minted and credited.

Status lifecycle

pendingpartialcompleted | expired
  • partial: one of two tokens received
  • completed: both tokens received, LP tokens minted
  • expired: deposits not completed within 30 minutes

Example

const intent = await client.liquidity.create({
  poolId: 'Amulet-USDCx',
  amountA: '100',
  amountB: '150'
})

// Send both tokens to intent.depositAddress

intent.on('partial', () => console.log('One token received'))
const result = await intent.wait()

Positions and earnings

// Get LP positions for a user
const positions = await client.positions.list('user-123')

// Get earnings estimate
const earnings = await client.positions.getEarnings('user-123', 'Amulet-USDCx')
console.log(`APR: ${earnings.apr}%, APY: ${earnings.apy}%`)

Pricing model

OneSwap uses constant product pricing:
x × y = k
output = y - (k / (x + input))
A 0.3% fee is deducted from the input before calculation. Fees are split 80% to LPs and 20% to the platform.