# Bonding Curve Mechanics

## Overview

The bonding curve phase implements the **LMSR (Logarithmic Market Scoring Rule)** pricing model, a mathematically rigorous market maker designed specifically for prediction markets. This mechanism enables permissionless market creation without seed liquidity while providing bounded losses and smooth price discovery.

***

## Pricing Model

### LMSR Formula

The protocol uses the Logarithmic Market Scoring Rule with liquidity parameter `b`:

**Cost Function:**

```
C(q) = b × ln(e^(q_yes/b) + e^(q_no/b))
```

**Price Formulas:**

```
Price(YES) = e^(q_yes/b) / (e^(q_yes/b) + e^(q_no/b))
Price(NO)  = e^(q_no/b) / (e^(q_yes/b) + e^(q_no/b))
```

> \[!IMPORTANT] **Key Property**: Price(YES) + Price(NO) = 1.0 **ALWAYS**. This fundamental invariant ensures market coherence.

### Liquidity Parameter (b)

The `b` parameter controls price sensitivity:

* **Higher b** = More liquidity, less price impact per trade
* **Lower b** = Less liquidity, more volatile prices
* **Default**: `b = bondingTarget / 7` (approximately $143 for a $1,000 target)

### Price Impact Examples

Starting from 50/50 prices with b ≈ $143:

| Action       | Shares Bought | YES Price After | NO Price After |
| ------------ | ------------- | --------------- | -------------- |
| $100 YES buy | \~97 shares   | 55.2%           | 44.8%          |
| $200 YES buy | \~189 shares  | 60.1%           | 39.9%          |
| $500 YES buy | \~420 shares  | 73.5%           | 26.5%          |

***

## Trade Execution

### Buy Order Processing (LMSR)

For a YES purchase of USDC amount `A`:

```
1. Calculate current cost: C_before = b × ln(e^(qYes/b) + e^(qNo/b))
2. Binary search for shares where: C(qYes + shares, qNo) - C_before = A
3. shares = MAX(calculated_shares, A)  ← $1 CEILING
4. qYes += shares
5. vault += A
6. Mint shares to user
```

> \[!TIP] **$1 Ceiling Guarantee**: You always receive at least 1 share per $1 spent. If LMSR price exceeds $1, you still get 1:1. This ensures winners always profit.

### Sell Order Processing (LMSR)

For selling `S` YES shares:

```
1. Calculate current cost: C_before = b × ln(e^(qYes/b) + e^(qNo/b))
2. Calculate new cost: C_after = b × ln(e^((qYes-S)/b) + e^(qNo/b))
3. payout = C_before - C_after (capped at vault balance)
4. qYes -= S
5. vault -= payout
6. Burn shares from user
```

***

## LMSR vs CPMM

| Property               | LMSR                  | CPMM                |
| ---------------------- | --------------------- | ------------------- |
| **Price Sum**          | Always = 1.0          | May drift           |
| **Bounded Loss**       | Yes, for market maker | No inherent bound   |
| **Price Sensitivity**  | Adjustable via `b`    | Fixed by pool ratio |
| **Mathematical Basis** | Information theory    | Uniswap-style       |
| **Prediction Markets** | Designed for          | Adapted from DeFi   |

***

## Fee Structure

| Operation | Fee Rate | Notes           |
| --------- | -------- | --------------- |
| Buy       | **0%**   | No trading fees |
| Sell      | **0%**   | No trading fees |

> \[!NOTE] The bonding phase has **zero trading fees**. Solvency is maintained through the natural dynamics of the LMSR curve. Fees are only collected at graduation (2%).

***

## Early Exit Mechanism

Users may liquidate positions at any time during the bonding phase:

### Exit Dynamics

* **LMSR Payout**: Calculated as decrease in cost function when removing shares
* **First-mover advantage**: Earlier sellers when prices are extreme receive better payouts
* **Vault protection**: Payout limited by available reserves

***

## Bonding Phase Termination

The bonding phase ends under one of two conditions:

### Condition 1: Graduation (Success)

```
VaultBalance >= bondingTarget AND Solvency >= 100% AND each side >= 20%
```

Market transitions to Order Book trading with real transferable ERC-20 tokens.

### Condition 2: Deadline Expiry (Failure)

```
block.timestamp > bondingDeadline AND (Solvency < 100% OR Vault < bondingTarget)
```

Refund mode activates; users claim pro-rata share of vault.

***

## Economic Incentives

| Actor           | Incentive       | Mechanism                           |
| --------------- | --------------- | ----------------------------------- |
| Early buyers    | Lower prices    | LMSR starting at 50%                |
| Large buyers    | Price discovery | Exponential price movement          |
| Arbitrageurs    | Balance markets | Cheap side offers profit            |
| OG Participants | Bonus pool      | Early depositors share excess vault |
| Protocol        | Graduation fees | 2% collected at graduation          |

***

## Mathematical Properties

### Solvency Guarantee

LMSR ensures the market maker's maximum loss is bounded:

```
Max Loss = b × ln(2)
```

This property, combined with the $1 ceiling on share prices, ensures the vault can always cover winning payouts.

### Price Smoothness

Unlike CPMM with its hyperbolic curve, LMSR provides smoother price transitions through the entire probability range (0% to 100%), making it ideal for prediction markets where extreme probabilities are meaningful.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.basecase.gg/core-concepts/bonding-curve.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
