hadron-sdk 0.2.1

Rust client SDK for the Hadron protocol
Documentation
use solana_sdk::pubkey;
use solana_sdk::pubkey::Pubkey;

// ============================================================================
// Program
// ============================================================================

pub const HADRON_PROGRAM_ID: Pubkey = pubkey!("Q72w4coozA552keKDdeeh2EyQw32qfMFsHPu6cbatom");

// ============================================================================
// PDA Seeds
// ============================================================================

pub const CONFIG_SEED: &[u8] = b"hadron-config";
pub const MIDPRICE_ORACLE_SEED: &[u8] = b"hadron-midprice";
pub const CURVE_META_SEED: &[u8] = b"hadron-curve-meta";
pub const CURVE_PREFABS_SEED: &[u8] = b"hadron-curve-prefabs";
pub const CURVE_UPDATES_SEED: &[u8] = b"hadron-curve-updates";
pub const FEE_CONFIG_SEED: &[u8] = b"fee_config";
pub const SPREAD_CONFIG_SEED: &[u8] = b"spread_config";

// ============================================================================
// Account Sizes
// ============================================================================

pub const CONFIG_SIZE: usize = 248;
pub const MIDPRICE_ORACLE_SIZE: usize = 64;
pub const CURVE_META_SIZE: usize = 48;
pub const FEE_CONFIG_SIZE: usize = 72;
pub const CURVE_UPDATES_SIZE: usize = 258;
pub const CURVE_SIDE_HEADER: usize = 8;
pub const CURVE_POINT_LEN: usize = 24;

// ============================================================================
// Pool Parameter Defaults & Limits
// ============================================================================

pub const DEFAULT_MAX_PREFAB_SLOTS: u8 = 10;
pub const DEFAULT_MAX_CURVE_POINTS: u8 = 16;
pub const ABSOLUTE_MAX_PREFAB_SLOTS: u8 = 16;
pub const ABSOLUTE_MAX_CURVE_POINTS: u8 = 128;
pub const MAX_SETCURVE_POINTS: u8 = 32;
pub const MAX_CURVE_UPDATE_OPS: u8 = 8;

// ============================================================================
// Fixed-Point Math
// ============================================================================

/// Q32.32 representation of 1.0
pub const Q32_ONE: u64 = 1u64 << 32; // 4294967296

// ============================================================================
// Instruction Discriminators
// ============================================================================

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum Discriminator {
    Initialize = 0,
    Deposit = 1,
    Withdraw = 2,
    SwapExactIn = 3,
    SetCurve = 4,
    UpdateMidprice = 5,
    InitializeFeeConfig = 6,
    UpdateFeeConfig = 7,
    SetRiskCurve = 8,
    UpdateBaseSpread = 9,
    UpdateMidpriceAndBaseSpread = 10,
    SwitchPriceCurve = 11,
    SwitchRiskCurve = 12,
    InitializeSpreadConfig = 13,
    UpdateSpreadConfig = 14,
    UpdateDeltaStaleness = 15,
    NominateAuthority = 16,
    AcceptAuthority = 17,
    SubmitCurveUpdates = 18,
    ApplyCurveUpdates = 19,
    ClosePool = 20,
    SetPoolState = 21,
    AllocateCurvePrefabs = 22,
    SetQuotingAuthority = 23,
    RotateFeeAdmin = 24,
    InitializePoolFeeConfig = 25,
    UpdatePoolFeeConfig = 26,
}

// ============================================================================
// Instruction Data Sizes
// ============================================================================

/// Per-point data in SetCurve/SetRiskCurve: u64 + u64 + u8 + 4 params = 21 bytes
pub const POINT_DATA_SIZE: usize = 21;

/// Per-op data in SubmitCurveUpdates: curve_type(1)+op_kind(1)+point_index(1)+interp(1)+amount_in(8)+price(8)+params(4) = 24 bytes
pub const CURVE_UPDATE_OP_SIZE: usize = 24;

// ============================================================================
// Size Helpers
// ============================================================================

/// Compute CurvePrefabs account size for given pool parameters.
pub fn curve_prefabs_size(max_slots: u8, max_points: u8) -> usize {
    32 + 4 * (max_slots as usize) * (CURVE_SIDE_HEADER + (max_points as usize) * CURVE_POINT_LEN)
}