@percolatorct/sdk 1.0.0-beta.12 → 1.0.0-beta.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1573,7 +1573,21 @@ var V12_1_ACCOUNT_SIZE_SBF = 280;
1573
1573
  var V12_1_ENGINE_BITMAP_OFF = 1016;
1574
1574
  var V12_1_ENGINE_PARAMS_OFF_SBF = 32;
1575
1575
  var V12_1_ENGINE_PARAMS_OFF_HOST = 96;
1576
+ var V12_1_PARAMS_SIZE_SBF = 184;
1576
1577
  var V12_1_PARAMS_SIZE = 352;
1578
+ var V12_1_SBF_OFF_CURRENT_SLOT = 216;
1579
+ var V12_1_SBF_OFF_FUNDING_RATE = 224;
1580
+ var V12_1_SBF_OFF_LAST_CRANK_SLOT = 232;
1581
+ var V12_1_SBF_OFF_MAX_CRANK_STALENESS = 240;
1582
+ var V12_1_SBF_OFF_C_TOT = 248;
1583
+ var V12_1_SBF_OFF_PNL_POS_TOT = 264;
1584
+ var V12_1_SBF_OFF_LIQ_CURSOR = 296;
1585
+ var V12_1_SBF_OFF_GC_CURSOR = 298;
1586
+ var V12_1_SBF_OFF_LAST_SWEEP_START = 304;
1587
+ var V12_1_SBF_OFF_LAST_SWEEP_COMPLETE = 312;
1588
+ var V12_1_SBF_OFF_CRANK_CURSOR = 320;
1589
+ var V12_1_SBF_OFF_SWEEP_START_IDX = 322;
1590
+ var V12_1_SBF_OFF_LIFETIME_LIQUIDATIONS = 328;
1577
1591
  var V12_1_ENGINE_CURRENT_SLOT_OFF = 448;
1578
1592
  var V12_1_ENGINE_FUNDING_RATE_BPS_OFF = 456;
1579
1593
  var V12_1_ENGINE_LAST_CRANK_SLOT_OFF = 464;
@@ -1683,12 +1697,13 @@ for (const n of TIERS) {
1683
1697
  V12_1_SIZES.set(computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, n, 18), n);
1684
1698
  }
1685
1699
  var V12_1_SBF_ACCOUNT_SIZE = 280;
