Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.hadron.fi/llms.txt

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

Initializing a new pool

Hadron::initialize

Builds all the instructions needed to create a new on-chain pool: account allocation + initialization. Returns the instructions, derived pool address, and seed. The allocate instruction(s) must be confirmed before sending the initialize instruction (they can be in separate transactions, or together if they fit).
use hadron_sdk::hadron::Hadron;
use hadron_sdk::types::InitializeParams;
use hadron_sdk::helpers::math::to_q32;
use hadron_sdk::constants::HADRON_PROGRAM_ID;

let (instructions, pool_address, seed) = Hadron::initialize(&payer, &InitializeParams {
    seed: None,                              // auto-generated
    mint_x,
    mint_y,
    authority: payer,
    initial_midprice_q32: to_q32(1.0),       // midprice = 1.0
    oracle_mode: None,                       // default: Authority
    max_prefab_slots: None,                  // default: 10
    max_curve_points: None,                  // default: 16
    token_program_x: None,                   // default: SPL Token
    token_program_y: None,                   // default: SPL Token
}, &HADRON_PROGRAM_ID);

// Send the instructions (group into transactions as needed)
ParamTypeDescription
payer&PubkeyTransaction fee payer and account funder
params.seedOption<u64>Pool seed. Auto-generated if None. Allows multiple pools per token pair.
params.mint_xPubkeyBase token mint
params.mint_yPubkeyQuote token mint
params.authorityPubkeyPool authority (manages curves, oracle, state)
params.initial_midprice_q32u64Starting midprice in Q32 fixed-point format
params.oracle_modeOption<OracleMode>Authority (default) or Relative (vault ratio)
params.token_program_xOption<Pubkey>Token program for X (default: SPL Token)
params.token_program_yOption<Pubkey>Token program for Y (default: SPL Token)
params.max_prefab_slotsOption<u8>Max curve prefab slots (default: 10)
params.max_curve_pointsOption<u8>Max points per curve (default: 16)
Returns (Vec<Instruction>, Pubkey, u64) — instructions, pool address, seed
With default parameters the CurvePrefabs account is ~15 KB, so two allocate instructions are returned (Solana’s single-instruction realloc limit is 10 KB). Send the allocates first, then the initialize.

Loading an existing pool

Hadron::from_accounts

Create a Hadron instance from raw account data bytes. This is sync — no RPC calls. You fetch the accounts however you like (RPC, Geyser, etc.) and pass the raw data in.
use hadron_sdk::hadron::Hadron;

let pool = Hadron::from_accounts(
    pool_address,
    &config_data,
    &oracle_data,
    &curve_meta_data,
    &curve_prefabs_data,
)?;
ParamTypeDescription
pool_addressPubkeyThe pool’s on-chain address
config_data&[u8]Raw config account data
oracle_data&[u8]Raw midprice oracle account data
curve_meta_data&[u8]Raw curve metadata account data
curve_prefabs_data&[u8]Raw curve prefabs account data
Returns Result<Hadron, HadronSdkError>
Enable the rpc feature (cargo add hadron-sdk --features rpc) for a convenience Hadron::load(&rpc_client, &pool_address) method that fetches accounts over RPC.

Reading pool state

get_midprice

Current midprice decoded from the on-chain Q32 oracle value.
let mid = pool.get_midprice(); // e.g. 1.0023
Returns f64

get_spread_factor / get_spread_bps

Current spread factor and basis-point equivalent.
let factor = pool.get_spread_factor(); // e.g. 0.9995
let bps    = pool.get_spread_bps();    // e.g. 5.0
Returns f64

get_active_curve_slots

Returns the slot index for each active curve.
let slots = pool.get_active_curve_slots();
// ActiveCurveSlots { price_bid: 0, price_ask: 0, risk_bid: 0, risk_ask: 0 }
Returns ActiveCurveSlots

get_active_curves

