Skip to main content
Bitrune implements a constant-product automated market maker on Bitcoin L1. Each pool holds a BTC reserve and a Rune reserve, bound by the invariant x × y = k.

Constant-Product Formula

Every swap preserves k (net of fees). The price of one asset in terms of the other is the ratio of reserves.

Quote Calculation

Given an input amount, the output is computed as follows:
  • fee_bps: pool fee in basis points. Default is 30 (0.3%).
  • Fees remain in the pool reserves. They accrue to liquidity providers proportionally.

Price Impact

Price impact increases with trade size relative to pool depth. A swap that consumes a large fraction of reserve_out will receive a significantly worse rate than the spot price.

Slippage Protection

Every swap accepts a minimum output parameter. The transaction is not constructed if the computed output falls below this minimum. This protects the user from front-running and stale quotes.

LP Mechanics

Liquidity providers deposit both assets into a pool and receive LP shares representing their proportional ownership.

First Deposit

The first depositor sets the initial price ratio.

Subsequent Deposits

Depositing in a ratio that differs from the current reserves results in fewer shares (the excess is a donation to existing LPs).

Withdrawal (Burn)

Burning shares returns a proportional slice of both reserves.

LP-Rune

An on-chain Rune token represents LP shares for pools that have undergone LP-Rune etching. LP-Rune balances are tracked separately from the general balance ledger. LP-Rune tokens can be staked into mining pools to earn BITRUNE rewards.

Protocol Fee (kLast Accrual)

The protocol fee is accrued on every LP mint or burn event. It captures a fraction of the fee growth that occurred between LP events.

Calculation

If root_k > root_k_last (the pool grew from swap fees):

Parameters

The k_last snapshot is updated after every mint or burn. Swap-only activity accumulates growth silently until the next LP event triggers accrual.