Skip to main content

Initialize Public Pool

This instruction creates a unified public liquidity pool along with all required auxiliary state accounts.

It must be executed before:

  • Adding liquidity
  • Matching orders against the pool
  • Executing liquidations involving the pool
  • Recording maker deals

Instruction Overview

Discriminator: 19
Instruction: InitializePublicPool


PDA Structure

The pool system consists of 1 main PDA + 7 auxiliary PDAs.


0️⃣ PoolList PDA

Stores all initialized settlement-token pools.

["pool_list"]
function findPoolListAddress(
programId: PublicKey
): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[Buffer.from('pool_list')],
programId
);
}

1️⃣ Pool PDA

["pool", token_mint]
function findPoolAddress(
programId: PublicKey,
tokenMint: PublicKey,
): [PublicKey, number] {
return PublicKey.findProgramAddressSync(
[
Buffer.from('pool'),
tokenMint.toBuffer()
],
programId
);
}

2️⃣ Auxiliary PDAs

Each auxiliary account is derived from the pool PDA.


Makers

["makers", pool_pda]

Liquidity Markets

["liquidity_markets", pool_pda]

Match IDs

["match_ids", pool_pda]

User Deals

["user_deals", pool_pda]

Positions

["position", pool_pda]

Share Holders

["share_holders", pool_pda]

Keepers

["keepers", pool_pda]

Required Accounts (Strict Order)

IndexAccountSignerWritable
0Authority (payer)
1PoolList PDA
2Pool PDA
3Makers PDA
4LiquidityMarkets PDA
5MatchIds PDA
6ShareHolders PDA
7UserDeals PDA
8Positions PDA
9Keepers PDA
10Token Mint
11Risk Fund
12Program ID
13Program ID
14Program ID
15System Program
16Rent Sysvar

⚠️ Account ordering must match exactly.


Instruction Data Layout

u8      discriminator (19)
Pubkey risk_fund
u8 token_decimals

TypeScript Instruction Builder

function createInitializePublicPoolInstruction(
programId: PublicKey,
authority: PublicKey,
poolListPda: PublicKey,
poolPda: PublicKey,
poolPdas: PoolPDAs,
tokenMint: PublicKey,
riskFund: PublicKey,
tokenDecimals: number
): TransactionInstruction {

const data = Buffer.concat([
Buffer.from([19]),
riskFund.toBuffer(),
Buffer.from([tokenDecimals]),
]);

return new TransactionInstruction({
keys: [
{ pubkey: authority, isSigner: true, isWritable: true },
{ pubkey: poolListPda, isSigner: false, isWritable: true },
{ pubkey: poolPda, isSigner: false, isWritable: true },
{ pubkey: poolPdas.makers, isSigner: false, isWritable: true },
{ pubkey: poolPdas.liquidityMarkets, isSigner: false, isWritable: true },
{ pubkey: poolPdas.matchIds, isSigner: false, isWritable: true },
{ pubkey: poolPdas.shareHolders, isSigner: false, isWritable: true },
{ pubkey: poolPdas.userDeals, isSigner: false, isWritable: true },
{ pubkey: poolPdas.positions, isSigner: false, isWritable: true },
{ pubkey: poolPdas.keepers, isSigner: false, isWritable: true },
{ pubkey: tokenMint, isSigner: false, isWritable: false },
{ pubkey: riskFund, isSigner: false, isWritable: false },
{ pubkey: programId, isSigner: false, isWritable: false },
{ pubkey: programId, isSigner: false, isWritable: false },
{ pubkey: programId, isSigner: false, isWritable: false },
{ pubkey: SystemProgram.programId, isSigner: false, isWritable: false },
{ pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false },
],
programId,
data,
});
}

Execution Flow

  1. Derive pool PDA
  2. Derive 7 auxiliary PDAs
  3. Check if pool already exists
  4. Build instruction
  5. Send transaction
  6. Verify all 8 accounts were created

What Gets Created

After successful execution:

  • Pool account
  • Makers account
  • LiquidityMarkets account
  • MatchIds account
  • UserDeals account
  • Positions account
  • ShareHolders account
  • Keepers account

All accounts are program-owned and rent-exempt.


Result

A fully initialized public liquidity pool ready for:

  • Liquidity provisioning
  • Order matching
  • Position management
  • Liquidation handling