@theliem/xmarket-sdk 3.20.0 → 3.21.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
@@ -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
- 2,
2549
- // ix_index: Ed25519 ix is ix[2] (cuLimit=0, heapFrame=1, ed25519=2)
2583
+ ed25519IxIndex,
2584
+ // ix_index: adjusted for any prepended hook init ixs
2550
2585
  signedOrders.length,
2551
2586
  outcomeIndex
2552
2587
  ).accounts({
@@ -2570,7 +2605,7 @@ ${logs.join("\n")}`);
2570
2605
  systemProgram: SystemProgram.programId
2571
2606
  }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2572
2607
  const cachedAlt = this._altCache.get(condition.toBase58());
2573
- return this._buildUnsignedVtx([ed25519Ix, collectIx], cachedAlt, payer);
2608
+ return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx], cachedAlt, payer);
2574
2609
  }
2575
2610
  // ─── Queries ─────────────────────────────────────────────────────────────────
2576
2611
  async fetchConfig() {
@@ -16386,6 +16421,7 @@ var XMarketSDK = class {
16386
16421
  }
16387
16422
  this._clob.ctfClient = this.ctf;
16388
16423
  this._clob.qmConfigPda = this.market.configPda;
16424
+ this._clob.hookClient = this.hook;
16389
16425
  }
16390
16426
  return this._clob;
16391
16427
  }