> 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/program-reference.md). Agents can also search and read this documentation through its [MCP server](https://docs.orriss.xyz/~gitbook/mcp).

# Program reference

Identify pool accounts, read bin state and reproduce a direct quote using integer token amounts.

The program holds inventory in two SPL Token vaults owned by a program-derived address (PDA). Pool state assigns that inventory to bins and tracks amounts owed to the creator and treasury. Each LP position records its own share count in each bin.

## Identify a pool

For the configured SOL/USDC market, read `GET /api/config` on the terminal origin. Use the nested `liquidity.cluster`, `liquidity.program`, `liquidity.pool` and `liquidity.quoteMint` fields. For a mainnet integration, require `liquidity.enabled`, `liquidity.cluster == "mainnet-beta"`, and the canonical USDC mint. Verify the account owner, discriminator and PDA on that cluster. The terminal’s **Pool ↗** link is another way to inspect the selected account.

| Account                | Seeds or identity                                                 | Contents                                                              |
| ---------------------- | ----------------------------------------------------------------- | --------------------------------------------------------------------- |
| Pool PDA               | UTF-8 `pool`, quote mint bytes                                    | Reference, observation metadata, 20 bins, active index and fee ledger |
| Position PDA           | UTF-8 `position`, pool, owner, nonce as eight little-endian bytes | Pool, owner, nonce and 20 bin share counts                            |
| Token vaults           | Associated token accounts for the pool PDA and each mint          | WSOL and quote-token balances, including accrued fixed fee shares     |
| Funded market term PDA | UTF-8 `oracle-term`, pool                                         | Signed 64-bit Unix expiry timestamp                                   |

**WSOL mint** · `So11111111111111111111111111111111111111112` (9 decimals)\
**USDC mint** · `EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v` (6 decimals)

## Read-only requests

| Request on the terminal origin                                        | Result                                                                                                               |
| --------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `GET /api/liquidity/pool`                                             | Configured pool, source slot, observation time, active step, fee bps, reserves and shares per bin                    |
| `GET /api/liquidity/quote?input=USDC&amount=150000000&slippageBps=50` | Exact-input pool quote for spending 150 USDC with 0.50% tolerance, when the configured pool has sufficient liquidity |
| `GET /api/liquidity/positions?address=<wallet>`                       | Positions for the owner in the selected pool                                                                         |
| `GET /api/liquidity/funded-positions?address=<wallet>`                | Open funded-market positions for the same owner                                                                      |

Parse `inAmount`, `outAmount`, `otherAmountThreshold` and `expectedPriceMicro` as integers. Keep all calculations in atomic units until display. The quote response gives an estimate against a particular state. A later transaction can only settle under its own minimum-output and expected-price constraints. In funded pools the raw price field is quote-token atoms per SOL even though the field name includes “Micro”. [Reference prices](https://docs.orriss.xyz/bin-pricing/reference-price.md)

## Binary layout

All multibyte integer fields are little-endian. The current pool account is 681 bytes with discriminator `ORRPOOL1`. A 617-byte pool has the common prefix and no fixed-fee ledger. Decode its inventory and positions using the common prefix. Swaps require the fee-ledger migration.

| Byte offset        | Pool field                                                                     |
| ------------------ | ------------------------------------------------------------------------------ |
| 8, 40, 72          | Quote mint, external source, publisher (32 bytes each)                         |
| 104, 112, 120, 128 | Price u64, source slot u64, observed Unix time i64, update slot u64            |
| 136 + 24 × i       | Bin i, three u64 values in order: WSOL atoms, quote atoms, total shares        |
| 616                | Active bin index u8 (0–19). The API’s displayed step is index − 10.            |
| 617                | Creator public key (32 bytes)                                                  |
| 649, 657, 665, 673 | Treasury WSOL, treasury quote, creator WSOL, creator quote, all in token atoms |

A position is 240 bytes. Its discriminator is `ORRPOS01`, followed by the pool and owner public keys, the u64 nonce and 20 u64 share counts. A wallet can hold multiple positions in the same pool by using distinct nonces.

## Instructions

| Tag | Operation                                        | Data after the one-byte tag                                                                           |
| --- | ------------------------------------------------ | ----------------------------------------------------------------------------------------------------- |
| 0   | Initialize canonical pool                        | Empty                                                                                                 |
| 1   | Refresh reference                                | Direct source uses empty data. The signed path supplies price u64, source slot u64 and Unix time i64. |
| 2   | Deposit into a new position                      | nonce, expected price, 20 token amounts, 20 minimum shares, all u64                                   |
| 3   | Withdraw and close position                      | nonce u64                                                                                             |
| 4   | Exact-input swap                                 | direction u8 (1 buys SOL, 0 sells SOL), input u64, minimum output u64, expected price u64             |
| 5   | Initialize funded market and first position      | Same data shape as tag 2, with additional mint, service, reference and term accounts                  |
| 6   | Initialize fee ledger on an eligible legacy pool | Verified creator public key, 32 bytes                                                                 |
| 7   | Claim creator or treasury balance                | Empty. The signer must be the corresponding recipient.                                                |

For a direct SOL/USDC swap, pass accounts in this order: trader signer, pool, trader WSOL account, trader USDC account, pool WSOL vault, pool USDC vault, SPL Token program, read-only source Whirlpool. A funded market uses its stored signed price and omits the final Whirlpool account.

For indexers, successful program logs include `ORR_OPEN`, `ORR_FILL` and `ORR_EXIT`. A single swap can emit multiple bin fills. Count successful tag 4 instructions in settled transactions to measure swaps. Multiple swaps can share a transaction. Aggregate their constituent fills to measure bin activity.


---

# 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/program-reference.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.
