Skip to main content

Defining mid-price

Defining and updating mid-price on Hadron has three variables
  • Input: Mid-price is defined in quote atoms per base atom
  • Sequence: Sequence is a nonce sent by the operator to prevent stale quotes from block builders re-ordering transactions. Instructions with a sequence strictly less than the current sequence will be fail.
  • Base spread (optional): Operators can initialize an optional base spread with the mid-price update.
//Updating a midprice of 117.20 and base spread of 5bps

const ix = buildUpdateMidpriceInstruction(
    HADRON_PROGRAM_ID,
    authority.publicKey,
    midpriceOraclePda,
    1n,                                  // sequence = 1
    uiPriceToMidpriceQ32(117.20, 9, 6)   // $117.20 SOL/USDC
    bpsToBaseSpreadQ32(5)                // 5 Bps base spread
);

Building Bid and Ask Curves

Simple 3 point curve Points on Hadron are a function of 3 input values:
  • Volume: Input volume in atoms
  • Spread: Distance from the Mid-price
  • Interpolation mode: Moving between any two points
// 3 point bid curve with a midprice of 1.00
// Points: Input Amount 0 (base), 1000, 2000 units
// Spread of 10, 20, 50 Bps from Mid 
// Interpolating step wise for all 3 points

const ix = buildSetCurveInstruction(
    HADRON_PROGRAM_ID,
    authority.publicKey,
    configPda,
    "bid",									  // curve side
    "step", 								  // interpolation mode
    [
        { xIn: 0n,    priceFactor: 0.9990 },  // 0-1000: 10bps fee
        { xIn: 1000n, priceFactor: 0.9980 },  // 1000-5000: 20bps fee
        { xIn: 5000n, priceFactor: 0.9950 },  // 5000+: 50bps fee
    ]
);

Curve Visualization:

Bid Ask