@percolatorct/sdk 1.0.0-beta.1 → 1.0.0-beta.11

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.
@@ -117,21 +117,6 @@ export declare const ACCOUNTS_UNPAUSE_MARKET: readonly AccountSpec[];
117
117
  * remember the positional order, and errors clearly on missing names.
118
118
  */
119
119
  export declare function buildAccountMetas(spec: readonly AccountSpec[], keys: PublicKey[] | Record<string, PublicKey>): AccountMeta[];
120
- /**
121
- * CreateInsuranceMint: 9 accounts
122
- * Creates SPL mint PDA for insurance LP tokens. Admin only, once per market.
123
- */
124
- export declare const ACCOUNTS_CREATE_INSURANCE_MINT: readonly AccountSpec[];
125
- /**
126
- * DepositInsuranceLP: 8 accounts
127
- * Deposit collateral into insurance fund, receive LP tokens.
128
- */
129
- export declare const ACCOUNTS_DEPOSIT_INSURANCE_LP: readonly AccountSpec[];
130
- /**
131
- * WithdrawInsuranceLP: 8 accounts
132
- * Burn LP tokens and withdraw proportional share of insurance fund.
133
- */
134
- export declare const ACCOUNTS_WITHDRAW_INSURANCE_LP: readonly AccountSpec[];
135
120
  /**
136
121
  * LpVaultWithdraw: 10 accounts (tag 39, PERC-627 / GH#1926 / PERC-8287)
137
122
  *
@@ -30,16 +30,20 @@ export declare const IX_TAG: {
30
30
  readonly ResolveMarket: 19;
31
31
  readonly WithdrawInsurance: 20;
32
32
  readonly AdminForceClose: 21;
33
- readonly UpdateRiskParams: 22;
34
- readonly RenounceAdmin: 23;
35
- readonly CreateInsuranceMint: 24;
36
- readonly DepositInsuranceLP: 25;
37
- readonly WithdrawInsuranceLP: 26;
38
- readonly PauseMarket: 27;
39
- readonly UnpauseMarket: 28;
40
- readonly AcceptAdmin: 29;
41
- readonly SetInsuranceWithdrawPolicy: 30;
42
- readonly WithdrawInsuranceLimited: 31;
33
+ readonly SetInsuranceWithdrawPolicy: 22;
34
+ /** @deprecated Use SetInsuranceWithdrawPolicy */ readonly UpdateRiskParams: 22;
35
+ readonly WithdrawInsuranceLimited: 23;
36
+ /** @deprecated Use WithdrawInsuranceLimited */ readonly RenounceAdmin: 23;
37
+ readonly QueryLpFees: 24;
38
+ readonly ReclaimEmptyAccount: 25;
39
+ readonly SettleAccount: 26;
40
+ readonly DepositFeeCredits: 27;
41
+ /** @deprecated No on-chain PauseMarket instruction */ readonly PauseMarket: 27;
42
+ readonly ConvertReleasedPnl: 28;
43
+ /** @deprecated No on-chain UnpauseMarket instruction */ readonly UnpauseMarket: 28;
44
+ readonly ResolvePermissionless: 29;
45
+ /** @deprecated Use ResolvePermissionless */ readonly AcceptAdmin: 29;
46
+ readonly ForceCloseResolved: 30;
43
47
  readonly SetPythOracle: 32;
44
48
  readonly UpdateMarkPrice: 33;
45
49
  readonly UpdateHyperpMark: 34;
