API Reference
Complete reference for all exported functions, types, and constants from the taurusSwap SDK. Organized by module.
@taurus-swap/sdk/math
solveTorusInvariant
function solveTorusInvariant(
poolState: PoolState,
trade: TradeInput
): TradeOutputSolves the torus invariant for the output amount given an input trade. Uses Newton's method for root finding.
- Returns:
TradeOutputwith amountOut, priceImpact, segments - Throws:
InsufficientLiquidityErrorif trade is too large
polarDecompose
function polarDecompose(
reserves: bigint[],
n: number
): { alpha: bigint; normWSq: bigint }Computes the polar decomposition of reserves into α (equal-price component) and ‖w‖² (orthogonal component).
‖w‖² = ∑xᵢ² − (∑xᵢ)²/n
kFromDepegPrice
function kFromDepegPrice(
r: bigint,
depegPrice: number,
n: number
): bigintConverts a user-friendly depeg threshold into the tick parameter k.
depegPrice = 0.99→ 1% depeg alloweddepegPrice = 0.95→ 5% depeg allowed
@taurus-swap/sdk/pool
getSwapQuote
async function getSwapQuote(
poolState: PoolState,
trade: {
tokenInIndex: number;
tokenOutIndex: number;
amountIn: bigint;
}
): Promise<SwapQuote>Computes a swap quote by solving the torus invariant. Handles tick crossings automatically.
computeDepositPerToken
function computeDepositPerToken(
poolState: PoolState,
tick: { r: bigint; k: bigint }
): bigint[]Returns the deposit amount for each token to add a tick with parameters (r, k).
computePendingFees
function computePendingFees(
shares: bigint,
feeGrowth: bigint[],
feeCheckpoints: bigint[],
tickTotalR: bigint
): bigint[]Computes accrued fees for a position using the fee growth formula.
@taurus-swap/sdk/algorand
readPoolState
async function readPoolState(
algodClient: Algodv2,
appId: number
): Promise<PoolState>Reads and decodes all pool state from global state and box storage.
readTickState
async function readTickState(
algodClient: Algodv2,
appId: number,
tickId: number
): Promise<TickState>Reads a specific tick's state from box storage.
readPosition
async function readPosition(
algodClient: Algodv2,
appId: number,
address: string,
tickId: number
): Promise<Position>Reads an LP position and computes pending fees.
buildSwapTransactionGroup
async function buildSwapTransactionGroup(
algodClient: Algodv2,
appId: number,
account: Account | string,
params: {
tokenInIndex: number;
tokenOutIndex: number;
amountIn: bigint;
minOut: bigint;
claimedOut: bigint;
}
): Promise<{ txGroup: Transaction[] }>Builds the atomic transaction group for a swap.
buildAddLiquidityGroup
async function buildAddLiquidityGroup(
algodClient: Algodv2,
appId: number,
account: Account | string,
params: {
r: bigint;
k: bigint;
deposits: bigint[];
}
): Promise<{ txGroup: Transaction[] }>Builds the transaction group for adding liquidity (n ASA transfers + app call).
buildRemoveLiquidityGroup
async function buildRemoveLiquidityGroup(
algodClient: Algodv2,
appId: number,
account: Account | string,
params: {
tickId: number;
sharesToRemove: bigint;
}
): Promise<{ txGroup: Transaction[] }>Builds the transaction group for removing liquidity.
buildClaimFeesGroup
async function buildClaimFeesGroup(
algodClient: Algodv2,
appId: number,
account: Account | string,
tickId: number
): Promise<{ txGroup: Transaction[] }>Builds the transaction group for claiming fees.
@taurus-swap/sdk/types
PoolState
interface PoolState {
n: number;
appId: number;
sumX: bigint;
sumXSq: bigint;
rInt: bigint;
sBound: bigint;
kBound: bigint;
totalR: bigint;
virtualOffset: bigint;
feeBps: number;
feeGrowth: bigint[];
numTicks: number;
reserves: bigint[];
tokenAsas: number[];
tokenDecimals: number[];
}SwapQuote
interface SwapQuote {
amountOut: bigint;
priceImpact: number;
effectivePrice: number;
fee: bigint;
feeBps: number;
ticksCrossed: number;
segments: TradeSegment[];
minOut: bigint;
}Position
interface Position {
shares: bigint;
pendingFees: bigint[];
feeCheckpoints: bigint[];
}TickState
interface TickState {
id: number;
r: bigint;
k: bigint;
state: 'INTERIOR' | 'BOUNDARY';
totalShares: bigint;
effectiveRadius: bigint;
}Constants
// Math constants
export const PRECISION = 1_000_000_000n; // 10^9
export const AMOUNT_SCALE = 1000n;
export const TOLERANCE = 1000n;
// Default values
export const DEFAULT_SLIPPAGE_BPS = 50; // 0.5%
export const MAX_NEWTON_ITERATIONS = 50;
export const MAX_TICK_CROSSINGS = 20;
// Fee defaults
export const DEFAULT_FEE_BPS = 30; // 0.3%