@theliem/xmarket-sdk 3.22.0 → 3.25.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.js CHANGED
@@ -63,7 +63,11 @@ var SEEDS = {
63
63
  userClaim: Buffer.from("user_claim"),
64
64
  // Admin Contract
65
65
  adminConfig: Buffer.from("admin_config"),
66
- claimRecord: Buffer.from("claim_record")
66
+ claimRecord: Buffer.from("claim_record"),
67
+ // Dispute
68
+ disputeConfig: Buffer.from("dispute_config"),
69
+ disputeMarket: Buffer.from("dispute_market"),
70
+ userDispute: Buffer.from("user_dispute")
67
71
  };
68
72
  var PDA = class {
69
73
  // ─── Question Market ────────────────────────────────────────────────────────
@@ -183,6 +187,14 @@ var PDA = class {
183
187
  programIds.clobExchange
184
188
  );
185
189
  }
190
+ static collectFeeOrderRecord(user, nonce, programIds) {
191
+ const nonceBuf = Buffer.alloc(8);
192
+ nonceBuf.writeBigUInt64LE(BigInt(nonce.toString()));
193
+ return web3_js.PublicKey.findProgramAddressSync(
194
+ [Buffer.from("collect_order"), user.toBuffer(), nonceBuf],
195
+ programIds.clobExchange
196
+ );
197
+ }
186
198
  // ─── Fee Management ─────────────────────────────────────────────────────────
187
199
  static feeConfig(owner, programIds) {
188
200
  if (!programIds.feeManagement) throw new Error("feeManagement program ID not configured");
@@ -274,6 +286,28 @@ var PDA = class {
274
286
  programIds.adminContract
275
287
  );
276
288
  }
289
+ // ─── Dispute ─────────────────────────────────────────────────────────────
290
+ static disputeConfig(owner, programIds) {
291
+ if (!programIds.dispute) throw new Error("dispute program ID not configured");
292
+ return web3_js.PublicKey.findProgramAddressSync(
293
+ [SEEDS.disputeConfig, owner.toBuffer()],
294
+ programIds.dispute
295
+ );
296
+ }
297
+ static disputeMarket(conditionId, programIds) {
298
+ if (!programIds.dispute) throw new Error("dispute program ID not configured");
299
+ return web3_js.PublicKey.findProgramAddressSync(
300
+ [SEEDS.disputeMarket, Buffer.from(conditionId)],
301
+ programIds.dispute
302
+ );
303
+ }
304
+ static userDispute(user, conditionId, programIds) {
305
+ if (!programIds.dispute) throw new Error("dispute program ID not configured");
306
+ return web3_js.PublicKey.findProgramAddressSync(
307
+ [SEEDS.userDispute, user.toBuffer(), Buffer.from(conditionId)],
308
+ programIds.dispute
309
+ );
310
+ }
277
311
  };
278
312
  function generateQuestionId(content, salt) {
279
313
  const input = content + (salt ?? Date.now());
@@ -1618,6 +1652,39 @@ var ClobClient = class {
1618
1652
  this._marketOracleVaultCache.set(key, vault);
1619
1653
  return vault;
1620
1654
  }
1655
+ /**
1656
+ * Returns a createATA ix for the oracle vault when:
1657
+ * - takerFee > 0
1658
+ * - marketFeeOverride exists for the condition
1659
+ * - oracle vault ATA is not yet initialized
1660
+ * Idempotent — safe to call every tx; returns null if vault already exists.
1661
+ */
1662
+ async buildInitOracleVaultIfNeeded(condition, collateralMint, takerFee, payer) {
1663
+ if (takerFee.isZero()) return null;
1664
+ if (!this.feeConfigOwner || !this.programIds.feeManagement) return null;
1665
+ if (!this.ctfClient || !this.qmConfigPda || !this.programIds.marketOracle) return null;
1666
+ const companyAddr = await this.companyAddress();
1667
+ const refVault = await this.referralVault();
1668
+ if (!companyAddr || !refVault) return null;
1669
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1670
+ const cond = await this.ctfClient.fetchCondition(condition);
1671
+ if (!cond) return null;
1672
+ const [questionPda] = PDA.question(this.qmConfigPda, cond.questionId, this.programIds);
1673
+ const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
1674
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
1675
+ const [feeOverrideInfo, vaultInfo] = await Promise.all([
1676
+ this.provider.connection.getAccountInfo(feeOverridePda),
1677
+ this.provider.connection.getAccountInfo(vault)
1678
+ ]);
1679
+ if (!feeOverrideInfo) return null;
1680
+ if (vaultInfo) return null;
1681
+ return splToken.createAssociatedTokenAccountIdempotentInstruction(
1682
+ payer,
1683
+ vault,
1684
+ marketOraclePda,
1685
+ collateralMint
1686
+ );
1687
+ }
1621
1688
  get walletPubkey() {
1622
1689
  return this.provider.wallet.publicKey;
1623
1690
  }
@@ -1756,8 +1823,8 @@ var ClobClient = class {
1756
1823
  async _sendLegacyTxSig(instructions) {
1757
1824
  const { connection } = this.provider;
1758
1825
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1759
- const { Transaction: Transaction10 } = await import('@solana/web3.js');
1760
- const tx = new Transaction10();
1826
+ const { Transaction: Transaction12 } = await import('@solana/web3.js');
1827
+ const tx = new Transaction12();
1761
1828
  tx.recentBlockhash = blockhash;
1762
1829
  tx.feePayer = this.walletPubkey;
1763
1830
  tx.add(...instructions);
@@ -1783,10 +1850,10 @@ ${logs.join("\n")}`);
1783
1850
  connection.getAccountInfo(clobYesAta),
1784
1851
  connection.getAccountInfo(clobNoAta)
1785
1852
  ]);
1786
- const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction4 } = await import('@solana/spl-token');
1853
+ const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction5 } = await import('@solana/spl-token');
1787
1854
  const ixs = [];
1788
1855
  if (!yesInfo) {
1789
- ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1856
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction5(
1790
1857
  this.walletPubkey,
1791
1858
  clobYesAta,
1792
1859
  clobConfig,
@@ -1795,7 +1862,7 @@ ${logs.join("\n")}`);
1795
1862
  ));
1796
1863
  }
1797
1864
  if (!noInfo) {
1798
- ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1865
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction5(
1799
1866
  this.walletPubkey,
1800
1867
  clobNoAta,
1801
1868
  clobConfig,
@@ -1878,6 +1945,49 @@ ${logs.join("\n")}`);
1878
1945
  await this.registerOrder(signed);
1879
1946
  }
1880
1947
  }
1948
+ // ─── Register CollectFeeOrder ────────────────────────────────────────────────
1949
+ /**
1950
+ * Build a legacy Transaction to register a CollectFeeOrder on-chain.
1951
+ * Must be signed and sent before calling buildBatchCollectRedeemEarlyTx.
1952
+ *
1953
+ * Flow: [Ed25519 ix (1 user sig) + register_collect_fee_order ix]
1954
+ * Caller signs with payer keypair and sends.
1955
+ */
1956
+ async buildRegisterCollectFeeOrderTx(signedOrder, payer) {
1957
+ const { order } = signedOrder;
1958
+ const [collectFeeOrderRecord] = PDA.collectFeeOrderRecord(order.user, order.nonce, this.programIds);
1959
+ const ed25519Ix = buildBatchedCollectFeeEd25519Instruction([signedOrder]);
1960
+ const registerIx = await this.program.methods.registerCollectFeeOrder(order.nonce).accounts({
1961
+ payer,
1962
+ clobConfig: this.configPda(),
1963
+ ixSysvar: IX_SYSVAR,
1964
+ orderSigner: order.user,
1965
+ collectFeeOrderRecord,
1966
+ systemProgram: web3_js.SystemProgram.programId
1967
+ }).instruction();
1968
+ const { blockhash } = await this.provider.connection.getLatestBlockhash();
1969
+ const tx = new web3_js.Transaction();
1970
+ tx.recentBlockhash = blockhash;
1971
+ tx.feePayer = payer;
1972
+ tx.add(ed25519Ix, registerIx);
1973
+ return tx;
1974
+ }
1975
+ /**
1976
+ * Register a CollectFeeOrder on-chain and send immediately (operator-signed flow).
1977
+ * Idempotent — skips if PDA already exists.
1978
+ */
1979
+ async registerCollectFeeOrderIfNeeded(signedOrder) {
1980
+ const [pda] = PDA.collectFeeOrderRecord(
1981
+ signedOrder.order.user,
1982
+ signedOrder.order.nonce,
1983
+ this.programIds
1984
+ );
1985
+ const existing = await this.program.account.collectFeeOrderRecord?.fetchNullable(pda);
1986
+ if (!existing) {
1987
+ const tx = await this.buildRegisterCollectFeeOrderTx(signedOrder, this.walletPubkey);
1988
+ await this._sendLegacyTx(tx.instructions);
1989
+ }
1990
+ }
1881
1991
  /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
1882
1992
  async cancelOrder(nonce) {
1883
1993
  const [orderRecord] = PDA.orderRecord(this.walletPubkey, nonce, this.programIds);
@@ -2460,6 +2570,13 @@ ${logs.join("\n")}`);
2460
2570
  if (yIx) hookInitIxs.push(yIx);
2461
2571
  if (nIx) hookInitIxs.push(nIx);
2462
2572
  }