@@ -138,6 +142,9 @@ export interface InitMarketArgs {
138
142
  invert: number;
139
143
  unitScale: number;
140
144
  initialMarkPriceE6: bigint | string;
145
+ maxMaintenanceFeePerSlot?: bigint | string;
146
+ maxInsuranceFloor?: bigint | string;
147
+ minOraclePriceCap?: bigint | string;
141
148
  warmupPeriodSlots: bigint | string;
142
149
  maintenanceMarginBps: bigint | string;
143
150
  initialMarginBps: bigint | string;
@@ -151,6 +158,9 @@ export interface InitMarketArgs {
151
158
  liquidationFeeCap: bigint | string;
152
159
  liquidationBufferBps: bigint | string;
153
160
  minLiquidationAbs: bigint | string;
161
+ minInitialDeposit: bigint | string;
162
+ minNonzeroMmReq: bigint | string;
163
+ minNonzeroImReq: bigint | string;
154
164
  }
155
165
  export declare function encodeInitMarket(args: InitMarketArgs): Uint8Array;
156
166
  /**
@@ -390,27 +400,6 @@ export declare const UNRESOLVE_CONFIRMATION = 16045690984503054900n;
390
400
  * to prevent accidental invocation.
391
401
  */
392
402
  export declare function encodeRenounceAdmin(): Uint8Array;
393
- /**
394
- * CreateInsuranceMint instruction data (1 byte)
395
- * Creates the SPL mint PDA for insurance LP tokens. Admin only, once per market.
396
- */
397
- export declare function encodeCreateInsuranceMint(): Uint8Array;
398
- /**
399
- * DepositInsuranceLP instruction data (9 bytes)
400
- * Deposit collateral into insurance fund, receive LP tokens proportional to share.
401
- */
402
- export interface DepositInsuranceLPArgs {
403
- amount: bigint | string;
404
- }
405
- export declare function encodeDepositInsuranceLP(args: DepositInsuranceLPArgs): Uint8Array;
406
- /**
407
- * WithdrawInsuranceLP instruction data (9 bytes)
408
- * Burn LP tokens and withdraw proportional share of insurance fund.
409
- */
410
- export interface WithdrawInsuranceLPArgs {
411
- lpAmount: bigint | string;
412
- }
413
- export declare function encodeWithdrawInsuranceLP(args: WithdrawInsuranceLPArgs): Uint8Array;
414
403
  /**
415
404
  * LpVaultWithdraw (Tag 39, PERC-627 / GH#1926 / PERC-8287) — burn LP vault tokens and
416
405
  * withdraw proportional collateral.
@@ -1056,3 +1045,67 @@ export interface InitMatcherCtxArgs {
1056
1045
  skewSpreadMultBps: number;
1057
1046
  }
1058
1047
  export declare function encodeInitMatcherCtx(args: InitMatcherCtxArgs): Uint8Array;
1048
+ /** SetInsuranceWithdrawPolicy (tag 22): authority + min_withdraw_base + max_withdraw_bps + cooldown_slots */
1049
+ export interface SetInsuranceWithdrawPolicyArgs {
1050
+ authority: PublicKey | string;
1051
+ minWithdrawBase: bigint | string;
1052
+ maxWithdrawBps: number;
1053
+ cooldownSlots: bigint | string;
1054
+ }
1055
+ export declare function encodeSetInsuranceWithdrawPolicy(args: SetInsuranceWithdrawPolicyArgs): Uint8Array;
1056
+ /** WithdrawInsuranceLimited (tag 23): amount */
1057
+ export declare function encodeWithdrawInsuranceLimited(args: {
1058
+ amount: bigint | string;
1059
+ }): Uint8Array;
1060
+ /** ResolvePermissionless (tag 29): no args */
1061
+ export declare function encodeResolvePermissionless(): Uint8Array;
1062
+ /** ForceCloseResolved (tag 30): user_idx */
1063
+ export declare function encodeForceCloseResolved(args: {
1064
+ userIdx: number;
1065
+ }): Uint8Array;
1066
+ /** CreateLpVault (tag 37): fee_share_bps + util_curve_enabled */
1067
+ export declare function encodeCreateLpVault(args: {
1068
+ feeShareBps: bigint | string;
1069
+ utilCurveEnabled?: boolean;
1070
+ }): Uint8Array;
1071
+ /** LpVaultDeposit (tag 38): amount */
1072
+ export declare function encodeLpVaultDeposit(args: {
1073
+ amount: bigint | string;
1074
+ }): Uint8Array;
1075
+ /** LpVaultCrankFees (tag 40): no args */
1076
+ export declare function encodeLpVaultCrankFees(): Uint8Array;
1077
+ /** ChallengeSettlement (tag 43): proposed_price_e6 */
1078
+ export declare function encodeChallengeSettlement(args: {
1079
+ proposedPriceE6: bigint | string;
1080
+ }): Uint8Array;
1081
+ /** ResolveDispute (tag 44): accept (0 = reject, 1 = accept) */
1082
+ export declare function encodeResolveDispute(args: {
1083
+ accept: number;
1084
+ }): Uint8Array;
1085
+ /** DepositLpCollateral (tag 45): user_idx + lp_amount */
1086
+ export declare function encodeDepositLpCollateral(args: {
1087
+ userIdx: number;
1088
+ lpAmount: bigint | string;
1089
+ }): Uint8Array;
1090
+ /** WithdrawLpCollateral (tag 46): user_idx + lp_amount */
1091
+ export declare function encodeWithdrawLpCollateral(args: {
1092
+ userIdx: number;
1093
+ lpAmount: bigint | string;
1094
+ }): Uint8Array;
1095
+ /** SetOffsetPair (tag 54): offset_bps */
1096
+ export declare function encodeSetOffsetPair(args: {
1097
+ offsetBps: number;
1098
+ }): Uint8Array;
1099
+ /** AttestCrossMargin (tag 55): user_idx_a + user_idx_b */
1100
+ export declare function encodeAttestCrossMargin(args: {
1101
+ userIdxA: number;
1102
+ userIdxB: number;
1103
+ }): Uint8Array;
1104
+ /** RescueOrphanVault (tag 72): no args */
1105
+ export declare function encodeRescueOrphanVault(): Uint8Array;
1106
+ /** CloseOrphanSlab (tag 73): no args */
1107
+ export declare function encodeCloseOrphanSlab(): Uint8Array;
1108
+ /** SetDexPool (tag 74): pool pubkey */
1109
+ export declare function encodeSetDexPool(args: {
1110
+ pool: PublicKey | string;
1111
+ }): Uint8Array;
@@ -17,7 +17,7 @@ export declare const PROGRAM_IDS: {
17
17
  readonly matcher: "GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k";
18
18
  };
19
19
  readonly mainnet: {
20
- readonly percolator: "GM8zjJ8LTBMv9xEsverh6H6wLyevgMHEJXcEzyY3rY24";
20
+ readonly percolator: "ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv";
21
21
  readonly matcher: "DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX";
22
22
  };
23
23
  };
