@percolatorct/sdk 1.0.0-beta.33 → 1.0.0-beta.35

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.
@@ -727,10 +727,30 @@ export interface VammMatcherParams {
727
727
  impactKBps: number;
728
728
  liquidityNotionalE6: bigint;
729
729
  }
730
- /** Magic bytes identifying a vAMM matcher context: "PERCMATC" as u64 LE */
730
+ /** Magic bytes identifying a vAMM matcher context: "PERCMATC" as u64 LE = 0x504552434d415443 */
731
731
  export declare const VAMM_MAGIC = 5784119745439683651n;
732
- /** Offset into matcher context where vAMM params start */
732
+ /** Alias matching the Rust constant name for parity tests */
733
+ export declare const MATCHER_MAGIC = 5784119745439683651n;
734
+ /** Offset where matcher return is written in the context account (always 0 per ABI) */
735
+ export declare const CTX_RETURN_OFFSET = 0;
736
+ /** Byte length of the MatcherReturn section of the context account */
737
+ export declare const MATCHER_RETURN_LEN = 64;
738
+ /** Offset into matcher context where vAMM params start (= MATCHER_RETURN_LEN) */
733
739
  export declare const CTX_VAMM_OFFSET = 64;
740
+ /** Byte length of the MatcherCtx (vAMM state) section of the context account */
741
+ export declare const CTX_VAMM_LEN = 256;
742
+ /** Total matcher context account size: MATCHER_RETURN_LEN + CTX_VAMM_LEN */
743
+ export declare const MATCHER_CONTEXT_LEN = 320;
744
+ /** Byte length of a MatcherCall instruction (tag 0 CPI payload) */
745
+ export declare const MATCHER_CALL_LEN = 67;
746
+ /**
747
+ * Byte length of an InitMatcherCtx instruction payload sent to the matcher program.
748
+ * Layout: tag(1) + kind(1) + trading_fee_bps(4) + base_spread_bps(4) +
749
+ * max_total_bps(4) + impact_k_bps(4) + liquidity_notional_e6(16) +
750
+ * max_fill_abs(16) + max_inventory_abs(16) + fee_to_insurance_bps(2) +
751
+ * skew_spread_mult_bps(2) + lp_account_id(8) = 78
752
+ */
753
+ export declare const INIT_CTX_LEN = 78;
734
754
  /**
735
755
  * Compute execution price for a given LP quote.
736
756
  * For buys (isLong=true): price above oracle.
package/dist/index.js CHANGED
@@ -560,7 +560,14 @@ function encodeAuditCrank() {
560
560
  return encU8(IX_TAG.AuditCrank);
561
561
  }
562
562
  var VAMM_MAGIC = 0x504552434d415443n;
563
+ var MATCHER_MAGIC = VAMM_MAGIC;
564
+ var CTX_RETURN_OFFSET = 0;
565
+ var MATCHER_RETURN_LEN = 64;
563
566
  var CTX_VAMM_OFFSET = 64;
567
+ var CTX_VAMM_LEN = 256;
568
+ var MATCHER_CONTEXT_LEN = 320;
569
+ var MATCHER_CALL_LEN = 67;
570
+ var INIT_CTX_LEN = 78;
564
571
  var BPS_DENOM = 10000n;
565
572
  function computeVammQuote(params, oraclePriceE6, tradeSize, isLong) {
566
573
  const absSize = tradeSize < 0n ? -tradeSize : tradeSize;
@@ -2078,6 +2085,7 @@ var V12_17_ENGINE_OFF = 592;
2078
2085
  var V12_17_ACCOUNT_SIZE = 368;
2079
2086
  var V12_17_ENGINE_BITMAP_OFF = 752;
2080
2087
  var V12_17_RISK_BUF_LEN = 160;
2088
+ var V12_17_GEN_TABLE_ENTRY = 8;
2081
2089
  var V12_17_ENGINE_OFF_SBF = 584;
2082
2090
  var V12_17_ACCOUNT_SIZE_SBF = 352;
2083
2091
  var V12_17_ENGINE_BITMAP_OFF_SBF = 712;
@@ -2110,9 +2118,13 @@ var V12_17_ENGINE_MARKET_MODE_OFF = 232;
2110
2118
  var V12_17_ENGINE_RESOLVED_K_LONG_OFF = 304;
2111
2119
  var V12_17_ENGINE_RESOLVED_K_SHORT_OFF = 320;
2112
2120
  var V12_17_ENGINE_RESOLVED_LIVE_PRICE_OFF = 336;
2121
+ var V12_17_ENGINE_LAST_CRANK_SLOT_OFF = 344;
2113
2122
  var V12_17_ENGINE_C_TOT_OFF = 352;
2114
2123
  var V12_17_ENGINE_PNL_POS_TOT_OFF = 368;
2115
2124
  var V12_17_ENGINE_PNL_MATURED_POS_TOT_OFF = 384;
2125
+ var V12_17_ENGINE_GC_CURSOR_OFF = 400;
2126
+ var V12_17_ENGINE_OI_EFF_LONG_OFF = 528;
2127
+ var V12_17_ENGINE_OI_EFF_SHORT_OFF = 544;
2116
2128
  var V12_17_ENGINE_NEG_PNL_COUNT_OFF = 648;
2117
2129
  var V12_17_ENGINE_LAST_ORACLE_PRICE_OFF = 656;
2118
2130
  var V12_17_ENGINE_FUND_PX_LAST_OFF = 664;
@@ -2120,9 +2132,13 @@ var V12_17_ENGINE_F_LONG_NUM_OFF = 688;
2120
2132
  var V12_17_ENGINE_F_SHORT_NUM_OFF = 704;
2121
2133
  var V12_17_SBF_ENGINE_CURRENT_SLOT_OFF = 216;
2122
2134
  var V12_17_SBF_ENGINE_MARKET_MODE_OFF = 224;
2135
+ var V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF = 328;
2123
2136
  var V12_17_SBF_ENGINE_C_TOT_OFF = 336;
2124
2137
  var V12_17_SBF_ENGINE_PNL_POS_TOT_OFF = 352;
2125
2138
  var V12_17_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF = 368;
2139
+ var V12_17_SBF_ENGINE_GC_CURSOR_OFF = 384;
2140
+ var V12_17_SBF_ENGINE_OI_EFF_LONG_OFF = 504;
2141
+ var V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF = 520;
2126
2142
  var V12_17_SBF_ENGINE_NEG_PNL_COUNT_OFF = 616;
2127
2143
  var V12_17_SBF_ENGINE_LAST_ORACLE_PRICE_OFF = 624;
2128
2144
  var V12_17_SBF_ENGINE_FUND_PX_LAST_OFF = 632;
@@ -2213,11 +2229,11 @@ for (const n of V12_17_TIERS) {
2213
2229
  const nextFreeBytes = n * 2;
2214
2230
  const preAccNative = V12_17_ENGINE_BITMAP_OFF + bitmapBytes + postBitmap + nextFreeBytes;
2215
2231
  const accountsOffNative = Math.ceil(preAccNative / 16) * 16;
2216
- const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + n * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN;
2232
+ const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + n * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN + n * V12_17_GEN_TABLE_ENTRY;
2217
2233
  V12_17_SIZES.set(nativeSize, n);
2218
2234
  const preAccSbf = V12_17_ENGINE_BITMAP_OFF_SBF + bitmapBytes + postBitmap + nextFreeBytes;
2219
2235
  const accountsOffSbf = Math.ceil(preAccSbf / 8) * 8;
2220
- const sbfSize = V12_17_ENGINE_OFF_SBF + accountsOffSbf + n * V12_17_ACCOUNT_SIZE_SBF + V12_17_RISK_BUF_LEN;
2236
+ 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;
2221
2237
  V12_17_SIZES.set(sbfSize, n);
2222
2238
  }
2223
2239
  var V12_1_SBF_ACCOUNT_SIZE = 280;
@@ -2712,7 +2728,7 @@ for (const [label, n] of [["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
2712
2728
  const bitmapBytes = Math.ceil(n / 64) * 8;
2713
2729
  const preAcc = V12_17_ENGINE_BITMAP_OFF_SBF + bitmapBytes + 4 + n * 2;
2714
2730
  const accountsOff = Math.ceil(preAcc / 8) * 8;
2715
- const size = V12_17_ENGINE_OFF_SBF + accountsOff + n * V12_17_ACCOUNT_SIZE_SBF + V12_17_RISK_BUF_LEN;
2731
+ const size = V12_17_ENGINE_OFF_SBF + accountsOff + n * V12_17_ACCOUNT_SIZE_SBF + V12_17_RISK_BUF_LEN + n * V12_17_GEN_TABLE_ENTRY;
2716
2732
  SLAB_TIERS_V12_17[label.toLowerCase()] = { maxAccounts: n, dataSize: size, label, description: `${n} slots (v12.17)` };
2717
2733
  }
2718
2734
  function buildLayoutVSetDexPool(maxAccounts) {
@@ -3018,7 +3034,7 @@ function buildLayoutV12_17(maxAccounts, dataLen) {
3018
3034
  const bitmapBytes2 = Math.ceil(maxAccounts / 64) * 8;
3019
3035
  const preAccNative = V12_17_ENGINE_BITMAP_OFF + bitmapBytes2 + 4 + maxAccounts * 2;
3020
3036
  const accountsOffNative = Math.ceil(preAccNative / 16) * 16;
3021
- const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + maxAccounts * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN;
3037
+ const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + maxAccounts * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN + maxAccounts * V12_17_GEN_TABLE_ENTRY;
3022
3038
  return dataLen !== nativeSize;
3023
3039
  })();
3024
3040
  const engineOff = isSbf ? V12_17_ENGINE_OFF_SBF : V12_17_ENGINE_OFF;
@@ -3061,15 +3077,18 @@ function buildLayoutV12_17(maxAccounts, dataLen) {
3061
3077
  engineFundingRateBpsOff: -1,
3062
3078
  // no stored funding rate in v12.17
3063
3079
  engineMarkPriceOff: -1,
3064
- engineLastCrankSlotOff: -1,
3080
+ // v12.17 computes mark from state; no stored field
3081
+ engineLastCrankSlotOff: isSbf ? V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF : V12_17_ENGINE_LAST_CRANK_SLOT_OFF,
3065
3082
  engineMaxCrankStalenessOff: -1,
3066
3083
  engineTotalOiOff: -1,
3067
- engineLongOiOff: -1,
3068
- engineShortOiOff: -1,
3084
+ // parseEngine sums long + short when total offset is -1
3085
+ engineLongOiOff: isSbf ? V12_17_SBF_ENGINE_OI_EFF_LONG_OFF : V12_17_ENGINE_OI_EFF_LONG_OFF,
3086
+ engineShortOiOff: isSbf ? V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF : V12_17_ENGINE_OI_EFF_SHORT_OFF,
3069
3087
  engineCTotOff: isSbf ? V12_17_SBF_ENGINE_C_TOT_OFF : V12_17_ENGINE_C_TOT_OFF,
3070
3088
  enginePnlPosTotOff: isSbf ? V12_17_SBF_ENGINE_PNL_POS_TOT_OFF : V12_17_ENGINE_PNL_POS_TOT_OFF,
3071
3089
  engineLiqCursorOff: -1,
3072
- engineGcCursorOff: -1,
3090
+ // removed in v12.17
3091
+ engineGcCursorOff: isSbf ? V12_17_SBF_ENGINE_GC_CURSOR_OFF : V12_17_ENGINE_GC_CURSOR_OFF,
3073
3092
  engineLastSweepStartOff: -1,
3074
3093
  engineLastSweepCompleteOff: -1,
3075
3094
  engineCrankCursorOff: -1,
@@ -3491,6 +3510,12 @@ function parseEngine(data) {
3491
3510
  const resolvedKLongOff = isSbf ? 288 : V12_17_ENGINE_RESOLVED_K_LONG_OFF;
3492
3511
  const resolvedKShortOff = isSbf ? 304 : V12_17_ENGINE_RESOLVED_K_SHORT_OFF;
3493
3512
  const resolvedLivePriceOff = isSbf ? 320 : V12_17_ENGINE_RESOLVED_LIVE_PRICE_OFF;
3513
+ const lastCrankSlotOff = isSbf ? V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF : V12_17_ENGINE_LAST_CRANK_SLOT_OFF;
3514
+ const gcCursorOff = isSbf ? V12_17_SBF_ENGINE_GC_CURSOR_OFF : V12_17_ENGINE_GC_CURSOR_OFF;
3515
+ const oiEffLongOff = isSbf ? V12_17_SBF_ENGINE_OI_EFF_LONG_OFF : V12_17_ENGINE_OI_EFF_LONG_OFF;
3516
+ const oiEffShortOff = isSbf ? V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF : V12_17_ENGINE_OI_EFF_SHORT_OFF;
3517
+ const longOi = readU128LE(data, base + oiEffLongOff);
3518
+ const shortOi = readU128LE(data, base + oiEffShortOff);
3494
3519
  const bitmapEnd = layout.engineBitmapOff + layout.bitmapWords * 8;
3495
3520
  return {
3496
3521
  vault: readU128LE(data, base),
@@ -3509,16 +3534,16 @@ function parseEngine(data) {
3509
3534
  fundingRateE9: 0n,
3510
3535
  // no stored funding rate in v12.17
3511
3536
  marketMode: readU8(data, base + marketModeOff) === 1 ? 1 : 0,
3512
- lastCrankSlot: 0n,
3537
+ lastCrankSlot: readU64LE(data, base + lastCrankSlotOff),
3513
3538
  maxCrankStalenessSlots: 0n,
3514
- totalOpenInterest: 0n,
3515
- longOi: 0n,
3516
- shortOi: 0n,
3539
+ totalOpenInterest: longOi + shortOi,
3540
+ longOi,
3541
+ shortOi,
3517
3542
  cTot: readU128LE(data, base + cTotOff),
3518
3543
  pnlPosTot: readU128LE(data, base + pnlPosTotOff),
3519
3544
  pnlMaturedPosTot: readU128LE(data, base + pnlMaturedOff),
3520
3545
  liqCursor: 0,
3521
- gcCursor: 0,
3546
+ gcCursor: readU16LE(data, base + gcCursorOff),
3522
3547
  lastSweepStartSlot: 0n,
3523
3548
  lastSweepCompleteSlot: 0n,
3524
3549
  crankCursor: 0,
@@ -5153,10 +5178,9 @@ function decodeStakePool(data) {
5153
5178
  const reservedStart = off;
5154
5179
  const marketResolved = bytes[reservedStart + 9] === 1;
5155
5180
  const hwmEnabled = bytes[reservedStart + 10] === 1;
5156
- const hwmTvlLow = readU64LE4(bytes, reservedStart + 11);
5157
- const hwmTvlHigh = readU64LE4(bytes, reservedStart + 19);
5158
- const epochHighWaterTvl = hwmTvlLow | hwmTvlHigh << 64n;
5159
- const hwmFloorBps = readU16LE3(bytes, reservedStart + 27);
5181
+ const hwmFloorBps = readU16LE3(bytes, reservedStart + 11);
5182
+ const epochHighWaterTvl = readU64LE4(bytes, reservedStart + 16);
5183
+ const hwmLastEpoch = readU64LE4(bytes, reservedStart + 24);
5160
5184
  const trancheEnabled = bytes[reservedStart + 32] === 1;
5161
5185
  const juniorBalance = readU64LE4(bytes, reservedStart + 33);
5162
5186
  const juniorTotalLp = readU64LE4(bytes, reservedStart + 41);
@@ -5187,6 +5211,7 @@ function decodeStakePool(data) {
5187
5211
  hwmEnabled,
5188
5212
  epochHighWaterTvl,
5189
5213
  hwmFloorBps,
5214
+ hwmLastEpoch,
5190
5215
  trancheEnabled,
5191
5216
  juniorBalance,
5192
5217
  juniorTotalLp,
@@ -6660,10 +6685,13 @@ export {
6660
6685
  CHAINLINK_DECIMALS_OFFSET,
6661
6686
  CHAINLINK_MIN_SIZE,
6662
6687
  CREATOR_LOCK_SEED,
6688
+ CTX_RETURN_OFFSET,
6689
+ CTX_VAMM_LEN,
6663
6690
  CTX_VAMM_OFFSET,
6664
6691
  DEFAULT_OI_RAMP_SLOTS,
6665
6692
  ENGINE_MARK_PRICE_OFF,
6666
6693
  ENGINE_OFF,
6694
+ INIT_CTX_LEN,
6667
6695
  IX_TAG,
6668
6696
  LIGHTHOUSE_CONSTRAINT_ADDRESS,
6669
6697
  LIGHTHOUSE_ERROR_CODES,
@@ -6673,6 +6701,10 @@ export {
6673
6701
  LiquidationPolicyTag,
6674
6702
  MARK_PRICE_EMA_ALPHA_E6,
6675
6703
  MARK_PRICE_EMA_WINDOW_SLOTS,
6704
+ MATCHER_CALL_LEN,
6705
+ MATCHER_CONTEXT_LEN,
6706
+ MATCHER_MAGIC,
6707
+ MATCHER_RETURN_LEN,
6676
6708
  MAX_DECIMALS,
6677
6709
  METEORA_DLMM_PROGRAM_ID,
6678
6710
  NFT_IX_TAG,