> For the complete documentation index, see [llms.txt](https://docs.orriss.xyz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.orriss.xyz/bin-pricing/lp-accounting.md). Agents can also search and read this documentation through its [MCP server](https://docs.orriss.xyz/~gitbook/mcp).

# LP shares and fees

Value a bin, mint position shares and trace the distribution of input-token fees.

Each position records how many shares its owner holds in each of the pool's 20 bins. A share is a claim on that bin's two token reserves. Two positions can own different percentages of the same bin, and a single position can own different percentages across several bins.

## How a deposit receives shares

For one bin, let `b` be its WSOL balance in lamports, `q` its quote balance in atoms, `p` its execution midpoint in quote atoms per SOL, and `S` its outstanding shares. The program marks the bin to its own midpoint and computes the reserve value **before** adding the deposit.

`V = q + floor(b × p / 1,000,000,000)`

The deposit value `v` uses the same quote-atom unit. A quote-token deposit contributes its number of atoms directly. For a WSOL deposit, multiply the deposited lamports by `p`, divide by one billion and round down.

| Bin before deposit    | Shares minted          |
| --------------------- | ---------------------- |
| No outstanding shares | `s = v`                |
| Existing shares       | `s = floor(v × S / V)` |

The program credits `s` to the position and increases the bin supply to `S + s`. The new position's fraction of that bin is `s / (S + s)`. The depositor supplies a positive minimum share count for every funded bin and zero for each untouched bin. If one funded bin mints fewer than its minimum, the whole deposit fails.

## Example · Deposit SOL into a mixed bin

Suppose the reference is 100 USDC/SOL. Bin 10 has a midpoint of 100.50 USDC/SOL. Prior trading has left **2 SOL and 201 USDC** in the bin. Assume it has 402,000,000 outstanding shares.

| Step                     | Calculation                             | Result             |
| ------------------------ | --------------------------------------- | ------------------ |
| Mark existing inventory  | 2 × 100.50 + 201                        | 402 USDC           |
| Value a deposit of 1 SOL | 1 × 100.50                              | 100.50 USDC        |
| Mint shares              | 100,500,000 × 402,000,000 / 402,000,000 | 100,500,000 shares |
| Compute ownership        | 100,500,000 / 502,500,000               | 20%                |

An immediate withdrawal, before any further activity, returns 20% of the bin's 3 SOL and 201 USDC. The owner receives **0.600000000 SOL and 40.200000 USDC**, worth 100.50 USDC in total at the bin midpoint. A deposit of a single asset can give its owner exposure to both assets as soon as the position opens.

## Where the fees go

Fees are collected in the input token on every fill. Let `F` be the full fee in that token's atoms. The program credits two separate ledgers and keeps the residual in the executing bin.

| Recipient                             | Per-fill amount                  | How it is received                          |
| ------------------------------------- | -------------------------------- | ------------------------------------------- |
| Platform treasury (20%)               | `floor(F / 5)`                   | Claim against the treasury ledger           |
| Pool creator (10%)                    | `floor(F / 10)`                  | Claim against the recorded creator's ledger |
| LPs in the filled bin (nominally 70%) | Remainder after both allocations | Included in the bin's reserves              |

For example, the first fill in the 150 USDC buy incurs a fee of **201,403 micro-USDC**. The treasury earns 40,280, the creator earns 20,140 and LPs retain the remaining 140,983 micro-USDC. The bin's quote balance increases by the 100.500000 USDC used for conversion plus 0.140983 USDC of LP fees. Only owners of shares in this bin participate in that fill. See [Swap execution](https://docs.orriss.xyz/bin-pricing/swap-math.md).

The creator can claim accrued creator fees independently of any LP position. In the terminal’s position view, **Claim pool fees** appears for the connected recipient when its ledger has a positive balance. For LPs, the nominal share is 70% of each fee, plus the residual from rounding the two fixed allocations down. Incoming LP fees increase existing reserves without minting new position shares.

## Withdrawing a position

Closing a position redeems all its shares across all occupied bins. For each bin, let `h` be the position's shares and `S` the current total supply, both measured immediately before withdrawal.

`baseOut = floor(b × h / S)`

`quoteOut = floor(q × h / S)`

The program rounds each token down **in each bin**, then sums the resulting lamports and quote atoms. It removes the redeemed shares and transfers both totals to the owner's token accounts. Rounding remainders stay with the remaining shares. A position that owns the entire supply of a bin receives its entire recorded reserve.

Withdrawal uses the recorded reserves and share supply. It can proceed when the price reference is stale. Closing also returns the lamports held in the position account to the owner. See [Bin pricing](https://docs.orriss.xyz/bin-pricing.md) and [Reference price](https://docs.orriss.xyz/bin-pricing/reference-price.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.orriss.xyz/bin-pricing/lp-accounting.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
