Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.meteora.ag/llms.txt

Use this file to discover all available pages before exploring further.

Use CPI only when your Solana program must compose directly with Presale Vault. For off-chain apps, launch scripts, and dashboards, the TypeScript SDK is simpler and safer.
Do not hand-type account order from memory. Generate CPI bindings from the Presale Vault IDL or depend on the local Anchor crate with the cpi feature, then compare against SDK-built instructions for the same flow.

Program ID

pub const PRESALE_PROGRAM_ID: Pubkey =
    pubkey!("presSVxnf9UU8jMxhgSMqaRwNiT36qeBdNeTRKjTdbj");
The public program ID is the same for mainnet and devnet.

Dependency

[dependencies]
presale = { path = "../presale/programs/presale", features = ["cpi"] }
Keep the local crate, IDL, deployed program, and TypeScript SDK revision aligned in tests.

CPI Instruction Scope

The full instruction list is documented in Program Instructions. CPI integrations most often need:
FlowInstruction
Create buyer escrowcreate_permissionless_escrow, create_permissioned_escrow_with_merkle_proof, or create_permissioned_escrow_with_creator
Deposit quote tokendeposit
Withdraw during presalewithdraw
Claim base tokenclaim
Refund failed or prorata overflow quotewithdraw_remaining_quote
Refresh claimable staterefresh_escrow
Close escrowclose_escrow
Creator-managed flows such as presale initialization, Merkle root config, operator setup, creator withdrawal, fee collection, and unsold token action can also be called by CPI, but they require stricter authority and lifecycle planning.

Event CPI Accounts

Most account structs use #[event_cpi]. Generated clients include these accounts after the primary accounts:
AccountWhy it appears
event_authorityAnchor event-CPI PDA for the presale program.
programThe presale program account used by event CPI emission.
Omitting these accounts from a CPI call can cause account validation or account-count failures.

Account Planning

FlowRequired planning
Initialize presalePresale PDA, vault PDAs, presale authority, base and quote token programs, payer base token account, base signer, creator, fixed-price extra-args remaining account when mode is fixed price, and Token 2022 base transfer-hook accounts when required.
Create permissionless escrowPresale state, escrow PDA from registry 0, owner, payer, and system program.
Create Merkle proof escrowPresale state, escrow PDA from registry index, owner, Merkle root config, payer, proof, and deposit cap.
Create authority escrowPresale state, escrow PDA from registry index, owner, operator PDA, operator owner signer, payer, and deposit cap.
DepositPresale state, quote vault, quote mint, escrow, payer quote token account, payer signer, token program, and quote transfer-hook remaining accounts when required.
WithdrawPresale state, quote vault, quote mint, presale authority, escrow, owner quote token account, owner signer, token program, memo program, and quote transfer-hook accounts when required.
ClaimPresale state, base vault, base mint, presale authority, escrow, owner base token account, owner signer, token program, memo program, and base transfer-hook accounts when required.
Creator withdrawBase or quote vault and mint are passed as remaining accounts depending on whether the presale failed or completed.
Read mints, vaults, token program flags, mode, whitelist mode, and registry state from the Presale account whenever possible. Avoid deriving business assumptions from user input alone.

Token 2022 Remaining Accounts

Presale Vault supports Token 2022 transfer hooks through RemainingAccountsInfo:
pub enum AccountsType {
    TransferHookBase,
    TransferHookQuote,
}
TransferSlice type
Base token transfersTransferHookBase
Quote token transfersTransferHookQuote
If a mint has a transfer-hook program, include the required hook accounts in the remaining accounts and set the matching slice length. If a mint does not have a hook program, do not pass transfer-hook accounts for that mint.

Common CPI Failures

Error or symptomLikely cause
NotEnoughAccountKeysMissing event CPI accounts, memo program, mode-specific remaining accounts, or transfer-hook remaining accounts.
ConstraintSeeds / ConstraintAddressPresale, vault, escrow, operator, Merkle root, presale authority, or event authority PDA is wrong.
ConstraintHasOneEscrow, vault, mint, owner, or metadata account does not match parent account state.
PresaleNotOpenForDepositPresale progress is not Ongoing.
PresaleNotOpenForWithdrawMode disallows withdrawal, fixed-price withdrawal is disabled, or presale is no longer ongoing.
MissingPresaleExtraParamsFixed-price initialization did not pass the fixed-price extra-args account as the first remaining account.
InvalidRemainingAccountSliceRemaining-account slice type or length does not match the accounts provided.
MissingRemainingAccountForTransferHookToken 2022 mint has a transfer hook but CPI did not forward the hook accounts.
NoTransferHookProgramHook accounts were forwarded for a mint without a transfer-hook program.
EscrowNotEmptyCPI attempted to close an escrow before all state-dependent claim, refund, or withdrawal requirements were complete.

Best Practices

CheckDetail
Generate accountsUse generated CPI bindings or the local Anchor crate. Compare account metas against the TypeScript SDK for the same flow.
Simulate firstSimulate CPI transactions with realistic presale state, especially Token 2022 and permissioned flows.
Respect lifecycle stateLoad Presale and derive PresaleProgress from current timestamp before deciding which instruction to call.
Handle once-only flagsCreator withdrawal, fee collection, unsold token action, and remaining quote withdrawal are guarded by account flags.
Plan Token 2022 feesTransfer-fee mints affect gross and net amounts. Use SDK or Rust helper math before setting amounts and bounds.
Keep registries straightDerive escrows with the intended registry index and validate registry caps before submitting transactions.
Test every modeFixed-price, prorata, and FCFS have different withdrawal, cap, price, and refund behavior.