Protocol · Swap

Swap Tokens

Trade any ThiChain token pair with karma-adjusted fees and quantum-safe settlement on ThiChain L1.

Base Fee 30 BPSGuardian Fee 0 BPSSettlement ~2 seconds

How Swaps Work

QuantumDEX swaps use the constant product AMM formula (x · y = k) implemented in QuantumPair.sol. Every token pair has its own liquidity pool. The QuantumRouter routes your swap through the optimal path and handles all token approvals.

Swap Flow

  1. You approve the QuantumRouter to spend your input token
  2. Router calls swapExactTokensForTokens() or swapTokensForExactTokens()
  3. The KarmaOracle precompile (0x0421) is consulted to determine your fee tier
  4. Fee is deducted, remaining tokens swap through the x·y=k invariant
  5. Output tokens arrive in your wallet in the same ThiChain transaction (~2 second block time)

Karma Fee Tiers

Your fee is determined by your wallet's on-chain Karma Score, computed by the ThiChain Dharmic Validator:

TierKarma ScoreFeeNotes
Visitor0–25030 BPS (0.30%)Default for new wallets
Practitioner251–75015 BPS (0.15%)Achieved through constructive on-chain behaviour
Guardian751+0–15 BPS (scaled)High-karma wallets approaching zero-fee trading
Karma Score is earned, not bought. It reflects your history of honest, non-harmful transactions on ThiChain. It is separate from QBIT token holdings.

Price Impact

Price impact increases with trade size relative to pool liquidity. QuantumDEX shows estimated price impact before you confirm. As a guideline:

  • < 0.5% — Excellent liquidity. Proceed normally.
  • 0.5% – 2% — Moderate impact. Consider splitting the trade.
  • > 2% — High impact. QuantumDEX will warn you before confirmation.

Slippage Tolerance

The minimum amount you are willing to receive is set via the amountOutMin parameter in swapExactTokensForTokens(). The default UI slippage tolerance is 0.5%. You can adjust this in Settings before swapping.

// Example: Swap 100 USDC for at least 99.5 THI (0.5% slippage)
await router.swapExactTokensForTokens(
  parseUnits("100", 6),   // amountIn (USDC)
  parseUnits("99.5", 18), // amountOutMin (THI)
  [USDC_ADDRESS, THI_ADDRESS],
  userAddress,
  deadline
);

SDK Example

import { QuantumDEXClient } from '@qubismic/quantumdex-sdk';
import { createWalletClient, http } from 'viem';
import { thichain } from '@qubismic/quantumdex-sdk/chains';

const client = new QuantumDEXClient({
  chain: thichain,          // Chain ID 420420
  transport: http('https://rpc.thichain.io'),
  walletClient: myWalletClient,
});

// Get best swap route
const route = await client.getSwapRoute({
  tokenIn:  '0x...USDC',
  tokenOut: '0x...THI',
  amountIn: parseUnits('100', 6),
});

console.log('Karma fee tier:', route.karmaTier);     // 'PRACTITIONER'
console.log('Fee BPS:', route.feeBps);               // 15
console.log('Expected output:', route.amountOut);

// Execute swap
const tx = await client.executeSwap(route, {
  slippageTolerance: 0.005,   // 0.5%
});

console.log('TX hash:', tx.hash);

See the full SDK Documentation for all available methods.