Constants

All numeric constants used in taurusSwap, with explanations for why each specific value was chosen.

Math Constants

PRECISION

PRECISION = 1_000_000_000  // 10^9

Fixed-point scaling factor for fee growth and other fractional calculations. Chosen to provide 9 decimal places of precision while avoiding uint64 overflow.

AMOUNT_SCALE

AMOUNT_SCALE = 1000

Divides raw microunit reserves before squaring to prevent overflow. Without this, squaring 50M tokens (5 × 10¹⁰ microunits) would give 2.5 × 10²¹, exceeding uint64 max (1.8 × 10¹⁹).

TOLERANCE

TOLERANCE = 1000

Allowed error margin for invariant checks. Accounts for integer division rounding and AMOUNT_SCALE precision loss.

Fee Constants

DEFAULT_FEE_BPS

DEFAULT_FEE_BPS = 30  // 0.3%

Default swap fee in basis points. Matches Uniswap V3's 0.3% tier for standard volatile pairs.

MAX_FEE_BPS

MAX_FEE_BPS = 1000  // 10%

Maximum allowed fee. Prevents governance from setting exploitative fees.

Trading Constants

DEFAULT_SLIPPAGE_BPS

DEFAULT_SLIPPAGE_BPS = 50  // 0.5%

Default slippage tolerance in the UI. Users can adjust this, but 0.5% is a sensible default for stablecoin swaps.

MAX_NEWTON_ITERATIONS

MAX_NEWTON_ITERATIONS = 50

Maximum iterations for Newton's method when solving the torus invariant. Typically converges in 10-20 iterations; 50 is a safe upper bound.

MAX_TICK_CROSSINGS

MAX_TICK_CROSSINGS = 20

Maximum number of ticks a single swap can cross. Prevents DoS via complex trade recipes. Most swaps cross 0-2 ticks.

Storage Constants

MAX_TICKS

MAX_TICKS = 256

Maximum number of active ticks per pool. Limited by box storage capacity (25 bytes per tick × 256 = 6.4KB).

Box Key Prefixes

TICK_PREFIX = "tick:"
POSITION_PREFIX = "pos:"
TOKEN_PREFIX = "token:"

String prefixes for box storage keys. Used to namespace different data types.

Geometric Constants

√n Cache

const SQRT_N_CACHE = {
  2: 1.4142135623730951,
  3: 1.7320508075688772,
  4: 2.0,
  5: 2.23606797749979,
  // ...
};

Precomputed square roots for common pool sizes. Avoids runtime sqrt calls for constant values.

Equal-Price Point Formula

q = r * (1 - 1 / sqrt(n))

The reserve value at which all tokens trade at parity. For n=5, this is approximately 0.553r.

Summary Table

ConstantValuePurpose
PRECISION10⁹Fixed-point math scaling
AMOUNT_SCALE1000Overflow prevention
TOLERANCE1000Invariant check margin
DEFAULT_FEE_BPS30Default swap fee (0.3%)
DEFAULT_SLIPPAGE_BPS50Default slippage (0.5%)
MAX_NEWTON_ITERATIONS50Solver iteration limit
MAX_TICK_CROSSINGS20Trade complexity limit
MAX_TICKS256Max ticks per pool