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

# Trading & Redemption

> Take a position in a P2P market, read live odds, and redeem winning positions with pnp-core.

Once a market exists, users take positions and — after settlement — redeem winnings. The full
trade lifecycle lives on **`client.p2p`**; the AMM namespace currently exposes market creation
plus price/multiplier **reads**.

**1. Buy into a side**

`client.p2p.buy` — spend collateral to mint decision tokens.

**2. Watch the odds**

`client.p2p.getMarket` — implied probabilities and pot sizes update as people trade.

**3. Settle**

An authorized settler calls `client.p2p.settle` after `endTime`. See [Custom Oracles](https://pnpprotocol.mintlify.site/sdk/custom-oracles.md).

**4. Redeem**

Winners call `client.p2p.redeem` to burn winning tokens and collect the payout.

## Buy into a P2P market

Spend `amount` collateral (base units) to mint decision tokens on `side`. The buyer's YES/NO
associated token accounts are created on demand.

```ts theme={null}
import { PnpClient, uiToBaseUnits } from "pnp-core";

const client = PnpClient.mainnet({ wallet });

const res = await client.p2p.buy({
  market: 42n,                        // numeric id or the market PDA
  side: "no",
  amount: uiToBaseUnits(50, 6),       // spend 50 USDC
  minTokensOut: uiToBaseUnits(48, 6), // optional slippage floor (base units)
});

console.log(res.signature, res.side);
```

**market** `PublicKey | bigint | number` *required*

The market to bet on — its numeric id or PDA.

**side** `"yes" | "no"` *required*

Side to buy (mint decision tokens for).

**amount** `BN | bigint | number` *required*

Collateral to spend, in base units.

**minTokensOut** `BN | bigint | number` (default: 0)

Slippage floor: minimum decision tokens to receive. `0` disables the guard.

**computeUnitLimit** `number` (default: 300000)

CU limit prepended to the tx (covers ATA creation). `0` skips it.

> [!NOTE]
>
> **New-rules markets (id ≥ 79)** use a locked-liquidity model: only the creator may buy the
> creator's side, and the opposite side is whitelist-gated. The SDK passes the gate PDA
> automatically — an unauthorized buy reverts on-chain. Legacy markets (id \< 79) are open.

## Read a market's state

`getMarket` decodes and enriches a market — pot sizes, implied probabilities, mints, and status
— from a numeric id or PDA. No wallet required.

```ts theme={null}
const m = await client.p2p.getMarket(42n);

console.log(m.question);
console.log("status:", m.status);                 // "open" | "ended" | "resolved"
console.log("YES pool:", m.yesPot, "NO pool:", m.noPot);
console.log("implied YES %:", (m.impliedYesProbability * 100).toFixed(1));
if (m.status === "resolved") console.log("winner:", m.winner);
```

Key fields on `P2PMarket`: `yesPot` / `noPot` / `totalPot`, `impliedYesProbability` /
`impliedNoProbability` (0–1), `creatorSide`, `endTime`, `resolved`, `winner`, `oddsBps`, and
the `yesMint` / `noMint` / `collateralMint` addresses. See the
[API Reference](https://pnpprotocol.mintlify.site/sdk/api-reference.md) for the full shape.

## Read AMM prices & multipliers

AMM (Pythagorean) markets expose spot prices and potential payout multiples. Fresh markets read
50/50 and 2×/2×.

```ts theme={null}
const price = await client.amm.readPrice(marketId);
// { yesPrice: 0.5, noPrice: 0.5 }  — each in [0,1]

const mult = await client.amm.readMultiplier(marketId);
// { yesMultiplier: 2, noMultiplier: 2 }
//   yesMultiplier = 1 + (noSupply / yesSupply)²
```

> [!NOTE]
>
> AMM markets are **create + read** in `pnp-core` today. On-chain AMM buys/sells aren't yet
> exposed through the SDK — the parimutuel (`p2p`) path is the supported end-to-end trading flow.

## Redeem a winning position

After a market is settled, the winner burns their winning decision tokens and receives the
payout. A **2% fee** is taken from the gross payout (60% to the creator's fee treasury, 40% to
the P2P admin); you receive the rest.

```ts theme={null}
const res = await client.p2p.redeem({ market: 42n });
console.log("redeemed:", res.signature);
```

> [!WARNING]
>
> `redeem` only works **after** the market is settled (`status === "resolved"`). The signer must
> hold the winning-side tokens. Redeeming before settlement reverts on-chain. To take back
> **unmatched** collateral instead, see [Refunds](https://pnpprotocol.mintlify.site/sdk/refunds.md).

## End-to-end

```ts theme={null}
import { PnpClient, uiToBaseUnits } from "pnp-core";

const client = PnpClient.mainnet({ wallet });

// 1) create — seed YES with 100 USDC
const { marketId } = await client.p2p.createMarket({
  question: "Will it ship this month?",
  initialAmount: uiToBaseUnits(100, 6),
  side: "yes",
  endTime: new Date(Date.now() + 7 * 864e5),
});

// 2) a taker buys the NO side
await client.p2p.buy({ market: marketId, side: "no", amount: uiToBaseUnits(40, 6) });

// 3) after endTime, an authorized settler resolves it
await client.p2p.settle({ market: marketId, winner: "yes" });

// 4) the YES holder redeems
await client.p2p.redeem({ market: marketId });
```


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