2573
+ const oracleVaultInitIx = await this.buildInitOracleVaultIfNeeded(
2574
+ t.condition,
2575
+ collateralMint,
2576
+ t.fee,
2577
+ payer
2578
+ );
2579
+ const preIxs = oracleVaultInitIx ? [...hookInitIxs, oracleVaultInitIx] : hookInitIxs;
2463
2580
  if (t.tokenId === m0.tokenId) {
2464
2581
  let buySignedOrder, sellCandidates;
2465
2582
  if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
@@ -2479,7 +2596,7 @@ ${logs.join("\n")}`);
2479
2596
  opts,
2480
2597
  false
2481
2598
  );
2482
- return this._buildUnsignedVtx([...hookInitIxs, ...ixs3], alt, payer);
2599
+ return this._buildUnsignedVtx([...preIxs, ...ixs3], alt, payer);
2483
2600
  } else {
2484
2601
  throw new InvalidParamError("COMPLEMENTARY requires one BUY and one or more SELLs on same tokenId");
2485
2602
  }
@@ -2495,7 +2612,7 @@ ${logs.join("\n")}`);
2495
2612
  operator,
2496
2613
  opts
2497
2614
  );
2498
- return this._buildUnsignedVtx([...hookInitIxs, ...ixs2], alt, payer);
2615
+ return this._buildUnsignedVtx([...preIxs, ...ixs2], alt, payer);
2499
2616
  }
2500
2617
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
2501
2618
  const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
@@ -2516,7 +2633,7 @@ ${logs.join("\n")}`);
2516
2633
  ]);
2517
2634
  await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2518
2635
  const ix = allBuy ? await this._buildMintIx(taker, makers, collateralMint, operator, payer) : await this._buildMergeIx(taker, makers, collateralMint, operator, payer, opts);
2519
- return this._buildUnsignedVtx([...hookInitIxs, ix], alt, payer);
2636
+ return this._buildUnsignedVtx([...preIxs, ix], alt, payer);
2520
2637
  }
2521
2638
  await Promise.all([
2522
2639
  this.registerOrderIfNeeded(taker),
@@ -2528,17 +2645,19 @@ ${logs.join("\n")}`);
2528
2645
  const ix = allBuy ? await this._buildMintIx(yesMaker, [taker], collateralMint, operator, payer) : await this._buildMergeIx(yesMaker, [taker], collateralMint, operator, payer, opts);
2529
2646
  ixs.push(ix);
2530
2647
  }
2531
- return this._buildUnsignedVtx([...hookInitIxs, ...ixs], alt, payer);
2648
+ return this._buildUnsignedVtx([...preIxs, ...ixs], alt, payer);
2532
2649
  }
2533
2650
  // ─── batchCollectRedeemEarly ─────────────────────────────────────────────────
2534
2651
  /**
2535
2652
  * Build VersionedTransaction for batchCollectRedeemEarly.
2536
2653
  *
2537
- * Flow: Ed25519 ix (user sigs) + batchCollectRedeemEarly ix.
2538
- * Each SignedCollectFeeOrder authorizes CLOB to collect `amount` winning tokens
2539
- * from that user, redeem via CTF, then distribute as fees.
2654
+ * Prerequisite: each user's CollectFeeOrder must be registered on-chain via
2655
+ * buildRegisterCollectFeeOrderTx (one tx per user).
2656
+ *
2657
+ * Flow: batchCollectRedeemEarly ix reads CollectFeeOrderRecord PDAs — no Ed25519 inline.
2658
+ * No tx-size limit from signatures, supports 10+ orders in one tx.
2540
2659
  *
2541
- * @param signedOrders - Array of { order, signature } from winning users
2660
+ * @param signedOrders - Array of { order, signature } (used to derive record PDAs)
2542
2661
  * @param condition - Market condition PDA
2543
2662
  * @param outcomeIndex - 0 = NO wins, 1 = YES wins
2544
2663
  * @param operator - Whitelisted operator pubkey (must sign)
@@ -2564,9 +2683,11 @@ ${logs.join("\n")}`);
2564
2683
  const [clobNoPosition] = PDA.position(condition, 0, clobConfig, this.programIds);
2565
2684
  const userAccounts = [];
2566
2685
  for (const { order } of signedOrders) {
2686
+ const [collectFeeOrderRecord] = PDA.collectFeeOrderRecord(order.user, order.nonce, this.programIds);
2567
2687
  const userTokenAta = splToken.getAssociatedTokenAddressSync(outcomeMint, order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2568
2688
  const [userPosition] = PDA.position(condition, outcomeIndex, order.user, this.programIds);
2569
2689
  userAccounts.push(
2690
+ { pubkey: collectFeeOrderRecord, isSigner: false, isWritable: true },
2570
2691
  { pubkey: order.user, isSigner: false, isWritable: false },
2571
2692
  { pubkey: userTokenAta, isSigner: false, isWritable: true },
2572
2693
  { pubkey: userPosition, isSigner: false, isWritable: true }
@@ -2603,11 +2724,7 @@ ${logs.join("\n")}`);
2603
2724
  const ix = await this.hookClient.buildInitHookIxIfNeeded(outcomeMint, payer);
2604
2725
  if (ix) hookInitIxs.push(ix);
2605
2726
  }
2606
- const ed25519Ix = buildBatchedCollectFeeEd25519Instruction(signedOrders);
2607
- const ed25519IxIndex = 2 + hookInitIxs.length;
2608
2727
  const collectIx = await this.program.methods.batchCollectRedeemEarly(
2609
- ed25519IxIndex,
2610
- // ix_index: adjusted for any prepended hook init ixs
2611
2728
  signedOrders.length,
2612
2729
  outcomeIndex
2613
2730
  ).accounts({
@@ -2624,14 +2741,96 @@ ${logs.join("\n")}`);
2624
2741
  clobNoAta,
2625
2742
  clobYesPosition,
2626
2743
  clobNoPosition,
2627
- ixSysvar: IX_SYSVAR,
2628
2744
  conditionalTokensProgram: this.programIds.conditionalTokens,
2629
2745
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
2630
2746
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
2631
2747
  systemProgram: web3_js.SystemProgram.programId
2632
2748
  }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2633
- const alt = opts?.lookupTable ?? this._altCache.get(condition.toBase58()) ?? await this.buildAltForCondition(condition, payer, collateralMint);
2634
- return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx], alt, payer);
2749
+ const alt = opts?.lookupTable ?? await this.buildAltForCollectBatch(condition, payer, collateralMint, signedOrders, outcomeIndex);
2750
+ return this._buildUnsignedVtx([...hookInitIxs, collectIx], alt, payer);
2751
+ }
2752
+ /**
2753
+ * Build ALT for batchCollectRedeemEarly — includes per-user accounts so all
2754
+ * remaining_accounts fit as 1-byte ALT indices instead of 32-byte inline addresses.
2755
+ */
2756
+ async buildAltForCollectBatch(condition, payer, collateralMint, signedOrders, outcomeIndex) {
2757
+ const userKeys = signedOrders.map((o) => o.order.user.toBase58()).sort((a, b) => a.localeCompare(b)).join(",");
2758
+ const cacheKey = `${condition.toBase58()}:collect:${userKeys}`;
2759
+ if (this._altCache.has(cacheKey)) return this._altCache.get(cacheKey);
2760
+ const { connection } = this.provider;
2761
+ const clobConfigPda = this.configPda();
2762
+ const [yesMint] = PDA.yesMint(condition, this.programIds);
2763
+ const [noMint] = PDA.noMint(condition, this.programIds);
2764
+ const outcomeMint = outcomeIndex === 1 ? yesMint : noMint;
2765
+ const [extraAccountMeta] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
2766
+ const [hookConfig] = PDA.hookConfig(this.programIds);
2767
+ const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
2768
+ const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
2769
+ const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfigPda, true, splToken.TOKEN_2022_PROGRAM_ID);
2770
+ const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfigPda, true, splToken.TOKEN_2022_PROGRAM_ID);
2771
+ const [clobYesPos] = PDA.position(condition, 1, clobConfigPda, this.programIds);
2772
+ const [clobNoPos] = PDA.position(condition, 0, clobConfigPda, this.programIds);
2773
+ const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
2774
+ const addresses = [
2775
+ this.programIds.clobExchange,
2776
+ this.programIds.conditionalTokens,
2777
+ this.programIds.hook,
2778
+ splToken.TOKEN_PROGRAM_ID,
2779
+ splToken.TOKEN_2022_PROGRAM_ID,
2780
+ web3_js.SystemProgram.programId,
2781
+ clobConfigPda,
2782
+ hookConfig,
2783
+ condition,
2784
+ yesMint,
2785
+ noMint,
2786
+ extraAccountMeta,
2787
+ collateralVault,
2788
+ vaultTokenAccount,
2789
+ clobYesAta,
2790
+ clobNoAta,
2791
+ clobYesPos,
2792
+ clobNoPos
2793
+ ];
2794
+ if (feeRecipientAddr) addresses.push(feeRecipientAddr);
2795
+ if (this.feeConfigOwner && this.programIds.feeManagement) {
2796
+ const companyAddr = await this.companyAddress();
2797
+ const refVault = await this.referralVault();
2798
+ addresses.push(this.programIds.feeManagement);
2799
+ addresses.push(PDA.feeConfig(this.feeConfigOwner, this.programIds)[0]);
2800
+ addresses.push(PDA.marketFeeOverride(condition, this.programIds)[0]);
2801
+ if (companyAddr) addresses.push(splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr));
2802
+ if (refVault) addresses.push(refVault);
2803
+ const oracleVault = await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2804
+ addresses.push(oracleVault);
2805
+ }
2806
+ for (const { order } of signedOrders) {
2807
+ const [collectFeeOrderRecord] = PDA.collectFeeOrderRecord(order.user, order.nonce, this.programIds);
2808
+ const userTokenAta = splToken.getAssociatedTokenAddressSync(outcomeMint, order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2809
+ const [userPosition] = PDA.position(condition, outcomeIndex, order.user, this.programIds);
2810
+ addresses.push(collectFeeOrderRecord, order.user, userTokenAta, userPosition);
2811
+ }
2812
+ const slot = await connection.getSlot("finalized");
2813
+ const [createIx, altAddress] = web3_js.AddressLookupTableProgram.createLookupTable(
2814
+ { authority: payer, payer, recentSlot: slot }
2815
+ );
2816
+ const BATCH = 30;
2817
+ const extendIxs = [];
2818
+ for (let i = 0; i < addresses.length; i += BATCH) {
2819
+ extendIxs.push(web3_js.AddressLookupTableProgram.extendLookupTable(
2820
+ { payer, authority: payer, lookupTable: altAddress, addresses: addresses.slice(i, i + BATCH) }
2821
+ ));
2822
+ }
2823
+ await this._sendLegacyTx([createIx, extendIxs[0]]);
2824
+ for (let i = 1; i < extendIxs.length; i++) await this._sendLegacyTx([extendIxs[i]]);
2825
+ for (let attempt = 0; attempt < 30; attempt++) {
2826
+ await new Promise((r) => setTimeout(r, 1e3));
2827
+ const res = await connection.getAddressLookupTable(altAddress);
2828
+ if (res.value && res.value.state.addresses.length === addresses.length) {
2829
+ this._altCache.set(cacheKey, res.value);
2830
+ return res.value;
2831
+ }
2832
+ }
2833
+ throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
2635
2834
  }
