@percolatorct/sdk 2.0.1 → 2.0.3

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.1`. v12.19 single-target. 792 tests passing. Do NOT use with real funds.
5
+ > **EXPERIMENTAL. NOT AUDITED.** `2.0.3`. 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,52 +2308,71 @@ 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;
2313
- var V12_19_SBF_ENGINE_CURRENT_SLOT_OFF = 216;
2314
- var V12_19_SBF_ENGINE_MARKET_MODE_OFF = 224;
2315
- var V12_19_SBF_ENGINE_RESOLVED_LIVE_PRICE_OFF = 320;
2316
- var V12_19_SBF_ENGINE_C_TOT_OFF = 328;
2317
- var V12_19_SBF_ENGINE_PNL_POS_TOT_OFF = 344;
2318
- var V12_19_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF = 360;
2319
- var V12_19_SBF_ENGINE_OI_EFF_LONG_OFF = 488;
2320
- var V12_19_SBF_ENGINE_OI_EFF_SHORT_OFF = 504;
2321
- var V12_19_SBF_ENGINE_NEG_PNL_COUNT_OFF = 608;
2322
- var V12_19_SBF_ENGINE_RR_CURSOR_OFF = 616;
2323
- var V12_19_SBF_ENGINE_LAST_ORACLE_PRICE_OFF = 640;
2324
- var V12_19_SBF_ENGINE_FUND_PX_LAST_OFF = 648;
2325
- var V12_19_SBF_ENGINE_LAST_MARKET_SLOT_OFF = 656;
2326
- var V12_19_SBF_ENGINE_F_LONG_NUM_OFF = 664;
2327
- var V12_19_SBF_ENGINE_F_SHORT_NUM_OFF = 680;
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;
2328
2331
  var V12_19_SIZES = /* @__PURE__ */ new Map([
2329
- [19640, 64],
2330
- // --features micro
2331
- [94168, 256],
2332
- // --features small (deployed mainnet ESa89R5...)
2333
- [372280, 1024],
2334
- // --features medium
2335
- [1484728, 4096]
2336
- // 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)
2337
2340
  ]);
2338
- function buildLayoutV12_19(maxAccounts, dataLen) {
2339
- 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
+ );
2340
2356
  return {
2341
2357
  ...base,
2358
+ headerLen: V12_19_HEADER_LEN_SBF,
2342
2359
  configLen: V12_19_CONFIG_LEN,
2360
+ configOffset: V12_19_HEADER_LEN_SBF,
2361
+ // header runs 0..136 in v12.19
2343
2362
  engineOff: V12_19_ENGINE_OFF_SBF,
2344
- accountsOff: V12_19_ENGINE_OFF_SBF + (base.accountsOff - base.engineOff),
2345
- // V12_19 engine field offsets (only the fields exposed in SlabLayout).
2346
- // Other engine fields (negPnlCount, fundPxLast, fLongNum, fShortNum,
2347
- // lastOraclePrice, marketMode, pnlMaturedPosTot) are read by parseEngine
2348
- // via its own version-aware switch keyed on engineOff === 600.
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):
2349
2368
  engineCurrentSlotOff: V12_19_SBF_ENGINE_CURRENT_SLOT_OFF,
2350
2369
  engineCTotOff: V12_19_SBF_ENGINE_C_TOT_OFF,
2351
2370
  enginePnlPosTotOff: V12_19_SBF_ENGINE_PNL_POS_TOT_OFF,
2352
2371
  engineLongOiOff: V12_19_SBF_ENGINE_OI_EFF_LONG_OFF,
2353
2372
  engineShortOiOff: V12_19_SBF_ENGINE_OI_EFF_SHORT_OFF,
2354
- // V12_19 last_market_slot replaces V12_17 last_crank_slot semantics.
2373
+ // last_market_slot replaces V12_17 last_crank_slot semantics.
2355
2374
  engineLastCrankSlotOff: V12_19_SBF_ENGINE_LAST_MARKET_SLOT_OFF,
2356
- // V12_19 rr_cursor_position replaces V12_17 gc_cursor semantics.
2375
+ // rr_cursor_position replaces V12_17 gc_cursor semantics.
2357
2376
  engineGcCursorOff: V12_19_SBF_ENGINE_RR_CURSOR_OFF
2358
2377
  };
2359
2378
  }
@@ -3463,10 +3482,85 @@ function parseConfigV12_17(data, configOff) {
3463
3482
  dexPool
3464
3483
  };
3465
3484
  }
3485
+ function parseConfigV12_19(data, configOff) {
3486
+ const MIN_V12_19_BYTES = 480;
3487
+ if (data.length < configOff + MIN_V12_19_BYTES) {
3488
+ throw new Error(`Slab data too short for V12_19 config: ${data.length} < ${configOff + MIN_V12_19_BYTES}`);
3489
+ }
3490
+ const b = configOff;
3491
+ const collateralMint = new PublicKey5(data.subarray(b + 0, b + 32));
3492
+ const vaultPubkey = new PublicKey5(data.subarray(b + 32, b + 64));
3493
+ const indexFeedId = new PublicKey5(data.subarray(b + 64, b + 96));
3494
+ const maxStalenessSlots = readU64LE(data, b + 96);
3495
+ const confFilterBps = readU16LE(data, b + 104);
3496
+ const vaultAuthorityBump = readU8(data, b + 106);
3497
+ const invert = readU8(data, b + 107);
3498
+ const unitScale = readU32LE(data, b + 108);
3499
+ const fundingHorizonSlots = readU64LE(data, b + 112);
3500
+ const fundingKBps = readU64LE(data, b + 120);
3501
+ const fundingMaxPremiumBps = readI64LE(data, b + 128);
3502
+ const fundingMaxBpsPerSlot = readI64LE(data, b + 136);
3503
+ const oracleAuthority = new PublicKey5(data.subarray(b + 144, b + 176));
3504
+ const authorityPriceE6 = readU64LE(data, b + 176);
3505
+ const authorityTimestamp = readI64LE(data, b + 184);
3506
+ const lastEffectivePriceE6 = readU64LE(data, b + 192);
3507
+ const oraclePriceCapE2bps = readU64LE(data, b + 216);
3508
+ const dexPoolBytes = data.subarray(b + 368, b + 400);
3509
+ const dexPool = dexPoolBytes.some((x) => x !== 0) ? new PublicKey5(dexPoolBytes) : null;
3510
+ return {
3511
+ collateralMint,
3512
+ vaultPubkey,
3513
+ indexFeedId,
3514
+ maxStalenessSlots,
3515
+ confFilterBps,
3516
+ vaultAuthorityBump,
3517
+ invert,
3518
+ unitScale,
3519
+ fundingHorizonSlots,
3520
+ fundingKBps,
3521
+ fundingInvScaleNotionalE6: 0n,
3522
+ fundingMaxPremiumBps,
3523
+ fundingMaxBpsPerSlot,
3524
+ fundingPremiumWeightBps: 0n,
3525
+ fundingSettlementIntervalSlots: 0n,
3526
+ fundingPremiumDampeningE6: 0n,
3527
+ fundingPremiumMaxBpsPerSlot: 0n,
3528
+ threshFloor: 0n,
3529
+ threshRiskBps: 0n,
3530
+ threshUpdateIntervalSlots: 0n,
3531
+ threshStepBps: 0n,
3532
+ threshAlphaBps: 0n,
3533
+ threshMin: 0n,
3534
+ threshMax: 0n,
3535
+ threshMinStep: 0n,
3536
+ oracleAuthority,
3537
+ authorityPriceE6,
3538
+ authorityTimestamp,
3539
+ oraclePriceCapE2bps,
3540
+ lastEffectivePriceE6,
3541
+ oiCapMultiplierBps: readU64LE(data, b + 416),
3542
+ maxPnlCap: readU64LE(data, b + 400),
3543
+ adaptiveFundingEnabled: false,
3544
+ adaptiveScaleBps: 0,
3545
+ adaptiveMaxFundingBps: 0n,
3546
+ marketCreatedSlot: 0n,
3547
+ oiRampSlots: 0n,
3548
+ resolvedSlot: 0n,
3549
+ insuranceIsolationBps: 0,
3550
+ oraclePhase: 0,
3551
+ cumulativeVolumeE6: 0n,
3552
+ phase2DeltaSlots: 0,
3553
+ dexPool
3554
+ };
3555
+ }
3466
3556
  function parseConfig(data, layoutHint) {
3467
3557
  const layout = layoutHint !== void 0 ? layoutHint : detectSlabLayout(data.length, data);
3468
3558
  const configOff = layout ? layout.configOffset : V0_HEADER_LEN;
3469
3559
  const configLen = layout ? layout.configLen : V0_CONFIG_LEN;
3560
+ const isV12_19 = layout && layout.accountSize === V12_19_ACCOUNT_SIZE_SBF;
3561
+ if (isV12_19) {
3562
+ return parseConfigV12_19(data, configOff);
3563
+ }
3470
3564
  const isV12_17 = layout && (layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF);
3471
3565
  if (isV12_17) {
3472
3566
  return parseConfigV12_17(data, configOff);
@@ -3702,8 +3796,8 @@ function parseEngine(data) {
3702
3796
  const base = layout.engineOff;
3703
3797
  const isV12_17 = layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF;
3704
3798
  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);
3705
- if (isV12_17) {
3706
- const isV12_19 = layout.engineOff === V12_19_ENGINE_OFF_SBF;
3799
+ const isV12_19 = layout.accountSize === V12_19_ACCOUNT_SIZE_SBF;
3800
+ if (isV12_17 || isV12_19) {
3707
3801
  const isSbf = layout.engineOff === V12_17_ENGINE_OFF_SBF || isV12_19;
3708
3802
  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;
3709
3803
  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;