> ## Documentation Index
> Fetch the complete documentation index at: https://getequity.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Solana — Trading

> The rwa_market instructions you call to quote, buy, sell, and redeem RWA tokens on Solana.

You trade by calling **`rwa_market`** instructions, reading the price from the **`Asset`**
account and the settlement mint from the token's **`TokenMeta`**. The full IDL JSON files
(loadable with Anchor's `Program`) are the ground truth; below is the trader-facing
subset. All prices are **integer USD cents** (`price_cents`).

## Read the price — `Asset` account

The `Asset` PDA (`["asset", mint]`) holds everything you quote against:

```
Asset {
    mint, vault, payout_mint, price_cents, fee_bps,
    is_active, max_per_tx, max_per_user, ...
}
```

* `price_cents` — USD cents per whole token.
* `fee_bps` — fee in basis points taken off your trade.
* `is_active` — whether trading is currently enabled.
* `max_per_tx` / `max_per_user` — trade-size caps (`0` = unlimited).

## Trade — `buy` / `sell`

| Instruction | Args | Notes |
| - | - | - |
| `buy` | `amount: u64, max_cost: u64` | You pay payout → vault; vault → you RWA. `max_cost` = slippage guard. |
| `sell` | `amount: u64, min_proceeds: u64` | You deliver RWA → vault; vault → you payout. `min_proceeds` = slippage guard. |

Trades are **non-custodial** — your wallet signs, and the vault side moves automatically
via a pre-authorized delegate. Both `buy` and `sell` use the same `Trade` account
context:

* `trader` (signer) — your wallet
* `asset` PDA — `["asset", mint]`
* `rwa_mint`, `payout_mint`
* the **vault's** RWA + payout token accounts (ATAs owned by the vault PDA)
* **your** RWA + payout token accounts (ATAs)
* both token programs (SPL Token + Token-2022)

### Trade math

The amounts are computed in `u128`, against the **accrued** price rather than the stored
`price_cents` (see below):

```
price    = current price at cents x 1e18        // see "Reading the accrued price"
proceeds = amount * price * 10^payout_dec / (100 * 10^rwa_dec * 1e18)
fee      = proceeds * fee_bps / 10_000
```

On a buy you pay `proceeds + fee` (capped by `max_cost`); on a sell you receive
`proceeds - fee` (floored by `min_proceeds`).

### Reading the accrued price

Interest is not paid out — it accrues into the price, every second, at the asset's annual
rate. Everything needed to compute it is on the `Asset` account, so there is **no oracle
program to call**:

| Field | Meaning |
| - | - |
| `checkpoint_price_scaled` | base price at cents x 1e18 |
| `checkpoint_at` | unix seconds the base was taken; accrual runs from here |
| `rate_bps` | signed annual rate; 0 = no accrual |
| `maturity_ts` | accrual stops here; 0 = perpetual |

```
elapsed = min(now, maturity_ts or now) - checkpoint_at
price   = checkpoint_price_scaled
        + checkpoint_price_scaled * rate_bps * elapsed / (10_000 * 365 days)
```

Simple interest pro-rated by the second — it does not compound between checkpoints.

> [!WARNING]
>
> **Do not read `price_cents` and stop there.** It is only rewritten when a checkpoint is
> taken, so between checkpoints it is both **stale** and **rounded to whole hundredths**.
> On a low-priced asset it can sit unchanged for weeks while the real value accrues. Use
> the formula above.

An on-chain program can skip the arithmetic entirely by depending on the `rwa_market`
crate and calling `rwa_market::current_price_scaled(&asset, now)` — the same function every
pricing path inside the program uses.

## Read the settlement token — `TokenMeta`

Before trading, read `payout_token` (and `decimals`) from the token's `TokenMeta` PDA
(`["meta", mint]`) so you know which mint you're spending/receiving and how to scale
amounts.

## Redemption — `rwa_exit.claim`

At end-of-life the asset admin freezes a final price and opens claims. Redemption is
**claim-based — you pull your principal**:

| Instruction | Args | Notes |
| - | - | - |
| `claim` | `amount: u64` | Burns your RWA and pays `final_price_cents * amount` (pro-rata) from the escrow. |

The `ExitState` PDA (`["exit", mint]`) exposes `final_price_cents`, `initiated`, and
`completed` so you can check whether claiming is open. Payout math matches trading:
`amount * final_price_cents * 10^payout_dec / (100 * 10^rwa_dec)`.

## Download the IDLs

The IDL JSON files are the complete, machine-readable contract surface — the ground
truth for every instruction, account, and type. Download the ones you need and load them
with Anchor's `Program`. Each program id is embedded in the IDL's `address` field, so you
don't need to hard-code it.

> [card] [rwa\_market.json](https://getequity.io/docs/idl/rwa_market.json)
>
> Trading — `buy` / `sell`, the `Asset` account.

> [card] [rwa\_token.json](https://getequity.io/docs/idl/rwa_token.json)
>
> Asset terms & the `TokenMeta` account (`payout_token`, decimals).

> [card] [rwa\_exit.json](https://getequity.io/docs/idl/rwa_exit.json)
>
> Redemption — `claim`, the `ExitState` account.

> [card] [rwa\_vault.json](https://getequity.io/docs/idl/rwa_vault.json)
>
> The vault accounts a trade touches.

> [card] [rwa\_venue.json](https://getequity.io/docs/idl/rwa_venue.json)
>
> Market-making pools — `create`, `request_redeem`, `set_quote` (devnet only).

> [!TIP]
>
> Direct links: [rwa\_market.json](https://getequity.io/docs/idl/rwa_market.json) ·
> [rwa\_token.json](https://getequity.io/docs/idl/rwa_token.json) ·
> [rwa\_exit.json](https://getequity.io/docs/idl/rwa_exit.json) ·
> [rwa\_vault.json](https://getequity.io/docs/idl/rwa_vault.json) ·
> [rwa\_automation.json](https://getequity.io/docs/idl/rwa_automation.json) ·
> [rwa\_venue.json](https://getequity.io/docs/idl/rwa_venue.json)

## Loading the IDL (Anchor)

Save the file you downloaded above into your project (e.g. `./idl/`) and import it:

```js theme={null}
import { Program, AnchorProvider } from "@coral-xyz/anchor";
import rwaMarketIdl from "./idl/rwa_market.json"; // downloaded from the links above

const program = new Program(rwaMarketIdl, provider); // program id is embedded in the IDL `address`
const [assetPda] = PublicKey.findProgramAddressSync(
  [Buffer.from("asset"), mint.toBuffer()], program.programId);
const asset = await program.account.asset.fetch(assetPda);
// asset.priceCents, asset.feeBps, asset.isActive, asset.vault, asset.payoutMint, ...
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.