> ## 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`:

```
proceeds = amount * price_cents * 10^payout_dec / (100 * 10^rwa_dec)
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`).

## 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.

<CardGroup cols={2}>
  <Card title="rwa_market.json" icon="download" href="/docs/idl/rwa_market.json">
    Trading — `buy` / `sell`, the `Asset` account.
  </Card>

  <Card title="rwa_token.json" icon="download" href="/docs/idl/rwa_token.json">
    Asset terms & the `TokenMeta` account (`payout_token`, decimals).
  </Card>

  <Card title="rwa_exit.json" icon="download" href="/docs/idl/rwa_exit.json">
    Redemption — `claim`, the `ExitState` account.
  </Card>

  <Card title="rwa_vault.json" icon="download" href="/docs/idl/rwa_vault.json">
    The vault accounts a trade touches.
  </Card>
</CardGroup>

<Tip>
  Direct links: [rwa\_market.json](/docs/idl/rwa_market.json) ·
  [rwa\_token.json](/docs/idl/rwa_token.json) ·
  [rwa\_exit.json](/docs/idl/rwa_exit.json) ·
  [rwa\_vault.json](/docs/idl/rwa_vault.json) ·
  [rwa\_automation.json](/docs/idl/rwa_automation.json)
</Tip>

## 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, ...
```