2636
2835
  /**
2637
2836
  * Build ALT with static accounts for a condition — no order-specific PDAs needed.
@@ -3345,6 +3544,137 @@ var ReferralClient = class {
3345
3544
  ).transaction();
3346
3545
  }
3347
3546
  };
3547
+ var DisputeClient = class {
3548
+ constructor(program, provider, programIds) {
3549
+ this.program = program;
3550
+ this.provider = provider;
3551
+ this.programIds = programIds;
3552
+ }
3553
+ get walletPubkey() {
3554
+ return this.provider.wallet.publicKey;
3555
+ }
3556
+ configPdaFor(owner) {
3557
+ const [pda] = PDA.disputeConfig(owner, this.programIds);
3558
+ return pda;
3559
+ }
3560
+ disputeVault(owner, collateralMint) {
3561
+ const configPda = this.configPdaFor(owner);
3562
+ return splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3563
+ }
3564
+ // ─── Fetch ────────────────────────────────────────────────────────────────
3565
+ async fetchConfig(owner = this.walletPubkey) {
3566
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3567
+ try {
3568
+ const acc = await this.program.account.disputeConfig.fetch(configPda);
3569
+ return {
3570
+ version: acc.version,
3571
+ owner: acc.owner,
3572
+ admin: acc.admin,
3573
+ collateralMint: acc.collateralMint,
3574
+ bump: acc.bump
3575
+ };
3576
+ } catch {
3577
+ return null;
3578
+ }
3579
+ }
3580
+ async fetchDisputeMarket(conditionId) {
3581
+ const [pda] = PDA.disputeMarket(conditionId, this.programIds);
3582
+ try {
3583
+ const acc = await this.program.account.disputeMarket.fetch(pda);
3584
+ return {
3585
+ version: acc.version,
3586
+ conditionId: acc.conditionId,
3587
+ deadline: acc.deadline,
3588
+ bond: acc.bond,
3589
+ amount: acc.amount,
3590
+ isResolved: acc.isResolved,
3591
+ bump: acc.bump
3592
+ };
3593
+ } catch {
3594
+ return null;
3595
+ }
3596
+ }
3597
+ async fetchUserDispute(user, conditionId) {
3598
+ const [pda] = PDA.userDispute(user, conditionId, this.programIds);
3599
+ try {
3600
+ const acc = await this.program.account.userDispute.fetch(pda);
3601
+ return {
3602
+ version: acc.version,
3603
+ user: acc.user,
3604
+ conditionId: acc.conditionId,
3605
+ amount: acc.amount,
3606
+ bump: acc.bump
3607
+ };
3608
+ } catch {
3609
+ return null;
3610
+ }
3611
+ }
3612
+ // ─── Instructions ─────────────────────────────────────────────────────────
3613
+ async initialize(collateralMint, owner = this.walletPubkey) {
3614
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3615
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3616
+ return this.program.methods.initialize().accounts({
3617
+ owner,
3618
+ disputeConfig: configPda,
3619
+ collateralMint,
3620
+ disputeVault: vault,
3621
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
3622
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
3623
+ systemProgram: web3_js.SystemProgram.programId
3624
+ }).transaction();
3625
+ }
3626
+ async buildSetAdminTx(newAdmin, owner = this.walletPubkey) {
3627
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3628
+ return this.program.methods.setAdmin(newAdmin).accounts({
3629
+ owner,
3630
+ disputeConfig: configPda
3631
+ }).transaction();
3632
+ }
3633
+ async buildRaiseDisputeTx(conditionId, collateralMint, owner, user = this.walletPubkey, payer = user) {
3634
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3635
+ const [disputeMarket] = PDA.disputeMarket(conditionId, this.programIds);
3636
+ const [userDispute] = PDA.userDispute(user, conditionId, this.programIds);
3637
+ const userAta = splToken.getAssociatedTokenAddressSync(collateralMint, user);
3638
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3639
+ return this.program.methods.raiseDispute(Array.from(conditionId)).accounts({
3640
+ user,
3641
+ payer,
3642
+ disputeConfig: configPda,
3643
+ disputeMarket,
3644
+ userDispute,
3645
+ userAta,
3646
+ disputeVault: vault,
3647
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
3648
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
3649
+ systemProgram: web3_js.SystemProgram.programId
3650
+ }).transaction();
3651
+ }
3652
+ async buildClaimTx(conditionId, collateralMint, owner, user = this.walletPubkey) {
3653
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3654
+ const [disputeMarket] = PDA.disputeMarket(conditionId, this.programIds);
3655
+ const [userDispute] = PDA.userDispute(user, conditionId, this.programIds);
3656
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3657
+ const userAta = splToken.getAssociatedTokenAddressSync(collateralMint, user);
3658
+ return this.program.methods.claim(Array.from(conditionId)).accounts({
3659
+ user,
3660
+ disputeConfig: configPda,
3661
+ disputeMarket,
3662
+ userDispute,
3663
+ disputeVault: vault,
3664
+ userAta,
3665
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
3666
+ }).transaction();
3667
+ }
3668
+ async buildResolveDisputeTx(conditionId, amount, isRefunded, owner, admin = this.walletPubkey) {
3669
+ const [configPda] = PDA.disputeConfig(owner, this.programIds);
3670
+ const [disputeMarket] = PDA.disputeMarket(conditionId, this.programIds);
3671
+ return this.program.methods.resolveDispute(Array.from(conditionId), amount, isRefunded).accounts({
3672
+ admin,
3673
+ disputeConfig: configPda,
3674
+ disputeMarket
3675
+ }).transaction();
3676
+ }
3677
+ };
3348
3678
 
3349
3679
  // src/idls/oracle.json
3350
3680
  var oracle_default = {
@@ -9263,7 +9593,8 @@ var clob_exchange_default = {
9263
9593
  name: "batch_collect_redeem_early",
9264
9594
  docs: [
9265
9595
  "Batch collect fee tokens from winning users after question resolution,",
9266
- "redeem them via CTF, and distribute USDS via fee_management."
9596
+ "redeem them via CTF, and distribute USDS via fee_management.",
9597
+ "Requires each user's CollectFeeOrderRecord to be registered via register_collect_fee_order."
9267
9598
  ],
9268
9599
  discriminator: [
9269
9600
  87,
@@ -9373,7 +9704,7 @@ var clob_exchange_default = {
9373
9704
  {
9374
9705
  name: "clob_yes_ata",
9375
9706
  docs: [
9376
- "CLOB's YES ATA (Token-2022) \u2014 must be pre-initialized (created during prior matchOrders)."
9707
+ "CLOB's YES ATA (Token-2022) \u2014 must be pre-initialized."
9377
9708
  ],
9378
9709
  writable: true
9379
9710
  },
@@ -9392,9 +9723,6 @@ var clob_exchange_default = {
9392
9723
  name: "clob_no_position",
9393
9724
  writable: true
9394
9725
  },
9395
- {
9396
- name: "ix_sysvar"
9397
- },
9398
9726
  {
9399
9727
  name: "conditional_tokens_program",
9400
9728
  address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
@@ -9413,10 +9741,6 @@ var clob_exchange_default = {
9413
9741
  }
9414
9742
  ],
9415
9743
  args: [
9416
- {
9417
- name: "ix_index",
9418
- type: "u8"
9419
- },
9420
9744
  {
9421
9745
  name: "order_count",
9422
9746
  type: "u8"
@@ -10363,27 +10687,25 @@ var clob_exchange_default = {
10363
10687
  ]
10364
10688
  },
10365
10689
  {
10366
- name: "register_order",
10690
+ name: "register_collect_fee_order",
10367
10691
  docs: [
10368
- "Register a signed order on-chain (Ed25519 verify at registration time).",
10369
- "ix[0] must be Ed25519 precompile with 1 entry for order.signer."
10692
+ "Register a signed CollectFeeOrder on-chain (Ed25519 verify at registration time).",
10693
+ "ix[0] must be Ed25519 precompile with 1 entry for order.user.",
10694
+ "Call once per user before batch_collect_redeem_early."
10370
10695
  ],
10371
10696
  discriminator: [
10372
- 92,
10373
- 37,
10374
- 29,
10375
- 46,
10376
- 77,
10377
- 250,
10378
- 219,
10379
- 6
10697
+ 63,
10698
+ 26,
10699
+ 202,
10700
+ 98,
10701
+ 195,
10702
+ 2,
10703
+ 211,
10704
+ 36
10380
10705
  ],
10381
10706
  accounts: [
10382
10707
  {
10383
10708
  name: "payer",
10384
- docs: [
10385
- "Operator pays rent for the OrderRecord PDA."
10386
- ],
10387
10709
  writable: true,
10388
10710
  signer: true
10389
10711
  },
@@ -10418,25 +10740,26 @@ var clob_exchange_default = {
10418
10740
  name: "order_signer"
10419
10741
  },
10420
10742
  {
10421
- name: "order_record",
10743
+ name: "collect_fee_order_record",
10422
10744
  writable: true,
10423
10745
  pda: {
10424
10746
  seeds: [
10425
10747
  {
10426
10748
  kind: "const",
10427
10749
  value: [
10750
+ 99,
10428
10751
  111,
10429
- 114,
10430
- 100,
10431
- 101,
10432
- 114,
10433
- 95,
10434
- 114,
10752
+ 108,
10753
+ 108,
10435
10754
  101,
10436
10755
  99,
10756
+ 116,
10757
+ 95,
10437
10758
  111,
10438
10759
  114,
10439
- 100
10760
+ 100,
10761
+ 101,
10762
+ 114
10440
10763
  ]
10441
10764
  },
10442
10765
  {
@@ -10451,16 +10774,116 @@ var clob_exchange_default = {
10451
10774
  }
10452
10775
  },
10453
10776
  {
10454
- name: "order_status",
10455
- writable: true,
10456
- pda: {
10457
- seeds: [
10458
- {
10459
- kind: "const",
10460
- value: [
10461
- 111,
10462
- 114,
10463
- 100,
10777
+ name: "system_program",
10778
+ address: "11111111111111111111111111111111"
10779
+ }
10780
+ ],
10781
+ args: [
10782
+ {
10783
+ name: "nonce",
10784
+ type: "u64"
10785
+ }
10786
+ ]
10787
+ },
10788
+ {
10789
+ name: "register_order",
10790
+ docs: [
10791
+ "Register a signed order on-chain (Ed25519 verify at registration time).",
10792
+ "ix[0] must be Ed25519 precompile with 1 entry for order.signer."
10793
+ ],
10794
+ discriminator: [
10795
+ 92,
10796
+ 37,
10797
+ 29,
10798
+ 46,
10799
+ 77,
10800
+ 250,
10801
+ 219,
10802
+ 6
10803
+ ],
10804
+ accounts: [
10805
+ {
10806
+ name: "payer",
10807
+ docs: [
10808
+ "Operator pays rent for the OrderRecord PDA."
10809
+ ],
10810
+ writable: true,
10811
+ signer: true
10812
+ },
10813
+ {
10814
+ name: "clob_config",
10815
+ pda: {
10816
+ seeds: [
10817
+ {
10818
+ kind: "const",
10819
+ value: [
10820
+ 99,
10821
+ 108,
10822
+ 111,
10823
+ 98,
10824
+ 95,
10825
+ 99,
10826
+ 111,
10827
+ 110,
10828
+ 102,
10829
+ 105,
10830
+ 103
10831
+ ]
10832
+ }
10833
+ ]
10834
+ }
10835
+ },
10836
+ {
10837
+ name: "ix_sysvar",
10838
+ address: "Sysvar1nstructions1111111111111111111111111"
10839
+ },
10840
+ {
10841
+ name: "order_signer"
10842
+ },
10843
+ {
10844
+ name: "order_record",
10845
+ writable: true,
10846
+ pda: {
10847
+ seeds: [
10848
+ {
10849
+ kind: "const",
10850
+ value: [
10851
+ 111,
10852
+ 114,
10853
+ 100,
10854
+ 101,
10855
+ 114,
10856
+ 95,
10857
+ 114,
10858
+ 101,
10859
+ 99,
10860
+ 111,
10861
+ 114,
10862
+ 100
10863
+ ]
10864
+ },
10865
+ {
10866
+ kind: "account",
10867
+ path: "order_signer"
10868
+ },
10869
+ {
10870
+ kind: "arg",
10871
+ path: "nonce"
10872
+ }
10873
+ ]
10874
+ }
10875
+ },
10876
+ {
10877
+ name: "order_status",
10878
+ writable: true,
10879
+ pda: {
10880
+ seeds: [
10881
+ {
10882
+ kind: "const",
10883
+ value: [
10884
+ 111,
10885
+ 114,
10886
+ 100,
10464
10887
  101,
10465
10888
  114
10466
10889
  ]
@@ -10652,6 +11075,19 @@ var clob_exchange_default = {
10652
11075
  160
10653
11076
  ]
10654
11077
  },
11078
+ {
11079
+ name: "CollectFeeOrderRecord",
11080
+ discriminator: [
11081
+ 145,
11082
+ 140,
11083
+ 193,
11084
+ 74,
11085
+ 12,
11086
+ 98,
11087
+ 74,
11088
+ 130
11089
+ ]
11090
+ },
10655
11091
  {
10656
11092
  name: "OrderStatus",
10657
11093
  discriminator: [
@@ -10861,6 +11297,53 @@ var clob_exchange_default = {
10861
11297
  ]
10862
11298
  }
10863
11299
  },
11300
+ {
11301
+ name: "CollectFeeOrderRecord",
11302
+ docs: [
11303
+ "On-chain record of a signed CollectFeeOrder.",
11304
+ "Created by `register_collect_fee_order` after Ed25519 verification.",
11305
+ "Read and marked collected by `batch_collect_redeem_early`.",
11306
+ "",
11307
+ 'PDA seeds: [b"collect_order", user, nonce_le_bytes]'
11308
+ ],
11309
+ type: {
11310
+ kind: "struct",
11311
+ fields: [
11312
+ {
11313
+ name: "user",
11314
+ type: "pubkey"
11315
+ },
11316
+ {
11317
+ name: "condition",
11318
+ type: "pubkey"
11319
+ },
11320
+ {
11321
+ name: "token_mint",
11322
+ type: "pubkey"
11323
+ },
11324
+ {
11325
+ name: "amount",
11326
+ type: "u64"
11327
+ },
11328
+ {
11329
+ name: "nonce",
11330
+ type: "u64"
11331
+ },
11332
+ {
11333
+ name: "expiry",
11334
+ type: "i64"
11335
+ },
11336
+ {
11337
+ name: "is_collected",
11338
+ type: "bool"
11339
+ },
11340
+ {
11341
+ name: "bump",
11342
+ type: "u8"
11343
+ }
11344
+ ]
11345
+ }
11346
+ },
10864
11347
  {
10865
11348
  name: "ComplementaryMatchEvent",
10866
11349
  type: {
@@ -16466,106 +16949,1135 @@ var referral_default = {
16466
16949
  ]
16467
16950
  };
16468
16951
 
16469
- // src/sdk.ts
16470
- var XMarketSDK = class {
16471
- constructor(config, wallet, marketOwner) {
16472
- this.networkConfig = config;
16473
- this.provider = new anchor5__namespace.AnchorProvider(
16474
- new web3_js.Connection(config.rpcUrl, "confirmed"),
16475
- wallet,
16476
- { commitment: "confirmed", preflightCommitment: "confirmed" }
16477
- );
16478
- anchor5__namespace.setProvider(this.provider);
16479
- this._programIds = config.programIds;
16480
- this._marketOwner = marketOwner ?? wallet.publicKey;
16481
- }
16482
- _withAddress(idl, address) {
16483
- return { ...idl, address: address.toBase58() };
16484
- }
16485
- get oracle() {
16486
- if (!this._oracle) {
16487
- const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
16488
- this._oracle = new OracleClient(program, this.provider, this._programIds);
16489
- }
16490
- return this._oracle;
16491
- }
16492
- get hook() {
16493
- if (!this._hook) {
16494
- const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
16495
- this._hook = new HookClient(program, this.provider, this._programIds);
16496
- }
16497
- return this._hook;
16498
- }
16499
- get market() {
16500
- if (!this._market) {
16501
- const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
16502
- this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
16503
- this._market.ctfClient = this.ctf;
16504
- this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
16505
- }
16506
- return this._market;
16507
- }
16508
- get ctf() {
16509
- if (!this._ctf) {
16510
- const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
16511
- this._ctf = new CtfClient(program, this.provider, this._programIds);
16512
- }
16513
- return this._ctf;
16514
- }
16515
- get clob() {
16516
- if (!this._clob) {
16517
- const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
16518
- this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
16519
- if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
16520
- this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
16521
- this._clob.feeClient = this.fee;
16522
- }
16523
- this._clob.ctfClient = this.ctf;
16524
- this._clob.qmConfigPda = this.market.configPda;
16525
- this._clob.hookClient = this.hook;
16526
- }
16527
- return this._clob;
16528
- }
16529
- get fee() {
16530
- if (!this._fee) {
16531
- if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
16532
- const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
16533
- this._fee = new FeeManagementClient(program, this.provider, this._programIds);
16534
- }
16535
- return this._fee;
16536
- }
16537
- get presale() {
16538
- if (!this._presale) {
16539
- if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
16540
- const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
16541
- this._presale = new PresaleClient(program, this.provider, this._programIds);
16542
- }
16543
- return this._presale;
16544
- }
16545
- get marketOracle() {
16546
- if (!this._marketOracle) {
16547
- if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
16548
- const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
16549
- this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
16550
- }
16551
- return this._marketOracle;
16552
- }
16553
- get admin() {
16554
- if (!this._admin) {
16555
- if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
16556
- const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
16557
- this._admin = new AdminClient(program, this.provider, this._programIds);
16558
- }
16559
- return this._admin;
16560
- }
16561
- get referral() {
16562
- if (!this._referral) {
16563
- if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
16564
- const program = new anchor5__namespace.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
16952
+ // src/idls/dispute.json
16953
+ var dispute_default = {
16954
+ address: "4toSDWDCcx37R6HZ78P71nDp3NNoJvcmQpzP4sfivVvL",
16955
+ metadata: {
16956
+ name: "dispute",
16957
+ version: "0.1.0",
16958
+ spec: "0.1.0",
16959
+ description: "Dispute program for XMarket \u2014 raise/resolve/claim disputes on prediction markets"
16960
+ },
16961
+ instructions: [
16962
+ {
16963
+ name: "claim",
16964
+ discriminator: [
16965
+ 62,
16966
+ 198,
16967
+ 214,
16968
+ 193,
16969
+ 213,
16970
+ 159,
16971
+ 108,
16972
+ 210
16973
+ ],
16974
+ accounts: [
16975
+ {
16976
+ name: "user",
16977
+ signer: true
16978
+ },
16979
+ {
16980
+ name: "dispute_config",
16981
+ pda: {
16982
+ seeds: [
16983
+ {
16984
+ kind: "const",
16985
+ value: [
16986
+ 100,
16987
+ 105,
16988
+ 115,
16989
+ 112,
16990
+ 117,
16991
+ 116,
16992
+ 101,
16993
+ 95,
16994
+ 99,
16995
+ 111,
16996
+ 110,
16997
+ 102,
16998
+ 105,
16999
+ 103
17000
+ ]
17001
+ },
17002
+ {
17003
+ kind: "account",
17004
+ path: "dispute_config.owner",
17005
+ account: "DisputeConfig"
17006
+ }
17007
+ ]
17008
+ }
17009
+ },
17010
+ {
17011
+ name: "dispute_market",
17012
+ pda: {
17013
+ seeds: [
17014
+ {
17015
+ kind: "const",
17016
+ value: [
17017
+ 100,
17018
+ 105,
17019
+ 115,
17020
+ 112,
17021
+ 117,
17022
+ 116,
17023
+ 101,
17024
+ 95,
17025
+ 109,
17026
+ 97,
17027
+ 114,
17028
+ 107,
17029
+ 101,
17030
+ 116
17031
+ ]
17032
+ },
17033
+ {
17034
+ kind: "arg",
17035
+ path: "condition_id"
17036
+ }
17037
+ ]
17038
+ }
17039
+ },
17040
+ {
17041
+ name: "user_dispute",
17042
+ writable: true,
17043
+ pda: {
17044
+ seeds: [
17045
+ {
17046
+ kind: "const",
17047
+ value: [
17048
+ 117,
17049
+ 115,
17050
+ 101,
17051
+ 114,
17052
+ 95,
17053
+ 100,
17054
+ 105,
17055
+ 115,
17056
+ 112,
17057
+ 117,
17058
+ 116,
17059
+ 101
17060
+ ]
17061
+ },
17062
+ {
17063
+ kind: "account",
17064
+ path: "user"
17065
+ },
17066
+ {
17067
+ kind: "arg",
17068
+ path: "condition_id"
17069
+ }
17070
+ ]
17071
+ }
17072
+ },
17073
+ {
17074
+ name: "dispute_vault",
17075
+ writable: true,
17076
+ pda: {
17077
+ seeds: [
17078
+ {
17079
+ kind: "account",
17080
+ path: "dispute_config"
17081
+ },
17082
+ {
17083
+ kind: "const",
17084
+ value: [
17085
+ 6,
17086
+ 221,
17087
+ 246,
17088
+ 225,
17089
+ 215,
17090
+ 101,
17091
+ 161,
17092
+ 147,
17093
+ 217,
17094
+ 203,
17095
+ 225,
17096
+ 70,
17097
+ 206,
17098
+ 235,
17099
+ 121,
17100
+ 172,
17101
+ 28,
17102
+ 180,
17103
+ 133,
17104
+ 237,
17105
+ 95,
17106
+ 91,
17107
+ 55,
17108
+ 145,
17109
+ 58,
17110
+ 140,
17111
+ 245,
17112
+ 133,
17113
+ 126,
17114
+ 255,
17115
+ 0,
17116
+ 169
17117
+ ]
17118
+ },
17119
+ {
17120
+ kind: "account",
17121
+ path: "dispute_config.collateral_mint",
17122
+ account: "DisputeConfig"
17123
+ }
17124
+ ],
17125
+ program: {
17126
+ kind: "const",
17127
+ value: [
17128
+ 140,
17129
+ 151,
17130
+ 37,
17131
+ 143,
17132
+ 78,
17133
+ 36,
17134
+ 137,
17135
+ 241,
17136
+ 187,
17137
+ 61,
17138
+ 16,
17139
+ 41,
17140
+ 20,
17141
+ 142,
17142
+ 13,
17143
+ 131,
17144
+ 11,
17145
+ 90,
17146
+ 19,
17147
+ 153,
17148
+ 218,
17149
+ 255,
17150
+ 16,
17151
+ 132,
17152
+ 4,
17153
+ 142,
17154
+ 123,
17155
+ 216,
17156
+ 219,
17157
+ 233,
17158
+ 248,
17159
+ 89
17160
+ ]
17161
+ }
17162
+ }
17163
+ },
17164
+ {
17165
+ name: "user_ata",
17166
+ writable: true
17167
+ },
17168
+ {
17169
+ name: "token_program",
17170
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
17171
+ }
17172
+ ],
17173
+ args: [
17174
+ {
17175
+ name: "condition_id",
17176
+ type: {
17177
+ array: [
17178
+ "u8",
17179
+ 32
17180
+ ]
17181
+ }
17182
+ }
17183
+ ]
17184
+ },
17185
+ {
17186
+ name: "initialize",
17187
+ discriminator: [
17188
+ 175,
17189
+ 175,
17190
+ 109,
17191
+ 31,
17192
+ 13,
17193
+ 152,
17194
+ 155,
17195
+ 237
17196
+ ],
17197
+ accounts: [
17198
+ {
17199
+ name: "owner",
17200
+ writable: true,
17201
+ signer: true
17202
+ },
17203
+ {
17204
+ name: "dispute_config",
17205
+ writable: true,
17206
+ pda: {
17207
+ seeds: [
17208
+ {
17209
+ kind: "const",
17210
+ value: [
17211
+ 100,
17212
+ 105,
17213
+ 115,
17214
+ 112,
17215
+ 117,
17216
+ 116,
17217
+ 101,
17218
+ 95,
17219
+ 99,
17220
+ 111,
17221
+ 110,
17222
+ 102,
17223
+ 105,
17224
+ 103
17225
+ ]
17226
+ },
17227
+ {
17228
+ kind: "account",
17229
+ path: "owner"
17230
+ }
17231
+ ]
17232
+ }
17233
+ },
17234
+ {
17235
+ name: "collateral_mint"
17236
+ },
17237
+ {
17238
+ name: "dispute_vault",
17239
+ docs: [
17240
+ "ATA owned by dispute_config PDA \u2014 holds USDS bonds from all dispute raisers"
17241
+ ],
17242
+ writable: true,
17243
+ pda: {
17244
+ seeds: [
17245
+ {
17246
+ kind: "account",
17247
+ path: "dispute_config"
17248
+ },
17249
+ {
17250
+ kind: "const",
17251
+ value: [
17252
+ 6,
17253
+ 221,
17254
+ 246,
17255
+ 225,
17256
+ 215,
17257
+ 101,
17258
+ 161,
17259
+ 147,
17260
+ 217,
17261
+ 203,
17262
+ 225,
17263
+ 70,
17264
+ 206,
17265
+ 235,
17266
+ 121,
17267
+ 172,
17268
+ 28,
17269
+ 180,
17270
+ 133,
17271
+ 237,
17272
+ 95,
17273
+ 91,
17274
+ 55,
17275
+ 145,
17276
+ 58,
17277
+ 140,
17278
+ 245,
17279
+ 133,
17280
+ 126,
17281
+ 255,
17282
+ 0,
17283
+ 169
17284
+ ]
17285
+ },
17286
+ {
17287
+ kind: "account",
17288
+ path: "collateral_mint"
17289
+ }
17290
+ ],
17291
+ program: {
17292
+ kind: "const",
17293
+ value: [
17294
+ 140,
17295
+ 151,
17296
+ 37,
17297
+ 143,
17298
+ 78,
17299
+ 36,
17300
+ 137,
17301
+ 241,
17302
+ 187,
17303
+ 61,
17304
+ 16,
17305
+ 41,
17306
+ 20,
17307
+ 142,
17308
+ 13,
17309
+ 131,
17310
+ 11,
17311
+ 90,
17312
+ 19,
17313
+ 153,
17314
+ 218,
17315
+ 255,
17316
+ 16,
17317
+ 132,
17318
+ 4,
17319
+ 142,
17320
+ 123,
17321
+ 216,
17322
+ 219,
17323
+ 233,
17324
+ 248,
17325
+ 89
17326
+ ]
17327
+ }
17328
+ }
17329
+ },
17330
+ {
17331
+ name: "token_program",
17332
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
17333
+ },
17334
+ {
17335
+ name: "associated_token_program",
17336
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
17337
+ },
17338
+ {
17339
+ name: "system_program",
17340
+ address: "11111111111111111111111111111111"
17341
+ }
17342
+ ],
17343
+ args: []
17344
+ },
17345
+ {
17346
+ name: "raise_dispute",
17347
+ discriminator: [
17348
+ 41,
17349
+ 243,
17350
+ 1,
17351
+ 51,
17352
+ 150,
17353
+ 95,
17354
+ 246,
17355
+ 73
17356
+ ],
17357
+ accounts: [
17358
+ {
17359
+ name: "user",
17360
+ signer: true
17361
+ },
17362
+ {
17363
+ name: "payer",
17364
+ writable: true,
17365
+ signer: true
17366
+ },
17367
+ {
17368
+ name: "dispute_config",
17369
+ pda: {
17370
+ seeds: [
17371
+ {
17372
+ kind: "const",
17373
+ value: [
17374
+ 100,
17375
+ 105,
17376
+ 115,
17377
+ 112,
17378
+ 117,
17379
+ 116,
17380
+ 101,
17381
+ 95,
17382
+ 99,
17383
+ 111,
17384
+ 110,
17385
+ 102,
17386
+ 105,
17387
+ 103
17388
+ ]
17389
+ },
17390
+ {
17391
+ kind: "account",
17392
+ path: "dispute_config.owner",
17393
+ account: "DisputeConfig"
17394
+ }
17395
+ ]
17396
+ }
17397
+ },
17398
+ {
17399
+ name: "dispute_market",
17400
+ writable: true,
17401
+ pda: {
17402
+ seeds: [
17403
+ {
17404
+ kind: "const",
17405
+ value: [
17406
+ 100,
17407
+ 105,
17408
+ 115,
17409
+ 112,
17410
+ 117,
17411
+ 116,
17412
+ 101,
17413
+ 95,
17414
+ 109,
17415
+ 97,
17416
+ 114,
17417
+ 107,
17418
+ 101,
17419
+ 116
17420
+ ]
17421
+ },
17422
+ {
17423
+ kind: "arg",
17424
+ path: "condition_id"
17425
+ }
17426
+ ]
17427
+ }
17428
+ },
17429
+ {
17430
+ name: "user_dispute",
17431
+ writable: true,
17432
+ pda: {
17433
+ seeds: [
17434
+ {
17435
+ kind: "const",
17436
+ value: [
17437
+ 117,
17438
+ 115,
17439
+ 101,
17440
+ 114,
17441
+ 95,
17442
+ 100,
17443
+ 105,
17444
+ 115,
17445
+ 112,
17446
+ 117,
17447
+ 116,
17448
+ 101
17449
+ ]
17450
+ },
17451
+ {
17452
+ kind: "account",
17453
+ path: "user"
17454
+ },
17455
+ {
17456
+ kind: "arg",
17457
+ path: "condition_id"
17458
+ }
17459
+ ]
17460
+ }
17461
+ },
17462
+ {
17463
+ name: "user_ata",
17464
+ writable: true,
17465
+ pda: {
17466
+ seeds: [
17467
+ {
17468
+ kind: "account",
17469
+ path: "user"
17470
+ },
17471
+ {
17472
+ kind: "const",
17473
+ value: [
17474
+ 6,
17475
+ 221,
17476
+ 246,
17477
+ 225,
17478
+ 215,
17479
+ 101,
17480
+ 161,
17481
+ 147,
17482
+ 217,
17483
+ 203,
17484
+ 225,
17485
+ 70,
17486
+ 206,
17487
+ 235,
17488
+ 121,
17489
+ 172,
17490
+ 28,
17491
+ 180,
17492
+ 133,
17493
+ 237,
17494
+ 95,
17495
+ 91,
17496
+ 55,
17497
+ 145,
17498
+ 58,
17499
+ 140,
17500
+ 245,
17501
+ 133,
17502
+ 126,
17503
+ 255,
17504
+ 0,
17505
+ 169
17506
+ ]
17507
+ },
17508
+ {
17509
+ kind: "account",
17510
+ path: "dispute_config.collateral_mint",
17511
+ account: "DisputeConfig"
17512
+ }
17513
+ ],
17514
+ program: {
17515
+ kind: "const",
17516
+ value: [
17517
+ 140,
17518
+ 151,
17519
+ 37,
17520
+ 143,
17521
+ 78,
17522
+ 36,
17523
+ 137,
17524
+ 241,
17525
+ 187,
17526
+ 61,
17527
+ 16,
17528
+ 41,
17529
+ 20,
17530
+ 142,
17531
+ 13,
17532
+ 131,
17533
+ 11,
17534
+ 90,
17535
+ 19,
17536
+ 153,
17537
+ 218,
17538
+ 255,
17539
+ 16,
17540
+ 132,
17541
+ 4,
17542
+ 142,
17543
+ 123,
17544
+ 216,
17545
+ 219,
17546
+ 233,
17547
+ 248,
17548
+ 89
17549
+ ]
17550
+ }
17551
+ }
17552
+ },
17553
+ {
17554
+ name: "dispute_vault",
17555
+ writable: true,
17556
+ pda: {
17557
+ seeds: [
17558
+ {
17559
+ kind: "account",
17560
+ path: "dispute_config"
17561
+ },
17562
+ {
17563
+ kind: "const",
17564
+ value: [
17565
+ 6,
17566
+ 221,
17567
+ 246,
17568
+ 225,
17569
+ 215,
17570
+ 101,
17571
+ 161,
17572
+ 147,
17573
+ 217,
17574
+ 203,
17575
+ 225,
17576
+ 70,
17577
+ 206,
17578
+ 235,
17579
+ 121,
17580
+ 172,
17581
+ 28,
17582
+ 180,
17583
+ 133,
17584
+ 237,
17585
+ 95,
17586
+ 91,
17587
+ 55,
17588
+ 145,
17589
+ 58,
17590
+ 140,
17591
+ 245,
17592
+ 133,
17593
+ 126,
17594
+ 255,
17595
+ 0,
17596
+ 169
17597
+ ]
17598
+ },
17599
+ {
17600
+ kind: "account",
17601
+ path: "dispute_config.collateral_mint",
17602
+ account: "DisputeConfig"
17603
+ }
17604
+ ],
17605
+ program: {
17606
+ kind: "const",
17607
+ value: [
17608
+ 140,
17609
+ 151,
17610
+ 37,
17611
+ 143,
17612
+ 78,
17613
+ 36,
17614
+ 137,
17615
+ 241,
17616
+ 187,
17617
+ 61,
17618
+ 16,
17619
+ 41,
17620
+ 20,
17621
+ 142,
17622
+ 13,
17623
+ 131,
17624
+ 11,
17625
+ 90,
17626
+ 19,
17627
+ 153,
17628
+ 218,
17629
+ 255,
17630
+ 16,
17631
+ 132,
17632
+ 4,
17633
+ 142,
17634
+ 123,
17635
+ 216,
17636
+ 219,
17637
+ 233,
17638
+ 248,
17639
+ 89
17640
+ ]
17641
+ }
17642
+ }
17643
+ },
17644
+ {
17645
+ name: "token_program",
17646
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
17647
+ },
17648
+ {
17649
+ name: "associated_token_program",
17650
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
17651
+ },
17652
+ {
17653
+ name: "system_program",
17654
+ address: "11111111111111111111111111111111"
17655
+ }
17656
+ ],
17657
+ args: [
17658
+ {
17659
+ name: "condition_id",
17660
+ type: {
17661
+ array: [
17662
+ "u8",
17663
+ 32
17664
+ ]
17665
+ }
17666
+ }
17667
+ ]
17668
+ },
17669
+ {
17670
+ name: "resolve_dispute",
17671
+ discriminator: [
17672
+ 231,
17673
+ 6,
17674
+ 202,
17675
+ 6,
17676
+ 96,
17677
+ 103,
17678
+ 12,
17679
+ 230
17680
+ ],
17681
+ accounts: [
17682
+ {
17683
+ name: "admin",
17684
+ signer: true
17685
+ },
17686
+ {
17687
+ name: "dispute_config",
17688
+ pda: {
17689
+ seeds: [
17690
+ {
17691
+ kind: "const",
17692
+ value: [
17693
+ 100,
17694
+ 105,
17695
+ 115,
17696
+ 112,
17697
+ 117,
17698
+ 116,
17699
+ 101,
17700
+ 95,
17701
+ 99,
17702
+ 111,
17703
+ 110,
17704
+ 102,
17705
+ 105,
17706
+ 103
17707
+ ]
17708
+ },
17709
+ {
17710
+ kind: "account",
17711
+ path: "dispute_config.owner",
17712
+ account: "DisputeConfig"
17713
+ }
17714
+ ]
17715
+ }
17716
+ },
17717
+ {
17718
+ name: "dispute_market",
17719
+ writable: true,
17720
+ pda: {
17721
+ seeds: [
17722
+ {
17723
+ kind: "const",
17724
+ value: [
17725
+ 100,
17726
+ 105,
17727
+ 115,
17728
+ 112,
17729
+ 117,
17730
+ 116,
17731
+ 101,
17732
+ 95,
17733
+ 109,
17734
+ 97,
17735
+ 114,
17736
+ 107,
17737
+ 101,
17738
+ 116
17739
+ ]
17740
+ },
17741
+ {
17742
+ kind: "arg",
17743
+ path: "condition_id"
17744
+ }
17745
+ ]
17746
+ }
17747
+ }
17748
+ ],
17749
+ args: [
17750
+ {
17751
+ name: "condition_id",
17752
+ type: {
17753
+ array: [
17754
+ "u8",
17755
+ 32
17756
+ ]
17757
+ }
17758
+ },
17759
+ {
17760
+ name: "amount",
17761
+ type: "u64"
17762
+ },
17763
+ {
17764
+ name: "is_refunded",
17765
+ type: "bool"
17766
+ }
17767
+ ]
17768
+ },
17769
+ {
17770
+ name: "set_admin",
17771
+ discriminator: [
17772
+ 251,
17773
+ 163,
17774
+ 0,
17775
+ 52,
17776
+ 91,
17777
+ 194,
17778
+ 187,
17779
+ 92
17780
+ ],
17781
+ accounts: [
17782
+ {
17783
+ name: "owner",
17784
+ signer: true
17785
+ },
17786
+ {
17787
+ name: "dispute_config",
17788
+ writable: true,
17789
+ pda: {
17790
+ seeds: [
17791
+ {
17792
+ kind: "const",
17793
+ value: [
17794
+ 100,
17795
+ 105,
17796
+ 115,
17797
+ 112,
17798
+ 117,
17799
+ 116,
17800
+ 101,
17801
+ 95,
17802
+ 99,
17803
+ 111,
17804
+ 110,
17805
+ 102,
17806
+ 105,
17807
+ 103
17808
+ ]
17809
+ },
17810
+ {
17811
+ kind: "account",
17812
+ path: "owner"
17813
+ }
17814
+ ]
17815
+ }
17816
+ }
17817
+ ],
17818
+ args: [
17819
+ {
17820
+ name: "new_admin",
17821
+ type: "pubkey"
17822
+ }
17823
+ ]
17824
+ }
17825
+ ],
17826
+ accounts: [
17827
+ {
17828
+ name: "DisputeConfig",
17829
+ discriminator: [
17830
+ 230,
17831
+ 88,
17832
+ 200,
17833
+ 99,
17834
+ 12,
17835
+ 93,
17836
+ 56,
17837
+ 156
17838
+ ]
17839
+ },
17840
+ {
17841
+ name: "DisputeMarket",
17842
+ discriminator: [
17843
+ 235,
17844
+ 222,
17845
+ 113,
17846
+ 250,
17847
+ 83,
17848
+ 196,
17849
+ 239,
17850
+ 159
17851
+ ]
17852
+ },
17853
+ {
17854
+ name: "UserDispute",
17855
+ discriminator: [
17856
+ 54,
17857
+ 252,
17858
+ 42,
17859
+ 67,
17860
+ 211,
17861
+ 11,
17862
+ 192,
17863
+ 188
17864
+ ]
17865
+ }
17866
+ ],
17867
+ types: [
17868
+ {
17869
+ name: "DisputeConfig",
17870
+ type: {
17871
+ kind: "struct",
17872
+ fields: [
17873
+ {
17874
+ name: "version",
17875
+ type: "u8"
17876
+ },
17877
+ {
17878
+ name: "owner",
17879
+ type: "pubkey"
17880
+ },
17881
+ {
17882
+ name: "admin",
17883
+ type: "pubkey"
17884
+ },
17885
+ {
17886
+ name: "collateral_mint",
17887
+ type: "pubkey"
17888
+ },
17889
+ {
17890
+ name: "bump",
17891
+ type: "u8"
17892
+ }
17893
+ ]
17894
+ }
17895
+ },
17896
+ {
17897
+ name: "DisputeMarket",
17898
+ type: {
17899
+ kind: "struct",
17900
+ fields: [
17901
+ {
17902
+ name: "version",
17903
+ type: "u8"
17904
+ },
17905
+ {
17906
+ name: "condition_id",
17907
+ type: {
17908
+ array: [
17909
+ "u8",
17910
+ 32
17911
+ ]
17912
+ }
17913
+ },
17914
+ {
17915
+ name: "deadline",
17916
+ type: "i64"
17917
+ },
17918
+ {
17919
+ name: "bond",
17920
+ type: "u64"
17921
+ },
17922
+ {
17923
+ name: "amount",
17924
+ type: "u64"
17925
+ },
17926
+ {
17927
+ name: "is_resolved",
17928
+ type: "bool"
17929
+ },
17930
+ {
17931
+ name: "bump",
17932
+ type: "u8"
17933
+ }
17934
+ ]
17935
+ }
17936
+ },
17937
+ {
17938
+ name: "UserDispute",
17939
+ type: {
17940
+ kind: "struct",
17941
+ fields: [
17942
+ {
17943
+ name: "version",
17944
+ type: "u8"
17945
+ },
17946
+ {
17947
+ name: "user",
17948
+ type: "pubkey"
17949
+ },
17950
+ {
17951
+ name: "condition_id",
17952
+ type: {
17953
+ array: [
17954
+ "u8",
17955
+ 32
17956
+ ]
17957
+ }
17958
+ },
17959
+ {
17960
+ name: "amount",
17961
+ type: "u64"
17962
+ },
17963
+ {
17964
+ name: "bump",
17965
+ type: "u8"
17966
+ }
17967
+ ]
17968
+ }
17969
+ }
17970
+ ]
17971
+ };
17972
+
17973
+ // src/sdk.ts
17974
+ var XMarketSDK = class {
17975
+ constructor(config, wallet, marketOwner) {
17976
+ this.networkConfig = config;
17977
+ this.provider = new anchor5__namespace.AnchorProvider(
17978
+ new web3_js.Connection(config.rpcUrl, "confirmed"),
17979
+ wallet,
17980
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
17981
+ );
17982
+ anchor5__namespace.setProvider(this.provider);
17983
+ this._programIds = config.programIds;
17984
+ this._marketOwner = marketOwner ?? wallet.publicKey;
17985
+ }
17986
+ _withAddress(idl, address) {
17987
+ return { ...idl, address: address.toBase58() };
17988
+ }
17989
+ get oracle() {
17990
+ if (!this._oracle) {
17991
+ const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
17992
+ this._oracle = new OracleClient(program, this.provider, this._programIds);
17993
+ }
17994
+ return this._oracle;
17995
+ }
17996
+ get hook() {
17997
+ if (!this._hook) {
17998
+ const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
17999
+ this._hook = new HookClient(program, this.provider, this._programIds);
18000
+ }
18001
+ return this._hook;
18002
+ }
18003
+ get market() {
18004
+ if (!this._market) {
18005
+ const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
18006
+ this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
18007
+ this._market.ctfClient = this.ctf;
18008
+ this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
18009
+ }
18010
+ return this._market;
18011
+ }
18012
+ get ctf() {
18013
+ if (!this._ctf) {
18014
+ const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
18015
+ this._ctf = new CtfClient(program, this.provider, this._programIds);
18016
+ }
18017
+ return this._ctf;
18018
+ }
18019
+ get clob() {
18020
+ if (!this._clob) {
18021
+ const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
18022
+ this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
18023
+ if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
18024
+ this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
18025
+ this._clob.feeClient = this.fee;
18026
+ }
18027
+ this._clob.ctfClient = this.ctf;
18028
+ this._clob.qmConfigPda = this.market.configPda;
18029
+ this._clob.hookClient = this.hook;
18030
+ }
18031
+ return this._clob;
18032
+ }
18033
+ get fee() {
18034
+ if (!this._fee) {
18035
+ if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
18036
+ const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
18037
+ this._fee = new FeeManagementClient(program, this.provider, this._programIds);
18038
+ }
18039
+ return this._fee;
18040
+ }
18041
+ get presale() {
18042
+ if (!this._presale) {
18043
+ if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
18044
+ const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
18045
+ this._presale = new PresaleClient(program, this.provider, this._programIds);
18046
+ }
18047
+ return this._presale;
18048
+ }
18049
+ get marketOracle() {
18050
+ if (!this._marketOracle) {
18051
+ if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
18052
+ const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
18053
+ this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
18054
+ }
18055
+ return this._marketOracle;
18056
+ }
18057
+ get admin() {
18058
+ if (!this._admin) {
18059
+ if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
18060
+ const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
18061
+ this._admin = new AdminClient(program, this.provider, this._programIds);
18062
+ }
18063
+ return this._admin;
18064
+ }
18065
+ get referral() {
18066
+ if (!this._referral) {
18067
+ if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
18068
+ const program = new anchor5__namespace.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
16565
18069
  this._referral = new ReferralClient(program, this.provider, this._programIds);
16566
18070
  }
16567
18071
  return this._referral;
16568
18072
  }
18073
+ get dispute() {
18074
+ if (!this._dispute) {
18075
+ if (!this._programIds.dispute) throw new Error("dispute program ID not configured in NetworkConfig");
18076
+ const program = new anchor5__namespace.Program(this._withAddress(dispute_default, this._programIds.dispute), this.provider);
18077
+ this._dispute = new DisputeClient(program, this.provider, this._programIds);
18078
+ }
18079
+ return this._dispute;
18080
+ }
16569
18081
  };
16570
18082
  var MAX_APPROVE_AMOUNT = new BN4__default.default("18446744073709551615");
16571
18083
  function buildCreateUserAtasTx(condition, user, payer, programIds) {
@@ -16642,6 +18154,7 @@ exports.AccountNotFoundError = AccountNotFoundError;
16642
18154
  exports.AdminClient = AdminClient;
16643
18155
  exports.ClobClient = ClobClient;
16644
18156
  exports.CtfClient = CtfClient;
18157
+ exports.DisputeClient = DisputeClient;
16645
18158
  exports.FEE_DENOMINATOR = FEE_DENOMINATOR;
16646
18159
  exports.FeeManagementClient = FeeManagementClient;
16647
18160
  exports.HookClient = HookClient;