Skip to main content

Initialize

Creates a new trading pair and optionally adds initial liquidity in a single transaction.

Accounts

deployer
Signer
required
The account that will pay for pair creation and provide initial liquidity.
token0_mint
InterfaceAccount<Mint>
required
The mint address for token0. Must be less than token1_mint (canonical ordering).
token1_mint
InterfaceAccount<Mint>
required
The mint address for token1. Must be greater than token0_mint (canonical ordering).
pair
Account<Pair>
required
The pair account to initialize. PDA derived from [PAIR_SEED_PREFIX, token0, token1, params_hash].
futarchy_authority
Account<FutarchyAuthority>
required
The futarchy authority account. PDA derived from [FUTARCHY_AUTHORITY_SEED_PREFIX].
rate_model
Account<RateModel>
required
The interest rate model account for this pair.
lp_mint
UncheckedAccount
required
The LP token mint account. Must be uninitialized and will be initialized by the program.

Arguments

swap_fee_bps
u16
required
Swap fee in basis points (0-10000). Applied to all swaps on this pair.
half_life
u64
required
EMA half-life in seconds. Must be between 60 (1 minute) and 43200 (12 hours).
fixed_cf_bps
Option<u16>
Optional fixed collateral factor in basis points. If Some, overrides dynamic CF calculation.
params_hash
[u8; 32]
required
SHA256 hash of [version, swap_fee_bps, half_life, fixed_cf_bps.unwrap_or(0)]. Used for pair PDA derivation.
amount0_in
u64
required
Initial amount of token0 to deposit. Must be greater than 0.
amount1_in
u64
required
Initial amount of token1 to deposit. Must be greater than 0.
min_liquidity_out
u64
required
Minimum LP tokens to receive. Used for slippage protection.
use anchor_lang::prelude::*;
use omnipair::program::Omnipair;

let initialize_args = InitializeAndBootstrapArgs {
    swap_fee_bps: 30, // 0.3%
    half_life: 3600, // 1 hour
    fixed_cf_bps: None, // Use dynamic CF
    params_hash: compute_params_hash(1, 30, 3600, None),
    version: 1,
    amount0_in: 1000 * 10u64.pow(token0_decimals),
    amount1_in: 2000 * 10u64.pow(token1_decimals),
    min_liquidity_out: 0,
    lp_name: "OMFG/USDC omLP".to_string(),
    lp_symbol: "OM.US-OMLP".to_string(),
    lp_uri: "https://example.com/metadata.json".to_string(),
};

let accounts = InitializeAndBootstrap {
    deployer: deployer.key(),
    token0_mint: token0_mint.key(),
    token1_mint: token1_mint.key(),
    pair: pair_pda,
    futarchy_authority: futarchy_authority_pda,
    rate_model: rate_model_pda,
    lp_mint: lp_mint_key,
    // ... other accounts
};

let ctx = CpiContext::new(program_id, accounts);
omnipair::cpi::initialize(ctx, initialize_args)?;
{
  "signature": "5VERv8NMvzbJMEkV8xnrLkEaWRtSz9CosKDYjCJjBRnbJLgp8uirBgmG5Rk88jH2k9f4w3JHFf7Pjsk3bWqeXrC",
  "slot": 123456789
}