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

# Prefabs

> Pre-built curves for advanced makers

Prefabs allow operators to save multiple curves in the contract, allowing them to switch between strategies by only updating a single parameter in the instruction. This allows for switching between vastly different (or similar) quoting functions and risk curves in under 40 CUs. Makers can store up to 16 prefabs for each curve (64 total) on Hadron, set at pool initialization (2 by default).

## How Prefabs Work:

Concepts:

* **Slot (0 to maxPrefabSlots−1, up to 0–15):** Which prefab slot to write to (SetCurve / SetRiskCurve) or to activate (SwitchPriceCurve / SwitchRiskCurve).
* **Side:** `bid` (0) or `ask` (1). Price and risk curves have one active slot per side
* **Active slot:** The slot index currently used for quoting. Swap reads the active curve from prefabs by this index.

## Example: Switching between multiple price and risk curves

Store two ask curves in different slots (e.g. slot 0 = tight spread, slot 1 = wide spread). Then switch the active ask curve by sending a single **SwitchPriceCurve** instruction with `side: Side.Ask`, `slot: 0` or `1`.

* *1. Set an ask curve into slot 0 with (e.g. tight spread)*

```typescript theme={null}
// `pool` is a loaded Hadron instance; `authority` is the pool authority (see SDK ▸ Quickstart)
const setAskSlot0Ix = pool.setCurve(authority, {
    side: Side.Ask,
    defaultInterpolation: Interpolation.Linear,
    slot: 0,
    points: [
        { amountIn: 0n, priceFactor: 1.0010, interpolation: Interpolation.Step },
        { amountIn: 1000n, priceFactor: 1.0020, interpolation: Interpolation.Linear },
        { amountIn: 2000n, priceFactor: 1.0050, interpolation: Interpolation.Linear },
        { amountIn: 5000n, priceFactor: 1.0100, interpolation: Interpolation.Step },
        { amountIn: 10000n, priceFactor: 1.0150, interpolation: Interpolation.Step },
    ],
});
```

* *2. Set a different ask curve into slot 1 (e.g. wide spread)*

```typescript theme={null}
// Same structure, wider spreads (e.g. 50, 100, 200, 400, 600 bps)
// Slot 1 = "wide" strategy

const setAskSlot1Ix = pool.setCurve(authority, {
    side: Side.Ask,
    defaultInterpolation: Interpolation.Linear,
    slot: 1,
    points: [
        { amountIn: 0n, priceFactor: 1.0050, interpolation: Interpolation.Step },
        { amountIn: 1000n, priceFactor: 1.0100, interpolation: Interpolation.Linear },
        { amountIn: 2000n, priceFactor: 1.0200, interpolation: Interpolation.Linear },
        { amountIn: 5000n, priceFactor: 1.0400, interpolation: Interpolation.Step },
        { amountIn: 10000n, priceFactor: 1.0600, interpolation: Interpolation.Step },
    ],
});
```

* *3. Switch the active ask curve to slot 0 or 1 (one parameter, \~38 CUs)*\*
  * No curve data is sent in the switch instruction—only `sequence`, `side`, and `slot`. The program updates the active slot index

```typescript theme={null}
// Switch active ask price curve to slot 1 (~38 CUs)

const switchPriceAskIx = pool.switchPriceCurve(authority, {
    sequence: 1n,   // must be >= pool.curveMeta.switchSequence
    side: Side.Ask,
    slot: 1,
});
```
