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.
Install and use the Hadron Rust SDK in a few minutes.
Documentation Index
Fetch the complete documentation index at: https://docs.hadron.fi/llms.txt
Install
# Cargo.toml
hadron-sdk = "latest"
solana-sdk = "latest"
Or via cargo:
cargo add hadron-sdk
cargo add solana-sdk
The SDK requires solana-sdk for Pubkey and Instruction types.
Initializing a Pool
Initialising a Hadron pool gives you your own propAMM instance.
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; use Some(n) for deterministic address
mint_x,
mint_y,
authority: payer,
initial_midprice_q32: to_q32(1.0), // midprice = 1.0
oracle_mode: None, // default: Authority (you push updates)
max_prefab_slots: None, // default: 10 — cannot be changed after init
max_curve_points: None, // default: 16 — cannot be changed after init
token_program_x: None, // default: SPL Token; pass Token-2022 pubkey if needed
token_program_y: None,
}, &HADRON_PROGRAM_ID);
// Send the instructions (group into transactions as needed)
Two transactions required
With default parameters the CurvePrefabs account is ~15 KB. Two allocate instructions are returned because Solana’s single-instruction realloc limit is 10 KB. Send the allocates first in one transaction, then send the initialize instruction.
| Param | Type | Description |
|---|
payer | &Pubkey | Transaction fee payer and account funder |
params.seed | Option<u64> | Pool seed. Auto-generated if None. Allows multiple pools per token pair. |
params.mint_x | Pubkey | Base token mint |
params.mint_y | Pubkey | Quote token mint |
params.authority | Pubkey | Pool authority (manages curves, oracle, state) |
params.initial_midprice_q32 | u64 | Starting midprice in Q32 format — use to_q32(price) |
params.max_prefab_slots | Option<u8> | Max curve prefab slots, 1–16. Cannot be changed after init. Default: 10 |
params.max_curve_points | Option<u8> | Max points per curve, 1–128. Cannot be changed after init. Default: 16 |
params.token_program_x | Option<Pubkey> | Token program for X — SPL Token or Token-2022. Default: SPL Token |
params.token_program_y | Option<Pubkey> | Token program for Y — SPL Token or Token-2022. Default: SPL Token |
Returns (Vec<Instruction>, Pubkey, u64) — instructions, pool address, seed
Loading an Existing Pool
The Rust SDK is sync-first — you provide raw account data and it decodes everything locally. No async required.
use hadron_sdk::hadron::Hadron;
// Fetch account data however you like (RPC, Geyser, websocket, etc.)
// let config_data = rpc.get_account_data(&pool_address)?;
// let oracle_data = rpc.get_account_data(&oracle_pda)?;
// let meta_data = rpc.get_account_data(&curve_meta_pda)?;
// let prefabs_data = rpc.get_account_data(&curve_prefabs_pda)?;
let pool = Hadron::from_accounts(
pool_address,
&config_data,
&oracle_data,
&meta_data,
&prefabs_data,
)?;
RPC convenience loader
Enable the rpc feature for a one-liner: cargo add hadron-sdk --features rpc
Then call Hadron::load(&rpc_client, &pool_address) which fetches all accounts automatically.
setPoolState
Pools are initialised by default as RejectSwaps. This lets you deposit funds before the pool is indexed by aggregators.
use hadron_sdk::types::{SetPoolStateParams, PoolState};
let ix = pool.set_pool_state(&authority, &SetPoolStateParams {
new_state: PoolState::Initialized,
});
| State | Description |
|---|
Initialized | Pool is live and will be indexed by aggregators |
RejectSwaps | Swaps are rejected; deposits and withdrawals still allowed |
Paused | All operations paused — no swaps, deposits, or withdrawals |
WithdrawOnly | Only withdrawals permitted |
Depositing Funds
Build a deposit instruction.
use hadron_sdk::types::DepositParams;
let ix = pool.deposit(&user, &DepositParams {
amount_x: 1_000_000, // in atoms (smallest token unit)
amount_y: 2_000_000,
expiration: None, // optional slot deadline
});
| Param | Type | Description |
|---|
user | &Pubkey | The user’s wallet |
params.amount_x | u64 | Amount of token X to deposit (in atoms) |
params.amount_y | u64 | Amount of token Y to deposit (in atoms) |
params.expiration | Option<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,
});
| Param | Type | Description |
|---|
user | &Pubkey | The user’s wallet |
params.amount_x | u64 | Amount of token X to withdraw (in atoms) |
params.amount_y | u64 | Amount of token Y to withdraw (in atoms) |
params.expiration | Option<i64> | Optional slot expiration |