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

# Configuring Your Pool

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.

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

```rust theme={null}
use hadron_sdk_v2::types::UpdateBaseSpreadParams;
use hadron_sdk_v2::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,
});
```

| **Param**                  | **Type**      | **Description**                                                      |
| -------------------------- | ------------- | -------------------------------------------------------------------- |
| `params.spread_factor_q32` | `u64`         | Spread discount factor in Q32 — use `spread_bps_to_q32(n)` for n bps |
| `params.sequence`          | `Option<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.

```rust theme={null}
use hadron_sdk_v2::types::*;
use hadron_sdk_v2::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,
});
```

| **Param**                      | **Type**                  | **Description**                                                     |
| ------------------------------ | ------------------------- | ------------------------------------------------------------------- |
| `authority`                    | `&Pubkey`                 | Pool authority                                                      |
| `params.side`                  | `Side`                    | `Bid` or `Ask`                                                      |
| `params.default_interpolation` | `Interpolation`           | See interpolation types below                                       |
| `params.points`                | `Vec<SetCurvePointInput>` | Array of `{ amount_in, price_factor_q32, interpolation?, params? }` |
| `params.slot`                  | `Option<u8>`              | Target prefab slot (default: 0)                                     |
| `params.x_mode`                | `Option<CurveXMode>`      | X-axis mode: `Native` (token atoms) or `Alternate`                  |

**Returns** `Instruction`

### Interpolation Types

| **Type**       | **Description**                                                      |
| -------------- | -------------------------------------------------------------------- |
| `Step`         | Flat price until the next point — staircase shape                    |
| `Linear`       | Straight line between points                                         |
| `MarginalStep` | Step applied to the marginal (last unit) rather than the whole order |
| `Hyperbolic`   | Smooth curve with configurable curvature                             |
| `Quadratic`    | Parabolic curve between points                                       |
| `Cubic`        | Cubic spline between points                                          |

***

## switchPriceCurve

Switch between different price curves in a single instruction. Up to 16 per curve side (set at pool initialization).

```rust theme={null}
let ix = pool.switch_price_curve(&authority, &SwitchCurveParams {
    sequence: 1, // must be >= pool.curve_meta.switch_sequence
    side: Side::Bid,
    slot: 1,
});
```

| **Param**         | **Type**  | **Description**                                                                                             |
| ----------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
| `authority`       | `&Pubkey` | Pool authority                                                                                              |
| `params.sequence` | `u64`     | Monotonic ordering guard. Must be ≥ the pool's current switch sequence (`pool.curve_meta.switch_sequence`). |
| `params.side`     | `Side`    | `Bid` or `Ask`                                                                                              |
| `params.slot`     | `u8`      | Slot index to activate                                                                                      |

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

## setRiskCurve

Write a risk curve using percent-of-vault on the x-axis. Risk curves adjust price based on your current inventory position.

```rust theme={null}
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
});
```

| **Param**                      | **Type**                      | **Description**                                                                 |
| ------------------------------ | ----------------------------- | ------------------------------------------------------------------------------- |
| `authority`                    | `&Pubkey`                     | Pool authority                                                                  |
| `params.side`                  | `Side`                        | `Bid` or `Ask`                                                                  |
| `params.default_interpolation` | `Interpolation`               | Interpolation mode                                                              |
| `params.points`                | `Vec<SetRiskCurvePointInput>` | Points with `pct_base_q32` (0.0–1.0 as Q32), `price_factor_q32`                 |
| `params.slot`                  | `Option<u8>`                  | Target prefab slot                                                              |
| `params.risk_mode`             | `Option<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.

```rust theme={null}
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,
});
```

| **Param**                      | **Type**                              | **Description**                                            |
| ------------------------------ | ------------------------------------- | ---------------------------------------------------------- |
| `authority`                    | `&Pubkey`                             | Pool authority                                             |
| `params.side`                  | `Side`                                | `Bid` or `Ask`                                             |
| `params.default_interpolation` | `Interpolation`                       | Interpolation mode                                         |
| `params.points`                | `Vec<SetRiskCurveAbsolutePointInput>` | Points with `vault_balance` (in atoms), `price_factor_q32` |
| `params.slot`                  | `Option<u8>`                          | Target prefab slot                                         |
| `params.risk_mode`             | `Option<RiskMode>`                    | `Virtual` or `Integrated`                                  |

***

## switchRiskCurve

Switch between different risk curves in a single instruction. Up to 16 per curve side (set at pool initialization).

```rust theme={null}
let ix = pool.switch_risk_curve(&authority, &SwitchCurveParams {
    sequence: 1, // must be >= pool.curve_meta.switch_sequence
    side: Side::Ask,
    slot: 2,
});
```

| **Param**         | **Type**  | **Description**                                                                                             |
| ----------------- | --------- | ----------------------------------------------------------------------------------------------------------- |
| `authority`       | `&Pubkey` | Pool authority                                                                                              |
| `params.sequence` | `u64`     | Monotonic ordering guard. Must be ≥ the pool's current switch sequence (`pool.curve_meta.switch_sequence`). |
| `params.side`     | `Side`    | `Bid` or `Ask`                                                                                              |
| `params.slot`     | `u8`      | Slot 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.

```rust theme={null}
use hadron_sdk_v2::types::{CurveUpdateOp, CurveUpdateOpKind, CurveType};

// `sequence` must be >= the CurveUpdates account's current sequence (monotonic guard).
let ix1 = pool.submit_curve_updates(&authority, 1, &[
    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],
        target_slot: 0,      // active slot this op targets — apply rejects on mismatch
        expected_x_in: 0,    // expected current x_in at point_index (ignored for Add)
    },
]);
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.

<Tip>
  For a visual helper please visit [https://dashboard.hadron.fi/curves](https://dashboard.hadron.fi/curves)
</Tip>
