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

# PDA Reference

> Program Derived Address derivation utilities.

PDAs are deterministic addresses derived from seeds. Both SDKs provide utilities for deriving all Orica PDAs.

***

## Orica PDAs

Access via `sdk.orica.pda`:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const pda = sdk.orica.pda;
> ```

> [tab] Python
>
> ```python theme={"dark"}
> pda = sdk.orica.pda
> ```

### Global State

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [globalState, bump] = pda.globalState();
> // Seeds: ["global_state"]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> global_state, bump = pda.global_state()
> # Seeds: [b"global_state"]
> ```

### Fee Vault

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [feeVault, bump] = pda.feeVault();
> // Seeds: ["fee_vault"]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> fee_vault, bump = pda.fee_vault()
> # Seeds: [b"fee_vault"]
> ```

### Market

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [market, bump] = pda.market(globalState, marketId);
> // Seeds: ["market", globalState, marketId (8 bytes LE)]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> market, bump = pda.market(global_state, market_id)
> # Seeds: [b"market", global_state, market_id (8 bytes LE)]
> ```

### Market Vault

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [marketVault, bump] = pda.marketVault(globalState, marketId);
> // Seeds: ["market_vault", globalState, marketId (8 bytes LE)]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> market_vault, bump = pda.market_vault(global_state, market_id)
> # Seeds: [b"market_vault", global_state, market_id (8 bytes LE)]
> ```

### Vault Authority

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [vaultAuthority, bump] = pda.vaultAuthority(globalState, marketId);
> // Seeds: ["vault_authority", globalState, marketId (8 bytes LE)]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> vault_authority, bump = pda.vault_authority(global_state, market_id)
> # Seeds: [b"vault_authority", global_state, market_id (8 bytes LE)]
> ```

### Position

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [position, bump] = pda.position(market, user);
> // Seeds: ["position", market, user]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> position, bump = pda.position(market, user)
> # Seeds: [b"position", market, user]
> ```

***

## Disputes PDAs

Access via `sdk.disputes.pda`:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const pda = sdk.disputes.pda;
> ```

> [tab] Python
>
> ```python theme={"dark"}
> pda = sdk.disputes.pda
> ```

### Dispute Config

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [disputeConfig, bump] = pda.disputeConfig();
> // Seeds: ["dispute_config"]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> dispute_config, bump = pda.dispute_config()
> # Seeds: [b"dispute_config"]
> ```

### Dispute

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [dispute, bump] = pda.dispute(market);
> // Seeds: ["dispute", market]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> dispute, bump = pda.dispute(market)
> # Seeds: [b"dispute", market]
> ```

### Dispute Vote

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [disputeVote, bump] = pda.disputeVote(dispute, user);
> // Seeds: ["dispute_vote", dispute, user]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> dispute_vote, bump = pda.dispute_vote(dispute, user)
> # Seeds: [b"dispute_vote", dispute, user]
> ```

### Dispute Message

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [message, bump] = pda.disputeMessage(dispute, author, messageCount);
> // Seeds: ["message", dispute, author, messageCount (4 bytes LE)]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> message, bump = pda.dispute_message(dispute, author, message_count)
> # Seeds: [b"message", dispute, author, message_count (4 bytes LE)]
> ```

### Boost Record

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [boostRecord, bump] = pda.boostRecord(message, booster);
> // Seeds: ["boost_record", message, booster]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> boost_record, bump = pda.boost_record(message, booster)
> # Seeds: [b"boost_record", message, booster]
> ```

### User Dispute Action

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> const [userAction, bump] = pda.userDisputeAction(dispute, user);
> // Seeds: ["user_action", dispute, user]
> ```

> [tab] Python
>
> ```python theme={"dark"}
> user_action, bump = pda.user_dispute_action(dispute, user)
> # Seeds: [b"user_action", dispute, user]
> ```

***

## Example: Derive All PDAs for a Trade

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> async function getTradeAddresses(
>   sdk: OricaSDK,
>   marketAddress: PublicKey,
>   userPubkey: PublicKey
> ) {
>   const [globalState] = sdk.orica.pda.globalState();
>   const [feeVault] = sdk.orica.pda.feeVault();
>   const [position] = sdk.orica.pda.position(marketAddress, userPubkey);
>
>   // Fetch market to get marketId
>   const market = await sdk.orica.fetchMarket(marketAddress);
>
>   const [marketVault] = sdk.orica.pda.marketVault(globalState, market.id);
>   const [vaultAuthority] = sdk.orica.pda.vaultAuthority(globalState, market.id);
>
>   return {
>     globalState,
>     feeVault,
>     position,
>     marketVault,
>     vaultAuthority,
>   };
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> async def get_trade_addresses(sdk, market_address, user_pubkey):
>     global_state, _ = sdk.orica.pda.global_state()
>     fee_vault, _ = sdk.orica.pda.fee_vault()
>     position, _ = sdk.orica.pda.position(market_address, user_pubkey)
>
>     # Fetch market to get market_id
>     market = await sdk.orica.fetch_market(market_address)
>
>     market_vault, _ = sdk.orica.pda.market_vault(global_state, market.id)
>     vault_authority, _ = sdk.orica.pda.vault_authority(global_state, market.id)
>
>     return {
>         "global_state": global_state,
>         "fee_vault": fee_vault,
>         "position": position,
>         "market_vault": market_vault,
>         "vault_authority": vault_authority,
>     }
> ```

***

## Manual PDA Derivation

If you need to derive PDAs without the SDK:

> [tab] TypeScript
>
> ```typescript theme={"dark"}
> import { PublicKey } from "@solana/web3.js";
> import { BN } from "@coral-xyz/anchor";
>
> const ORICA_PROGRAM_ID = new PublicKey("oEarJ8xDDssLcWwgkSpRVVbmiUyeDnoHFNAHPp6eetw");
>
> function deriveMarketPDA(globalState: PublicKey, marketId: BN | number) {
>   const id = typeof marketId === "number" ? new BN(marketId) : marketId;
>   return PublicKey.findProgramAddressSync(
>     [
>       Buffer.from("market"),
>       globalState.toBuffer(),
>       id.toArrayLike(Buffer, "le", 8),
>     ],
>     ORICA_PROGRAM_ID
>   );
> }
> ```

> [tab] Python
>
> ```python theme={"dark"}
> from solders.pubkey import Pubkey
>
> ORICA_PROGRAM_ID = Pubkey.from_string("oEarJ8xDDssLcWwgkSpRVVbmiUyeDnoHFNAHPp6eetw")
>
> def derive_market_pda(global_state: Pubkey, market_id: int):
>     return Pubkey.find_program_address(
>         [
>             b"market",
>             bytes(global_state),
>             market_id.to_bytes(8, "little"),
>         ],
>         ORICA_PROGRAM_ID,
>     )
> ```

***

## Next Steps

> [card] [Types](https://docs.orica.markets/sdk/types.md)
>
> Complete type definitions.

> [card] [Trading](https://docs.orica.markets/sdk/trading.md)
>
> Use PDAs in transactions.


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