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

# API Reference

> Complete reference for pnp-core — the PnpClient, the p2p / amm / oracle namespaces, helper functions, constants, and exported types.

Import everything from the package root:

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

> [!NOTE]
>
> On-chain read/write methods accept a market as a numeric **id** (`bigint | number`) **or** its
> **`PublicKey`** PDA. Oracle (indexer) methods accept a `PublicKey | string`. **Amounts are in
> base units** — use `uiToBaseUnits` / `baseUnitsToUi`.

## PnpClient

| Member | Signature | Notes |
| - | - | - |
| constructor | `new PnpClient(opts: PnpClientOptions)` | `cluster` required; omit `wallet` → read-only |
| `PnpClient.mainnet` | `(opts?) => PnpClient` | mainnet preset |
| `PnpClient.devnet` | `(opts?) => PnpClient` | devnet preset |
| `.p2p` | `P2PModule` | parimutuel / V3 API |
| `.amm` | `AmmModule` | Pythagorean / V2 API |
| `.oracle` | `OracleModule` | indexer / oracle reads |
| `.canSign` | `boolean` | true if a signer is attached |
| `.payer` | `PublicKey` | signer pubkey; throws if read-only |
| `.requireWallet()` | `() => AnchorWallet` | returns the signer or throws |
| `.signMessage(msg)` | `(Uint8Array) => Promise<Uint8Array>` | ed25519 sign for off-chain auth |

Also exposed as properties: `network`, `connection`, `programId`, `program` (the underlying
anchor `Program`), `provider`, `commitment`, `wallet?`, `criteriaApiUrl`, `oracleApiUrl`.

**cluster** `"mainnet" | "devnet"` *required*

Target network. Set automatically by the `.mainnet()` / `.devnet()` presets.

**wallet** `Keypair | AnchorWallet`

A Node `Keypair` or browser wallet adapter. Omit for a read-only client.

**rpcUrl** `string`

Override the network default RPC endpoint.

**connection** `Connection`

Provide a preconfigured `@solana/web3.js` connection instead of `rpcUrl`.

**commitment** `Commitment` (default: confirmed)

Transaction commitment level.

**criteriaApiUrl** `string`

Override the settlement-criteria server base URL.

**oracleApiUrl** `string`

Override the indexer API base URL (include the `/api` prefix).

## client.p2p — parimutuel (V3)

| Method | Signature |
| - | - |
| `createMarket` | `(params: CreateMarketParams) => Promise<CreateMarketResult>` |
| `createMarketCustom` | `(params: CreateMarketCustomParams) => Promise<CreateMarketResult>` |
| `buy` | `(params: BuyParams) => Promise<BuyResult>` |
| `creatorWithdraw` | `(params: CreatorWithdrawParams) => Promise<CreatorWithdrawResult>` |
| `redeem` | `(params: RedeemParams) => Promise<RedeemResult>` |
| `settle` | `(params: SettleParams) => Promise<SettleResult>` |
| `setEndTime` | `(params: SetEndTimeParams) => Promise<SetEndTimeResult>` |
| `updateCreator` | `(params: UpdateCreatorParams) => Promise<UpdateCreatorResult>` |
| `setSettlementCriteria` | `(params: SetSettlementCriteriaParams) => Promise<SetSettlementCriteriaResult>` |
| `getSettlementCriteria` | `(market, opts?) => Promise<SettlementCriteriaRecord \| null>` |
| `getMarket` | `(market) => Promise<P2PMarket>` |
| `fetchGlobalConfig` | `() => Promise<GlobalConfigAccount>` |
| `nextMarketId` | `() => Promise<bigint>` |

## client.amm — Pythagorean (V2)

| Method | Signature |
| - | - |
| `createMarket` | `(params: AmmCreateMarketParams) => Promise<AmmCreateMarketResult>` |
| `createMarketCustom` | `(params: AmmCreateMarketCustomParams) => Promise<AmmCreateMarketResult>` |
| `createCoinMarket` | `(params: CreateCoinMarketParams) => Promise<AmmCreateMarketResult>` |
| `createYoutubeMarket` | `(params: CreateYoutubeMarketParams) => Promise<AmmCreateMarketResult>` |
| `getMarket` | `(market) => Promise<AmmMarket>` |
| `readPrice` | `(market) => Promise<AmmPrice>` — `{ yesPrice, noPrice }` |
| `readMultiplier` | `(market) => Promise<AmmMultiplier>` — `{ yesMultiplier, noMultiplier }` |
| `fetchGlobalConfig` | `() => Promise<GlobalConfigAccount>` |
| `nextMarketId` | `() => Promise<bigint>` |

## client.oracle — indexer reads

| Method | Signature |
| - | - |
| `getResolvableStatus` | `(market: PublicKey \| string, opts?) => Promise<ResolvableStatus>` |
| `getSettlementCriteria` | `(market: PublicKey \| string, opts?) => Promise<OracleSettlementCriteria \| null>` |
| `waitForResolvable` | `(market: PublicKey \| string, opts?) => Promise<WaitForResolvableResult>` |

`ResolvableStatus` = `"checking" | "resolvable" | "unresolvable"`.
`waitForResolvable` options: `{ apiUrl?, intervalMs? (3000), timeoutMs? (120000) }`.

