> ## 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.

# Hadron Quickstart

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](https://docs.hadron.fi/llms.txt)

## Install

```toml theme={null}
# Cargo.toml
hadron-sdk-v2 = "0.1"
solana-sdk = "3"
```

Or via cargo:

```bash theme={null}
cargo add hadron-sdk-v2
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.

```rust theme={null}
use hadron_sdk_v2::hadron::Hadron;
use hadron_sdk_v2::types::InitializeParams;
use hadron_sdk_v2::helpers::math::to_q32;
use hadron_sdk_v2::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,
    creator: None,                       // defaults to `authority` (signer of AllocateCurvePrefabs)
    initial_midprice_q32: to_q32(1.0),  // midprice = 1.0
    lp_self_rotate: false,               // false = custodial (admin can rotate LP authorities)
    max_prefab_slots: None,              // default: 2 — cannot be changed after init
    max_curve_points: None,              // default: 16 — cannot be changed after init
    combined_factor_max_q32: None,       // defaults to Q32_ONE (1.0)
    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.creator`                 | `Option<Pubkey>` | Creator of the curve prefabs account (must sign `AllocateCurvePrefabs`). Defaults to `authority`.                                |
| `params.initial_midprice_q32`    | `u64`            | Starting midprice in Q32 format — use `to_q32(price)`                                                                            |
| `params.lp_self_rotate`          | `bool`           | `false` = custodial (admin can rotate deposit/withdraw authorities); `true` = only the LP role-holder can. Immutable after init. |
| `params.max_prefab_slots`        | `Option<u8>`     | Max curve prefab slots, 1–16. **Cannot be changed after init.** Default: 2                                                       |
| `params.max_curve_points`        | `Option<u8>`     | Max points per curve, 1–128. **Cannot be changed after init.** Default: 16                                                       |
| `params.combined_factor_max_q32` | `Option<u64>`    | Hard ceiling on the combined price×risk factor. Defaults to `Q32_ONE` (1.0).                                                     |
| `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.

```rust theme={null}
use hadron_sdk_v2::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 fee_config_data = rpc.get_account_data(&fee_config_pda)?; // pool-specific or global

let pool = Hadron::from_accounts(
    pool_address,
    &config_data,
    &oracle_data,
    &meta_data,
    &prefabs_data,
    &fee_config_data,
)?;
```

> **RPC convenience loader**

> Enable the `rpc` feature for a one-liner: `cargo add hadron-sdk-v2 --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.

```rust theme={null}
use hadron_sdk_v2::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 |

***

## Depositing Funds

Build a deposit instruction.

```rust theme={null}
use hadron_sdk_v2::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.

```rust theme={null}
use hadron_sdk_v2::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                 |
