@theliem/xmarket-sdk 3.20.0 → 3.22.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/dist/index.d.mts +14 -1
- package/dist/index.d.ts +14 -1
- package/dist/index.js +122 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +122 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -354,7 +354,7 @@ var OracleClient = class {
|
|
|
354
354
|
owner: acc.owner,
|
|
355
355
|
admin: acc.admin,
|
|
356
356
|
questionCount: acc.questionCount.toNumber(),
|
|
357
|
-
whitelist: acc.whitelist,
|
|
357
|
+
whitelist: acc.whitelist.slice(0, acc.whitelistLen),
|
|
358
358
|
whitelistLen: acc.whitelistLen,
|
|
359
359
|
isPaused: acc.isPaused,
|
|
360
360
|
bump: acc.bump
|
|
@@ -407,6 +407,23 @@ var HookClient = class {
|
|
|
407
407
|
}).rpc();
|
|
408
408
|
return { signature: sig };
|
|
409
409
|
}
|
|
410
|
+
/**
|
|
411
|
+
* Returns initializeExtraAccountMetaList instruction if the account doesn't exist yet, else null.
|
|
412
|
+
* Used by ClobClient to auto-prepend when extraAccountMetaList is missing.
|
|
413
|
+
*/
|
|
414
|
+
async buildInitHookIxIfNeeded(mint, payer) {
|
|
415
|
+
const [extraAccountMetaList] = PDA.extraAccountMetaList(mint, this.programIds);
|
|
416
|
+
const existing = await this.provider.connection.getAccountInfo(extraAccountMetaList);
|
|
417
|
+
if (existing) return null;
|
|
418
|
+
return this.program.methods.initializeExtraAccountMetaList().accounts({
|
|
419
|
+
payer,
|
|
420
|
+
extraAccountMetaList,
|
|
421
|
+
mint,
|
|
422
|
+
hookConfig: this.configPda(),
|
|
423
|
+
tokenProgram: TOKEN_2022_PROGRAM_ID,
|
|
424
|
+
systemProgram: SystemProgram.programId
|
|
425
|
+
}).instruction();
|
|
426
|
+
}
|
|
410
427
|
/**
|
|
411
428
|
* Register extra account metas for a Token-2022 YES/NO mint.
|
|
412
429
|
* Must be called once per mint after CTF creates it.
|
|
@@ -481,7 +498,7 @@ var HookClient = class {
|
|
|
481
498
|
const acc = await this.program.account.hookConfig.fetch(this.configPda());
|
|
482
499
|
return {
|
|
483
500
|
owner: acc.owner,
|
|
484
|
-
whitelist: acc.whitelist,
|
|
501
|
+
whitelist: acc.whitelist.slice(0, acc.whitelistLen),
|
|
485
502
|
whitelistLen: acc.whitelistLen,
|
|
486
503
|
isFrozen: acc.isFrozen,
|
|
487
504
|
bump: acc.bump
|
|
@@ -684,7 +701,7 @@ var MarketClient = class {
|
|
|
684
701
|
approvedCount: acc.approvedCount.toNumber(),
|
|
685
702
|
rejectedCount: acc.rejectedCount.toNumber(),
|
|
686
703
|
presaleCount: acc.presaleCount.toNumber(),
|
|
687
|
-
whitelist: acc.whitelist,
|
|
704
|
+
whitelist: acc.whitelist.slice(0, acc.whitelistLen),
|
|
688
705
|
whitelistLen: acc.whitelistLen,
|
|
689
706
|
isPaused: acc.isPaused,
|
|
690
707
|
bump: acc.bump
|
|
@@ -2405,6 +2422,18 @@ ${logs.join("\n")}`);
|
|
|
2405
2422
|
const m0 = makers[0].order;
|
|
2406
2423
|
const SIDE_BUY = 0;
|
|
2407
2424
|
const SIDE_SELL = 1;
|
|
2425
|
+
const hookInitIxs = [];
|
|
2426
|
+
if (this.hookClient) {
|
|
2427
|
+
const condition0 = t.condition;
|
|
2428
|
+
const [ym] = PDA.yesMint(condition0, this.programIds);
|
|
2429
|
+
const [nm] = PDA.noMint(condition0, this.programIds);
|
|
2430
|
+
const [yIx, nIx] = await Promise.all([
|
|
2431
|
+
this.hookClient.buildInitHookIxIfNeeded(ym, payer),
|
|
2432
|
+
this.hookClient.buildInitHookIxIfNeeded(nm, payer)
|
|
2433
|
+
]);
|
|
2434
|
+
if (yIx) hookInitIxs.push(yIx);
|
|
2435
|
+
if (nIx) hookInitIxs.push(nIx);
|
|
2436
|
+
}
|
|
2408
2437
|
if (t.tokenId === m0.tokenId) {
|
|
2409
2438
|
let buySignedOrder, sellCandidates;
|
|
2410
2439
|
if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
|
|
@@ -2424,7 +2453,7 @@ ${logs.join("\n")}`);
|
|
|
2424
2453
|
opts,
|
|
2425
2454
|
false
|
|
2426
2455
|
);
|
|
2427
|
-
return this._buildUnsignedVtx(ixs3, alt, payer);
|
|
2456
|
+
return this._buildUnsignedVtx([...hookInitIxs, ...ixs3], alt, payer);
|
|
2428
2457
|
} else {
|
|
2429
2458
|
throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
|
|
2430
2459
|
}
|
|
@@ -2440,7 +2469,7 @@ ${logs.join("\n")}`);
|
|
|
2440
2469
|
operator,
|
|
2441
2470
|
opts
|
|
2442
2471
|
);
|
|
2443
|
-
return this._buildUnsignedVtx(ixs2, alt, payer);
|
|
2472
|
+
return this._buildUnsignedVtx([...hookInitIxs, ...ixs2], alt, payer);
|
|
2444
2473
|
}
|
|
2445
2474
|
const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
|
|
2446
2475
|
const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
|
|
@@ -2461,7 +2490,7 @@ ${logs.join("\n")}`);
|
|
|
2461
2490
|
]);
|
|
2462
2491
|
await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
|
|
2463
2492
|
const ix = allBuy ? await this._buildMintIx(taker, makers, collateralMint, operator, payer) : await this._buildMergeIx(taker, makers, collateralMint, operator, payer, opts);
|
|
2464
|
-
return this._buildUnsignedVtx([ix], alt, payer);
|
|
2493
|
+
return this._buildUnsignedVtx([...hookInitIxs, ix], alt, payer);
|
|
2465
2494
|
}
|
|
2466
2495
|
await Promise.all([
|
|
2467
2496
|
this.registerOrderIfNeeded(taker),
|
|
@@ -2473,7 +2502,7 @@ ${logs.join("\n")}`);
|
|
|
2473
2502
|
const ix = allBuy ? await this._buildMintIx(yesMaker, [taker], collateralMint, operator, payer) : await this._buildMergeIx(yesMaker, [taker], collateralMint, operator, payer, opts);
|
|
2474
2503
|
ixs.push(ix);
|
|
2475
2504
|
}
|
|
2476
|
-
return this._buildUnsignedVtx(ixs, alt, payer);
|
|
2505
|
+
return this._buildUnsignedVtx([...hookInitIxs, ...ixs], alt, payer);
|
|
2477
2506
|
}
|
|
2478
2507
|
// ─── batchCollectRedeemEarly ─────────────────────────────────────────────────
|
|
2479
2508
|
/**
|
|
@@ -2543,10 +2572,16 @@ ${logs.join("\n")}`);
|
|
|
2543
2572
|
}
|
|
2544
2573
|
}
|
|
2545
2574
|
await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
|
|
2575
|
+
const hookInitIxs = [];
|
|
2576
|
+
if (this.hookClient) {
|
|
2577
|
+
const ix = await this.hookClient.buildInitHookIxIfNeeded(outcomeMint, payer);
|
|
2578
|
+
if (ix) hookInitIxs.push(ix);
|
|
2579
|
+
}
|
|
2546
2580
|
const ed25519Ix = buildBatchedCollectFeeEd25519Instruction(signedOrders);
|
|
2581
|
+
const ed25519IxIndex = 2 + hookInitIxs.length;
|
|
2547
2582
|
const collectIx = await this.program.methods.batchCollectRedeemEarly(
|
|
2548
|
-
|
|
2549
|
-
// ix_index:
|
|
2583
|
+
ed25519IxIndex,
|
|
2584
|
+
// ix_index: adjusted for any prepended hook init ixs
|
|
2550
2585
|
signedOrders.length,
|
|
2551
2586
|
outcomeIndex
|
|
2552
2587
|
).accounts({
|
|
@@ -2569,8 +2604,83 @@ ${logs.join("\n")}`);
|
|
|
2569
2604
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
2570
2605
|
systemProgram: SystemProgram.programId
|
|
2571
2606
|
}).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
|
|
2572
|
-
const
|
|
2573
|
-
return this._buildUnsignedVtx([ed25519Ix, collectIx],
|
|
2607
|
+
const alt = opts?.lookupTable ?? this._altCache.get(condition.toBase58()) ?? await this.buildAltForCondition(condition, payer, collateralMint);
|
|
2608
|
+
return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx], alt, payer);
|
|
2609
|
+
}
|
|
2610
|
+
/**
|
|
2611
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
2612
|
+
* Use before buildBatchCollectRedeemEarlyTx when no prior buildMatchOrdersTx ran in this session.
|
|
2613
|
+
*/
|
|
2614
|
+
async buildAltForCondition(condition, _payer, collateralMint) {
|
|
2615
|
+
const cacheKey = condition.toBase58();
|
|
2616
|
+
if (this._altCache.has(cacheKey)) return this._altCache.get(cacheKey);
|
|
2617
|
+
const mint = collateralMint ?? this.networkConfig.defaultCollateral.mint;
|
|
2618
|
+
const payer = this.walletPubkey;
|
|
2619
|
+
const { connection } = this.provider;
|
|
2620
|
+
const clobConfigPda = this.configPda();
|
|
2621
|
+
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2622
|
+
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
2623
|
+
const [extraAccountMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
|
|
2624
|
+
const [hookConfig] = PDA.hookConfig(this.programIds);
|
|
2625
|
+
const [collateralVault] = PDA.collateralVault(mint, this.programIds);
|
|
2626
|
+
const [vaultTokenAccount] = PDA.vaultToken(mint, this.programIds);
|
|
2627
|
+
const clobYesAta = getAssociatedTokenAddressSync(yesMint, clobConfigPda, true, TOKEN_2022_PROGRAM_ID);
|
|
2628
|
+
const clobNoAta = getAssociatedTokenAddressSync(noMint, clobConfigPda, true, TOKEN_2022_PROGRAM_ID);
|
|
2629
|
+
const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
|
|
2630
|
+
const addresses = [
|
|
2631
|
+
Ed25519Program.programId,
|
|
2632
|
+
this.programIds.clobExchange,
|
|
2633
|
+
this.programIds.conditionalTokens,
|
|
2634
|
+
this.programIds.hook,
|
|
2635
|
+
TOKEN_PROGRAM_ID,
|
|
2636
|
+
TOKEN_2022_PROGRAM_ID,
|
|
2637
|
+
SystemProgram.programId,
|
|
2638
|
+
SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2639
|
+
clobConfigPda,
|
|
2640
|
+
hookConfig,
|
|
2641
|
+
condition,
|
|
2642
|
+
yesMint,
|
|
2643
|
+
noMint,
|
|
2644
|
+
extraAccountMeta,
|
|
2645
|
+
collateralVault,
|
|
2646
|
+
vaultTokenAccount,
|
|
2647
|
+
clobYesAta,
|
|
2648
|
+
clobNoAta
|
|
2649
|
+
];
|
|
2650
|
+
if (feeRecipientAddr) addresses.push(feeRecipientAddr);
|
|
2651
|
+
if (this.feeConfigOwner && this.programIds.feeManagement) {
|
|
2652
|
+
const companyAddr = await this.companyAddress();
|
|
2653
|
+
const refVault = await this.referralVault();
|
|
2654
|
+
addresses.push(this.programIds.feeManagement);
|
|
2655
|
+
addresses.push(PDA.feeConfig(this.feeConfigOwner, this.programIds)[0]);
|
|
2656
|
+
addresses.push(PDA.marketFeeOverride(condition, this.programIds)[0]);
|
|
2657
|
+
if (companyAddr) addresses.push(getAssociatedTokenAddressSync(mint, companyAddr));
|
|
2658
|
+
if (refVault) addresses.push(refVault);
|
|
2659
|
+
const oracleVault = await this.getMarketOracleVault(condition, mint) ?? payer;
|
|
2660
|
+
addresses.push(oracleVault);
|
|
2661
|
+
}
|
|
2662
|
+
const slot = await connection.getSlot("finalized");
|
|
2663
|
+
const [createIx, altAddress] = AddressLookupTableProgram.createLookupTable(
|
|
2664
|
+
{ authority: payer, payer, recentSlot: slot }
|
|
2665
|
+
);
|
|
2666
|
+
const BATCH = 30;
|
|
2667
|
+
const extendIxs = [];
|
|
2668
|
+
for (let i = 0; i < addresses.length; i += BATCH) {
|
|
2669
|
+
extendIxs.push(AddressLookupTableProgram.extendLookupTable(
|
|
2670
|
+
{ payer, authority: payer, lookupTable: altAddress, addresses: addresses.slice(i, i + BATCH) }
|
|
2671
|
+
));
|
|
2672
|
+
}
|
|
2673
|
+
await this._sendLegacyTx([createIx, extendIxs[0]]);
|
|
2674
|
+
for (let i = 1; i < extendIxs.length; i++) await this._sendLegacyTx([extendIxs[i]]);
|
|
2675
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
2676
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
2677
|
+
const res = await connection.getAddressLookupTable(altAddress);
|
|
2678
|
+
if (res.value && res.value.state.addresses.length === addresses.length) {
|
|
2679
|
+
this._altCache.set(cacheKey, res.value);
|
|
2680
|
+
return res.value;
|
|
2681
|
+
}
|
|
2682
|
+
}
|
|
2683
|
+
throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
|
|
2574
2684
|
}
|
|
2575
2685
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
2576
2686
|
async fetchConfig() {
|
|
@@ -16386,6 +16496,7 @@ var XMarketSDK = class {
|
|
|
16386
16496
|
}
|
|
16387
16497
|
this._clob.ctfClient = this.ctf;
|
|
16388
16498
|
this._clob.qmConfigPda = this.market.configPda;
|
|
16499
|
+
this._clob.hookClient = this.hook;
|
|
16389
16500
|
}
|
|
16390
16501
|
return this._clob;
|
|
16391
16502
|
}
|