hadron-sdk
Rust client SDK for the Hadron protocol on Solana.
Build, sign, and send instructions for Hadron AMM pools — deposits, withdrawals, swaps, curve management, oracle updates, and more.
Usage
[dependencies]
hadron-sdk = "0.1"
hadron-sdk = { version = "0.1", features = ["rpc"] }
Load an existing pool (with rpc feature)
use hadron_sdk::Hadron;
use solana_client::rpc_client::RpcClient;
use solana_sdk::pubkey::Pubkey;
let rpc = RpcClient::new("https://api.mainnet-beta.solana.com");
let pool_address: Pubkey = "...".parse().unwrap();
let pool = Hadron::load(&rpc, &pool_address).unwrap();
println!("Midprice: {}", pool.get_midprice());
println!("Spread: {} bps", pool.get_spread_bps());
Load from raw account data (no RPC dependency)
use hadron_sdk::Hadron;
let pool = Hadron::from_accounts(
pool_address,
&config_data,
&oracle_data,
&curve_meta_data,
&curve_prefabs_data,
).unwrap();
Build a swap instruction
use hadron_sdk::{Hadron, SwapParams};
let ix = pool.swap(&user_pubkey, &SwapParams {
is_x: true,
amount_in: 1_000_000,
min_out: 950_000,
fee_recipient,
expiration: None,
});
Initialize a new pool
use hadron_sdk::{Hadron, InitializeParams, helpers::math::to_q32};
let (instructions, pool_address, seed) = Hadron::initialize(
&payer,
&InitializeParams {
seed: None, mint_x,
mint_y,
authority: payer,
initial_midprice_q32: to_q32(100.0),
oracle_mode: None,
max_prefab_slots: None,
max_curve_points: None,
token_program_x: None,
token_program_y: None,
},
&hadron_sdk::HADRON_PROGRAM_ID,
);
Set price curves
use hadron_sdk::{Interpolation, Side, SetCurvePointInput, SetCurveBothParams, SetCurveHalfParams};
use hadron_sdk::helpers::math::to_q32;
let [bid_ix, ask_ix] = pool.set_curve_both(&authority, &SetCurveBothParams {
bid: SetCurveHalfParams {
default_interpolation: Interpolation::Linear,
points: vec![
SetCurvePointInput { amount_in: 0, price_factor_q32: to_q32(0.999), interpolation: None, params: None },
SetCurvePointInput { amount_in: 1_000_000, price_factor_q32: to_q32(0.995), interpolation: None, params: None },
],
slot: None,
x_mode: None,
},
ask: SetCurveHalfParams {
default_interpolation: Interpolation::Linear,
points: vec![
SetCurvePointInput { amount_in: 0, price_factor_q32: to_q32(0.999), interpolation: None, params: None },
SetCurvePointInput { amount_in: 1_000_000, price_factor_q32: to_q32(0.995), interpolation: None, params: None },
],
slot: None,
x_mode: None,
},
});
Features
| Feature |
Description |
| (default) |
Instruction builders, account decoders, PDA derivation, math helpers |
rpc |
Adds Hadron::load(), load_from_seed(), refetch_states() via solana-client |
License
Apache-2.0