@percolatorct/sdk 1.0.0-beta.8 → 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 +1897 -700
- 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 -13
- 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;
|
|
@@ -2449,14 +3475,6 @@ function parseConfig(data, layoutHint) {
|
|
|
2449
3475
|
off += 8;
|
|
2450
3476
|
const fundingMaxBpsPerSlot = readI64LE(data, off);
|
|
2451
3477
|
off += 8;
|
|
2452
|
-
const fundingPremiumWeightBps = readU64LE(data, off);
|
|
2453
|
-
off += 8;
|
|
2454
|
-
const fundingSettlementIntervalSlots = readU64LE(data, off);
|
|
2455
|
-
off += 8;
|
|
2456
|
-
const fundingPremiumDampeningE6 = readU64LE(data, off);
|
|
2457
|
-
off += 8;
|
|
2458
|
-
const fundingPremiumMaxBpsPerSlot = readU64LE(data, off);
|
|
2459
|
-
off += 8;
|
|
2460
3478
|
const threshFloor = readU128LE(data, off);
|
|
2461
3479
|
off += 16;
|
|
2462
3480
|
const threshRiskBps = readU64LE(data, off);
|
|
@@ -2473,7 +3491,7 @@ function parseConfig(data, layoutHint) {
|
|
|
2473
3491
|
off += 16;
|
|
2474
3492
|
const threshMinStep = readU128LE(data, off);
|
|
2475
3493
|
off += 16;
|
|
2476
|
-
const oracleAuthority = new
|
|
3494
|
+
const oracleAuthority = new PublicKey5(data.subarray(off, off + 32));
|
|
2477
3495
|
off += 32;
|
|
2478
3496
|
const authorityPriceE6 = readU64LE(data, off);
|
|
2479
3497
|
off += 8;
|
|
@@ -2526,7 +3544,7 @@ function parseConfig(data, layoutHint) {
|
|
|
2526
3544
|
if (configLen >= DEX_POOL_REL_OFF + 32 && data.length >= configOff + DEX_POOL_REL_OFF + 32) {
|
|
2527
3545
|
const dexPoolBytes = data.subarray(configOff + DEX_POOL_REL_OFF, configOff + DEX_POOL_REL_OFF + 32);
|
|
2528
3546
|
if (dexPoolBytes.some((b) => b !== 0)) {
|
|
2529
|
-
dexPool = new
|
|
3547
|
+
dexPool = new PublicKey5(dexPoolBytes);
|
|
2530
3548
|
}
|
|
2531
3549
|
}
|
|
2532
3550
|
return {
|
|
@@ -2543,10 +3561,10 @@ function parseConfig(data, layoutHint) {
|
|
|
2543
3561
|
fundingInvScaleNotionalE6,
|
|
2544
3562
|
fundingMaxPremiumBps,
|
|
2545
3563
|
fundingMaxBpsPerSlot,
|
|
2546
|
-
fundingPremiumWeightBps,
|
|
2547
|
-
fundingSettlementIntervalSlots,
|
|
2548
|
-
fundingPremiumDampeningE6,
|
|
2549
|
-
fundingPremiumMaxBpsPerSlot,
|
|
3564
|
+
fundingPremiumWeightBps: 0n,
|
|
3565
|
+
fundingSettlementIntervalSlots: 0n,
|
|
3566
|
+
fundingPremiumDampeningE6: 0n,
|
|
3567
|
+
fundingPremiumMaxBpsPerSlot: 0n,
|
|
2550
3568
|
threshFloor,
|
|
2551
3569
|
threshRiskBps,
|
|
2552
3570
|
threshUpdateIntervalSlots,
|
|
@@ -2581,26 +3599,61 @@ function parseParams(data, layoutHint) {
|
|
|
2581
3599
|
const paramsOff = layout ? layout.engineParamsOff : V0_ENGINE_PARAMS_OFF;
|
|
2582
3600
|
const paramsSize = layout ? layout.paramsSize : V0_PARAMS_SIZE;
|
|
2583
3601
|
const base = engineOff + paramsOff;
|
|
2584
|
-
|
|
2585
|
-
|
|
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}`);
|
|
2586
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;
|
|
2587
3608
|
const result = {
|
|
2588
|
-
warmupPeriodSlots: readU64LE(data, base + PARAMS_WARMUP_PERIOD_OFF),
|
|
2589
|
-
maintenanceMarginBps: readU64LE(data, base + PARAMS_MAINTENANCE_MARGIN_OFF),
|
|
2590
|
-
initialMarginBps: readU64LE(data, base + PARAMS_INITIAL_MARGIN_OFF),
|
|
2591
|
-
tradingFeeBps: readU64LE(data, base + PARAMS_TRADING_FEE_OFF),
|
|
2592
|
-
maxAccounts: readU64LE(data, base + PARAMS_MAX_ACCOUNTS_OFF),
|
|
2593
|
-
newAccountFee: readU128LE(data, base + PARAMS_NEW_ACCOUNT_FEE_OFF),
|
|
2594
|
-
// 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
|
|
2595
3616
|
riskReductionThreshold: 0n,
|
|
2596
3617
|
maintenanceFeePerSlot: 0n,
|
|
2597
3618
|
maxCrankStalenessSlots: 0n,
|
|
2598
3619
|
liquidationFeeBps: 0n,
|
|
2599
3620
|
liquidationFeeCap: 0n,
|
|
2600
3621
|
liquidationBufferBps: 0n,
|
|
2601
|
-
minLiquidationAbs: 0n
|
|
3622
|
+
minLiquidationAbs: 0n,
|
|
3623
|
+
minInitialDeposit: 0n,
|
|
3624
|
+
minNonzeroMmReq: 0n,
|
|
3625
|
+
minNonzeroImReq: 0n,
|
|
3626
|
+
insuranceFloor: 0n,
|
|
3627
|
+
hMin: 0n,
|
|
3628
|
+
hMax: 0n
|
|
2602
3629
|
};
|
|
2603
|
-
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) {
|
|
2604
3657
|
result.riskReductionThreshold = readU128LE(data, base + PARAMS_RISK_THRESHOLD_OFF);
|
|
2605
3658
|
result.maintenanceFeePerSlot = readU128LE(data, base + PARAMS_MAINTENANCE_FEE_OFF);
|
|
2606
3659
|
result.maxCrankStalenessSlots = readU64LE(data, base + PARAMS_MAX_CRANK_STALENESS_OFF);
|
|
@@ -2608,6 +3661,8 @@ function parseParams(data, layoutHint) {
|
|
|
2608
3661
|
result.liquidationFeeCap = readU128LE(data, base + PARAMS_LIQUIDATION_FEE_CAP_OFF);
|
|
2609
3662
|
result.liquidationBufferBps = readU64LE(data, base + PARAMS_LIQUIDATION_BUFFER_OFF);
|
|
2610
3663
|
result.minLiquidationAbs = readU128LE(data, base + PARAMS_MIN_LIQUIDATION_OFF);
|
|
3664
|
+
result.hMin = result.warmupPeriodSlots;
|
|
3665
|
+
result.hMax = result.warmupPeriodSlots;
|
|
2611
3666
|
}
|
|
2612
3667
|
return result;
|
|
2613
3668
|
}
|
|
@@ -2617,41 +3672,128 @@ function parseEngine(data) {
|
|
|
2617
3672
|
throw new Error(`Unrecognized slab data length: ${data.length}. Cannot determine layout version.`);
|
|
2618
3673
|
}
|
|
2619
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);
|
|
2620
3755
|
return {
|
|
2621
3756
|
vault: readU128LE(data, base),
|
|
2622
3757
|
insuranceFund: {
|
|
2623
3758
|
balance: readU128LE(data, base + layout.engineInsuranceOff),
|
|
2624
|
-
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,
|
|
2625
3761
|
isolatedBalance: layout.hasInsuranceIsolation ? readU128LE(data, base + layout.engineInsuranceIsolatedOff) : 0n,
|
|
2626
3762
|
isolationBps: layout.hasInsuranceIsolation ? readU16LE(data, base + layout.engineInsuranceIsolationBpsOff) : 0
|
|
2627
3763
|
},
|
|
2628
3764
|
currentSlot: readU64LE(data, base + layout.engineCurrentSlotOff),
|
|
2629
|
-
fundingIndexQpbE6: readI128LE(data, base + layout.engineFundingIndexOff),
|
|
2630
|
-
lastFundingSlot: readU64LE(data, base + layout.engineLastFundingSlotOff),
|
|
2631
|
-
fundingRateBpsPerSlotLast
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
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,
|
|
2635
3773
|
longOi: layout.engineLongOiOff >= 0 ? readU128LE(data, base + layout.engineLongOiOff) : 0n,
|
|
2636
3774
|
shortOi: layout.engineShortOiOff >= 0 ? readU128LE(data, base + layout.engineShortOiOff) : 0n,
|
|
2637
3775
|
cTot: readU128LE(data, base + layout.engineCTotOff),
|
|
2638
3776
|
pnlPosTot: readU128LE(data, base + layout.enginePnlPosTotOff),
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
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,
|
|
2649
3788
|
lpMaxAbs: layout.engineLpMaxAbsOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsOff) : 0n,
|
|
2650
3789
|
lpMaxAbsSweep: layout.engineLpMaxAbsSweepOff >= 0 ? readU128LE(data, base + layout.engineLpMaxAbsSweepOff) : 0n,
|
|
2651
3790
|
emergencyOiMode: layout.engineEmergencyOiModeOff >= 0 ? data[base + layout.engineEmergencyOiModeOff] !== 0 : false,
|
|
2652
3791
|
emergencyStartSlot: layout.engineEmergencyStartSlotOff >= 0 ? readU64LE(data, base + layout.engineEmergencyStartSlotOff) : 0n,
|
|
2653
3792
|
lastBreakerSlot: layout.engineLastBreakerSlotOff >= 0 ? readU64LE(data, base + layout.engineLastBreakerSlotOff) : 0n,
|
|
2654
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,
|
|
2655
3797
|
numUsedAccounts: (() => {
|
|
2656
3798
|
if (layout.postBitmap < 18) return 0;
|
|
2657
3799
|
const bw = layout.bitmapWords;
|
|
@@ -2662,7 +3804,15 @@ function parseEngine(data) {
|
|
|
2662
3804
|
const bw = layout.bitmapWords;
|
|
2663
3805
|
const numUsedOff = layout.engineBitmapOff + bw * 8;
|
|
2664
3806
|
return readU64LE(data, base + Math.ceil((numUsedOff + 2) / 8) * 8);
|
|
2665
|
-
})()
|
|
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
|
|
2666
3816
|
};
|
|
2667
3817
|
}
|
|
2668
3818
|
function parseUsedIndices(data) {
|
|
@@ -2712,17 +3862,129 @@ function parseAccount(data, idx) {
|
|
|
2712
3862
|
if (data.length < base + layout.accountSize) {
|
|
2713
3863
|
throw new Error("Slab data too short for account");
|
|
2714
3864
|
}
|
|
2715
|
-
const
|
|
2716
|
-
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
|
+
}
|
|
2717
3979
|
const warmupStartedOff = isAdl ? V_ADL_ACCT_WARMUP_STARTED_OFF : ACCT_WARMUP_STARTED_OFF;
|
|
2718
3980
|
const warmupSlopeOff = isAdl ? V_ADL_ACCT_WARMUP_SLOPE_OFF : ACCT_WARMUP_SLOPE_OFF;
|
|
2719
|
-
const positionSizeOff = isV12_1 ? V12_1_ACCT_POSITION_SIZE_OFF : isAdl ? V_ADL_ACCT_POSITION_SIZE_OFF : ACCT_POSITION_SIZE_OFF;
|
|
2720
|
-
const entryPriceOff = isV12_1 ? V12_1_ACCT_ENTRY_PRICE_OFF : isAdl ? V_ADL_ACCT_ENTRY_PRICE_OFF : ACCT_ENTRY_PRICE_OFF;
|
|
2721
|
-
const fundingIndexOff = isV12_1 ?
|
|
2722
|
-
const matcherProgOff = isV12_1 ? V12_1_ACCT_MATCHER_PROGRAM_OFF : isAdl ? V_ADL_ACCT_MATCHER_PROGRAM_OFF : ACCT_MATCHER_PROGRAM_OFF;
|
|
2723
|
-
const matcherCtxOff = isV12_1 ? V12_1_ACCT_MATCHER_CONTEXT_OFF : isAdl ? V_ADL_ACCT_MATCHER_CONTEXT_OFF : ACCT_MATCHER_CONTEXT_OFF;
|
|
2724
|
-
const feeCreditsOff = isV12_1 ? V12_1_ACCT_FEE_CREDITS_OFF : isAdl ? V_ADL_ACCT_FEE_CREDITS_OFF : ACCT_FEE_CREDITS_OFF;
|
|
2725
|
-
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;
|
|
2726
3988
|
const kindByte = readU8(data, base + ACCT_KIND_OFF);
|
|
2727
3989
|
const kind = kindByte === 1 ? 1 /* LP */ : 0 /* User */;
|
|
2728
3990
|
return {
|
|
@@ -2735,14 +3997,37 @@ function parseAccount(data, idx) {
|
|
|
2735
3997
|
warmupSlopePerStep: readU128LE(data, base + warmupSlopeOff),
|
|
2736
3998
|
positionSize: readI128LE(data, base + positionSizeOff),
|
|
2737
3999
|
entryPrice: entryPriceOff >= 0 ? readU64LE(data, base + entryPriceOff) : 0n,
|
|
2738
|
-
// V12_1:
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
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)),
|
|
2744
4005
|
feeCredits: readI128LE(data, base + feeCreditsOff),
|
|
2745
|
-
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
|
|
2746
4031
|
};
|
|
2747
4032
|
}
|
|
2748
4033
|
function parseAllAccounts(data) {
|
|
@@ -2762,14 +4047,20 @@ function parseAllAccounts(data) {
|
|
|
2762
4047
|
}
|
|
2763
4048
|
|
|
2764
4049
|
// src/solana/pda.ts
|
|
2765
|
-
import { PublicKey as
|
|
4050
|
+
import { PublicKey as PublicKey6 } from "@solana/web3.js";
|
|
2766
4051
|
var textEncoder = new TextEncoder();
|
|
2767
4052
|
function deriveVaultAuthority(programId, slab) {
|
|
2768
|
-
return
|
|
4053
|
+
return PublicKey6.findProgramAddressSync(
|
|
2769
4054
|
[textEncoder.encode("vault"), slab.toBytes()],
|
|
2770
4055
|
programId
|
|
2771
4056
|
);
|
|
2772
4057
|
}
|
|
4058
|
+
function deriveInsuranceLpMint(programId, slab) {
|
|
4059
|
+
return PublicKey6.findProgramAddressSync(
|
|
4060
|
+
[textEncoder.encode("lp_vault_mint"), slab.toBytes()],
|
|
4061
|
+
programId
|
|
4062
|
+
);
|
|
4063
|
+
}
|
|
2773
4064
|
var LP_INDEX_U16_MAX = 65535;
|
|
2774
4065
|
function deriveLpPda(programId, slab, lpIdx) {
|
|
2775
4066
|
if (typeof lpIdx !== "number" || !Number.isInteger(lpIdx) || lpIdx < 0 || lpIdx > LP_INDEX_U16_MAX) {
|
|
@@ -2777,34 +4068,28 @@ function deriveLpPda(programId, slab, lpIdx) {
|
|
|
2777
4068
|
`deriveLpPda: lpIdx must be an integer in [0, ${LP_INDEX_U16_MAX}], got ${lpIdx}`
|
|
2778
4069
|
);
|
|
2779
4070
|
}
|
|
2780
|
-
const
|
|
2781
|
-
new DataView(
|
|
2782
|
-
return
|
|
2783
|
-
[textEncoder.encode("lp"), slab.toBytes(),
|
|
2784
|
-
programId
|
|
2785
|
-
);
|
|
2786
|
-
}
|
|
2787
|
-
function deriveKeeperFund(programId, slab) {
|
|
2788
|
-
return PublicKey4.findProgramAddressSync(
|
|
2789
|
-
[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],
|
|
2790
4075
|
programId
|
|
2791
4076
|
);
|
|
2792
4077
|
}
|
|
2793
|
-
var PUMPSWAP_PROGRAM_ID = new
|
|
4078
|
+
var PUMPSWAP_PROGRAM_ID = new PublicKey6(
|
|
2794
4079
|
"pAMMBay6oceH9fJKBRHGP5D4bD4sWpmSwMn52FMfXEA"
|
|
2795
4080
|
);
|
|
2796
|
-
var RAYDIUM_CLMM_PROGRAM_ID = new
|
|
4081
|
+
var RAYDIUM_CLMM_PROGRAM_ID = new PublicKey6(
|
|
2797
4082
|
"CAMMCzo5YL8w4VFF8KVHrK22GGUsp5VTaW7grrKgrWqK"
|
|
2798
4083
|
);
|
|
2799
|
-
var METEORA_DLMM_PROGRAM_ID = new
|
|
4084
|
+
var METEORA_DLMM_PROGRAM_ID = new PublicKey6(
|
|
2800
4085
|
"LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
|
|
2801
4086
|
);
|
|
2802
|
-
var PYTH_PUSH_ORACLE_PROGRAM_ID = new
|
|
4087
|
+
var PYTH_PUSH_ORACLE_PROGRAM_ID = new PublicKey6(
|
|
2803
4088
|
"pythWSnswVUd12oZpeFP8e9CVaEqJg25g1Vtc2biRsT"
|
|
2804
4089
|
);
|
|
2805
4090
|
var CREATOR_LOCK_SEED = "creator_lock";
|
|
2806
4091
|
function deriveCreatorLockPda(programId, slab) {
|
|
2807
|
-
return
|
|
4092
|
+
return PublicKey6.findProgramAddressSync(
|
|
2808
4093
|
[textEncoder.encode(CREATOR_LOCK_SEED), slab.toBytes()],
|
|
2809
4094
|
programId
|
|
2810
4095
|
);
|
|
@@ -2826,17 +4111,10 @@ function derivePythPushOraclePDA(feedIdHex) {
|
|
|
2826
4111
|
}
|
|
2827
4112
|
const feedId = new Uint8Array(32);
|
|
2828
4113
|
for (let i = 0; i < 32; i++) {
|
|
2829
|
-
|
|
2830
|
-
const byte = parseInt(hexPair, 16);
|
|
2831
|
-
if (Number.isNaN(byte)) {
|
|
2832
|
-
throw new Error(
|
|
2833
|
-
`derivePythPushOraclePDA: failed to parse hex byte at position ${i}: "${hexPair}"`
|
|
2834
|
-
);
|
|
2835
|
-
}
|
|
2836
|
-
feedId[i] = byte;
|
|
4114
|
+
feedId[i] = parseInt(normalized.substring(i * 2, i * 2 + 2), 16);
|
|
2837
4115
|
}
|
|
2838
4116
|
const shardBuf = new Uint8Array(2);
|
|
2839
|
-
return
|
|
4117
|
+
return PublicKey6.findProgramAddressSync(
|
|
2840
4118
|
[shardBuf, feedId],
|
|
2841
4119
|
PYTH_PUSH_ORACLE_PROGRAM_ID
|
|
2842
4120
|
);
|
|
@@ -2860,14 +4138,12 @@ async function fetchTokenAccount(connection, address, tokenProgramId = TOKEN_PRO
|
|
|
2860
4138
|
}
|
|
2861
4139
|
|
|
2862
4140
|
// src/solana/discovery.ts
|
|
2863
|
-
import { PublicKey as
|
|
4141
|
+
import { PublicKey as PublicKey8 } from "@solana/web3.js";
|
|
2864
4142
|
|
|
2865
4143
|
// src/solana/static-markets.ts
|
|
2866
|
-
import { PublicKey as
|
|
4144
|
+
import { PublicKey as PublicKey7 } from "@solana/web3.js";
|
|
2867
4145
|
var MAINNET_MARKETS = [
|
|
2868
|
-
|
|
2869
|
-
// To add entries:
|
|
2870
|
-
// { slabAddress: "ABC123...", symbol: "SOL-PERP", name: "SOL Perpetual" },
|
|
4146
|
+
{ slabAddress: "7psyeWRts4pRX2cyAWD1NH87bR9ugXP7pe6ARgfG79Do", symbol: "SOL-PERP", name: "SOL/USDC Perpetual" }
|
|
2871
4147
|
];
|
|
2872
4148
|
var DEVNET_MARKETS = [
|
|
2873
4149
|
// Populated from prior discoverMarkets() runs on devnet.
|
|
@@ -2901,7 +4177,7 @@ function registerStaticMarkets(network, entries) {
|
|
|
2901
4177
|
if (!entry.slabAddress) continue;
|
|
2902
4178
|
if (seen.has(entry.slabAddress)) continue;
|
|
2903
4179
|
try {
|
|
2904
|
-
new
|
|
4180
|
+
new PublicKey7(entry.slabAddress);
|
|
2905
4181
|
} catch {
|
|
2906
4182
|
console.warn(
|
|
2907
4183
|
`[registerStaticMarkets] Skipping invalid slabAddress: ${entry.slabAddress}`
|
|
@@ -2925,10 +4201,9 @@ function clearStaticMarkets(network) {
|
|
|
2925
4201
|
var ENGINE_BITMAP_OFF_V0 = 320;
|
|
2926
4202
|
var MAGIC_BYTES = new Uint8Array([84, 65, 76, 79, 67, 82, 69, 80]);
|
|
2927
4203
|
var SLAB_TIERS = {
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
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"]
|
|
2932
4207
|
};
|
|
2933
4208
|
var SLAB_TIERS_V0 = {
|
|
2934
4209
|
small: { maxAccounts: 256, dataSize: 62808, label: "Small", description: "256 slots \xB7 ~0.44 SOL" },
|
|
@@ -3035,6 +4310,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3035
4310
|
fundingIndexQpbE6: readI128LE2(data, base + 112),
|
|
3036
4311
|
lastFundingSlot: readU64LE2(data, base + 128),
|
|
3037
4312
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 136),
|
|
4313
|
+
fundingRateE9: 0n,
|
|
4314
|
+
marketMode: null,
|
|
3038
4315
|
lastCrankSlot: readU64LE2(data, base + 144),
|
|
3039
4316
|
maxCrankStalenessSlots: readU64LE2(data, base + 152),
|
|
3040
4317
|
totalOpenInterest: readU128LE2(data, base + 160),
|
|
@@ -3042,6 +4319,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3042
4319
|
shortOi: 0n,
|
|
3043
4320
|
cTot: readU128LE2(data, base + 176),
|
|
3044
4321
|
pnlPosTot: readU128LE2(data, base + 192),
|
|
4322
|
+
pnlMaturedPosTot: 0n,
|
|
3045
4323
|
liqCursor: readU16LE2(data, base + 208),
|
|
3046
4324
|
gcCursor: readU16LE2(data, base + 210),
|
|
3047
4325
|
lastSweepStartSlot: readU64LE2(data, base + 216),
|
|
@@ -3059,6 +4337,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3059
4337
|
lastBreakerSlot: 0n,
|
|
3060
4338
|
markPriceE6: 0n,
|
|
3061
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,
|
|
3062
4348
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3063
4349
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3064
4350
|
};
|
|
@@ -3077,6 +4363,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3077
4363
|
fundingIndexQpbE6: readI128LE2(data, base + 360),
|
|
3078
4364
|
lastFundingSlot: readU64LE2(data, base + 376),
|
|
3079
4365
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 384),
|
|
4366
|
+
fundingRateE9: 0n,
|
|
4367
|
+
marketMode: null,
|
|
3080
4368
|
lastCrankSlot: readU64LE2(data, base + 392),
|
|
3081
4369
|
maxCrankStalenessSlots: readU64LE2(data, base + 400),
|
|
3082
4370
|
totalOpenInterest: readU128LE2(data, base + 408),
|
|
@@ -3086,6 +4374,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3086
4374
|
// V2 has no short_oi
|
|
3087
4375
|
cTot: readU128LE2(data, base + 424),
|
|
3088
4376
|
pnlPosTot: readU128LE2(data, base + 440),
|
|
4377
|
+
pnlMaturedPosTot: 0n,
|
|
3089
4378
|
liqCursor: readU16LE2(data, base + 456),
|
|
3090
4379
|
gcCursor: readU16LE2(data, base + 458),
|
|
3091
4380
|
lastSweepStartSlot: readU64LE2(data, base + 464),
|
|
@@ -3104,6 +4393,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3104
4393
|
lastBreakerSlot: 0n,
|
|
3105
4394
|
markPriceE6: 0n,
|
|
3106
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,
|
|
3107
4404
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3108
4405
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3109
4406
|
};
|
|
@@ -3123,6 +4420,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3123
4420
|
fundingIndexQpbE6: readI128LE2(data, base + l.engineFundingIndexOff),
|
|
3124
4421
|
lastFundingSlot: readU64LE2(data, base + l.engineLastFundingSlotOff),
|
|
3125
4422
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + l.engineFundingRateBpsOff),
|
|
4423
|
+
fundingRateE9: 0n,
|
|
4424
|
+
marketMode: null,
|
|
3126
4425
|
lastCrankSlot: readU64LE2(data, base + l.engineLastCrankSlotOff),
|
|
3127
4426
|
maxCrankStalenessSlots: readU64LE2(data, base + l.engineMaxCrankStalenessOff),
|
|
3128
4427
|
totalOpenInterest: readU128LE2(data, base + l.engineTotalOiOff),
|
|
@@ -3130,6 +4429,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3130
4429
|
shortOi: l.engineShortOiOff >= 0 ? readU128LE2(data, base + l.engineShortOiOff) : 0n,
|
|
3131
4430
|
cTot: readU128LE2(data, base + l.engineCTotOff),
|
|
3132
4431
|
pnlPosTot: readU128LE2(data, base + l.enginePnlPosTotOff),
|
|
4432
|
+
pnlMaturedPosTot: 0n,
|
|
3133
4433
|
liqCursor: readU16LE2(data, base + l.engineLiqCursorOff),
|
|
3134
4434
|
gcCursor: readU16LE2(data, base + l.engineGcCursorOff),
|
|
3135
4435
|
lastSweepStartSlot: readU64LE2(data, base + l.engineLastSweepStartOff),
|
|
@@ -3146,6 +4446,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3146
4446
|
emergencyStartSlot: l.engineEmergencyStartSlotOff >= 0 ? readU64LE2(data, base + l.engineEmergencyStartSlotOff) : 0n,
|
|
3147
4447
|
lastBreakerSlot: l.engineLastBreakerSlotOff >= 0 ? readU64LE2(data, base + l.engineLastBreakerSlotOff) : 0n,
|
|
3148
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,
|
|
3149
4457
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3150
4458
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3151
4459
|
};
|
|
@@ -3163,6 +4471,8 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3163
4471
|
fundingIndexQpbE6: readI128LE2(data, base + 368),
|
|
3164
4472
|
lastFundingSlot: readU64LE2(data, base + 384),
|
|
3165
4473
|
fundingRateBpsPerSlotLast: readI64LE2(data, base + 392),
|
|
4474
|
+
fundingRateE9: 0n,
|
|
4475
|
+
marketMode: null,
|
|
3166
4476
|
lastCrankSlot: readU64LE2(data, base + 424),
|
|
3167
4477
|
maxCrankStalenessSlots: readU64LE2(data, base + 408),
|
|
3168
4478
|
totalOpenInterest: readU128LE2(data, base + 416),
|
|
@@ -3170,6 +4480,7 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3170
4480
|
shortOi: readU128LE2(data, base + 448),
|
|
3171
4481
|
cTot: readU128LE2(data, base + 464),
|
|
3172
4482
|
pnlPosTot: readU128LE2(data, base + 480),
|
|
4483
|
+
pnlMaturedPosTot: 0n,
|
|
3173
4484
|
liqCursor: readU16LE2(data, base + 496),
|
|
3174
4485
|
gcCursor: readU16LE2(data, base + 498),
|
|
3175
4486
|
lastSweepStartSlot: readU64LE2(data, base + 504),
|
|
@@ -3187,6 +4498,14 @@ function parseEngineLight(data, layout, maxAccounts = 4096) {
|
|
|
3187
4498
|
lastBreakerSlot: readU64LE2(data, base + 624),
|
|
3188
4499
|
markPriceE6: readU64LE2(data, base + 400),
|
|
3189
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,
|
|
3190
4509
|
numUsedAccounts: canReadNumUsed ? readU16LE2(data, base + numUsedOff) : 0,
|
|
3191
4510
|
nextAccountId: canReadNextId ? readU64LE2(data, base + nextAccountIdOff) : 0n
|
|
3192
4511
|
};
|
|
@@ -3208,12 +4527,19 @@ async function discoverMarkets(connection, programId, options = {}) {
|
|
|
3208
4527
|
} = options;
|
|
3209
4528
|
const ALL_TIERS = [
|
|
3210
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
|
|
3211
4535
|
...Object.values(SLAB_TIERS_V0),
|
|
3212
4536
|
...Object.values(SLAB_TIERS_V1D),
|
|
3213
4537
|
...Object.values(SLAB_TIERS_V1D_LEGACY),
|
|
3214
4538
|
...Object.values(SLAB_TIERS_V2),
|
|
3215
4539
|
...Object.values(SLAB_TIERS_V1M),
|
|
3216
|
-
...Object.values(
|
|
4540
|
+
...Object.values(SLAB_TIERS_V1M2),
|
|
4541
|
+
...Object.values(SLAB_TIERS_V_ADL),
|
|
4542
|
+
...Object.values(SLAB_TIERS_V_SETDEXPOOL)
|
|
3217
4543
|
];
|
|
3218
4544
|
let rawAccounts = [];
|
|
3219
4545
|
async function fetchTierWithRetry(tier) {
|
|
@@ -3511,7 +4837,7 @@ async function discoverMarketsViaApi(connection, programId, apiBaseUrl, options
|
|
|
3511
4837
|
for (const entry of apiMarkets) {
|
|
3512
4838
|
if (!entry.slab_address || typeof entry.slab_address !== "string") continue;
|
|
3513
4839
|
try {
|
|
3514
|
-
addresses.push(new
|
|
4840
|
+
addresses.push(new PublicKey8(entry.slab_address));
|
|
3515
4841
|
} catch {
|
|
3516
4842
|
console.warn(
|
|
3517
4843
|
`[discoverMarketsViaApi] Skipping invalid slab address: ${entry.slab_address}`
|
|
@@ -3533,7 +4859,7 @@ async function discoverMarketsViaStaticBundle(connection, programId, entries, op
|
|
|
3533
4859
|
for (const entry of entries) {
|
|
3534
4860
|
if (!entry.slabAddress || typeof entry.slabAddress !== "string") continue;
|
|
3535
4861
|
try {
|
|
3536
|
-
addresses.push(new
|
|
4862
|
+
addresses.push(new PublicKey8(entry.slabAddress));
|
|
3537
4863
|
} catch {
|
|
3538
4864
|
console.warn(
|
|
3539
4865
|
`[discoverMarketsViaStaticBundle] Skipping invalid slab address: ${entry.slabAddress}`
|
|
@@ -3551,7 +4877,7 @@ async function discoverMarketsViaStaticBundle(connection, programId, entries, op
|
|
|
3551
4877
|
}
|
|
3552
4878
|
|
|
3553
4879
|
// src/solana/dex-oracle.ts
|
|
3554
|
-
import { PublicKey as
|
|
4880
|
+
import { PublicKey as PublicKey9 } from "@solana/web3.js";
|
|
3555
4881
|
function detectDexType(ownerProgramId) {
|
|
3556
4882
|
if (ownerProgramId.equals(PUMPSWAP_PROGRAM_ID)) return "pumpswap";
|
|
3557
4883
|
if (ownerProgramId.equals(RAYDIUM_CLMM_PROGRAM_ID)) return "raydium-clmm";
|
|
@@ -3587,10 +4913,10 @@ function parsePumpSwapPool(poolAddress, data) {
|
|
|
3587
4913
|
return {
|
|
3588
4914
|
dexType: "pumpswap",
|
|
3589
4915
|
poolAddress,
|
|
3590
|
-
baseMint: new
|
|
3591
|
-
quoteMint: new
|
|
3592
|
-
baseVault: new
|
|
3593
|
-
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))
|
|
3594
4920
|
};
|
|
3595
4921
|
}
|
|
3596
4922
|
var SPL_TOKEN_AMOUNT_MIN_LEN = 72;
|
|
@@ -3616,8 +4942,8 @@ function parseRaydiumClmmPool(poolAddress, data) {
|
|
|
3616
4942
|
return {
|
|
3617
4943
|
dexType: "raydium-clmm",
|
|
3618
4944
|
poolAddress,
|
|
3619
|
-
baseMint: new
|
|
3620
|
-
quoteMint: new
|
|
4945
|
+
baseMint: new PublicKey9(data.slice(73, 105)),
|
|
4946
|
+
quoteMint: new PublicKey9(data.slice(105, 137))
|
|
3621
4947
|
};
|
|
3622
4948
|
}
|
|
3623
4949
|
var MAX_TOKEN_DECIMALS = 24;
|
|
@@ -3635,7 +4961,9 @@ function computeRaydiumClmmPriceE6(data) {
|
|
|
3635
4961
|
}
|
|
3636
4962
|
const sqrtPriceX64 = readU128LE3(dv3, 253);
|
|
3637
4963
|
if (sqrtPriceX64 === 0n) return 0n;
|
|
3638
|
-
const
|
|
4964
|
+
const scaledSqrt = sqrtPriceX64 * 1000000n;
|
|
4965
|
+
const term = scaledSqrt >> 64n;
|
|
4966
|
+
const priceE6Raw = term * sqrtPriceX64 >> 64n;
|
|
3639
4967
|
const decimalDiff = 6 + decimals0 - decimals1;
|
|
3640
4968
|
const adjustedDiff = decimalDiff - 6;
|
|
3641
4969
|
if (adjustedDiff >= 0) {
|
|
@@ -3654,8 +4982,8 @@ function parseMeteoraPool(poolAddress, data) {
|
|
|
3654
4982
|
return {
|
|
3655
4983
|
dexType: "meteora-dlmm",
|
|
3656
4984
|
poolAddress,
|
|
3657
|
-
baseMint: new
|
|
3658
|
-
quoteMint: new
|
|
4985
|
+
baseMint: new PublicKey9(data.slice(81, 113)),
|
|
4986
|
+
quoteMint: new PublicKey9(data.slice(113, 145))
|
|
3659
4987
|
};
|
|
3660
4988
|
}
|
|
3661
4989
|
var MAX_BIN_STEP = 1e4;
|
|
@@ -3676,26 +5004,13 @@ function computeMeteoraDlmmPriceE6(data) {
|
|
|
3676
5004
|
`Meteora DLMM: |activeId| ${Math.abs(activeId)} exceeds max ${MAX_ACTIVE_ID_ABS}`
|
|
3677
5005
|
);
|
|
3678
5006
|
}
|
|
3679
|
-
const MAX_ABS_BIN_ID = 5e5;
|
|
3680
|
-
if (activeId > MAX_ABS_BIN_ID || activeId < -MAX_ABS_BIN_ID) {
|
|
3681
|
-
throw new Error(
|
|
3682
|
-
`Meteora DLMM: activeId ${activeId} exceeds safe range (\xB1${MAX_ABS_BIN_ID})`
|
|
3683
|
-
);
|
|
3684
|
-
}
|
|
3685
5007
|
const SCALE = 1000000000000000000n;
|
|
3686
5008
|
const base = SCALE + BigInt(binStep) * SCALE / 10000n;
|
|
3687
5009
|
const isNeg = activeId < 0;
|
|
3688
5010
|
let exp = isNeg ? BigInt(-activeId) : BigInt(activeId);
|
|
3689
5011
|
let result = SCALE;
|
|
3690
5012
|
let b = base;
|
|
3691
|
-
let iterations = 0;
|
|
3692
|
-
const MAX_ITERATIONS = 25;
|
|
3693
5013
|
while (exp > 0n) {
|
|
3694
|
-
if (iterations++ >= MAX_ITERATIONS) {
|
|
3695
|
-
throw new Error(
|
|
3696
|
-
`Meteora DLMM: exponentiation loop exceeded ${MAX_ITERATIONS} iterations (activeId=${activeId})`
|
|
3697
|
-
);
|
|
3698
|
-
}
|
|
3699
5014
|
if (exp & 1n) {
|
|
3700
5015
|
result = result * b / SCALE;
|
|
3701
5016
|
}
|
|
@@ -3726,7 +5041,6 @@ function readU128LE3(dv3, offset) {
|
|
|
3726
5041
|
var CHAINLINK_MIN_SIZE = 224;
|
|
3727
5042
|
var MAX_DECIMALS = 18;
|
|
3728
5043
|
var CHAINLINK_DECIMALS_OFFSET = 138;
|
|
3729
|
-
var CHAINLINK_TIMESTAMP_OFFSET = 168;
|
|
3730
5044
|
var CHAINLINK_ANSWER_OFFSET = 216;
|
|
3731
5045
|
function readU82(data, off) {
|
|
3732
5046
|
return data[off];
|
|
@@ -3734,7 +5048,7 @@ function readU82(data, off) {
|
|
|
3734
5048
|
function readBigInt64LE(data, off) {
|
|
3735
5049
|
return new DataView(data.buffer, data.byteOffset, data.byteLength).getBigInt64(off, true);
|
|
3736
5050
|
}
|
|
3737
|
-
function parseChainlinkPrice(data
|
|
5051
|
+
function parseChainlinkPrice(data) {
|
|
3738
5052
|
if (data.length < CHAINLINK_MIN_SIZE) {
|
|
3739
5053
|
throw new Error(
|
|
3740
5054
|
`Oracle account data too small: ${data.length} bytes (need at least ${CHAINLINK_MIN_SIZE})`
|
|
@@ -3752,18 +5066,7 @@ function parseChainlinkPrice(data, options) {
|
|
|
3752
5066
|
`Oracle price is non-positive: ${price}`
|
|
3753
5067
|
);
|
|
3754
5068
|
}
|
|
3755
|
-
|
|
3756
|
-
const updatedAt = Number(updatedAtBig);
|
|
3757
|
-
if (options?.maxStalenessSeconds !== void 0 && updatedAt > 0) {
|
|
3758
|
-
const now = Math.floor(Date.now() / 1e3);
|
|
3759
|
-
const age = now - updatedAt;
|
|
3760
|
-
if (age > options.maxStalenessSeconds) {
|
|
3761
|
-
throw new Error(
|
|
3762
|
-
`Oracle price is stale: last updated ${age}s ago (max ${options.maxStalenessSeconds}s)`
|
|
3763
|
-
);
|
|
3764
|
-
}
|
|
3765
|
-
}
|
|
3766
|
-
return { price, decimals, updatedAt: updatedAt > 0 ? updatedAt : void 0 };
|
|
5069
|
+
return { price, decimals };
|
|
3767
5070
|
}
|
|
3768
5071
|
function isValidChainlinkOracle(data) {
|
|
3769
5072
|
try {
|
|
@@ -3775,19 +5078,15 @@ function isValidChainlinkOracle(data) {
|
|
|
3775
5078
|
}
|
|
3776
5079
|
|
|
3777
5080
|
// src/solana/token-program.ts
|
|
3778
|
-
import { PublicKey as
|
|
5081
|
+
import { PublicKey as PublicKey10 } from "@solana/web3.js";
|
|
3779
5082
|
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
|
|
3780
|
-
var TOKEN_2022_PROGRAM_ID = new
|
|
5083
|
+
var TOKEN_2022_PROGRAM_ID = new PublicKey10(
|
|
3781
5084
|
"TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
|
|
3782
5085
|
);
|
|
3783
5086
|
async function detectTokenProgram(connection, mint) {
|
|
3784
5087
|
const info = await connection.getAccountInfo(mint);
|
|
3785
5088
|
if (!info) throw new Error(`Mint account not found: ${mint.toBase58()}`);
|
|
3786
|
-
|
|
3787
|
-
if (info.owner.equals(TOKEN_2022_PROGRAM_ID)) return TOKEN_2022_PROGRAM_ID;
|
|
3788
|
-
throw new Error(
|
|
3789
|
-
`Mint ${mint.toBase58()} is owned by ${info.owner.toBase58()}, which is neither TOKEN_PROGRAM_ID nor TOKEN_2022_PROGRAM_ID`
|
|
3790
|
-
);
|
|
5089
|
+
return info.owner;
|
|
3791
5090
|
}
|
|
3792
5091
|
function isToken2022(tokenProgramId) {
|
|
3793
5092
|
return tokenProgramId.equals(TOKEN_2022_PROGRAM_ID);
|
|
@@ -3797,70 +5096,8 @@ function isStandardToken(tokenProgramId) {
|
|
|
3797
5096
|
}
|
|
3798
5097
|
|
|
3799
5098
|
// src/solana/stake.ts
|
|
3800
|
-
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";
|
|
3801
5100
|
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4 } from "@solana/spl-token";
|
|
3802
|
-
|
|
3803
|
-
// src/config/program-ids.ts
|
|
3804
|
-
import { PublicKey as PublicKey9 } from "@solana/web3.js";
|
|
3805
|
-
function safeEnv(key) {
|
|
3806
|
-
try {
|
|
3807
|
-
return typeof process !== "undefined" && process?.env ? process.env[key] : void 0;
|
|
3808
|
-
} catch {
|
|
3809
|
-
return void 0;
|
|
3810
|
-
}
|
|
3811
|
-
}
|
|
3812
|
-
var PROGRAM_IDS = {
|
|
3813
|
-
devnet: {
|
|
3814
|
-
percolator: "FxfD37s1AZTeWfFQps9Zpebi2dNQ9QSSDtfMKdbsfKrD",
|
|
3815
|
-
matcher: "GTRgyTDfrMvBubALAqtHuQwT8tbGyXid7svXZKtWfC9k"
|
|
3816
|
-
},
|
|
3817
|
-
mainnet: {
|
|
3818
|
-
percolator: "ESa89R5Es3rJ5mnwGybVRG1GrNt9etP11Z5V2QWD4edv",
|
|
3819
|
-
matcher: "DHP6DtwXP1yJsz8YzfoeigRFPB979gzmumkmCxDLSkUX"
|
|
3820
|
-
}
|
|
3821
|
-
};
|
|
3822
|
-
function getProgramId(network) {
|
|
3823
|
-
if (!network) {
|
|
3824
|
-
const override = safeEnv("PROGRAM_ID");
|
|
3825
|
-
if (override) {
|
|
3826
|
-
console.warn(
|
|
3827
|
-
`[percolator-sdk] PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3828
|
-
);
|
|
3829
|
-
return new PublicKey9(override);
|
|
3830
|
-
}
|
|
3831
|
-
}
|
|
3832
|
-
const detectedNetwork = getCurrentNetwork();
|
|
3833
|
-
const targetNetwork = network ?? detectedNetwork;
|
|
3834
|
-
const programId = PROGRAM_IDS[targetNetwork].percolator;
|
|
3835
|
-
return new PublicKey9(programId);
|
|
3836
|
-
}
|
|
3837
|
-
function getMatcherProgramId(network) {
|
|
3838
|
-
if (!network) {
|
|
3839
|
-
const override = safeEnv("MATCHER_PROGRAM_ID");
|
|
3840
|
-
if (override) {
|
|
3841
|
-
console.warn(
|
|
3842
|
-
`[percolator-sdk] MATCHER_PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3843
|
-
);
|
|
3844
|
-
return new PublicKey9(override);
|
|
3845
|
-
}
|
|
3846
|
-
}
|
|
3847
|
-
const detectedNetwork = getCurrentNetwork();
|
|
3848
|
-
const targetNetwork = network ?? detectedNetwork;
|
|
3849
|
-
const programId = PROGRAM_IDS[targetNetwork].matcher;
|
|
3850
|
-
if (!programId) {
|
|
3851
|
-
throw new Error(`Matcher program not deployed on ${targetNetwork}`);
|
|
3852
|
-
}
|
|
3853
|
-
return new PublicKey9(programId);
|
|
3854
|
-
}
|
|
3855
|
-
function getCurrentNetwork() {
|
|
3856
|
-
const network = safeEnv("NETWORK")?.toLowerCase();
|
|
3857
|
-
if (network === "mainnet" || network === "mainnet-beta") {
|
|
3858
|
-
return "mainnet";
|
|
3859
|
-
}
|
|
3860
|
-
return "devnet";
|
|
3861
|
-
}
|
|
3862
|
-
|
|
3863
|
-
// src/solana/stake.ts
|
|
3864
5101
|
var STAKE_PROGRAM_IDS = {
|
|
3865
5102
|
devnet: "6aJb1F9CDCVWCNYFwj8aQsVb696YnW6J1FznteHq4Q6k",
|
|
3866
5103
|
mainnet: "DC5fovFQD5SZYsetwvEqd4Wi4PFY1Yfnc669VMe6oa7F"
|
|
@@ -3871,11 +5108,14 @@ function getStakeProgramId(network) {
|
|
|
3871
5108
|
console.warn(
|
|
3872
5109
|
`[percolator-sdk] STAKE_PROGRAM_ID env override active: ${override} \u2014 ensure this points to a trusted program`
|
|
3873
5110
|
);
|
|
3874
|
-
return new
|
|
5111
|
+
return new PublicKey11(override);
|
|
3875
5112
|
}
|
|
3876
5113
|
const detectedNetwork = network ?? (() => {
|
|
3877
5114
|
const n = safeEnv("NEXT_PUBLIC_DEFAULT_NETWORK")?.toLowerCase() ?? safeEnv("NETWORK")?.toLowerCase() ?? "";
|
|
3878
|
-
|
|
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";
|
|
3879
5119
|
})();
|
|
3880
5120
|
const id = STAKE_PROGRAM_IDS[detectedNetwork];
|
|
3881
5121
|
if (!id) {
|
|
@@ -3883,21 +5123,30 @@ function getStakeProgramId(network) {
|
|
|
3883
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.`
|
|
3884
5124
|
);
|
|
3885
5125
|
}
|
|
3886
|
-
return new
|
|
5126
|
+
return new PublicKey11(id);
|
|
3887
5127
|
}
|
|
3888
|
-
var STAKE_PROGRAM_ID = new
|
|
5128
|
+
var STAKE_PROGRAM_ID = new PublicKey11(STAKE_PROGRAM_IDS.devnet);
|
|
3889
5129
|
var STAKE_IX = {
|
|
3890
5130
|
InitPool: 0,
|
|
3891
5131
|
Deposit: 1,
|
|
3892
5132
|
Withdraw: 2,
|
|
3893
5133
|
FlushToInsurance: 3,
|
|
3894
5134
|
UpdateConfig: 4,
|
|
5135
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3895
5136
|
TransferAdmin: 5,
|
|
5137
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3896
5138
|
AdminSetOracleAuthority: 6,
|
|
5139
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3897
5140
|
AdminSetRiskThreshold: 7,
|
|
5141
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3898
5142
|
AdminSetMaintenanceFee: 8,
|
|
5143
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3899
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. */
|
|
3900
5148
|
AdminWithdrawInsurance: 10,
|
|
5149
|
+
/** @deprecated Removed on-chain in stake v3. This tag now rejects. */
|
|
3901
5150
|
AdminSetInsurancePolicy: 11,
|
|
3902
5151
|
/** PERC-272: Accrue trading fees to LP vault */
|
|
3903
5152
|
AccrueFees: 12,
|
|
@@ -3908,24 +5157,26 @@ var STAKE_IX = {
|
|
|
3908
5157
|
/** PERC-303: Enable/configure senior-junior LP tranches */
|
|
3909
5158
|
AdminSetTrancheConfig: 15,
|
|
3910
5159
|
/** PERC-303: Deposit into junior (first-loss) tranche */
|
|
3911
|
-
DepositJunior: 16
|
|
5160
|
+
DepositJunior: 16,
|
|
5161
|
+
/** Mark the pool as resolved after the wrapper market has been resolved directly. */
|
|
5162
|
+
SetMarketResolved: 18
|
|
3912
5163
|
};
|
|
3913
|
-
var
|
|
5164
|
+
var TEXT2 = new TextEncoder();
|
|
3914
5165
|
function deriveStakePool(slab, programId) {
|
|
3915
|
-
return
|
|
3916
|
-
[
|
|
5166
|
+
return PublicKey11.findProgramAddressSync(
|
|
5167
|
+
[TEXT2.encode("stake_pool"), slab.toBytes()],
|
|
3917
5168
|
programId ?? getStakeProgramId()
|
|
3918
5169
|
);
|
|
3919
5170
|
}
|
|
3920
5171
|
function deriveStakeVaultAuth(pool, programId) {
|
|
3921
|
-
return
|
|
3922
|
-
[
|
|
5172
|
+
return PublicKey11.findProgramAddressSync(
|
|
5173
|
+
[TEXT2.encode("vault_auth"), pool.toBytes()],
|
|
3923
5174
|
programId ?? getStakeProgramId()
|
|
3924
5175
|
);
|
|
3925
5176
|
}
|
|
3926
5177
|
function deriveDepositPda(pool, user, programId) {
|
|
3927
|
-
return
|
|
3928
|
-
[
|
|
5178
|
+
return PublicKey11.findProgramAddressSync(
|
|
5179
|
+
[TEXT2.encode("stake_deposit"), pool.toBytes(), user.toBytes()],
|
|
3929
5180
|
programId ?? getStakeProgramId()
|
|
3930
5181
|
);
|
|
3931
5182
|
}
|
|
@@ -3946,9 +5197,6 @@ function readU16LE3(data, off) {
|
|
|
3946
5197
|
);
|
|
3947
5198
|
}
|
|
3948
5199
|
function u64Le(v) {
|
|
3949
|
-
if (typeof v === "number" && !Number.isSafeInteger(v)) {
|
|
3950
|
-
throw new Error(`u64Le: number ${v} exceeds Number.MAX_SAFE_INTEGER \u2014 use BigInt`);
|
|
3951
|
-
}
|
|
3952
5200
|
const big = BigInt(v);
|
|
3953
5201
|
if (big < 0n) throw new Error(`u64Le: value must be non-negative, got ${big}`);
|
|
3954
5202
|
if (big > 0xFFFFFFFFFFFFFFFFn) throw new Error(`u64Le: value exceeds u64 max`);
|
|
@@ -3956,21 +5204,8 @@ function u64Le(v) {
|
|
|
3956
5204
|
new DataView(arr.buffer).setBigUint64(0, big, true);
|
|
3957
5205
|
return arr;
|
|
3958
5206
|
}
|
|
3959
|
-
function u128Le(v) {
|
|
3960
|
-
if (typeof v === "number" && !Number.isSafeInteger(v)) {
|
|
3961
|
-
throw new Error(`u128Le: number ${v} exceeds Number.MAX_SAFE_INTEGER \u2014 use BigInt`);
|
|
3962
|
-
}
|
|
3963
|
-
const big = BigInt(v);
|
|
3964
|
-
if (big < 0n) throw new Error(`u128Le: value must be non-negative, got ${big}`);
|
|
3965
|
-
if (big > (1n << 128n) - 1n) throw new Error(`u128Le: value exceeds u128 max`);
|
|
3966
|
-
const arr = new Uint8Array(16);
|
|
3967
|
-
const view = new DataView(arr.buffer);
|
|
3968
|
-
view.setBigUint64(0, big & 0xFFFFFFFFFFFFFFFFn, true);
|
|
3969
|
-
view.setBigUint64(8, big >> 64n, true);
|
|
3970
|
-
return arr;
|
|
3971
|
-
}
|
|
3972
5207
|
function u16Le(v) {
|
|
3973
|
-
if (
|
|
5208
|
+
if (v < 0 || v > 65535) throw new Error(`u16Le: value out of u16 range (0..65535), got ${v}`);
|
|
3974
5209
|
const arr = new Uint8Array(2);
|
|
3975
5210
|
new DataView(arr.buffer).setUint16(0, v, true);
|
|
3976
5211
|
return arr;
|
|
@@ -4000,36 +5235,38 @@ function encodeStakeUpdateConfig(newCooldownSlots, newDepositCap) {
|
|
|
4000
5235
|
u64Le(newDepositCap ?? 0n)
|
|
4001
5236
|
);
|
|
4002
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
|
+
}
|
|
4003
5243
|
function encodeStakeTransferAdmin() {
|
|
4004
|
-
return
|
|
5244
|
+
return removedStakeInstruction("encodeStakeTransferAdmin", STAKE_IX.TransferAdmin);
|
|
4005
5245
|
}
|
|
4006
5246
|
function encodeStakeAdminSetOracleAuthority(newAuthority) {
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
newAuthority.toBytes()
|
|
4010
|
-
);
|
|
5247
|
+
void newAuthority;
|
|
5248
|
+
return removedStakeInstruction("encodeStakeAdminSetOracleAuthority", STAKE_IX.AdminSetOracleAuthority);
|
|
4011
5249
|
}
|
|
4012
5250
|
function encodeStakeAdminSetRiskThreshold(newThreshold) {
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
u128Le(newThreshold)
|
|
4016
|
-
);
|
|
5251
|
+
void newThreshold;
|
|
5252
|
+
return removedStakeInstruction("encodeStakeAdminSetRiskThreshold", STAKE_IX.AdminSetRiskThreshold);
|
|
4017
5253
|
}
|
|
4018
5254
|
function encodeStakeAdminSetMaintenanceFee(newFee) {
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
u128Le(newFee)
|
|
4022
|
-
);
|
|
5255
|
+
void newFee;
|
|
5256
|
+
return removedStakeInstruction("encodeStakeAdminSetMaintenanceFee", STAKE_IX.AdminSetMaintenanceFee);
|
|
4023
5257
|
}
|
|
4024
5258
|
function encodeStakeAdminResolveMarket() {
|
|
4025
|
-
return
|
|
5259
|
+
return removedStakeInstruction("encodeStakeAdminResolveMarket", STAKE_IX.AdminResolveMarket);
|
|
4026
5260
|
}
|
|
4027
|
-
function
|
|
5261
|
+
function encodeStakeReturnInsurance(amount) {
|
|
4028
5262
|
return concatBytes(
|
|
4029
|
-
new Uint8Array([STAKE_IX.
|
|
5263
|
+
new Uint8Array([STAKE_IX.ReturnInsurance]),
|
|
4030
5264
|
u64Le(amount)
|
|
4031
5265
|
);
|
|
4032
5266
|
}
|
|
5267
|
+
function encodeStakeAdminWithdrawInsurance(amount) {
|
|
5268
|
+
return encodeStakeReturnInsurance(amount);
|
|
5269
|
+
}
|
|
4033
5270
|
function encodeStakeAccrueFees() {
|
|
4034
5271
|
return new Uint8Array([STAKE_IX.AccrueFees]);
|
|
4035
5272
|
}
|
|
@@ -4056,14 +5293,15 @@ function encodeStakeAdminSetTrancheConfig(juniorFeeMultBps) {
|
|
|
4056
5293
|
function encodeStakeDepositJunior(amount) {
|
|
4057
5294
|
return concatBytes(new Uint8Array([STAKE_IX.DepositJunior]), u64Le(amount));
|
|
4058
5295
|
}
|
|
5296
|
+
function encodeStakeSetMarketResolved() {
|
|
5297
|
+
return new Uint8Array([STAKE_IX.SetMarketResolved]);
|
|
5298
|
+
}
|
|
4059
5299
|
function encodeStakeAdminSetInsurancePolicy(authority, minWithdrawBase, maxWithdrawBps, cooldownSlots) {
|
|
4060
|
-
|
|
4061
|
-
|
|
4062
|
-
|
|
4063
|
-
|
|
4064
|
-
|
|
4065
|
-
u64Le(cooldownSlots)
|
|
4066
|
-
);
|
|
5300
|
+
void authority;
|
|
5301
|
+
void minWithdrawBase;
|
|
5302
|
+
void maxWithdrawBps;
|
|
5303
|
+
void cooldownSlots;
|
|
5304
|
+
return removedStakeInstruction("encodeStakeAdminSetInsurancePolicy", STAKE_IX.AdminSetInsurancePolicy);
|
|
4067
5305
|
}
|
|
4068
5306
|
var STAKE_POOL_SIZE = 352;
|
|
4069
5307
|
function decodeStakePool(data) {
|
|
@@ -4081,15 +5319,15 @@ function decodeStakePool(data) {
|
|
|
4081
5319
|
const adminTransferred = bytes[off] === 1;
|
|
4082
5320
|
off += 1;
|
|
4083
5321
|
off += 4;
|
|
4084
|
-
const slab = new
|
|
5322
|
+
const slab = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4085
5323
|
off += 32;
|
|
4086
|
-
const admin = new
|
|
5324
|
+
const admin = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4087
5325
|
off += 32;
|
|
4088
|
-
const collateralMint = new
|
|
5326
|
+
const collateralMint = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4089
5327
|
off += 32;
|
|
4090
|
-
const lpMint = new
|
|
5328
|
+
const lpMint = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4091
5329
|
off += 32;
|
|
4092
|
-
const vault = new
|
|
5330
|
+
const vault = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4093
5331
|
off += 32;
|
|
4094
5332
|
const totalDeposited = readU64LE4(bytes, off);
|
|
4095
5333
|
off += 8;
|
|
@@ -4105,7 +5343,7 @@ function decodeStakePool(data) {
|
|
|
4105
5343
|
off += 8;
|
|
4106
5344
|
const totalWithdrawn = readU64LE4(bytes, off);
|
|
4107
5345
|
off += 8;
|
|
4108
|
-
const percolatorProgram = new
|
|
5346
|
+
const percolatorProgram = new PublicKey11(bytes.subarray(off, off + 32));
|
|
4109
5347
|
off += 32;
|
|
4110
5348
|
const totalFeesEarned = readU64LE4(bytes, off);
|
|
4111
5349
|
off += 8;
|
|
@@ -4117,11 +5355,11 @@ function decodeStakePool(data) {
|
|
|
4117
5355
|
off += 1;
|
|
4118
5356
|
off += 7;
|
|
4119
5357
|
const reservedStart = off;
|
|
4120
|
-
const
|
|
4121
|
-
const
|
|
4122
|
-
const
|
|
4123
|
-
const epochHighWaterTvl =
|
|
4124
|
-
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);
|
|
4125
5363
|
const trancheEnabled = bytes[reservedStart + 32] === 1;
|
|
4126
5364
|
const juniorBalance = readU64LE4(bytes, reservedStart + 33);
|
|
4127
5365
|
const juniorTotalLp = readU64LE4(bytes, reservedStart + 41);
|
|
@@ -4131,6 +5369,7 @@ function decodeStakePool(data) {
|
|
|
4131
5369
|
bump,
|
|
4132
5370
|
vaultAuthorityBump,
|
|
4133
5371
|
adminTransferred,
|
|
5372
|
+
marketResolved,
|
|
4134
5373
|
slab,
|
|
4135
5374
|
admin,
|
|
4136
5375
|
collateralMint,
|
|
@@ -4151,12 +5390,27 @@ function decodeStakePool(data) {
|
|
|
4151
5390
|
hwmEnabled,
|
|
4152
5391
|
epochHighWaterTvl,
|
|
4153
5392
|
hwmFloorBps,
|
|
5393
|
+
hwmLastEpoch,
|
|
4154
5394
|
trancheEnabled,
|
|
4155
5395
|
juniorBalance,
|
|
4156
5396
|
juniorTotalLp,
|
|
4157
5397
|
juniorFeeMultBps
|
|
4158
5398
|
};
|
|
4159
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
|
+
}
|
|
4160
5414
|
function initPoolAccounts(a) {
|
|
4161
5415
|
return [
|
|
4162
5416
|
{ pubkey: a.admin, isSigner: true, isWritable: true },
|
|
@@ -4225,9 +5479,7 @@ function computePnlPct(pnl, capital) {
|
|
|
4225
5479
|
}
|
|
4226
5480
|
function isAdlTriggered(slabData) {
|
|
4227
5481
|
const layout = detectSlabLayout(slabData.length);
|
|
4228
|
-
if (!layout)
|
|
4229
|
-
return false;
|
|
4230
|
-
}
|
|
5482
|
+
if (!layout) return false;
|
|
4231
5483
|
try {
|
|
4232
5484
|
const engine = parseEngine(slabData);
|
|
4233
5485
|
if (engine.pnlPosTot === 0n) return false;
|
|
@@ -4270,14 +5522,6 @@ function rankAdlPositions(slabData) {
|
|
|
4270
5522
|
if (account.kind !== 0 /* User */) continue;
|
|
4271
5523
|
if (account.positionSize === 0n) continue;
|
|
4272
5524
|
const side = account.positionSize > 0n ? "long" : "short";
|
|
4273
|
-
if (side === "long" && account.positionSize <= 0n) {
|
|
4274
|
-
console.warn(`[fetchAdlRankedPositions] account idx=${idx}: side=long but positionSize=${account.positionSize}`);
|
|
4275
|
-
continue;
|
|
4276
|
-
}
|
|
4277
|
-
if (side === "short" && account.positionSize >= 0n) {
|
|
4278
|
-
console.warn(`[fetchAdlRankedPositions] account idx=${idx}: side=short but positionSize=${account.positionSize}`);
|
|
4279
|
-
continue;
|
|
4280
|
-
}
|
|
4281
5525
|
const pnlPct = computePnlPct(account.pnl, account.capital);
|
|
4282
5526
|
positions.push({
|
|
4283
5527
|
idx,
|
|
@@ -4310,8 +5554,7 @@ function buildAdlInstruction(caller, slab, oracle, programId, targetIdx, backupO
|
|
|
4310
5554
|
`buildAdlInstruction: targetIdx must be a non-negative integer, got ${targetIdx}`
|
|
4311
5555
|
);
|
|
4312
5556
|
}
|
|
4313
|
-
const
|
|
4314
|
-
const data = Buffer.from(dataBytes);
|
|
5557
|
+
const data = Buffer.from(encodeExecuteAdl({ targetIdx }));
|
|
4315
5558
|
const keys = [
|
|
4316
5559
|
{ pubkey: caller, isSigner: true, isWritable: false },
|
|
4317
5560
|
{ pubkey: slab, isSigner: false, isWritable: true },
|
|
@@ -4351,11 +5594,7 @@ function parseAdlEvent(logs) {
|
|
|
4351
5594
|
}
|
|
4352
5595
|
if (tag !== ADL_EVENT_TAG) continue;
|
|
4353
5596
|
try {
|
|
4354
|
-
const
|
|
4355
|
-
if (targetIdxBig < 0n || targetIdxBig > 65535n) {
|
|
4356
|
-
continue;
|
|
4357
|
-
}
|
|
4358
|
-
const targetIdx = Number(targetIdxBig);
|
|
5597
|
+
const targetIdx = Number(BigInt(match[2]));
|
|
4359
5598
|
const price = BigInt(match[3]);
|
|
4360
5599
|
const closedLo = BigInt(match[4]);
|
|
4361
5600
|
const closedHi = BigInt(match[5]);
|
|
@@ -4383,22 +5622,6 @@ async function fetchAdlRankings(apiBase, slab, fetchFn = fetch) {
|
|
|
4383
5622
|
);
|
|
4384
5623
|
}
|
|
4385
5624
|
const json = await res.json();
|
|
4386
|
-
if (typeof json !== "object" || json === null) {
|
|
4387
|
-
throw new Error("fetchAdlRankings: API returned non-object response");
|
|
4388
|
-
}
|
|
4389
|
-
const obj = json;
|
|
4390
|
-
if (!Array.isArray(obj.rankings)) {
|
|
4391
|
-
throw new Error("fetchAdlRankings: API response missing rankings array");
|
|
4392
|
-
}
|
|
4393
|
-
for (const entry of obj.rankings) {
|
|
4394
|
-
if (typeof entry !== "object" || entry === null) {
|
|
4395
|
-
throw new Error("fetchAdlRankings: invalid ranking entry (not an object)");
|
|
4396
|
-
}
|
|
4397
|
-
const r = entry;
|
|
4398
|
-
if (typeof r.idx !== "number" || !Number.isInteger(r.idx) || r.idx < 0) {
|
|
4399
|
-
throw new Error(`fetchAdlRankings: invalid ranking idx: ${r.idx}`);
|
|
4400
|
-
}
|
|
4401
|
-
}
|
|
4402
5625
|
return json;
|
|
4403
5626
|
}
|
|
4404
5627
|
|
|
@@ -4916,11 +6139,11 @@ function formatResult(result, jsonMode) {
|
|
|
4916
6139
|
}
|
|
4917
6140
|
|
|
4918
6141
|
// src/runtime/lighthouse.ts
|
|
4919
|
-
import { PublicKey as
|
|
4920
|
-
var LIGHTHOUSE_PROGRAM_ID = new
|
|
6142
|
+
import { PublicKey as PublicKey14, Transaction as Transaction2 } from "@solana/web3.js";
|
|
6143
|
+
var LIGHTHOUSE_PROGRAM_ID = new PublicKey14(
|
|
4921
6144
|
"L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95"
|
|
4922
6145
|
);
|
|
4923
|
-
var
|
|
6146
|
+
var LIGHTHOUSE_PROGRAM_ID_STR = "L2TExMFKdjpN9kozasaurPirfHy9P8sbXoAN1qA3S95";
|
|
4924
6147
|
var LIGHTHOUSE_CONSTRAINT_ADDRESS = 6400;
|
|
4925
6148
|
var LIGHTHOUSE_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
4926
6149
|
6e3,
|
|
@@ -4966,7 +6189,7 @@ function isLighthouseInstruction(ix) {
|
|
|
4966
6189
|
function isLighthouseError(error) {
|
|
4967
6190
|
const msg = extractErrorMessage(error);
|
|
4968
6191
|
if (!msg) return false;
|
|
4969
|
-
if (msg.includes(
|
|
6192
|
+
if (msg.includes(LIGHTHOUSE_PROGRAM_ID_STR)) return true;
|
|
4970
6193
|
if (/custom\s+program\s+error:\s*0x1900\b/i.test(msg)) return true;
|
|
4971
6194
|
if (/"Custom"\s*:\s*6400\b/.test(msg) && /InstructionError/i.test(msg)) return true;
|
|
4972
6195
|
return false;
|
|
@@ -4976,18 +6199,18 @@ function isLighthouseFailureInLogs(logs) {
|
|
|
4976
6199
|
let insideLighthouse = false;
|
|
4977
6200
|
for (const line of logs) {
|
|
4978
6201
|
if (typeof line !== "string") continue;
|
|
4979
|
-
if (line.includes(`Program ${
|
|
6202
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} invoke`)) {
|
|
4980
6203
|
insideLighthouse = true;
|
|
4981
6204
|
continue;
|
|
4982
6205
|
}
|
|
4983
|
-
if (line.includes(`Program ${
|
|
6206
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} success`)) {
|
|
4984
6207
|
insideLighthouse = false;
|
|
4985
6208
|
continue;
|
|
4986
6209
|
}
|
|
4987
6210
|
if (insideLighthouse && /failed/i.test(line)) {
|
|
4988
6211
|
return true;
|
|
4989
6212
|
}
|
|
4990
|
-
if (line.includes(`Program ${
|
|
6213
|
+
if (line.includes(`Program ${LIGHTHOUSE_PROGRAM_ID_STR} failed`)) {
|
|
4991
6214
|
return true;
|
|
4992
6215
|
}
|
|
4993
6216
|
}
|
|
@@ -5072,10 +6295,16 @@ function computeLiqPrice(entryPrice, capital, positionSize, maintenanceMarginBps
|
|
|
5072
6295
|
function computePreTradeLiqPrice(oracleE6, margin, posSize, maintBps, feeBps, direction) {
|
|
5073
6296
|
if (oracleE6 === 0n || margin === 0n || posSize === 0n) return 0n;
|
|
5074
6297
|
const absPos = posSize < 0n ? -posSize : posSize;
|
|
5075
|
-
const fee = absPos * feeBps / 10000n;
|
|
5076
|
-
const effectiveCapital = margin > fee ? margin - fee : 0n;
|
|
5077
6298
|
const signedPos = direction === "long" ? absPos : -absPos;
|
|
5078
|
-
|
|
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);
|
|
5079
6308
|
}
|
|
5080
6309
|
function computeTradingFee(notional, tradingFeeBps) {
|
|
5081
6310
|
return notional * tradingFeeBps / 10000n;
|
|
@@ -5095,20 +6324,9 @@ function computeFeeSplit(totalFee, config) {
|
|
|
5095
6324
|
if (config.lpBps === 0n && config.protocolBps === 0n && config.creatorBps === 0n) {
|
|
5096
6325
|
return [totalFee, 0n, 0n];
|
|
5097
6326
|
}
|
|
5098
|
-
const totalBps = config.lpBps + config.protocolBps + config.creatorBps;
|
|
5099
|
-
if (totalBps !== 10000n) {
|
|
5100
|
-
throw new Error(
|
|
5101
|
-
`Fee split must equal exactly 10000 bps (100%): lpBps=${config.lpBps} + protocolBps=${config.protocolBps} + creatorBps=${config.creatorBps} = ${totalBps}`
|
|
5102
|
-
);
|
|
5103
|
-
}
|
|
5104
6327
|
const lp = totalFee * config.lpBps / 10000n;
|
|
5105
6328
|
const protocol = totalFee * config.protocolBps / 10000n;
|
|
5106
6329
|
const creator = totalFee - lp - protocol;
|
|
5107
|
-
if (creator < 0n) {
|
|
5108
|
-
throw new Error(
|
|
5109
|
-
`Internal error: creator fee is negative (${creator}). This should not happen if lpBps + protocolBps + creatorBps === 10000.`
|
|
5110
|
-
);
|
|
5111
|
-
}
|
|
5112
6330
|
return [lp, protocol, creator];
|
|
5113
6331
|
}
|
|
5114
6332
|
function computePnlPercent(pnlTokens, capital) {
|
|
@@ -5123,17 +6341,10 @@ function computePnlPercent(pnlTokens, capital) {
|
|
|
5123
6341
|
}
|
|
5124
6342
|
function computeEstimatedEntryPrice(oracleE6, tradingFeeBps, direction) {
|
|
5125
6343
|
if (oracleE6 === 0n) return 0n;
|
|
5126
|
-
if (tradingFeeBps < 0n) {
|
|
5127
|
-
throw new Error(`computeEstimatedEntryPrice: tradingFeeBps must be non-negative, got ${tradingFeeBps}`);
|
|
5128
|
-
}
|
|
5129
6344
|
const feeImpact = oracleE6 * tradingFeeBps / 10000n;
|
|
5130
|
-
|
|
5131
|
-
|
|
5132
|
-
|
|
5133
|
-
`computeEstimatedEntryPrice: result ${result} is non-positive (tradingFeeBps=${tradingFeeBps} too high for oracle=${oracleE6})`
|
|
5134
|
-
);
|
|
5135
|
-
}
|
|
5136
|
-
return result;
|
|
6345
|
+
if (direction === "long") return oracleE6 + feeImpact;
|
|
6346
|
+
const shortEntry = oracleE6 - feeImpact;
|
|
6347
|
+
return shortEntry > 0n ? shortEntry : 1n;
|
|
5137
6348
|
}
|
|
5138
6349
|
var MAX_SAFE_BIGINT = BigInt(Number.MAX_SAFE_INTEGER);
|
|
5139
6350
|
var MIN_SAFE_BIGINT = BigInt(-Number.MAX_SAFE_INTEGER);
|
|
@@ -5154,12 +6365,7 @@ function computeMaxLeverage(initialMarginBps) {
|
|
|
5154
6365
|
if (initialMarginBps <= 0n) {
|
|
5155
6366
|
throw new Error("computeMaxLeverage: initialMarginBps must be positive");
|
|
5156
6367
|
}
|
|
5157
|
-
|
|
5158
|
-
return Number(scaledResult) / 1e6;
|
|
5159
|
-
}
|
|
5160
|
-
function computeMaxWithdrawable(capital, pnl, reservedPnl) {
|
|
5161
|
-
const maturedPnl = pnl - reservedPnl;
|
|
5162
|
-
return capital + (maturedPnl > 0n ? maturedPnl : 0n);
|
|
6368
|
+
return Number(10000n / initialMarginBps);
|
|
5163
6369
|
}
|
|
5164
6370
|
|
|
5165
6371
|
// src/math/warmup.ts
|
|
@@ -5171,9 +6377,6 @@ function computeWarmupUnlockedCapital(totalCapital, currentSlot, warmupStartSlot
|
|
|
5171
6377
|
return totalCapital * elapsed / warmupPeriodSlots;
|
|
5172
6378
|
}
|
|
5173
6379
|
function computeWarmupLeverageCap(initialMarginBps, totalCapital, currentSlot, warmupStartSlot, warmupPeriodSlots) {
|
|
5174
|
-
if (initialMarginBps <= 0n) {
|
|
5175
|
-
throw new Error("computeWarmupLeverageCap: initialMarginBps must be positive");
|
|
5176
|
-
}
|
|
5177
6380
|
const maxLev = computeMaxLeverage(initialMarginBps);
|
|
5178
6381
|
if (warmupPeriodSlots === 0n || warmupStartSlot === 0n) return maxLev;
|
|
5179
6382
|
if (totalCapital <= 0n) return 1;
|
|
@@ -5184,14 +6387,7 @@ function computeWarmupLeverageCap(initialMarginBps, totalCapital, currentSlot, w
|
|
|
5184
6387
|
warmupPeriodSlots
|
|
5185
6388
|
);
|
|
5186
6389
|
if (unlocked <= 0n) return 1;
|
|
5187
|
-
const
|
|
5188
|
-
if (scaledResult > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5189
|
-
console.warn(
|
|
5190
|
-
`[computeWarmupLeverageCap] Warning: effective leverage ${scaledResult} exceeds MAX_SAFE_INTEGER, returning MAX_SAFE_INTEGER as a safety bound`
|
|
5191
|
-
);
|
|
5192
|
-
return Number.MAX_SAFE_INTEGER;
|
|
5193
|
-
}
|
|
5194
|
-
const effectiveLev = Number(scaledResult);
|
|
6390
|
+
const effectiveLev = Number(BigInt(maxLev) * unlocked / totalCapital);
|
|
5195
6391
|
return Math.max(1, effectiveLev);
|
|
5196
6392
|
}
|
|
5197
6393
|
function computeWarmupMaxPositionSize(initialMarginBps, totalCapital, currentSlot, warmupStartSlot, warmupPeriodSlots) {
|
|
@@ -5204,41 +6400,10 @@ function computeWarmupMaxPositionSize(initialMarginBps, totalCapital, currentSlo
|
|
|
5204
6400
|
);
|
|
5205
6401
|
return unlocked * BigInt(maxLev);
|
|
5206
6402
|
}
|
|
5207
|
-
function computeWarmupProgress(currentSlot, warmupStartedAtSlot, warmupPeriodSlots, pnl, reservedPnl) {
|
|
5208
|
-
if (warmupPeriodSlots === 0n || warmupStartedAtSlot === 0n) {
|
|
5209
|
-
return {
|
|
5210
|
-
maturedPnl: pnl > 0n ? pnl : 0n,
|
|
5211
|
-
reservedPnl: 0n,
|
|
5212
|
-
progressBps: 10000n,
|
|
5213
|
-
// 100%
|
|
5214
|
-
slotsRemaining: 0n
|
|
5215
|
-
};
|
|
5216
|
-
}
|
|
5217
|
-
const elapsed = currentSlot >= warmupStartedAtSlot ? currentSlot - warmupStartedAtSlot : 0n;
|
|
5218
|
-
if (elapsed >= warmupPeriodSlots) {
|
|
5219
|
-
return {
|
|
5220
|
-
maturedPnl: pnl > 0n ? pnl : 0n,
|
|
5221
|
-
reservedPnl: 0n,
|
|
5222
|
-
progressBps: 10000n,
|
|
5223
|
-
// 100%
|
|
5224
|
-
slotsRemaining: 0n
|
|
5225
|
-
};
|
|
5226
|
-
}
|
|
5227
|
-
const progressBps = elapsed * 10000n / warmupPeriodSlots;
|
|
5228
|
-
const slotsRemaining = warmupPeriodSlots - elapsed;
|
|
5229
|
-
const maturedPnl = pnl > 0n ? pnl * progressBps / 10000n : 0n;
|
|
5230
|
-
const locked = reservedPnl > 0n ? reservedPnl : 0n;
|
|
5231
|
-
return {
|
|
5232
|
-
maturedPnl,
|
|
5233
|
-
reservedPnl: locked,
|
|
5234
|
-
progressBps,
|
|
5235
|
-
slotsRemaining
|
|
5236
|
-
};
|
|
5237
|
-
}
|
|
5238
6403
|
|
|
5239
6404
|
// src/validation.ts
|
|
5240
|
-
import { PublicKey as
|
|
5241
|
-
var
|
|
6405
|
+
import { PublicKey as PublicKey15 } from "@solana/web3.js";
|
|
6406
|
+
var U16_MAX2 = 65535;
|
|
5242
6407
|
var U64_MAX = BigInt("18446744073709551615");
|
|
5243
6408
|
var I64_MIN = BigInt("-9223372036854775808");
|
|
5244
6409
|
var I64_MAX = BigInt("9223372036854775807");
|
|
@@ -5267,7 +6432,7 @@ var ValidationError = class extends Error {
|
|
|
5267
6432
|
};
|
|
5268
6433
|
function validatePublicKey(value, field) {
|
|
5269
6434
|
try {
|
|
5270
|
-
return new
|
|
6435
|
+
return new PublicKey15(value);
|
|
5271
6436
|
} catch {
|
|
5272
6437
|
throw new ValidationError(
|
|
5273
6438
|
field,
|
|
@@ -5278,26 +6443,24 @@ function validatePublicKey(value, field) {
|
|
|
5278
6443
|
function validateIndex(value, field) {
|
|
5279
6444
|
const t = requireDecimalUIntString(value, field);
|
|
5280
6445
|
const bi = BigInt(t);
|
|
5281
|
-
if (bi > BigInt(
|
|
6446
|
+
if (bi > BigInt(U16_MAX2)) {
|
|
5282
6447
|
throw new ValidationError(
|
|
5283
6448
|
field,
|
|
5284
|
-
`must be <= ${
|
|
6449
|
+
`must be <= ${U16_MAX2} (u16 max), got ${t}`
|
|
5285
6450
|
);
|
|
5286
6451
|
}
|
|
5287
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5288
|
-
throw new ValidationError(field, `internal error: u16 value exceeds MAX_SAFE_INTEGER`);
|
|
5289
|
-
}
|
|
5290
6452
|
return Number(bi);
|
|
5291
6453
|
}
|
|
5292
6454
|
function validateAmount(value, field) {
|
|
5293
|
-
|
|
5294
|
-
|
|
6455
|
+
let num;
|
|
6456
|
+
try {
|
|
6457
|
+
num = BigInt(value);
|
|
6458
|
+
} catch {
|
|
5295
6459
|
throw new ValidationError(
|
|
5296
6460
|
field,
|
|
5297
|
-
`"${value}" is not a valid
|
|
6461
|
+
`"${value}" is not a valid number. Use decimal digits only.`
|
|
5298
6462
|
);
|
|
5299
6463
|
}
|
|
5300
|
-
const num = BigInt(t);
|
|
5301
6464
|
if (num < 0n) {
|
|
5302
6465
|
throw new ValidationError(field, `must be non-negative, got ${num}`);
|
|
5303
6466
|
}
|
|
@@ -5310,14 +6473,15 @@ function validateAmount(value, field) {
|
|
|
5310
6473
|
return num;
|
|
5311
6474
|
}
|
|
5312
6475
|
function validateU128(value, field) {
|
|
5313
|
-
|
|
5314
|
-
|
|
6476
|
+
let num;
|
|
6477
|
+
try {
|
|
6478
|
+
num = BigInt(value);
|
|
6479
|
+
} catch {
|
|
5315
6480
|
throw new ValidationError(
|
|
5316
6481
|
field,
|
|
5317
|
-
`"${value}" is not a valid
|
|
6482
|
+
`"${value}" is not a valid number. Use decimal digits only.`
|
|
5318
6483
|
);
|
|
5319
6484
|
}
|
|
5320
|
-
const num = BigInt(t);
|
|
5321
6485
|
if (num < 0n) {
|
|
5322
6486
|
throw new ValidationError(field, `must be non-negative, got ${num}`);
|
|
5323
6487
|
}
|
|
@@ -5330,14 +6494,15 @@ function validateU128(value, field) {
|
|
|
5330
6494
|
return num;
|
|
5331
6495
|
}
|
|
5332
6496
|
function validateI64(value, field) {
|
|
5333
|
-
|
|
5334
|
-
|
|
6497
|
+
let num;
|
|
6498
|
+
try {
|
|
6499
|
+
num = BigInt(value);
|
|
6500
|
+
} catch {
|
|
5335
6501
|
throw new ValidationError(
|
|
5336
6502
|
field,
|
|
5337
|
-
`"${value}" is not a valid
|
|
6503
|
+
`"${value}" is not a valid number. Use decimal digits only, with optional leading minus.`
|
|
5338
6504
|
);
|
|
5339
6505
|
}
|
|
5340
|
-
const num = BigInt(t);
|
|
5341
6506
|
if (num < I64_MIN) {
|
|
5342
6507
|
throw new ValidationError(
|
|
5343
6508
|
field,
|
|
@@ -5353,14 +6518,15 @@ function validateI64(value, field) {
|
|
|
5353
6518
|
return num;
|
|
5354
6519
|
}
|
|
5355
6520
|
function validateI128(value, field) {
|
|
5356
|
-
|
|
5357
|
-
|
|
6521
|
+
let num;
|
|
6522
|
+
try {
|
|
6523
|
+
num = BigInt(value);
|
|
6524
|
+
} catch {
|
|
5358
6525
|
throw new ValidationError(
|
|
5359
6526
|
field,
|
|
5360
|
-
`"${value}" is not a valid
|
|
6527
|
+
`"${value}" is not a valid number. Use decimal digits only, with optional leading minus.`
|
|
5361
6528
|
);
|
|
5362
6529
|
}
|
|
5363
|
-
const num = BigInt(t);
|
|
5364
6530
|
if (num < I128_MIN) {
|
|
5365
6531
|
throw new ValidationError(
|
|
5366
6532
|
field,
|
|
@@ -5384,9 +6550,6 @@ function validateBps(value, field) {
|
|
|
5384
6550
|
`must be <= 10000 (100%), got ${t}`
|
|
5385
6551
|
);
|
|
5386
6552
|
}
|
|
5387
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5388
|
-
throw new ValidationError(field, `internal error: bps value exceeds MAX_SAFE_INTEGER`);
|
|
5389
|
-
}
|
|
5390
6553
|
return Number(bi);
|
|
5391
6554
|
}
|
|
5392
6555
|
function validateU64(value, field) {
|
|
@@ -5395,15 +6558,12 @@ function validateU64(value, field) {
|
|
|
5395
6558
|
function validateU16(value, field) {
|
|
5396
6559
|
const t = requireDecimalUIntString(value, field);
|
|
5397
6560
|
const bi = BigInt(t);
|
|
5398
|
-
if (bi > BigInt(
|
|
6561
|
+
if (bi > BigInt(U16_MAX2)) {
|
|
5399
6562
|
throw new ValidationError(
|
|
5400
6563
|
field,
|
|
5401
|
-
`must be <= ${
|
|
6564
|
+
`must be <= ${U16_MAX2} (u16 max), got ${t}`
|
|
5402
6565
|
);
|
|
5403
6566
|
}
|
|
5404
|
-
if (bi > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
5405
|
-
throw new ValidationError(field, `internal error: u16 value exceeds MAX_SAFE_INTEGER`);
|
|
5406
|
-
}
|
|
5407
6567
|
return Number(bi);
|
|
5408
6568
|
}
|
|
5409
6569
|
|
|
@@ -5454,9 +6614,7 @@ function parseDexScreenerPairs(json) {
|
|
|
5454
6614
|
else if (liquidity > 1e4) confidence = 60;
|
|
5455
6615
|
else if (liquidity > 1e3) confidence = 45;
|
|
5456
6616
|
const priceUsd = pair.priceUsd;
|
|
5457
|
-
const
|
|
5458
|
-
if (!Number.isFinite(rawPrice) || rawPrice <= 0) continue;
|
|
5459
|
-
const price = rawPrice;
|
|
6617
|
+
const price = typeof priceUsd === "string" || typeof priceUsd === "number" ? parseFloat(String(priceUsd)) || 0 : 0;
|
|
5460
6618
|
let baseSym = "?";
|
|
5461
6619
|
let quoteSym = "?";
|
|
5462
6620
|
if (isRecord(pair.baseToken) && typeof pair.baseToken.symbol === "string") {
|
|
@@ -5487,8 +6645,8 @@ function parseJupiterMintEntry(json, mint) {
|
|
|
5487
6645
|
if (!isRecord(row)) return null;
|
|
5488
6646
|
const rawPrice = row.price;
|
|
5489
6647
|
if (rawPrice === void 0 || rawPrice === null) return null;
|
|
5490
|
-
const price = parseFloat(String(rawPrice));
|
|
5491
|
-
if (
|
|
6648
|
+
const price = parseFloat(String(rawPrice)) || 0;
|
|
6649
|
+
if (price <= 0) return null;
|
|
5492
6650
|
let mintSymbol = "?";
|
|
5493
6651
|
if (typeof row.mintSymbol === "string") mintSymbol = row.mintSymbol;
|
|
5494
6652
|
return { price, mintSymbol };
|
|
@@ -5554,17 +6712,10 @@ async function fetchDexSources(mint, signal) {
|
|
|
5554
6712
|
headers: { "User-Agent": "percolator/1.0" }
|
|
5555
6713
|
}
|
|
5556
6714
|
);
|
|
5557
|
-
if (!resp.ok)
|
|
5558
|
-
console.debug(`[fetchDexSources] HTTP ${resp.status} for mint ${mint}`);
|
|
5559
|
-
return [];
|
|
5560
|
-
}
|
|
6715
|
+
if (!resp.ok) return [];
|
|
5561
6716
|
const json = await resp.json();
|
|
5562
6717
|
return parseDexScreenerPairs(json);
|
|
5563
|
-
} catch
|
|
5564
|
-
console.warn(
|
|
5565
|
-
`[fetchDexSources] Error fetching DexScreener data for mint ${mint}:`,
|
|
5566
|
-
err instanceof Error ? err.message : String(err)
|
|
5567
|
-
);
|
|
6718
|
+
} catch {
|
|
5568
6719
|
return [];
|
|
5569
6720
|
}
|
|
5570
6721
|
}
|
|
@@ -5575,7 +6726,7 @@ function lookupPythSource(mint) {
|
|
|
5575
6726
|
type: "pyth",
|
|
5576
6727
|
address: entry.feedId,
|
|
5577
6728
|
pairLabel: `${entry.symbol} / USD (Pyth)`,
|
|
5578
|
-
liquidity:
|
|
6729
|
+
liquidity: Infinity,
|
|
5579
6730
|
// Pyth is considered deep liquidity
|
|
5580
6731
|
price: 0,
|
|
5581
6732
|
// We don't fetch live price here; caller can enrich
|
|
@@ -5592,16 +6743,10 @@ async function fetchJupiterSource(mint, signal) {
|
|
|
5592
6743
|
headers: { "User-Agent": "percolator/1.0" }
|
|
5593
6744
|
}
|
|
5594
6745
|
);
|
|
5595
|
-
if (!resp.ok)
|
|
5596
|
-
console.debug(`[fetchJupiterSource] HTTP ${resp.status} for mint ${mint}`);
|
|
5597
|
-
return null;
|
|
5598
|
-
}
|
|
6746
|
+
if (!resp.ok) return null;
|
|
5599
6747
|
const json = await resp.json();
|
|
5600
6748
|
const row = parseJupiterMintEntry(json, mint);
|
|
5601
|
-
if (!row)
|
|
5602
|
-
console.debug(`[fetchJupiterSource] No price data from Jupiter for mint ${mint}`);
|
|
5603
|
-
return null;
|
|
5604
|
-
}
|
|
6749
|
+
if (!row) return null;
|
|
5605
6750
|
return {
|
|
5606
6751
|
type: "jupiter",
|
|
5607
6752
|
address: mint,
|
|
@@ -5612,39 +6757,23 @@ async function fetchJupiterSource(mint, signal) {
|
|
|
5612
6757
|
confidence: 40
|
|
5613
6758
|
// Fallback — lower confidence
|
|
5614
6759
|
};
|
|
5615
|
-
} catch
|
|
5616
|
-
console.warn(
|
|
5617
|
-
`[fetchJupiterSource] Error fetching Jupiter data for mint ${mint}:`,
|
|
5618
|
-
err instanceof Error ? err.message : String(err)
|
|
5619
|
-
);
|
|
6760
|
+
} catch {
|
|
5620
6761
|
return null;
|
|
5621
6762
|
}
|
|
5622
6763
|
}
|
|
5623
6764
|
async function resolvePrice(mint, signal, options) {
|
|
5624
6765
|
const timeoutMs = options?.timeoutMs ?? DEFAULT_RESOLVE_TIMEOUT_MS;
|
|
5625
6766
|
const timeoutSignal = AbortSignal.timeout(timeoutMs);
|
|
5626
|
-
const
|
|
6767
|
+
const combinedSignal = signal ? combineAbortSignals([signal, timeoutSignal]) : timeoutSignal;
|
|
5627
6768
|
const [dexSources, jupiterSource] = await Promise.all([
|
|
5628
|
-
fetchDexSources(mint,
|
|
5629
|
-
fetchJupiterSource(mint,
|
|
6769
|
+
fetchDexSources(mint, combinedSignal),
|
|
6770
|
+
fetchJupiterSource(mint, combinedSignal)
|
|
5630
6771
|
]);
|
|
5631
6772
|
const pythSource = lookupPythSource(mint);
|
|
5632
6773
|
const allSources = [];
|
|
5633
6774
|
if (pythSource) {
|
|
5634
|
-
const
|
|
5635
|
-
|
|
5636
|
-
if (dexPrice > 0 && jupPrice > 0) {
|
|
5637
|
-
const mid = (dexPrice + jupPrice) / 2;
|
|
5638
|
-
const deviation = Math.abs(dexPrice - jupPrice) / mid;
|
|
5639
|
-
if (deviation > 0.5) {
|
|
5640
|
-
pythSource.price = 0;
|
|
5641
|
-
pythSource.confidence = 20;
|
|
5642
|
-
} else {
|
|
5643
|
-
pythSource.price = mid;
|
|
5644
|
-
}
|
|
5645
|
-
} else {
|
|
5646
|
-
pythSource.price = dexPrice || jupPrice || 0;
|
|
5647
|
-
}
|
|
6775
|
+
const refPrice = dexSources[0]?.price || jupiterSource?.price || 0;
|
|
6776
|
+
pythSource.price = refPrice;
|
|
5648
6777
|
allSources.push(pythSource);
|
|
5649
6778
|
}
|
|
5650
6779
|
allSources.push(...dexSources);
|
|
@@ -5660,17 +6789,29 @@ async function resolvePrice(mint, signal, options) {
|
|
|
5660
6789
|
};
|
|
5661
6790
|
}
|
|
5662
6791
|
export {
|
|
6792
|
+
ACCOUNTS_ACCEPT_ADMIN,
|
|
6793
|
+
ACCOUNTS_ADMIN_FORCE_CLOSE,
|
|
5663
6794
|
ACCOUNTS_ADVANCE_ORACLE_PHASE,
|
|
6795
|
+
ACCOUNTS_ATTEST_CROSS_MARGIN,
|
|
5664
6796
|
ACCOUNTS_AUDIT_CRANK,
|
|
5665
6797
|
ACCOUNTS_BURN_POSITION_NFT,
|
|
5666
6798
|
ACCOUNTS_CANCEL_QUEUED_WITHDRAWAL,
|
|
6799
|
+
ACCOUNTS_CHALLENGE_SETTLEMENT,
|
|
5667
6800
|
ACCOUNTS_CLAIM_QUEUED_WITHDRAWAL,
|
|
5668
6801
|
ACCOUNTS_CLEAR_PENDING_SETTLEMENT,
|
|
5669
6802
|
ACCOUNTS_CLOSE_ACCOUNT,
|
|
6803
|
+
ACCOUNTS_CLOSE_ORPHAN_SLAB,
|
|
5670
6804
|
ACCOUNTS_CLOSE_SLAB,
|
|
5671
6805
|
ACCOUNTS_CLOSE_STALE_SLABS,
|
|
6806
|
+
ACCOUNTS_CONVERT_RELEASED_PNL,
|
|
6807
|
+
ACCOUNTS_CREATE_INSURANCE_MINT,
|
|
6808
|
+
ACCOUNTS_CREATE_LP_VAULT,
|
|
5672
6809
|
ACCOUNTS_DEPOSIT_COLLATERAL,
|
|
6810
|
+
ACCOUNTS_DEPOSIT_FEE_CREDITS,
|
|
6811
|
+
ACCOUNTS_DEPOSIT_INSURANCE_LP,
|
|
6812
|
+
ACCOUNTS_DEPOSIT_LP_COLLATERAL,
|
|
5673
6813
|
ACCOUNTS_EXECUTE_ADL,
|
|
6814
|
+
ACCOUNTS_FORCE_CLOSE_RESOLVED,
|
|
5674
6815
|
ACCOUNTS_FUND_MARKET_INSURANCE,
|
|
5675
6816
|
ACCOUNTS_INIT_LP,
|
|
5676
6817
|
ACCOUNTS_INIT_MARKET,
|
|
@@ -5678,52 +6819,82 @@ export {
|
|
|
5678
6819
|
ACCOUNTS_INIT_USER,
|
|
5679
6820
|
ACCOUNTS_KEEPER_CRANK,
|
|
5680
6821
|
ACCOUNTS_LIQUIDATE_AT_ORACLE,
|
|
6822
|
+
ACCOUNTS_LP_VAULT_CRANK_FEES,
|
|
6823
|
+
ACCOUNTS_LP_VAULT_DEPOSIT,
|
|
5681
6824
|
ACCOUNTS_LP_VAULT_WITHDRAW,
|
|
5682
6825
|
ACCOUNTS_MINT_POSITION_NFT,
|
|
6826
|
+
ACCOUNTS_NFT_BURN,
|
|
6827
|
+
ACCOUNTS_NFT_EMERGENCY_BURN,
|
|
6828
|
+
ACCOUNTS_NFT_MINT,
|
|
5683
6829
|
ACCOUNTS_PAUSE_MARKET,
|
|
5684
|
-
ACCOUNTS_PUSH_ORACLE_PRICE,
|
|
5685
6830
|
ACCOUNTS_QUEUE_WITHDRAWAL,
|
|
6831
|
+
ACCOUNTS_RECLAIM_EMPTY_ACCOUNT,
|
|
5686
6832
|
ACCOUNTS_RECLAIM_SLAB_RENT,
|
|
6833
|
+
ACCOUNTS_RESCUE_ORPHAN_VAULT,
|
|
6834
|
+
ACCOUNTS_RESOLVE_DISPUTE,
|
|
5687
6835
|
ACCOUNTS_RESOLVE_MARKET,
|
|
6836
|
+
ACCOUNTS_RESOLVE_PERMISSIONLESS,
|
|
6837
|
+
ACCOUNTS_SETTLE_ACCOUNT,
|
|
6838
|
+
ACCOUNTS_SET_DEX_POOL,
|
|
6839
|
+
ACCOUNTS_SET_DISPUTE_PARAMS,
|
|
5688
6840
|
ACCOUNTS_SET_INSURANCE_ISOLATION,
|
|
6841
|
+
ACCOUNTS_SET_INSURANCE_WITHDRAW_POLICY,
|
|
6842
|
+
ACCOUNTS_SET_LP_COLLATERAL_PARAMS,
|
|
5689
6843
|
ACCOUNTS_SET_MAINTENANCE_FEE,
|
|
6844
|
+
ACCOUNTS_SET_MAX_PNL_CAP,
|
|
6845
|
+
ACCOUNTS_SET_OFFSET_PAIR,
|
|
6846
|
+
ACCOUNTS_SET_OI_CAP_MULTIPLIER,
|
|
5690
6847
|
ACCOUNTS_SET_OI_IMBALANCE_HARD_BLOCK,
|
|
5691
|
-
ACCOUNTS_SET_ORACLE_AUTHORITY,
|
|
5692
6848
|
ACCOUNTS_SET_ORACLE_PRICE_CAP,
|
|
5693
6849
|
ACCOUNTS_SET_PENDING_SETTLEMENT,
|
|
5694
6850
|
ACCOUNTS_SET_RISK_THRESHOLD,
|
|
5695
6851
|
ACCOUNTS_SET_WALLET_CAP,
|
|
5696
6852
|
ACCOUNTS_TOPUP_INSURANCE,
|
|
5697
|
-
ACCOUNTS_TOPUP_KEEPER_FUND,
|
|
5698
6853
|
ACCOUNTS_TRADE_CPI,
|
|
5699
6854
|
ACCOUNTS_TRADE_NOCPI,
|
|
6855
|
+
ACCOUNTS_TRANSFER_OWNERSHIP_CPI,
|
|
5700
6856
|
ACCOUNTS_TRANSFER_POSITION_OWNERSHIP,
|
|
5701
6857
|
ACCOUNTS_UNPAUSE_MARKET,
|
|
5702
6858
|
ACCOUNTS_UPDATE_ADMIN,
|
|
6859
|
+
ACCOUNTS_UPDATE_AUTHORITY,
|
|
5703
6860
|
ACCOUNTS_UPDATE_CONFIG,
|
|
6861
|
+
ACCOUNTS_UPDATE_HYPERP_MARK,
|
|
5704
6862
|
ACCOUNTS_WITHDRAW_COLLATERAL,
|
|
5705
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,
|
|
5706
6869
|
AccountKind,
|
|
5707
6870
|
CHAINLINK_ANSWER_OFFSET,
|
|
5708
6871
|
CHAINLINK_DECIMALS_OFFSET,
|
|
5709
6872
|
CHAINLINK_MIN_SIZE,
|
|
5710
|
-
CHAINLINK_TIMESTAMP_OFFSET,
|
|
5711
6873
|
CREATOR_LOCK_SEED,
|
|
6874
|
+
CTX_RETURN_OFFSET,
|
|
6875
|
+
CTX_VAMM_LEN,
|
|
5712
6876
|
CTX_VAMM_OFFSET,
|
|
5713
6877
|
DEFAULT_OI_RAMP_SLOTS,
|
|
5714
6878
|
ENGINE_MARK_PRICE_OFF,
|
|
5715
6879
|
ENGINE_OFF,
|
|
6880
|
+
INIT_CTX_LEN,
|
|
5716
6881
|
IX_TAG,
|
|
5717
6882
|
LIGHTHOUSE_CONSTRAINT_ADDRESS,
|
|
5718
6883
|
LIGHTHOUSE_ERROR_CODES,
|
|
5719
6884
|
LIGHTHOUSE_PROGRAM_ID,
|
|
5720
|
-
|
|
6885
|
+
LIGHTHOUSE_PROGRAM_ID_STR,
|
|
5721
6886
|
LIGHTHOUSE_USER_MESSAGE,
|
|
6887
|
+
LiquidationPolicyTag,
|
|
5722
6888
|
MARK_PRICE_EMA_ALPHA_E6,
|
|
5723
6889
|
MARK_PRICE_EMA_WINDOW_SLOTS,
|
|
6890
|
+
MATCHER_CALL_LEN,
|
|
6891
|
+
MATCHER_CONTEXT_LEN,
|
|
6892
|
+
MATCHER_MAGIC,
|
|
6893
|
+
MATCHER_RETURN_LEN,
|
|
5724
6894
|
MAX_DECIMALS,
|
|
5725
|
-
MAX_ORACLE_PRICE,
|
|
5726
6895
|
METEORA_DLMM_PROGRAM_ID,
|
|
6896
|
+
NFT_IX_TAG,
|
|
6897
|
+
NFT_PROGRAM_ID,
|
|
5727
6898
|
ORACLE_PHASE_GROWING,
|
|
5728
6899
|
ORACLE_PHASE_MATURE,
|
|
5729
6900
|
ORACLE_PHASE_NASCENT,
|
|
@@ -5732,6 +6903,7 @@ export {
|
|
|
5732
6903
|
PHASE1_VOLUME_MIN_SLOTS,
|
|
5733
6904
|
PHASE2_MATURITY_SLOTS,
|
|
5734
6905
|
PHASE2_VOLUME_THRESHOLD,
|
|
6906
|
+
POSITION_NFT_STATE_LEN,
|
|
5735
6907
|
PROGRAM_IDS,
|
|
5736
6908
|
PUMPSWAP_PROGRAM_ID,
|
|
5737
6909
|
PYTH_PUSH_ORACLE_PROGRAM_ID,
|
|
@@ -5741,10 +6913,13 @@ export {
|
|
|
5741
6913
|
RAYDIUM_CLMM_PROGRAM_ID,
|
|
5742
6914
|
RENOUNCE_ADMIN_CONFIRMATION,
|
|
5743
6915
|
RpcPool,
|
|
6916
|
+
SLAB_MAGIC,
|
|
5744
6917
|
SLAB_TIERS,
|
|
5745
6918
|
SLAB_TIERS_V0,
|
|
5746
6919
|
SLAB_TIERS_V1,
|
|
5747
6920
|
SLAB_TIERS_V12_1,
|
|
6921
|
+
SLAB_TIERS_V12_15,
|
|
6922
|
+
SLAB_TIERS_V12_17,
|
|
5748
6923
|
SLAB_TIERS_V1D,
|
|
5749
6924
|
SLAB_TIERS_V1D_LEGACY,
|
|
5750
6925
|
SLAB_TIERS_V1M,
|
|
@@ -5753,6 +6928,7 @@ export {
|
|
|
5753
6928
|
SLAB_TIERS_V_ADL,
|
|
5754
6929
|
SLAB_TIERS_V_ADL_DISCOVERY,
|
|
5755
6930
|
SLAB_TIERS_V_SETDEXPOOL,
|
|
6931
|
+
STAKE_DEPOSIT_SIZE,
|
|
5756
6932
|
STAKE_IX,
|
|
5757
6933
|
STAKE_POOL_SIZE,
|
|
5758
6934
|
STAKE_PROGRAM_ID,
|
|
@@ -5782,7 +6958,6 @@ export {
|
|
|
5782
6958
|
computeLiqPrice,
|
|
5783
6959
|
computeMarkPnl,
|
|
5784
6960
|
computeMaxLeverage,
|
|
5785
|
-
computeMaxWithdrawable,
|
|
5786
6961
|
computePnlPercent,
|
|
5787
6962
|
computePreTradeLiqPrice,
|
|
5788
6963
|
computeRequiredMargin,
|
|
@@ -5790,17 +6965,20 @@ export {
|
|
|
5790
6965
|
computeVammQuote,
|
|
5791
6966
|
computeWarmupLeverageCap,
|
|
5792
6967
|
computeWarmupMaxPositionSize,
|
|
5793
|
-
computeWarmupProgress,
|
|
5794
6968
|
computeWarmupUnlockedCapital,
|
|
5795
6969
|
concatBytes,
|
|
5796
6970
|
countLighthouseInstructions,
|
|
6971
|
+
decodeDepositPda,
|
|
5797
6972
|
decodeError,
|
|
5798
6973
|
decodeStakePool,
|
|
5799
6974
|
depositAccounts,
|
|
5800
6975
|
deriveCreatorLockPda,
|
|
5801
6976
|
deriveDepositPda,
|
|
5802
|
-
|
|
6977
|
+
deriveInsuranceLpMint,
|
|
5803
6978
|
deriveLpPda,
|
|
6979
|
+
deriveMintAuthority,
|
|
6980
|
+
deriveNftMint,
|
|
6981
|
+
deriveNftPda,
|
|
5804
6982
|
derivePythPriceUpdateAccount,
|
|
5805
6983
|
derivePythPushOraclePDA,
|
|
5806
6984
|
deriveStakePool,
|
|
@@ -5822,6 +7000,7 @@ export {
|
|
|
5822
7000
|
encU32,
|
|
5823
7001
|
encU64,
|
|
5824
7002
|
encU8,
|
|
7003
|
+
encodeAcceptAdmin,
|
|
5825
7004
|
encodeAdminForceClose,
|
|
5826
7005
|
encodeAdvanceEpoch,
|
|
5827
7006
|
encodeAdvanceOraclePhase,
|
|
@@ -5838,8 +7017,12 @@ export {
|
|
|
5838
7017
|
encodeCloseOrphanSlab,
|
|
5839
7018
|
encodeCloseSlab,
|
|
5840
7019
|
encodeCloseStaleSlabs,
|
|
7020
|
+
encodeConvertReleasedPnl,
|
|
7021
|
+
encodeCreateInsuranceMint,
|
|
5841
7022
|
encodeCreateLpVault,
|
|
5842
7023
|
encodeDepositCollateral,
|
|
7024
|
+
encodeDepositFeeCredits,
|
|
7025
|
+
encodeDepositInsuranceLP,
|
|
5843
7026
|
encodeDepositLpCollateral,
|
|
5844
7027
|
encodeExecuteAdl,
|
|
5845
7028
|
encodeForceCloseResolved,
|
|
@@ -5855,10 +7038,14 @@ export {
|
|
|
5855
7038
|
encodeLpVaultDeposit,
|
|
5856
7039
|
encodeLpVaultWithdraw,
|
|
5857
7040
|
encodeMintPositionNft,
|
|
7041
|
+
encodeNftBurn,
|
|
7042
|
+
encodeNftEmergencyBurn,
|
|
7043
|
+
encodeNftMint,
|
|
7044
|
+
encodeNftSettleFunding,
|
|
5858
7045
|
encodePauseMarket,
|
|
5859
|
-
encodePushOraclePrice,
|
|
5860
7046
|
encodeQueueWithdrawal,
|
|
5861
7047
|
encodeQueueWithdrawalSV,
|
|
7048
|
+
encodeReclaimEmptyAccount,
|
|
5862
7049
|
encodeReclaimSlabRent,
|
|
5863
7050
|
encodeRenounceAdmin,
|
|
5864
7051
|
encodeRescueOrphanVault,
|
|
@@ -5866,17 +7053,21 @@ export {
|
|
|
5866
7053
|
encodeResolveMarket,
|
|
5867
7054
|
encodeResolvePermissionless,
|
|
5868
7055
|
encodeSetDexPool,
|
|
7056
|
+
encodeSetDisputeParams,
|
|
5869
7057
|
encodeSetInsuranceIsolation,
|
|
5870
7058
|
encodeSetInsuranceWithdrawPolicy,
|
|
7059
|
+
encodeSetLpCollateralParams,
|
|
5871
7060
|
encodeSetMaintenanceFee,
|
|
7061
|
+
encodeSetMaxPnlCap,
|
|
5872
7062
|
encodeSetOffsetPair,
|
|
7063
|
+
encodeSetOiCapMultiplier,
|
|
5873
7064
|
encodeSetOiImbalanceHardBlock,
|
|
5874
|
-
encodeSetOracleAuthority,
|
|
5875
7065
|
encodeSetOraclePriceCap,
|
|
5876
7066
|
encodeSetPendingSettlement,
|
|
5877
7067
|
encodeSetPythOracle,
|
|
5878
7068
|
encodeSetRiskThreshold,
|
|
5879
7069
|
encodeSetWalletCap,
|
|
7070
|
+
encodeSettleAccount,
|
|
5880
7071
|
encodeSlashCreationDeposit,
|
|
5881
7072
|
encodeStakeAccrueFees,
|
|
5882
7073
|
encodeStakeAdminResolveMarket,
|
|
@@ -5892,24 +7083,28 @@ export {
|
|
|
5892
7083
|
encodeStakeFlushToInsurance,
|
|
5893
7084
|
encodeStakeInitPool,
|
|
5894
7085
|
encodeStakeInitTradingPool,
|
|
7086
|
+
encodeStakeReturnInsurance,
|
|
7087
|
+
encodeStakeSetMarketResolved,
|
|
5895
7088
|
encodeStakeTransferAdmin,
|
|
5896
7089
|
encodeStakeUpdateConfig,
|
|
5897
7090
|
encodeStakeWithdraw,
|
|
5898
7091
|
encodeTopUpInsurance,
|
|
5899
|
-
encodeTopUpKeeperFund,
|
|
5900
7092
|
encodeTradeCpi,
|
|
5901
7093
|
encodeTradeCpiV2,
|
|
5902
7094
|
encodeTradeNoCpi,
|
|
5903
7095
|
encodeTransferOwnershipCpi,
|
|
5904
7096
|
encodeTransferPositionOwnership,
|
|
5905
7097
|
encodeUnpauseMarket,
|
|
7098
|
+
encodeUnresolveMarket,
|
|
5906
7099
|
encodeUpdateAdmin,
|
|
7100
|
+
encodeUpdateAuthority,
|
|
5907
7101
|
encodeUpdateConfig,
|
|
5908
7102
|
encodeUpdateHyperpMark,
|
|
5909
7103
|
encodeUpdateMarkPrice,
|
|
5910
7104
|
encodeUpdateRiskParams,
|
|
5911
7105
|
encodeWithdrawCollateral,
|
|
5912
7106
|
encodeWithdrawInsurance,
|
|
7107
|
+
encodeWithdrawInsuranceLP,
|
|
5913
7108
|
encodeWithdrawInsuranceLimited,
|
|
5914
7109
|
encodeWithdrawLpCollateral,
|
|
5915
7110
|
fetchAdlRankedPositions,
|
|
@@ -5925,13 +7120,13 @@ export {
|
|
|
5925
7120
|
getErrorName,
|
|
5926
7121
|
getMarketsByAddress,
|
|
5927
7122
|
getMatcherProgramId,
|
|
7123
|
+
getNftProgramId,
|
|
5928
7124
|
getProgramId,
|
|
5929
7125
|
getStakeProgramId,
|
|
5930
7126
|
getStaticMarkets,
|
|
5931
7127
|
initPoolAccounts,
|
|
5932
7128
|
isAccountUsed,
|
|
5933
7129
|
isAdlTriggered,
|
|
5934
|
-
isAnchorErrorCode,
|
|
5935
7130
|
isLighthouseError,
|
|
5936
7131
|
isLighthouseFailureInLogs,
|
|
5937
7132
|
isLighthouseInstruction,
|
|
@@ -5939,6 +7134,7 @@ export {
|
|
|
5939
7134
|
isToken2022,
|
|
5940
7135
|
isValidChainlinkOracle,
|
|
5941
7136
|
maxAccountIndex,
|
|
7137
|
+
packOiCap,
|
|
5942
7138
|
parseAccount,
|
|
5943
7139
|
parseAdlEvent,
|
|
5944
7140
|
parseAllAccounts,
|
|
@@ -5949,6 +7145,7 @@ export {
|
|
|
5949
7145
|
parseErrorFromLogs,
|
|
5950
7146
|
parseHeader,
|
|
5951
7147
|
parseParams,
|
|
7148
|
+
parsePositionNftAccount,
|
|
5952
7149
|
parseUsedIndices,
|
|
5953
7150
|
rankAdlPositions,
|
|
5954
7151
|
readLastThrUpdateSlot,
|