@theliem/xmarket-sdk 3.21.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.mjs CHANGED
@@ -2604,8 +2604,83 @@ ${logs.join("\n")}`);
2604
2604
  token2022Program: TOKEN_2022_PROGRAM_ID,
2605
2605
  systemProgram: SystemProgram.programId
2606
2606
  }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2607
- const cachedAlt = this._altCache.get(condition.toBase58());
2608
- return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx], cachedAlt, payer);
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`);
2609
2684
  }
2610
2685
  // ─── Queries ─────────────────────────────────────────────────────────────────
2611
2686
  async fetchConfig() {