Decodes and returns all four active curves from prefab data.
let curves = pool.get_active_curves()?;
// curves.price_bid.points, curves.price_ask.points, etc.
Returns Result<ActiveCurves, HadronSdkError> Each CurveSide contains:
FieldTypeDescription
num_pointsu8Number of curve points
default_interpolationInterpolationDefault interpolation mode
x_modeCurveXModeX-axis mode (Native or Alternate)
risk_modeRiskModeVirtual or Integrated
pointsVec<DecodedCurvePoint>The curve point array

get_curve_slot

Decode a specific curve slot by type and index.
use hadron_sdk::types::CurveType;

let curve = pool.get_curve_slot(CurveType::PriceBid, 1)?;
ParamTypeDescription
curve_typeCurveTypeOne of PriceBid, PriceAsk, RiskBid, RiskAsk
slotu8Slot index
Returns Result<CurveSide, HadronSdkError>

Building instructions

All methods below return an Instruction. They do not send a transaction — add the instruction to a Transaction and submit it yourself.

swap

Build a swap instruction.
use hadron_sdk::types::SwapParams;

let ix = pool.swap(&user, &SwapParams {
    is_x: true,               // true = sell X for Y, false = sell Y for X
    amount_in: 1_000_000,
    min_out: 0,                // set > 0 for slippage protection
    fee_recipient,
    expiration: None,
});
ParamTypeDescription
user&PubkeyThe user’s wallet
params.is_xboolDirection: true = X→Y, false = Y→X
params.amount_inu64Input amount in token atoms
params.min_outu64Minimum output (slippage protection)
params.fee_recipientPubkeyAddress to receive fees
params.expirationOption<i64>Optional slot expiration

deposit

Build a deposit instruction.
use hadron_sdk::types::DepositParams;

let ix = pool.deposit(&user, &DepositParams {
    amount_x: 1_000_000,
    amount_y: 2_000_000,
    expiration: None,
});
ParamTypeDescription
user&PubkeyThe user’s wallet
params.amount_xu64Amount of token X to deposit (in atoms)
params.amount_yu64Amount of token Y to deposit (in atoms)
params.expirationOption<i64>Optional slot expiration

withdraw

Build a withdraw instruction.
use hadron_sdk::types::WithdrawParams;

let ix = pool.withdraw(&user, &WithdrawParams {
    amount_x: 500_000,
    amount_y: 1_000_000,
    expiration: None,
});
ParamTypeDescription
user&PubkeyThe user’s wallet
params.amount_xu64Amount of token X to withdraw (in atoms)
params.amount_yu64Amount of token Y to withdraw (in atoms)
params.expirationOption<i64>Optional slot expiration

Curve management

set_curve

Write a price curve to a prefab slot.
use hadron_sdk::types::*;
use hadron_sdk::helpers::math::to_q32;

let ix = pool.set_curve(&authority, &SetCurveParams {
    side: Side::Bid,
    default_interpolation: Interpolation::Linear,
    points: vec![
        SetCurvePointInput {
            amount_in: 100_000,
            price_factor_q32: to_q32(0.99),
            interpolation: None,
            params: None,
        },
        SetCurvePointInput {
            amount_in: 500_000,
            price_factor_q32: to_q32(0.95),
            interpolation: None,
            params: None,
        },
    ],
    slot: Some(0),
    x_mode: None,
});
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.default_interpolationInterpolationStep, Linear, MarginalStep, Hyperbolic, Quadratic, Cubic
params.pointsVec<SetCurvePointInput>Array of curve points with amount_in, price_factor_q32, optional interpolation and params
params.slotOption<u8>Target prefab slot (default: 0)
params.x_modeOption<CurveXMode>X-axis mode

set_risk_curve

Write a risk curve using percent-of-vault x-axis.
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.default_interpolationInterpolationInterpolation mode
params.pointsVec<SetRiskCurvePointInput>Points with pct_base_q32, price_factor_q32, etc.
params.slotOption<u8>Target prefab slot
params.x_modeOption<CurveXMode>X-axis mode
params.risk_modeOption<RiskMode>Virtual or Integrated

set_risk_curve_absolute

