@percolatorct/sdk 1.0.0-beta.9 → 2.0.0
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 +24 -4
- package/dist/abi/accounts.d.ts +129 -25
- package/dist/abi/errors.d.ts +0 -11
- package/dist/abi/index.d.ts +1 -0
- package/dist/abi/instructions.d.ts +429 -150
- package/dist/abi/nft.d.ts +136 -0
- package/dist/config/program-ids.d.ts +1 -1
- package/dist/index.js +1893 -688
- package/dist/index.js.map +1 -1
- package/dist/math/trading.d.ts +1 -116
- package/dist/math/warmup.d.ts +0 -50
- package/dist/runtime/lighthouse.d.ts +1 -1
- package/dist/solana/discovery.d.ts +2 -13
- package/dist/solana/oracle.d.ts +2 -10
- package/dist/solana/pda.d.ts +6 -5
- package/dist/solana/slab.d.ts +133 -9
- package/dist/solana/stake.d.ts +51 -9
- package/dist/validation.d.ts +1 -26
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
// src/abi/encode.ts
|
|
2
2
|
import { PublicKey } from "@solana/web3.js";
|
|
3
|
+
var U8_MAX = 255;
|
|
4
|
+
var U16_MAX = 65535;
|
|
5
|
+
var U32_MAX = 4294967295;
|
|
3
6
|
function encU8(val) {
|
|
4
|
-
if (!Number.isInteger(val) || val < 0 || val >
|
|
7
|
+
if (!Number.isInteger(val) || val < 0 || val > U8_MAX) {
|
|
5
8
|
throw new Error(`encU8: value out of range (0..255), got ${val}`);
|
|
6
9
|
}
|
|
7
10
|
return new Uint8Array([val]);
|
|
8
11
|
}
|
|
9
12
|
function encU16(val) {
|
|
10
|
-
if (!Number.isInteger(val) || val < 0 || val >
|
|
13
|
+
if (!Number.isInteger(val) || val < 0 || val > U16_MAX) {
|
|
11
14
|
throw new Error(`encU16: value out of range (0..65535), got ${val}`);
|
|
12
15
|
}
|
|
13
16
|
const buf = new Uint8Array(2);
|
|
@@ -15,7 +18,7 @@ function encU16(val) {
|
|
|
15
18
|
return buf;
|
|
16
19
|
}
|
|
17
20
|
function encU32(val) {
|
|
18
|
-
if (!Number.isInteger(val) || val < 0 || val >
|
|
21
|
+
if (!Number.isInteger(val) || val < 0 || val > U32_MAX) {
|
|
19
22
|
throw new Error(`encU32: value out of range (0..4294967295), got ${val}`);
|
|
20
23
|
}
|
|
21
24
|
const buf = new Uint8Array(4);
|
|
@@ -93,7 +96,6 @@ function concatBytes(...arrays) {
|
|
|
93
96
|
}
|
|
94
97
|
|
|
95
98
|
// src/abi/instructions.ts
|
|
96
|
-
var MAX_ORACLE_PRICE = 1000000000000n;
|
|
97
99
|
var IX_TAG = {
|
|
98
100
|
InitMarket: 0,
|
|
99
101
|
InitUser: 1,
|
|
@@ -111,8 +113,7 @@ var IX_TAG = {
|
|
|
111
113
|
CloseSlab: 13,
|
|
112
114
|
UpdateConfig: 14,
|
|
113
115
|
SetMaintenanceFee: 15,
|
|
114
|
-
|
|
115
|
-
PushOraclePrice: 17,
|
|
116
|
+
// 16, 17 — removed in v1.0.0-beta.29 (Phase G admin-push oracle removal)
|
|
116
117
|
SetOraclePriceCap: 18,
|
|
117
118
|
ResolveMarket: 19,
|
|
118
119
|
WithdrawInsurance: 20,
|
|
@@ -131,17 +132,12 @@ var IX_TAG = {
|
|
|
131
132
|
ReclaimEmptyAccount: 25,
|
|
132
133
|
SettleAccount: 26,
|
|
133
134
|
// Tags 27-28: on-chain = DepositFeeCredits/ConvertReleasedPnl.
|
|
134
|
-
// Legacy aliases (PauseMarket/UnpauseMarket) kept — those instructions don't exist on-chain.
|
|
135
135
|
DepositFeeCredits: 27,
|
|
136
|
-
/** @deprecated No on-chain PauseMarket instruction */
|
|
137
|
-
PauseMarket: 27,
|
|
138
136
|
ConvertReleasedPnl: 28,
|
|
139
|
-
/** @deprecated No on-chain UnpauseMarket instruction */
|
|
140
|
-
UnpauseMarket: 28,
|
|
141
137
|
// Tags 29-30: on-chain = ResolvePermissionless/ForceCloseResolved.
|
|
142
138
|
ResolvePermissionless: 29,
|
|
143
|
-
|
|
144
|
-
AcceptAdmin
|
|
139
|
+
// Note: `AcceptAdmin` used to be a @deprecated alias for tag 29; removed in
|
|
140
|
+
// beta.27 because AcceptAdmin is now a real instruction at tag 82 (Phase E).
|
|
145
141
|
ForceCloseResolved: 30,
|
|
146
142
|
// Tag 31: gap (no decode arm on-chain)
|
|
147
143
|
SetPythOracle: 32,
|
|
@@ -188,8 +184,7 @@ var IX_TAG = {
|
|
|
188
184
|
AttestCrossMargin: 55,
|
|
189
185
|
/** PERC-622: Advance oracle phase (permissionless crank) */
|
|
190
186
|
AdvanceOraclePhase: 56,
|
|
191
|
-
|
|
192
|
-
TopUpKeeperFund: 57,
|
|
187
|
+
// 57: removed (keeper fund)
|
|
193
188
|
/** PERC-629: Slash a market creator's deposit (permissionless) */
|
|
194
189
|
SlashCreationDeposit: 58,
|
|
195
190
|
/** PERC-628: Initialize the global shared vault (admin) */
|
|
@@ -225,9 +220,36 @@ var IX_TAG = {
|
|
|
225
220
|
/** PERC-SetDexPool: Pin admin-approved DEX pool address for a HYPERP market (admin). */
|
|
226
221
|
SetDexPool: 74,
|
|
227
222
|
/** CPI to the matcher program to initialize a matcher context account for an LP slot. Admin-only. */
|
|
228
|
-
InitMatcherCtx: 75
|
|
223
|
+
InitMatcherCtx: 75,
|
|
224
|
+
/** PauseMarket (tag 76): admin emergency pause. Blocks Trade/Deposit/Withdraw/InitUser. */
|
|
225
|
+
PauseMarket: 76,
|
|
226
|
+
/** UnpauseMarket (tag 77): admin unpause. Re-enables all operations. */
|
|
227
|
+
UnpauseMarket: 77,
|
|
228
|
+
/** PERC-305 / SECURITY(H-4): Set PnL cap for ADL pre-check (admin only). */
|
|
229
|
+
SetMaxPnlCap: 78,
|
|
230
|
+
/** PERC-309: Set OI cap multiplier for LP withdrawal limits (admin only). Packed u64. */
|
|
231
|
+
SetOiCapMultiplier: 79,
|
|
232
|
+
/** PERC-314: Set dispute params (window_slots + bond_amount, admin only). */
|
|
233
|
+
SetDisputeParams: 80,
|
|
234
|
+
/** PERC-315: Set LP collateral params (enabled + ltv_bps, admin only). */
|
|
235
|
+
SetLpCollateralParams: 81,
|
|
236
|
+
/** Phase E (2026-04-17): Accept a pending admin transfer. Signer must match pending_admin. */
|
|
237
|
+
AcceptAdmin: 82,
|
|
238
|
+
/**
|
|
239
|
+
* v12.18.x 4-way authority split (added 2026-04-22, wrapper 86ea41f).
|
|
240
|
+
* Unified mutator for admin/hyperp_mark/insurance/insurance_operator.
|
|
241
|
+
* Wrapper handler: src/percolator.rs:6876.
|
|
242
|
+
*/
|
|
243
|
+
UpdateAuthority: 83
|
|
244
|
+
// 78: removed (keeper fund)
|
|
229
245
|
};
|
|
230
246
|
Object.freeze(IX_TAG);
|
|
247
|
+
function removedInstruction(name, tag, replacement) {
|
|
248
|
+
const suffix = replacement ? ` Use ${replacement} instead.` : "";
|
|
249
|
+
throw new Error(
|
|
250
|
+
`${name} (tag ${tag}) is not accepted by the deployed wrapper program.${suffix}`
|
|
251
|
+
);
|
|
252
|
+
}
|
|
231
253
|
var HEX_RE = /^[0-9a-fA-F]{64}$/;
|
|
232
254
|
function encodeFeedId(feedId) {
|
|
233
255
|
const hex = feedId.startsWith("0x") ? feedId.slice(2) : feedId;
|
|
@@ -248,9 +270,29 @@ function encodeFeedId(feedId) {
|
|
|
248
270
|
}
|
|
249
271
|
return bytes;
|
|
250
272
|
}
|
|
251
|
-
var
|
|
273
|
+
var INIT_MARKET_BASE_LEN = 304;
|
|
274
|
+
var INIT_MARKET_EXTENDED_TAIL_LEN = 66;
|
|
275
|
+
function extendedTailHasNonZero(t) {
|
|
276
|
+
const toBigInt = (v) => typeof v === "string" ? BigInt(v) : v;
|
|
277
|
+
return t.insuranceWithdrawMaxBps !== 0 || toBigInt(t.insuranceWithdrawCooldownSlots) !== 0n || toBigInt(t.permissionlessResolveStaleSlots) !== 0n || toBigInt(t.fundingHorizonSlots) !== 0n || toBigInt(t.fundingKBps) !== 0n || toBigInt(t.fundingMaxPremiumBps) !== 0n || toBigInt(t.fundingMaxBpsPerSlot) !== 0n || toBigInt(t.markMinFee) !== 0n || toBigInt(t.forceCloseDelaySlots) !== 0n;
|
|
278
|
+
}
|
|
279
|
+
function encodeExtendedTail(t) {
|
|
280
|
+
return concatBytes(
|
|
281
|
+
encU16(t.insuranceWithdrawMaxBps),
|
|
282
|
+
encU64(t.insuranceWithdrawCooldownSlots),
|
|
283
|
+
encU64(t.permissionlessResolveStaleSlots),
|
|
284
|
+
encU64(t.fundingHorizonSlots),
|
|
285
|
+
encU64(t.fundingKBps),
|
|
286
|
+
encI64(t.fundingMaxPremiumBps),
|
|
287
|
+
encI64(t.fundingMaxBpsPerSlot),
|
|
288
|
+
encU64(t.markMinFee),
|
|
289
|
+
encU64(t.forceCloseDelaySlots)
|
|
290
|
+
);
|
|
291
|
+
}
|
|
252
292
|
function encodeInitMarket(args) {
|
|
253
|
-
const
|
|
293
|
+
const hMin = args.hMin ?? args.warmupPeriodSlots ?? 0n;
|
|
294
|
+
const hMax = args.hMax ?? args.warmupPeriodSlots ?? 0n;
|
|
295
|
+
const header = concatBytes(
|
|
254
296
|
encU8(IX_TAG.InitMarket),
|
|
255
297
|
encPubkey(args.admin),
|
|
256
298
|
encPubkey(args.collateralMint),
|
|
@@ -260,34 +302,43 @@ function encodeInitMarket(args) {
|
|
|
260
302
|
encU8(args.invert),
|
|
261
303
|
encU32(args.unitScale),
|
|
262
304
|
encU64(args.initialMarkPriceE6),
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
encU64(
|
|
267
|
-
// RiskParams block (15 fields)
|
|
268
|
-
encU64(args.warmupPeriodSlots),
|
|
305
|
+
encU128(args.maxMaintenanceFeePerSlot ?? 0n)
|
|
306
|
+
);
|
|
307
|
+
const riskParamsCommon = concatBytes(
|
|
308
|
+
encU64(hMin),
|
|
269
309
|
encU64(args.maintenanceMarginBps),
|
|
270
310
|
encU64(args.initialMarginBps),
|
|
271
311
|
encU64(args.tradingFeeBps),
|
|
272
312
|
encU64(args.maxAccounts),
|
|
273
313
|
encU128(args.newAccountFee),
|
|
274
|
-
encU128(args.
|
|
275
|
-
|
|
314
|
+
encU128(args.insuranceFloor ?? 0n),
|
|
315
|
+
encU64(hMax),
|
|
276
316
|
encU64(args.maxCrankStalenessSlots),
|
|
277
317
|
encU64(args.liquidationFeeBps),
|
|
278
318
|
encU128(args.liquidationFeeCap),
|
|
279
|
-
encU64(args.liquidationBufferBps),
|
|
280
|
-
encU128(args.minLiquidationAbs)
|
|
281
|
-
|
|
319
|
+
encU64(args.liquidationBufferBps ?? 0n),
|
|
320
|
+
encU128(args.minLiquidationAbs)
|
|
321
|
+
);
|
|
322
|
+
const riskParamsTail = concatBytes(
|
|
282
323
|
encU128(args.minNonzeroMmReq),
|
|
283
324
|
encU128(args.minNonzeroImReq)
|
|
284
325
|
);
|
|
285
|
-
|
|
326
|
+
const base = concatBytes(header, riskParamsCommon, riskParamsTail);
|
|
327
|
+
if (base.length !== INIT_MARKET_BASE_LEN) {
|
|
286
328
|
throw new Error(
|
|
287
|
-
`encodeInitMarket: expected ${
|
|
329
|
+
`encodeInitMarket: base payload expected ${INIT_MARKET_BASE_LEN} bytes, got ${base.length}`
|
|
288
330
|
);
|
|
289
331
|
}
|
|
290
|
-
|
|
332
|
+
if (args.extendedTail && extendedTailHasNonZero(args.extendedTail)) {
|
|
333
|
+
const tail = encodeExtendedTail(args.extendedTail);
|
|
334
|
+
if (tail.length !== INIT_MARKET_EXTENDED_TAIL_LEN) {
|
|
335
|
+
throw new Error(
|
|
336
|
+
`encodeInitMarket: extended tail expected ${INIT_MARKET_EXTENDED_TAIL_LEN} bytes, got ${tail.length}`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
return concatBytes(base, tail);
|
|
340
|
+
}
|
|
341
|
+
return base;
|
|
291
342
|
}
|
|
292
343
|
function encodeInitUser(args) {
|
|
293
344
|
return concatBytes(encU8(IX_TAG.InitUser), encU64(args.feePayment));
|
|
@@ -314,12 +365,28 @@ function encodeWithdrawCollateral(args) {
|
|
|
314
365
|
encU64(args.amount)
|
|
315
366
|
);
|
|
316
367
|
}
|
|
368
|
+
var LiquidationPolicyTag = {
|
|
369
|
+
FullClose: 0,
|
|
370
|
+
ExactPartial: 1,
|
|
371
|
+
TouchOnly: 255
|
|
372
|
+
};
|
|
317
373
|
function encodeKeeperCrank(args) {
|
|
318
|
-
|
|
374
|
+
const parts = [
|
|
319
375
|
encU8(IX_TAG.KeeperCrank),
|
|
320
376
|
encU16(args.callerIdx),
|
|
321
|
-
encU8(
|
|
322
|
-
|
|
377
|
+
encU8(1)
|
|
378
|
+
// format_version = 1 (REQUIRED by v12.17)
|
|
379
|
+
];
|
|
380
|
+
if (args.candidates) {
|
|
381
|
+
for (const c of args.candidates) {
|
|
382
|
+
parts.push(encU16(c.idx));
|
|
383
|
+
parts.push(encU8(c.policy));
|
|
384
|
+
if (c.policy === LiquidationPolicyTag.ExactPartial) {
|
|
385
|
+
parts.push(encU128(c.quantity));
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return concatBytes(...parts);
|
|
323
390
|
}
|
|
324
391
|
function encodeTradeNoCpi(args) {
|
|
325
392
|
return concatBytes(
|
|
@@ -346,23 +413,18 @@ function encodeTradeCpi(args) {
|
|
|
346
413
|
encU8(IX_TAG.TradeCpi),
|
|
347
414
|
encU16(args.lpIdx),
|
|
348
415
|
encU16(args.userIdx),
|
|
349
|
-
encI128(args.size)
|
|
350
|
-
);
|
|
351
|
-
}
|
|
352
|
-
function encodeTradeCpiV2(args) {
|
|
353
|
-
return concatBytes(
|
|
354
|
-
encU8(IX_TAG.TradeCpiV2),
|
|
355
|
-
encU16(args.lpIdx),
|
|
356
|
-
encU16(args.userIdx),
|
|
357
416
|
encI128(args.size),
|
|
358
|
-
|
|
417
|
+
encU64(args.limitPriceE6)
|
|
359
418
|
);
|
|
360
419
|
}
|
|
361
|
-
function
|
|
362
|
-
return
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
);
|
|
420
|
+
function encodeTradeCpiV2(_args) {
|
|
421
|
+
return removedInstruction("TradeCpiV2", IX_TAG.TradeCpiV2, "encodeTradeCpi()");
|
|
422
|
+
}
|
|
423
|
+
function encodeUnresolveMarket(_args) {
|
|
424
|
+
return removedInstruction("UnresolveMarket", IX_TAG.UnresolveMarket, "encodeResolveMarket()");
|
|
425
|
+
}
|
|
426
|
+
function encodeSetRiskThreshold(_args) {
|
|
427
|
+
return removedInstruction("SetRiskThreshold", IX_TAG.SetRiskThreshold, "encodeInitMarket()");
|
|
366
428
|
}
|
|
367
429
|
function encodeUpdateAdmin(args) {
|
|
368
430
|
return concatBytes(encU8(IX_TAG.UpdateAdmin), encPubkey(args.newAdmin));
|
|
@@ -375,46 +437,13 @@ function encodeUpdateConfig(args) {
|
|
|
375
437
|
encU8(IX_TAG.UpdateConfig),
|
|
376
438
|
encU64(args.fundingHorizonSlots),
|
|
377
439
|
encU64(args.fundingKBps),
|
|
378
|
-
encU128(args.fundingInvScaleNotionalE6),
|
|
379
440
|
encI64(args.fundingMaxPremiumBps),
|
|
380
|
-
// Rust: i64 (can be negative)
|
|
381
441
|
encI64(args.fundingMaxBpsPerSlot),
|
|
382
|
-
|
|
383
|
-
encU128(args.threshFloor),
|
|
384
|
-
encU64(args.threshRiskBps),
|
|
385
|
-
encU64(args.threshUpdateIntervalSlots),
|
|
386
|
-
encU64(args.threshStepBps),
|
|
387
|
-
encU64(args.threshAlphaBps),
|
|
388
|
-
encU128(args.threshMin),
|
|
389
|
-
encU128(args.threshMax),
|
|
390
|
-
encU128(args.threshMinStep)
|
|
442
|
+
encU16(args.tvlInsuranceCapMult ?? 0)
|
|
391
443
|
);
|
|
392
444
|
}
|
|
393
|
-
function encodeSetMaintenanceFee(
|
|
394
|
-
return
|
|
395
|
-
encU8(IX_TAG.SetMaintenanceFee),
|
|
396
|
-
encU128(args.newFee)
|
|
397
|
-
);
|
|
398
|
-
}
|
|
399
|
-
function encodeSetOracleAuthority(args) {
|
|
400
|
-
return concatBytes(
|
|
401
|
-
encU8(IX_TAG.SetOracleAuthority),
|
|
402
|
-
encPubkey(args.newAuthority)
|
|
403
|
-
);
|
|
404
|
-
}
|
|
405
|
-
function encodePushOraclePrice(args) {
|
|
406
|
-
const price = typeof args.priceE6 === "string" ? BigInt(args.priceE6) : args.priceE6;
|
|
407
|
-
if (price === 0n) {
|
|
408
|
-
throw new Error("encodePushOraclePrice: price cannot be zero (division by zero in engine)");
|
|
409
|
-
}
|
|
410
|
-
if (price > MAX_ORACLE_PRICE) {
|
|
411
|
-
throw new Error(`encodePushOraclePrice: price exceeds maximum (${MAX_ORACLE_PRICE}), got ${price}`);
|
|
412
|
-
}
|
|
413
|
-
return concatBytes(
|
|
414
|
-
encU8(IX_TAG.PushOraclePrice),
|
|
415
|
-
encU64(price),
|
|
416
|
-
encI64(args.timestamp)
|
|
417
|
-
);
|
|
445
|
+
function encodeSetMaintenanceFee(_args) {
|
|
446
|
+
return removedInstruction("SetMaintenanceFee", IX_TAG.SetMaintenanceFee, "encodeInitMarket()");
|
|
418
447
|
}
|
|
419
448
|
function encodeSetOraclePriceCap(args) {
|
|
420
449
|
return concatBytes(
|
|
@@ -434,23 +463,20 @@ function encodeAdminForceClose(args) {
|
|
|
434
463
|
encU16(args.targetIdx)
|
|
435
464
|
);
|
|
436
465
|
}
|
|
437
|
-
function encodeUpdateRiskParams(
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
if (args.tradingFeeBps !== void 0) {
|
|
444
|
-
parts.push(encU64(args.tradingFeeBps));
|
|
445
|
-
}
|
|
446
|
-
return concatBytes(...parts);
|
|
466
|
+
function encodeUpdateRiskParams(_args) {
|
|
467
|
+
return removedInstruction(
|
|
468
|
+
"UpdateRiskParams",
|
|
469
|
+
IX_TAG.UpdateRiskParams,
|
|
470
|
+
"encodeSetInsuranceWithdrawPolicy()"
|
|
471
|
+
);
|
|
447
472
|
}
|
|
448
473
|
var RENOUNCE_ADMIN_CONFIRMATION = 0x52454E4F554E4345n;
|
|
449
474
|
var UNRESOLVE_CONFIRMATION = 0xDEADBEEFCAFE1234n;
|
|
450
475
|
function encodeRenounceAdmin() {
|
|
451
|
-
return
|
|
452
|
-
|
|
453
|
-
|
|
476
|
+
return removedInstruction(
|
|
477
|
+
"RenounceAdmin",
|
|
478
|
+
IX_TAG.RenounceAdmin,
|
|
479
|
+
"encodeWithdrawInsuranceLimited()"
|
|
454
480
|
);
|
|
455
481
|
}
|
|
456
482
|
function encodeLpVaultWithdraw(args) {
|
|
@@ -463,34 +489,22 @@ function encodeUnpauseMarket() {
|
|
|
463
489
|
return encU8(IX_TAG.UnpauseMarket);
|
|
464
490
|
}
|
|
465
491
|
function encodeSetPythOracle(args) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
const buf = new Uint8Array(43);
|
|
469
|
-
const dv3 = new DataView(buf.buffer);
|
|
470
|
-
buf[0] = 32;
|
|
471
|
-
buf.set(args.feedId, 1);
|
|
472
|
-
dv3.setBigUint64(
|
|
473
|
-
33,
|
|
474
|
-
args.maxStalenessSecs,
|
|
475
|
-
/* little-endian */
|
|
476
|
-
true
|
|
477
|
-
);
|
|
478
|
-
dv3.setUint16(41, args.confFilterBps, true);
|
|
479
|
-
return buf;
|
|
492
|
+
void args;
|
|
493
|
+
return removedInstruction("SetPythOracle", IX_TAG.SetPythOracle, "encodeInitMarket()");
|
|
480
494
|
}
|
|
481
495
|
var PYTH_RECEIVER_PROGRAM_ID = "rec5EKMGg6MxZYaMdyBfgwp4d5rB9T1VQH5pJv5LtFJ";
|
|
482
496
|
async function derivePythPriceUpdateAccount(feedId, shardId = 0) {
|
|
483
|
-
const { PublicKey:
|
|
497
|
+
const { PublicKey: PublicKey16 } = await import("@solana/web3.js");
|
|
484
498
|
const shardBuf = new Uint8Array(2);
|
|
485
499
|
new DataView(shardBuf.buffer).setUint16(0, shardId, true);
|
|
486
|
-
const [pda] =
|
|
500
|
+
const [pda] = PublicKey16.findProgramAddressSync(
|
|
487
501
|
[shardBuf, feedId],
|
|
488
|
-
new
|
|
502
|
+
new PublicKey16(PYTH_RECEIVER_PROGRAM_ID)
|
|
489
503
|
);
|
|
490
504
|
return pda.toBase58();
|
|
491
505
|
}
|
|
492
506
|
function encodeUpdateMarkPrice() {
|
|
493
|
-
return
|
|
507
|
+
return removedInstruction("UpdateMarkPrice", IX_TAG.UpdateMarkPrice, "encodeUpdateHyperpMark()");
|
|
494
508
|
}
|
|
495
509
|
var MARK_PRICE_EMA_WINDOW_SLOTS = 72000n;
|
|
496
510
|
var MARK_PRICE_EMA_ALPHA_E6 = 2000000n / (MARK_PRICE_EMA_WINDOW_SLOTS + 1n);
|
|
@@ -516,7 +530,12 @@ function encodeFundMarketInsurance(args) {
|
|
|
516
530
|
return concatBytes(encU8(IX_TAG.FundMarketInsurance), encU64(args.amount));
|
|
517
531
|
}
|
|
518
532
|
function encodeSetInsuranceIsolation(args) {
|
|
519
|
-
|
|
533
|
+
void args;
|
|
534
|
+
return removedInstruction(
|
|
535
|
+
"SetInsuranceIsolation",
|
|
536
|
+
IX_TAG.SetInsuranceIsolation,
|
|
537
|
+
"encodeFundMarketInsurance()"
|
|
538
|
+
);
|
|
520
539
|
}
|
|
521
540
|
function encodeQueueWithdrawal(args) {
|
|
522
541
|
return concatBytes(encU8(IX_TAG.QueueWithdrawal), encU64(args.lpAmount));
|
|
@@ -540,7 +559,14 @@ function encodeAuditCrank() {
|
|
|
540
559
|
return encU8(IX_TAG.AuditCrank);
|
|
541
560
|
}
|
|
542
561
|
var VAMM_MAGIC = 0x504552434d415443n;
|
|
562
|
+
var MATCHER_MAGIC = VAMM_MAGIC;
|
|
563
|
+
var CTX_RETURN_OFFSET = 0;
|
|
564
|
+
var MATCHER_RETURN_LEN = 64;
|
|
543
565
|
var CTX_VAMM_OFFSET = 64;
|
|
566
|
+
var CTX_VAMM_LEN = 256;
|
|
567
|
+
var MATCHER_CONTEXT_LEN = 320;
|
|
568
|
+
var MATCHER_CALL_LEN = 67;
|
|
569
|
+
var INIT_CTX_LEN = 78;
|
|
544
570
|
var BPS_DENOM = 10000n;
|
|
545
571
|
function computeVammQuote(params, oraclePriceE6, tradeSize, isLong) {
|
|
546
572
|
const absSize = tradeSize < 0n ? -tradeSize : tradeSize;
|
|
@@ -596,11 +622,8 @@ function checkPhaseTransition(currentSlot, marketCreatedSlot, oraclePhase, cumul
|
|
|
596
622
|
return [ORACLE_PHASE_MATURE, false];
|
|
597
623
|
}
|
|
598
624
|
}
|
|
599
|
-
function encodeTopUpKeeperFund(args) {
|
|
600
|
-
return concatBytes(encU8(IX_TAG.TopUpKeeperFund), encU64(args.amount));
|
|
601
|
-
}
|
|
602
625
|
function encodeSlashCreationDeposit() {
|
|
603
|
-
return
|
|
626
|
+
return removedInstruction("SlashCreationDeposit", IX_TAG.SlashCreationDeposit);
|
|
604
627
|
}
|
|
605
628
|
function encodeInitSharedVault(args) {
|
|
606
629
|
return concatBytes(
|
|
@@ -720,6 +743,87 @@ function encodeCloseOrphanSlab() {
|
|
|
720
743
|
function encodeSetDexPool(args) {
|
|
721
744
|
return concatBytes(encU8(IX_TAG.SetDexPool), encPubkey(args.pool));
|
|
722
745
|
}
|
|
746
|
+
function encodeCreateInsuranceMint() {
|
|
747
|
+
return encodeCreateLpVault({ feeShareBps: 0n });
|
|
748
|
+
}
|
|
749
|
+
function encodeDepositInsuranceLP(args) {
|
|
750
|
+
return encodeLpVaultDeposit({ amount: args.amount });
|
|
751
|
+
}
|
|
752
|
+
function encodeWithdrawInsuranceLP(args) {
|
|
753
|
+
return encodeLpVaultWithdraw({ lpAmount: args.lpAmount });
|
|
754
|
+
}
|
|
755
|
+
function encodeSetMaxPnlCap(args) {
|
|
756
|
+
return concatBytes(encU8(IX_TAG.SetMaxPnlCap), encU64(args.cap));
|
|
757
|
+
}
|
|
758
|
+
function encodeSetOiCapMultiplier(args) {
|
|
759
|
+
return concatBytes(encU8(IX_TAG.SetOiCapMultiplier), encU64(args.packed));
|
|
760
|
+
}
|
|
761
|
+
function packOiCap(multiplierBps, softCapBps) {
|
|
762
|
+
if (multiplierBps < 0 || multiplierBps > 4294967295) {
|
|
763
|
+
throw new Error(`packOiCap: multiplier_bps out of u32 range: ${multiplierBps}`);
|
|
764
|
+
}
|
|
765
|
+
if (softCapBps < 0 || softCapBps > 4294967295) {
|
|
766
|
+
throw new Error(`packOiCap: soft_cap_bps out of u32 range: ${softCapBps}`);
|
|
767
|
+
}
|
|
768
|
+
return BigInt(multiplierBps) | BigInt(softCapBps) << 32n;
|
|
769
|
+
}
|
|
770
|
+
function encodeSetDisputeParams(args) {
|
|
771
|
+
return concatBytes(
|
|
772
|
+
encU8(IX_TAG.SetDisputeParams),
|
|
773
|
+
encU64(args.windowSlots),
|
|
774
|
+
encU64(args.bondAmount)
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
function encodeSetLpCollateralParams(args) {
|
|
778
|
+
if (args.enabled !== 0 && args.enabled !== 1) {
|
|
779
|
+
throw new Error(`encodeSetLpCollateralParams: enabled must be 0 or 1, got ${args.enabled}`);
|
|
780
|
+
}
|
|
781
|
+
if (args.ltvBps < 0 || args.ltvBps > 1e4) {
|
|
782
|
+
throw new Error(`encodeSetLpCollateralParams: ltvBps ${args.ltvBps} out of range [0, 10000]`);
|
|
783
|
+
}
|
|
784
|
+
return concatBytes(
|
|
785
|
+
encU8(IX_TAG.SetLpCollateralParams),
|
|
786
|
+
encU8(args.enabled),
|
|
787
|
+
encU16(args.ltvBps)
|
|
788
|
+
);
|
|
789
|
+
}
|
|
790
|
+
function encodeAcceptAdmin() {
|
|
791
|
+
return encU8(IX_TAG.AcceptAdmin);
|
|
792
|
+
}
|
|
793
|
+
function encodeReclaimEmptyAccount(args) {
|
|
794
|
+
return concatBytes(encU8(IX_TAG.ReclaimEmptyAccount), encU16(args.userIdx));
|
|
795
|
+
}
|
|
796
|
+
function encodeSettleAccount(args) {
|
|
797
|
+
return concatBytes(encU8(IX_TAG.SettleAccount), encU16(args.userIdx));
|
|
798
|
+
}
|
|
799
|
+
function encodeDepositFeeCredits(args) {
|
|
800
|
+
return concatBytes(
|
|
801
|
+
encU8(IX_TAG.DepositFeeCredits),
|
|
802
|
+
encU16(args.userIdx),
|
|
803
|
+
encU64(args.amount)
|
|
804
|
+
);
|
|
805
|
+
}
|
|
806
|
+
function encodeConvertReleasedPnl(args) {
|
|
807
|
+
return concatBytes(
|
|
808
|
+
encU8(IX_TAG.ConvertReleasedPnl),
|
|
809
|
+
encU16(args.userIdx),
|
|
810
|
+
encU64(args.amount)
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
var AUTHORITY_KIND = {
|
|
814
|
+
Admin: 0,
|
|
815
|
+
HyperpMark: 1,
|
|
816
|
+
Insurance: 2,
|
|
817
|
+
InsuranceOperator: 4
|
|
818
|
+
};
|
|
819
|
+
Object.freeze(AUTHORITY_KIND);
|
|
820
|
+
function encodeUpdateAuthority(args) {
|
|
821
|
+
return concatBytes(
|
|
822
|
+
encU8(IX_TAG.UpdateAuthority),
|
|
823
|
+
encU8(args.kind),
|
|
824
|
+
encPubkey(args.newPubkey)
|
|
825
|
+
);
|
|
826
|
+
}
|
|
723
827
|
|
|
724
828
|
// src/abi/accounts.ts
|
|
725
829
|
import {
|
|
@@ -744,14 +848,16 @@ var ACCOUNTS_INIT_USER = [
|
|
|
744
848
|
{ name: "slab", signer: false, writable: true },
|
|
745
849
|
{ name: "userAta", signer: false, writable: true },
|
|
746
850
|
{ name: "vault", signer: false, writable: true },
|
|
747
|
-
{ name: "tokenProgram", signer: false, writable: false }
|
|
851
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
852
|
+
{ name: "clock", signer: false, writable: false }
|
|
748
853
|
];
|
|
749
854
|
var ACCOUNTS_INIT_LP = [
|
|
750
855
|
{ name: "user", signer: true, writable: true },
|
|
751
856
|
{ name: "slab", signer: false, writable: true },
|
|
752
857
|
{ name: "userAta", signer: false, writable: true },
|
|
753
858
|
{ name: "vault", signer: false, writable: true },
|
|
754
|
-
{ name: "tokenProgram", signer: false, writable: false }
|
|
859
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
860
|
+
{ name: "clock", signer: false, writable: false }
|
|
755
861
|
];
|
|
756
862
|
var ACCOUNTS_DEPOSIT_COLLATERAL = [
|
|
757
863
|
{ name: "user", signer: true, writable: true },
|
|
@@ -781,6 +887,7 @@ var ACCOUNTS_TRADE_NOCPI = [
|
|
|
781
887
|
{ name: "user", signer: true, writable: true },
|
|
782
888
|
{ name: "lp", signer: true, writable: true },
|
|
783
889
|
{ name: "slab", signer: false, writable: true },
|
|
890
|
+
{ name: "clock", signer: false, writable: false },
|
|
784
891
|
{ name: "oracle", signer: false, writable: false }
|
|
785
892
|
];
|
|
786
893
|
var ACCOUNTS_LIQUIDATE_AT_ORACLE = [
|
|
@@ -804,13 +911,15 @@ var ACCOUNTS_TOPUP_INSURANCE = [
|
|
|
804
911
|
{ name: "slab", signer: false, writable: true },
|
|
805
912
|
{ name: "userAta", signer: false, writable: true },
|
|
806
913
|
{ name: "vault", signer: false, writable: true },
|
|
807
|
-
{ name: "tokenProgram", signer: false, writable: false }
|
|
914
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
915
|
+
{ name: "clock", signer: false, writable: false }
|
|
808
916
|
];
|
|
809
917
|
var ACCOUNTS_TRADE_CPI = [
|
|
810
918
|
{ name: "user", signer: true, writable: true },
|
|
811
919
|
{ name: "lpOwner", signer: false, writable: false },
|
|
812
920
|
// LP delegated to matcher - no signature needed
|
|
813
921
|
{ name: "slab", signer: false, writable: true },
|
|
922
|
+
{ name: "clock", signer: false, writable: false },
|
|
814
923
|
{ name: "oracle", signer: false, writable: false },
|
|
815
924
|
{ name: "matcherProg", signer: false, writable: false },
|
|
816
925
|
{ name: "matcherCtx", signer: false, writable: true },
|
|
@@ -824,33 +933,37 @@ var ACCOUNTS_UPDATE_ADMIN = [
|
|
|
824
933
|
{ name: "admin", signer: true, writable: true },
|
|
825
934
|
{ name: "slab", signer: false, writable: true }
|
|
826
935
|
];
|
|
827
|
-
var
|
|
828
|
-
{ name: "
|
|
936
|
+
var ACCOUNTS_ACCEPT_ADMIN = [
|
|
937
|
+
{ name: "pendingAdmin", signer: true, writable: true },
|
|
829
938
|
{ name: "slab", signer: false, writable: true }
|
|
830
939
|
];
|
|
940
|
+
var ACCOUNTS_CLOSE_SLAB = [
|
|
941
|
+
{ name: "dest", signer: true, writable: true },
|
|
942
|
+
{ name: "slab", signer: false, writable: true },
|
|
943
|
+
{ name: "vault", signer: false, writable: true },
|
|
944
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
945
|
+
{ name: "destAta", signer: false, writable: true },
|
|
946
|
+
{ name: "tokenProgram", signer: false, writable: false }
|
|
947
|
+
];
|
|
831
948
|
var ACCOUNTS_UPDATE_CONFIG = [
|
|
832
949
|
{ name: "admin", signer: true, writable: true },
|
|
833
|
-
{ name: "slab", signer: false, writable: true }
|
|
950
|
+
{ name: "slab", signer: false, writable: true },
|
|
951
|
+
{ name: "clock", signer: false, writable: false }
|
|
834
952
|
];
|
|
835
953
|
var ACCOUNTS_SET_MAINTENANCE_FEE = [
|
|
836
954
|
{ name: "admin", signer: true, writable: true },
|
|
837
955
|
{ name: "slab", signer: false, writable: true }
|
|
838
956
|
];
|
|
839
|
-
var ACCOUNTS_SET_ORACLE_AUTHORITY = [
|
|
840
|
-
{ name: "admin", signer: true, writable: true },
|
|
841
|
-
{ name: "slab", signer: false, writable: true }
|
|
842
|
-
];
|
|
843
957
|
var ACCOUNTS_SET_ORACLE_PRICE_CAP = [
|
|
844
958
|
{ name: "admin", signer: true, writable: true },
|
|
845
|
-
{ name: "slab", signer: false, writable: true }
|
|
846
|
-
|
|
847
|
-
var ACCOUNTS_PUSH_ORACLE_PRICE = [
|
|
848
|
-
{ name: "authority", signer: true, writable: true },
|
|
849
|
-
{ name: "slab", signer: false, writable: true }
|
|
959
|
+
{ name: "slab", signer: false, writable: true },
|
|
960
|
+
{ name: "clock", signer: false, writable: false }
|
|
850
961
|
];
|
|
851
962
|
var ACCOUNTS_RESOLVE_MARKET = [
|
|
852
963
|
{ name: "admin", signer: true, writable: true },
|
|
853
|
-
{ name: "slab", signer: false, writable: true }
|
|
964
|
+
{ name: "slab", signer: false, writable: true },
|
|
965
|
+
{ name: "clock", signer: false, writable: false },
|
|
966
|
+
{ name: "oracle", signer: false, writable: false }
|
|
854
967
|
];
|
|
855
968
|
var ACCOUNTS_WITHDRAW_INSURANCE = [
|
|
856
969
|
{ name: "admin", signer: true, writable: true },
|
|
@@ -860,6 +973,19 @@ var ACCOUNTS_WITHDRAW_INSURANCE = [
|
|
|
860
973
|
{ name: "tokenProgram", signer: false, writable: false },
|
|
861
974
|
{ name: "vaultPda", signer: false, writable: false }
|
|
862
975
|
];
|
|
976
|
+
var ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_RESOLVED = [
|
|
977
|
+
{ name: "authority", signer: true, writable: true },
|
|
978
|
+
{ name: "slab", signer: false, writable: true },
|
|
979
|
+
{ name: "authorityAta", signer: false, writable: true },
|
|
980
|
+
{ name: "vault", signer: false, writable: true },
|
|
981
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
982
|
+
{ name: "vaultPda", signer: false, writable: false },
|
|
983
|
+
{ name: "clock", signer: false, writable: false }
|
|
984
|
+
];
|
|
985
|
+
var ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_LIVE = [
|
|
986
|
+
...ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_RESOLVED,
|
|
987
|
+
{ name: "oracle", signer: false, writable: false }
|
|
988
|
+
];
|
|
863
989
|
var ACCOUNTS_PAUSE_MARKET = [
|
|
864
990
|
{ name: "admin", signer: true, writable: true },
|
|
865
991
|
{ name: "slab", signer: false, writable: true }
|
|
@@ -868,6 +994,38 @@ var ACCOUNTS_UNPAUSE_MARKET = [
|
|
|
868
994
|
{ name: "admin", signer: true, writable: true },
|
|
869
995
|
{ name: "slab", signer: false, writable: true }
|
|
870
996
|
];
|
|
997
|
+
var ACCOUNTS_RECLAIM_EMPTY_ACCOUNT = [
|
|
998
|
+
{ name: "slab", signer: false, writable: true },
|
|
999
|
+
{ name: "clock", signer: false, writable: false }
|
|
1000
|
+
];
|
|
1001
|
+
var ACCOUNTS_SETTLE_ACCOUNT = [
|
|
1002
|
+
{ name: "slab", signer: false, writable: true },
|
|
1003
|
+
{ name: "clock", signer: false, writable: false },
|
|
1004
|
+
{ name: "oracle", signer: false, writable: false }
|
|
1005
|
+
];
|
|
1006
|
+
var ACCOUNTS_DEPOSIT_FEE_CREDITS = [
|
|
1007
|
+
{ name: "user", signer: true, writable: true },
|
|
1008
|
+
{ name: "slab", signer: false, writable: true },
|
|
1009
|
+
{ name: "userAta", signer: false, writable: true },
|
|
1010
|
+
{ name: "vault", signer: false, writable: true },
|
|
1011
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1012
|
+
{ name: "clock", signer: false, writable: false }
|
|
1013
|
+
];
|
|
1014
|
+
var ACCOUNTS_CONVERT_RELEASED_PNL = [
|
|
1015
|
+
{ name: "user", signer: true, writable: true },
|
|
1016
|
+
{ name: "slab", signer: false, writable: true },
|
|
1017
|
+
{ name: "clock", signer: false, writable: false },
|
|
1018
|
+
{ name: "oracle", signer: false, writable: false }
|
|
1019
|
+
];
|
|
1020
|
+
var ACCOUNTS_SET_INSURANCE_WITHDRAW_POLICY = [
|
|
1021
|
+
{ name: "admin", signer: true, writable: true },
|
|
1022
|
+
{ name: "slab", signer: false, writable: true }
|
|
1023
|
+
];
|
|
1024
|
+
var ACCOUNTS_UPDATE_AUTHORITY = [
|
|
1025
|
+
{ name: "currentAuthority", signer: true, writable: false },
|
|
1026
|
+
{ name: "newAuthority", signer: true, writable: false },
|
|
1027
|
+
{ name: "slab", signer: false, writable: true }
|
|
1028
|
+
];
|
|
871
1029
|
function buildAccountMetas(spec, keys) {
|
|
872
1030
|
let keysArray;
|
|
873
1031
|
if (Array.isArray(keys)) {
|
|
@@ -894,6 +1052,37 @@ function buildAccountMetas(spec, keys) {
|
|
|
894
1052
|
isWritable: s.writable
|
|
895
1053
|
}));
|
|
896
1054
|
}
|
|
1055
|
+
var ACCOUNTS_CREATE_INSURANCE_MINT = [
|
|
1056
|
+
{ name: "admin", signer: true, writable: false },
|
|
1057
|
+
{ name: "slab", signer: false, writable: false },
|
|
1058
|
+
{ name: "insLpMint", signer: false, writable: true },
|
|
1059
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1060
|
+
{ name: "collateralMint", signer: false, writable: false },
|
|
1061
|
+
{ name: "systemProgram", signer: false, writable: false },
|
|
1062
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1063
|
+
{ name: "rent", signer: false, writable: false },
|
|
1064
|
+
{ name: "payer", signer: true, writable: true }
|
|
1065
|
+
];
|
|
1066
|
+
var ACCOUNTS_DEPOSIT_INSURANCE_LP = [
|
|
1067
|
+
{ name: "depositor", signer: true, writable: false },
|
|
1068
|
+
{ name: "slab", signer: false, writable: true },
|
|
1069
|
+
{ name: "depositorAta", signer: false, writable: true },
|
|
1070
|
+
{ name: "vault", signer: false, writable: true },
|
|
1071
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1072
|
+
{ name: "insLpMint", signer: false, writable: true },
|
|
1073
|
+
{ name: "depositorLpAta", signer: false, writable: true },
|
|
1074
|
+
{ name: "vaultAuthority", signer: false, writable: false }
|
|
1075
|
+
];
|
|
1076
|
+
var ACCOUNTS_WITHDRAW_INSURANCE_LP = [
|
|
1077
|
+
{ name: "withdrawer", signer: true, writable: false },
|
|
1078
|
+
{ name: "slab", signer: false, writable: true },
|
|
1079
|
+
{ name: "withdrawerAta", signer: false, writable: true },
|
|
1080
|
+
{ name: "vault", signer: false, writable: true },
|
|
1081
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1082
|
+
{ name: "insLpMint", signer: false, writable: true },
|
|
1083
|
+
{ name: "withdrawerLpAta", signer: false, writable: true },
|
|
1084
|
+
{ name: "vaultAuthority", signer: false, writable: false }
|
|
1085
|
+
];
|
|
897
1086
|
var ACCOUNTS_LP_VAULT_WITHDRAW = [
|
|
898
1087
|
{ name: "withdrawer", signer: true, writable: false },
|
|
899
1088
|
{ name: "slab", signer: false, writable: true },
|
|
@@ -947,6 +1136,30 @@ var ACCOUNTS_EXECUTE_ADL = [
|
|
|
947
1136
|
{ name: "clock", signer: false, writable: false },
|
|
948
1137
|
{ name: "oracle", signer: false, writable: false }
|
|
949
1138
|
];
|
|
1139
|
+
var ACCOUNTS_RESOLVE_PERMISSIONLESS = [
|
|
1140
|
+
{ name: "slab", signer: false, writable: true },
|
|
1141
|
+
{ name: "clock", signer: false, writable: false },
|
|
1142
|
+
{ name: "oracle", signer: false, writable: false }
|
|
1143
|
+
];
|
|
1144
|
+
var ACCOUNTS_FORCE_CLOSE_RESOLVED = [
|
|
1145
|
+
{ name: "slab", signer: false, writable: true },
|
|
1146
|
+
{ name: "vault", signer: false, writable: true },
|
|
1147
|
+
{ name: "ownerAta", signer: false, writable: true },
|
|
1148
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1149
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1150
|
+
{ name: "clock", signer: false, writable: false },
|
|
1151
|
+
{ name: "oracle", signer: false, writable: false }
|
|
1152
|
+
];
|
|
1153
|
+
var ACCOUNTS_ADMIN_FORCE_CLOSE = [
|
|
1154
|
+
{ name: "admin", signer: true, writable: true },
|
|
1155
|
+
{ name: "slab", signer: false, writable: true },
|
|
1156
|
+
{ name: "vault", signer: false, writable: true },
|
|
1157
|
+
{ name: "ownerAta", signer: false, writable: true },
|
|
1158
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1159
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1160
|
+
{ name: "clock", signer: false, writable: false },
|
|
1161
|
+
{ name: "oracle", signer: false, writable: false }
|
|
1162
|
+
];
|
|
950
1163
|
var ACCOUNTS_CLOSE_STALE_SLABS = [
|
|
951
1164
|
{ name: "dest", signer: true, writable: true },
|
|
952
1165
|
{ name: "slab", signer: false, writable: true }
|
|
@@ -961,15 +1174,108 @@ var ACCOUNTS_AUDIT_CRANK = [
|
|
|
961
1174
|
var ACCOUNTS_ADVANCE_ORACLE_PHASE = [
|
|
962
1175
|
{ name: "slab", signer: false, writable: true }
|
|
963
1176
|
];
|
|
964
|
-
var
|
|
965
|
-
{ name: "
|
|
1177
|
+
var ACCOUNTS_UPDATE_HYPERP_MARK = [
|
|
1178
|
+
{ name: "slab", signer: false, writable: true },
|
|
1179
|
+
{ name: "dexPool", signer: false, writable: false },
|
|
1180
|
+
{ name: "clock", signer: false, writable: false }
|
|
1181
|
+
];
|
|
1182
|
+
var ACCOUNTS_CREATE_LP_VAULT = [
|
|
1183
|
+
{ name: "admin", signer: true, writable: true },
|
|
1184
|
+
{ name: "slab", signer: false, writable: true },
|
|
1185
|
+
{ name: "lpVaultState", signer: false, writable: true },
|
|
1186
|
+
{ name: "lpVaultMint", signer: false, writable: true },
|
|
1187
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1188
|
+
{ name: "systemProgram", signer: false, writable: false },
|
|
1189
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1190
|
+
{ name: "rent", signer: false, writable: false }
|
|
1191
|
+
];
|
|
1192
|
+
var ACCOUNTS_LP_VAULT_DEPOSIT = [
|
|
1193
|
+
{ name: "depositor", signer: true, writable: true },
|
|
1194
|
+
{ name: "slab", signer: false, writable: true },
|
|
1195
|
+
{ name: "depositorAta", signer: false, writable: true },
|
|
1196
|
+
{ name: "vault", signer: false, writable: true },
|
|
1197
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1198
|
+
{ name: "lpVaultMint", signer: false, writable: true },
|
|
1199
|
+
{ name: "depositorLpAta", signer: false, writable: true },
|
|
1200
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1201
|
+
{ name: "lpVaultState", signer: false, writable: true }
|
|
1202
|
+
];
|
|
1203
|
+
var ACCOUNTS_LP_VAULT_CRANK_FEES = [
|
|
1204
|
+
{ name: "slab", signer: false, writable: true },
|
|
1205
|
+
{ name: "lpVaultState", signer: false, writable: true }
|
|
1206
|
+
];
|
|
1207
|
+
var ACCOUNTS_CHALLENGE_SETTLEMENT = [
|
|
1208
|
+
{ name: "challenger", signer: true, writable: true },
|
|
1209
|
+
{ name: "slab", signer: false, writable: true },
|
|
1210
|
+
{ name: "dispute", signer: false, writable: true },
|
|
1211
|
+
{ name: "challengerAta", signer: false, writable: true },
|
|
1212
|
+
{ name: "vault", signer: false, writable: true },
|
|
1213
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1214
|
+
{ name: "systemProgram", signer: false, writable: false }
|
|
1215
|
+
];
|
|
1216
|
+
var ACCOUNTS_RESOLVE_DISPUTE = [
|
|
1217
|
+
{ name: "admin", signer: true, writable: true },
|
|
1218
|
+
{ name: "slab", signer: false, writable: true },
|
|
1219
|
+
{ name: "dispute", signer: false, writable: true },
|
|
1220
|
+
{ name: "challengerAta", signer: false, writable: true },
|
|
1221
|
+
{ name: "vault", signer: false, writable: true },
|
|
1222
|
+
{ name: "vaultAuthority", signer: false, writable: false },
|
|
1223
|
+
{ name: "tokenProgram", signer: false, writable: false }
|
|
1224
|
+
];
|
|
1225
|
+
var ACCOUNTS_DEPOSIT_LP_COLLATERAL = [
|
|
1226
|
+
{ name: "user", signer: true, writable: true },
|
|
966
1227
|
{ name: "slab", signer: false, writable: true },
|
|
967
|
-
{ name: "
|
|
1228
|
+
{ name: "userLpAta", signer: false, writable: true },
|
|
1229
|
+
{ name: "lpVaultMint", signer: false, writable: false },
|
|
1230
|
+
{ name: "lpVaultState", signer: false, writable: true },
|
|
1231
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1232
|
+
{ name: "lpEscrow", signer: false, writable: true }
|
|
1233
|
+
];
|
|
1234
|
+
var ACCOUNTS_WITHDRAW_LP_COLLATERAL = [
|
|
1235
|
+
{ name: "user", signer: true, writable: true },
|
|
1236
|
+
{ name: "slab", signer: false, writable: true },
|
|
1237
|
+
{ name: "userLpAta", signer: false, writable: true },
|
|
1238
|
+
{ name: "lpVaultMint", signer: false, writable: false },
|
|
1239
|
+
{ name: "lpVaultState", signer: false, writable: true },
|
|
1240
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1241
|
+
{ name: "lpEscrow", signer: false, writable: true },
|
|
1242
|
+
{ name: "vaultAuthority", signer: false, writable: false }
|
|
1243
|
+
];
|
|
1244
|
+
var ACCOUNTS_SET_OFFSET_PAIR = [
|
|
1245
|
+
{ name: "admin", signer: true, writable: true },
|
|
1246
|
+
{ name: "slabA", signer: false, writable: true },
|
|
1247
|
+
{ name: "slabB", signer: false, writable: true },
|
|
1248
|
+
{ name: "pairPda", signer: false, writable: true },
|
|
1249
|
+
{ name: "systemProgram", signer: false, writable: false }
|
|
1250
|
+
];
|
|
1251
|
+
var ACCOUNTS_ATTEST_CROSS_MARGIN = [
|
|
1252
|
+
{ name: "payer", signer: true, writable: true },
|
|
1253
|
+
{ name: "slabA", signer: false, writable: true },
|
|
1254
|
+
{ name: "slabB", signer: false, writable: true },
|
|
1255
|
+
{ name: "attestation", signer: false, writable: true },
|
|
1256
|
+
{ name: "pairPda", signer: false, writable: false },
|
|
1257
|
+
{ name: "systemProgram", signer: false, writable: false }
|
|
968
1258
|
];
|
|
969
1259
|
var ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK = [
|
|
970
1260
|
{ name: "admin", signer: true, writable: false },
|
|
971
1261
|
{ name: "slab", signer: false, writable: true }
|
|
972
1262
|
];
|
|
1263
|
+
var ACCOUNTS_SET_MAX_PNL_CAP = [
|
|
1264
|
+
{ name: "admin", signer: true, writable: false },
|
|
1265
|
+
{ name: "slab", signer: false, writable: true }
|
|
1266
|
+
];
|
|
1267
|
+
var ACCOUNTS_SET_OI_CAP_MULTIPLIER = [
|
|
1268
|
+
{ name: "admin", signer: true, writable: false },
|
|
1269
|
+
{ name: "slab", signer: false, writable: true }
|
|
1270
|
+
];
|
|
1271
|
+
var ACCOUNTS_SET_DISPUTE_PARAMS = [
|
|
1272
|
+
{ name: "admin", signer: true, writable: false },
|
|
1273
|
+
{ name: "slab", signer: false, writable: true }
|
|
1274
|
+
];
|
|
1275
|
+
var ACCOUNTS_SET_LP_COLLATERAL_PARAMS = [
|
|
1276
|
+
{ name: "admin", signer: true, writable: false },
|
|
1277
|
+
{ name: "slab", signer: false, writable: true }
|
|
1278
|
+
];
|
|
973
1279
|
var ACCOUNTS_MINT_POSITION_NFT = [
|
|
974
1280
|
{ name: "payer", signer: true, writable: true },
|
|
975
1281
|
{ name: "slab", signer: false, writable: true },
|
|
@@ -1011,10 +1317,33 @@ var ACCOUNTS_CLEAR_PENDING_SETTLEMENT = [
|
|
|
1011
1317
|
{ name: "slab", signer: false, writable: false },
|
|
1012
1318
|
{ name: "positionNftPda", signer: false, writable: true }
|
|
1013
1319
|
];
|
|
1320
|
+
var ACCOUNTS_TRANSFER_OWNERSHIP_CPI = [
|
|
1321
|
+
{ name: "caller", signer: true, writable: false },
|
|
1322
|
+
{ name: "slab", signer: false, writable: true },
|
|
1323
|
+
{ name: "nftProgram", signer: false, writable: false }
|
|
1324
|
+
];
|
|
1014
1325
|
var ACCOUNTS_SET_WALLET_CAP = [
|
|
1015
1326
|
{ name: "admin", signer: true, writable: false },
|
|
1016
1327
|
{ name: "slab", signer: false, writable: true }
|
|
1017
1328
|
];
|
|
1329
|
+
var ACCOUNTS_RESCUE_ORPHAN_VAULT = [
|
|
1330
|
+
{ name: "admin", signer: true, writable: true },
|
|
1331
|
+
{ name: "slab", signer: false, writable: true },
|
|
1332
|
+
{ name: "adminAta", signer: false, writable: true },
|
|
1333
|
+
{ name: "vault", signer: false, writable: true },
|
|
1334
|
+
{ name: "tokenProgram", signer: false, writable: false },
|
|
1335
|
+
{ name: "vaultPda", signer: false, writable: false }
|
|
1336
|
+
];
|
|
1337
|
+
var ACCOUNTS_CLOSE_ORPHAN_SLAB = [
|
|
1338
|
+
{ name: "admin", signer: true, writable: true },
|
|
1339
|
+
{ name: "slab", signer: false, writable: true },
|
|
1340
|
+
{ name: "vault", signer: false, writable: true }
|
|
1341
|
+
];
|
|
1342
|
+
var ACCOUNTS_SET_DEX_POOL = [
|
|
1343
|
+
{ name: "admin", signer: true, writable: false },
|
|
1344
|
+
{ name: "slab", signer: false, writable: true },
|
|
1345
|
+
{ name: "poolAccount", signer: false, writable: false }
|
|
1346
|
+
];
|
|
1018
1347
|
var ACCOUNTS_INIT_MATCHER_CTX = [
|
|
1019
1348
|
{ name: "admin", signer: true, writable: false },
|
|
1020
1349
|
{ name: "slab", signer: false, writable: false },
|
|
@@ -1306,24 +1635,11 @@ function getErrorName(code) {
|
|
|
1306
1635
|
function getErrorHint(code) {
|
|
1307
1636
|
return PERCOLATOR_ERRORS[code]?.hint;
|
|
1308
1637
|
}
|
|
1309
|
-
var LIGHTHOUSE_PROGRAM_ID_STR = "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95";
|
|
1310
|
-
var ANCHOR_ERROR_RANGE_START = 6e3;
|
|
1311
|
-
var ANCHOR_ERROR_RANGE_END = 8191;
|
|
1312
|
-
var ANCHOR_ERROR_NAMES = {
|
|
1313
|
-
6032: "ConstraintMut",
|
|
1314
|
-
6036: "ConstraintOwner",
|
|
1315
|
-
6038: "ConstraintSeeds",
|
|
1316
|
-
6400: "ConstraintAddress"
|
|
1317
|
-
};
|
|
1318
|
-
function isAnchorErrorCode(code) {
|
|
1319
|
-
return code >= ANCHOR_ERROR_RANGE_START && code <= ANCHOR_ERROR_RANGE_END;
|
|
1320
|
-
}
|
|
1321
1638
|
var CUSTOM_ERROR_HEX_MAX_LEN = 8;
|
|
1322
1639
|
function parseErrorFromLogs(logs) {
|
|
1323
1640
|
if (!Array.isArray(logs)) {
|
|
1324
1641
|
return null;
|
|
1325
1642
|
}
|
|
1326
|
-
let insideLighthouse = false;
|
|
1327
1643
|
const re = new RegExp(
|
|
1328
1644
|
`custom program error: 0x([0-9a-fA-F]{1,${CUSTOM_ERROR_HEX_MAX_LEN}})(?![0-9a-fA-F])`,
|
|
1329
1645
|
"i"
|
|
@@ -1332,44 +1648,212 @@ function parseErrorFromLogs(logs) {
|
|
|
1332
1648
|
if (typeof log !== "string") {
|
|
1333
1649
|
continue;
|
|
1334
1650
|
}
|
|
1335
|
-
if (log.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} invoke`)) {
|
|
1336
|
-
insideLighthouse = true;
|
|
1337
|
-
} else if (log.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} success`)) {
|
|
1338
|
-
insideLighthouse = false;
|
|
1339
|
-
}
|
|
1340
1651
|
const match = log.match(re);
|
|
1341
1652
|
if (match) {
|
|
1342
1653
|
const code = parseInt(match[1], 16);
|
|
1343
1654
|
if (!Number.isFinite(code) || code < 0 || code > 4294967295) {
|
|
1344
1655
|
continue;
|
|
1345
1656
|
}
|
|
1346
|
-
if (isAnchorErrorCode(code) || insideLighthouse) {
|
|
1347
|
-
const anchorName = ANCHOR_ERROR_NAMES[code] ?? `AnchorError(0x${code.toString(16)})`;
|
|
1348
|
-
return {
|
|
1349
|
-
code,
|
|
1350
|
-
name: `Lighthouse:${anchorName}`,
|
|
1351
|
-
hint: "This error comes from the Lighthouse/Blowfish wallet guard, not from Percolator. The transaction itself is valid. Disable transaction simulation in your wallet settings, or use a wallet without Blowfish protection (e.g., Backpack, Solflare).",
|
|
1352
|
-
source: "lighthouse"
|
|
1353
|
-
};
|
|
1354
|
-
}
|
|
1355
1657
|
const info = decodeError(code);
|
|
1356
1658
|
return {
|
|
1357
1659
|
code,
|
|
1358
1660
|
name: info?.name ?? `Unknown(${code})`,
|
|
1359
|
-
hint: info?.hint
|
|
1360
|
-
source: info ? "percolator" : "unknown"
|
|
1661
|
+
hint: info?.hint
|
|
1361
1662
|
};
|
|
1362
1663
|
}
|
|
1363
1664
|
}
|
|
1364
1665
|
return null;
|
|
1365
1666
|
}
|
|
1366
1667
|
|
|
1367
|
-
// src/
|
|
1668
|
+
// src/abi/nft.ts
|
|
1669
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
1670
|
+
|
|
1671
|
+
// src/config/program-ids.ts
|
|
1368
1672
|
import { PublicKey as PublicKey3 } from "@solana/web3.js";
|
|
1673
|
+
function safeEnv(key) {
|
|
1674
|
+
try {
|
|
1675
|
+
return typeof process !== "undefined" && process?.env ? process.env[key] : void 0;
|
|
1676
|
+
} catch {
|
|
1677
|
+
return void 0;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
var PROGRAM_IDS = {
|
|
1681
|
+
devnet: {
|
|
1682
|
+
percolator: "FxfD37s1AZTeWfFQps9Zpebi2dNQ9QSSDtfMKdbsfKrD",
|
|
1683
|
+
matcher: "GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k"
|
|
1684
|
+
},
|
|
1685
|
+
mainnet: {
|
|
1686
|
+
percolator: "ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv",
|
|
1687
|
+
matcher: "GDK8wx38kpiSVSfGTVNiSdptX3Z5R4kQyqh6Q3QX6wmi"
|
|
1688
|
+
}
|
|
1689
|
+
};
|
|
1690
|
+
function getProgramId(network) {
|
|
1691
|
+
const override = safeEnv("PROGRAM_ID");
|
|
1692
|
+
if (override) {
|
|
1693
|
+
console.warn(
|
|
1694
|
+
`[percolator-sdk] PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
1695
|
+
);
|
|
1696
|
+
return new PublicKey3(override);
|
|
1697
|
+
}
|
|
1698
|
+
const detectedNetwork = getCurrentNetwork();
|
|
1699
|
+
const targetNetwork = network ?? detectedNetwork;
|
|
1700
|
+
const programId = PROGRAM_IDS[targetNetwork].percolator;
|
|
1701
|
+
return new PublicKey3(programId);
|
|
1702
|
+
}
|
|
1703
|
+
function getMatcherProgramId(network) {
|
|
1704
|
+
const override = safeEnv("MATCHER_PROGRAM_ID");
|
|
1705
|
+
if (override) {
|
|
1706
|
+
console.warn(
|
|
1707
|
+
`[percolator-sdk] MATCHER_PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
1708
|
+
);
|
|
1709
|
+
return new PublicKey3(override);
|
|
1710
|
+
}
|
|
1711
|
+
const detectedNetwork = getCurrentNetwork();
|
|
1712
|
+
const targetNetwork = network ?? detectedNetwork;
|
|
1713
|
+
const programId = PROGRAM_IDS[targetNetwork].matcher;
|
|
1714
|
+
if (!programId) {
|
|
1715
|
+
throw new Error(`Matcher program not deployed on ${targetNetwork}`);
|
|
1716
|
+
}
|
|
1717
|
+
return new PublicKey3(programId);
|
|
1718
|
+
}
|
|
1719
|
+
function getCurrentNetwork() {
|
|
1720
|
+
const network = safeEnv("NETWORK")?.toLowerCase();
|
|
1721
|
+
if (network === "mainnet" || network === "mainnet-beta") {
|
|
1722
|
+
return "mainnet";
|
|
1723
|
+
}
|
|
1724
|
+
return "devnet";
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
// src/abi/nft.ts
|
|
1728
|
+
var NFT_PROGRAM_OVERRIDE = safeEnv("NFT_PROGRAM_ID");
|
|
1729
|
+
var NFT_PROGRAM_ID = new PublicKey4(
|
|
1730
|
+
NFT_PROGRAM_OVERRIDE ?? "FqhKJT9gtScjrmfUuRMjeg7cXNpif1fqsy5Jh65tJmTS"
|
|
1731
|
+
);
|
|
1732
|
+
function getNftProgramId() {
|
|
1733
|
+
return NFT_PROGRAM_ID;
|
|
1734
|
+
}
|
|
1735
|
+
var NFT_IX_TAG = {
|
|
1736
|
+
MintPositionNft: 0,
|
|
1737
|
+
BurnPositionNft: 1,
|
|
1738
|
+
SettleFunding: 2,
|
|
1739
|
+
GetPositionValue: 3,
|
|
1740
|
+
ExecuteTransferHook: 4,
|
|
1741
|
+
EmergencyBurn: 5
|
|
1742
|
+
};
|
|
1743
|
+
function encodeNftMint(userIdx) {
|
|
1744
|
+
const buf = new Uint8Array(3);
|
|
1745
|
+
buf[0] = NFT_IX_TAG.MintPositionNft;
|
|
1746
|
+
buf[1] = userIdx & 255;
|
|
1747
|
+
buf[2] = userIdx >> 8 & 255;
|
|
1748
|
+
return buf;
|
|
1749
|
+
}
|
|
1750
|
+
function encodeNftBurn() {
|
|
1751
|
+
return new Uint8Array([NFT_IX_TAG.BurnPositionNft]);
|
|
1752
|
+
}
|
|
1753
|
+
function encodeNftSettleFunding() {
|
|
1754
|
+
return new Uint8Array([NFT_IX_TAG.SettleFunding]);
|
|
1755
|
+
}
|
|
1756
|
+
function encodeNftEmergencyBurn() {
|
|
1757
|
+
return new Uint8Array([NFT_IX_TAG.EmergencyBurn]);
|
|
1758
|
+
}
|
|
1759
|
+
var ACCOUNTS_NFT_MINT = [
|
|
1760
|
+
"sw",
|
|
1761
|
+
"w",
|
|
1762
|
+
"sw",
|
|
1763
|
+
"w",
|
|
1764
|
+
"r",
|
|
1765
|
+
"r",
|
|
1766
|
+
"r",
|
|
1767
|
+
"r",
|
|
1768
|
+
"r",
|
|
1769
|
+
"w"
|
|
1770
|
+
];
|
|
1771
|
+
var ACCOUNTS_NFT_BURN = [
|
|
1772
|
+
"s",
|
|
1773
|
+
"w",
|
|
1774
|
+
"w",
|
|
1775
|
+
"w",
|
|
1776
|
+
"r",
|
|
1777
|
+
"r",
|
|
1778
|
+
"r"
|
|
1779
|
+
];
|
|
1780
|
+
var ACCOUNTS_NFT_EMERGENCY_BURN = [
|
|
1781
|
+
"s",
|
|
1782
|
+
"w",
|
|
1783
|
+
"w",
|
|
1784
|
+
"w",
|
|
1785
|
+
"r",
|
|
1786
|
+
"r",
|
|
1787
|
+
"r"
|
|
1788
|
+
];
|
|
1789
|
+
var TEXT = new TextEncoder();
|
|
1790
|
+
function idxBuf(userIdx) {
|
|
1791
|
+
const buf = new Uint8Array(2);
|
|
1792
|
+
new DataView(buf.buffer).setUint16(0, userIdx, true);
|
|
1793
|
+
return buf;
|
|
1794
|
+
}
|
|
1795
|
+
function deriveNftPda(slab, userIdx, programId = NFT_PROGRAM_ID) {
|
|
1796
|
+
return PublicKey4.findProgramAddressSync(
|
|
1797
|
+
[TEXT.encode("position_nft"), slab.toBytes(), idxBuf(userIdx)],
|
|
1798
|
+
programId
|
|
1799
|
+
);
|
|
1800
|
+
}
|
|
1801
|
+
function deriveNftMint(slab, userIdx, programId = NFT_PROGRAM_ID) {
|
|
1802
|
+
return PublicKey4.findProgramAddressSync(
|
|
1803
|
+
[TEXT.encode("position_nft_mint"), slab.toBytes(), idxBuf(userIdx)],
|
|
1804
|
+
programId
|
|
1805
|
+
);
|
|
1806
|
+
}
|
|
1807
|
+
function deriveMintAuthority(programId = NFT_PROGRAM_ID) {
|
|
1808
|
+
return PublicKey4.findProgramAddressSync(
|
|
1809
|
+
[TEXT.encode("mint_authority")],
|
|
1810
|
+
programId
|
|
1811
|
+
);
|
|
1812
|
+
}
|
|
1813
|
+
var POSITION_NFT_STATE_LEN = 208;
|
|
1814
|
+
function readI128FromView(view, offset) {
|
|
1815
|
+
const lo = view.getBigUint64(offset, true);
|
|
1816
|
+
const hi = view.getBigUint64(offset + 8, true);
|
|
1817
|
+
const unsigned = hi << 64n | lo;
|
|
1818
|
+
const SIGN_BIT = 1n << 127n;
|
|
1819
|
+
if (unsigned >= SIGN_BIT) {
|
|
1820
|
+
return unsigned - (1n << 128n);
|
|
1821
|
+
}
|
|
1822
|
+
return unsigned;
|
|
1823
|
+
}
|
|
1824
|
+
function parsePositionNftAccount(data) {
|
|
1825
|
+
if (data.length < POSITION_NFT_STATE_LEN) {
|
|
1826
|
+
throw new Error(
|
|
1827
|
+
`PositionNft account too small: ${data.length} < ${POSITION_NFT_STATE_LEN}`
|
|
1828
|
+
);
|
|
1829
|
+
}
|
|
1830
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1831
|
+
return {
|
|
1832
|
+
version: data[8],
|
|
1833
|
+
bump: data[9],
|
|
1834
|
+
slab: new PublicKey4(data.subarray(16, 48)),
|
|
1835
|
+
userIdx: view.getUint16(48, true),
|
|
1836
|
+
nftMint: new PublicKey4(data.subarray(56, 88)),
|
|
1837
|
+
positionOwner: new PublicKey4(data.subarray(160, 192)),
|
|
1838
|
+
entryPriceE6: view.getBigUint64(88, true),
|
|
1839
|
+
positionSize: view.getBigUint64(96, true),
|
|
1840
|
+
isLong: data[104] === 1,
|
|
1841
|
+
positionBasisQ: readI128FromView(view, 112),
|
|
1842
|
+
lastFundingIndexE18: readI128FromView(view, 128),
|
|
1843
|
+
mintedAt: view.getBigInt64(144, true),
|
|
1844
|
+
accountId: view.getBigUint64(152, true)
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// src/solana/slab.ts
|
|
1849
|
+
import { PublicKey as PublicKey5 } from "@solana/web3.js";
|
|
1369
1850
|
function dv(data) {
|
|
1370
1851
|
return new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
1371
1852
|
}
|
|
1372
1853
|
function readU8(data, off) {
|
|
1854
|
+
if (off >= data.length) {
|
|
1855
|
+
throw new RangeError(`readU8: offset ${off} out of bounds (length ${data.length})`);
|
|
1856
|
+
}
|
|
1373
1857
|
return data[off];
|
|
1374
1858
|
}
|
|
1375
1859
|
function readU16LE(data, off) {
|
|
@@ -1400,6 +1884,7 @@ function readU128LE(buf, offset) {
|
|
|
1400
1884
|
return hi << 64n | lo;
|
|
1401
1885
|
}
|
|
1402
1886
|
var MAGIC = 0x504552434f4c4154n;
|
|
1887
|
+
var SLAB_MAGIC = MAGIC;
|
|
1403
1888
|
var FLAG_RESOLVED = 1 << 0;
|
|
1404
1889
|
var V0_HEADER_LEN = 72;
|
|
1405
1890
|
var V0_CONFIG_LEN = 408;
|
|
@@ -1571,8 +2056,27 @@ var V12_1_ENGINE_OFF = 648;
|
|
|
1571
2056
|
var V12_1_ACCOUNT_SIZE = 320;
|
|
1572
2057
|
var V12_1_ACCOUNT_SIZE_SBF = 280;
|
|
1573
2058
|
var V12_1_ENGINE_BITMAP_OFF = 1016;
|
|
1574
|
-
var
|
|
2059
|
+
var V12_1_ENGINE_PARAMS_OFF_SBF = 32;
|
|
2060
|
+
var V12_1_ENGINE_PARAMS_OFF_HOST = 96;
|
|
2061
|
+
var V12_1_PARAMS_SIZE_SBF = 184;
|
|
1575
2062
|
var V12_1_PARAMS_SIZE = 352;
|
|
2063
|
+
var V12_1_SBF_OFF_CURRENT_SLOT = 216;
|
|
2064
|
+
var V12_1_SBF_OFF_FUNDING_RATE = 224;
|
|
2065
|
+
var V12_1_SBF_OFF_LAST_CRANK_SLOT = 232;
|
|
2066
|
+
var V12_1_SBF_OFF_MAX_CRANK_STALENESS = 240;
|
|
2067
|
+
var V12_1_SBF_OFF_C_TOT = 248;
|
|
2068
|
+
var V12_1_SBF_OFF_PNL_POS_TOT = 264;
|
|
2069
|
+
var V12_1_SBF_OFF_LIQ_CURSOR = 296;
|
|
2070
|
+
var V12_1_SBF_OFF_GC_CURSOR = 298;
|
|
2071
|
+
var V12_1_SBF_OFF_LAST_SWEEP_START = 304;
|
|
2072
|
+
var V12_1_SBF_OFF_LAST_SWEEP_COMPLETE = 312;
|
|
2073
|
+
var V12_1_SBF_OFF_CRANK_CURSOR = 320;
|
|
2074
|
+
var V12_1_SBF_OFF_SWEEP_START_IDX = 322;
|
|
2075
|
+
var V12_1_SBF_OFF_LIFETIME_LIQUIDATIONS = 328;
|
|
2076
|
+
var V12_1_SBF_OFF_TOTAL_OI = 448;
|
|
2077
|
+
var V12_1_SBF_OFF_LONG_OI = 464;
|
|
2078
|
+
var V12_1_SBF_OFF_SHORT_OI = 480;
|
|
2079
|
+
var V12_1_SBF_OFF_MARK_PRICE_E6 = 560;
|
|
1576
2080
|
var V12_1_ENGINE_CURRENT_SLOT_OFF = 448;
|
|
1577
2081
|
var V12_1_ENGINE_FUNDING_RATE_BPS_OFF = 456;
|
|
1578
2082
|
var V12_1_ENGINE_LAST_CRANK_SLOT_OFF = 464;
|
|
@@ -1607,7 +2111,112 @@ var V12_1_ACCT_FEE_CREDITS_OFF = 240;
|
|
|
1607
2111
|
var V12_1_ACCT_LAST_FEE_SLOT_OFF = 256;
|
|
1608
2112
|
var V12_1_ACCT_POSITION_SIZE_OFF = 88;
|
|
1609
2113
|
var V12_1_ACCT_ENTRY_PRICE_OFF = -1;
|
|
1610
|
-
var
|
|
2114
|
+
var V12_1_EP_SBF_ACCOUNT_SIZE = 288;
|
|
2115
|
+
var V12_1_EP_ACCT_ENTRY_PRICE_OFF = 144;
|
|
2116
|
+
var V12_1_EP_ACCT_MATCHER_PROGRAM_OFF = 152;
|
|
2117
|
+
var V12_1_EP_ACCT_MATCHER_CONTEXT_OFF = 184;
|
|
2118
|
+
var V12_1_EP_ACCT_OWNER_OFF = 216;
|
|
2119
|
+
var V12_1_EP_ACCT_FEE_CREDITS_OFF = 248;
|
|
2120
|
+
var V12_1_EP_ACCT_LAST_FEE_SLOT_OFF = 264;
|
|
2121
|
+
var V12_15_ENGINE_OFF = 624;
|
|
2122
|
+
var V12_15_ENGINE_OFF_SBF = 616;
|
|
2123
|
+
var V12_15_ACCOUNT_SIZE = 4400;
|
|
2124
|
+
var V12_15_ACCOUNT_SIZE_SMALL = 920;
|
|
2125
|
+
var V12_15_ACCT_ACCOUNT_ID_OFF = 0;
|
|
2126
|
+
var V12_15_ACCT_CAPITAL_OFF = 8;
|
|
2127
|
+
var V12_15_ACCT_KIND_OFF = 24;
|
|
2128
|
+
var V12_15_ACCT_PNL_OFF = 32;
|
|
2129
|
+
var V12_15_ACCT_RESERVED_PNL_OFF = 48;
|
|
2130
|
+
var V12_15_ACCT_POSITION_BASIS_Q_OFF = 64;
|
|
2131
|
+
var V12_15_ACCT_ENTRY_PRICE_OFF = 120;
|
|
2132
|
+
var V12_15_ACCT_MATCHER_PROGRAM_OFF = 128;
|
|
2133
|
+
var V12_15_ACCT_MATCHER_CONTEXT_OFF = 160;
|
|
2134
|
+
var V12_15_ACCT_OWNER_OFF = 192;
|
|
2135
|
+
var V12_15_ACCT_FEE_CREDITS_OFF = 224;
|
|
2136
|
+
var V12_15_ACCT_FEES_EARNED_TOTAL_OFF = 240;
|
|
2137
|
+
var V12_15_ACCT_EXACT_RESERVE_COHORTS_OFF = 256;
|
|
2138
|
+
var V12_15_ACCT_EXACT_COHORT_COUNT_OFF = 4224;
|
|
2139
|
+
var V12_15_ACCT_OVERFLOW_OLDER_OFF = 4240;
|
|
2140
|
+
var V12_15_ACCT_OVERFLOW_OLDER_PRESENT_OFF = 4304;
|
|
2141
|
+
var V12_15_ACCT_OVERFLOW_NEWEST_OFF = 4320;
|
|
2142
|
+
var V12_15_ACCT_OVERFLOW_NEWEST_PRESENT_OFF = 4384;
|
|
2143
|
+
var V12_15_PARAMS_SIZE = 192;
|
|
2144
|
+
var V12_15_PARAMS_MAX_ACCOUNTS_OFF = 24;
|
|
2145
|
+
var V12_15_PARAMS_INSURANCE_FLOOR_OFF = 144;
|
|
2146
|
+
var V12_15_PARAMS_H_MIN_OFF = 160;
|
|
2147
|
+
var V12_15_PARAMS_H_MAX_OFF = 168;
|
|
2148
|
+
var V12_15_ENGINE_PARAMS_OFF = 32;
|
|
2149
|
+
var V12_15_ENGINE_CURRENT_SLOT_OFF = 224;
|
|
2150
|
+
var V12_15_ENGINE_FUNDING_RATE_E9_OFF = 240;
|
|
2151
|
+
var V12_15_ENGINE_C_TOT_OFF = 344;
|
|
2152
|
+
var V12_15_ENGINE_PNL_POS_TOT_OFF = 368;
|
|
2153
|
+
var V12_15_ENGINE_PNL_MATURED_POS_TOT_OFF = 384;
|
|
2154
|
+
var V12_15_ENGINE_BITMAP_OFF = 862;
|
|
2155
|
+
var V12_15_SIZES = /* @__PURE__ */ new Map();
|
|
2156
|
+
var V12_17_ENGINE_OFF = 592;
|
|
2157
|
+
var V12_17_ACCOUNT_SIZE = 368;
|
|
2158
|
+
var V12_17_ENGINE_BITMAP_OFF = 752;
|
|
2159
|
+
var V12_17_RISK_BUF_LEN = 160;
|
|
2160
|
+
var V12_17_GEN_TABLE_ENTRY = 8;
|
|
2161
|
+
var V12_17_ENGINE_OFF_SBF = 584;
|
|
2162
|
+
var V12_17_ACCOUNT_SIZE_SBF = 352;
|
|
2163
|
+
var V12_17_ENGINE_BITMAP_OFF_SBF = 712;
|
|
2164
|
+
var V12_17_ACCT_CAPITAL_OFF = 0;
|
|
2165
|
+
var V12_17_ACCT_KIND_OFF = 16;
|
|
2166
|
+
var V12_17_ACCT_PNL_OFF = 32;
|
|
2167
|
+
var V12_17_ACCT_RESERVED_PNL_OFF = 48;
|
|
2168
|
+
var V12_17_ACCT_POSITION_BASIS_Q_OFF = 64;
|
|
2169
|
+
var V12_17_ACCT_ADL_A_BASIS_OFF = 80;
|
|
2170
|
+
var V12_17_ACCT_ADL_K_SNAP_OFF = 96;
|
|
2171
|
+
var V12_17_ACCT_F_SNAP_OFF = 112;
|
|
2172
|
+
var V12_17_ACCT_ADL_EPOCH_SNAP_OFF = 128;
|
|
2173
|
+
var V12_17_ACCT_MATCHER_PROGRAM_OFF = 136;
|
|
2174
|
+
var V12_17_ACCT_MATCHER_CONTEXT_OFF = 168;
|
|
2175
|
+
var V12_17_ACCT_OWNER_OFF = 200;
|
|
2176
|
+
var V12_17_ACCT_FEE_CREDITS_OFF = 232;
|
|
2177
|
+
var V12_17_ACCT_SCHED_PRESENT_OFF = 248;
|
|
2178
|
+
var V12_17_ACCT_SCHED_REMAINING_Q_OFF = 256;
|
|
2179
|
+
var V12_17_ACCT_SCHED_ANCHOR_Q_OFF = 272;
|
|
2180
|
+
var V12_17_ACCT_SCHED_START_SLOT_OFF = 288;
|
|
2181
|
+
var V12_17_ACCT_SCHED_HORIZON_OFF = 296;
|
|
2182
|
+
var V12_17_ACCT_SCHED_RELEASE_Q_OFF = 304;
|
|
2183
|
+
var V12_17_ACCT_PENDING_PRESENT_OFF = 320;
|
|
2184
|
+
var V12_17_ACCT_PENDING_REMAINING_Q_OFF = 336;
|
|
2185
|
+
var V12_17_ACCT_PENDING_HORIZON_OFF = 352;
|
|
2186
|
+
var V12_17_ACCT_PENDING_CREATED_SLOT_OFF = 360;
|
|
2187
|
+
var V12_17_ENGINE_PARAMS_OFF = 32;
|
|
2188
|
+
var V12_17_ENGINE_CURRENT_SLOT_OFF = 224;
|
|
2189
|
+
var V12_17_ENGINE_MARKET_MODE_OFF = 232;
|
|
2190
|
+
var V12_17_ENGINE_RESOLVED_K_LONG_OFF = 304;
|
|
2191
|
+
var V12_17_ENGINE_RESOLVED_K_SHORT_OFF = 320;
|
|
2192
|
+
var V12_17_ENGINE_RESOLVED_LIVE_PRICE_OFF = 336;
|
|
2193
|
+
var V12_17_ENGINE_LAST_CRANK_SLOT_OFF = 344;
|
|
2194
|
+
var V12_17_ENGINE_C_TOT_OFF = 352;
|
|
2195
|
+
var V12_17_ENGINE_PNL_POS_TOT_OFF = 368;
|
|
2196
|
+
var V12_17_ENGINE_PNL_MATURED_POS_TOT_OFF = 384;
|
|
2197
|
+
var V12_17_ENGINE_GC_CURSOR_OFF = 400;
|
|
2198
|
+
var V12_17_ENGINE_OI_EFF_LONG_OFF = 528;
|
|
2199
|
+
var V12_17_ENGINE_OI_EFF_SHORT_OFF = 544;
|
|
2200
|
+
var V12_17_ENGINE_NEG_PNL_COUNT_OFF = 648;
|
|
2201
|
+
var V12_17_ENGINE_LAST_ORACLE_PRICE_OFF = 656;
|
|
2202
|
+
var V12_17_ENGINE_FUND_PX_LAST_OFF = 664;
|
|
2203
|
+
var V12_17_ENGINE_F_LONG_NUM_OFF = 688;
|
|
2204
|
+
var V12_17_ENGINE_F_SHORT_NUM_OFF = 704;
|
|
2205
|
+
var V12_17_SBF_ENGINE_CURRENT_SLOT_OFF = 216;
|
|
2206
|
+
var V12_17_SBF_ENGINE_MARKET_MODE_OFF = 224;
|
|
2207
|
+
var V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF = 328;
|
|
2208
|
+
var V12_17_SBF_ENGINE_C_TOT_OFF = 336;
|
|
2209
|
+
var V12_17_SBF_ENGINE_PNL_POS_TOT_OFF = 352;
|
|
2210
|
+
var V12_17_SBF_ENGINE_PNL_MATURED_POS_TOT_OFF = 368;
|
|
2211
|
+
var V12_17_SBF_ENGINE_GC_CURSOR_OFF = 384;
|
|
2212
|
+
var V12_17_SBF_ENGINE_OI_EFF_LONG_OFF = 504;
|
|
2213
|
+
var V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF = 520;
|
|
2214
|
+
var V12_17_SBF_ENGINE_NEG_PNL_COUNT_OFF = 616;
|
|
2215
|
+
var V12_17_SBF_ENGINE_LAST_ORACLE_PRICE_OFF = 624;
|
|
2216
|
+
var V12_17_SBF_ENGINE_FUND_PX_LAST_OFF = 632;
|
|
2217
|
+
var V12_17_SBF_ENGINE_F_LONG_NUM_OFF = 648;
|
|
2218
|
+
var V12_17_SBF_ENGINE_F_SHORT_NUM_OFF = 664;
|
|
2219
|
+
var V12_17_SIZES = /* @__PURE__ */ new Map();
|
|
1611
2220
|
var V1M_ENGINE_OFF = 640;
|
|
1612
2221
|
var V1M_CONFIG_LEN = 536;
|
|
1613
2222
|
var V1M_ACCOUNT_SIZE = 248;
|
|
@@ -1680,16 +2289,64 @@ for (const n of TIERS) {
|
|
|
1680
2289
|
V1M2_SIZES.set(computeSlabSize(V1M2_ENGINE_OFF, V1M2_ENGINE_BITMAP_OFF, V1M2_ACCOUNT_SIZE, n, 18), n);
|
|
1681
2290
|
V_SETDEXPOOL_SIZES.set(computeSlabSize(V_SETDEXPOOL_ENGINE_OFF, V_ADL_ENGINE_BITMAP_OFF, V_ADL_ACCOUNT_SIZE, n, 18), n);
|
|
1682
2291
|
V12_1_SIZES.set(computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, n, 18), n);
|
|
2292
|
+
V12_15_SIZES.set(computeSlabSize(V12_15_ENGINE_OFF, V12_15_ENGINE_BITMAP_OFF, V12_15_ACCOUNT_SIZE, n, 18), n);
|
|
2293
|
+
}
|
|
2294
|
+
V12_15_SIZES.set(computeSlabSize(V12_15_ENGINE_OFF, V12_15_ENGINE_BITMAP_OFF, V12_15_ACCOUNT_SIZE, 2048, 18), 2048);
|
|
2295
|
+
V12_15_SIZES.set(237512, 256);
|
|
2296
|
+
var V12_17_TIERS = [256, 1024, 4096];
|
|
2297
|
+
for (const n of V12_17_TIERS) {
|
|
2298
|
+
const bitmapWords = Math.ceil(n / 64);
|
|
2299
|
+
const bitmapBytes = bitmapWords * 8;
|
|
2300
|
+
const postBitmap = 4;
|
|
2301
|
+
const nextFreeBytes = n * 2;
|
|
2302
|
+
const preAccNative = V12_17_ENGINE_BITMAP_OFF + bitmapBytes + postBitmap + nextFreeBytes;
|
|
2303
|
+
const accountsOffNative = Math.ceil(preAccNative / 16) * 16;
|
|
2304
|
+
const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + n * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN + n * V12_17_GEN_TABLE_ENTRY;
|
|
2305
|
+
V12_17_SIZES.set(nativeSize, n);
|
|
2306
|
+
const preAccSbf = V12_17_ENGINE_BITMAP_OFF_SBF + bitmapBytes + postBitmap + nextFreeBytes;
|
|
2307
|
+
const accountsOffSbf = Math.ceil(preAccSbf / 8) * 8;
|
|
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
|
+
V12_17_SIZES.set(sbfSize, n);
|
|
2310
|
+
}
|
|
2311
|
+
var V12_19_CONFIG_LEN = 528;
|
|
2312
|
+
var V12_19_ENGINE_OFF_SBF = 600;
|
|
2313
|
+
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)
|
|
2322
|
+
]);
|
|
2323
|
+
function buildLayoutV12_19(maxAccounts, dataLen) {
|
|
2324
|
+
const base = buildLayoutV12_17(maxAccounts, dataLen);
|
|
2325
|
+
return {
|
|
2326
|
+
...base,
|
|
2327
|
+
configLen: V12_19_CONFIG_LEN,
|
|
2328
|
+
engineOff: V12_19_ENGINE_OFF_SBF,
|
|
2329
|
+
accountsOff: V12_19_ENGINE_OFF_SBF + (base.accountsOff - base.engineOff)
|
|
2330
|
+
};
|
|
1683
2331
|
}
|
|
1684
2332
|
var V12_1_SBF_ACCOUNT_SIZE = 280;
|
|
1685
|
-
var
|
|
2333
|
+
var V12_1_SBF_ENGINE_OFF = 616;
|
|
2334
|
+
var V12_1_SBF_BITMAP_OFF = 584;
|
|
1686
2335
|
for (const [, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
|
|
1687
2336
|
const bitmapBytes = Math.ceil(n / 64) * 8;
|
|
1688
|
-
const preAccLen =
|
|
2337
|
+
const preAccLen = V12_1_SBF_BITMAP_OFF + bitmapBytes + 18 + n * 2;
|
|
1689
2338
|
const accountsOff = Math.ceil(preAccLen / 8) * 8;
|
|
1690
|
-
const total =
|
|
2339
|
+
const total = V12_1_SBF_ENGINE_OFF + accountsOff + n * V12_1_SBF_ACCOUNT_SIZE;
|
|
1691
2340
|
V12_1_SIZES.set(total, n);
|
|
1692
2341
|
}
|
|
2342
|
+
var V12_1_EP_SIZES = /* @__PURE__ */ new Map();
|
|
2343
|
+
for (const [, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
|
|
2344
|
+
const bitmapBytes = Math.ceil(n / 64) * 8;
|
|
2345
|
+
const preAccLen = V12_1_SBF_BITMAP_OFF + bitmapBytes + 18 + n * 2;
|
|
2346
|
+
const accountsOff = Math.ceil(preAccLen / 8) * 8;
|
|
2347
|
+
const total = V12_1_SBF_ENGINE_OFF + accountsOff + n * V12_1_EP_SBF_ACCOUNT_SIZE;
|
|
2348
|
+
V12_1_EP_SIZES.set(total, n);
|
|
2349
|
+
}
|
|
1693
2350
|
var SLAB_TIERS_V2 = {
|
|
1694
2351
|
small: { maxAccounts: 256, dataSize: 65088, label: "Small", description: "256 slots (V2 BPF intermediate)" },
|
|
1695
2352
|
large: { maxAccounts: 4096, dataSize: 1025568, label: "Large", description: "4,096 slots (V2 BPF intermediate)" }
|
|
@@ -2154,6 +2811,19 @@ for (const [label, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Lar
|
|
|
2154
2811
|
const size = computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, n, 18);
|
|
2155
2812
|
SLAB_TIERS_V12_1[label.toLowerCase()] = { maxAccounts: n, dataSize: size, label, description: `${n} slots (v12.1)` };
|
|
2156
2813
|
}
|
|
2814
|
+
var SLAB_TIERS_V12_15 = {};
|
|
2815
|
+
for (const [label, n] of [["Micro", 64], ["Small", 256], ["Medium", 1024], ["Medium2048", 2048], ["Large", 4096]]) {
|
|
2816
|
+
const size = computeSlabSize(V12_15_ENGINE_OFF, V12_15_ENGINE_BITMAP_OFF, V12_15_ACCOUNT_SIZE, n, 18);
|
|
2817
|
+
SLAB_TIERS_V12_15[label.toLowerCase()] = { maxAccounts: n, dataSize: size, label, description: `${n} slots (v12.15)` };
|
|
2818
|
+
}
|
|
2819
|
+
var SLAB_TIERS_V12_17 = {};
|
|
2820
|
+
for (const [label, n] of [["Small", 256], ["Medium", 1024], ["Large", 4096]]) {
|
|
2821
|
+
const bitmapBytes = Math.ceil(n / 64) * 8;
|
|
2822
|
+
const preAcc = V12_17_ENGINE_BITMAP_OFF_SBF + bitmapBytes + 4 + n * 2;
|
|
2823
|
+
const accountsOff = Math.ceil(preAcc / 8) * 8;
|
|
2824
|
+
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;
|
|
2825
|
+
SLAB_TIERS_V12_17[label.toLowerCase()] = { maxAccounts: n, dataSize: size, label, description: `${n} slots (v12.17)` };
|
|
2826
|
+
}
|
|
2157
2827
|
function buildLayoutVSetDexPool(maxAccounts) {
|
|
2158
2828
|
const engineOff = V_SETDEXPOOL_ENGINE_OFF;
|
|
2159
2829
|
const bitmapOff = V_ADL_ENGINE_BITMAP_OFF;
|
|
@@ -2214,73 +2884,341 @@ function buildLayoutVSetDexPool(maxAccounts) {
|
|
|
2214
2884
|
engineInsuranceIsolationBpsOff: 64
|
|
2215
2885
|
};
|
|
2216
2886
|
}
|
|
2217
|
-
function buildLayoutV12_1(maxAccounts, dataLen) {
|
|
2218
|
-
const
|
|
2219
|
-
const
|
|
2220
|
-
const
|
|
2221
|
-
const
|
|
2222
|
-
const accountSize = isSbf ? V12_1_ACCOUNT_SIZE_SBF : V12_1_ACCOUNT_SIZE;
|
|
2887
|
+
function buildLayoutV12_1(maxAccounts, dataLen) {
|
|
2888
|
+
const hostSize = computeSlabSize(V12_1_ENGINE_OFF, V12_1_ENGINE_BITMAP_OFF, V12_1_ACCOUNT_SIZE, maxAccounts, 18);
|
|
2889
|
+
const isSbf = dataLen !== void 0 && dataLen !== hostSize;
|
|
2890
|
+
const engineOff = isSbf ? V12_1_SBF_ENGINE_OFF : V12_1_ENGINE_OFF;
|
|
2891
|
+
const bitmapOff = isSbf ? V12_1_SBF_BITMAP_OFF : V12_1_ENGINE_BITMAP_OFF - V12_1_ENGINE_OFF;
|
|
2892
|
+
const accountSize = isSbf ? V12_1_ACCOUNT_SIZE_SBF : V12_1_ACCOUNT_SIZE;
|
|
2893
|
+
const bitmapWords = Math.ceil(maxAccounts / 64);
|
|
2894
|
+
const bitmapBytes = bitmapWords * 8;
|
|
2895
|
+
const postBitmap = 18;
|
|
2896
|
+
const nextFreeBytes = maxAccounts * 2;
|
|
2897
|
+
const preAccountsLen = bitmapOff + bitmapBytes + postBitmap + nextFreeBytes;
|
|
2898
|
+
const accountsOffRel = Math.ceil(preAccountsLen / 8) * 8;
|
|
2899
|
+
return {
|
|
2900
|
+
version: 1,
|
|
2901
|
+
headerLen: V0_HEADER_LEN,
|
|
2902
|
+
// 72
|
|
2903
|
+
configOffset: V0_HEADER_LEN,
|
|
2904
|
+
// 72
|
|
2905
|
+
configLen: isSbf ? 544 : 576,
|
|
2906
|
+
reservedOff: V1_RESERVED_OFF,
|
|
2907
|
+
engineOff,
|
|
2908
|
+
accountSize,
|
|
2909
|
+
maxAccounts,
|
|
2910
|
+
bitmapWords,
|
|
2911
|
+
accountsOff: engineOff + accountsOffRel,
|
|
2912
|
+
engineInsuranceOff: 16,
|
|
2913
|
+
engineParamsOff: isSbf ? V12_1_ENGINE_PARAMS_OFF_SBF : V12_1_ENGINE_PARAMS_OFF_HOST,
|
|
2914
|
+
paramsSize: isSbf ? V12_1_PARAMS_SIZE_SBF : V12_1_PARAMS_SIZE,
|
|
2915
|
+
// SBF engine offsets — all verified by cargo build-sbf offset_of! assertions.
|
|
2916
|
+
// Fields that don't exist in the deployed program are set to -1 on SBF.
|
|
2917
|
+
engineCurrentSlotOff: isSbf ? V12_1_SBF_OFF_CURRENT_SLOT : V12_1_ENGINE_CURRENT_SLOT_OFF,
|
|
2918
|
+
engineFundingIndexOff: isSbf ? -1 : V12_1_ENGINE_FUNDING_INDEX_OFF,
|
|
2919
|
+
// not in deployed struct
|
|
2920
|
+
engineLastFundingSlotOff: isSbf ? -1 : V12_1_ENGINE_LAST_FUNDING_SLOT_OFF,
|
|
2921
|
+
// not in deployed struct
|
|
2922
|
+
engineFundingRateBpsOff: isSbf ? V12_1_SBF_OFF_FUNDING_RATE : V12_1_ENGINE_FUNDING_RATE_BPS_OFF,
|
|
2923
|
+
engineMarkPriceOff: isSbf ? V12_1_SBF_OFF_MARK_PRICE_E6 : V12_1_ENGINE_MARK_PRICE_OFF,
|
|
2924
|
+
engineLastCrankSlotOff: isSbf ? V12_1_SBF_OFF_LAST_CRANK_SLOT : V12_1_ENGINE_LAST_CRANK_SLOT_OFF,
|
|
2925
|
+
engineMaxCrankStalenessOff: isSbf ? V12_1_SBF_OFF_MAX_CRANK_STALENESS : V12_1_ENGINE_MAX_CRANK_STALENESS_OFF,
|
|
2926
|
+
engineTotalOiOff: isSbf ? V12_1_SBF_OFF_TOTAL_OI : V12_1_ENGINE_TOTAL_OI_OFF,
|
|
2927
|
+
engineLongOiOff: isSbf ? V12_1_SBF_OFF_LONG_OI : V12_1_ENGINE_LONG_OI_OFF,
|
|
2928
|
+
engineShortOiOff: isSbf ? V12_1_SBF_OFF_SHORT_OI : V12_1_ENGINE_SHORT_OI_OFF,
|
|
2929
|
+
engineCTotOff: isSbf ? V12_1_SBF_OFF_C_TOT : V12_1_ENGINE_C_TOT_OFF,
|
|
2930
|
+
enginePnlPosTotOff: isSbf ? V12_1_SBF_OFF_PNL_POS_TOT : V12_1_ENGINE_PNL_POS_TOT_OFF,
|
|
2931
|
+
engineLiqCursorOff: isSbf ? V12_1_SBF_OFF_LIQ_CURSOR : V12_1_ENGINE_LIQ_CURSOR_OFF,
|
|
2932
|
+
engineGcCursorOff: isSbf ? V12_1_SBF_OFF_GC_CURSOR : V12_1_ENGINE_GC_CURSOR_OFF,
|
|
2933
|
+
engineLastSweepStartOff: isSbf ? V12_1_SBF_OFF_LAST_SWEEP_START : V12_1_ENGINE_LAST_SWEEP_START_OFF,
|
|
2934
|
+
engineLastSweepCompleteOff: isSbf ? V12_1_SBF_OFF_LAST_SWEEP_COMPLETE : V12_1_ENGINE_LAST_SWEEP_COMPLETE_OFF,
|
|
2935
|
+
engineCrankCursorOff: isSbf ? V12_1_SBF_OFF_CRANK_CURSOR : V12_1_ENGINE_CRANK_CURSOR_OFF,
|
|
2936
|
+
engineSweepStartIdxOff: isSbf ? V12_1_SBF_OFF_SWEEP_START_IDX : V12_1_ENGINE_SWEEP_START_IDX_OFF,
|
|
2937
|
+
engineLifetimeLiquidationsOff: isSbf ? V12_1_SBF_OFF_LIFETIME_LIQUIDATIONS : V12_1_ENGINE_LIFETIME_LIQUIDATIONS_OFF,
|
|
2938
|
+
engineLifetimeForceClosesOff: isSbf ? -1 : V12_1_ENGINE_LIFETIME_FORCE_CLOSES_OFF,
|
|
2939
|
+
// not in deployed struct
|
|
2940
|
+
engineNetLpPosOff: isSbf ? -1 : V12_1_ENGINE_NET_LP_POS_OFF,
|
|
2941
|
+
// not in deployed struct
|
|
2942
|
+
engineLpSumAbsOff: isSbf ? -1 : V12_1_ENGINE_LP_SUM_ABS_OFF,
|
|
2943
|
+
// not in deployed struct
|
|
2944
|
+
engineLpMaxAbsOff: isSbf ? -1 : V12_1_ENGINE_LP_MAX_ABS_OFF,
|
|
2945
|
+
// not in deployed struct
|
|
2946
|
+
engineLpMaxAbsSweepOff: isSbf ? -1 : V12_1_ENGINE_LP_MAX_ABS_SWEEP_OFF,
|
|
2947
|
+
// not in deployed struct
|
|
2948
|
+
engineEmergencyOiModeOff: isSbf ? -1 : V12_1_ENGINE_EMERGENCY_OI_MODE_OFF,
|
|
2949
|
+
// not in deployed struct
|
|
2950
|
+
engineEmergencyStartSlotOff: isSbf ? -1 : V12_1_ENGINE_EMERGENCY_START_SLOT_OFF,
|
|
2951
|
+
// not in deployed struct
|
|
2952
|
+
engineLastBreakerSlotOff: isSbf ? -1 : V12_1_ENGINE_LAST_BREAKER_SLOT_OFF,
|
|
2953
|
+
// not in deployed struct
|
|
2954
|
+
engineBitmapOff: bitmapOff,
|
|
2955
|
+
postBitmap: 18,
|
|
2956
|
+
acctOwnerOff: V12_1_ACCT_OWNER_OFF,
|
|
2957
|
+
// InsuranceFund on deployed program is just {balance: U128} = 16 bytes.
|
|
2958
|
+
// No isolated_balance or insurance_isolation_bps fields.
|
|
2959
|
+
hasInsuranceIsolation: !isSbf,
|
|
2960
|
+
engineInsuranceIsolatedOff: isSbf ? -1 : 48,
|
|
2961
|
+
engineInsuranceIsolationBpsOff: isSbf ? -1 : 64
|
|
2962
|
+
};
|
|
2963
|
+
}
|
|
2964
|
+
function buildLayoutV12_1EP(maxAccounts) {
|
|
2965
|
+
const engineOff = V12_1_SBF_ENGINE_OFF;
|
|
2966
|
+
const bitmapOff = V12_1_SBF_BITMAP_OFF;
|
|
2967
|
+
const accountSize = V12_1_EP_SBF_ACCOUNT_SIZE;
|
|
2968
|
+
const bitmapWords = Math.ceil(maxAccounts / 64);
|
|
2969
|
+
const bitmapBytes = bitmapWords * 8;
|
|
2970
|
+
const postBitmap = 18;
|
|
2971
|
+
const nextFreeBytes = maxAccounts * 2;
|
|
2972
|
+
const preAccountsLen = bitmapOff + bitmapBytes + postBitmap + nextFreeBytes;
|
|
2973
|
+
const accountsOffRel = Math.ceil(preAccountsLen / 8) * 8;
|
|
2974
|
+
return {
|
|
2975
|
+
version: 1,
|
|
2976
|
+
headerLen: 72,
|
|
2977
|
+
configOffset: 72,
|
|
2978
|
+
configLen: 544,
|
|
2979
|
+
reservedOff: 80,
|
|
2980
|
+
// V1_RESERVED_OFF
|
|
2981
|
+
engineOff,
|
|
2982
|
+
accountSize,
|
|
2983
|
+
maxAccounts,
|
|
2984
|
+
bitmapWords,
|
|
2985
|
+
accountsOff: engineOff + accountsOffRel,
|
|
2986
|
+
engineInsuranceOff: 16,
|
|
2987
|
+
engineParamsOff: 32,
|
|
2988
|
+
// V12_1_ENGINE_PARAMS_OFF_SBF
|
|
2989
|
+
paramsSize: 184,
|
|
2990
|
+
// V12_1_PARAMS_SIZE_SBF
|
|
2991
|
+
// Engine offsets identical to V12_1 SBF
|
|
2992
|
+
engineCurrentSlotOff: V12_1_SBF_OFF_CURRENT_SLOT,
|
|
2993
|
+
engineFundingIndexOff: -1,
|
|
2994
|
+
engineLastFundingSlotOff: -1,
|
|
2995
|
+
engineFundingRateBpsOff: V12_1_SBF_OFF_FUNDING_RATE,
|
|
2996
|
+
engineMarkPriceOff: V12_1_SBF_OFF_MARK_PRICE_E6,
|
|
2997
|
+
engineLastCrankSlotOff: V12_1_SBF_OFF_LAST_CRANK_SLOT,
|
|
2998
|
+
engineMaxCrankStalenessOff: V12_1_SBF_OFF_MAX_CRANK_STALENESS,
|
|
2999
|
+
engineTotalOiOff: V12_1_SBF_OFF_TOTAL_OI,
|
|
3000
|
+
engineLongOiOff: V12_1_SBF_OFF_LONG_OI,
|
|
3001
|
+
engineShortOiOff: V12_1_SBF_OFF_SHORT_OI,
|
|
3002
|
+
engineCTotOff: V12_1_SBF_OFF_C_TOT,
|
|
3003
|
+
enginePnlPosTotOff: V12_1_SBF_OFF_PNL_POS_TOT,
|
|
3004
|
+
engineLiqCursorOff: V12_1_SBF_OFF_LIQ_CURSOR,
|
|
3005
|
+
engineGcCursorOff: V12_1_SBF_OFF_GC_CURSOR,
|
|
3006
|
+
engineLastSweepStartOff: V12_1_SBF_OFF_LAST_SWEEP_START,
|
|
3007
|
+
engineLastSweepCompleteOff: V12_1_SBF_OFF_LAST_SWEEP_COMPLETE,
|
|
3008
|
+
engineCrankCursorOff: V12_1_SBF_OFF_CRANK_CURSOR,
|
|
3009
|
+
engineSweepStartIdxOff: V12_1_SBF_OFF_SWEEP_START_IDX,
|
|
3010
|
+
engineLifetimeLiquidationsOff: V12_1_SBF_OFF_LIFETIME_LIQUIDATIONS,
|
|
3011
|
+
engineLifetimeForceClosesOff: -1,
|
|
3012
|
+
engineNetLpPosOff: -1,
|
|
3013
|
+
engineLpSumAbsOff: -1,
|
|
3014
|
+
engineLpMaxAbsOff: -1,
|
|
3015
|
+
engineLpMaxAbsSweepOff: -1,
|
|
3016
|
+
engineEmergencyOiModeOff: -1,
|
|
3017
|
+
engineEmergencyStartSlotOff: -1,
|
|
3018
|
+
engineLastBreakerSlotOff: -1,
|
|
3019
|
+
engineBitmapOff: bitmapOff,
|
|
3020
|
+
postBitmap: 18,
|
|
3021
|
+
// Account offsets — shifted +8 from V12_1 due to entry_price insertion
|
|
3022
|
+
acctOwnerOff: V12_1_EP_ACCT_OWNER_OFF,
|
|
3023
|
+
// 216 (was 208)
|
|
3024
|
+
hasInsuranceIsolation: false,
|
|
3025
|
+
engineInsuranceIsolatedOff: -1,
|
|
3026
|
+
engineInsuranceIsolationBpsOff: -1
|
|
3027
|
+
};
|
|
3028
|
+
}
|
|
3029
|
+
function buildLayoutV12_15(maxAccounts, dataLen) {
|
|
3030
|
+
const isSbf = dataLen === 237512;
|
|
3031
|
+
const accountSize = isSbf ? V12_15_ACCOUNT_SIZE_SMALL : V12_15_ACCOUNT_SIZE;
|
|
3032
|
+
const engineOff = isSbf ? V12_15_ENGINE_OFF_SBF : V12_15_ENGINE_OFF;
|
|
3033
|
+
const bitmapOff = V12_15_ENGINE_BITMAP_OFF;
|
|
3034
|
+
const effectiveBitmapOff = isSbf ? 648 : bitmapOff;
|
|
3035
|
+
const bitmapWords = Math.ceil(maxAccounts / 64);
|
|
3036
|
+
const bitmapBytes = bitmapWords * 8;
|
|
3037
|
+
const postBitmap = 18;
|
|
3038
|
+
const nextFreeBytes = maxAccounts * 2;
|
|
3039
|
+
const preAccountsLen = effectiveBitmapOff + bitmapBytes + postBitmap + nextFreeBytes;
|
|
3040
|
+
const accountsOffRel = Math.ceil(preAccountsLen / 8) * 8;
|
|
3041
|
+
return {
|
|
3042
|
+
version: 2,
|
|
3043
|
+
headerLen: V0_HEADER_LEN,
|
|
3044
|
+
// 72
|
|
3045
|
+
configOffset: V0_HEADER_LEN,
|
|
3046
|
+
// 72
|
|
3047
|
+
configLen: 552,
|
|
3048
|
+
// SBF CONFIG_LEN for v12.15
|
|
3049
|
+
reservedOff: V1_RESERVED_OFF,
|
|
3050
|
+
// 80
|
|
3051
|
+
engineOff,
|
|
3052
|
+
accountSize,
|
|
3053
|
+
maxAccounts,
|
|
3054
|
+
bitmapWords,
|
|
3055
|
+
accountsOff: engineOff + accountsOffRel,
|
|
3056
|
+
engineInsuranceOff: 16,
|
|
3057
|
+
engineParamsOff: V12_15_ENGINE_PARAMS_OFF,
|
|
3058
|
+
// 32
|
|
3059
|
+
paramsSize: isSbf ? 184 : V12_15_PARAMS_SIZE,
|
|
3060
|
+
// SBF=184 (no trailing pad), native=192
|
|
3061
|
+
engineCurrentSlotOff: isSbf ? 216 : V12_15_ENGINE_CURRENT_SLOT_OFF,
|
|
3062
|
+
// SBF=216, native=224
|
|
3063
|
+
engineFundingIndexOff: -1,
|
|
3064
|
+
// not present in v12.15 engine struct
|
|
3065
|
+
engineLastFundingSlotOff: -1,
|
|
3066
|
+
// not present in v12.15 engine struct
|
|
3067
|
+
engineFundingRateBpsOff: isSbf ? 224 : V12_15_ENGINE_FUNDING_RATE_E9_OFF,
|
|
3068
|
+
// SBF=224, native=240
|
|
3069
|
+
engineMarkPriceOff: -1,
|
|
3070
|
+
// not present in v12.15
|
|
3071
|
+
engineLastCrankSlotOff: -1,
|
|
3072
|
+
// not yet mapped
|
|
3073
|
+
engineMaxCrankStalenessOff: -1,
|
|
3074
|
+
// not yet mapped
|
|
3075
|
+
engineTotalOiOff: -1,
|
|
3076
|
+
// not present in v12.15 engine
|
|
3077
|
+
engineLongOiOff: -1,
|
|
3078
|
+
// not present in v12.15 engine
|
|
3079
|
+
engineShortOiOff: -1,
|
|
3080
|
+
// not present in v12.15 engine
|
|
3081
|
+
engineCTotOff: isSbf ? 320 : V12_15_ENGINE_C_TOT_OFF,
|
|
3082
|
+
// SBF=320 (verified on-chain), native=344
|
|
3083
|
+
enginePnlPosTotOff: isSbf ? 336 : V12_15_ENGINE_PNL_POS_TOT_OFF,
|
|
3084
|
+
// SBF=336 (verified), native=368
|
|
3085
|
+
engineLiqCursorOff: -1,
|
|
3086
|
+
// not yet mapped
|
|
3087
|
+
engineGcCursorOff: -1,
|
|
3088
|
+
// not yet mapped
|
|
3089
|
+
engineLastSweepStartOff: -1,
|
|
3090
|
+
// not yet mapped
|
|
3091
|
+
engineLastSweepCompleteOff: -1,
|
|
3092
|
+
// not yet mapped
|
|
3093
|
+
engineCrankCursorOff: -1,
|
|
3094
|
+
// not yet mapped
|
|
3095
|
+
engineSweepStartIdxOff: -1,
|
|
3096
|
+
// not yet mapped
|
|
3097
|
+
engineLifetimeLiquidationsOff: -1,
|
|
3098
|
+
// not yet mapped
|
|
3099
|
+
engineLifetimeForceClosesOff: -1,
|
|
3100
|
+
// not present in v12.15
|
|
3101
|
+
engineNetLpPosOff: -1,
|
|
3102
|
+
// not present in v12.15
|
|
3103
|
+
engineLpSumAbsOff: -1,
|
|
3104
|
+
// not present in v12.15
|
|
3105
|
+
engineLpMaxAbsOff: -1,
|
|
3106
|
+
// not present in v12.15
|
|
3107
|
+
engineLpMaxAbsSweepOff: -1,
|
|
3108
|
+
// not present in v12.15
|
|
3109
|
+
engineEmergencyOiModeOff: -1,
|
|
3110
|
+
// not present in v12.15
|
|
3111
|
+
engineEmergencyStartSlotOff: -1,
|
|
3112
|
+
// not present in v12.15
|
|
3113
|
+
engineLastBreakerSlotOff: -1,
|
|
3114
|
+
// not present in v12.15
|
|
3115
|
+
engineBitmapOff: effectiveBitmapOff,
|
|
3116
|
+
// SBF=640, native=862
|
|
3117
|
+
postBitmap,
|
|
3118
|
+
acctOwnerOff: V12_15_ACCT_OWNER_OFF,
|
|
3119
|
+
// 192
|
|
3120
|
+
hasInsuranceIsolation: false,
|
|
3121
|
+
engineInsuranceIsolatedOff: -1,
|
|
3122
|
+
engineInsuranceIsolationBpsOff: -1
|
|
3123
|
+
};
|
|
3124
|
+
}
|
|
3125
|
+
function buildLayoutV12_17(maxAccounts, dataLen) {
|
|
3126
|
+
const isSbf = (() => {
|
|
3127
|
+
const bitmapBytes2 = Math.ceil(maxAccounts / 64) * 8;
|
|
3128
|
+
const preAccNative = V12_17_ENGINE_BITMAP_OFF + bitmapBytes2 + 4 + maxAccounts * 2;
|
|
3129
|
+
const accountsOffNative = Math.ceil(preAccNative / 16) * 16;
|
|
3130
|
+
const nativeSize = V12_17_ENGINE_OFF + accountsOffNative + maxAccounts * V12_17_ACCOUNT_SIZE + V12_17_RISK_BUF_LEN + maxAccounts * V12_17_GEN_TABLE_ENTRY;
|
|
3131
|
+
return dataLen !== nativeSize;
|
|
3132
|
+
})();
|
|
3133
|
+
const engineOff = isSbf ? V12_17_ENGINE_OFF_SBF : V12_17_ENGINE_OFF;
|
|
3134
|
+
const accountSize = isSbf ? V12_17_ACCOUNT_SIZE_SBF : V12_17_ACCOUNT_SIZE;
|
|
3135
|
+
const bitmapOff = isSbf ? V12_17_ENGINE_BITMAP_OFF_SBF : V12_17_ENGINE_BITMAP_OFF;
|
|
2223
3136
|
const bitmapWords = Math.ceil(maxAccounts / 64);
|
|
2224
3137
|
const bitmapBytes = bitmapWords * 8;
|
|
2225
|
-
const postBitmap =
|
|
3138
|
+
const postBitmap = 4;
|
|
2226
3139
|
const nextFreeBytes = maxAccounts * 2;
|
|
2227
3140
|
const preAccountsLen = bitmapOff + bitmapBytes + postBitmap + nextFreeBytes;
|
|
2228
|
-
const
|
|
3141
|
+
const acctAlign = isSbf ? 8 : 16;
|
|
3142
|
+
const accountsOffRel = Math.ceil(preAccountsLen / acctAlign) * acctAlign;
|
|
2229
3143
|
return {
|
|
2230
|
-
version:
|
|
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.
|
|
3144
|
+
version: 2,
|
|
2233
3145
|
headerLen: V0_HEADER_LEN,
|
|
2234
|
-
// 72
|
|
3146
|
+
// 72
|
|
2235
3147
|
configOffset: V0_HEADER_LEN,
|
|
2236
3148
|
// 72
|
|
2237
|
-
configLen
|
|
2238
|
-
//
|
|
3149
|
+
// configLen = 512 (SBF-aligned MarketConfig size after Phase A/B/E).
|
|
3150
|
+
// Verified field-by-field against percolator-prog/src/percolator.rs MarketConfig struct.
|
|
3151
|
+
// Missing 80 bytes from prior value 432: max_pnl_cap, last_audit_pause_slot,
|
|
3152
|
+
// oi_cap_multiplier_bps, dispute_window_slots, dispute_bond_amount,
|
|
3153
|
+
// lp_collateral_enabled, lp_collateral_ltv_bps, _new_fields_pad, pending_admin.
|
|
3154
|
+
configLen: 512,
|
|
2239
3155
|
reservedOff: V1_RESERVED_OFF,
|
|
3156
|
+
// 80
|
|
2240
3157
|
engineOff,
|
|
2241
3158
|
accountSize,
|
|
2242
3159
|
maxAccounts,
|
|
2243
3160
|
bitmapWords,
|
|
2244
3161
|
accountsOff: engineOff + accountsOffRel,
|
|
2245
3162
|
engineInsuranceOff: 16,
|
|
2246
|
-
engineParamsOff:
|
|
2247
|
-
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
|
|
2254
|
-
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
|
|
2260
|
-
|
|
2261
|
-
|
|
2262
|
-
|
|
2263
|
-
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
3163
|
+
engineParamsOff: V12_17_ENGINE_PARAMS_OFF,
|
|
3164
|
+
// 32
|
|
3165
|
+
paramsSize: isSbf ? 184 : 192,
|
|
3166
|
+
engineCurrentSlotOff: isSbf ? V12_17_SBF_ENGINE_CURRENT_SLOT_OFF : V12_17_ENGINE_CURRENT_SLOT_OFF,
|
|
3167
|
+
engineFundingIndexOff: -1,
|
|
3168
|
+
// replaced by per-side f_long_num/f_short_num
|
|
3169
|
+
engineLastFundingSlotOff: -1,
|
|
3170
|
+
engineFundingRateBpsOff: -1,
|
|
3171
|
+
// no stored funding rate in v12.17
|
|
3172
|
+
engineMarkPriceOff: -1,
|
|
3173
|
+
// v12.17 computes mark from state; no stored field
|
|
3174
|
+
engineLastCrankSlotOff: isSbf ? V12_17_SBF_ENGINE_LAST_CRANK_SLOT_OFF : V12_17_ENGINE_LAST_CRANK_SLOT_OFF,
|
|
3175
|
+
engineMaxCrankStalenessOff: -1,
|
|
3176
|
+
engineTotalOiOff: -1,
|
|
3177
|
+
// parseEngine sums long + short when total offset is -1
|
|
3178
|
+
engineLongOiOff: isSbf ? V12_17_SBF_ENGINE_OI_EFF_LONG_OFF : V12_17_ENGINE_OI_EFF_LONG_OFF,
|
|
3179
|
+
engineShortOiOff: isSbf ? V12_17_SBF_ENGINE_OI_EFF_SHORT_OFF : V12_17_ENGINE_OI_EFF_SHORT_OFF,
|
|
3180
|
+
engineCTotOff: isSbf ? V12_17_SBF_ENGINE_C_TOT_OFF : V12_17_ENGINE_C_TOT_OFF,
|
|
3181
|
+
enginePnlPosTotOff: isSbf ? V12_17_SBF_ENGINE_PNL_POS_TOT_OFF : V12_17_ENGINE_PNL_POS_TOT_OFF,
|
|
3182
|
+
engineLiqCursorOff: -1,
|
|
3183
|
+
// removed in v12.17
|
|
3184
|
+
engineGcCursorOff: isSbf ? V12_17_SBF_ENGINE_GC_CURSOR_OFF : V12_17_ENGINE_GC_CURSOR_OFF,
|
|
3185
|
+
engineLastSweepStartOff: -1,
|
|
3186
|
+
engineLastSweepCompleteOff: -1,
|
|
3187
|
+
engineCrankCursorOff: -1,
|
|
3188
|
+
engineSweepStartIdxOff: -1,
|
|
3189
|
+
engineLifetimeLiquidationsOff: -1,
|
|
3190
|
+
engineLifetimeForceClosesOff: -1,
|
|
3191
|
+
engineNetLpPosOff: -1,
|
|
3192
|
+
engineLpSumAbsOff: -1,
|
|
3193
|
+
engineLpMaxAbsOff: -1,
|
|
3194
|
+
engineLpMaxAbsSweepOff: -1,
|
|
3195
|
+
engineEmergencyOiModeOff: -1,
|
|
3196
|
+
engineEmergencyStartSlotOff: -1,
|
|
3197
|
+
engineLastBreakerSlotOff: -1,
|
|
3198
|
+
engineBitmapOff: bitmapOff,
|
|
3199
|
+
postBitmap,
|
|
3200
|
+
acctOwnerOff: isSbf ? 192 : V12_17_ACCT_OWNER_OFF,
|
|
3201
|
+
// SBF=192, native=200
|
|
3202
|
+
hasInsuranceIsolation: false,
|
|
3203
|
+
engineInsuranceIsolatedOff: -1,
|
|
3204
|
+
engineInsuranceIsolationBpsOff: -1,
|
|
3205
|
+
// v12.17 dropped the engine.mark_price field (see engineMarkPriceOff above).
|
|
3206
|
+
// The EWMA-smoothed mark that the matcher actually quotes against lives in
|
|
3207
|
+
// MarketConfig.mark_ewma_e6 at offset 304 within the config struct.
|
|
3208
|
+
// Layout is identical on SBF and native. configOffset is V0_HEADER_LEN = 72,
|
|
3209
|
+
// so absolute offset in the slab is 72 + 304 = 376.
|
|
3210
|
+
configMarkEwmaOff: V0_HEADER_LEN + 304
|
|
2281
3211
|
};
|
|
2282
3212
|
}
|
|
2283
3213
|
function detectSlabLayout(dataLen, data) {
|
|
3214
|
+
const v1219n = V12_19_SIZES.get(dataLen);
|
|
3215
|
+
if (v1219n !== void 0) return buildLayoutV12_19(v1219n, dataLen);
|
|
3216
|
+
const v1217n = V12_17_SIZES.get(dataLen);
|
|
3217
|
+
if (v1217n !== void 0) return buildLayoutV12_17(v1217n, dataLen);
|
|
3218
|
+
const v1215n = V12_15_SIZES.get(dataLen);
|
|
3219
|
+
if (v1215n !== void 0) return buildLayoutV12_15(v1215n, dataLen);
|
|
3220
|
+
const v121epn = V12_1_EP_SIZES.get(dataLen);
|
|
3221
|
+
if (v121epn !== void 0) return buildLayoutV12_1EP(v121epn);
|
|
2284
3222
|
const v121n = V12_1_SIZES.get(dataLen);
|
|
2285
3223
|
if (v121n !== void 0) return buildLayoutV12_1(v121n, dataLen);
|
|
2286
3224
|
const vsdpn = V_SETDEXPOOL_SIZES.get(dataLen);
|
|
@@ -2327,6 +3265,15 @@ var PARAMS_LIQUIDATION_FEE_BPS_OFF = 96;
|
|
|
2327
3265
|
var PARAMS_LIQUIDATION_FEE_CAP_OFF = 104;
|
|
2328
3266
|
var PARAMS_LIQUIDATION_BUFFER_OFF = 120;
|
|
2329
3267
|
var PARAMS_MIN_LIQUIDATION_OFF = 128;
|
|
3268
|
+
var V12_1_PARAMS_MAINT_FEE_OFF = 56;
|
|
3269
|
+
var V12_1_PARAMS_MAX_CRANK_OFF = 72;
|
|
3270
|
+
var V12_1_PARAMS_LIQ_FEE_BPS_OFF = 80;
|
|
3271
|
+
var V12_1_PARAMS_LIQ_FEE_CAP_OFF = 88;
|
|
3272
|
+
var V12_1_PARAMS_MIN_LIQ_OFF = 104;
|
|
3273
|
+
var V12_1_PARAMS_MIN_INITIAL_DEP_OFF = 120;
|
|
3274
|
+
var V12_1_PARAMS_MIN_NZ_MM_OFF = 136;
|
|
3275
|
+
var V12_1_PARAMS_MIN_NZ_IM_OFF = 152;
|
|
3276
|
+
var V12_1_PARAMS_INS_FLOOR_OFF = 168;
|
|
2330
3277
|
var ACCT_ACCOUNT_ID_OFF = 0;
|
|
2331
3278
|
var ACCT_CAPITAL_OFF = 8;
|
|
2332
3279
|
var ACCT_KIND_OFF = 24;
|
|
@@ -2397,7 +3344,7 @@ function parseHeader(data) {
|
|
|
2397
3344
|
const version = readU32LE(data, 8);
|
|
2398
3345
|
const bump = readU8(data, 12);
|
|
2399
3346
|
const flags = readU8(data, 13);
|
|
2400
|
-
const admin = new
|
|
3347
|
+
const admin = new PublicKey5(data.subarray(16, 48));
|
|
2401
3348
|
const layout = detectSlabLayout(data.length, data);
|
|
2402
3349
|
const roff = layout ? layout.reservedOff : V0_RESERVED_OFF;
|
|
2403
3350
|
const nonce = readU64LE(data, roff);
|
|
@@ -2414,20 +3361,99 @@ function parseHeader(data) {
|
|
|
2414
3361
|
lastThrUpdateSlot
|
|
2415
3362
|
};
|
|
2416
3363
|
}
|
|
3364
|
+
function parseConfigV12_17(data, configOff) {
|
|
3365
|
+
const MIN_V12_17_BYTES = 512;
|
|
3366
|
+
if (data.length < configOff + MIN_V12_17_BYTES) {
|
|
3367
|
+
throw new Error(`Slab data too short for V12_17 config: ${data.length} < ${configOff + MIN_V12_17_BYTES}`);
|
|
3368
|
+
}
|
|
3369
|
+
const b = configOff;
|
|
3370
|
+
const collateralMint = new PublicKey5(data.subarray(b + 0, b + 32));
|
|
3371
|
+
const vaultPubkey = new PublicKey5(data.subarray(b + 32, b + 64));
|
|
3372
|
+
const indexFeedId = new PublicKey5(data.subarray(b + 64, b + 96));
|
|
3373
|
+
const maxStalenessSlots = readU64LE(data, b + 96);
|
|
3374
|
+
const confFilterBps = readU16LE(data, b + 104);
|
|
3375
|
+
const vaultAuthorityBump = readU8(data, b + 106);
|
|
3376
|
+
const invert = readU8(data, b + 107);
|
|
3377
|
+
const unitScale = readU32LE(data, b + 108);
|
|
3378
|
+
const fundingHorizonSlots = readU64LE(data, b + 112);
|
|
3379
|
+
const fundingKBps = readU64LE(data, b + 120);
|
|
3380
|
+
const fundingMaxPremiumBps = readI64LE(data, b + 128);
|
|
3381
|
+
const fundingMaxBpsPerSlot = readI64LE(data, b + 136);
|
|
3382
|
+
const oracleAuthority = new PublicKey5(data.subarray(b + 144, b + 176));
|
|
3383
|
+
const authorityPriceE6 = readU64LE(data, b + 176);
|
|
3384
|
+
const authorityTimestamp = readI64LE(data, b + 184);
|
|
3385
|
+
const oraclePriceCapE2bps = readU64LE(data, b + 192);
|
|
3386
|
+
const lastEffectivePriceE6 = readU64LE(data, b + 200);
|
|
3387
|
+
const dexPoolBytes = data.subarray(b + 400, b + 432);
|
|
3388
|
+
const dexPool = dexPoolBytes.some((x) => x !== 0) ? new PublicKey5(dexPoolBytes) : null;
|
|
3389
|
+
return {
|
|
3390
|
+
collateralMint,
|
|
3391
|
+
vaultPubkey,
|
|
3392
|
+
indexFeedId,
|
|
3393
|
+
maxStalenessSlots,
|
|
3394
|
+
confFilterBps,
|
|
3395
|
+
vaultAuthorityBump,
|
|
3396
|
+
invert,
|
|
3397
|
+
unitScale,
|
|
3398
|
+
fundingHorizonSlots,
|
|
3399
|
+
fundingKBps,
|
|
3400
|
+
fundingInvScaleNotionalE6: 0n,
|
|
3401
|
+
// removed in v12.17
|
|
3402
|
+
fundingMaxPremiumBps,
|
|
3403
|
+
fundingMaxBpsPerSlot,
|
|
3404
|
+
fundingPremiumWeightBps: 0n,
|
|
3405
|
+
fundingSettlementIntervalSlots: 0n,
|
|
3406
|
+
fundingPremiumDampeningE6: 0n,
|
|
3407
|
+
fundingPremiumMaxBpsPerSlot: 0n,
|
|
3408
|
+
threshFloor: 0n,
|
|
3409
|
+
// removed in v12.17
|
|
3410
|
+
threshRiskBps: 0n,
|
|
3411
|
+
threshUpdateIntervalSlots: 0n,
|
|
3412
|
+
threshStepBps: 0n,
|
|
3413
|
+
threshAlphaBps: 0n,
|
|
3414
|
+
threshMin: 0n,
|
|
3415
|
+
threshMax: 0n,
|
|
3416
|
+
threshMinStep: 0n,
|
|
3417
|
+
oracleAuthority,
|
|
3418
|
+
authorityPriceE6,
|
|
3419
|
+
authorityTimestamp,
|
|
3420
|
+
oraclePriceCapE2bps,
|
|
3421
|
+
lastEffectivePriceE6,
|
|
3422
|
+
oiCapMultiplierBps: readU64LE(data, b + 448),
|
|
3423
|
+
maxPnlCap: readU64LE(data, b + 432),
|
|
3424
|
+
adaptiveFundingEnabled: false,
|
|
3425
|
+
// removed in v12.17
|
|
3426
|
+
adaptiveScaleBps: 0,
|
|
3427
|
+
adaptiveMaxFundingBps: 0n,
|
|
3428
|
+
marketCreatedSlot: 0n,
|
|
3429
|
+
oiRampSlots: 0n,
|
|
3430
|
+
resolvedSlot: 0n,
|
|
3431
|
+
insuranceIsolationBps: 0,
|
|
3432
|
+
oraclePhase: 0,
|
|
3433
|
+
cumulativeVolumeE6: 0n,
|
|
3434
|
+
phase2DeltaSlots: 0,
|
|
3435
|
+
dexPool
|
|
3436
|
+
};
|
|
3437
|
+
}
|
|
2417
3438
|
function parseConfig(data, layoutHint) {
|
|
2418
3439
|
const layout = layoutHint !== void 0 ? layoutHint : detectSlabLayout(data.length, data);
|
|
2419
3440
|
const configOff = layout ? layout.configOffset : V0_HEADER_LEN;
|
|
2420
3441
|
const configLen = layout ? layout.configLen : V0_CONFIG_LEN;
|
|
2421
|
-
const
|
|
3442
|
+
const isV12_17 = layout && (layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF);
|
|
3443
|
+
if (isV12_17) {
|
|
3444
|
+
return parseConfigV12_17(data, configOff);
|
|
3445
|
+
}
|
|
3446
|
+
const MIN_CONFIG_BYTES = 376;
|
|
3447
|
+
const minLen = configOff + Math.min(configLen, MIN_CONFIG_BYTES);
|
|
2422
3448
|
if (data.length < minLen) {
|
|
2423
3449
|
throw new Error(`Slab data too short for config: ${data.length} < ${minLen}`);
|
|
2424
3450
|
}
|
|
2425
3451
|
let off = configOff;
|
|
2426
|
-
const collateralMint = new
|
|
3452
|
+
const collateralMint = new PublicKey5(data.subarray(off, off + 32));
|
|
2427
3453
|
off += 32;
|
|
2428
|
-
const vaultPubkey = new
|
|
3454
|
+
const vaultPubkey = new PublicKey5(data.subarray(off, off + 32));
|
|
2429
3455
|
off += 32;
|
|
2430
|
-
const indexFeedId = new
|
|
3456
|
+
const indexFeedId = new PublicKey5(data.subarray(off, off + 32));
|
|
2431
3457
|
off += 32;
|
|
2432
3458
|
const maxStalenessSlots = readU64LE(data, off);
|
|
2433
3459
|
off += 8;
|
|
@@ -2465,7 +3491,7 @@ function parseConfig(data, layoutHint) {
|
|
|
2465
3491
|
off += 16;
|
|
2466
3492
|
const threshMinStep = readU128LE(data, off);
|
|
2467
3493
|
off += 16;
|
|
2468
|
-
const oracleAuthority = new
|
|
3494
|
+
const oracleAuthority = new PublicKey5(data.subarray(off, off + 32));
|
|
2469
3495
|
off += 32;
|
|
2470
3496
|
const authorityPriceE6 = readU64LE(data, off);
|
|
2471
3497
|
off += 8;
|
|
@@ -2518,7 +3544,7 @@ function parseConfig(data, layoutHint) {
|
|
|
2518
3544
|
if (configLen >= DEX_POOL_REL_OFF + 32 && data.length >= configOff + DEX_POOL_REL_OFF + 32) {
|
|
2519
3545
|
const dexPoolBytes = data.subarray(configOff + DEX_POOL_REL_OFF, configOff + DEX_POOL_REL_OFF + 32);
|
|
2520
3546
|
if (dexPoolBytes.some((b) => b !== 0)) {
|
|
2521
|
-
dexPool = new
|
|
3547
|
+
dexPool = new PublicKey5(dexPoolBytes);
|
|
2522
3548
|
}
|
|
2523
3549
|
}
|
|
2524
3550
|
return {
|
|
@@ -2573,26 +3599,61 @@ function parseParams(data, layoutHint) {
|
|
|
2573
3599
|
const paramsOff = layout ? layout.engineParamsOff : V0_ENGINE_PARAMS_OFF;
|
|
2574
3600
|
const paramsSize = layout ? layout.paramsSize : V0_PARAMS_SIZE;
|
|
2575
3601
|
const base = engineOff + paramsOff;
|
|
2576
|
-
|
|
2577
|
-
|
|
3602
|
+
const MIN_PARAMS_BYTES = paramsSize >= 144 ? 144 : 56;
|
|
3603
|
+
if (data.length < base + MIN_PARAMS_BYTES) {
|
|
3604
|
+
throw new Error(`Slab data too short for RiskParams: ${data.length} < ${base + MIN_PARAMS_BYTES}`);
|
|
2578
3605
|
}
|
|
3606
|
+
const isV12_15Params = paramsSize === V12_15_PARAMS_SIZE || paramsSize === 184;
|
|
3607
|
+
const isV12_1Sbf = !isV12_15Params && layout !== null && layout !== void 0 && layout.engineOff === V12_1_SBF_ENGINE_OFF && paramsSize === 184;
|
|
2579
3608
|
const result = {
|
|
2580
|
-
warmupPeriodSlots: readU64LE(data, base + PARAMS_WARMUP_PERIOD_OFF),
|
|
2581
|
-
maintenanceMarginBps: readU64LE(data, base + PARAMS_MAINTENANCE_MARGIN_OFF),
|
|
2582
|
-
initialMarginBps: readU64LE(data, base + PARAMS_INITIAL_MARGIN_OFF),
|
|
2583
|
-
tradingFeeBps: readU64LE(data, base + PARAMS_TRADING_FEE_OFF),
|
|
2584
|
-
maxAccounts: readU64LE(data, base + PARAMS_MAX_ACCOUNTS_OFF),
|
|
2585
|
-
newAccountFee: readU128LE(data, base + PARAMS_NEW_ACCOUNT_FEE_OFF),
|
|
2586
|
-
// Extended params:
|
|
3609
|
+
warmupPeriodSlots: isV12_15Params ? readU64LE(data, base + V12_15_PARAMS_H_MIN_OFF) : readU64LE(data, base + PARAMS_WARMUP_PERIOD_OFF),
|
|
3610
|
+
maintenanceMarginBps: isV12_15Params ? readU64LE(data, base + 0) : readU64LE(data, base + PARAMS_MAINTENANCE_MARGIN_OFF),
|
|
3611
|
+
initialMarginBps: isV12_15Params ? readU64LE(data, base + 8) : readU64LE(data, base + PARAMS_INITIAL_MARGIN_OFF),
|
|
3612
|
+
tradingFeeBps: isV12_15Params ? readU64LE(data, base + 16) : readU64LE(data, base + PARAMS_TRADING_FEE_OFF),
|
|
3613
|
+
maxAccounts: isV12_15Params ? readU64LE(data, base + V12_15_PARAMS_MAX_ACCOUNTS_OFF) : readU64LE(data, base + PARAMS_MAX_ACCOUNTS_OFF),
|
|
3614
|
+
newAccountFee: isV12_15Params ? readU128LE(data, base + 32) : readU128LE(data, base + PARAMS_NEW_ACCOUNT_FEE_OFF),
|
|
3615
|
+
// Extended params: defaults; overwritten below if layout supports them
|
|
2587
3616
|
riskReductionThreshold: 0n,
|
|
2588
3617
|
maintenanceFeePerSlot: 0n,
|
|
2589
3618
|
maxCrankStalenessSlots: 0n,
|
|
2590
3619
|
liquidationFeeBps: 0n,
|
|
2591
3620
|
liquidationFeeCap: 0n,
|
|
2592
3621
|
liquidationBufferBps: 0n,
|
|
2593
|
-
minLiquidationAbs: 0n
|
|
3622
|
+
minLiquidationAbs: 0n,
|
|
3623
|
+
minInitialDeposit: 0n,
|
|
3624
|
+
minNonzeroMmReq: 0n,
|
|
3625
|
+
minNonzeroImReq: 0n,
|
|
3626
|
+
insuranceFloor: 0n,
|
|
3627
|
+
hMin: 0n,
|
|
3628
|
+
hMax: 0n
|
|
2594
3629
|
};
|
|
2595
|
-
if (
|
|
3630
|
+
if (isV12_15Params) {
|
|
3631
|
+
result.hMin = readU64LE(data, base + V12_15_PARAMS_H_MIN_OFF);
|
|
3632
|
+
result.hMax = readU64LE(data, base + V12_15_PARAMS_H_MAX_OFF);
|
|
3633
|
+
result.insuranceFloor = readU128LE(data, base + V12_15_PARAMS_INSURANCE_FLOOR_OFF);
|
|
3634
|
+
result.riskReductionThreshold = 0n;
|
|
3635
|
+
result.maintenanceFeePerSlot = 0n;
|
|
3636
|
+
result.maxCrankStalenessSlots = readU64LE(data, base + 48);
|
|
3637
|
+
result.liquidationFeeBps = readU64LE(data, base + 56);
|
|
3638
|
+
result.liquidationFeeCap = readU128LE(data, base + 64);
|
|
3639
|
+
result.liquidationBufferBps = 0n;
|
|
3640
|
+
result.minLiquidationAbs = readU128LE(data, base + 80);
|
|
3641
|
+
result.minInitialDeposit = readU128LE(data, base + 96);
|
|
3642
|
+
result.minNonzeroMmReq = readU128LE(data, base + 112);
|
|
3643
|
+
result.minNonzeroImReq = readU128LE(data, base + 128);
|
|
3644
|
+
} else if (isV12_1Sbf) {
|
|
3645
|
+
result.maintenanceFeePerSlot = readU128LE(data, base + V12_1_PARAMS_MAINT_FEE_OFF);
|
|
3646
|
+
result.maxCrankStalenessSlots = readU64LE(data, base + V12_1_PARAMS_MAX_CRANK_OFF);
|
|
3647
|
+
result.liquidationFeeBps = readU64LE(data, base + V12_1_PARAMS_LIQ_FEE_BPS_OFF);
|
|
3648
|
+
result.liquidationFeeCap = readU128LE(data, base + V12_1_PARAMS_LIQ_FEE_CAP_OFF);
|
|
3649
|
+
result.minLiquidationAbs = readU128LE(data, base + V12_1_PARAMS_MIN_LIQ_OFF);
|
|
3650
|
+
result.minInitialDeposit = readU128LE(data, base + V12_1_PARAMS_MIN_INITIAL_DEP_OFF);
|
|
3651
|
+
result.minNonzeroMmReq = readU128LE(data, base + V12_1_PARAMS_MIN_NZ_MM_OFF);
|
|
3652
|
+
result.minNonzeroImReq = readU128LE(data, base + V12_1_PARAMS_MIN_NZ_IM_OFF);
|
|
3653
|
+
result.insuranceFloor = readU128LE(data, base + V12_1_PARAMS_INS_FLOOR_OFF);
|
|
3654
|
+
result.hMin = result.warmupPeriodSlots;
|
|
3655
|
+
result.hMax = result.warmupPeriodSlots;
|
|
3656
|
+
} else if (paramsSize >= 144) {
|
|
2596
3657
|
result.riskReductionThreshold = readU128LE(data, base + PARAMS_RISK_THRESHOLD_OFF);
|
|
2597
3658
|
result.maintenanceFeePerSlot = readU128LE(data, base + PARAMS_MAINTENANCE_FEE_OFF);
|
|
2598
3659
|
result.maxCrankStalenessSlots = readU64LE(data, base + PARAMS_MAX_CRANK_STALENESS_OFF);
|
|
@@ -2600,6 +3661,8 @@ function parseParams(data, layoutHint) {
|
|
|
2600
3661
|
result.liquidationFeeCap = readU128LE(data, base + PARAMS_LIQUIDATION_FEE_CAP_OFF);
|
|
2601
3662
|
result.liquidationBufferBps = readU64LE(data, base + PARAMS_LIQUIDATION_BUFFER_OFF);
|
|
2602
3663
|
result.minLiquidationAbs = readU128LE(data, base + PARAMS_MIN_LIQUIDATION_OFF);
|
|
3664
|
+
result.hMin = result.warmupPeriodSlots;
|
|
3665
|
+
result.hMax = result.warmupPeriodSlots;
|
|
2603
3666
|
}
|
|
2604
3667
|
return result;
|
|
2605
3668
|
}
|
|
@@ -2609,41 +3672,128 @@ function parseEngine(data) {
|
|
|
2609
3672
|
throw new Error(`Unrecognized slab data length: ${data.length}. Cannot determine layout version.`);
|
|
2610
3673
|
}
|
|
2611
3674
|
const base = layout.engineOff;
|
|
3675
|
+
const isV12_17 = layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF;
|
|
3676
|
+
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;
|
|
3696
|
+
const longOi = readU128LE(data, base + oiEffLongOff);
|
|
3697
|
+
const shortOi = readU128LE(data, base + oiEffShortOff);
|
|
3698
|
+
const bitmapEnd = layout.engineBitmapOff + layout.bitmapWords * 8;
|
|
3699
|
+
return {
|
|
3700
|
+
vault: readU128LE(data, base),
|
|
3701
|
+
insuranceFund: {
|
|
3702
|
+
balance: readU128LE(data, base + 16),
|
|
3703
|
+
feeRevenue: 0n,
|
|
3704
|
+
isolatedBalance: 0n,
|
|
3705
|
+
isolationBps: 0
|
|
3706
|
+
},
|
|
3707
|
+
currentSlot: readU64LE(data, base + currentSlotOff),
|
|
3708
|
+
fundingIndexQpbE6: 0n,
|
|
3709
|
+
// replaced by per-side funding
|
|
3710
|
+
lastFundingSlot: 0n,
|
|
3711
|
+
fundingRateBpsPerSlotLast: 0n,
|
|
3712
|
+
// no stored funding rate in v12.17
|
|
3713
|
+
fundingRateE9: 0n,
|
|
3714
|
+
// no stored funding rate in v12.17
|
|
3715
|
+
marketMode: readU8(data, base + marketModeOff) === 1 ? 1 : 0,
|
|
3716
|
+
lastCrankSlot: readU64LE(data, base + lastCrankSlotOff),
|
|
3717
|
+
maxCrankStalenessSlots: 0n,
|
|
3718
|
+
totalOpenInterest: longOi + shortOi,
|
|
3719
|
+
longOi,
|
|
3720
|
+
shortOi,
|
|
3721
|
+
cTot: readU128LE(data, base + cTotOff),
|
|
3722
|
+
pnlPosTot: readU128LE(data, base + pnlPosTotOff),
|
|
3723
|
+
pnlMaturedPosTot: readU128LE(data, base + pnlMaturedOff),
|
|
3724
|
+
liqCursor: 0,
|
|
3725
|
+
gcCursor: readU16LE(data, base + gcCursorOff),
|
|
3726
|
+
lastSweepStartSlot: 0n,
|
|
3727
|
+
lastSweepCompleteSlot: 0n,
|
|
3728
|
+
crankCursor: 0,
|
|
3729
|
+
sweepStartIdx: 0,
|
|
3730
|
+
lifetimeLiquidations: 0n,
|
|
3731
|
+
lifetimeForceCloses: 0n,
|
|
3732
|
+
netLpPos: 0n,
|
|
3733
|
+
lpSumAbs: 0n,
|
|
3734
|
+
lpMaxAbs: 0n,
|
|
3735
|
+
lpMaxAbsSweep: 0n,
|
|
3736
|
+
emergencyOiMode: false,
|
|
3737
|
+
emergencyStartSlot: 0n,
|
|
3738
|
+
lastBreakerSlot: 0n,
|
|
3739
|
+
markPriceE6: 0n,
|
|
3740
|
+
oraclePriceE6: readU64LE(data, base + oraclePriceOff),
|
|
3741
|
+
numUsedAccounts: readU16LE(data, base + bitmapEnd),
|
|
3742
|
+
nextAccountId: 0n,
|
|
3743
|
+
// removed in v12.17 (replaced by mat_counter in header)
|
|
3744
|
+
// V12_17 fields
|
|
3745
|
+
fLongNum: readI128LE(data, base + fLongNumOff),
|
|
3746
|
+
fShortNum: readI128LE(data, base + fShortNumOff),
|
|
3747
|
+
negPnlAccountCount: readU64LE(data, base + negPnlOff),
|
|
3748
|
+
fundPxLast: readU64LE(data, base + fundPxLastOff),
|
|
3749
|
+
resolvedKLongTerminalDelta: readI128LE(data, base + resolvedKLongOff),
|
|
3750
|
+
resolvedKShortTerminalDelta: readI128LE(data, base + resolvedKShortOff),
|
|
3751
|
+
resolvedLivePrice: readU64LE(data, base + resolvedLivePriceOff)
|
|
3752
|
+
};
|
|
3753
|
+
}
|
|
3754
|
+
const fundingRateBpsPerSlotLast = isV12_15 ? readI128LE(data, base + layout.engineFundingRateBpsOff) : readI64LE(data, base + layout.engineFundingRateBpsOff);
|
|
2612
3755
|
return {
|
|
2613
3756
|
vault: readU128LE(data, base),
|
|
2614
3757
|
insuranceFund: {
|
|
2615
3758
|
balance: readU128LE(data, base + layout.engineInsuranceOff),
|
|
2616
|
-
feeRevenue:
|
|
3759
|
+
// feeRevenue: only exists in percolator-core (80-byte InsuranceFund), not deployed (16-byte)
|
|
3760
|
+
feeRevenue: layout.hasInsuranceIsolation ? readU128LE(data, base + layout.engineInsuranceOff + 16) : 0n,
|
|
2617
3761
|
isolatedBalance: layout.hasInsuranceIsolation ? readU128LE(data, base + layout.engineInsuranceIsolatedOff) : 0n,
|
|
2618
3762
|
isolationBps: layout.hasInsuranceIsolation ? readU16LE(data, base + layout.engineInsuranceIsolationBpsOff) : 0
|
|
2619
3763
|
},
|
|
2620
3764
|
currentSlot: readU64LE(data, base + layout.engineCurrentSlotOff),
|
|
2621
|
-
fundingIndexQpbE6: readI128LE(data, base + layout.engineFundingIndexOff),
|
|
2622
|
-
lastFundingSlot: readU64LE(data, base + layout.engineLastFundingSlotOff),
|
|
2623
|
-
fundingRateBpsPerSlotLast
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
3765
|
+
fundingIndexQpbE6: layout.engineFundingIndexOff >= 0 ? readI128LE(data, base + layout.engineFundingIndexOff) : 0n,
|
|
3766
|
+
lastFundingSlot: layout.engineLastFundingSlotOff >= 0 ? readU64LE(data, base + layout.engineLastFundingSlotOff) : 0n,
|
|
3767
|
+
fundingRateBpsPerSlotLast,
|
|
3768
|
+
fundingRateE9: isV12_15 ? readI128LE(data, base + layout.engineFundingRateBpsOff) : 0n,
|
|
3769
|
+
marketMode: isV12_15 ? readU8(data, base + layout.engineFundingRateBpsOff + 16) === 1 ? 1 : 0 : null,
|
|
3770
|
+
lastCrankSlot: layout.engineLastCrankSlotOff >= 0 ? readU64LE(data, base + layout.engineLastCrankSlotOff) : 0n,
|
|
3771
|
+
maxCrankStalenessSlots: layout.engineMaxCrankStalenessOff >= 0 ? readU64LE(data, base + layout.engineMaxCrankStalenessOff) : 0n,
|
|
3772
|
+
totalOpenInterest: layout.engineTotalOiOff >= 0 ? readU128LE(data, base + layout.engineTotalOiOff) : 0n,
|
|
2627
3773
|
longOi: layout.engineLongOiOff >= 0 ? readU128LE(data, base + layout.engineLongOiOff) : 0n,
|
|
2628
3774
|
shortOi: layout.engineShortOiOff >= 0 ? readU128LE(data, base + layout.engineShortOiOff) : 0n,
|
|
2629
3775
|
cTot: readU128LE(data, base + layout.engineCTotOff),
|
|
2630
3776
|
pnlPosTot: readU128LE(data, base + layout.enginePnlPosTotOff),
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
3777
|
+
pnlMaturedPosTot: isV12_15 ? readU128LE(data, base + V12_15_ENGINE_PNL_MATURED_POS_TOT_OFF) : 0n,
|
|
3778
|
+
liqCursor: layout.engineLiqCursorOff >= 0 ? readU16LE(data, base + layout.engineLiqCursorOff) : 0,
|
|
3779
|
+
gcCursor: layout.engineGcCursorOff >= 0 ? readU16LE(data, base + layout.engineGcCursorOff) : 0,
|
|
3780
|
+
lastSweepStartSlot: layout.engineLastSweepStartOff >= 0 ? readU64LE(data, base + layout.engineLastSweepStartOff) : 0n,
|
|
3781
|
+
lastSweepCompleteSlot: layout.engineLastSweepCompleteOff >= 0 ? readU64LE(data, base + layout.engineLastSweepCompleteOff) : 0n,
|
|
3782
|
+
crankCursor: layout.engineCrankCursorOff >= 0 ? readU16LE(data, base + layout.engineCrankCursorOff) : 0,
|
|
3783
|
+
sweepStartIdx: layout.engineSweepStartIdxOff >= 0 ? readU16LE(data, base + layout.engineSweepStartIdxOff) : 0,
|
|
3784
|
+
lifetimeLiquidations: layout.engineLifetimeLiquidationsOff >= 0 ? readU64LE(data, base + layout.engineLifetimeLiquidationsOff) : 0n,
|
|
3785
|
+
lifetimeForceCloses: layout.engineLifetimeForceClosesOff >= 0 ? readU64LE(data, base + layout.engineLifetimeForceClosesOff) : 0n,
|
|
3786
|
+
netLpPos: layout.engineNetLpPosOff >= 0 ? readI128LE(data, base + layout.engineNetLpPosOff) : 0n,
|
|
3787
|
+
lpSumAbs: layout.engineLpSumAbsOff >= 0 ? readU128LE(data, base + layout.engineLpSumAbsOff) : 0n,
|
|
2641
3788
|
lpMaxAbs: layout.engineLpMaxAbsOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsOff) : 0n,
|
|
2642
3789
|
lpMaxAbsSweep: layout.engineLpMaxAbsSweepOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsSweepOff) : 0n,
|
|
2643
3790
|
emergencyOiMode: layout.engineEmergencyOiModeOff >= 0 ? data[base + layout.engineEmergencyOiModeOff] !== 0 : false,
|
|
2644
3791
|
emergencyStartSlot: layout.engineEmergencyStartSlotOff >= 0 ? readU64LE(data, base + layout.engineEmergencyStartSlotOff) : 0n,
|
|
2645
3792
|
lastBreakerSlot: layout.engineLastBreakerSlotOff >= 0 ? readU64LE(data, base + layout.engineLastBreakerSlotOff) : 0n,
|
|
2646
3793
|
markPriceE6: layout.engineMarkPriceOff >= 0 ? readU64LE(data, base + layout.engineMarkPriceOff) : 0n,
|
|
3794
|
+
// V12_15: last_oracle_price at engine+608 (SBF) / engine+... (native).
|
|
3795
|
+
// Located at bitmapOff - 40 on SBF (648-40=608, verified on-chain).
|
|
3796
|
+
oraclePriceE6: isV12_15 ? readU64LE(data, base + layout.engineBitmapOff - 40) : 0n,
|
|
2647
3797
|
numUsedAccounts: (() => {
|
|
2648
3798
|
if (layout.postBitmap < 18) return 0;
|
|
2649
3799
|
const bw = layout.bitmapWords;
|
|
@@ -2654,7 +3804,15 @@ function parseEngine(data) {
|
|
|
2654
3804
|
const bw = layout.bitmapWords;
|
|
2655
3805
|
const numUsedOff = layout.engineBitmapOff + bw * 8;
|
|
2656
3806
|
return readU64LE(data, base + Math.ceil((numUsedOff + 2) / 8) * 8);
|
|
2657
|
-
})()
|
|
3807
|
+
})(),
|
|
3808
|
+
// V12_17 fields (not present in pre-v12.17)
|
|
3809
|
+
fLongNum: 0n,
|
|
3810
|
+
fShortNum: 0n,
|
|
3811
|
+
negPnlAccountCount: 0n,
|
|
3812
|
+
fundPxLast: 0n,
|
|
3813
|
+
resolvedKLongTerminalDelta: 0n,
|
|
3814
|
+
resolvedKShortTerminalDelta: 0n,
|
|
3815
|
+
resolvedLivePrice: 0n
|
|
2658
3816
|
};
|
|
2659
3817
|
}
|
|
2660
3818
|
function parseUsedIndices(data) {
|
|
@@ -2704,17 +3862,129 @@ function parseAccount(data, idx) {
|
|
|
2704
3862
|
if (data.length < base + layout.accountSize) {
|
|
2705
3863
|
throw new Error("Slab data too short for account");
|
|
2706
3864
|
}
|
|
2707
|
-
const
|
|
2708
|
-
const
|
|
3865
|
+
const isV12_17 = layout.accountSize === V12_17_ACCOUNT_SIZE || layout.accountSize === V12_17_ACCOUNT_SIZE_SBF;
|
|
3866
|
+
const isV12_15 = !isV12_17 && (layout.accountSize === V12_15_ACCOUNT_SIZE || layout.accountSize === V12_15_ACCOUNT_SIZE_SMALL);
|
|
3867
|
+
const isV12_1EP = !isV12_17 && !isV12_15 && layout.accountSize === V12_1_EP_SBF_ACCOUNT_SIZE && layout.engineOff === V12_1_SBF_ENGINE_OFF;
|
|
3868
|
+
const isV12_1 = !isV12_17 && !isV12_15 && !isV12_1EP && (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);
|
|
3869
|
+
const isAdl = !isV12_17 && !isV12_15 && (layout.accountSize >= 312 || isV12_1 || isV12_1EP);
|
|
3870
|
+
if (isV12_17) {
|
|
3871
|
+
const isSbf = layout.accountSize === V12_17_ACCOUNT_SIZE_SBF;
|
|
3872
|
+
const d1 = isSbf ? 8 : 0;
|
|
3873
|
+
const d2 = isSbf ? 16 : 0;
|
|
3874
|
+
const kindByte2 = readU8(data, base + V12_17_ACCT_KIND_OFF);
|
|
3875
|
+
const kind2 = kindByte2 === 1 ? 1 /* LP */ : 0 /* User */;
|
|
3876
|
+
return {
|
|
3877
|
+
kind: kind2,
|
|
3878
|
+
accountId: 0n,
|
|
3879
|
+
// removed in v12.17
|
|
3880
|
+
capital: readU128LE(data, base + V12_17_ACCT_CAPITAL_OFF),
|
|
3881
|
+
pnl: readI128LE(data, base + V12_17_ACCT_PNL_OFF - d1),
|
|
3882
|
+
reservedPnl: readU128LE(data, base + V12_17_ACCT_RESERVED_PNL_OFF - d1),
|
|
3883
|
+
warmupStartedAtSlot: 0n,
|
|
3884
|
+
// removed
|
|
3885
|
+
warmupSlopePerStep: 0n,
|
|
3886
|
+
// removed
|
|
3887
|
+
positionSize: readI128LE(data, base + V12_17_ACCT_POSITION_BASIS_Q_OFF - d1),
|
|
3888
|
+
entryPrice: 0n,
|
|
3889
|
+
// removed — compute off-chain from position_basis_q / effective_pos_q
|
|
3890
|
+
fundingIndex: 0n,
|
|
3891
|
+
// replaced by per-side f_long_num/f_short_num + per-account f_snap
|
|
3892
|
+
matcherProgram: new PublicKey5(data.subarray(base + V12_17_ACCT_MATCHER_PROGRAM_OFF - d1, base + V12_17_ACCT_MATCHER_PROGRAM_OFF - d1 + 32)),
|
|
3893
|
+
matcherContext: new PublicKey5(data.subarray(base + V12_17_ACCT_MATCHER_CONTEXT_OFF - d1, base + V12_17_ACCT_MATCHER_CONTEXT_OFF - d1 + 32)),
|
|
3894
|
+
owner: new PublicKey5(data.subarray(base + V12_17_ACCT_OWNER_OFF - d1, base + V12_17_ACCT_OWNER_OFF - d1 + 32)),
|
|
3895
|
+
feeCredits: readI128LE(data, base + V12_17_ACCT_FEE_CREDITS_OFF - d1),
|
|
3896
|
+
lastFeeSlot: 0n,
|
|
3897
|
+
// removed
|
|
3898
|
+
feesEarnedTotal: 0n,
|
|
3899
|
+
// removed in v12.17
|
|
3900
|
+
exactReserveCohorts: null,
|
|
3901
|
+
// replaced by two-bucket warmup
|
|
3902
|
+
exactCohortCount: null,
|
|
3903
|
+
overflowOlder: null,
|
|
3904
|
+
overflowOlderPresent: null,
|
|
3905
|
+
overflowNewest: null,
|
|
3906
|
+
overflowNewestPresent: null,
|
|
3907
|
+
// V12_17 fields
|
|
3908
|
+
fSnap: readI128LE(data, base + V12_17_ACCT_F_SNAP_OFF - d1),
|
|
3909
|
+
adlABasis: readU128LE(data, base + V12_17_ACCT_ADL_A_BASIS_OFF - d1),
|
|
3910
|
+
adlKSnap: readI128LE(data, base + V12_17_ACCT_ADL_K_SNAP_OFF - d1),
|
|
3911
|
+
adlEpochSnap: readU64LE(data, base + V12_17_ACCT_ADL_EPOCH_SNAP_OFF - d1),
|
|
3912
|
+
schedPresent: readU8(data, base + V12_17_ACCT_SCHED_PRESENT_OFF - d1) !== 0,
|
|
3913
|
+
schedRemainingQ: readU128LE(data, base + V12_17_ACCT_SCHED_REMAINING_Q_OFF - d1),
|
|
3914
|
+
schedAnchorQ: readU128LE(data, base + V12_17_ACCT_SCHED_ANCHOR_Q_OFF - d1),
|
|
3915
|
+
schedStartSlot: readU64LE(data, base + V12_17_ACCT_SCHED_START_SLOT_OFF - d1),
|
|
3916
|
+
schedHorizon: readU64LE(data, base + V12_17_ACCT_SCHED_HORIZON_OFF - d1),
|
|
3917
|
+
schedReleaseQ: readU128LE(data, base + V12_17_ACCT_SCHED_RELEASE_Q_OFF - d1),
|
|
3918
|
+
pendingPresent: readU8(data, base + V12_17_ACCT_PENDING_PRESENT_OFF - d1) !== 0,
|
|
3919
|
+
pendingRemainingQ: readU128LE(data, base + V12_17_ACCT_PENDING_REMAINING_Q_OFF - d2),
|
|
3920
|
+
pendingHorizon: readU64LE(data, base + V12_17_ACCT_PENDING_HORIZON_OFF - d2),
|
|
3921
|
+
pendingCreatedSlot: readU64LE(data, base + V12_17_ACCT_PENDING_CREATED_SLOT_OFF - d2)
|
|
3922
|
+
};
|
|
3923
|
+
}
|
|
3924
|
+
if (isV12_15) {
|
|
3925
|
+
const kindByte2 = readU8(data, base + V12_15_ACCT_KIND_OFF);
|
|
3926
|
+
const kind2 = kindByte2 === 1 ? 1 /* LP */ : 0 /* User */;
|
|
3927
|
+
const cohortCount = readU8(data, base + V12_15_ACCT_EXACT_COHORT_COUNT_OFF);
|
|
3928
|
+
const exactReserveCohorts = [];
|
|
3929
|
+
for (let i = 0; i < 62; i++) {
|
|
3930
|
+
const cohortOff = base + V12_15_ACCT_EXACT_RESERVE_COHORTS_OFF + i * 64;
|
|
3931
|
+
exactReserveCohorts.push(data.slice(cohortOff, cohortOff + 64));
|
|
3932
|
+
}
|
|
3933
|
+
const overflowOlderPresent = readU8(data, base + V12_15_ACCT_OVERFLOW_OLDER_PRESENT_OFF) !== 0;
|
|
3934
|
+
const overflowNewestPresent = readU8(data, base + V12_15_ACCT_OVERFLOW_NEWEST_PRESENT_OFF) !== 0;
|
|
3935
|
+
return {
|
|
3936
|
+
kind: kind2,
|
|
3937
|
+
accountId: readU64LE(data, base + V12_15_ACCT_ACCOUNT_ID_OFF),
|
|
3938
|
+
capital: readU128LE(data, base + V12_15_ACCT_CAPITAL_OFF),
|
|
3939
|
+
pnl: readI128LE(data, base + V12_15_ACCT_PNL_OFF),
|
|
3940
|
+
reservedPnl: readU128LE(data, base + V12_15_ACCT_RESERVED_PNL_OFF),
|
|
3941
|
+
warmupStartedAtSlot: 0n,
|
|
3942
|
+
// removed in v12.15
|
|
3943
|
+
warmupSlopePerStep: 0n,
|
|
3944
|
+
// removed in v12.15
|
|
3945
|
+
positionSize: readI128LE(data, base + V12_15_ACCT_POSITION_BASIS_Q_OFF),
|
|
3946
|
+
entryPrice: readU64LE(data, base + V12_15_ACCT_ENTRY_PRICE_OFF),
|
|
3947
|
+
fundingIndex: 0n,
|
|
3948
|
+
// not present in v12.15 account struct
|
|
3949
|
+
matcherProgram: new PublicKey5(data.subarray(base + V12_15_ACCT_MATCHER_PROGRAM_OFF, base + V12_15_ACCT_MATCHER_PROGRAM_OFF + 32)),
|
|
3950
|
+
matcherContext: new PublicKey5(data.subarray(base + V12_15_ACCT_MATCHER_CONTEXT_OFF, base + V12_15_ACCT_MATCHER_CONTEXT_OFF + 32)),
|
|
3951
|
+
owner: new PublicKey5(data.subarray(base + V12_15_ACCT_OWNER_OFF, base + V12_15_ACCT_OWNER_OFF + 32)),
|
|
3952
|
+
feeCredits: readI128LE(data, base + V12_15_ACCT_FEE_CREDITS_OFF),
|
|
3953
|
+
lastFeeSlot: 0n,
|
|
3954
|
+
// removed in v12.15
|
|
3955
|
+
feesEarnedTotal: readU128LE(data, base + V12_15_ACCT_FEES_EARNED_TOTAL_OFF),
|
|
3956
|
+
exactReserveCohorts,
|
|
3957
|
+
exactCohortCount: cohortCount,
|
|
3958
|
+
overflowOlder: data.slice(base + V12_15_ACCT_OVERFLOW_OLDER_OFF, base + V12_15_ACCT_OVERFLOW_OLDER_OFF + 64),
|
|
3959
|
+
overflowOlderPresent,
|
|
3960
|
+
overflowNewest: data.slice(base + V12_15_ACCT_OVERFLOW_NEWEST_OFF, base + V12_15_ACCT_OVERFLOW_NEWEST_OFF + 64),
|
|
3961
|
+
overflowNewestPresent,
|
|
3962
|
+
// v12.17 fields (not present in v12.15)
|
|
3963
|
+
fSnap: 0n,
|
|
3964
|
+
adlABasis: 0n,
|
|
3965
|
+
adlKSnap: 0n,
|
|
3966
|
+
adlEpochSnap: 0n,
|
|
3967
|
+
schedPresent: null,
|
|
3968
|
+
schedRemainingQ: null,
|
|
3969
|
+
schedAnchorQ: null,
|
|
3970
|
+
schedStartSlot: null,
|
|
3971
|
+
schedHorizon: null,
|
|
3972
|
+
schedReleaseQ: null,
|
|
3973
|
+
pendingPresent: null,
|
|
3974
|
+
pendingRemainingQ: null,
|
|
3975
|
+
pendingHorizon: null,
|
|
3976
|
+
pendingCreatedSlot: null
|
|
3977
|
+
};
|
|
3978
|
+
}
|
|
2709
3979
|
const warmupStartedOff = isAdl ? V_ADL_ACCT_WARMUP_STARTED_OFF : ACCT_WARMUP_STARTED_OFF;
|
|
2710
3980
|
const warmupSlopeOff = isAdl ? V_ADL_ACCT_WARMUP_SLOPE_OFF : ACCT_WARMUP_SLOPE_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 ?
|
|
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;
|
|
3981
|
+
const positionSizeOff = isV12_1 || isV12_1EP ? V12_1_ACCT_POSITION_SIZE_OFF : isAdl ? V_ADL_ACCT_POSITION_SIZE_OFF : ACCT_POSITION_SIZE_OFF;
|
|
3982
|
+
const entryPriceOff = isV12_1EP ? V12_1_EP_ACCT_ENTRY_PRICE_OFF : isV12_1 ? V12_1_ACCT_ENTRY_PRICE_OFF : isAdl ? V_ADL_ACCT_ENTRY_PRICE_OFF : ACCT_ENTRY_PRICE_OFF;
|
|
3983
|
+
const fundingIndexOff = isV12_1 || isV12_1EP ? -1 : isAdl ? V_ADL_ACCT_FUNDING_INDEX_OFF : ACCT_FUNDING_INDEX_OFF;
|
|
3984
|
+
const matcherProgOff = isV12_1EP ? V12_1_EP_ACCT_MATCHER_PROGRAM_OFF : isV12_1 ? V12_1_ACCT_MATCHER_PROGRAM_OFF : isAdl ? V_ADL_ACCT_MATCHER_PROGRAM_OFF : ACCT_MATCHER_PROGRAM_OFF;
|
|
3985
|
+
const matcherCtxOff = isV12_1EP ? V12_1_EP_ACCT_MATCHER_CONTEXT_OFF : isV12_1 ? V12_1_ACCT_MATCHER_CONTEXT_OFF : isAdl ? V_ADL_ACCT_MATCHER_CONTEXT_OFF : ACCT_MATCHER_CONTEXT_OFF;
|
|
3986
|
+
const feeCreditsOff = isV12_1EP ? V12_1_EP_ACCT_FEE_CREDITS_OFF : isV12_1 ? V12_1_ACCT_FEE_CREDITS_OFF : isAdl ? V_ADL_ACCT_FEE_CREDITS_OFF : ACCT_FEE_CREDITS_OFF;
|
|
3987
|
+
const lastFeeSlotOff = isV12_1EP ? V12_1_EP_ACCT_LAST_FEE_SLOT_OFF : isV12_1 ? V12_1_ACCT_LAST_FEE_SLOT_OFF : isAdl ? V_ADL_ACCT_LAST_FEE_SLOT_OFF : ACCT_LAST_FEE_SLOT_OFF;
|
|
2718
3988
|
const kindByte = readU8(data, base + ACCT_KIND_OFF);
|
|
2719
3989
|
const kind = kindByte === 1 ? 1 /* LP */ : 0 /* User */;
|
|
2720
3990
|
return {
|
|
@@ -2727,14 +3997,37 @@ function parseAccount(data, idx) {
|
|
|
2727
3997
|
warmupSlopePerStep: readU128LE(data, base + warmupSlopeOff),
|
|
2728
3998
|
positionSize: readI128LE(data, base + positionSizeOff),
|
|
2729
3999
|
entryPrice: entryPriceOff >= 0 ? readU64LE(data, base + entryPriceOff) : 0n,
|
|
2730
|
-
// V12_1:
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
owner: new PublicKey3(data.subarray(base + layout.acctOwnerOff, base + layout.acctOwnerOff + 32)),
|
|
4000
|
+
// V12_1/V12_1_EP: funding_index not present in SBF layout
|
|
4001
|
+
fundingIndex: isV12_1 || isV12_1EP ? fundingIndexOff >= 0 ? BigInt(readI64LE(data, base + fundingIndexOff)) : 0n : readI128LE(data, base + fundingIndexOff),
|
|
4002
|
+
matcherProgram: new PublicKey5(data.subarray(base + matcherProgOff, base + matcherProgOff + 32)),
|
|
4003
|
+
matcherContext: new PublicKey5(data.subarray(base + matcherCtxOff, base + matcherCtxOff + 32)),
|
|
4004
|
+
owner: new PublicKey5(data.subarray(base + layout.acctOwnerOff, base + layout.acctOwnerOff + 32)),
|
|
2736
4005
|
feeCredits: readI128LE(data, base + feeCreditsOff),
|
|
2737
|
-
lastFeeSlot: readU64LE(data, base + lastFeeSlotOff)
|
|
4006
|
+
lastFeeSlot: readU64LE(data, base + lastFeeSlotOff),
|
|
4007
|
+
feesEarnedTotal: 0n,
|
|
4008
|
+
// not present in pre-v12.15 layouts
|
|
4009
|
+
exactReserveCohorts: null,
|
|
4010
|
+
// not present in pre-v12.15 layouts
|
|
4011
|
+
exactCohortCount: null,
|
|
4012
|
+
overflowOlder: null,
|
|
4013
|
+
overflowOlderPresent: null,
|
|
4014
|
+
overflowNewest: null,
|
|
4015
|
+
overflowNewestPresent: null,
|
|
4016
|
+
// v12.17 fields (not present in pre-v12.17)
|
|
4017
|
+
fSnap: 0n,
|
|
4018
|
+
adlABasis: 0n,
|
|
4019
|
+
adlKSnap: 0n,
|
|
4020
|
+
adlEpochSnap: 0n,
|
|
4021
|
+
schedPresent: null,
|
|
4022
|
+
schedRemainingQ: null,
|
|
4023
|
+
schedAnchorQ: null,
|
|
4024
|
+
schedStartSlot: null,
|
|
4025
|
+
schedHorizon: null,
|
|
4026
|
+
schedReleaseQ: null,
|
|
4027
|
+
pendingPresent: null,
|
|
4028
|
+
pendingRemainingQ: null,
|
|
4029
|
+
pendingHorizon: null,
|
|
4030
|
+
pendingCreatedSlot: null
|
|
2738
4031
|
};
|
|
2739
4032
|
}
|
|
2740
4033
|
function parseAllAccounts(data) {
|
|
@@ -2754,14 +4047,20 @@ function parseAllAccounts(data) {
|
|
|
2754
4047
|
}
|
|
2755
4048
|
|
|
2756
4049
|
// src/solana/pda.ts
|
|
2757
|
-
import { PublicKey as
|
|
4050
|
+
import { PublicKey as PublicKey6 } from "@solana/web3.js";
|
|
2758
4051
|
var textEncoder = new TextEncoder();
|
|
2759
4052
|
function deriveVaultAuthority(programId, slab) {
|
|
2760
|
-
return
|
|
4053
|
+
return PublicKey6.findProgramAddressSync(
|
|
2761
4054
|
[textEncoder.encode("vault"), slab.toBytes()],
|
|
2762
4055
|
programId
|
|
2763
4056
|
);
|
|
2764
4057
|
}
|
|
4058
|
+
function deriveInsuranceLpMint(programId, slab) {
|
|
4059
|
+
return PublicKey6.findProgramAddressSync(
|
|
4060
|
+
[textEncoder.encode("lp_vault_mint"), slab.toBytes()],
|
|
4061
|
+
programId
|
|
4062
|
+
);
|
|
4063
|
+
}
|
|
2765
4064
|
var LP_INDEX_U16_MAX = 65535;
|
|
2766
4065
|
function deriveLpPda(programId, slab, lpIdx) {
|
|
2767
4066
|
if (typeof lpIdx !== "number" || !Number.isInteger(lpIdx) || lpIdx < 0 || lpIdx > LP_INDEX_U16_MAX) {
|
|
@@ -2769,34 +4068,28 @@ function deriveLpPda(programId, slab, lpIdx) {
|
|
|
2769
4068
|
`deriveLpPda: lpIdx must be an integer in [0, ${LP_INDEX_U16_MAX}], got ${lpIdx}`
|
|
2770
4069
|
);
|
|
2771
4070
|
}
|
|
2772
|
-
const
|
|
2773
|
-
new DataView(
|
|
2774
|
-
return
|
|
2775
|
-
[textEncoder.encode("lp"), slab.toBytes(),
|
|
2776
|
-
programId
|
|
2777
|
-
);
|
|
2778
|
-
}
|
|
2779
|
-
function deriveKeeperFund(programId, slab) {
|
|
2780
|
-
return PublicKey4.findProgramAddressSync(
|
|
2781
|
-
[textEncoder.encode("keeper_fund"), slab.toBytes()],
|
|
4071
|
+
const idxBuf2 = new Uint8Array(2);
|
|
4072
|
+
new DataView(idxBuf2.buffer).setUint16(0, lpIdx, true);
|
|
4073
|
+
return PublicKey6.findProgramAddressSync(
|
|
4074
|
+
[textEncoder.encode("lp"), slab.toBytes(), idxBuf2],
|
|
2782
4075
|
programId
|
|
2783
4076
|
);
|
|
2784
4077
|
}
|
|
2785
|
-
var PUMPSWAP_PROGRAM_ID = new
|
|
4078
|
+
var PUMPSWAP_PROGRAM_ID = new PublicKey6(
|
|
2786
4079
|
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"
|
|
2787
4080
|
);
|
|
2788
|
-
var RAYDIUM_CLMM_PROGRAM_ID = new
|
|
4081
|
+
var RAYDIUM_CLMM_PROGRAM_ID = new PublicKey6(
|
|
2789
4082
|
"CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"
|
|
2790
4083
|
);
|
|
2791
|
-
var METEORA_DLMM_PROGRAM_ID = new
|
|
4084
|
+
var METEORA_DLMM_PROGRAM_ID = new PublicKey6(
|
|
2792
4085
|
"LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
|
|
2793
4086
|
);
|
|
2794
|
-
var PYTH_PUSH_ORACLE_PROGRAM_ID = new
|
|
4087
|
+
var PYTH_PUSH_ORACLE_PROGRAM_ID = new PublicKey6(
|
|
2795
4088
|
"pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT"
|
|
2796
4089
|
);
|
|
2797
4090
|
var CREATOR_LOCK_SEED = "creator_lock";
|
|
2798
4091
|
function deriveCreatorLockPda(programId, slab) {
|
|
2799
|
-
return
|
|
4092
|
+
return PublicKey6.findProgramAddressSync(
|
|
2800
4093
|
[textEncoder.encode(CREATOR_LOCK_SEED), slab.toBytes()],
|
|
2801
4094
|
programId
|
|
2802
4095
|
);
|
|
@@ -2818,17 +4111,10 @@ function derivePythPushOraclePDA(feedIdHex) {
|
|
|
2818
4111
|
}
|
|
2819
4112
|
const feedId = new Uint8Array(32);
|
|
2820
4113
|
for (let i = 0; i < 32; i++) {
|
|
2821
|
-
|
|
2822
|
-
const byte = parseInt(hexPair, 16);
|
|
2823
|
-
if (Number.isNaN(byte)) {
|
|
2824
|
-
throw new Error(
|
|
2825
|
-
`derivePythPushOraclePDA: failed to parse hex byte at position ${i}: "${hexPair}"`
|
|
2826
|
-
);
|
|
2827
|
-
}
|
|
2828
|
-
feedId[i] = byte;
|
|
4114
|
+
feedId[i] = parseInt(normalized.substring(i * 2, i * 2 + 2), 16);
|
|
2829
4115
|
}
|
|
2830
4116
|
const shardBuf = new Uint8Array(2);
|
|
2831
|
-
return
|
|
4117
|
+
return PublicKey6.findProgramAddressSync(
|
|
2832
4118
|
[shardBuf, feedId],
|
|
2833
4119
|
PYTH_PUSH_ORACLE_PROGRAM_ID
|
|
2834
4120
|
);
|
|
@@ -2852,14 +4138,12 @@ async function fetchTokenAccount(connection, address, tokenProgramId = TOKEN_PRO
|
|
|
2852
4138
|
}
|
|
2853
4139
|
|
|
2854
4140
|
// src/solana/discovery.ts
|
|
2855
|
-
import { PublicKey as
|
|
4141
|
+
import { PublicKey as PublicKey8 } from "@solana/web3.js";
|
|
2856
4142
|
|
|
2857
4143
|
// src/solana/static-markets.ts
|
|
2858
|
-
import { PublicKey as
|
|
4144
|
+
import { PublicKey as PublicKey7 } from "@solana/web3.js";
|
|
2859
4145
|
var MAINNET_MARKETS = [
|
|
2860
|
-
|
|
2861
|
-
// To add entries:
|
|
2862
|
-
// { slabAddress: "ABC123...", symbol: "SOL-PERP", name: "SOL Perpetual" },
|
|
4146
|
+
{ slabAddress: "7psyeWRts4pRX2cyAWD1NH87bR9ugXP7pe6ARgfG79Do", symbol: "SOL-PERP", name: "SOL/USDC Perpetual" }
|
|
2863
4147
|
];
|
|
2864
4148
|
var DEVNET_MARKETS = [
|
|
2865
4149
|
// Populated from prior discoverMarkets() runs on devnet.
|
|
@@ -2893,7 +4177,7 @@ function registerStaticMarkets(network, entries) {
|
|
|
2893
4177
|
if (!entry.slabAddress) continue;
|
|
2894
4178
|
if (seen.has(entry.slabAddress)) continue;
|
|
2895
4179
|
try {
|
|
2896
|
-
new
|
|
4180
|
+
new PublicKey7(entry.slabAddress);
|
|
2897
4181
|
} catch {
|
|
2898
4182
|
console.warn(
|
|
2899
4183
|
`[registerStaticMarkets] Skipping invalid slabAddress: ${entry.slabAddress}`
|
|
@@ -2917,10 +4201,9 @@ function clearStaticMarkets(network) {
|
|
|
2917
4201
|
var ENGINE_BITMAP_OFF_V0 = 320;
|
|
2918
4202
|
var MAGIC_BYTES = new Uint8Array([84, 65, 76, 79, 67, 82, 69, 80]);
|
|
2919
4203
|
var SLAB_TIERS = {
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
large: SLAB_TIERS_V12_1["large"]
|
|
4204
|
+
small: SLAB_TIERS_V12_17["small"],
|
|
4205
|
+
medium: SLAB_TIERS_V12_17["medium"],
|
|
4206
|
+
large: SLAB_TIERS_V12_17["large"]
|
|
2924
4207
|
};
|
|
2925
4208
|
var SLAB_TIERS_V0 = {
|
|
2926
4209
|
small: { maxAccounts: 256, dataSize: 62808, label: "Small", description: "256 slots \xB7 ~0.44 SOL" },
|
|
@@ -3027,6 +4310,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3027
4310
|
fundingIndexQpbE6: readI128LE2(data, base + 112),
|
|
3028
4311
|
lastFundingSlot: readU64LE2(data, base + 128),
|
|
3029
4312
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 136),
|
|
4313
|
+
fundingRateE9: 0n,
|
|
4314
|
+
marketMode: null,
|
|
3030
4315
|
lastCrankSlot: readU64LE2(data, base + 144),
|
|
3031
4316
|
maxCrankStalenessSlots: readU64LE2(data, base + 152),
|
|
3032
4317
|
totalOpenInterest: readU128LE2(data, base + 160),
|
|
@@ -3034,6 +4319,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3034
4319
|
shortOi: 0n,
|
|
3035
4320
|
cTot: readU128LE2(data, base + 176),
|
|
3036
4321
|
pnlPosTot: readU128LE2(data, base + 192),
|
|
4322
|
+
pnlMaturedPosTot: 0n,
|
|
3037
4323
|
liqCursor: readU16LE2(data, base + 208),
|
|
3038
4324
|
gcCursor: readU16LE2(data, base + 210),
|
|
3039
4325
|
lastSweepStartSlot: readU64LE2(data, base + 216),
|
|
@@ -3051,6 +4337,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3051
4337
|
lastBreakerSlot: 0n,
|
|
3052
4338
|
markPriceE6: 0n,
|
|
3053
4339
|
// V0 engine has no mark_price field
|
|
4340
|
+
oraclePriceE6: 0n,
|
|
4341
|
+
fLongNum: 0n,
|
|
4342
|
+
fShortNum: 0n,
|
|
4343
|
+
negPnlAccountCount: 0n,
|
|
4344
|
+
fundPxLast: 0n,
|
|
4345
|
+
resolvedKLongTerminalDelta: 0n,
|
|
4346
|
+
resolvedKShortTerminalDelta: 0n,
|
|
4347
|
+
resolvedLivePrice: 0n,
|
|
3054
4348
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3055
4349
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3056
4350
|
};
|
|
@@ -3069,6 +4363,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3069
4363
|
fundingIndexQpbE6: readI128LE2(data, base + 360),
|
|
3070
4364
|
lastFundingSlot: readU64LE2(data, base + 376),
|
|
3071
4365
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 384),
|
|
4366
|
+
fundingRateE9: 0n,
|
|
4367
|
+
marketMode: null,
|
|
3072
4368
|
lastCrankSlot: readU64LE2(data, base + 392),
|
|
3073
4369
|
maxCrankStalenessSlots: readU64LE2(data, base + 400),
|
|
3074
4370
|
totalOpenInterest: readU128LE2(data, base + 408),
|
|
@@ -3078,6 +4374,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3078
4374
|
// V2 has no short_oi
|
|
3079
4375
|
cTot: readU128LE2(data, base + 424),
|
|
3080
4376
|
pnlPosTot: readU128LE2(data, base + 440),
|
|
4377
|
+
pnlMaturedPosTot: 0n,
|
|
3081
4378
|
liqCursor: readU16LE2(data, base + 456),
|
|
3082
4379
|
gcCursor: readU16LE2(data, base + 458),
|
|
3083
4380
|
lastSweepStartSlot: readU64LE2(data, base + 464),
|
|
@@ -3096,6 +4393,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3096
4393
|
lastBreakerSlot: 0n,
|
|
3097
4394
|
markPriceE6: 0n,
|
|
3098
4395
|
// V2 has no mark_price
|
|
4396
|
+
oraclePriceE6: 0n,
|
|
4397
|
+
fLongNum: 0n,
|
|
4398
|
+
fShortNum: 0n,
|
|
4399
|
+
negPnlAccountCount: 0n,
|
|
4400
|
+
fundPxLast: 0n,
|
|
4401
|
+
resolvedKLongTerminalDelta: 0n,
|
|
4402
|
+
resolvedKShortTerminalDelta: 0n,
|
|
4403
|
+
resolvedLivePrice: 0n,
|
|
3099
4404
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3100
4405
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3101
4406
|
};
|
|
@@ -3115,6 +4420,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3115
4420
|
fundingIndexQpbE6: readI128LE2(data, base + l.engineFundingIndexOff),
|
|
3116
4421
|
lastFundingSlot: readU64LE2(data, base + l.engineLastFundingSlotOff),
|
|
3117
4422
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + l.engineFundingRateBpsOff),
|
|
4423
|
+
fundingRateE9: 0n,
|
|
4424
|
+
marketMode: null,
|
|
3118
4425
|
lastCrankSlot: readU64LE2(data, base + l.engineLastCrankSlotOff),
|
|
3119
4426
|
maxCrankStalenessSlots: readU64LE2(data, base + l.engineMaxCrankStalenessOff),
|
|
3120
4427
|
totalOpenInterest: readU128LE2(data, base + l.engineTotalOiOff),
|
|
@@ -3122,6 +4429,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3122
4429
|
shortOi: l.engineShortOiOff >= 0 ? readU128LE2(data, base + l.engineShortOiOff) : 0n,
|
|
3123
4430
|
cTot: readU128LE2(data, base + l.engineCTotOff),
|
|
3124
4431
|
pnlPosTot: readU128LE2(data, base + l.enginePnlPosTotOff),
|
|
4432
|
+
pnlMaturedPosTot: 0n,
|
|
3125
4433
|
liqCursor: readU16LE2(data, base + l.engineLiqCursorOff),
|
|
3126
4434
|
gcCursor: readU16LE2(data, base + l.engineGcCursorOff),
|
|
3127
4435
|
lastSweepStartSlot: readU64LE2(data, base + l.engineLastSweepStartOff),
|
|
@@ -3138,6 +4446,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3138
4446
|
emergencyStartSlot: l.engineEmergencyStartSlotOff >= 0 ? readU64LE2(data, base + l.engineEmergencyStartSlotOff) : 0n,
|
|
3139
4447
|
lastBreakerSlot: l.engineLastBreakerSlotOff >= 0 ? readU64LE2(data, base + l.engineLastBreakerSlotOff) : 0n,
|
|
3140
4448
|
markPriceE6: l.engineMarkPriceOff >= 0 ? readU64LE2(data, base + l.engineMarkPriceOff) : 0n,
|
|
4449
|
+
oraclePriceE6: 0n,
|
|
4450
|
+
fLongNum: 0n,
|
|
4451
|
+
fShortNum: 0n,
|
|
4452
|
+
negPnlAccountCount: 0n,
|
|
4453
|
+
fundPxLast: 0n,
|
|
4454
|
+
resolvedKLongTerminalDelta: 0n,
|
|
4455
|
+
resolvedKShortTerminalDelta: 0n,
|
|
4456
|
+
resolvedLivePrice: 0n,
|
|
3141
4457
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3142
4458
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3143
4459
|
};
|
|
@@ -3155,6 +4471,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3155
4471
|
fundingIndexQpbE6: readI128LE2(data, base + 368),
|
|
3156
4472
|
lastFundingSlot: readU64LE2(data, base + 384),
|
|
3157
4473
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 392),
|
|
4474
|
+
fundingRateE9: 0n,
|
|
4475
|
+
marketMode: null,
|
|
3158
4476
|
lastCrankSlot: readU64LE2(data, base + 424),
|
|
3159
4477
|
maxCrankStalenessSlots: readU64LE2(data, base + 408),
|
|
3160
4478
|
totalOpenInterest: readU128LE2(data, base + 416),
|
|
@@ -3162,6 +4480,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3162
4480
|
shortOi: readU128LE2(data, base + 448),
|
|
3163
4481
|
cTot: readU128LE2(data, base + 464),
|
|
3164
4482
|
pnlPosTot: readU128LE2(data, base + 480),
|
|
4483
|
+
pnlMaturedPosTot: 0n,
|
|
3165
4484
|
liqCursor: readU16LE2(data, base + 496),
|
|
3166
4485
|
gcCursor: readU16LE2(data, base + 498),
|
|
3167
4486
|
lastSweepStartSlot: readU64LE2(data, base + 504),
|
|
@@ -3179,6 +4498,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3179
4498
|
lastBreakerSlot: readU64LE2(data, base + 624),
|
|
3180
4499
|
markPriceE6: readU64LE2(data, base + 400),
|
|
3181
4500
|
// PERC-1094: was 392
|
|
4501
|
+
oraclePriceE6: 0n,
|
|
4502
|
+
fLongNum: 0n,
|
|
4503
|
+
fShortNum: 0n,
|
|
4504
|
+
negPnlAccountCount: 0n,
|
|
4505
|
+
fundPxLast: 0n,
|
|
4506
|
+
resolvedKLongTerminalDelta: 0n,
|
|
4507
|
+
resolvedKShortTerminalDelta: 0n,
|
|
4508
|
+
resolvedLivePrice: 0n,
|
|
3182
4509
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3183
4510
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3184
4511
|
};
|
|
@@ -3200,12 +4527,19 @@ async function discoverMarkets(connection, programId, options = {}) {
|
|
|
3200
4527
|
} = options;
|
|
3201
4528
|
const ALL_TIERS = [
|
|
3202
4529
|
...Object.values(SLAB_TIERS),
|
|
4530
|
+
// v12.17 (default)
|
|
4531
|
+
...Object.values(SLAB_TIERS_V12_15),
|
|
4532
|
+
// v12.15
|
|
4533
|
+
...Object.values(SLAB_TIERS_V12_1),
|
|
4534
|
+
// v12.1
|
|
3203
4535
|
...Object.values(SLAB_TIERS_V0),
|
|
3204
4536
|
...Object.values(SLAB_TIERS_V1D),
|
|
3205
4537
|
...Object.values(SLAB_TIERS_V1D_LEGACY),
|
|
3206
4538
|
...Object.values(SLAB_TIERS_V2),
|
|
3207
4539
|
...Object.values(SLAB_TIERS_V1M),
|
|
3208
|
-
...Object.values(
|
|
4540
|
+
...Object.values(SLAB_TIERS_V1M2),
|
|
4541
|
+
...Object.values(SLAB_TIERS_V_ADL),
|
|
4542
|
+
...Object.values(SLAB_TIERS_V_SETDEXPOOL)
|
|
3209
4543
|
];
|
|
3210
4544
|
let rawAccounts = [];
|
|
3211
4545
|
async function fetchTierWithRetry(tier) {
|
|
@@ -3503,7 +4837,7 @@ async function discoverMarketsViaApi(connection, programId, apiBaseUrl, options
|
|
|
3503
4837
|
for (const entry of apiMarkets) {
|
|
3504
4838
|
if (!entry.slab_address || typeof entry.slab_address !== "string") continue;
|
|
3505
4839
|
try {
|
|
3506
|
-
addresses.push(new
|
|
4840
|
+
addresses.push(new PublicKey8(entry.slab_address));
|
|
3507
4841
|
} catch {
|
|
3508
4842
|
console.warn(
|
|
3509
4843
|
`[discoverMarketsViaApi] Skipping invalid slab address: ${entry.slab_address}`
|
|
@@ -3525,7 +4859,7 @@ async function discoverMarketsViaStaticBundle(connection, programId, entries, op
|
|
|
3525
4859
|
for (const entry of entries) {
|
|
3526
4860
|
if (!entry.slabAddress || typeof entry.slabAddress !== "string") continue;
|
|
3527
4861
|
try {
|
|
3528
|
-
addresses.push(new
|
|
4862
|
+
addresses.push(new PublicKey8(entry.slabAddress));
|
|
3529
4863
|
} catch {
|
|
3530
4864
|
console.warn(
|
|
3531
4865
|
`[discoverMarketsViaStaticBundle] Skipping invalid slab address: ${entry.slabAddress}`
|
|
@@ -3543,7 +4877,7 @@ async function discoverMarketsViaStaticBundle(connection, programId, entries, op
|
|
|
3543
4877
|
}
|
|
3544
4878
|
|
|
3545
4879
|
// src/solana/dex-oracle.ts
|
|
3546
|
-
import { PublicKey as
|
|
4880
|
+
import { PublicKey as PublicKey9 } from "@solana/web3.js";
|
|
3547
4881
|
function detectDexType(ownerProgramId) {
|
|
3548
4882
|
if (ownerProgramId.equals(PUMPSWAP_PROGRAM_ID)) return "pumpswap";
|
|
3549
4883
|
if (ownerProgramId.equals(RAYDIUM_CLMM_PROGRAM_ID)) return "raydium-clmm";
|
|
@@ -3579,10 +4913,10 @@ function parsePumpSwapPool(poolAddress, data) {
|
|
|
3579
4913
|
return {
|
|
3580
4914
|
dexType: "pumpswap",
|
|
3581
4915
|
poolAddress,
|
|
3582
|
-
baseMint: new
|
|
3583
|
-
quoteMint: new
|
|
3584
|
-
baseVault: new
|
|
3585
|
-
quoteVault: new
|
|
4916
|
+
baseMint: new PublicKey9(data.slice(35, 67)),
|
|
4917
|
+
quoteMint: new PublicKey9(data.slice(67, 99)),
|
|
4918
|
+
baseVault: new PublicKey9(data.slice(131, 163)),
|
|
4919
|
+
quoteVault: new PublicKey9(data.slice(163, 195))
|
|
3586
4920
|
};
|
|
3587
4921
|
}
|
|
3588
4922
|
var SPL_TOKEN_AMOUNT_MIN_LEN = 72;
|
|
@@ -3608,8 +4942,8 @@ function parseRaydiumClmmPool(poolAddress, data) {
|
|
|
3608
4942
|
return {
|
|
3609
4943
|
dexType: "raydium-clmm",
|
|
3610
4944
|
poolAddress,
|
|
3611
|
-
baseMint: new
|
|
3612
|
-
quoteMint: new
|
|
4945
|
+
baseMint: new PublicKey9(data.slice(73, 105)),
|
|
4946
|
+
quoteMint: new PublicKey9(data.slice(105, 137))
|
|
3613
4947
|
};
|
|
3614
4948
|
}
|
|
3615
4949
|
var MAX_TOKEN_DECIMALS = 24;
|
|
@@ -3627,7 +4961,9 @@ function computeRaydiumClmmPriceE6(data) {
|
|
|
3627
4961
|
}
|
|
3628
4962
|
const sqrtPriceX64 = readU128LE3(dv3, 253);
|
|
3629
4963
|
if (sqrtPriceX64 === 0n) return 0n;
|
|
3630
|
-
const
|
|
4964
|
+
const scaledSqrt = sqrtPriceX64 * 1000000n;
|
|
4965
|
+
const term = scaledSqrt >> 64n;
|
|
4966
|
+
const priceE6Raw = term * sqrtPriceX64 >> 64n;
|
|
3631
4967
|
const decimalDiff = 6 + decimals0 - decimals1;
|
|
3632
4968
|
const adjustedDiff = decimalDiff - 6;
|
|
3633
4969
|
if (adjustedDiff >= 0) {
|
|
@@ -3646,8 +4982,8 @@ function parseMeteoraPool(poolAddress, data) {
|
|
|
3646
4982
|
return {
|
|
3647
4983
|
dexType: "meteora-dlmm",
|
|
3648
4984
|
poolAddress,
|
|
3649
|
-
baseMint: new
|
|
3650
|
-
quoteMint: new
|
|
4985
|
+
baseMint: new PublicKey9(data.slice(81, 113)),
|
|
4986
|
+
quoteMint: new PublicKey9(data.slice(113, 145))
|
|
3651
4987
|
};
|
|
3652
4988
|
}
|
|
3653
4989
|
var MAX_BIN_STEP = 1e4;
|
|
@@ -3668,26 +5004,13 @@ function computeMeteoraDlmmPriceE6(data) {
|
|
|
3668
5004
|
`Meteora DLMM: |activeId| ${Math.abs(activeId)} exceeds max ${MAX_ACTIVE_ID_ABS}`
|
|
3669
5005
|
);
|
|
3670
5006
|
}
|
|
3671
|
-
const MAX_ABS_BIN_ID = 5e5;
|
|
3672
|
-
if (activeId > MAX_ABS_BIN_ID || activeId < -MAX_ABS_BIN_ID) {
|
|
3673
|
-
throw new Error(
|
|
3674
|
-
`Meteora DLMM: activeId ${activeId} exceeds safe range (\xB1${MAX_ABS_BIN_ID})`
|
|
3675
|
-
);
|
|
3676
|
-
}
|
|
3677
5007
|
const SCALE = 1000000000000000000n;
|
|
3678
5008
|
const base = SCALE + BigInt(binStep) * SCALE / 10000n;
|
|
3679
5009
|
const isNeg = activeId < 0;
|
|
3680
5010
|
let exp = isNeg ? BigInt(-activeId) : BigInt(activeId);
|
|
3681
5011
|
let result = SCALE;
|
|
3682
5012
|
let b = base;
|
|
3683
|
-
let iterations = 0;
|
|
3684
|
-
const MAX_ITERATIONS = 25;
|
|
3685
5013
|
while (exp > 0n) {
|
|
3686
|
-
if (iterations++ >= MAX_ITERATIONS) {
|
|
3687
|
-
throw new Error(
|
|
3688
|
-
`Meteora DLMM: exponentiation loop exceeded ${MAX_ITERATIONS} iterations (activeId=${activeId})`
|
|
3689
|
-
);
|
|
3690
|
-
}
|
|
3691
5014
|
if (exp & 1n) {
|
|
3692
5015
|
result = result * b / SCALE;
|
|
3693
5016
|
}
|
|
@@ -3718,7 +5041,6 @@ function readU128LE3(dv3, offset) {
|
|
|
3718
5041
|
var CHAINLINK_MIN_SIZE = 224;
|
|
3719
5042
|
var MAX_DECIMALS = 18;
|
|
3720
5043
|
var CHAINLINK_DECIMALS_OFFSET = 138;
|
|
3721
|
-
var CHAINLINK_TIMESTAMP_OFFSET = 168;
|
|
3722
5044
|
var CHAINLINK_ANSWER_OFFSET = 216;
|
|
3723
5045
|
function readU82(data, off) {
|
|
3724
5046
|
return data[off];
|
|
@@ -3726,7 +5048,7 @@ function readU82(data, off) {
|
|
|
3726
5048
|
function readBigInt64LE(data, off) {
|
|
3727
5049
|
return new DataView(data.buffer, data.byteOffset, data.byteLength).getBigInt64(off, true);
|
|
3728
5050
|
}
|
|
3729
|
-
function parseChainlinkPrice(data
|
|
5051
|
+
function parseChainlinkPrice(data) {
|
|
3730
5052
|
if (data.length < CHAINLINK_MIN_SIZE) {
|
|
3731
5053
|
throw new Error(
|
|
3732
5054
|
`Oracle account data too small: ${data.length} bytes (need at least ${CHAINLINK_MIN_SIZE})`
|
|
@@ -3744,18 +5066,7 @@ function parseChainlinkPrice(data, options) {
|
|
|
3744
5066
|
`Oracle price is non-positive: ${price}`
|
|
3745
5067
|
);
|
|
3746
5068
|
}
|
|
3747
|
-
|
|
3748
|
-
const updatedAt = Number(updatedAtBig);
|
|
3749
|
-
if (options?.maxStalenessSeconds !== void 0 && updatedAt > 0) {
|
|
3750
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
3751
|
-
const age = now - updatedAt;
|
|
3752
|
-
if (age > options.maxStalenessSeconds) {
|
|
3753
|
-
throw new Error(
|
|
3754
|
-
`Oracle price is stale: last updated ${age}s ago (max ${options.maxStalenessSeconds}s)`
|
|
3755
|
-
);
|
|
3756
|
-
}
|
|
3757
|
-
}
|
|
3758
|
-
return { price, decimals, updatedAt: updatedAt > 0 ? updatedAt : void 0 };
|
|
5069
|
+
return { price, decimals };
|
|
3759
5070
|
}
|
|
3760
5071
|
function isValidChainlinkOracle(data) {
|
|
3761
5072
|
try {
|
|
@@ -3767,19 +5078,15 @@ function isValidChainlinkOracle(data) {
|
|
|
3767
5078
|
}
|
|
3768
5079
|
|
|
3769
5080
|
// src/solana/token-program.ts
|
|
3770
|
-
import { PublicKey as
|
|
5081
|
+
import { PublicKey as PublicKey10 } from "@solana/web3.js";
|
|
3771
5082
|
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
|
|
3772
|
-
var TOKEN_2022_PROGRAM_ID = new
|
|
5083
|
+
var TOKEN_2022_PROGRAM_ID = new PublicKey10(
|
|
3773
5084
|
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
3774
5085
|
);
|
|
3775
5086
|
async function detectTokenProgram(connection, mint) {
|
|
3776
5087
|
const info = await connection.getAccountInfo(mint);
|
|
3777
5088
|
if (!info) throw new Error(`Mint account not found: ${mint.toBase58()}`);
|
|
3778
|
-
|
|
3779
|
-
if (info.owner.equals(TOKEN_2022_PROGRAM_ID)) return TOKEN_2022_PROGRAM_ID;
|
|
3780
|
-
throw new Error(
|
|
3781
|
-
`Mint ${mint.toBase58()} is owned by ${info.owner.toBase58()}, which is neither TOKEN_PROGRAM_ID nor TOKEN_2022_PROGRAM_ID`
|
|
3782
|
-
);
|
|
5089
|
+
return info.owner;
|
|
3783
5090
|
}
|
|
3784
5091
|
function isToken2022(tokenProgramId) {
|
|
3785
5092
|
return tokenProgramId.equals(TOKEN_2022_PROGRAM_ID);
|
|
@@ -3789,70 +5096,8 @@ function isStandardToken(tokenProgramId) {
|
|
|
3789
5096
|
}
|
|
3790
5097
|
|
|
3791
5098
|
// src/solana/stake.ts
|
|
3792
|
-
import { PublicKey as
|
|
5099
|
+
import { PublicKey as PublicKey11, SystemProgram as SystemProgram2, SYSVAR_RENT_PUBKEY as SYSVAR_RENT_PUBKEY2, SYSVAR_CLOCK_PUBKEY as SYSVAR_CLOCK_PUBKEY2 } from "@solana/web3.js";
|
|
3793
5100
|
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4 } from "@solana/spl-token";
|
|
3794
|
-
|
|
3795
|
-
// src/config/program-ids.ts
|
|
3796
|
-
import { PublicKey as PublicKey9 } from "@solana/web3.js";
|
|
3797
|
-
function safeEnv(key) {
|
|
3798
|
-
try {
|
|
3799
|
-
return typeof process !== "undefined" && process?.env ? process.env[key] : void 0;
|
|
3800
|
-
} catch {
|
|
3801
|
-
return void 0;
|
|
3802
|
-
}
|
|
3803
|
-
}
|
|
3804
|
-
var PROGRAM_IDS = {
|
|
3805
|
-
devnet: {
|
|
3806
|
-
percolator: "FxfD37s1AZTeWfFQps9Zpebi2dNQ9QSSDtfMKdbsfKrD",
|
|
3807
|
-
matcher: "GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k"
|
|
3808
|
-
},
|
|
3809
|
-
mainnet: {
|
|
3810
|
-
percolator: "ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv",
|
|
3811
|
-
matcher: "DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX"
|
|
3812
|
-
}
|
|
3813
|
-
};
|
|
3814
|
-
function getProgramId(network) {
|
|
3815
|
-
if (!network) {
|
|
3816
|
-
const override = safeEnv("PROGRAM_ID");
|
|
3817
|
-
if (override) {
|
|
3818
|
-
console.warn(
|
|
3819
|
-
`[percolator-sdk] PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3820
|
-
);
|
|
3821
|
-
return new PublicKey9(override);
|
|
3822
|
-
}
|
|
3823
|
-
}
|
|
3824
|
-
const detectedNetwork = getCurrentNetwork();
|
|
3825
|
-
const targetNetwork = network ?? detectedNetwork;
|
|
3826
|
-
const programId = PROGRAM_IDS[targetNetwork].percolator;
|
|
3827
|
-
return new PublicKey9(programId);
|
|
3828
|
-
}
|
|
3829
|
-
function getMatcherProgramId(network) {
|
|
3830
|
-
if (!network) {
|
|
3831
|
-
const override = safeEnv("MATCHER_PROGRAM_ID");
|
|
3832
|
-
if (override) {
|
|
3833
|
-
console.warn(
|
|
3834
|
-
`[percolator-sdk] MATCHER_PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3835
|
-
);
|
|
3836
|
-
return new PublicKey9(override);
|
|
3837
|
-
}
|
|
3838
|
-
}
|
|
3839
|
-
const detectedNetwork = getCurrentNetwork();
|
|
3840
|
-
const targetNetwork = network ?? detectedNetwork;
|
|
3841
|
-
const programId = PROGRAM_IDS[targetNetwork].matcher;
|
|
3842
|
-
if (!programId) {
|
|
3843
|
-
throw new Error(`Matcher program not deployed on ${targetNetwork}`);
|
|
3844
|
-
}
|
|
3845
|
-
return new PublicKey9(programId);
|
|
3846
|
-
}
|
|
3847
|
-
function getCurrentNetwork() {
|
|
3848
|
-
const network = safeEnv("NETWORK")?.toLowerCase();
|
|
3849
|
-
if (network === "mainnet" || network === "mainnet-beta") {
|
|
3850
|
-
return "mainnet";
|
|
3851
|
-
}
|
|
3852
|
-
return "devnet";
|
|
3853
|
-
}
|
|
3854
|
-
|
|
3855
|
-
// src/solana/stake.ts
|
|
3856
5101
|
var STAKE_PROGRAM_IDS = {
|
|
3857
5102
|
devnet: "6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k",
|
|
3858
5103
|
mainnet: "DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F"
|
|
@@ -3863,11 +5108,14 @@ function getStakeProgramId(network) {
|
|
|
3863
5108
|
console.warn(
|
|
3864
5109
|
`[percolator-sdk] STAKE_PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3865
5110
|
);
|
|
3866
|
-
return new
|
|
5111
|
+
return new PublicKey11(override);
|
|
3867
5112
|
}
|
|
3868
5113
|
const detectedNetwork = network ?? (() => {
|
|
3869
5114
|
const n = safeEnv("NEXT_PUBLIC_DEFAULT_NETWORK")?.toLowerCase() ?? safeEnv("NETWORK")?.toLowerCase() ?? "";
|
|
3870
|
-
|
|
5115
|
+
if (n === "mainnet" || n === "mainnet-beta") return "mainnet";
|
|
5116
|
+
if (n === "devnet") return "devnet";
|
|
5117
|
+
if (typeof window !== "undefined") return "mainnet";
|
|
5118
|
+
return "devnet";
|
|
3871
5119
|
})();
|
|
3872
5120
|
const id = STAKE_PROGRAM_IDS[detectedNetwork];
|
|
3873
5121
|
if (!id) {
|
|
@@ -3875,21 +5123,30 @@ function getStakeProgramId(network) {
|
|
|
3875
5123
|
`Stake program not deployed on ${detectedNetwork}. Set STAKE_PROGRAM_ID env var or wait for DevOps to deploy and update STAKE_PROGRAM_IDS.mainnet.`
|
|
3876
5124
|
);
|
|
3877
5125
|
}
|
|
3878
|
-
return new
|
|
5126
|
+
return new PublicKey11(id);
|
|
3879
5127
|
}
|
|
3880
|
-
var STAKE_PROGRAM_ID = new
|
|
5128
|
+
var STAKE_PROGRAM_ID = new PublicKey11(STAKE_PROGRAM_IDS.devnet);
|
|
3881
5129
|
var STAKE_IX = {
|
|
3882
5130
|
InitPool: 0,
|
|
3883
5131
|
Deposit: 1,
|
|
3884
5132
|
Withdraw: 2,
|
|
3885
5133
|
FlushToInsurance: 3,
|
|
3886
5134
|
UpdateConfig: 4,
|
|
5135
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3887
5136
|
TransferAdmin: 5,
|
|
5137
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3888
5138
|
AdminSetOracleAuthority: 6,
|
|
5139
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3889
5140
|
AdminSetRiskThreshold: 7,
|
|
5141
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3890
5142
|
AdminSetMaintenanceFee: 8,
|
|
5143
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3891
5144
|
AdminResolveMarket: 9,
|
|
5145
|
+
/** Current on-chain tag 10: transfer withdrawn insurance back into the pool vault. */
|
|
5146
|
+
ReturnInsurance: 10,
|
|
5147
|
+
/** @deprecated Legacy alias for ReturnInsurance. */
|
|
3892
5148
|
AdminWithdrawInsurance: 10,
|
|
5149
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3893
5150
|
AdminSetInsurancePolicy: 11,
|
|
3894
5151
|
/** PERC-272: Accrue trading fees to LP vault */
|
|
3895
5152
|
AccrueFees: 12,
|
|
@@ -3900,24 +5157,26 @@ var STAKE_IX = {
|
|
|
3900
5157
|
/** PERC-303: Enable/configure senior-junior LP tranches */
|
|
3901
5158
|
AdminSetTrancheConfig: 15,
|
|
3902
5159
|
/** PERC-303: Deposit into junior (first-loss) tranche */
|
|
3903
|
-
DepositJunior: 16
|
|
5160
|
+
DepositJunior: 16,
|
|
5161
|
+
/** Mark the pool as resolved after the wrapper market has been resolved directly. */
|
|
5162
|
+
SetMarketResolved: 18
|
|
3904
5163
|
};
|
|
3905
|
-
var
|
|
5164
|
+
var TEXT2 = new TextEncoder();
|
|
3906
5165
|
function deriveStakePool(slab, programId) {
|
|
3907
|
-
return
|
|
3908
|
-
[
|
|
5166
|
+
return PublicKey11.findProgramAddressSync(
|
|
5167
|
+
[TEXT2.encode("stake_pool"), slab.toBytes()],
|
|
3909
5168
|
programId ?? getStakeProgramId()
|
|
3910
5169
|
);
|
|
3911
5170
|
}
|
|
3912
5171
|
function deriveStakeVaultAuth(pool, programId) {
|
|
3913
|
-
return
|
|
3914
|
-
[
|
|
5172
|
+
return PublicKey11.findProgramAddressSync(
|
|
5173
|
+
[TEXT2.encode("vault_auth"), pool.toBytes()],
|
|
3915
5174
|
programId ?? getStakeProgramId()
|
|
3916
5175
|
);
|
|
3917
5176
|
}
|
|
3918
5177
|
function deriveDepositPda(pool, user, programId) {
|
|
3919
|
-
return
|
|
3920
|
-
[
|
|
5178
|
+
return PublicKey11.findProgramAddressSync(
|
|
5179
|
+
[TEXT2.encode("stake_deposit"), pool.toBytes(), user.toBytes()],
|
|
3921
5180
|
programId ?? getStakeProgramId()
|
|
3922
5181
|
);
|
|
3923
5182
|
}
|
|
@@ -3938,9 +5197,6 @@ function readU16LE3(data, off) {
|
|
|
3938
5197
|
);
|
|
3939
5198
|
}
|
|
3940
5199
|
function u64Le(v) {
|
|
3941
|
-
if (typeof v === "number" && !Number.isSafeInteger(v)) {
|
|
3942
|
-
throw new Error(`u64Le: number ${v} exceeds Number.MAX_SAFE_INTEGER \u2014 use BigInt`);
|
|
3943
|
-
}
|
|
3944
5200
|
const big = BigInt(v);
|
|
3945
5201
|
if (big < 0n) throw new Error(`u64Le: value must be non-negative, got ${big}`);
|
|
3946
5202
|
if (big > 0xFFFFFFFFFFFFFFFFn) throw new Error(`u64Le: value exceeds u64 max`);
|
|
@@ -3948,21 +5204,8 @@ function u64Le(v) {
|
|
|
3948
5204
|
new DataView(arr.buffer).setBigUint64(0, big, true);
|
|
3949
5205
|
return arr;
|
|
3950
5206
|
}
|
|
3951
|
-
function u128Le(v) {
|
|
3952
|
-
if (typeof v === "number" && !Number.isSafeInteger(v)) {
|
|
3953
|
-
throw new Error(`u128Le: number ${v} exceeds Number.MAX_SAFE_INTEGER \u2014 use BigInt`);
|
|
3954
|
-
}
|
|
3955
|
-
const big = BigInt(v);
|
|
3956
|
-
if (big < 0n) throw new Error(`u128Le: value must be non-negative, got ${big}`);
|
|
3957
|
-
if (big > (1n << 128n) - 1n) throw new Error(`u128Le: value exceeds u128 max`);
|
|
3958
|
-
const arr = new Uint8Array(16);
|
|
3959
|
-
const view = new DataView(arr.buffer);
|
|
3960
|
-
view.setBigUint64(0, big & 0xFFFFFFFFFFFFFFFFn, true);
|
|
3961
|
-
view.setBigUint64(8, big >> 64n, true);
|
|
3962
|
-
return arr;
|
|
3963
|
-
}
|
|
3964
5207
|
function u16Le(v) {
|
|
3965
|
-
if (
|
|
5208
|
+
if (v < 0 || v > 65535) throw new Error(`u16Le: value out of u16 range (0..65535), got ${v}`);
|
|
3966
5209
|
const arr = new Uint8Array(2);
|
|
3967
5210
|
new DataView(arr.buffer).setUint16(0, v, true);
|
|
3968
5211
|
return arr;
|
|
@@ -3992,36 +5235,38 @@ function encodeStakeUpdateConfig(newCooldownSlots, newDepositCap) {
|
|
|
3992
5235
|
u64Le(newDepositCap ?? 0n)
|
|
3993
5236
|
);
|
|
3994
5237
|
}
|
|
5238
|
+
function removedStakeInstruction(name, tag) {
|
|
5239
|
+
throw new Error(
|
|
5240
|
+
`${name} (stake tag ${tag}) was removed on-chain in percolator-stake v3 and must not be sent.`
|
|
5241
|
+
);
|
|
5242
|
+
}
|
|
3995
5243
|
function encodeStakeTransferAdmin() {
|
|
3996
|
-
return
|
|
5244
|
+
return removedStakeInstruction("encodeStakeTransferAdmin", STAKE_IX.TransferAdmin);
|
|
3997
5245
|
}
|
|
3998
5246
|
function encodeStakeAdminSetOracleAuthority(newAuthority) {
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
newAuthority.toBytes()
|
|
4002
|
-
);
|
|
5247
|
+
void newAuthority;
|
|
5248
|
+
return removedStakeInstruction("encodeStakeAdminSetOracleAuthority", STAKE_IX.AdminSetOracleAuthority);
|
|
4003
5249
|
}
|
|
4004
5250
|
function encodeStakeAdminSetRiskThreshold(newThreshold) {
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
u128Le(newThreshold)
|
|
4008
|
-
);
|
|
5251
|
+
void newThreshold;
|
|
5252
|
+
return removedStakeInstruction("encodeStakeAdminSetRiskThreshold", STAKE_IX.AdminSetRiskThreshold);
|
|
4009
5253
|
}
|
|
4010
5254
|
function encodeStakeAdminSetMaintenanceFee(newFee) {
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
u128Le(newFee)
|
|
4014
|
-
);
|
|
5255
|
+
void newFee;
|
|
5256
|
+
return removedStakeInstruction("encodeStakeAdminSetMaintenanceFee", STAKE_IX.AdminSetMaintenanceFee);
|
|
4015
5257
|
}
|
|
4016
5258
|
function encodeStakeAdminResolveMarket() {
|
|
4017
|
-
return
|
|
5259
|
+
return removedStakeInstruction("encodeStakeAdminResolveMarket", STAKE_IX.AdminResolveMarket);
|
|
4018
5260
|
}
|
|
4019
|
-
function
|
|
5261
|
+
function encodeStakeReturnInsurance(amount) {
|
|
4020
5262
|
return concatBytes(
|
|
4021
|
-
new Uint8Array([STAKE_IX.
|
|
5263
|
+
new Uint8Array([STAKE_IX.ReturnInsurance]),
|
|
4022
5264
|
u64Le(amount)
|
|
4023
5265
|
);
|
|
4024
5266
|
}
|
|
5267
|
+
function encodeStakeAdminWithdrawInsurance(amount) {
|
|
5268
|
+
return encodeStakeReturnInsurance(amount);
|
|
5269
|
+
}
|
|
4025
5270
|
function encodeStakeAccrueFees() {
|
|
4026
5271
|
return new Uint8Array([STAKE_IX.AccrueFees]);
|
|
4027
5272
|
}
|
|
@@ -4048,14 +5293,15 @@ function encodeStakeAdminSetTrancheConfig(juniorFeeMultBps) {
|
|
|
4048
5293
|
function encodeStakeDepositJunior(amount) {
|
|
4049
5294
|
return concatBytes(new Uint8Array([STAKE_IX.DepositJunior]), u64Le(amount));
|
|
4050
5295
|
}
|
|
5296
|
+
function encodeStakeSetMarketResolved() {
|
|
5297
|
+
return new Uint8Array([STAKE_IX.SetMarketResolved]);
|
|
5298
|
+
}
|
|
4051
5299
|
function encodeStakeAdminSetInsurancePolicy(authority, minWithdrawBase, maxWithdrawBps, cooldownSlots) {
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
u64Le(cooldownSlots)
|
|
4058
|
-
);
|
|
5300
|
+
void authority;
|
|
5301
|
+
void minWithdrawBase;
|
|
5302
|
+
void maxWithdrawBps;
|
|
5303
|
+
void cooldownSlots;
|
|
5304
|
+
return removedStakeInstruction("encodeStakeAdminSetInsurancePolicy", STAKE_IX.AdminSetInsurancePolicy);
|
|
4059
5305
|
}
|
|
4060
5306
|
var STAKE_POOL_SIZE = 352;
|
|
4061
5307
|
function decodeStakePool(data) {
|
|
@@ -4073,15 +5319,15 @@ function decodeStakePool(data) {
|
|
|
4073
5319
|
const adminTransferred = bytes[off] === 1;
|
|
4074
5320
|
off += 1;
|
|
4075
5321
|
off += 4;
|
|
4076
|
-
const slab = new
|
|
5322
|
+
const slab = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4077
5323
|
off += 32;
|
|
4078
|
-
const admin = new
|
|
5324
|
+
const admin = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4079
5325
|
off += 32;
|
|
4080
|
-
const collateralMint = new
|
|
5326
|
+
const collateralMint = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4081
5327
|
off += 32;
|
|
4082
|
-
const lpMint = new
|
|
5328
|
+
const lpMint = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4083
5329
|
off += 32;
|
|
4084
|
-
const vault = new
|
|
5330
|
+
const vault = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4085
5331
|
off += 32;
|
|
4086
5332
|
const totalDeposited = readU64LE4(bytes, off);
|
|
4087
5333
|
off += 8;
|
|
@@ -4097,7 +5343,7 @@ function decodeStakePool(data) {
|
|
|
4097
5343
|
off += 8;
|
|
4098
5344
|
const totalWithdrawn = readU64LE4(bytes, off);
|
|
4099
5345
|
off += 8;
|
|
4100
|
-
const percolatorProgram = new
|
|
5346
|
+
const percolatorProgram = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4101
5347
|
off += 32;
|
|
4102
5348
|
const totalFeesEarned = readU64LE4(bytes, off);
|
|
4103
5349
|
off += 8;
|
|
@@ -4109,11 +5355,11 @@ function decodeStakePool(data) {
|
|
|
4109
5355
|
off += 1;
|
|
4110
5356
|
off += 7;
|
|
4111
5357
|
const reservedStart = off;
|
|
4112
|
-
const
|
|
4113
|
-
const
|
|
4114
|
-
const
|
|
4115
|
-
const epochHighWaterTvl =
|
|
4116
|
-
const
|
|
5358
|
+
const marketResolved = bytes[reservedStart + 9] === 1;
|
|
5359
|
+
const hwmEnabled = bytes[reservedStart + 10] === 1;
|
|
5360
|
+
const hwmFloorBps = readU16LE3(bytes, reservedStart + 11);
|
|
5361
|
+
const epochHighWaterTvl = readU64LE4(bytes, reservedStart + 16);
|
|
5362
|
+
const hwmLastEpoch = readU64LE4(bytes, reservedStart + 24);
|
|
4117
5363
|
const trancheEnabled = bytes[reservedStart + 32] === 1;
|
|
4118
5364
|
const juniorBalance = readU64LE4(bytes, reservedStart + 33);
|
|
4119
5365
|
const juniorTotalLp = readU64LE4(bytes, reservedStart + 41);
|
|
@@ -4123,6 +5369,7 @@ function decodeStakePool(data) {
|
|
|
4123
5369
|
bump,
|
|
4124
5370
|
vaultAuthorityBump,
|
|
4125
5371
|
adminTransferred,
|
|
5372
|
+
marketResolved,
|
|
4126
5373
|
slab,
|
|
4127
5374
|
admin,
|
|
4128
5375
|
collateralMint,
|
|
@@ -4143,12 +5390,27 @@ function decodeStakePool(data) {
|
|
|
4143
5390
|
hwmEnabled,
|
|
4144
5391
|
epochHighWaterTvl,
|
|
4145
5392
|
hwmFloorBps,
|
|
5393
|
+
hwmLastEpoch,
|
|
4146
5394
|
trancheEnabled,
|
|
4147
5395
|
juniorBalance,
|
|
4148
5396
|
juniorTotalLp,
|
|
4149
5397
|
juniorFeeMultBps
|
|
4150
5398
|
};
|
|
4151
5399
|
}
|
|
5400
|
+
var STAKE_DEPOSIT_SIZE = 152;
|
|
5401
|
+
function decodeDepositPda(data) {
|
|
5402
|
+
if (data.length < STAKE_DEPOSIT_SIZE) {
|
|
5403
|
+
throw new Error(`StakeDeposit data too short: ${data.length} < ${STAKE_DEPOSIT_SIZE}`);
|
|
5404
|
+
}
|
|
5405
|
+
return {
|
|
5406
|
+
isInitialized: data[0] === 1,
|
|
5407
|
+
bump: data[1],
|
|
5408
|
+
pool: new PublicKey11(data.subarray(8, 40)),
|
|
5409
|
+
user: new PublicKey11(data.subarray(40, 72)),
|
|
5410
|
+
lastDepositSlot: readU64LE4(data, 72),
|
|
5411
|
+
lpAmount: readU64LE4(data, 80)
|
|
5412
|
+
};
|
|
5413
|
+
}
|
|
4152
5414
|
function initPoolAccounts(a) {
|
|
4153
5415
|
return [
|
|
4154
5416
|
{ pubkey: a.admin, isSigner: true, isWritable: true },
|
|
@@ -4217,9 +5479,7 @@ function computePnlPct(pnl, capital) {
|
|
|
4217
5479
|
}
|
|
4218
5480
|
function isAdlTriggered(slabData) {
|
|
4219
5481
|
const layout = detectSlabLayout(slabData.length);
|
|
4220
|
-
if (!layout)
|
|
4221
|
-
return false;
|
|
4222
|
-
}
|
|
5482
|
+
if (!layout) return false;
|
|
4223
5483
|
try {
|
|
4224
5484
|
const engine = parseEngine(slabData);
|
|
4225
5485
|
if (engine.pnlPosTot === 0n) return false;
|
|
@@ -4262,14 +5522,6 @@ function rankAdlPositions(slabData) {
|
|
|
4262
5522
|
if (account.kind !== 0 /* User */) continue;
|
|
4263
5523
|
if (account.positionSize === 0n) continue;
|
|
4264
5524
|
const side = account.positionSize > 0n ? "long" : "short";
|
|
4265
|
-
if (side === "long" && account.positionSize <= 0n) {
|
|
4266
|
-
console.warn(`[fetchAdlRankedPositions] account idx=${idx}: side=long but positionSize=${account.positionSize}`);
|
|
4267
|
-
continue;
|
|
4268
|
-
}
|
|
4269
|
-
if (side === "short" && account.positionSize >= 0n) {
|
|
4270
|
-
console.warn(`[fetchAdlRankedPositions] account idx=${idx}: side=short but positionSize=${account.positionSize}`);
|
|
4271
|
-
continue;
|
|
4272
|
-
}
|
|
4273
5525
|
const pnlPct = computePnlPct(account.pnl, account.capital);
|
|
4274
5526
|
positions.push({
|
|
4275
5527
|
idx,
|
|
@@ -4302,8 +5554,7 @@ function buildAdlInstruction(caller, slab, oracle, programId, targetIdx, backupO
|
|
|
4302
5554
|
`buildAdlInstruction: targetIdx must be a non-negative integer, got ${targetIdx}`
|
|
4303
5555
|
);
|
|
4304
5556
|
}
|
|
4305
|
-
const
|
|
4306
|
-
const data = Buffer.from(dataBytes);
|
|
5557
|
+
const data = Buffer.from(encodeExecuteAdl({ targetIdx }));
|
|
4307
5558
|
const keys = [
|
|
4308
5559
|
{ pubkey: caller, isSigner: true, isWritable: false },
|
|
4309
5560
|
{ pubkey: slab, isSigner: false, isWritable: true },
|
|
@@ -4343,11 +5594,7 @@ function parseAdlEvent(logs) {
|
|
|
4343
5594
|
}
|
|
4344
5595
|
if (tag !== ADL_EVENT_TAG) continue;
|
|
4345
5596
|
try {
|
|
4346
|
-
const
|
|
4347
|
-
if (targetIdxBig < 0n || targetIdxBig > 65535n) {
|
|
4348
|
-
continue;
|
|
4349
|
-
}
|
|
4350
|
-
const targetIdx = Number(targetIdxBig);
|
|
5597
|
+
const targetIdx = Number(BigInt(match[2]));
|
|
4351
5598
|
const price = BigInt(match[3]);
|
|
4352
5599
|
const closedLo = BigInt(match[4]);
|
|
4353
5600
|
const closedHi = BigInt(match[5]);
|
|
@@ -4375,22 +5622,6 @@ async function fetchAdlRankings(apiBase, slab, fetchFn = fetch) {
|
|
|
4375
5622
|
);
|
|
4376
5623
|
}
|
|
4377
5624
|
const json = await res.json();
|
|
4378
|
-
if (typeof json !== "object" || json === null) {
|
|
4379
|
-
throw new Error("fetchAdlRankings: API returned non-object response");
|
|
4380
|
-
}
|
|
4381
|
-
const obj = json;
|
|
4382
|
-
if (!Array.isArray(obj.rankings)) {
|
|
4383
|
-
throw new Error("fetchAdlRankings: API response missing rankings array");
|
|
4384
|
-
}
|
|
4385
|
-
for (const entry of obj.rankings) {
|
|
4386
|
-
if (typeof entry !== "object" || entry === null) {
|
|
4387
|
-
throw new Error("fetchAdlRankings: invalid ranking entry (not an object)");
|
|
4388
|
-
}
|
|
4389
|
-
const r = entry;
|
|
4390
|
-
if (typeof r.idx !== "number" || !Number.isInteger(r.idx) || r.idx < 0) {
|
|
4391
|
-
throw new Error(`fetchAdlRankings: invalid ranking idx: ${r.idx}`);
|
|
4392
|
-
}
|
|
4393
|
-
}
|
|
4394
5625
|
return json;
|
|
4395
5626
|
}
|
|
4396
5627
|
|
|
@@ -4908,11 +6139,11 @@ function formatResult(result, jsonMode) {
|
|
|
4908
6139
|
}
|
|
4909
6140
|
|
|
4910
6141
|
// src/runtime/lighthouse.ts
|
|
4911
|
-
import { PublicKey as
|
|
4912
|
-
var LIGHTHOUSE_PROGRAM_ID = new
|
|
6142
|
+
import { PublicKey as PublicKey14, Transaction as Transaction2 } from "@solana/web3.js";
|
|
6143
|
+
var LIGHTHOUSE_PROGRAM_ID = new PublicKey14(
|
|
4913
6144
|
"L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95"
|
|
4914
6145
|
);
|
|
4915
|
-
var
|
|
6146
|
+
var LIGHTHOUSE_PROGRAM_ID_STR = "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95";
|
|
4916
6147
|
var LIGHTHOUSE_CONSTRAINT_ADDRESS = 6400;
|
|
4917
6148
|
var LIGHTHOUSE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
4918
6149
|
6e3,
|
|
@@ -4958,7 +6189,7 @@ function isLighthouseInstruction(ix) {
|
|
|
4958
6189
|
function isLighthouseError(error) {
|
|
4959
6190
|
const msg = extractErrorMessage(error);
|
|
4960
6191
|
if (!msg) return false;
|
|
4961
|
-
if (msg.includes(
|
|
6192
|
+
if (msg.includes(LIGHTHOUSE_PROGRAM_ID_STR)) return true;
|
|
4962
6193
|
if (/custom\s+program\s+error:\s*0x1900\b/i.test(msg)) return true;
|
|
4963
6194
|
if (/"Custom"\s*:\s*6400\b/.test(msg) && /InstructionError/i.test(msg)) return true;
|
|
4964
6195
|
return false;
|
|
@@ -4968,18 +6199,18 @@ function isLighthouseFailureInLogs(logs) {
|
|
|
4968
6199
|
let insideLighthouse = false;
|
|
4969
6200
|
for (const line of logs) {
|
|
4970
6201
|
if (typeof line !== "string") continue;
|
|
4971
|
-
if (line.includes(`Program ${
|
|
6202
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} invoke`)) {
|
|
4972
6203
|
insideLighthouse = true;
|
|
4973
6204
|
continue;
|
|
4974
6205
|
}
|
|
4975
|
-
if (line.includes(`Program ${
|
|
6206
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} success`)) {
|
|
4976
6207
|
insideLighthouse = false;
|
|
4977
6208
|
continue;
|
|
4978
6209
|
}
|
|
4979
6210
|
if (insideLighthouse && /failed/i.test(line)) {
|
|
4980
6211
|
return true;
|
|
4981
6212
|
}
|
|
4982
|
-
if (line.includes(`Program ${
|
|
6213
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} failed`)) {
|
|
4983
6214
|
return true;
|
|
4984
6215
|
}
|
|
4985
6216
|
}
|
|
@@ -5064,10 +6295,16 @@ function computeLiqPrice(entryPrice, capital, positionSize, maintenanceMarginBps
|
|
|
5064
6295
|
function computePreTradeLiqPrice(oracleE6, margin, posSize, maintBps, feeBps, direction) {
|
|
5065
6296
|
if (oracleE6 === 0n || margin === 0n || posSize === 0n) return 0n;
|
|
5066
6297
|
const absPos = posSize < 0n ? -posSize : posSize;
|
|
5067
|
-
const fee = absPos * feeBps / 10000n;
|
|
5068
|
-
const effectiveCapital = margin > fee ? margin - fee : 0n;
|
|
5069
6298
|
const signedPos = direction === "long" ? absPos : -absPos;
|
|
5070
|
-
|
|
6299
|
+
const feeAdjust = oracleE6 * feeBps / 10000n;
|
|
6300
|
+
let adjustedEntry;
|
|
6301
|
+
if (direction === "long") {
|
|
6302
|
+
adjustedEntry = oracleE6 + feeAdjust;
|
|
6303
|
+
} else {
|
|
6304
|
+
const shortEntry = oracleE6 - feeAdjust;
|
|
6305
|
+
adjustedEntry = shortEntry > 0n ? shortEntry : 1n;
|
|
6306
|
+
}
|
|
6307
|
+
return computeLiqPrice(adjustedEntry, margin, signedPos, maintBps);
|
|
5071
6308
|
}
|
|
5072
6309
|
function computeTradingFee(notional, tradingFeeBps) {
|
|
5073
6310
|
return notional * tradingFeeBps / 10000n;
|
|
@@ -5087,20 +6324,9 @@ function computeFeeSplit(totalFee, config) {
|
|
|
5087
6324
|
if (config.lpBps === 0n && config.protocolBps === 0n && config.creatorBps === 0n) {
|
|
5088
6325
|
return [totalFee, 0n, 0n];
|
|
5089
6326
|
}
|
|
5090
|
-
const totalBps = config.lpBps + config.protocolBps + config.creatorBps;
|
|
5091
|
-
if (totalBps !== 10000n) {
|
|
5092
|
-
throw new Error(
|
|
5093
|
-
`Fee split must equal exactly 10000 bps (100%): lpBps=${config.lpBps} + protocolBps=${config.protocolBps} + creatorBps=${config.creatorBps} = ${totalBps}`
|
|
5094
|
-
);
|
|
5095
|
-
}
|
|
5096
6327
|
const lp = totalFee * config.lpBps / 10000n;
|
|
5097
6328
|
const protocol = totalFee * config.protocolBps / 10000n;
|
|
5098
6329
|
const creator = totalFee - lp - protocol;
|
|
5099
|
-
if (creator < 0n) {
|
|
5100
|
-
throw new Error(
|
|
5101
|
-
`Internal error: creator fee is negative (${creator}). This should not happen if lpBps + protocolBps + creatorBps === 10000.`
|
|
5102
|
-
);
|
|
5103
|
-
}
|
|
5104
6330
|
return [lp, protocol, creator];
|
|
5105
6331
|
}
|
|
5106
6332
|
function computePnlPercent(pnlTokens, capital) {
|
|
@@ -5115,17 +6341,10 @@ function computePnlPercent(pnlTokens, capital) {
|
|
|
5115
6341
|
}
|
|
5116
6342
|
function computeEstimatedEntryPrice(oracleE6, tradingFeeBps, direction) {
|
|
5117
6343
|
if (oracleE6 === 0n) return 0n;
|
|
5118
|
-
if (tradingFeeBps < 0n) {
|
|
5119
|
-
throw new Error(`computeEstimatedEntryPrice: tradingFeeBps must be non-negative, got ${tradingFeeBps}`);
|
|
5120
|
-
}
|
|
5121
6344
|
const feeImpact = oracleE6 * tradingFeeBps / 10000n;
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
`computeEstimatedEntryPrice: result ${result} is non-positive (tradingFeeBps=${tradingFeeBps} too high for oracle=${oracleE6})`
|
|
5126
|
-
);
|
|
5127
|
-
}
|
|
5128
|
-
return result;
|
|
6345
|
+
if (direction === "long") return oracleE6 + feeImpact;
|
|
6346
|
+
const shortEntry = oracleE6 - feeImpact;
|
|
6347
|
+
return shortEntry > 0n ? shortEntry : 1n;
|
|
5129
6348
|
}
|
|
5130
6349
|
var MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
5131
6350
|
var MIN_SAFE_BIGINT = BigInt(-Number.MAX_SAFE_INTEGER);
|
|
@@ -5146,12 +6365,7 @@ function computeMaxLeverage(initialMarginBps) {
|
|
|
5146
6365
|
if (initialMarginBps <= 0n) {
|
|
5147
6366
|
throw new Error("computeMaxLeverage: initialMarginBps must be positive");
|
|
5148
6367
|
}
|
|
5149
|
-
|
|
5150
|
-
return Number(scaledResult) / 1e6;
|
|
5151
|
-
}
|
|
5152
|
-
function computeMaxWithdrawable(capital, pnl, reservedPnl) {
|
|
5153
|
-
const maturedPnl = pnl - reservedPnl;
|
|
5154
|
-
return capital + (maturedPnl > 0n ? maturedPnl : 0n);
|
|
6368
|
+
return Number(10000n / initialMarginBps);
|
|
5155
6369
|
}
|
|
5156
6370
|
|
|
5157
6371
|
// src/math/warmup.ts
|
|
@@ -5163,9 +6377,6 @@ function computeWarmupUnlockedCapital(totalCapital, currentSlot, warmupStartSlot
|
|
|
5163
6377
|
return totalCapital * elapsed / warmupPeriodSlots;
|
|
5164
6378
|
}
|
|
5165
6379
|
function computeWarmupLeverageCap(initialMarginBps, totalCapital, currentSlot, warmupStartSlot, warmupPeriodSlots) {
|
|
5166
|
-
if (initialMarginBps <= 0n) {
|
|
5167
|
-
throw new Error("computeWarmupLeverageCap: initialMarginBps must be positive");
|
|
5168
|
-
}
|
|
5169
6380
|
const maxLev = computeMaxLeverage(initialMarginBps);
|
|
5170
6381
|
if (warmupPeriodSlots === 0n || warmupStartSlot === 0n) return maxLev;
|
|
5171
6382
|
if (totalCapital <= 0n) return 1;
|
|
@@ -5176,14 +6387,7 @@ function computeWarmupLeverageCap(initialMarginBps, totalCapital, currentSlot, w
|
|
|
5176
6387
|
warmupPeriodSlots
|
|
5177
6388
|
);
|
|
5178
6389
|
if (unlocked <= 0n) return 1;
|
|
5179
|
-
const
|
|
5180
|
-
if (scaledResult > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5181
|
-
console.warn(
|
|
5182
|
-
`[computeWarmupLeverageCap] Warning: effective leverage ${scaledResult} exceeds MAX_SAFE_INTEGER, returning MAX_SAFE_INTEGER as a safety bound`
|
|
5183
|
-
);
|
|
5184
|
-
return Number.MAX_SAFE_INTEGER;
|
|
5185
|
-
}
|
|
5186
|
-
const effectiveLev = Number(scaledResult);
|
|
6390
|
+
const effectiveLev = Number(BigInt(maxLev) * unlocked / totalCapital);
|
|
5187
6391
|
return Math.max(1, effectiveLev);
|
|
5188
6392
|
}
|
|
5189
6393
|
function computeWarmupMaxPositionSize(initialMarginBps, totalCapital, currentSlot, warmupStartSlot, warmupPeriodSlots) {
|
|
@@ -5196,41 +6400,10 @@ function computeWarmupMaxPositionSize(initialMarginBps, totalCapital, currentSlo
|
|
|
5196
6400
|
);
|
|
5197
6401
|
return unlocked * BigInt(maxLev);
|
|
5198
6402
|
}
|
|
5199
|
-
function computeWarmupProgress(currentSlot, warmupStartedAtSlot, warmupPeriodSlots, pnl, reservedPnl) {
|
|
5200
|
-
if (warmupPeriodSlots === 0n || warmupStartedAtSlot === 0n) {
|
|
5201
|
-
return {
|
|
5202
|
-
maturedPnl: pnl > 0n ? pnl : 0n,
|
|
5203
|
-
reservedPnl: 0n,
|
|
5204
|
-
progressBps: 10000n,
|
|
5205
|
-
// 100%
|
|
5206
|
-
slotsRemaining: 0n
|
|
5207
|
-
};
|
|
5208
|
-
}
|
|
5209
|
-
const elapsed = currentSlot >= warmupStartedAtSlot ? currentSlot - warmupStartedAtSlot : 0n;
|
|
5210
|
-
if (elapsed >= warmupPeriodSlots) {
|
|
5211
|
-
return {
|
|
5212
|
-
maturedPnl: pnl > 0n ? pnl : 0n,
|
|
5213
|
-
reservedPnl: 0n,
|
|
5214
|
-
progressBps: 10000n,
|
|
5215
|
-
// 100%
|
|
5216
|
-
slotsRemaining: 0n
|
|
5217
|
-
};
|
|
5218
|
-
}
|
|
5219
|
-
const progressBps = elapsed * 10000n / warmupPeriodSlots;
|
|
5220
|
-
const slotsRemaining = warmupPeriodSlots - elapsed;
|
|
5221
|
-
const maturedPnl = pnl > 0n ? pnl * progressBps / 10000n : 0n;
|
|
5222
|
-
const locked = reservedPnl > 0n ? reservedPnl : 0n;
|
|
5223
|
-
return {
|
|
5224
|
-
maturedPnl,
|
|
5225
|
-
reservedPnl: locked,
|
|
5226
|
-
progressBps,
|
|
5227
|
-
slotsRemaining
|
|
5228
|
-
};
|
|
5229
|
-
}
|
|
5230
6403
|
|
|
5231
6404
|
// src/validation.ts
|
|
5232
|
-
import { PublicKey as
|
|
5233
|
-
var
|
|
6405
|
+
import { PublicKey as PublicKey15 } from "@solana/web3.js";
|
|
6406
|
+
var U16_MAX2 = 65535;
|
|
5234
6407
|
var U64_MAX = BigInt("18446744073709551615");
|
|
5235
6408
|
var I64_MIN = BigInt("-9223372036854775808");
|
|
5236
6409
|
var I64_MAX = BigInt("9223372036854775807");
|
|
@@ -5259,7 +6432,7 @@ var ValidationError = class extends Error {
|
|
|
5259
6432
|
};
|
|
5260
6433
|
function validatePublicKey(value, field) {
|
|
5261
6434
|
try {
|
|
5262
|
-
return new
|
|
6435
|
+
return new PublicKey15(value);
|
|
5263
6436
|
} catch {
|
|
5264
6437
|
throw new ValidationError(
|
|
5265
6438
|
field,
|
|
@@ -5270,26 +6443,24 @@ function validatePublicKey(value, field) {
|
|
|
5270
6443
|
function validateIndex(value, field) {
|
|
5271
6444
|
const t = requireDecimalUIntString(value, field);
|
|
5272
6445
|
const bi = BigInt(t);
|
|
5273
|
-
if (bi > BigInt(
|
|
6446
|
+
if (bi > BigInt(U16_MAX2)) {
|
|
5274
6447
|
throw new ValidationError(
|
|
5275
6448
|
field,
|
|
5276
|
-
`must be <= ${
|
|
6449
|
+
`must be <= ${U16_MAX2} (u16 max), got ${t}`
|
|
5277
6450
|
);
|
|
5278
6451
|
}
|
|
5279
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5280
|
-
throw new ValidationError(field, `internal error: u16 value exceeds MAX_SAFE_INTEGER`);
|
|
5281
|
-
}
|
|
5282
6452
|
return Number(bi);
|
|
5283
6453
|
}
|
|
5284
6454
|
function validateAmount(value, field) {
|
|
5285
|
-
|
|
5286
|
-
|
|
6455
|
+
let num;
|
|
6456
|
+
try {
|
|
6457
|
+
num = BigInt(value);
|
|
6458
|
+
} catch {
|
|
5287
6459
|
throw new ValidationError(
|
|
5288
6460
|
field,
|
|
5289
|
-
`"${value}" is not a valid
|
|
6461
|
+
`"${value}" is not a valid number. Use decimal digits only.`
|
|
5290
6462
|
);
|
|
5291
6463
|
}
|
|
5292
|
-
const num = BigInt(t);
|
|
5293
6464
|
if (num < 0n) {
|
|
5294
6465
|
throw new ValidationError(field, `must be non-negative, got ${num}`);
|
|
5295
6466
|
}
|
|
@@ -5302,14 +6473,15 @@ function validateAmount(value, field) {
|
|
|
5302
6473
|
return num;
|
|
5303
6474
|
}
|
|
5304
6475
|
function validateU128(value, field) {
|
|
5305
|
-
|
|
5306
|
-
|
|
6476
|
+
let num;
|
|
6477
|
+
try {
|
|
6478
|
+
num = BigInt(value);
|
|
6479
|
+
} catch {
|
|
5307
6480
|
throw new ValidationError(
|
|
5308
6481
|
field,
|
|
5309
|
-
`"${value}" is not a valid
|
|
6482
|
+
`"${value}" is not a valid number. Use decimal digits only.`
|
|
5310
6483
|
);
|
|
5311
6484
|
}
|
|
5312
|
-
const num = BigInt(t);
|
|
5313
6485
|
if (num < 0n) {
|
|
5314
6486
|
throw new ValidationError(field, `must be non-negative, got ${num}`);
|
|
5315
6487
|
}
|
|
@@ -5322,14 +6494,15 @@ function validateU128(value, field) {
|
|
|
5322
6494
|
return num;
|
|
5323
6495
|
}
|
|
5324
6496
|
function validateI64(value, field) {
|
|
5325
|
-
|
|
5326
|
-
|
|
6497
|
+
let num;
|
|
6498
|
+
try {
|
|
6499
|
+
num = BigInt(value);
|
|
6500
|
+
} catch {
|
|
5327
6501
|
throw new ValidationError(
|
|
5328
6502
|
field,
|
|
5329
|
-
`"${value}" is not a valid
|
|
6503
|
+
`"${value}" is not a valid number. Use decimal digits only, with optional leading minus.`
|
|
5330
6504
|
);
|
|
5331
6505
|
}
|
|
5332
|
-
const num = BigInt(t);
|
|
5333
6506
|
if (num < I64_MIN) {
|
|
5334
6507
|
throw new ValidationError(
|
|
5335
6508
|
field,
|
|
@@ -5345,14 +6518,15 @@ function validateI64(value, field) {
|
|
|
5345
6518
|
return num;
|
|
5346
6519
|
}
|
|
5347
6520
|
function validateI128(value, field) {
|
|
5348
|
-
|
|
5349
|
-
|
|
6521
|
+
let num;
|
|
6522
|
+
try {
|
|
6523
|
+
num = BigInt(value);
|
|
6524
|
+
} catch {
|
|
5350
6525
|
throw new ValidationError(
|
|
5351
6526
|
field,
|
|
5352
|
-
`"${value}" is not a valid
|
|
6527
|
+
`"${value}" is not a valid number. Use decimal digits only, with optional leading minus.`
|
|
5353
6528
|
);
|
|
5354
6529
|
}
|
|
5355
|
-
const num = BigInt(t);
|
|
5356
6530
|
if (num < I128_MIN) {
|
|
5357
6531
|
throw new ValidationError(
|
|
5358
6532
|
field,
|
|
@@ -5376,9 +6550,6 @@ function validateBps(value, field) {
|
|
|
5376
6550
|
`must be <= 10000 (100%), got ${t}`
|
|
5377
6551
|
);
|
|
5378
6552
|
}
|
|
5379
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5380
|
-
throw new ValidationError(field, `internal error: bps value exceeds MAX_SAFE_INTEGER`);
|
|
5381
|
-
}
|
|
5382
6553
|
return Number(bi);
|
|
5383
6554
|
}
|
|
5384
6555
|
function validateU64(value, field) {
|
|
@@ -5387,15 +6558,12 @@ function validateU64(value, field) {
|
|
|
5387
6558
|
function validateU16(value, field) {
|
|
5388
6559
|
const t = requireDecimalUIntString(value, field);
|
|
5389
6560
|
const bi = BigInt(t);
|
|
5390
|
-
if (bi > BigInt(
|
|
6561
|
+
if (bi > BigInt(U16_MAX2)) {
|
|
5391
6562
|
throw new ValidationError(
|
|
5392
6563
|
field,
|
|
5393
|
-
`must be <= ${
|
|
6564
|
+
`must be <= ${U16_MAX2} (u16 max), got ${t}`
|
|
5394
6565
|
);
|
|
5395
6566
|
}
|
|
5396
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5397
|
-
throw new ValidationError(field, `internal error: u16 value exceeds MAX_SAFE_INTEGER`);
|
|
5398
|
-
}
|
|
5399
6567
|
return Number(bi);
|
|
5400
6568
|
}
|
|
5401
6569
|
|
|
@@ -5446,9 +6614,7 @@ function parseDexScreenerPairs(json) {
|
|
|
5446
6614
|
else if (liquidity > 1e4) confidence = 60;
|
|
5447
6615
|
else if (liquidity > 1e3) confidence = 45;
|
|
5448
6616
|
const priceUsd = pair.priceUsd;
|
|
5449
|
-
const
|
|
5450
|
-
if (!Number.isFinite(rawPrice) || rawPrice <= 0) continue;
|
|
5451
|
-
const price = rawPrice;
|
|
6617
|
+
const price = typeof priceUsd === "string" || typeof priceUsd === "number" ? parseFloat(String(priceUsd)) || 0 : 0;
|
|
5452
6618
|
let baseSym = "?";
|
|
5453
6619
|
let quoteSym = "?";
|
|
5454
6620
|
if (isRecord(pair.baseToken) && typeof pair.baseToken.symbol === "string") {
|
|
@@ -5479,8 +6645,8 @@ function parseJupiterMintEntry(json, mint) {
|
|
|
5479
6645
|
if (!isRecord(row)) return null;
|
|
5480
6646
|
const rawPrice = row.price;
|
|
5481
6647
|
if (rawPrice === void 0 || rawPrice === null) return null;
|
|
5482
|
-
const price = parseFloat(String(rawPrice));
|
|
5483
|
-
if (
|
|
6648
|
+
const price = parseFloat(String(rawPrice)) || 0;
|
|
6649
|
+
if (price <= 0) return null;
|
|
5484
6650
|
let mintSymbol = "?";
|
|
5485
6651
|
if (typeof row.mintSymbol === "string") mintSymbol = row.mintSymbol;
|
|
5486
6652
|
return { price, mintSymbol };
|
|
@@ -5546,17 +6712,10 @@ async function fetchDexSources(mint, signal) {
|
|
|
5546
6712
|
headers: { "User-Agent": "percolator/1.0" }
|
|
5547
6713
|
}
|
|
5548
6714
|
);
|
|
5549
|
-
if (!resp.ok)
|
|
5550
|
-
console.debug(`[fetchDexSources] HTTP ${resp.status} for mint ${mint}`);
|
|
5551
|
-
return [];
|
|
5552
|
-
}
|
|
6715
|
+
if (!resp.ok) return [];
|
|
5553
6716
|
const json = await resp.json();
|
|
5554
6717
|
return parseDexScreenerPairs(json);
|
|
5555
|
-
} catch
|
|
5556
|
-
console.warn(
|
|
5557
|
-
`[fetchDexSources] Error fetching DexScreener data for mint ${mint}:`,
|
|
5558
|
-
err instanceof Error ? err.message : String(err)
|
|
5559
|
-
);
|
|
6718
|
+
} catch {
|
|
5560
6719
|
return [];
|
|
5561
6720
|
}
|
|
5562
6721
|
}
|
|
@@ -5567,7 +6726,7 @@ function lookupPythSource(mint) {
|
|
|
5567
6726
|
type: "pyth",
|
|
5568
6727
|
address: entry.feedId,
|
|
5569
6728
|
pairLabel: `${entry.symbol} / USD (Pyth)`,
|
|
5570
|
-
liquidity:
|
|
6729
|
+
liquidity: Infinity,
|
|
5571
6730
|
// Pyth is considered deep liquidity
|
|
5572
6731
|
price: 0,
|
|
5573
6732
|
// We don't fetch live price here; caller can enrich
|
|
@@ -5584,16 +6743,10 @@ async function fetchJupiterSource(mint, signal) {
|
|
|
5584
6743
|
headers: { "User-Agent": "percolator/1.0" }
|
|
5585
6744
|
}
|
|
5586
6745
|
);
|
|
5587
|
-
if (!resp.ok)
|
|
5588
|
-
console.debug(`[fetchJupiterSource] HTTP ${resp.status} for mint ${mint}`);
|
|
5589
|
-
return null;
|
|
5590
|
-
}
|
|
6746
|
+
if (!resp.ok) return null;
|
|
5591
6747
|
const json = await resp.json();
|
|
5592
6748
|
const row = parseJupiterMintEntry(json, mint);
|
|
5593
|
-
if (!row)
|
|
5594
|
-
console.debug(`[fetchJupiterSource] No price data from Jupiter for mint ${mint}`);
|
|
5595
|
-
return null;
|
|
5596
|
-
}
|
|
6749
|
+
if (!row) return null;
|
|
5597
6750
|
return {
|
|
5598
6751
|
type: "jupiter",
|
|
5599
6752
|
address: mint,
|
|
@@ -5604,39 +6757,23 @@ async function fetchJupiterSource(mint, signal) {
|
|
|
5604
6757
|
confidence: 40
|
|
5605
6758
|
// Fallback — lower confidence
|
|
5606
6759
|
};
|
|
5607
|
-
} catch
|
|
5608
|
-
console.warn(
|
|
5609
|
-
`[fetchJupiterSource] Error fetching Jupiter data for mint ${mint}:`,
|
|
5610
|
-
err instanceof Error ? err.message : String(err)
|
|
5611
|
-
);
|
|
6760
|
+
} catch {
|
|
5612
6761
|
return null;
|
|
5613
6762
|
}
|
|
5614
6763
|
}
|
|
5615
6764
|
async function resolvePrice(mint, signal, options) {
|
|
5616
6765
|
const timeoutMs = options?.timeoutMs ?? DEFAULT_RESOLVE_TIMEOUT_MS;
|
|
5617
6766
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
5618
|
-
const
|
|
6767
|
+
const combinedSignal = signal ? combineAbortSignals([signal, timeoutSignal]) : timeoutSignal;
|
|
5619
6768
|
const [dexSources, jupiterSource] = await Promise.all([
|
|
5620
|
-
fetchDexSources(mint,
|
|
5621
|
-
fetchJupiterSource(mint,
|
|
6769
|
+
fetchDexSources(mint, combinedSignal),
|
|
6770
|
+
fetchJupiterSource(mint, combinedSignal)
|
|
5622
6771
|
]);
|
|
5623
6772
|
const pythSource = lookupPythSource(mint);
|
|
5624
6773
|
const allSources = [];
|
|
5625
6774
|
if (pythSource) {
|
|
5626
|
-
const
|
|
5627
|
-
|
|
5628
|
-
if (dexPrice > 0 && jupPrice > 0) {
|
|
5629
|
-
const mid = (dexPrice + jupPrice) / 2;
|
|
5630
|
-
const deviation = Math.abs(dexPrice - jupPrice) / mid;
|
|
5631
|
-
if (deviation > 0.5) {
|
|
5632
|
-
pythSource.price = 0;
|
|
5633
|
-
pythSource.confidence = 20;
|
|
5634
|
-
} else {
|
|
5635
|
-
pythSource.price = mid;
|
|
5636
|
-
}
|
|
5637
|
-
} else {
|
|
5638
|
-
pythSource.price = dexPrice || jupPrice || 0;
|
|
5639
|
-
}
|
|
6775
|
+
const refPrice = dexSources[0]?.price || jupiterSource?.price || 0;
|
|
6776
|
+
pythSource.price = refPrice;
|
|
5640
6777
|
allSources.push(pythSource);
|
|
5641
6778
|
}
|
|
5642
6779
|
allSources.push(...dexSources);
|
|
@@ -5652,17 +6789,29 @@ async function resolvePrice(mint, signal, options) {
|
|
|
5652
6789
|
};
|
|
5653
6790
|
}
|
|
5654
6791
|
export {
|
|
6792
|
+
ACCOUNTS_ACCEPT_ADMIN,
|
|
6793
|
+
ACCOUNTS_ADMIN_FORCE_CLOSE,
|
|
5655
6794
|
ACCOUNTS_ADVANCE_ORACLE_PHASE,
|
|
6795
|
+
ACCOUNTS_ATTEST_CROSS_MARGIN,
|
|
5656
6796
|
ACCOUNTS_AUDIT_CRANK,
|
|
5657
6797
|
ACCOUNTS_BURN_POSITION_NFT,
|
|
5658
6798
|
ACCOUNTS_CANCEL_QUEUED_WITHDRAWAL,
|
|
6799
|
+
ACCOUNTS_CHALLENGE_SETTLEMENT,
|
|
5659
6800
|
ACCOUNTS_CLAIM_QUEUED_WITHDRAWAL,
|
|
5660
6801
|
ACCOUNTS_CLEAR_PENDING_SETTLEMENT,
|
|
5661
6802
|
ACCOUNTS_CLOSE_ACCOUNT,
|
|
6803
|
+
ACCOUNTS_CLOSE_ORPHAN_SLAB,
|
|
5662
6804
|
ACCOUNTS_CLOSE_SLAB,
|
|
5663
6805
|
ACCOUNTS_CLOSE_STALE_SLABS,
|
|
6806
|
+
ACCOUNTS_CONVERT_RELEASED_PNL,
|
|
6807
|
+
ACCOUNTS_CREATE_INSURANCE_MINT,
|
|
6808
|
+
ACCOUNTS_CREATE_LP_VAULT,
|
|
5664
6809
|
ACCOUNTS_DEPOSIT_COLLATERAL,
|
|
6810
|
+
ACCOUNTS_DEPOSIT_FEE_CREDITS,
|
|
6811
|
+
ACCOUNTS_DEPOSIT_INSURANCE_LP,
|
|
6812
|
+
ACCOUNTS_DEPOSIT_LP_COLLATERAL,
|
|
5665
6813
|
ACCOUNTS_EXECUTE_ADL,
|
|
6814
|
+
ACCOUNTS_FORCE_CLOSE_RESOLVED,
|
|
5666
6815
|
ACCOUNTS_FUND_MARKET_INSURANCE,
|
|
5667
6816
|
ACCOUNTS_INIT_LP,
|
|
5668
6817
|
ACCOUNTS_INIT_MARKET,
|
|
@@ -5670,52 +6819,82 @@ export {
|
|
|
5670
6819
|
ACCOUNTS_INIT_USER,
|
|
5671
6820
|
ACCOUNTS_KEEPER_CRANK,
|
|
5672
6821
|
ACCOUNTS_LIQUIDATE_AT_ORACLE,
|
|
6822
|
+
ACCOUNTS_LP_VAULT_CRANK_FEES,
|
|
6823
|
+
ACCOUNTS_LP_VAULT_DEPOSIT,
|
|
5673
6824
|
ACCOUNTS_LP_VAULT_WITHDRAW,
|
|
5674
6825
|
ACCOUNTS_MINT_POSITION_NFT,
|
|
6826
|
+
ACCOUNTS_NFT_BURN,
|
|
6827
|
+
ACCOUNTS_NFT_EMERGENCY_BURN,
|
|
6828
|
+
ACCOUNTS_NFT_MINT,
|
|
5675
6829
|
ACCOUNTS_PAUSE_MARKET,
|
|
5676
|
-
ACCOUNTS_PUSH_ORACLE_PRICE,
|
|
5677
6830
|
ACCOUNTS_QUEUE_WITHDRAWAL,
|
|
6831
|
+
ACCOUNTS_RECLAIM_EMPTY_ACCOUNT,
|
|
5678
6832
|
ACCOUNTS_RECLAIM_SLAB_RENT,
|
|
6833
|
+
ACCOUNTS_RESCUE_ORPHAN_VAULT,
|
|
6834
|
+
ACCOUNTS_RESOLVE_DISPUTE,
|
|
5679
6835
|
ACCOUNTS_RESOLVE_MARKET,
|
|
6836
|
+
ACCOUNTS_RESOLVE_PERMISSIONLESS,
|
|
6837
|
+
ACCOUNTS_SETTLE_ACCOUNT,
|
|
6838
|
+
ACCOUNTS_SET_DEX_POOL,
|
|
6839
|
+
ACCOUNTS_SET_DISPUTE_PARAMS,
|
|
5680
6840
|
ACCOUNTS_SET_INSURANCE_ISOLATION,
|
|
6841
|
+
ACCOUNTS_SET_INSURANCE_WITHDRAW_POLICY,
|
|
6842
|
+
ACCOUNTS_SET_LP_COLLATERAL_PARAMS,
|
|
5681
6843
|
ACCOUNTS_SET_MAINTENANCE_FEE,
|
|
6844
|
+
ACCOUNTS_SET_MAX_PNL_CAP,
|
|
6845
|
+
ACCOUNTS_SET_OFFSET_PAIR,
|
|
6846
|
+
ACCOUNTS_SET_OI_CAP_MULTIPLIER,
|
|
5682
6847
|
ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK,
|
|
5683
|
-
ACCOUNTS_SET_ORACLE_AUTHORITY,
|
|
5684
6848
|
ACCOUNTS_SET_ORACLE_PRICE_CAP,
|
|
5685
6849
|
ACCOUNTS_SET_PENDING_SETTLEMENT,
|
|
5686
6850
|
ACCOUNTS_SET_RISK_THRESHOLD,
|
|
5687
6851
|
ACCOUNTS_SET_WALLET_CAP,
|
|
5688
6852
|
ACCOUNTS_TOPUP_INSURANCE,
|
|
5689
|
-
ACCOUNTS_TOPUP_KEEPER_FUND,
|
|
5690
6853
|
ACCOUNTS_TRADE_CPI,
|
|
5691
6854
|
ACCOUNTS_TRADE_NOCPI,
|
|
6855
|
+
ACCOUNTS_TRANSFER_OWNERSHIP_CPI,
|
|
5692
6856
|
ACCOUNTS_TRANSFER_POSITION_OWNERSHIP,
|
|
5693
6857
|
ACCOUNTS_UNPAUSE_MARKET,
|
|
5694
6858
|
ACCOUNTS_UPDATE_ADMIN,
|
|
6859
|
+
ACCOUNTS_UPDATE_AUTHORITY,
|
|
5695
6860
|
ACCOUNTS_UPDATE_CONFIG,
|
|
6861
|
+
ACCOUNTS_UPDATE_HYPERP_MARK,
|
|
5696
6862
|
ACCOUNTS_WITHDRAW_COLLATERAL,
|
|
5697
6863
|
ACCOUNTS_WITHDRAW_INSURANCE,
|
|
6864
|
+
ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_LIVE,
|
|
6865
|
+
ACCOUNTS_WITHDRAW_INSURANCE_LIMITED_RESOLVED,
|
|
6866
|
+
ACCOUNTS_WITHDRAW_INSURANCE_LP,
|
|
6867
|
+
ACCOUNTS_WITHDRAW_LP_COLLATERAL,
|
|
6868
|
+
AUTHORITY_KIND,
|
|
5698
6869
|
AccountKind,
|
|
5699
6870
|
CHAINLINK_ANSWER_OFFSET,
|
|
5700
6871
|
CHAINLINK_DECIMALS_OFFSET,
|
|
5701
6872
|
CHAINLINK_MIN_SIZE,
|
|
5702
|
-
CHAINLINK_TIMESTAMP_OFFSET,
|
|
5703
6873
|
CREATOR_LOCK_SEED,
|
|
6874
|
+
CTX_RETURN_OFFSET,
|
|
6875
|
+
CTX_VAMM_LEN,
|
|
5704
6876
|
CTX_VAMM_OFFSET,
|
|
5705
6877
|
DEFAULT_OI_RAMP_SLOTS,
|
|
5706
6878
|
ENGINE_MARK_PRICE_OFF,
|
|
5707
6879
|
ENGINE_OFF,
|
|
6880
|
+
INIT_CTX_LEN,
|
|
5708
6881
|
IX_TAG,
|
|
5709
6882
|
LIGHTHOUSE_CONSTRAINT_ADDRESS,
|
|
5710
6883
|
LIGHTHOUSE_ERROR_CODES,
|
|
5711
6884
|
LIGHTHOUSE_PROGRAM_ID,
|
|
5712
|
-
|
|
6885
|
+
LIGHTHOUSE_PROGRAM_ID_STR,
|
|
5713
6886
|
LIGHTHOUSE_USER_MESSAGE,
|
|
6887
|
+
LiquidationPolicyTag,
|
|
5714
6888
|
MARK_PRICE_EMA_ALPHA_E6,
|
|
5715
6889
|
MARK_PRICE_EMA_WINDOW_SLOTS,
|
|
6890
|
+
MATCHER_CALL_LEN,
|
|
6891
|
+
MATCHER_CONTEXT_LEN,
|
|
6892
|
+
MATCHER_MAGIC,
|
|
6893
|
+
MATCHER_RETURN_LEN,
|
|
5716
6894
|
MAX_DECIMALS,
|
|
5717
|
-
MAX_ORACLE_PRICE,
|
|
5718
6895
|
METEORA_DLMM_PROGRAM_ID,
|
|
6896
|
+
NFT_IX_TAG,
|
|
6897
|
+
NFT_PROGRAM_ID,
|
|
5719
6898
|
ORACLE_PHASE_GROWING,
|
|
5720
6899
|
ORACLE_PHASE_MATURE,
|
|
5721
6900
|
ORACLE_PHASE_NASCENT,
|
|
@@ -5724,6 +6903,7 @@ export {
|
|
|
5724
6903
|
PHASE1_VOLUME_MIN_SLOTS,
|
|
5725
6904
|
PHASE2_MATURITY_SLOTS,
|
|
5726
6905
|
PHASE2_VOLUME_THRESHOLD,
|
|
6906
|
+
POSITION_NFT_STATE_LEN,
|
|
5727
6907
|
PROGRAM_IDS,
|
|
5728
6908
|
PUMPSWAP_PROGRAM_ID,
|
|
5729
6909
|
PYTH_PUSH_ORACLE_PROGRAM_ID,
|
|
@@ -5733,10 +6913,13 @@ export {
|
|
|
5733
6913
|
RAYDIUM_CLMM_PROGRAM_ID,
|
|
5734
6914
|
RENOUNCE_ADMIN_CONFIRMATION,
|
|
5735
6915
|
RpcPool,
|
|
6916
|
+
SLAB_MAGIC,
|
|
5736
6917
|
SLAB_TIERS,
|
|
5737
6918
|
SLAB_TIERS_V0,
|
|
5738
6919
|
SLAB_TIERS_V1,
|
|
5739
6920
|
SLAB_TIERS_V12_1,
|
|
6921
|
+
SLAB_TIERS_V12_15,
|
|
6922
|
+
SLAB_TIERS_V12_17,
|
|
5740
6923
|
SLAB_TIERS_V1D,
|
|
5741
6924
|
SLAB_TIERS_V1D_LEGACY,
|
|
5742
6925
|
SLAB_TIERS_V1M,
|
|
@@ -5745,6 +6928,7 @@ export {
|
|
|
5745
6928
|
SLAB_TIERS_V_ADL,
|
|
5746
6929
|
SLAB_TIERS_V_ADL_DISCOVERY,
|
|
5747
6930
|
SLAB_TIERS_V_SETDEXPOOL,
|
|
6931
|
+
STAKE_DEPOSIT_SIZE,
|
|
5748
6932
|
STAKE_IX,
|
|
5749
6933
|
STAKE_POOL_SIZE,
|
|
5750
6934
|
STAKE_PROGRAM_ID,
|
|
@@ -5774,7 +6958,6 @@ export {
|
|
|
5774
6958
|
computeLiqPrice,
|
|
5775
6959
|
computeMarkPnl,
|
|
5776
6960
|
computeMaxLeverage,
|
|
5777
|
-
computeMaxWithdrawable,
|
|
5778
6961
|
computePnlPercent,
|
|
5779
6962
|
computePreTradeLiqPrice,
|
|
5780
6963
|
computeRequiredMargin,
|
|
@@ -5782,17 +6965,20 @@ export {
|
|
|
5782
6965
|
computeVammQuote,
|
|
5783
6966
|
computeWarmupLeverageCap,
|
|
5784
6967
|
computeWarmupMaxPositionSize,
|
|
5785
|
-
computeWarmupProgress,
|
|
5786
6968
|
computeWarmupUnlockedCapital,
|
|
5787
6969
|
concatBytes,
|
|
5788
6970
|
countLighthouseInstructions,
|
|
6971
|
+
decodeDepositPda,
|
|
5789
6972
|
decodeError,
|
|
5790
6973
|
decodeStakePool,
|
|
5791
6974
|
depositAccounts,
|
|
5792
6975
|
deriveCreatorLockPda,
|
|
5793
6976
|
deriveDepositPda,
|
|
5794
|
-
|
|
6977
|
+
deriveInsuranceLpMint,
|
|
5795
6978
|
deriveLpPda,
|
|
6979
|
+
deriveMintAuthority,
|
|
6980
|
+
deriveNftMint,
|
|
6981
|
+
deriveNftPda,
|
|
5796
6982
|
derivePythPriceUpdateAccount,
|
|
5797
6983
|
derivePythPushOraclePDA,
|
|
5798
6984
|
deriveStakePool,
|
|
@@ -5814,6 +7000,7 @@ export {
|
|
|
5814
7000
|
encU32,
|
|
5815
7001
|
encU64,
|
|
5816
7002
|
encU8,
|
|
7003
|
+
encodeAcceptAdmin,
|
|
5817
7004
|
encodeAdminForceClose,
|
|
5818
7005
|
encodeAdvanceEpoch,
|
|
5819
7006
|
encodeAdvanceOraclePhase,
|
|
@@ -5830,8 +7017,12 @@ export {
|
|
|
5830
7017
|
encodeCloseOrphanSlab,
|
|
5831
7018
|
encodeCloseSlab,
|
|
5832
7019
|
encodeCloseStaleSlabs,
|
|
7020
|
+
encodeConvertReleasedPnl,
|
|
7021
|
+
encodeCreateInsuranceMint,
|
|
5833
7022
|
encodeCreateLpVault,
|
|
5834
7023
|
encodeDepositCollateral,
|
|
7024
|
+
encodeDepositFeeCredits,
|
|
7025
|
+
encodeDepositInsuranceLP,
|
|
5835
7026
|
encodeDepositLpCollateral,
|
|
5836
7027
|
encodeExecuteAdl,
|
|
5837
7028
|
encodeForceCloseResolved,
|
|
@@ -5847,10 +7038,14 @@ export {
|
|
|
5847
7038
|
encodeLpVaultDeposit,
|
|
5848
7039
|
encodeLpVaultWithdraw,
|
|
5849
7040
|
encodeMintPositionNft,
|
|
7041
|
+
encodeNftBurn,
|
|
7042
|
+
encodeNftEmergencyBurn,
|
|
7043
|
+
encodeNftMint,
|
|
7044
|
+
encodeNftSettleFunding,
|
|
5850
7045
|
encodePauseMarket,
|
|
5851
|
-
encodePushOraclePrice,
|
|
5852
7046
|
encodeQueueWithdrawal,
|
|
5853
7047
|
encodeQueueWithdrawalSV,
|
|
7048
|
+
encodeReclaimEmptyAccount,
|
|
5854
7049
|
encodeReclaimSlabRent,
|
|
5855
7050
|
encodeRenounceAdmin,
|
|
5856
7051
|
encodeRescueOrphanVault,
|
|
@@ -5858,17 +7053,21 @@ export {
|
|
|
5858
7053
|
encodeResolveMarket,
|
|
5859
7054
|
encodeResolvePermissionless,
|
|
5860
7055
|
encodeSetDexPool,
|
|
7056
|
+
encodeSetDisputeParams,
|
|
5861
7057
|
encodeSetInsuranceIsolation,
|
|
5862
7058
|
encodeSetInsuranceWithdrawPolicy,
|
|
7059
|
+
encodeSetLpCollateralParams,
|
|
5863
7060
|
encodeSetMaintenanceFee,
|
|
7061
|
+
encodeSetMaxPnlCap,
|
|
5864
7062
|
encodeSetOffsetPair,
|
|
7063
|
+
encodeSetOiCapMultiplier,
|
|
5865
7064
|
encodeSetOiImbalanceHardBlock,
|
|
5866
|
-
encodeSetOracleAuthority,
|
|
5867
7065
|
encodeSetOraclePriceCap,
|
|
5868
7066
|
encodeSetPendingSettlement,
|
|
5869
7067
|
encodeSetPythOracle,
|
|
5870
7068
|
encodeSetRiskThreshold,
|
|
5871
7069
|
encodeSetWalletCap,
|
|
7070
|
+
encodeSettleAccount,
|
|
5872
7071
|
encodeSlashCreationDeposit,
|
|
5873
7072
|
encodeStakeAccrueFees,
|
|
5874
7073
|
encodeStakeAdminResolveMarket,
|
|
@@ -5884,24 +7083,28 @@ export {
|
|
|
5884
7083
|
encodeStakeFlushToInsurance,
|
|
5885
7084
|
encodeStakeInitPool,
|
|
5886
7085
|
encodeStakeInitTradingPool,
|
|
7086
|
+
encodeStakeReturnInsurance,
|
|
7087
|
+
encodeStakeSetMarketResolved,
|
|
5887
7088
|
encodeStakeTransferAdmin,
|
|
5888
7089
|
encodeStakeUpdateConfig,
|
|
5889
7090
|
encodeStakeWithdraw,
|
|
5890
7091
|
encodeTopUpInsurance,
|
|
5891
|
-
encodeTopUpKeeperFund,
|
|
5892
7092
|
encodeTradeCpi,
|
|
5893
7093
|
encodeTradeCpiV2,
|
|
5894
7094
|
encodeTradeNoCpi,
|
|
5895
7095
|
encodeTransferOwnershipCpi,
|
|
5896
7096
|
encodeTransferPositionOwnership,
|
|
5897
7097
|
encodeUnpauseMarket,
|
|
7098
|
+
encodeUnresolveMarket,
|
|
5898
7099
|
encodeUpdateAdmin,
|
|
7100
|
+
encodeUpdateAuthority,
|
|
5899
7101
|
encodeUpdateConfig,
|
|
5900
7102
|
encodeUpdateHyperpMark,
|
|
5901
7103
|
encodeUpdateMarkPrice,
|
|
5902
7104
|
encodeUpdateRiskParams,
|
|
5903
7105
|
encodeWithdrawCollateral,
|
|
5904
7106
|
encodeWithdrawInsurance,
|
|
7107
|
+
encodeWithdrawInsuranceLP,
|
|
5905
7108
|
encodeWithdrawInsuranceLimited,
|
|
5906
7109
|
encodeWithdrawLpCollateral,
|
|
5907
7110
|
fetchAdlRankedPositions,
|
|
@@ -5917,13 +7120,13 @@ export {
|
|
|
5917
7120
|
getErrorName,
|
|
5918
7121
|
getMarketsByAddress,
|
|
5919
7122
|
getMatcherProgramId,
|
|
7123
|
+
getNftProgramId,
|
|
5920
7124
|
getProgramId,
|
|
5921
7125
|
getStakeProgramId,
|
|
5922
7126
|
getStaticMarkets,
|
|
5923
7127
|
initPoolAccounts,
|
|
5924
7128
|
isAccountUsed,
|
|
5925
7129
|
isAdlTriggered,
|
|
5926
|
-
isAnchorErrorCode,
|
|
5927
7130
|
isLighthouseError,
|
|
5928
7131
|
isLighthouseFailureInLogs,
|
|
5929
7132
|
isLighthouseInstruction,
|
|
@@ -5931,6 +7134,7 @@ export {
|
|
|
5931
7134
|
isToken2022,
|
|
5932
7135
|
isValidChainlinkOracle,
|
|
5933
7136
|
maxAccountIndex,
|
|
7137
|
+
packOiCap,
|
|
5934
7138
|
parseAccount,
|
|
5935
7139
|
parseAdlEvent,
|
|
5936
7140
|
parseAllAccounts,
|
|
@@ -5941,6 +7145,7 @@ export {
|
|
|
5941
7145
|
parseErrorFromLogs,
|
|
5942
7146
|
parseHeader,
|
|
5943
7147
|
parseParams,
|
|
7148
|
+
parsePositionNftAccount,
|
|
5944
7149
|
parseUsedIndices,
|
|
5945
7150
|
rankAdlPositions,
|
|
5946
7151
|
readLastThrUpdateSlot,
|