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)
| Index | Account | Signer | Writable |
|---|---|---|---|
| 0 | Authority (payer) | ✅ | ✅ |
| 1 | PoolList PDA | ❌ | ✅ |
| 2 | Pool PDA | ❌ | ✅ |
| 3 | Makers PDA | ❌ | ✅ |
| 4 | LiquidityMarkets PDA | ❌ | ✅ |
| 5 | MatchIds PDA | ❌ | ✅ |
| 6 | ShareHolders PDA | ❌ | ✅ |
| 7 | UserDeals PDA | ❌ | ✅ |
| 8 | Positions PDA | ❌ | ✅ |
| 9 | Keepers PDA | ❌ | ✅ |
| 10 | Token Mint | ❌ | ❌ |
| 11 | Risk Fund | ❌ | ❌ |
| 12 | Program ID | ❌ | ❌ |
| 13 | Program ID | ❌ | ❌ |
| 14 | Program ID | ❌ | ❌ |
| 15 | System Program | ❌ | ❌ |
| 16 | Rent 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
- Derive pool PDA
- Derive 7 auxiliary PDAs
- Check if pool already exists
- Build instruction
- Send transaction
- 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