package/dist/index.js CHANGED
@@ -117,16 +117,33 @@ var IX_TAG = {
117
117
  ResolveMarket: 19,
118
118
  WithdrawInsurance: 20,
119
119
  AdminForceClose: 21,
120
+ // Tags 22-23: on-chain these are SetInsuranceWithdrawPolicy / WithdrawInsuranceLimited.
121
+ // Legacy aliases (UpdateRiskParams/RenounceAdmin) kept for backward compat.
122
+ SetInsuranceWithdrawPolicy: 22,
123
+ /** @deprecated Use SetInsuranceWithdrawPolicy */
120
124
  UpdateRiskParams: 22,
125
+ WithdrawInsuranceLimited: 23,
126
+ /** @deprecated Use WithdrawInsuranceLimited */
121
127
  RenounceAdmin: 23,
122
- CreateInsuranceMint: 24,
123
- DepositInsuranceLP: 25,
124
- WithdrawInsuranceLP: 26,
128
+ // Tags 24–26: on-chain = QueryLpFees/ReclaimEmptyAccount/SettleAccount.
129
+ // Old insurance LP tags removed — those moved to percolator-stake.
130
+ QueryLpFees: 24,
131
+ ReclaimEmptyAccount: 25,
132
+ SettleAccount: 26,
133
+ // Tags 27-28: on-chain = DepositFeeCredits/ConvertReleasedPnl.
134
+ // Legacy aliases (PauseMarket/UnpauseMarket) kept — those instructions don't exist on-chain.
135
+ DepositFeeCredits: 27,
136
+ /** @deprecated No on-chain PauseMarket instruction */
125
137
  PauseMarket: 27,
138
+ ConvertReleasedPnl: 28,
139
+ /** @deprecated No on-chain UnpauseMarket instruction */
126
140
  UnpauseMarket: 28,
141
+ // Tags 29-30: on-chain = ResolvePermissionless/ForceCloseResolved.
142
+ ResolvePermissionless: 29,
143
+ /** @deprecated Use ResolvePermissionless */
127
144
  AcceptAdmin: 29,
128
- SetInsuranceWithdrawPolicy: 30,
129
- WithdrawInsuranceLimited: 31,
145
+ ForceCloseResolved: 30,
146
+ // Tag 31: gap (no decode arm on-chain)
130
147
  SetPythOracle: 32,
131
148
  UpdateMarkPrice: 33,
132
149
  UpdateHyperpMark: 34,
@@ -231,7 +248,7 @@ function encodeFeedId(feedId) {
231
248
  }
232
249
  return bytes;
233
250
  }