Write a risk curve using absolute token amounts on the x-axis.
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.default_interpolationInterpolationInterpolation mode
params.pointsVec<SetRiskCurveAbsolutePointInput>Points with vault_balance, price_factor_q32, etc.
params.slotOption<u8>Target prefab slot
params.risk_modeOption<RiskMode>Virtual or Integrated

switch_price_curve / switch_risk_curve

Activate a previously written curve slot (hot path — no curve data uploaded).
let ix1 = pool.switch_price_curve(&authority, &SwitchCurveParams { side: Side::Bid, slot: 1 });
let ix2 = pool.switch_risk_curve(&authority, &SwitchCurveParams { side: Side::Ask, slot: 2 });
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.slotu8Slot to activate

submit_curve_updates / apply_curve_updates

Two-step batched curve editing. Submit a list of point edits, then apply them.
let ix1 = pool.submit_curve_updates(&authority, &[
    CurveUpdateOp {
        curve_type: CurveType::PriceBid,
        op_kind: CurveUpdateOpKind::Edit,
        point_index: 0,
        interpolation: Interpolation::Linear,
        amount_in: 200_000,
        price_factor_q32: to_q32(0.98),
        params: [0; 4],
    },
]);
let ix2 = pool.apply_curve_updates(&authority);

Oracle management

update_midprice

use hadron_sdk::types::UpdateMidpriceParams;

let ix = pool.update_midprice(&authority, &UpdateMidpriceParams {
    midprice_q32: to_q32(1.05),
    sequence: None,
});
ParamTypeDescription
params.midprice_q32u64New midprice in Q32 format
params.sequenceOption<u64>Optional sequence number for ordering

update_base_spread

use hadron_sdk::types::UpdateBaseSpreadParams;

let ix = pool.update_base_spread(&authority, &UpdateBaseSpreadParams {
    spread_factor_q32: spread_bps_to_q32(5), // 5 bps
    sequence: None,
});
ParamTypeDescription
params.spread_factor_q32u64Spread discount factor in Q32 (e.g. spread_bps_to_q32(5) = 5 bps)
params.sequenceOption<u64>Optional sequence number

update_midprice_and_base_spread

Atomic update of both values in a single instruction.
use hadron_sdk::types::UpdateMidpriceAndBaseSpreadParams;

let ix = pool.update_midprice_and_base_spread(&authority, &UpdateMidpriceAndBaseSpreadParams {
    midprice_q32: to_q32(1.05),
    spread_factor_q32: spread_bps_to_q32(5),
    sequence: None,
});

Admin

nominate_authority / accept_authority

Two-step authority transfer.
use hadron_sdk::types::NominateAuthorityParams;

let ix1 = pool.nominate_authority(&authority, &NominateAuthorityParams {
    new_authority: new_pk,
    expiry_slot: 300_000_000,
});
// ... new_authority signs:
let ix2 = pool.accept_authority(&new_pk);

set_pool_state

use hadron_sdk::types::{SetPoolStateParams, PoolState};

let ix = pool.set_pool_state(&authority, &SetPoolStateParams {
    new_state: PoolState::Paused,
});
States: Uninitialized, Initialized, Paused, WithdrawOnly

update_delta_staleness

use hadron_sdk::types::UpdateDeltaStalenessParams;

let ix = pool.update_delta_staleness(&authority, &UpdateDeltaStalenessParams {
    delta_staleness: 150,
});

close_pool

Closes the pool and reclaims rent. Requires authority and all vaults to be empty.
let ix = pool.close_pool(&authority);

Properties

These are available on any Hadron instance:
PropertyTypeDescription
pool.program_idPubkeyProgram ID
pool.pool_addressPubkeyThe pool’s on-chain address
pool.addressesPoolAddressesAll derived PDA addresses for this pool
pool.configDecodedConfigDecoded config account data
pool.oracleDecodedMidpriceOracleDecoded oracle data
pool.curve_metaDecodedCurveMetaDecoded curve metadata
pool.curve_prefabs_dataVec<u8>Raw curve prefabs data (decode with get_active_curves())