Skip to main content
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 upto 10 prefabs for each curve (40 total) on Hadron.

How Prefabs Work:

Concepts:
  • Slot (0–9): 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: "ask", slot: 0 or 1.
  • 1. Set an ask curve into slot 0 with (e.g. tight spread)
const setAskSlot0Ix = buildSetCurveInstruction(
    HADRON_PROGRAM_ID,
    authority.publicKey,
    curveMetaPda,
    curvePrefabsPda,
    /* slot */ 0,
    "ask",
    [
        { xIn: 0n, priceFactor: 1.0010, interpolation: "step" },
        { xIn: 1000n, priceFactor: 1.0020, interpolation: "linear" },
        { xIn: 2000n, priceFactor: 1.0050, interpolation: "linear" },
        { xIn: 5000n, priceFactor: 1.0100, interpolation: "step" },
        { xIn: 10000n, priceFactor: 1.0150, interpolation: "step" },
    ]
);
  • 2. Set a different ask curve into slot 1 (e.g. wide spread)
// Same structure, wider spreads (e.g. 50, 100, 200, 400, 600 bps)
// Slot 1 = "wide" strategy

const setAskSlot1Ix = buildSetCurveInstruction(
    HADRON_PROGRAM_ID, authority.publicKey,
    curveMetaPda,
    curvePrefabsPda,
    /* slot */ 1,
    "ask",
    [
        { xIn: 0n, priceFactor: 1.0050, interpolation: "step" },
        { xIn: 1000n, priceFactor: 1.0100, interpolation: "linear" },
        { xIn: 2000n, priceFactor: 1.0200, interpolation: "linear" },
        { xIn: 5000n, priceFactor: 1.0400, interpolation: "step" },
        { xIn: 10000n, priceFactor: 1.0600, 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 side and slot. The program updates the active slot index
// Switch ask risk curve to slot 1 (~38 CUs)

const switchRiskAskIx = buildSwitchRiskCurveInstruction(
    HADRON_PROGRAM_ID,
    authority.publicKey,
    curveMetaPda,
    /* side */ 1,  // ask
    /* slot */ 0
);