@percolatorct/sdk 2.0.0 → 2.0.2

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/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  TypeScript SDK for building clients, bots, and UIs on top of the [Percolator](https://github.com/dcccrypto/percolator) perpetual futures protocol on Solana.
4
4
 
5
- > **EXPERIMENTAL. NOT AUDITED.** `2.0.0`. v12.19 single-target. 792 tests passing. Do NOT use with real funds.
5
+ > **EXPERIMENTAL. NOT AUDITED.** `2.0.2`. v12.19 single-target. 792 tests passing. Do NOT use with real funds.
6
6
 
7
7
  ## Target wrapper
8
8
 
package/dist/index.js CHANGED
@@ -2308,25 +2308,72 @@ for (const n of V12_17_TIERS) {
2308
2308
  const sbfSize = V12_17_ENGINE_OFF_SBF + accountsOffSbf + n * V12_17_ACCOUNT_SIZE_SBF + V12_17_RISK_BUF_LEN + n * V12_17_GEN_TABLE_ENTRY;
2309
2309
  V12_17_SIZES.set(sbfSize, n);
2310
2310
  }
2311
- var V12_19_CONFIG_LEN = 528;
2312
- var V12_19_ENGINE_OFF_SBF = 600;
2311
+ var V12_19_HEADER_LEN_SBF = 136;
2312
+ var V12_19_CONFIG_LEN = 480;
2313
+ var V12_19_ENGINE_OFF_SBF = 616;
2314
+ var V12_19_ACCOUNT_SIZE_SBF = 360;
2315
+ var V12_19_SBF_ENGINE_BITMAP_OFF = 712;
2316
+ var V12_19_SBF_ENGINE_CURRENT_SLOT_OFF = 200;
2317
+ var V12_19_SBF_ENGINE_MARKET_MODE_OFF = 208;
2318
+ var V12_19_SBF_ENGINE_RESOLVED_LIVE_PRICE_OFF = 304;
2319
+ var V12_19_SBF_ENGINE_C_TOT_OFF = 312;
2320
+ var V12_19_SBF_ENGINE_PNL_POS_TOT_OFF = 328;
2321
+ var V12_19_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF = 344;
2322
+ var V12_19_SBF_ENGINE_OI_EFF_LONG_OFF = 472;
2323
+ var V12_19_SBF_ENGINE_OI_EFF_SHORT_OFF = 488;
2324
+ var V12_19_SBF_ENGINE_NEG_PNL_COUNT_OFF = 584;
2325
+ var V12_19_SBF_ENGINE_RR_CURSOR_OFF = 592;
2326
+ var V12_19_SBF_ENGINE_LAST_ORACLE_PRICE_OFF = 624;
2327
+ var V12_19_SBF_ENGINE_FUND_PX_LAST_OFF = 632;
2328
+ var V12_19_SBF_ENGINE_LAST_MARKET_SLOT_OFF = 640;
2329
+ var V12_19_SBF_ENGINE_F_LONG_NUM_OFF = 648;
2330
+ var V12_19_SBF_ENGINE_F_SHORT_NUM_OFF = 664;
2313
2331
  var V12_19_SIZES = /* @__PURE__ */ new Map([
2314
- [19640, 64],
2315
- // --features micro
2316
- [94168, 256],
2317
- // --features small (deployed mainnet ESa89R5...)
2318
- [372280, 1024],
2319
- // --features medium
2320
- [1484728, 4096]
2321
- // default features (large)
2332
+ [26848, 64],
2333
+ // --features micro (derived)
2334
+ [96760, 256],
2335
+ // --features small (probe-confirmed; deployed mainnet ESa89R5...)
2336
+ [376408, 1024],
2337
+ // --features medium (derived)
2338
+ [1495e3, 4096]
2339
+ // default features / large (derived)
2322
2340
  ]);
2323
- function buildLayoutV12_19(maxAccounts, dataLen) {
2324
- const base = buildLayoutV12_17(maxAccounts, dataLen);
2341
+ function buildLayoutV12_19(maxAccounts, _dataLen) {
2342
+ const bitmapWords = Math.ceil(maxAccounts / 64);
2343
+ const bitmapBytes = bitmapWords * 8;
2344
+ const numUsedOff = V12_19_SBF_ENGINE_BITMAP_OFF + bitmapBytes;
2345
+ const freeHeadOff = numUsedOff + 2;
2346
+ const nextFreeOff = freeHeadOff + 2;
2347
+ const prevFreeOff = nextFreeOff + maxAccounts * 2;
2348
+ const accountsRelEnd = prevFreeOff + maxAccounts * 2;
2349
+ const accountsOffRel = Math.ceil(accountsRelEnd / 8) * 8;
2350
+ const accountsOff = V12_19_ENGINE_OFF_SBF + accountsOffRel;
2351
+ const base = buildLayoutV12_17(
2352
+ maxAccounts,
2353
+ /* synthetic V12_17 SBF size */
2354
+ 94168
2355
+ );
2325
2356
  return {
2326
2357
  ...base,
2358
+ headerLen: V12_19_HEADER_LEN_SBF,
2327
2359
  configLen: V12_19_CONFIG_LEN,
2360
+ configOffset: V12_19_HEADER_LEN_SBF,
2361
+ // header runs 0..136 in v12.19
2328
2362
  engineOff: V12_19_ENGINE_OFF_SBF,
2329
- accountsOff: V12_19_ENGINE_OFF_SBF + (base.accountsOff - base.engineOff)
2363
+ accountSize: V12_19_ACCOUNT_SIZE_SBF,
2364
+ accountsOff,
2365
+ bitmapWords,
2366
+ engineBitmapOff: V12_19_SBF_ENGINE_BITMAP_OFF,
2367
+ // V12_19-specific engine field offsets (probe-confirmed):
2368
+ engineCurrentSlotOff: V12_19_SBF_ENGINE_CURRENT_SLOT_OFF,
2369
+ engineCTotOff: V12_19_SBF_ENGINE_C_TOT_OFF,
2370
+ enginePnlPosTotOff: V12_19_SBF_ENGINE_PNL_POS_TOT_OFF,
2371
+ engineLongOiOff: V12_19_SBF_ENGINE_OI_EFF_LONG_OFF,
2372
+ engineShortOiOff: V12_19_SBF_ENGINE_OI_EFF_SHORT_OFF,
2373
+ // last_market_slot replaces V12_17 last_crank_slot semantics.
2374
+ engineLastCrankSlotOff: V12_19_SBF_ENGINE_LAST_MARKET_SLOT_OFF,
2375
+ // rr_cursor_position replaces V12_17 gc_cursor semantics.
2376
+ engineGcCursorOff: V12_19_SBF_ENGINE_RR_CURSOR_OFF
2330
2377
  };
2331
2378
  }
2332
2379
  var V12_1_SBF_ACCOUNT_SIZE = 280;
@@ -3674,25 +3721,26 @@ function parseEngine(data) {
3674
3721
  const base = layout.engineOff;
3675
3722
  const isV12_17 = layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF;
3676
3723
  const isV12_15 = !isV12_17 && (layout.accountSize === V12_15_ACCOUNT_SIZE || layout.accountSize === V12_15_ACCOUNT_SIZE_SMALL) && (layout.engineOff === V12_15_ENGINE_OFF || layout.engineOff === V12_15_ENGINE_OFF_SBF);
3677
- if (isV12_17) {
3678
- const isSbf = layout.engineOff === V12_17_ENGINE_OFF_SBF || layout.engineOff === V12_19_ENGINE_OFF_SBF;
3679
- const currentSlotOff = isSbf ? V12_17_SBF_ENGINE_CURRENT_SLOT_OFF : V12_17_ENGINE_CURRENT_SLOT_OFF;
3680
- const marketModeOff = isSbf ? V12_17_SBF_ENGINE_MARKET_MODE_OFF : V12_17_ENGINE_MARKET_MODE_OFF;
3681
- const cTotOff = isSbf ? V12_17_SBF_ENGINE_C_TOT_OFF : V12_17_ENGINE_C_TOT_OFF;
3682
- const pnlPosTotOff = isSbf ? V12_17_SBF_ENGINE_PNL_POS_TOT_OFF : V12_17_ENGINE_PNL_POS_TOT_OFF;
3683
- const pnlMaturedOff = isSbf ? V12_17_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF : V12_17_ENGINE_PNL_MATURED_POS_TOT_OFF;
3684
- const negPnlOff = isSbf ? V12_17_SBF_ENGINE_NEG_PNL_COUNT_OFF : V12_17_ENGINE_NEG_PNL_COUNT_OFF;
3685
- const oraclePriceOff = isSbf ? V12_17_SBF_ENGINE_LAST_ORACLE_PRICE_OFF : V12_17_ENGINE_LAST_ORACLE_PRICE_OFF;
3686
- const fundPxLastOff = isSbf ? V12_17_SBF_ENGINE_FUND_PX_LAST_OFF : V12_17_ENGINE_FUND_PX_LAST_OFF;
3687
- const fLongNumOff = isSbf ? V12_17_SBF_ENGINE_F_LONG_NUM_OFF : V12_17_ENGINE_F_LONG_NUM_OFF;
3688
- const fShortNumOff = isSbf ? V12_17_SBF_ENGINE_F_SHORT_NUM_OFF : V12_17_ENGINE_F_SHORT_NUM_OFF;
3689
- const resolvedKLongOff = isSbf ? 288 : V12_17_ENGINE_RESOLVED_K_LONG_OFF;
3690
- const resolvedKShortOff = isSbf ? 304 : V12_17_ENGINE_RESOLVED_K_SHORT_OFF;
3691
- const resolvedLivePriceOff = isSbf ? 320 : V12_17_ENGINE_RESOLVED_LIVE_PRICE_OFF;
3692
- const lastCrankSlotOff = isSbf ? V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF : V12_17_ENGINE_LAST_CRANK_SLOT_OFF;
3693
- const gcCursorOff = isSbf ? V12_17_SBF_ENGINE_GC_CURSOR_OFF : V12_17_ENGINE_GC_CURSOR_OFF;
3694
- const oiEffLongOff = isSbf ? V12_17_SBF_ENGINE_OI_EFF_LONG_OFF : V12_17_ENGINE_OI_EFF_LONG_OFF;
3695
- const oiEffShortOff = isSbf ? V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF : V12_17_ENGINE_OI_EFF_SHORT_OFF;
3724
+ const isV12_19 = layout.accountSize === V12_19_ACCOUNT_SIZE_SBF;
3725
+ if (isV12_17 || isV12_19) {
3726
+ const isSbf = layout.engineOff === V12_17_ENGINE_OFF_SBF || isV12_19;
3727
+ const currentSlotOff = isV12_19 ? V12_19_SBF_ENGINE_CURRENT_SLOT_OFF : isSbf ? V12_17_SBF_ENGINE_CURRENT_SLOT_OFF : V12_17_ENGINE_CURRENT_SLOT_OFF;
3728
+ const marketModeOff = isV12_19 ? V12_19_SBF_ENGINE_MARKET_MODE_OFF : isSbf ? V12_17_SBF_ENGINE_MARKET_MODE_OFF : V12_17_ENGINE_MARKET_MODE_OFF;
3729
+ const cTotOff = isV12_19 ? V12_19_SBF_ENGINE_C_TOT_OFF : isSbf ? V12_17_SBF_ENGINE_C_TOT_OFF : V12_17_ENGINE_C_TOT_OFF;
3730
+ const pnlPosTotOff = isV12_19 ? V12_19_SBF_ENGINE_PNL_POS_TOT_OFF : isSbf ? V12_17_SBF_ENGINE_PNL_POS_TOT_OFF : V12_17_ENGINE_PNL_POS_TOT_OFF;
3731
+ const pnlMaturedOff = isV12_19 ? V12_19_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF : isSbf ? V12_17_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF : V12_17_ENGINE_PNL_MATURED_POS_TOT_OFF;
3732
+ const negPnlOff = isV12_19 ? V12_19_SBF_ENGINE_NEG_PNL_COUNT_OFF : isSbf ? V12_17_SBF_ENGINE_NEG_PNL_COUNT_OFF : V12_17_ENGINE_NEG_PNL_COUNT_OFF;
3733
+ const oraclePriceOff = isV12_19 ? V12_19_SBF_ENGINE_LAST_ORACLE_PRICE_OFF : isSbf ? V12_17_SBF_ENGINE_LAST_ORACLE_PRICE_OFF : V12_17_ENGINE_LAST_ORACLE_PRICE_OFF;
3734
+ const fundPxLastOff = isV12_19 ? V12_19_SBF_ENGINE_FUND_PX_LAST_OFF : isSbf ? V12_17_SBF_ENGINE_FUND_PX_LAST_OFF : V12_17_ENGINE_FUND_PX_LAST_OFF;
3735
+ const fLongNumOff = isV12_19 ? V12_19_SBF_ENGINE_F_LONG_NUM_OFF : isSbf ? V12_17_SBF_ENGINE_F_LONG_NUM_OFF : V12_17_ENGINE_F_LONG_NUM_OFF;
3736
+ const fShortNumOff = isV12_19 ? V12_19_SBF_ENGINE_F_SHORT_NUM_OFF : isSbf ? V12_17_SBF_ENGINE_F_SHORT_NUM_OFF : V12_17_ENGINE_F_SHORT_NUM_OFF;
3737
+ const resolvedKLongOff = isV12_19 ? 288 : isSbf ? 288 : V12_17_ENGINE_RESOLVED_K_LONG_OFF;
3738
+ const resolvedKShortOff = isV12_19 ? 304 : isSbf ? 304 : V12_17_ENGINE_RESOLVED_K_SHORT_OFF;
3739
+ const resolvedLivePriceOff = isV12_19 ? V12_19_SBF_ENGINE_RESOLVED_LIVE_PRICE_OFF : isSbf ? 320 : V12_17_ENGINE_RESOLVED_LIVE_PRICE_OFF;
3740
+ const lastCrankSlotOff = isV12_19 ? V12_19_SBF_ENGINE_LAST_MARKET_SLOT_OFF : isSbf ? V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF : V12_17_ENGINE_LAST_CRANK_SLOT_OFF;
3741
+ const gcCursorOff = isV12_19 ? V12_19_SBF_ENGINE_RR_CURSOR_OFF : isSbf ? V12_17_SBF_ENGINE_GC_CURSOR_OFF : V12_17_ENGINE_GC_CURSOR_OFF;
3742
+ const oiEffLongOff = isV12_19 ? V12_19_SBF_ENGINE_OI_EFF_LONG_OFF : isSbf ? V12_17_SBF_ENGINE_OI_EFF_LONG_OFF : V12_17_ENGINE_OI_EFF_LONG_OFF;
3743
+ const oiEffShortOff = isV12_19 ? V12_19_SBF_ENGINE_OI_EFF_SHORT_OFF : isSbf ? V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF : V12_17_ENGINE_OI_EFF_SHORT_OFF;
3696
3744
  const longOi = readU128LE(data, base + oiEffLongOff);
3697
3745
  const shortOi = readU128LE(data, base + oiEffShortOff);
3698
3746
  const bitmapEnd = layout.engineBitmapOff + layout.bitmapWords * 8;