## Helper functions

> [accordion] Numeric & units
>
> * `toBN(value) => BN`
> * `toBig(value) => bigint`
> * `u64le(value) => Buffer` — 8-byte little-endian
> * `uiToBaseUnits(amount, decimals) => bigint` — `uiToBaseUnits(100, 6) === 100_000000n`
> * `baseUnitsToUi(amount, decimals) => number`

> [accordion] Token & ATA
>
> * `getTokenProgramForMint(connection, mint) => Promise<PublicKey>` — classic vs Token-2022
> * `ata(mint, owner, tokenProgram?) => PublicKey` — associated token address
> * Constants: `TOKEN_PROGRAM_ID`, `TOKEN_2022_PROGRAM_ID`, `ASSOCIATED_TOKEN_PROGRAM_ID`

> [accordion] PDAs (pda.\* namespace)
>
> Each is `(programId, id) => PublicKey` unless noted:
>
> * `pda.globalConfigPda(programId)`
> * `pda.marketV2Pda`, `pda.marketV2ExtensionPda`
> * `pda.marketV3Pda`, `pda.yesMintV3Pda`, `pda.noMintV3Pda`, `pda.marketV3ExtensionPda`, `pda.marketV3GatePda`
> * `pda.creatorFeeTreasuryPda(...)`, `pda.reserveVault(...)`

> [accordion] Settlement-criteria signing
>
> * `buildSettlementCriteriaMessage(params) => string`
> * `sha256Hex(input) => string`
> * `randomNonce() => string`

> [accordion] Networks & IDL
>
> * `resolveNetwork(cluster) => NetworkConfig`
> * `NETWORKS` — `{ mainnet, devnet }`
> * `getIdl(cluster) => Idl`, `PNP_IDL_MAINNET`, `PNP_IDL_DEVNET`, `IDL_PROGRAM_ADDRESS`

## Constants

| Constant | Value / meaning |
| - | - |
| `PNP_PROGRAM_ID` | `8PyE2dizL52ga7ytqLtqRyjwWp4yXEx8M5Z4BAHgHuTb` (same on both clusters) |
| `REDEEM_FEE_BPS` | `200` — 2% redemption fee on gross payout |
| `REDEEM_FEE_CREATOR_SHARE_PCT` / `REDEEM_FEE_ADMIN_SHARE_PCT` | `60` / `40` — fee split |
| `MIN_ODDS_BPS` / `MAX_ODDS_BPS` / `DEFAULT_ODDS_BPS` | `100` / `9900` / `10000` |
| `NEW_RULES_FROM_MARKET_ID` | `79n` — locked-liquidity threshold |
| `MAX_OPPOSITE_MULTIPLE` | `100n` — opposite-side pot cap (new-rules) |
| `MAX_GATE_ENTRIES` | `50` — whitelist gate capacity |
| `P2P_ADMIN_KEY` | Hardcoded P2P admin (settler + fee recipient) |
| `DEFAULT_CRITERIA_API_URL` / `DEFAULT_ORACLE_API_URL` | Criteria server / indexer defaults |
| `SEEDS` | PDA seed prefixes |

## Key types

### P2PMarket

Decoded + computed snapshot returned by `p2p.getMarket`. Token amounts are `bigint` base units.

```ts theme={null}
interface P2PMarket {
  address: PublicKey;
  id: bigint;
  question: string;
  status: "open" | "ended" | "resolved";
  creator: PublicKey;
  creatorSide: "yes" | "no";
  creatorInitialAmount: bigint;
  resolved: boolean;
  resolvable: boolean;
  winner: "yes" | "no" | null;
  endTime: number;          // unix seconds
  creationTime: number;
  yesPot: bigint; noPot: bigint; totalPot: bigint;
  yesTokensIssued: bigint; noTokensIssued: bigint;
  impliedYesProbability: number; // 0..1
  impliedNoProbability: number;  // 0..1
  collateralMint: PublicKey; yesMint: PublicKey; noMint: PublicKey;
  creatorFeeTreasury: PublicKey;
  hasExtension: boolean; oddsBps: number; oracle: PublicKey | null;
}
```

### AmmMarket

```ts theme={null}
interface AmmMarket {
  address: PublicKey; id: bigint; version: number;
  question: string; status: "open" | "ended" | "resolved";
  creator: PublicKey; resolved: boolean; resolvable: boolean;
  winner: "yes" | "no" | null;
  endTime: number; creationTime: number;
  collateralMint: PublicKey;
  yesMint: PublicKey | null; noMint: PublicKey | null; // null until first buy
  marketReserves: bigint; yesSupply: bigint; noSupply: bigint; initialLiquidity: bigint;
  creatorFeeTreasury: PublicKey;
  yesPrice: number; noPrice: number; yesMultiplier: number; noMultiplier: number;
}
```

### Shared enums

```ts theme={null}
type Side = "yes" | "no";
type Amount = BN | bigint | number;      // base units
type TimeInput = number | bigint | BN | Date;
type Cluster = "mainnet" | "devnet";
```

> [card] [Full type list](https://github.com/proxima424/pnp-sdk-v2/blob/main/FUNCTIONS.md)
>
> Every exported param/result/type is enumerated in the repo's `FUNCTIONS.md`.


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