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.

All Hadron pools have price and risk curves which encode your trading strategy into the on-chain PDA. You describe a quoting function — the midprice, how price changes with trade size, how price shifts with inventory — and Hadron runs it on chain.

Q32 Fixed-Point Format

Many curve and oracle params use Q32 (Q32.32) format. This is a fixed-point number where the value is stored as an integer scaled by 2^32.
use hadron_sdk::helpers::math::{to_q32, spread_bps_to_q32};

let midprice = to_q32(1.05);       // real value → Q32
let spread   = spread_bps_to_q32(5); // 5 bps spread factor
Use to_q32() for prices and price factors. Use spread_bps_to_q32() for spread values.

updateBaseSpread

Add a flat pool-level fee to all swaps.
use hadron_sdk::types::UpdateBaseSpreadParams;
use hadron_sdk::helpers::math::spread_bps_to_q32;

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 — use spread_bps_to_q32(n) for n bps
params.sequenceOption<u64>Optional sequence number for ordering concurrent updates

Creating Price Curves

Write a price curve to a prefab slot. Curves define how price moves relative to the midprice as trade size increases.
  • amount_in: Amount in atoms (smallest token unit based on token decimals). Stored as u64.
  • price_factor_q32: Distance from midprice — use to_q32(factor) where 1.0 = midprice, 0.99 = 1% below.
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,                    // for an input of 0.1 tokens (6 decimals)
            price_factor_q32: to_q32(0.99),        // quote at 1% below mid
            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_interpolationInterpolationSee interpolation types below
params.pointsVec<SetCurvePointInput>Array of { amount_in, price_factor_q32, interpolation?, params? }
params.slotOption<u8>Target prefab slot (default: 0)
params.x_modeOption<CurveXMode>X-axis mode: Native (token atoms) or Alternate
Returns Instruction

Interpolation Types

TypeDescription
StepFlat price until the next point — staircase shape
LinearStraight line between points
MarginalStepStep applied to the marginal (last unit) rather than the whole order
HyperbolicSmooth curve with configurable curvature
QuadraticParabolic curve between points
CubicCubic spline between points

switchPriceCurve

Switch between different price curves in a single instruction. Up to 10 per curve side (set at pool initialization).
let ix = pool.switch_price_curve(&authority, &SwitchCurveParams {
    side: Side::Bid,
    slot: 1,
});
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.slotu8Slot index to activate
Hadron protocol fees are added at the pool level to all pools and need to be factored into pools to remain competitive. For the latest fee rates go to https://docs.hadron.fi/fees

setRiskCurve

Write a risk curve using percent-of-vault on the x-axis. Risk curves adjust price based on your current inventory position.
let ix = pool.set_risk_curve(&authority, &SetRiskCurveParams {
    side: Side::Bid,
    default_interpolation: Interpolation::Linear,
    points: vec![
        SetRiskCurvePointInput {
            pct_base_q32: to_q32(0.25),        // 25% of vault
            price_factor_q32: to_q32(0.995),
            interpolation: None,
            params: None,
        },
        SetRiskCurvePointInput {
            pct_base_q32: to_q32(0.75),
            price_factor_q32: to_q32(1.005),
            interpolation: None,
            params: None,
        },
    ],
    slot: Some(0),
    x_mode: None,
    risk_mode: None,                           // default: Virtual
});
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.default_interpolationInterpolationInterpolation mode
params.pointsVec<SetRiskCurvePointInput>Points with pct_base_q32 (0.0–1.0 as Q32), price_factor_q32
params.slotOption<u8>Target prefab slot
params.risk_modeOption<RiskMode>Virtual (uses notional inventory) or Integrated (uses actual vault balance)

setRiskCurveAbsolute

Write a risk curve using absolute token amounts on the x-axis instead of percentages.
let ix = pool.set_risk_curve_absolute(&authority, &SetRiskCurveAbsoluteParams {
    side: Side::Ask,
    default_interpolation: Interpolation::Step,
    points: vec![
        SetRiskCurveAbsolutePointInput {
            vault_balance: 1_000_000_000,
            price_factor_q32: to_q32(1.002),
            interpolation: None,
            params: None,
        },
        SetRiskCurveAbsolutePointInput {
            vault_balance: 2_000_000_000,
            price_factor_q32: to_q32(1.006),
            interpolation: None,
            params: None,
        },
    ],
    slot: Some(0),
    risk_mode: None,
});
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.default_interpolationInterpolationInterpolation mode
params.pointsVec<SetRiskCurveAbsolutePointInput>Points with vault_balance (in atoms), price_factor_q32
params.slotOption<u8>Target prefab slot
params.risk_modeOption<RiskMode>Virtual or Integrated

switchRiskCurve

Switch between different risk curves in a single instruction. Up to 10 per curve side (set at pool initialization).
let ix = pool.switch_risk_curve(&authority, &SwitchCurveParams {
    side: Side::Ask,
    slot: 2,
});
ParamTypeDescription
authority&PubkeyPool authority
params.sideSideBid or Ask
params.slotu8Slot index to activate

submit_curve_updates / apply_curve_updates

Two-step batched curve editing for modifying individual points without rewriting an entire curve. Submit a list of edits, then apply them atomically.
use hadron_sdk::types::{CurveUpdateOp, CurveUpdateOpKind, CurveType};

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);
// Send ix1, confirm, then send ix2
Buffer limit If error CurveUpdatesBufferFull (code 46) is returned, call apply_curve_updates to flush before submitting more.
For a visual helper please visit https://dashboard.hadron.fi/curves