1686
- var V12_1_SBF_ENGINE_PREAMBLE = 558;
1700
+ var V12_1_SBF_ENGINE_OFF = 616;
1701
+ var V12_1_SBF_BITMAP_OFF = 584;
1687
1702
  for (const [, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
1688
1703
  const bitmapBytes = Math.ceil(n / 64) * 8;
1689
- const preAccLen = V12_1_SBF_ENGINE_PREAMBLE + bitmapBytes + 18 + n * 2;
1704
+ const preAccLen = V12_1_SBF_BITMAP_OFF + bitmapBytes + 18 + n * 2;
1690
1705
  const accountsOff = Math.ceil(preAccLen / 8) * 8;
1691
- const total = V12_1_ENGINE_OFF + accountsOff + n * V12_1_SBF_ACCOUNT_SIZE;
1706
+ const total = V12_1_SBF_ENGINE_OFF + accountsOff + n * V12_1_SBF_ACCOUNT_SIZE;
1692
1707
  V12_1_SIZES.set(total, n);
1693
1708
  }
1694
1709
  var SLAB_TIERS_V2 = {
@@ -2218,8 +2233,8 @@ function buildLayoutVSetDexPool(maxAccounts) {
2218
2233
  function buildLayoutV12_1(maxAccounts, dataLen) {
2219
2234
  const hostSize = computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, maxAccounts, 18);
2220
2235
  const isSbf = dataLen !== void 0 && dataLen !== hostSize;
2221
- const engineOff = isSbf ? 616 : V12_1_ENGINE_OFF;
2222
- const bitmapOff = isSbf ? 590 : V12_1_ENGINE_BITMAP_OFF - V12_1_ENGINE_OFF;
2236
+ const engineOff = isSbf ? V12_1_SBF_ENGINE_OFF : V12_1_ENGINE_OFF;
2237
+ const bitmapOff = isSbf ? V12_1_SBF_BITMAP_OFF : V12_1_ENGINE_BITMAP_OFF - V12_1_ENGINE_OFF;
2223
2238
  const accountSize = isSbf ? V12_1_ACCOUNT_SIZE_SBF : V12_1_ACCOUNT_SIZE;
2224
2239
  const bitmapWords = Math.ceil(maxAccounts / 64);
2225
2240
  const bitmapBytes = bitmapWords * 8;
@@ -2229,14 +2244,11 @@ function buildLayoutV12_1(maxAccounts, dataLen) {
2229
2244
  const accountsOffRel = Math.ceil(preAccountsLen / 8) * 8;
2230
2245
  return {
2231
2246
  version: 1,
2232
- // V12_1 upstream rebase uses 72-byte header (SlabHeader only, no V1 extension).
2233
- // Empirically verified: USDC mint found at offset 72 on mainnet slab BVjPc6rd.
2234
2247
  headerLen: V0_HEADER_LEN,
2235
- // 72 (not 104 — V12_1 removed the 32-byte header extension)
2248
+ // 72
2236
2249
  configOffset: V0_HEADER_LEN,
2237
2250
  // 72
2238
2251
  configLen: isSbf ? 544 : 576,
2239
- // SBF=544, host=576 (alignment diff)
2240
2252
  reservedOff: V1_RESERVED_OFF,
2241
2253
  engineOff,
2242
2254
  accountSize,
@@ -2245,42 +2257,58 @@ function buildLayoutV12_1(maxAccounts, dataLen) {
2245
2257
  accountsOff: engineOff + accountsOffRel,
2246
2258
  engineInsuranceOff: 16,
2247
2259
  engineParamsOff: isSbf ? V12_1_ENGINE_PARAMS_OFF_SBF : V12_1_ENGINE_PARAMS_OFF_HOST,
2248
- paramsSize: V12_1_PARAMS_SIZE,
2249
- // SBF shift: InsuranceFund=16B (was 80) + RiskParams=184B (was 352) = 232 bytes smaller.
2250
- // All engine fields after RiskParams are shifted by -232 on SBF.
2251
- engineCurrentSlotOff: isSbf ? V12_1_ENGINE_CURRENT_SLOT_OFF - 232 : V12_1_ENGINE_CURRENT_SLOT_OFF,
2252
- engineFundingIndexOff: isSbf ? V12_1_ENGINE_FUNDING_INDEX_OFF - 232 : V12_1_ENGINE_FUNDING_INDEX_OFF,
2253
- engineLastFundingSlotOff: isSbf ? V12_1_ENGINE_LAST_FUNDING_SLOT_OFF - 232 : V12_1_ENGINE_LAST_FUNDING_SLOT_OFF,
2254
- engineFundingRateBpsOff: isSbf ? V12_1_ENGINE_FUNDING_RATE_BPS_OFF - 232 : V12_1_ENGINE_FUNDING_RATE_BPS_OFF,
2255
- engineMarkPriceOff: isSbf ? V12_1_ENGINE_MARK_PRICE_OFF - 232 : V12_1_ENGINE_MARK_PRICE_OFF,
2256
- engineLastCrankSlotOff: isSbf ? V12_1_ENGINE_LAST_CRANK_SLOT_OFF - 232 : V12_1_ENGINE_LAST_CRANK_SLOT_OFF,
2257
- engineMaxCrankStalenessOff: isSbf ? V12_1_ENGINE_MAX_CRANK_STALENESS_OFF - 232 : V12_1_ENGINE_MAX_CRANK_STALENESS_OFF,
2258
- engineTotalOiOff: isSbf ? V12_1_ENGINE_TOTAL_OI_OFF - 232 : V12_1_ENGINE_TOTAL_OI_OFF,
2259
- engineLongOiOff: isSbf ? V12_1_ENGINE_LONG_OI_OFF - 232 : V12_1_ENGINE_LONG_OI_OFF,
2260
- engineShortOiOff: isSbf ? V12_1_ENGINE_SHORT_OI_OFF - 232 : V12_1_ENGINE_SHORT_OI_OFF,
2261
- engineCTotOff: isSbf ? V12_1_ENGINE_C_TOT_OFF - 232 : V12_1_ENGINE_C_TOT_OFF,
2262
- enginePnlPosTotOff: isSbf ? V12_1_ENGINE_PNL_POS_TOT_OFF - 232 : V12_1_ENGINE_PNL_POS_TOT_OFF,
2263
- engineLiqCursorOff: isSbf ? V12_1_ENGINE_LIQ_CURSOR_OFF - 232 : V12_1_ENGINE_LIQ_CURSOR_OFF,
2264
- engineGcCursorOff: isSbf ? V12_1_ENGINE_GC_CURSOR_OFF - 232 : V12_1_ENGINE_GC_CURSOR_OFF,
2265
- engineLastSweepStartOff: isSbf ? V12_1_ENGINE_LAST_SWEEP_START_OFF - 232 : V12_1_ENGINE_LAST_SWEEP_START_OFF,
2266
- engineLastSweepCompleteOff: isSbf ? V12_1_ENGINE_LAST_SWEEP_COMPLETE_OFF - 232 : V12_1_ENGINE_LAST_SWEEP_COMPLETE_OFF,
2267
- engineCrankCursorOff: isSbf ? V12_1_ENGINE_CRANK_CURSOR_OFF - 232 : V12_1_ENGINE_CRANK_CURSOR_OFF,
2268
- engineSweepStartIdxOff: isSbf ? V12_1_ENGINE_SWEEP_START_IDX_OFF - 232 : V12_1_ENGINE_SWEEP_START_IDX_OFF,
2269
- engineLifetimeLiquidationsOff: isSbf ? V12_1_ENGINE_LIFETIME_LIQUIDATIONS_OFF - 232 : V12_1_ENGINE_LIFETIME_LIQUIDATIONS_OFF,
2270
- engineLifetimeForceClosesOff: isSbf ? V12_1_ENGINE_LIFETIME_FORCE_CLOSES_OFF - 232 : V12_1_ENGINE_LIFETIME_FORCE_CLOSES_OFF,
2271
- engineNetLpPosOff: isSbf ? V12_1_ENGINE_NET_LP_POS_OFF - 232 : V12_1_ENGINE_NET_LP_POS_OFF,
2272
- engineLpSumAbsOff: isSbf ? V12_1_ENGINE_LP_SUM_ABS_OFF - 232 : V12_1_ENGINE_LP_SUM_ABS_OFF,
2273
- engineLpMaxAbsOff: isSbf ? V12_1_ENGINE_LP_MAX_ABS_OFF - 232 : V12_1_ENGINE_LP_MAX_ABS_OFF,
2274
- engineLpMaxAbsSweepOff: isSbf ? V12_1_ENGINE_LP_MAX_ABS_SWEEP_OFF - 232 : V12_1_ENGINE_LP_MAX_ABS_SWEEP_OFF,
2275
- engineEmergencyOiModeOff: isSbf ? V12_1_ENGINE_EMERGENCY_OI_MODE_OFF - 232 : V12_1_ENGINE_EMERGENCY_OI_MODE_OFF,
2276
- engineEmergencyStartSlotOff: isSbf ? V12_1_ENGINE_EMERGENCY_START_SLOT_OFF - 232 : V12_1_ENGINE_EMERGENCY_START_SLOT_OFF,
2277
- engineLastBreakerSlotOff: isSbf ? V12_1_ENGINE_LAST_BREAKER_SLOT_OFF - 232 : V12_1_ENGINE_LAST_BREAKER_SLOT_OFF,
2260
+ paramsSize: isSbf ? V12_1_PARAMS_SIZE_SBF : V12_1_PARAMS_SIZE,
2261
+ // SBF engine offsets all verified by cargo build-sbf offset_of! assertions.
2262
+ // Fields that don't exist in the deployed program are set to -1 on SBF.
2263
+ engineCurrentSlotOff: isSbf ? V12_1_SBF_OFF_CURRENT_SLOT : V12_1_ENGINE_CURRENT_SLOT_OFF,
2264
+ engineFundingIndexOff: isSbf ? -1 : V12_1_ENGINE_FUNDING_INDEX_OFF,
2265
+ // not in deployed struct
2266
+ engineLastFundingSlotOff: isSbf ? -1 : V12_1_ENGINE_LAST_FUNDING_SLOT_OFF,
2267
+ // not in deployed struct
2268
+ engineFundingRateBpsOff: isSbf ? V12_1_SBF_OFF_FUNDING_RATE : V12_1_ENGINE_FUNDING_RATE_BPS_OFF,
2269
+ engineMarkPriceOff: isSbf ? -1 : V12_1_ENGINE_MARK_PRICE_OFF,
2270
+ // not in deployed struct
2271
+ engineLastCrankSlotOff: isSbf ? V12_1_SBF_OFF_LAST_CRANK_SLOT : V12_1_ENGINE_LAST_CRANK_SLOT_OFF,
2272
+ engineMaxCrankStalenessOff: isSbf ? V12_1_SBF_OFF_MAX_CRANK_STALENESS : V12_1_ENGINE_MAX_CRANK_STALENESS_OFF,
2273
+ engineTotalOiOff: isSbf ? -1 : V12_1_ENGINE_TOTAL_OI_OFF,
2274
+ // not in deployed struct
2275
+ engineLongOiOff: isSbf ? -1 : V12_1_ENGINE_LONG_OI_OFF,
2276
+ // not in deployed struct
2277
+ engineShortOiOff: isSbf ? -1 : V12_1_ENGINE_SHORT_OI_OFF,
2278
+ // not in deployed struct
2279
+ engineCTotOff: isSbf ? V12_1_SBF_OFF_C_TOT : V12_1_ENGINE_C_TOT_OFF,
2280
+ enginePnlPosTotOff: isSbf ? V12_1_SBF_OFF_PNL_POS_TOT : V12_1_ENGINE_PNL_POS_TOT_OFF,
2281
+ engineLiqCursorOff: isSbf ? V12_1_SBF_OFF_LIQ_CURSOR : V12_1_ENGINE_LIQ_CURSOR_OFF,
2282
+ engineGcCursorOff: isSbf ? V12_1_SBF_OFF_GC_CURSOR : V12_1_ENGINE_GC_CURSOR_OFF,
2283
+ engineLastSweepStartOff: isSbf ? V12_1_SBF_OFF_LAST_SWEEP_START : V12_1_ENGINE_LAST_SWEEP_START_OFF,
2284
+ engineLastSweepCompleteOff: isSbf ? V12_1_SBF_OFF_LAST_SWEEP_COMPLETE : V12_1_ENGINE_LAST_SWEEP_COMPLETE_OFF,
2285
+ engineCrankCursorOff: isSbf ? V12_1_SBF_OFF_CRANK_CURSOR : V12_1_ENGINE_CRANK_CURSOR_OFF,
2286
+ engineSweepStartIdxOff: isSbf ? V12_1_SBF_OFF_SWEEP_START_IDX : V12_1_ENGINE_SWEEP_START_IDX_OFF,
2287
+ engineLifetimeLiquidationsOff: isSbf ? V12_1_SBF_OFF_LIFETIME_LIQUIDATIONS : V12_1_ENGINE_LIFETIME_LIQUIDATIONS_OFF,
2288
+ engineLifetimeForceClosesOff: isSbf ? -1 : V12_1_ENGINE_LIFETIME_FORCE_CLOSES_OFF,
2289
+ // not in deployed struct
2290
+ engineNetLpPosOff: isSbf ? -1 : V12_1_ENGINE_NET_LP_POS_OFF,
2291
+ // not in deployed struct
2292
+ engineLpSumAbsOff: isSbf ? -1 : V12_1_ENGINE_LP_SUM_ABS_OFF,
2293
+ // not in deployed struct
2294
+ engineLpMaxAbsOff: isSbf ? -1 : V12_1_ENGINE_LP_MAX_ABS_OFF,
2295
+ // not in deployed struct
2296
+ engineLpMaxAbsSweepOff: isSbf ? -1 : V12_1_ENGINE_LP_MAX_ABS_SWEEP_OFF,
2297
+ // not in deployed struct
2298
+ engineEmergencyOiModeOff: isSbf ? -1 : V12_1_ENGINE_EMERGENCY_OI_MODE_OFF,
2299
+ // not in deployed struct
2300
+ engineEmergencyStartSlotOff: isSbf ? -1 : V12_1_ENGINE_EMERGENCY_START_SLOT_OFF,
2301
+ // not in deployed struct
2302
+ engineLastBreakerSlotOff: isSbf ? -1 : V12_1_ENGINE_LAST_BREAKER_SLOT_OFF,
2303
+ // not in deployed struct
2278
2304
  engineBitmapOff: bitmapOff,
2279
2305
  postBitmap: 18,
2280
2306
  acctOwnerOff: V12_1_ACCT_OWNER_OFF,
2281
- hasInsuranceIsolation: true,
2282
- engineInsuranceIsolatedOff: 48,
2283
- engineInsuranceIsolationBpsOff: 64
2307
+ // InsuranceFund on deployed program is just {balance: U128} = 16 bytes.
2308
+ // No isolated_balance or insurance_isolation_bps fields.
2309
+ hasInsuranceIsolation: !isSbf,
2310
+ engineInsuranceIsolatedOff: isSbf ? -1 : 48,
2311
+ engineInsuranceIsolationBpsOff: isSbf ? -1 : 64
2284
2312
  };
2285
2313
  }
2286
2314
  function detectSlabLayout(dataLen, data) {
@@ -2616,17 +2644,18 @@ function parseEngine(data) {
2616
2644
  vault: readU128LE(data, base),
2617
2645
  insuranceFund: {
2618
2646
  balance: readU128LE(data, base + layout.engineInsuranceOff),
2619
- feeRevenue: readU128LE(data, base + layout.engineInsuranceOff + 16),
2647
+ // feeRevenue: only exists in percolator-core (80-byte InsuranceFund), not deployed (16-byte)
2648
+ feeRevenue: layout.hasInsuranceIsolation ? readU128LE(data, base + layout.engineInsuranceOff + 16) : 0n,
2620
2649
  isolatedBalance: layout.hasInsuranceIsolation ? readU128LE(data, base + layout.engineInsuranceIsolatedOff) : 0n,
2621
2650
  isolationBps: layout.hasInsuranceIsolation ? readU16LE(data, base + layout.engineInsuranceIsolationBpsOff) : 0
2622
2651
  },
2623
2652
  currentSlot: readU64LE(data, base + layout.engineCurrentSlotOff),
2624
- fundingIndexQpbE6: readI128LE(data, base + layout.engineFundingIndexOff),
2625
- lastFundingSlot: readU64LE(data, base + layout.engineLastFundingSlotOff),
2653
+ fundingIndexQpbE6: layout.engineFundingIndexOff >= 0 ? readI128LE(data, base + layout.engineFundingIndexOff) : 0n,
2654
+ lastFundingSlot: layout.engineLastFundingSlotOff >= 0 ? readU64LE(data, base + layout.engineLastFundingSlotOff) : 0n,
2626
2655
  fundingRateBpsPerSlotLast: readI64LE(data, base + layout.engineFundingRateBpsOff),
2627
2656
  lastCrankSlot: readU64LE(data, base + layout.engineLastCrankSlotOff),
2628
2657
  maxCrankStalenessSlots: readU64LE(data, base + layout.engineMaxCrankStalenessOff),
2629
- totalOpenInterest: readU128LE(data, base + layout.engineTotalOiOff),
2658
+ totalOpenInterest: layout.engineTotalOiOff >= 0 ? readU128LE(data, base + layout.engineTotalOiOff) : 0n,
2630
2659
  longOi: layout.engineLongOiOff >= 0 ? readU128LE(data, base + layout.engineLongOiOff) : 0n,
2631
2660
  shortOi: layout.engineShortOiOff >= 0 ? readU128LE(data, base + layout.engineShortOiOff) : 0n,
2632
2661
  cTot: readU128LE(data, base + layout.engineCTotOff),
@@ -2638,9 +2667,9 @@ function parseEngine(data) {
2638
2667
  crankCursor: readU16LE(data, base + layout.engineCrankCursorOff),
2639
2668
  sweepStartIdx: readU16LE(data, base + layout.engineSweepStartIdxOff),
2640
2669
  lifetimeLiquidations: readU64LE(data, base + layout.engineLifetimeLiquidationsOff),
2641
- lifetimeForceCloses: readU64LE(data, base + layout.engineLifetimeForceClosesOff),
2642
- netLpPos: readI128LE(data, base + layout.engineNetLpPosOff),
2643
- lpSumAbs: readU128LE(data, base + layout.engineLpSumAbsOff),
2670
+ lifetimeForceCloses: layout.engineLifetimeForceClosesOff >= 0 ? readU64LE(data, base + layout.engineLifetimeForceClosesOff) : 0n,
2671
+ netLpPos: layout.engineNetLpPosOff >= 0 ? readI128LE(data, base + layout.engineNetLpPosOff) : 0n,
2672
+ lpSumAbs: layout.engineLpSumAbsOff >= 0 ? readU128LE(data, base + layout.engineLpSumAbsOff) : 0n,
2644
2673
  lpMaxAbs: layout.engineLpMaxAbsOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsOff) : 0n,
2645
2674
  lpMaxAbsSweep: layout.engineLpMaxAbsSweepOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsSweepOff) : 0n,
2646
2675
  emergencyOiMode: layout.engineEmergencyOiModeOff >= 0 ? data[base + layout.engineEmergencyOiModeOff] !== 0 : false,
@@ -2707,7 +2736,7 @@ function parseAccount(data, idx) {
2707
2736
  if (data.length < base + layout.accountSize) {
2708
2737
  throw new Error("Slab data too short for account");
2709
2738
  }
2710
- const isV12_1 = layout.engineOff === V12_1_ENGINE_OFF && (layout.accountSize === V12_1_ACCOUNT_SIZE || layout.accountSize === V12_1_ACCOUNT_SIZE_SBF);
2739
+ const isV12_1 = (layout.engineOff === V12_1_ENGINE_OFF || layout.engineOff === V12_1_SBF_ENGINE_OFF) && (layout.accountSize === V12_1_ACCOUNT_SIZE || layout.accountSize === V12_1_ACCOUNT_SIZE_SBF);
2711
2740
  const isAdl = layout.accountSize >= 312 || isV12_1;
2712
2741
  const warmupStartedOff = isAdl ? V_ADL_ACCT_WARMUP_STARTED_OFF : ACCT_WARMUP_STARTED_OFF;
2713
2742
  const warmupSlopeOff = isAdl ? V_ADL_ACCT_WARMUP_SLOPE_OFF : ACCT_WARMUP_SLOPE_OFF;