234
- var INIT_MARKET_DATA_LEN = 264;
251
+ var INIT_MARKET_DATA_LEN = 352;
235
252
  function encodeInitMarket(args) {
236
253
  const data = concatBytes(
237
254
  encU8(IX_TAG.InitMarket),
@@ -243,6 +260,11 @@ function encodeInitMarket(args) {
243
260
  encU8(args.invert),
244
261
  encU32(args.unitScale),
245
262
  encU64(args.initialMarkPriceE6),
263
+ // 3 fields between header and RiskParams (immutable after init)
264
+ encU128(args.maxMaintenanceFeePerSlot ?? 0n),
265
+ encU128(args.maxInsuranceFloor ?? 0n),
266
+ encU64(args.minOraclePriceCap ?? 0n),
267
+ // RiskParams block (15 fields)
246
268
  encU64(args.warmupPeriodSlots),
247
269
  encU64(args.maintenanceMarginBps),
248
270
  encU64(args.initialMarginBps),
@@ -255,7 +277,10 @@ function encodeInitMarket(args) {
255
277
  encU64(args.liquidationFeeBps),
256
278
  encU128(args.liquidationFeeCap),
257
279
  encU64(args.liquidationBufferBps),
258
- encU128(args.minLiquidationAbs)
280
+ encU128(args.minLiquidationAbs),
281
+ encU128(args.minInitialDeposit),
282
+ encU128(args.minNonzeroMmReq),
283
+ encU128(args.minNonzeroImReq)
259
284
  );
260
285
  if (data.length !== INIT_MARKET_DATA_LEN) {
261
286
  throw new Error(
@@ -428,15 +453,6 @@ function encodeRenounceAdmin() {
428
453
  encU64(RENOUNCE_ADMIN_CONFIRMATION)
429
454
  );
430
455
  }
431
- function encodeCreateInsuranceMint() {
432
- return encU8(IX_TAG.CreateInsuranceMint);
433
- }
434
- function encodeDepositInsuranceLP(args) {
435
- return concatBytes(encU8(IX_TAG.DepositInsuranceLP), encU64(args.amount));
436
- }
437
- function encodeWithdrawInsuranceLP(args) {
438
- return concatBytes(encU8(IX_TAG.WithdrawInsuranceLP), encU64(args.lpAmount));
439
- }
440
456
  function encodeLpVaultWithdraw(args) {
441
457
  return concatBytes(encU8(IX_TAG.LpVaultWithdraw), encU64(args.lpAmount));
442
458
  }
@@ -652,6 +668,58 @@ function encodeInitMatcherCtx(args) {
652
668
  encU16(args.skewSpreadMultBps)
653
669
  );
654
670
  }
671
+ function encodeSetInsuranceWithdrawPolicy(args) {
672
+ return concatBytes(encU8(IX_TAG.SetInsuranceWithdrawPolicy), encPubkey(args.authority), encU64(args.minWithdrawBase), encU16(args.maxWithdrawBps), encU64(args.cooldownSlots));
673
+ }
674
+ function encodeWithdrawInsuranceLimited(args) {
675
+ return concatBytes(encU8(IX_TAG.WithdrawInsuranceLimited), encU64(args.amount));
676
+ }
677
+ function encodeResolvePermissionless() {
678
+ return concatBytes(encU8(IX_TAG.ResolvePermissionless));
679
+ }
680
+ function encodeForceCloseResolved(args) {
681
+ return concatBytes(encU8(IX_TAG.ForceCloseResolved), encU16(args.userIdx));
682
+ }
683
+ function encodeCreateLpVault(args) {
684
+ const parts = [encU8(IX_TAG.CreateLpVault), encU64(args.feeShareBps)];
685
+ if (args.utilCurveEnabled !== void 0) {
686
+ parts.push(encU8(args.utilCurveEnabled ? 1 : 0));
687
+ }
688
+ return concatBytes(...parts);
689
+ }
690
+ function encodeLpVaultDeposit(args) {
691
+ return concatBytes(encU8(IX_TAG.LpVaultDeposit), encU64(args.amount));
692
+ }
693
+ function encodeLpVaultCrankFees() {
694
+ return concatBytes(encU8(IX_TAG.LpVaultCrankFees));
695
+ }
696
+ function encodeChallengeSettlement(args) {
697
+ return concatBytes(encU8(IX_TAG.ChallengeSettlement), encU64(args.proposedPriceE6));
698
+ }
699
+ function encodeResolveDispute(args) {
700
+ return concatBytes(encU8(IX_TAG.ResolveDispute), encU8(args.accept));
701
+ }
702
+ function encodeDepositLpCollateral(args) {
703
+ return concatBytes(encU8(IX_TAG.DepositLpCollateral), encU16(args.userIdx), encU64(args.lpAmount));
704
+ }
705
+ function encodeWithdrawLpCollateral(args) {
706
+ return concatBytes(encU8(IX_TAG.WithdrawLpCollateral), encU16(args.userIdx), encU64(args.lpAmount));
707
+ }
708
+ function encodeSetOffsetPair(args) {
709
+ return concatBytes(encU8(IX_TAG.SetOffsetPair), encU16(args.offsetBps));
710
+ }
711
+ function encodeAttestCrossMargin(args) {
712
+ return concatBytes(encU8(IX_TAG.AttestCrossMargin), encU16(args.userIdxA), encU16(args.userIdxB));
713
+ }
714
+ function encodeRescueOrphanVault() {
715
+ return concatBytes(encU8(IX_TAG.RescueOrphanVault));
716
+ }
717
+ function encodeCloseOrphanSlab() {
718
+ return concatBytes(encU8(IX_TAG.CloseOrphanSlab));
719
+ }
720
+ function encodeSetDexPool(args) {
721
+ return concatBytes(encU8(IX_TAG.SetDexPool), encPubkey(args.pool));
722
+ }
655
723
 
656
724
  // src/abi/accounts.ts
657
725
  import {
@@ -826,37 +894,6 @@ function buildAccountMetas(spec, keys) {
826
894
  isWritable: s.writable
827
895
  }));
828
896
  }
829
- var ACCOUNTS_CREATE_INSURANCE_MINT = [
830
- { name: "admin", signer: true, writable: false },
831
- { name: "slab", signer: false, writable: false },
832
- { name: "insLpMint", signer: false, writable: true },
833
- { name: "vaultAuthority", signer: false, writable: false },
834
- { name: "collateralMint", signer: false, writable: false },
835
- { name: "systemProgram", signer: false, writable: false },
836
- { name: "tokenProgram", signer: false, writable: false },
837
- { name: "rent", signer: false, writable: false },
838
- { name: "payer", signer: true, writable: true }
839
- ];
840
- var ACCOUNTS_DEPOSIT_INSURANCE_LP = [
841
- { name: "depositor", signer: true, writable: false },
842
- { name: "slab", signer: false, writable: true },
843
- { name: "depositorAta", signer: false, writable: true },
844
- { name: "vault", signer: false, writable: true },
845
- { name: "tokenProgram", signer: false, writable: false },
846
- { name: "insLpMint", signer: false, writable: true },
847
- { name: "depositorLpAta", signer: false, writable: true },
848
- { name: "vaultAuthority", signer: false, writable: false }
849
- ];
850
- var ACCOUNTS_WITHDRAW_INSURANCE_LP = [
851
- { name: "withdrawer", signer: true, writable: false },
852
- { name: "slab", signer: false, writable: true },
853
- { name: "withdrawerAta", signer: false, writable: true },
854
- { name: "vault", signer: false, writable: true },
855
- { name: "tokenProgram", signer: false, writable: false },
856
- { name: "insLpMint", signer: false, writable: true },
857
- { name: "withdrawerLpAta", signer: false, writable: true },
858
- { name: "vaultAuthority", signer: false, writable: false }
859
- ];
860
897
  var ACCOUNTS_LP_VAULT_WITHDRAW = [
861
898
  { name: "withdrawer", signer: true, writable: false },
862
899
  { name: "slab", signer: false, writable: true },
@@ -1532,6 +1569,7 @@ var V_ADL_ACCT_FEE_CREDITS_OFF = 224;
1532
1569
  var V_ADL_ACCT_LAST_FEE_SLOT_OFF = 240;
1533
1570
  var V12_1_ENGINE_OFF = 648;
1534
1571
  var V12_1_ACCOUNT_SIZE = 320;
1572
+ var V12_1_ACCOUNT_SIZE_SBF = 280;
1535
1573
  var V12_1_ENGINE_BITMAP_OFF = 1016;
1536
1574
  var V12_1_ENGINE_PARAMS_OFF = 96;
1537
1575
  var V12_1_PARAMS_SIZE = 352;
@@ -1562,7 +1600,14 @@ var V12_1_ENGINE_EMERGENCY_OI_MODE_OFF = 968;
1562
1600
  var V12_1_ENGINE_EMERGENCY_START_SLOT_OFF = 976;
1563
1601
  var V12_1_ENGINE_LAST_BREAKER_SLOT_OFF = 984;
1564
1602
  var V12_1_ENGINE_LIFETIME_FORCE_CLOSES_OFF = 1008;
1603
+ var V12_1_ACCT_MATCHER_PROGRAM_OFF = 144;
1604
+ var V12_1_ACCT_MATCHER_CONTEXT_OFF = 176;
1565
1605
  var V12_1_ACCT_OWNER_OFF = 208;
1606
+ var V12_1_ACCT_FEE_CREDITS_OFF = 240;
1607
+ var V12_1_ACCT_LAST_FEE_SLOT_OFF = 256;
1608
+ var V12_1_ACCT_POSITION_SIZE_OFF = 88;
1609
+ var V12_1_ACCT_ENTRY_PRICE_OFF = -1;
1610
+ var V12_1_ACCT_FUNDING_INDEX_OFF = 288;
1566
1611
  var V1M_ENGINE_OFF = 640;
1567
1612
  var V1M_CONFIG_LEN = 536;
1568
1613
  var V1M_ACCOUNT_SIZE = 248;
@@ -1636,6 +1681,15 @@ for (const n of TIERS) {
1636
1681
  V_SETDEXPOOL_SIZES.set(computeSlabSize(V_SETDEXPOOL_ENGINE_OFF, V_ADL_ENGINE_BITMAP_OFF, V_ADL_ACCOUNT_SIZE, n, 18), n);
1637
1682
  V12_1_SIZES.set(computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, n, 18), n);
1638
1683
  }
1684
+ var V12_1_SBF_ACCOUNT_SIZE = 280;
1685
+ var V12_1_SBF_ENGINE_PREAMBLE = 558;
1686
+ for (const [, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
1687
+ const bitmapBytes = Math.ceil(n / 64) * 8;
1688
+ const preAccLen = V12_1_SBF_ENGINE_PREAMBLE + bitmapBytes + 18 + n * 2;
1689
+ const accountsOff = Math.ceil(preAccLen / 8) * 8;
1690
+ const total = V12_1_ENGINE_OFF + accountsOff + n * V12_1_SBF_ACCOUNT_SIZE;
1691
+ V12_1_SIZES.set(total, n);
1692
+ }
1639
1693
  var SLAB_TIERS_V2 = {
1640
1694
  small: { maxAccounts: 256, dataSize: 65088, label: "Small", description: "256 slots (V2 BPF intermediate)" },
1641
1695
  large: { maxAccounts: 4096, dataSize: 1025568, label: "Large", description: "4,096 slots (V2 BPF intermediate)" }
@@ -2160,10 +2214,12 @@ function buildLayoutVSetDexPool(maxAccounts) {
2160
2214
  engineInsuranceIsolationBpsOff: 64
2161
2215
  };
2162
2216
  }
2163
- function buildLayoutV12_1(maxAccounts) {
2164
- const engineOff = V12_1_ENGINE_OFF;
2165
- const bitmapOff = V12_1_ENGINE_BITMAP_OFF;
2166
- const accountSize = V12_1_ACCOUNT_SIZE;
2217
+ function buildLayoutV12_1(maxAccounts, dataLen) {
2218
+ const hostSize = computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, maxAccounts, 18);
2219
+ const isSbf = dataLen !== void 0 && dataLen !== hostSize;
2220
+ const engineOff = isSbf ? 616 : V12_1_ENGINE_OFF;
2221
+ const bitmapOff = isSbf ? 590 : V12_1_ENGINE_BITMAP_OFF - V12_1_ENGINE_OFF;
2222
+ const accountSize = isSbf ? V12_1_ACCOUNT_SIZE_SBF : V12_1_ACCOUNT_SIZE;
2167
2223
  const bitmapWords = Math.ceil(maxAccounts / 64);
2168
2224
  const bitmapBytes = bitmapWords * 8;
2169
2225
  const postBitmap = 18;
@@ -2172,10 +2228,14 @@ function buildLayoutV12_1(maxAccounts) {
2172
2228
  const accountsOffRel = Math.ceil(preAccountsLen / 8) * 8;
2173
2229
  return {
2174
2230
  version: 1,
2175
- headerLen: V1_HEADER_LEN,
2176
- configOffset: V1_HEADER_LEN,
2177
- configLen: V_SETDEXPOOL_CONFIG_LEN,
2178
- // 544 (same as V_SETDEXPOOL)
2231
+ // V12_1 upstream rebase uses 72-byte header (SlabHeader only, no V1 extension).
2232
+ // Empirically verified: USDC mint found at offset 72 on mainnet slab BVjPc6rd.
2233
+ headerLen: V0_HEADER_LEN,
2234
+ // 72 (not 104 — V12_1 removed the 32-byte header extension)
2235
+ configOffset: V0_HEADER_LEN,
2236
+ // 72
2237
+ configLen: isSbf ? 544 : 576,
2238
+ // SBF=544, host=576 (alignment diff)
2179
2239
  reservedOff: V1_RESERVED_OFF,
2180
2240
  engineOff,
2181
2241
  accountSize,
@@ -2222,7 +2282,7 @@ function buildLayoutV12_1(maxAccounts) {
2222
2282
  }
2223
2283
  function detectSlabLayout(dataLen, data) {
2224
2284
  const v121n = V12_1_SIZES.get(dataLen);
2225
- if (v121n !== void 0) return buildLayoutV12_1(v121n);
2285
+ if (v121n !== void 0) return buildLayoutV12_1(v121n, dataLen);
2226
2286
  const vsdpn = V_SETDEXPOOL_SIZES.get(dataLen);
2227
2287
  if (vsdpn !== void 0) return buildLayoutVSetDexPool(vsdpn);
2228
2288
  const v1m2n = V1M2_SIZES.get(dataLen);
@@ -2389,14 +2449,6 @@ function parseConfig(data, layoutHint) {
2389
2449
  off += 8;
2390
2450
  const fundingMaxBpsPerSlot = readI64LE(data, off);
2391
2451
  off += 8;
2392
- const fundingPremiumWeightBps = readU64LE(data, off);
2393
- off += 8;
2394
- const fundingSettlementIntervalSlots = readU64LE(data, off);
2395
- off += 8;
2396
- const fundingPremiumDampeningE6 = readU64LE(data, off);
2397
- off += 8;
2398
- const fundingPremiumMaxBpsPerSlot = readU64LE(data, off);
2399
- off += 8;
2400
2452
  const threshFloor = readU128LE(data, off);
2401
2453
  off += 16;
2402
2454
  const threshRiskBps = readU64LE(data, off);
@@ -2483,10 +2535,10 @@ function parseConfig(data, layoutHint) {
2483
2535
  fundingInvScaleNotionalE6,
2484
2536
  fundingMaxPremiumBps,
2485
2537
  fundingMaxBpsPerSlot,
2486
- fundingPremiumWeightBps,
2487
- fundingSettlementIntervalSlots,
2488
- fundingPremiumDampeningE6,
2489
- fundingPremiumMaxBpsPerSlot,
2538
+ fundingPremiumWeightBps: 0n,
2539
+ fundingSettlementIntervalSlots: 0n,
2540
+ fundingPremiumDampeningE6: 0n,
2541
+ fundingPremiumMaxBpsPerSlot: 0n,
2490
2542
  threshFloor,
2491
2543
  threshRiskBps,
2492
2544
  threshUpdateIntervalSlots,
@@ -2652,16 +2704,17 @@ function parseAccount(data, idx) {
2652
2704
  if (data.length < base + layout.accountSize) {
2653
2705
  throw new Error("Slab data too short for account");
2654
2706
  }
2655
- const isAdl = layout.accountSize >= 312;
2707
+ const isV12_1 = layout.engineOff === V12_1_ENGINE_OFF && (layout.accountSize === V12_1_ACCOUNT_SIZE || layout.accountSize === V12_1_ACCOUNT_SIZE_SBF);
2708
+ const isAdl = layout.accountSize >= 312 || isV12_1;
2656
2709
  const warmupStartedOff = isAdl ? V_ADL_ACCT_WARMUP_STARTED_OFF : ACCT_WARMUP_STARTED_OFF;
2657
2710
  const warmupSlopeOff = isAdl ? V_ADL_ACCT_WARMUP_SLOPE_OFF : ACCT_WARMUP_SLOPE_OFF;
2658
- const positionSizeOff = isAdl ? V_ADL_ACCT_POSITION_SIZE_OFF : ACCT_POSITION_SIZE_OFF;
2659
- const entryPriceOff = isAdl ? V_ADL_ACCT_ENTRY_PRICE_OFF : ACCT_ENTRY_PRICE_OFF;
2660
- const fundingIndexOff = isAdl ? V_ADL_ACCT_FUNDING_INDEX_OFF : ACCT_FUNDING_INDEX_OFF;
2661
- const matcherProgOff = isAdl ? V_ADL_ACCT_MATCHER_PROGRAM_OFF : ACCT_MATCHER_PROGRAM_OFF;
2662
- const matcherCtxOff = isAdl ? V_ADL_ACCT_MATCHER_CONTEXT_OFF : ACCT_MATCHER_CONTEXT_OFF;
2663
- const feeCreditsOff = isAdl ? V_ADL_ACCT_FEE_CREDITS_OFF : ACCT_FEE_CREDITS_OFF;
2664
- const lastFeeSlotOff = isAdl ? V_ADL_ACCT_LAST_FEE_SLOT_OFF : ACCT_LAST_FEE_SLOT_OFF;
2711
+ const positionSizeOff = isV12_1 ? V12_1_ACCT_POSITION_SIZE_OFF : isAdl ? V_ADL_ACCT_POSITION_SIZE_OFF : ACCT_POSITION_SIZE_OFF;
2712
+ const entryPriceOff = isV12_1 ? V12_1_ACCT_ENTRY_PRICE_OFF : isAdl ? V_ADL_ACCT_ENTRY_PRICE_OFF : ACCT_ENTRY_PRICE_OFF;
2713
+ const fundingIndexOff = isV12_1 ? V12_1_ACCT_FUNDING_INDEX_OFF : isAdl ? V_ADL_ACCT_FUNDING_INDEX_OFF : ACCT_FUNDING_INDEX_OFF;
2714
+ const matcherProgOff = isV12_1 ? V12_1_ACCT_MATCHER_PROGRAM_OFF : isAdl ? V_ADL_ACCT_MATCHER_PROGRAM_OFF : ACCT_MATCHER_PROGRAM_OFF;
2715
+ const matcherCtxOff = isV12_1 ? V12_1_ACCT_MATCHER_CONTEXT_OFF : isAdl ? V_ADL_ACCT_MATCHER_CONTEXT_OFF : ACCT_MATCHER_CONTEXT_OFF;
2716
+ const feeCreditsOff = isV12_1 ? V12_1_ACCT_FEE_CREDITS_OFF : isAdl ? V_ADL_ACCT_FEE_CREDITS_OFF : ACCT_FEE_CREDITS_OFF;
2717
+ const lastFeeSlotOff = isV12_1 ? V12_1_ACCT_LAST_FEE_SLOT_OFF : isAdl ? V_ADL_ACCT_LAST_FEE_SLOT_OFF : ACCT_LAST_FEE_SLOT_OFF;
2665
2718
  const kindByte = readU8(data, base + ACCT_KIND_OFF);
2666
2719
  const kind = kindByte === 1 ? 1 /* LP */ : 0 /* User */;
2667
2720
  return {
@@ -2673,8 +2726,10 @@ function parseAccount(data, idx) {
2673
2726
  warmupStartedAtSlot: readU64LE(data, base + warmupStartedOff),
2674
2727
  warmupSlopePerStep: readU128LE(data, base + warmupSlopeOff),
2675
2728
  positionSize: readI128LE(data, base + positionSizeOff),
2676
- entryPrice: readU64LE(data, base + entryPriceOff),
2677
- fundingIndex: readI128LE(data, base + fundingIndexOff),
2729
+ entryPrice: entryPriceOff >= 0 ? readU64LE(data, base + entryPriceOff) : 0n,
2730
+ // V12_1: entry_price removed
2731
+ // V12_1 changed funding_index from i128 to i64 (legacy field moved to end of account)
2732
+ fundingIndex: isV12_1 ? BigInt(readI64LE(data, base + fundingIndexOff)) : readI128LE(data, base + fundingIndexOff),
2678
2733
  matcherProgram: new PublicKey3(data.subarray(base + matcherProgOff, base + matcherProgOff + 32)),
2679
2734
  matcherContext: new PublicKey3(data.subarray(base + matcherCtxOff, base + matcherCtxOff + 32)),
2680
2735
  owner: new PublicKey3(data.subarray(base + layout.acctOwnerOff, base + layout.acctOwnerOff + 32)),
@@ -2707,12 +2762,6 @@ function deriveVaultAuthority(programId, slab) {
2707
2762
  programId
2708
2763
  );
2709
2764
  }
2710
- function deriveInsuranceLpMint(programId, slab) {
2711
- return PublicKey4.findProgramAddressSync(
2712
- [textEncoder.encode("ins_lp"), slab.toBytes()],
2713
- programId
2714
- );
2715
- }
2716
2765
  var LP_INDEX_U16_MAX = 65535;
2717
2766
  function deriveLpPda(programId, slab, lpIdx) {
2718
2767
  if (typeof lpIdx !== "number" || !Number.isInteger(lpIdx) || lpIdx < 0 || lpIdx > LP_INDEX_U16_MAX) {
@@ -3758,7 +3807,7 @@ var PROGRAM_IDS = {
3758
3807
  matcher: "GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k"
3759
3808
  },
3760
3809
  mainnet: {
3761
- percolator: "GM8zjJ8LTBMv9xEsverh6H6wLyevgMHEJXcEzyY3rY24",
3810
+ percolator: "ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv",
3762
3811
  matcher: "DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX"
3763
3812
  }
3764
3813
  };
@@ -3806,8 +3855,7 @@ function getCurrentNetwork() {
3806
3855
  // src/solana/stake.ts
3807
3856
  var STAKE_PROGRAM_IDS = {
3808
3857
  devnet: "6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k",
3809
- mainnet: ""
3810
- // TODO: populate once DevOps deploys percolator-stake to mainnet
3858
+ mainnet: "DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F"
3811
3859
  };
3812
3860
  function getStakeProgramId(network) {
3813
3861
  const override = safeEnv("STAKE_PROGRAM_ID");
@@ -3829,7 +3877,7 @@ function getStakeProgramId(network) {
3829
3877
  }
3830
3878
  return new PublicKey10(id);
3831
3879
  }
3832
- var STAKE_PROGRAM_ID = new PublicKey10(STAKE_PROGRAM_IDS.devnet);
3880
+ var STAKE_PROGRAM_ID = new PublicKey10(STAKE_PROGRAM_IDS.mainnet);
3833
3881
  var STAKE_IX = {
3834
3882
  InitPool: 0,
3835
3883
  Deposit: 1,
@@ -5050,7 +5098,7 @@ function computeFeeSplit(totalFee, config) {
5050
5098
  const creator = totalFee - lp - protocol;
5051
5099
  if (creator < 0n) {
5052
5100
  throw new Error(
5053
- `Internal error: creator fee is negative (${creator}). This should not happen if lpBps + protocolBps + creatorBps <= 10000.`
5101
+ `Internal error: creator fee is negative (${creator}). This should not happen if lpBps + protocolBps + creatorBps === 10000.`
5054
5102
  );
5055
5103
  }
5056
5104
  return [lp, protocol, creator];
@@ -5613,9 +5661,7 @@ export {
5613
5661
  ACCOUNTS_CLOSE_ACCOUNT,
5614
5662
  ACCOUNTS_CLOSE_SLAB,
5615
5663
  ACCOUNTS_CLOSE_STALE_SLABS,
5616
- ACCOUNTS_CREATE_INSURANCE_MINT,
5617
5664
  ACCOUNTS_DEPOSIT_COLLATERAL,
5618
- ACCOUNTS_DEPOSIT_INSURANCE_LP,
5619
5665
  ACCOUNTS_EXECUTE_ADL,
5620
5666
  ACCOUNTS_FUND_MARKET_INSURANCE,
5621
5667
  ACCOUNTS_INIT_LP,
@@ -5649,7 +5695,6 @@ export {
5649
5695
  ACCOUNTS_UPDATE_CONFIG,
5650
5696
  ACCOUNTS_WITHDRAW_COLLATERAL,
5651
5697
  ACCOUNTS_WITHDRAW_INSURANCE,
5652
- ACCOUNTS_WITHDRAW_INSURANCE_LP,
5653
5698
  AccountKind,
5654
5699
  CHAINLINK_ANSWER_OFFSET,
5655
5700
  CHAINLINK_DECIMALS_OFFSET,
@@ -5746,7 +5791,6 @@ export {
5746
5791
  depositAccounts,
5747
5792
  deriveCreatorLockPda,
5748
5793
  deriveDepositPda,
5749
- deriveInsuranceLpMint,
5750
5794
  deriveKeeperFund,
5751
5795
  deriveLpPda,
5752
5796
  derivePythPriceUpdateAccount,
@@ -5774,19 +5818,23 @@ export {
5774
5818
  encodeAdvanceEpoch,
5775
5819
  encodeAdvanceOraclePhase,
5776
5820
  encodeAllocateMarket,
5821
+ encodeAttestCrossMargin,
5777
5822
  encodeAuditCrank,
5778
5823
  encodeBurnPositionNft,
5779
5824
  encodeCancelQueuedWithdrawal,
5825
+ encodeChallengeSettlement,
5780
5826
  encodeClaimEpochWithdrawal,
5781
5827
  encodeClaimQueuedWithdrawal,
5782
5828
  encodeClearPendingSettlement,
5783
5829
  encodeCloseAccount,
5830
+ encodeCloseOrphanSlab,
5784
5831
  encodeCloseSlab,
5785
5832
  encodeCloseStaleSlabs,
5786
- encodeCreateInsuranceMint,
5833
+ encodeCreateLpVault,
5787
5834
  encodeDepositCollateral,
5788
- encodeDepositInsuranceLP,
5835
+ encodeDepositLpCollateral,
5789
5836
  encodeExecuteAdl,
5837
+ encodeForceCloseResolved,
5790
5838
  encodeFundMarketInsurance,
5791
5839
  encodeInitLP,
5792
5840
  encodeInitMarket,
@@ -5795,6 +5843,8 @@ export {
5795
5843
  encodeInitUser,
5796
5844
  encodeKeeperCrank,
5797
5845
  encodeLiquidateAtOracle,
5846
+ encodeLpVaultCrankFees,
5847
+ encodeLpVaultDeposit,
5798
5848
  encodeLpVaultWithdraw,
5799
5849
  encodeMintPositionNft,
5800
5850
  encodePauseMarket,
@@ -5803,9 +5853,15 @@ export {
5803
5853
  encodeQueueWithdrawalSV,
5804
5854
  encodeReclaimSlabRent,
5805
5855
  encodeRenounceAdmin,
5856
+ encodeRescueOrphanVault,
5857
+ encodeResolveDispute,
5806
5858
  encodeResolveMarket,
5859
+ encodeResolvePermissionless,
5860
+ encodeSetDexPool,
5807
5861
  encodeSetInsuranceIsolation,
5862
+ encodeSetInsuranceWithdrawPolicy,
5808
5863
  encodeSetMaintenanceFee,
5864
+ encodeSetOffsetPair,
5809
5865
  encodeSetOiImbalanceHardBlock,
5810
5866
  encodeSetOracleAuthority,
5811
5867
  encodeSetOraclePriceCap,
@@ -5846,7 +5902,8 @@ export {
5846
5902
  encodeUpdateRiskParams,
5847
5903
  encodeWithdrawCollateral,
5848
5904
  encodeWithdrawInsurance,
5849
- encodeWithdrawInsuranceLP,
5905
+ encodeWithdrawInsuranceLimited,
5906
+ encodeWithdrawLpCollateral,
5850
5907
  fetchAdlRankedPositions,
5851
5908
  fetchAdlRankings,
5852
5909
  fetchSlab,