Skip to main content
Example Three: Mixed curve with inventory curve logic Let’s take the same curve as before and add an inventory skew curve to this 5 point mixed curve. Risk curves have three input values:
  • Base/Quote Amount: Quantum of inventory. This can be expressed in two ways
    • Base/Quote Percentage: This is the relative percentage between Base and Quote amounts, normalized by your mid-price. (basePct + quotePct = 1)
    • Base/Quote Amount: This is an absolute amount of tokens expressed as atoms
  • Price Factor: Basis points added to the swap based on the value of inventory
  • Interpolation: Shape of the curve between two base/quote points
// 5 point ask curve with a midprice of 1.00
// Points: Input Amount 0 (base), 1000, 2000, 5000, 10000 units
// Spread of 10, 20, 50, 100, 150 Bps from Mid 
// Mixed Interpolation across points 
// Initialize risk curve below yellow line

// Same curve as previous example
const askCurveIx = buildSetCurveInstruction(
    HADRON_PROGRAM_ID,
    authority.publicKey,
    configPda,
    "ask",
    [
        { xIn: 0n,     priceFactor: 1.0010, interpolation: "step" },          // 10bps
        { xIn: 1000n,  priceFactor: 1.0020, interpolation: "linear" },        // 20bps
        { xIn: 2000n,  priceFactor: 1.0050, interpolation: "linear" },        // 50bps
        { xIn: 5000n,  priceFactor: 1.0100, interpolation: "step" }, 		  // 100bps
        { xIn: 10000n, priceFactor: 1.0150, interpolation: "step" },          // 150bps
    ]
);
// --------------------------------------------------------------------------- // 


const riskAskCurveIx = buildSetRiskCurveInstruction(
  HADRON_PROGRAM_ID,
  authority.publicKey,
  configPda,
  "bid",
  [
    { pctBase: 0.0,  priceFactor: 1.0050, interpolation: "linear" },
    { pctBase: 0.25, priceFactor: 1.0025, interpolation: "linear" },
    { pctBase: 0.50, priceFactor: 1.0000, interpolation: "linear" }, // optional
    { pctBase: 0.75, priceFactor: 0.9975, interpolation: "linear" },
    { pctBase: 1.0,  priceFactor: 0.9900, interpolation: "linear" },
  ],
  "ask",
  [
    { pctBase: 0.0,  priceFactor: 0.9900, interpolation: "linear" },
    { pctBase: 0.25, priceFactor: 0.9975, interpolation: "linear" },
    { pctBase: 0.50, priceFactor: 1.0000, interpolation: "linear" }, // optional
    { pctBase: 0.75, priceFactor: 1.0025, interpolation: "linear" },
    { pctBase: 1.0,  priceFactor: 1.0050, interpolation: "linear" },
  ],
);
Let’s now visualize these curves - try dragging the inventory slider: