@theliem/xmarket-sdk 3.12.0 → 3.16.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
@@ -50,6 +50,7 @@ var SEEDS = {
50
50
  clobConfig: Buffer.from("clob_config"),
51
51
  order: Buffer.from("order"),
52
52
  feeConfig: Buffer.from("fee_config"),
53
+ referralConfig: Buffer.from("referral_config"),
53
54
  questionFee: Buffer.from("question_fee"),
54
55
  marketFee: Buffer.from("market_fee"),
55
56
  // Presale
@@ -250,6 +251,14 @@ var PDA = class {
250
251
  programIds.marketOracle
251
252
  );
252
253
  }
254
+ // ─── Referral Program ────────────────────────────────────────────────────
255
+ static referralConfig(owner, programIds) {
256
+ if (!programIds.referral) throw new Error("referral program ID not configured");
257
+ return web3_js.PublicKey.findProgramAddressSync(
258
+ [SEEDS.referralConfig, owner.toBuffer()],
259
+ programIds.referral
260
+ );
261
+ }
253
262
  // ─── Admin Contract ──────────────────────────────────────────────────────
254
263
  static adminConfig(owner, programIds) {
255
264
  if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
@@ -522,7 +531,7 @@ var QuestionStatus = /* @__PURE__ */ ((QuestionStatus2) => {
522
531
  QuestionStatus2["Resolved"] = "resolved";
523
532
  return QuestionStatus2;
524
533
  })(QuestionStatus || {});
525
- var FEE_DENOMINATOR = 1e6;
534
+ var FEE_DENOMINATOR = 1e4;
526
535
  var XMarketError = class extends Error {
527
536
  constructor(message, code) {
528
537
  super(message);
@@ -587,6 +596,8 @@ var MarketClient = class {
587
596
  const [noMint] = PDA.noMint(conditionPda, this.programIds);
588
597
  const [mintAuthority] = PDA.mintAuthority(conditionPda, this.programIds);
589
598
  const [collateralVault] = PDA.collateralVault(params.collateralMint, this.programIds);
599
+ if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
600
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
590
601
  const tx = await this.program.methods.createQuestionAdmin({
591
602
  questionId: Array.from(questionId),
592
603
  contentHash: Array.from(contentHash),
@@ -606,6 +617,8 @@ var MarketClient = class {
606
617
  mintAuthority,
607
618
  collateralVault,
608
619
  conditionalTokensProgram: this.programIds.conditionalTokens,
620
+ questionFee: questionFeePda,
621
+ feeManagementProgram: this.programIds.feeManagement,
609
622
  tokenProgram: splToken.TOKEN_2022_PROGRAM_ID,
610
623
  systemProgram: web3_js.SystemProgram.programId,
611
624
  rent: web3_js.SYSVAR_RENT_PUBKEY
@@ -804,9 +817,25 @@ var MarketClient = class {
804
817
  * @param creator presale creator pubkey (stored in question)
805
818
  * @param currencyMint collateral mint
806
819
  */
807
- async approvePresale(presalePda, contentHash, hookProgram, authorizedClob, expirationTime, creator, currencyMint, caller = this.walletPubkey, payer = caller) {
820
+ async approvePresale(params) {
821
+ const {
822
+ presalePda,
823
+ contentHash,
824
+ hookProgram,
825
+ authorizedClob,
826
+ expirationTime,
827
+ creator,
828
+ currencyMint,
829
+ referralAddress,
830
+ companyAddress,
831
+ adminOwner
832
+ } = params;
833
+ const caller = params.caller ?? this.walletPubkey;
834
+ const payer = params.payer ?? caller;
808
835
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
809
836
  if (!this.programIds.marketOracle) throw new Error("marketOracle program ID not configured");
837
+ if (!this.programIds.feeManagement) throw new Error("feeManagement program ID not configured");
838
+ if (!this.programIds.adminContract) throw new Error("adminContract program ID not configured");
810
839
  const questionId = presalePda.toBytes();
811
840
  const [questionPda] = PDA.question(this.configPda, questionId, this.programIds);
812
841
  const marketConfig = await this.fetchConfig();
@@ -819,7 +848,14 @@ var MarketClient = class {
819
848
  const [collateralVault] = PDA.collateralVault(currencyMint, this.programIds);
820
849
  const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
821
850
  const marketOracleVault = splToken.getAssociatedTokenAddressSync(currencyMint, marketOraclePda, true);
822
- const tx = await this.program.methods.approvePresale({
851
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
852
+ const presaleVault = splToken.getAssociatedTokenAddressSync(currencyMint, presalePda, true);
853
+ const referralTokenAccount = splToken.getAssociatedTokenAddressSync(currencyMint, referralAddress);
854
+ const companyTokenAccount = splToken.getAssociatedTokenAddressSync(currencyMint, companyAddress);
855
+ const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
856
+ const adminVault = splToken.getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
857
+ const [claimRecord] = PDA.claimRecord(conditionPda.toBytes(), this.programIds);
858
+ const builder = this.program.methods.approvePresale({
823
859
  contentHash: Array.from(contentHash),
824
860
  hookProgram,
825
861
  authorizedClob,
@@ -840,15 +876,38 @@ var MarketClient = class {
840
876
  collateralVault,
841
877
  marketOracle: marketOraclePda,
842
878
  marketOracleVault,
879
+ presaleVault,
880
+ referralTokenAccount,
881
+ companyTokenAccount,
882
+ adminVault,
883
+ adminConfig,
884
+ claimRecord,
885
+ questionFee: questionFeePda,
886
+ feeManagementProgram: this.programIds.feeManagement,
843
887
  conditionalTokensProgram: this.programIds.conditionalTokens,
844
888
  presaleProgram: this.programIds.presale,
845
889
  marketOracleProgram: this.programIds.marketOracle,
890
+ adminProgram: this.programIds.adminContract,
846
891
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
847
892
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
848
893
  associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
849
894
  systemProgram: web3_js.SystemProgram.programId,
850
895
  rent: web3_js.SYSVAR_RENT_PUBKEY
851
- }).transaction();
896
+ });
897
+ let tx;
898
+ if (params.lookupTable) {
899
+ const ix = await builder.instruction();
900
+ const cu = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 14e5 });
901
+ const { blockhash } = await this.provider.connection.getLatestBlockhash();
902
+ const msg = new web3_js.TransactionMessage({
903
+ payerKey: payer,
904
+ recentBlockhash: blockhash,
905
+ instructions: [cu, ix]
906
+ }).compileToV0Message([params.lookupTable]);
907
+ tx = new web3_js.VersionedTransaction(msg);
908
+ } else {
909
+ tx = await builder.transaction();
910
+ }
852
911
  return { tx, questionPda, conditionPda, marketOraclePda, marketOracleVault };
853
912
  }
854
913
  /**
@@ -1338,6 +1397,49 @@ function buildBatchedEd25519Instruction(orders) {
1338
1397
  });
1339
1398
  }
1340
1399
  var IX_SYSVAR = web3_js.SYSVAR_INSTRUCTIONS_PUBKEY;
1400
+ function serializeCollectFeeOrderToBytes(order) {
1401
+ const buf = new Uint8Array(120);
1402
+ buf.set(order.user.toBytes(), 0);
1403
+ buf.set(order.condition.toBytes(), 32);
1404
+ buf.set(order.tokenMint.toBytes(), 64);
1405
+ buf.set(order.amount.toArrayLike(Buffer, "le", 8), 96);
1406
+ buf.set(order.nonce.toArrayLike(Buffer, "le", 8), 104);
1407
+ buf.set(order.expiry.toArrayLike(Buffer, "le", 8), 112);
1408
+ return buf;
1409
+ }
1410
+ function buildBatchedCollectFeeEd25519Instruction(orders) {
1411
+ const N = orders.length;
1412
+ if (N === 0) throw new Error("At least 1 order required");
1413
+ const MSG_SIZE = 120;
1414
+ const SIG_SIZE = 64;
1415
+ const PK_SIZE = 32;
1416
+ const HEADER = 2 + N * 14;
1417
+ const sigBase = HEADER;
1418
+ const pkBase = sigBase + N * SIG_SIZE;
1419
+ const msgBase = pkBase + N * PK_SIZE;
1420
+ const totalSize = msgBase + N * MSG_SIZE;
1421
+ const data = Buffer.alloc(totalSize);
1422
+ data[0] = N;
1423
+ data[1] = 0;
1424
+ for (let i = 0; i < N; i++) {
1425
+ const e = 2 + i * 14;
1426
+ data.writeUInt16LE(sigBase + i * SIG_SIZE, e);
1427
+ data.writeUInt16LE(65535, e + 2);
1428
+ data.writeUInt16LE(pkBase + i * PK_SIZE, e + 4);
1429
+ data.writeUInt16LE(65535, e + 6);
1430
+ data.writeUInt16LE(msgBase + i * MSG_SIZE, e + 8);
1431
+ data.writeUInt16LE(MSG_SIZE, e + 10);
1432
+ data.writeUInt16LE(65535, e + 12);
1433
+ data.set(orders[i].signature, sigBase + i * SIG_SIZE);
1434
+ data.set(orders[i].order.user.toBytes(), pkBase + i * PK_SIZE);
1435
+ data.set(serializeCollectFeeOrderToBytes(orders[i].order), msgBase + i * MSG_SIZE);
1436
+ }
1437
+ return new web3_js.TransactionInstruction({
1438
+ keys: [],
1439
+ programId: web3_js.Ed25519Program.programId,
1440
+ data
1441
+ });
1442
+ }
1341
1443
  function buildOrder(params) {
1342
1444
  return {
1343
1445
  maker: params.maker,
@@ -1455,10 +1557,17 @@ var ClobClient = class {
1455
1557
  if (!this.feeClient || !this.feeConfigOwner) return void 0;
1456
1558
  if (!this._companyAddress) {
1457
1559
  const cfg = await this.feeClient.fetchFeeConfig(this.feeConfigOwner);
1458
- if (cfg) this._companyAddress = cfg.companyAddress;
1560
+ if (cfg) {
1561
+ this._companyAddress = cfg.companyAddress;
1562
+ this._referralVault = cfg.referralVault;
1563
+ }
1459
1564
  }
1460
1565
  return this._companyAddress;
1461
1566
  }
1567
+ async referralVault() {
1568
+ await this.companyAddress();
1569
+ return this._referralVault;
1570
+ }
1462
1571
  get walletPubkey() {
1463
1572
  return this.provider.wallet.publicKey;
1464
1573
  }
@@ -1549,6 +1658,7 @@ var ClobClient = class {
1549
1658
  }
1550
1659
  if (this.programIds.feeManagement && this.feeConfigOwner) {
1551
1660
  const companyAddr = await this.companyAddress();
1661
+ const refVault = await this.referralVault();
1552
1662
  addresses.push(
1553
1663
  this.programIds.feeManagement,
1554
1664
  PDA.feeConfig(this.feeConfigOwner, this.programIds)[0],
@@ -1558,6 +1668,10 @@ var ClobClient = class {
1558
1668
  addresses.push(splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr));
1559
1669
  }
1560
1670
  addresses.push(payer);
1671
+ if (refVault) {
1672
+ addresses.push(refVault);
1673
+ }
1674
+ addresses.push(splToken.TOKEN_PROGRAM_ID);
1561
1675
  }
1562
1676
  const slot = await connection.getSlot("finalized");
1563
1677
  const [createIx, altAddress] = web3_js.AddressLookupTableProgram.createLookupTable({
@@ -1592,8 +1706,8 @@ var ClobClient = class {
1592
1706
  async _sendLegacyTxSig(instructions) {
1593
1707
  const { connection } = this.provider;
1594
1708
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1595
- const { Transaction: Transaction8 } = await import('@solana/web3.js');
1596
- const tx = new Transaction8();
1709
+ const { Transaction: Transaction10 } = await import('@solana/web3.js');
1710
+ const tx = new Transaction10();
1597
1711
  tx.recentBlockhash = blockhash;
1598
1712
  tx.feePayer = this.walletPubkey;
1599
1713
  tx.add(...instructions);
@@ -1619,10 +1733,10 @@ ${logs.join("\n")}`);
1619
1733
  connection.getAccountInfo(clobYesAta),
1620
1734
  connection.getAccountInfo(clobNoAta)
1621
1735
  ]);
1622
- const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction3 } = await import('@solana/spl-token');
1736
+ const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction4 } = await import('@solana/spl-token');
1623
1737
  const ixs = [];
1624
1738
  if (!yesInfo) {
1625
- ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1739
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1626
1740
  this.walletPubkey,
1627
1741
  clobYesAta,
1628
1742
  clobConfig,
@@ -1631,7 +1745,7 @@ ${logs.join("\n")}`);
1631
1745
  ));
1632
1746
  }
1633
1747
  if (!noInfo) {
1634
- ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1748
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1635
1749
  this.walletPubkey,
1636
1750
  clobNoAta,
1637
1751
  clobConfig,
@@ -1815,7 +1929,8 @@ ${logs.join("\n")}`);
1815
1929
  let feeAccounts = [];
1816
1930
  if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1817
1931
  const companyAddr = await this.companyAddress();
1818
- if (companyAddr) {
1932
+ const refVault = await this.referralVault();
1933
+ if (companyAddr && refVault) {
1819
1934
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1820
1935
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
1821
1936
  if (feeOverrideExists) {
@@ -1825,7 +1940,8 @@ ${logs.join("\n")}`);
1825
1940
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1826
1941
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
1827
1942
  { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1828
- { pubkey: oracleVault, isSigner: false, isWritable: true }
1943
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
1944
+ { pubkey: refVault, isSigner: false, isWritable: true }
1829
1945
  ];
1830
1946
  }
1831
1947
  }
@@ -2069,7 +2185,8 @@ ${logs.join("\n")}`);
2069
2185
  );
2070
2186
  if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
2071
2187
  const companyAddr = await this.companyAddress();
2072
- if (companyAddr) {
2188
+ const refVault = await this.referralVault();
2189
+ if (companyAddr && refVault) {
2073
2190
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2074
2191
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2075
2192
  if (feeOverrideExists) {
@@ -2079,7 +2196,9 @@ ${logs.join("\n")}`);
2079
2196
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2080
2197
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2081
2198
  { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2082
- { pubkey: oracleVault, isSigner: false, isWritable: true }
2199
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2200
+ { pubkey: refVault, isSigner: false, isWritable: true },
2201
+ { pubkey: splToken.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2083
2202
  );
2084
2203
  }
2085
2204
  }
@@ -2350,6 +2469,103 @@ ${logs.join("\n")}`);
2350
2469
  }
2351
2470
  return this._buildUnsignedVtx(ixs, alt, payer);
2352
2471
  }
2472
+ // ─── batchCollectRedeemEarly ─────────────────────────────────────────────────
2473
+ /**
2474
+ * Build VersionedTransaction for batchCollectRedeemEarly.
2475
+ *
2476
+ * Flow: Ed25519 ix (user sigs) + batchCollectRedeemEarly ix.
2477
+ * Each SignedCollectFeeOrder authorizes CLOB to collect `amount` winning tokens
2478
+ * from that user, redeem via CTF, then distribute as fees.
2479
+ *
2480
+ * @param signedOrders - Array of { order, signature } from winning users
2481
+ * @param condition - Market condition PDA
2482
+ * @param outcomeIndex - 0 = NO wins, 1 = YES wins
2483
+ * @param operator - Whitelisted operator pubkey (must sign)
2484
+ * @param payer - Fee payer pubkey (must sign)
2485
+ * @param opts.marketOracleVault - MarketOracle vault for fee distribution
2486
+ */
2487
+ async buildBatchCollectRedeemEarlyTx(signedOrders, condition, outcomeIndex, operator, payer, opts) {
2488
+ if (signedOrders.length === 0) throw new InvalidParamError("At least 1 order required");
2489
+ const collateralMint = this.networkConfig.defaultCollateral.mint;
2490
+ const cfg = await this.fetchConfig();
2491
+ if (!cfg) throw new InvalidParamError("CLOB config not found on-chain");
2492
+ const clobConfig = this.configPda();
2493
+ const [yesMint] = PDA.yesMint(condition, this.programIds);
2494
+ const [noMint] = PDA.noMint(condition, this.programIds);
2495
+ const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
2496
+ const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
2497
+ const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2498
+ const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfig, true, splToken.TOKEN_2022_PROGRAM_ID);
2499
+ const outcomeMint = outcomeIndex === 1 ? yesMint : noMint;
2500
+ const [extraAccountMeta] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
2501
+ const [hookConfig] = PDA.hookConfig(this.programIds);
2502
+ const [clobYesPosition] = PDA.position(condition, 1, clobConfig, this.programIds);
2503
+ const [clobNoPosition] = PDA.position(condition, 0, clobConfig, this.programIds);
2504
+ const userAccounts = [];
2505
+ for (const { order } of signedOrders) {
2506
+ const userTokenAta = splToken.getAssociatedTokenAddressSync(outcomeMint, order.user, false, splToken.TOKEN_2022_PROGRAM_ID);
2507
+ const [userPosition] = PDA.position(condition, outcomeIndex, order.user, this.programIds);
2508
+ userAccounts.push(
2509
+ { pubkey: order.user, isSigner: false, isWritable: false },
2510
+ { pubkey: userTokenAta, isSigner: false, isWritable: true },
2511
+ { pubkey: userPosition, isSigner: false, isWritable: true }
2512
+ );
2513
+ }
2514
+ const hookAccounts = [
2515
+ { pubkey: extraAccountMeta, isSigner: false, isWritable: false },
2516
+ { pubkey: hookConfig, isSigner: false, isWritable: false },
2517
+ { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
2518
+ ];
2519
+ let feeAccounts = [];
2520
+ if (this.programIds.feeManagement && this.feeConfigOwner) {
2521
+ const companyAddr = await this.companyAddress();
2522
+ const refVault = await this.referralVault();
2523
+ if (companyAddr && refVault) {
2524
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2525
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2526
+ if (feeOverrideExists) {
2527
+ const oracleVault = opts?.marketOracleVault ?? payer;
2528
+ feeAccounts = [
2529
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2530
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2531
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2532
+ { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2533
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2534
+ { pubkey: refVault, isSigner: false, isWritable: true }
2535
+ ];
2536
+ }
2537
+ }
2538
+ }
2539
+ await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2540
+ const ed25519Ix = buildBatchedCollectFeeEd25519Instruction(signedOrders);
2541
+ const collectIx = await this.program.methods.batchCollectRedeemEarly(
2542
+ 2,
2543
+ // ix_index: Ed25519 ix is ix[2] (cuLimit=0, heapFrame=1, ed25519=2)
2544
+ signedOrders.length,
2545
+ outcomeIndex
2546
+ ).accounts({
2547
+ operator,
2548
+ payer,
2549
+ clobConfig,
2550
+ condition,
2551
+ collateralVault,
2552
+ vaultTokenAccount,
2553
+ feeRecipient: cfg.feeRecipient,
2554
+ yesMint,
2555
+ noMint,
2556
+ clobYesAta,
2557
+ clobNoAta,
2558
+ clobYesPosition,
2559
+ clobNoPosition,
2560
+ ixSysvar: IX_SYSVAR,
2561
+ conditionalTokensProgram: this.programIds.conditionalTokens,
2562
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2563
+ token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
2564
+ systemProgram: web3_js.SystemProgram.programId
2565
+ }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2566
+ const cachedAlt = this._altCache.get(condition.toBase58());
2567
+ return this._buildUnsignedVtx([ed25519Ix, collectIx], cachedAlt, payer);
2568
+ }
2353
2569
  // ─── Queries ─────────────────────────────────────────────────────────────────
2354
2570
  async fetchConfig() {
2355
2571
  try {
@@ -2398,20 +2614,22 @@ var FeeManagementClient = class {
2398
2614
  this.provider = provider;
2399
2615
  this.programIds = programIds;
2400
2616
  }
2401
- async initFeeConfig(admin, companyAddress, referralAddress, presaleRevenueAddress, investorsMarketRev, companyMarketRev, agentsPresaleRev, companyPresaleRev, authority, payer) {
2402
- const [feeConfigPda] = PDA.feeConfig(authority, this.programIds);
2617
+ async initFeeConfig(params) {
2618
+ const [feeConfigPda] = PDA.feeConfig(params.authority, this.programIds);
2403
2619
  const sig = await this.program.methods.initialize({
2404
- admin,
2405
- companyAddress,
2406
- referralAddress,
2407
- presaleRevenueAddress,
2408
- investorsMarketRev,
2409
- companyMarketRev,
2410
- agentsPresaleRev,
2411
- companyPresaleRev
2620
+ admin: params.admin,
2621
+ companyAddress: params.companyAddress,
2622
+ referralAddress: params.referralAddress,
2623
+ presaleRevenueAddress: params.presaleRevenueAddress,
2624
+ investorsMarketRev: params.investorsMarketRev,
2625
+ companyMarketRev: params.companyMarketRev,
2626
+ agentsPresaleRev: params.agentsPresaleRev,
2627
+ companyPresaleRev: params.companyPresaleRev,
2628
+ referralMarketRev: params.referralMarketRev,
2629
+ referralVault: params.referralVault
2412
2630
  }).accounts({
2413
- authority,
2414
- payer,
2631
+ authority: params.authority,
2632
+ payer: params.payer,
2415
2633
  feeConfig: feeConfigPda,
2416
2634
  systemProgram: web3_js.SystemProgram.programId
2417
2635
  }).signers([]).rpc();
@@ -2426,9 +2644,14 @@ var FeeManagementClient = class {
2426
2644
  }
2427
2645
  }
2428
2646
  /**
2429
- * Fetch per-question fees for a condition.
2430
- * Returns null if no fees have been set yet.
2647
+ * Fetch per-market fees for a condition.
2648
+ * Returns null if fees have not been initialized yet.
2649
+ * Fees are set automatically via CPI when create_question_admin / approve_presale runs.
2650
+ * Defaults: swapFee=200 (2%), redeemFee=0, mergeFee=2000 (20%), out of FEE_DENOMINATOR=10_000.
2431
2651
  */
2652
+ async getMarketFee(conditionPda) {
2653
+ return this.fetchQuestionFee(conditionPda);
2654
+ }
2432
2655
  async fetchQuestionFee(conditionPda) {
2433
2656
  try {
2434
2657
  const [pda] = PDA.questionFee(conditionPda, this.programIds);
@@ -2445,28 +2668,30 @@ var FeeManagementClient = class {
2445
2668
  }
2446
2669
  }
2447
2670
  /**
2448
- * Set per-question fees for a condition.
2671
+ * Set per-question fees for a condition (whitelist-only edit after market creation).
2449
2672
  * @param conditionPda - condition PDA from the question
2450
- * @param mergeFee - fee out of FEE_DENOMINATOR (1_000_000), e.g. 2_000 = 0.2%
2673
+ * @param mergeFee - fee out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
2451
2674
  * @param redeemFee - fee out of FEE_DENOMINATOR
2452
- * @param swapFee - trading fee out of FEE_DENOMINATOR
2675
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
2453
2676
  * @param feeConfigOwner - pubkey that owns the fee_config PDA (usually market deployer)
2454
2677
  * @param authority - signer authorized in fee_config whitelist / admin / owner
2455
2678
  * @param payer - rent + tx fee payer
2456
2679
  */
2457
- async updateFeeConfig(companyAddress, referralAddress, presaleRevenueAddress, investorsMarketRev, companyMarketRev, agentsPresaleRev, companyPresaleRev, authority, payer) {
2458
- const [feeConfigPda] = PDA.feeConfig(authority, this.programIds);
2680
+ async updateFeeConfig(params) {
2681
+ const [feeConfigPda] = PDA.feeConfig(params.authority, this.programIds);
2459
2682
  const sig = await this.program.methods.updateConfig({
2460
- companyAddress,
2461
- referralAddress,
2462
- presaleRevenueAddress,
2463
- investorsMarketRev,
2464
- companyMarketRev,
2465
- agentsPresaleRev,
2466
- companyPresaleRev
2683
+ companyAddress: params.companyAddress,
2684
+ referralAddress: params.referralAddress,
2685
+ presaleRevenueAddress: params.presaleRevenueAddress,
2686
+ investorsMarketRev: params.investorsMarketRev,
2687
+ companyMarketRev: params.companyMarketRev,
2688
+ agentsPresaleRev: params.agentsPresaleRev,
2689
+ companyPresaleRev: params.companyPresaleRev,
2690
+ referralMarketRev: params.referralMarketRev,
2691
+ referralVault: params.referralVault
2467
2692
  }).accounts({
2468
- authority,
2469
- payer,
2693
+ authority: params.authority,
2694
+ payer: params.payer,
2470
2695
  feeConfig: feeConfigPda
2471
2696
  }).signers([]).rpc();
2472
2697
  return { signature: sig };
@@ -2483,33 +2708,33 @@ var FeeManagementClient = class {
2483
2708
  }).signers([]).rpc();
2484
2709
  return { signature: sig };
2485
2710
  }
2486
- async buildDistributeFeeIx(conditionPda, amount, feeConfigOwner, sourceAta, companyAta, marketOracleVault, authority) {
2711
+ /**
2712
+ * Build editMarketFee transaction (whitelist-only).
2713
+ * @param conditionPda - condition PDA (market identifier)
2714
+ * @param mergeFee - out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
2715
+ * @param redeemFee - out of FEE_DENOMINATOR
2716
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
2717
+ * @param feeConfigOwner - owner of fee_config PDA
2718
+ * @param authority - whitelisted signer (signs tx externally)
2719
+ * @param payer - fee payer (can differ from authority)
2720
+ */
2721
+ async buildEditMarketFeeTx(conditionPda, mergeFee, redeemFee, swapFee, feeConfigOwner, authority, payer = authority) {
2487
2722
  const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2488
- const [marketFeeOverridePda] = PDA.marketFeeOverride(conditionPda, this.programIds);
2489
- return this.program.methods.distributeFee(conditionPda, amount).accounts({
2490
- feeConfig: feeConfigPda,
2491
- marketFeeOverride: marketFeeOverridePda,
2723
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
2724
+ return this.program.methods.setQuestionFee(
2725
+ Array.from(conditionPda.toBytes()),
2726
+ mergeFee,
2727
+ redeemFee,
2728
+ swapFee
2729
+ ).accounts({
2492
2730
  authority,
2493
- sourceAta,
2494
- companyAta,
2495
- marketOracleVault,
2496
- tokenProgram: new web3_js.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
2497
- }).instruction();
2498
- }
2499
- async distributeFee(conditionPda, amount, feeConfigOwner, sourceAta, companyAta, marketOracleVault, authority) {
2500
- const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2501
- const [marketFeeOverridePda] = PDA.marketFeeOverride(conditionPda, this.programIds);
2502
- const sig = await this.program.methods.distributeFee(conditionPda, amount).accounts({
2731
+ payer,
2503
2732
  feeConfig: feeConfigPda,
2504
- marketFeeOverride: marketFeeOverridePda,
2505
- authority,
2506
- sourceAta,
2507
- companyAta,
2508
- marketOracleVault,
2509
- tokenProgram: new web3_js.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
2510
- }).signers([]).rpc();
2511
- return { signature: sig };
2733
+ questionFee: questionFeePda,
2734
+ systemProgram: web3_js.SystemProgram.programId
2735
+ }).transaction();
2512
2736
  }
2737
+ /** @deprecated use buildEditMarketFeeTx */
2513
2738
  async setQuestionFee(conditionPda, mergeFee, redeemFee, swapFee, feeConfigOwner, authority, payer) {
2514
2739
  const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2515
2740
  const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
@@ -2867,6 +3092,98 @@ var AdminClient = class {
2867
3092
  }).transaction();
2868
3093
  }
2869
3094
  };
3095
+ var ReferralClient = class {
3096
+ constructor(program, provider, programIds) {
3097
+ this.program = program;
3098
+ this.provider = provider;
3099
+ this.programIds = programIds;
3100
+ }
3101
+ get walletPubkey() {
3102
+ return this.provider.wallet.publicKey;
3103
+ }
3104
+ referralVault(owner, collateralMint) {
3105
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3106
+ return splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3107
+ }
3108
+ async fetchConfig(owner) {
3109
+ try {
3110
+ const [pda] = PDA.referralConfig(owner, this.programIds);
3111
+ const acc = await this.program.account.referralConfig.fetch(pda);
3112
+ return {
3113
+ owner: acc.owner,
3114
+ collateralMint: acc.collateralMint,
3115
+ whitelist: acc.whitelist.slice(0, acc.whitelistLen),
3116
+ bump: acc.bump
3117
+ };
3118
+ } catch {
3119
+ return null;
3120
+ }
3121
+ }
3122
+ /**
3123
+ * Build initialize tx — creates referral config PDA.
3124
+ * Also prepends an ATA creation instruction for the referral vault (idempotent).
3125
+ * Build-tx pattern.
3126
+ */
3127
+ async buildInitializeTx(collateralMint, owner = this.walletPubkey, payer = owner) {
3128
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3129
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3130
+ const vaultAta = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3131
+ const createVaultIx = splToken.createAssociatedTokenAccountIdempotentInstruction(
3132
+ payer,
3133
+ vaultAta,
3134
+ configPda,
3135
+ collateralMint
3136
+ );
3137
+ const initTx = await this.program.methods.initialize().accounts({
3138
+ owner,
3139
+ payer,
3140
+ config: configPda,
3141
+ collateralMint,
3142
+ systemProgram: web3_js.SystemProgram.programId
3143
+ }).transaction();
3144
+ const tx = new web3_js.Transaction().add(createVaultIx, ...initTx.instructions);
3145
+ return { tx, configPda, vaultAta };
3146
+ }
3147
+ /** Build add-to-whitelist tx. Build-tx pattern. */
3148
+ async buildAddToWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3149
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3150
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3151
+ return this.program.methods.addToWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3152
+ }
3153
+ /** Build remove-from-whitelist tx. Build-tx pattern. */
3154
+ async buildRemoveFromWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3155
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3156
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3157
+ return this.program.methods.removeFromWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3158
+ }
3159
+ /**
3160
+ * Build batchSendUsds tx. Build-tx pattern.
3161
+ * @param recipients - wallet addresses to send to
3162
+ * @param amounts - corresponding amounts in token smallest units
3163
+ * @param configOwner - owner of referral config (used to derive config + vault)
3164
+ * @param collateralMint - token mint
3165
+ * @param authority - whitelisted signer
3166
+ * @param payer - fee payer (can differ from authority)
3167
+ */
3168
+ async buildBatchSendUsdsTx(recipients, amounts, configOwner, collateralMint, authority = this.walletPubkey, payer = authority) {
3169
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3170
+ if (recipients.length !== amounts.length) throw new Error("recipients and amounts must have same length");
3171
+ if (recipients.length === 0) throw new Error("recipients array is empty");
3172
+ const [configPda] = PDA.referralConfig(configOwner, this.programIds);
3173
+ const referralVault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
3174
+ const recipientAtas = recipients.map(
3175
+ (wallet) => splToken.getAssociatedTokenAddressSync(collateralMint, wallet)
3176
+ );
3177
+ return this.program.methods.batchSendUsds(amounts).accounts({
3178
+ authority,
3179
+ config: configPda,
3180
+ referralVault,
3181
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
3182
+ }).remainingAccounts(
3183
+ recipientAtas.map((ata) => ({ pubkey: ata, isSigner: false, isWritable: true }))
3184
+ ).transaction();
3185
+ }
3186
+ };
2870
3187
 
2871
3188
  // src/idls/oracle.json
2872
3189
  var oracle_default = {
@@ -4286,9 +4603,59 @@ var question_market_default = {
4286
4603
  ],
4287
4604
  writable: true
4288
4605
  },
4606
+ {
4607
+ name: "presale_vault",
4608
+ writable: true
4609
+ },
4610
+ {
4611
+ name: "referral_token_account",
4612
+ docs: [
4613
+ "Referral address USDC ATA (receives agents_fee 10%)"
4614
+ ],
4615
+ writable: true
4616
+ },
4617
+ {
4618
+ name: "company_token_account",
4619
+ docs: [
4620
+ "Company address USDC ATA (receives company_fee 10%)"
4621
+ ],
4622
+ writable: true
4623
+ },
4624
+ {
4625
+ name: "admin_vault",
4626
+ docs: [
4627
+ "admin_contract vault ATA (receives botmm_revenue 80%)"
4628
+ ],
4629
+ writable: true
4630
+ },
4631
+ {
4632
+ name: "admin_config",
4633
+ docs: [
4634
+ "admin_contract config PDA (seeds=[ADMIN_CONFIG_SEED, owner] \u2014 validated by admin_contract CPI)"
4635
+ ]
4636
+ },
4637
+ {
4638
+ name: "claim_record",
4639
+ docs: [
4640
+ "ClaimRecord PDA for this presale's conditionId (seeds=[CLAIM_RECORD_SEED, condition_id])",
4641
+ "condition_id computed inside handler \u2014 seeds validated by admin_contract CPI"
4642
+ ],
4643
+ writable: true
4644
+ },
4289
4645
  {
4290
4646
  name: "conditional_tokens_program"
4291
4647
  },
4648
+ {
4649
+ name: "question_fee",
4650
+ docs: [
4651
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management"
4652
+ ],
4653
+ writable: true
4654
+ },
4655
+ {
4656
+ name: "fee_management_program",
4657
+ address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
4658
+ },
4292
4659
  {
4293
4660
  name: "presale_program",
4294
4661
  address: "2Rnw1VoEtsUMQ7wkvYZjDehqSqRob6uNkeymDfvKrquB"
@@ -4297,6 +4664,10 @@ var question_market_default = {
4297
4664
  name: "market_oracle_program",
4298
4665
  address: "ADWF4J3nCJ2kWnCtycuem2jhu7amUqJWQG3oa5xF67QJ"
4299
4666
  },
4667
+ {
4668
+ name: "admin_program",
4669
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T"
4670
+ },
4300
4671
  {
4301
4672
  name: "token_program",
4302
4673
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -4940,12 +5311,53 @@ var question_market_default = {
4940
5311
  name: "conditional_tokens_program"
4941
5312
  },
4942
5313
  {
4943
- name: "token_program",
4944
- address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
4945
- },
4946
- {
4947
- name: "system_program",
4948
- address: "11111111111111111111111111111111"
5314
+ name: "question_fee",
5315
+ docs: [
5316
+ "QuestionFee PDA \u2014 initialized with default fees via CPI to fee-management.",
5317
+ "Seed uses condition.key() bytes (consistent with existing set_question_fee SDK convention)."
5318
+ ],
5319
+ writable: true,
5320
+ pda: {
5321
+ seeds: [
5322
+ {
5323
+ kind: "const",
5324
+ value: [
5325
+ 113,
5326
+ 117,
5327
+ 101,
5328
+ 115,
5329
+ 116,
5330
+ 105,
5331
+ 111,
5332
+ 110,
5333
+ 95,
5334
+ 102,
5335
+ 101,
5336
+ 101
5337
+ ]
5338
+ },
5339
+ {
5340
+ kind: "account",
5341
+ path: "condition"
5342
+ }
5343
+ ],
5344
+ program: {
5345
+ kind: "account",
5346
+ path: "fee_management_program"
5347
+ }
5348
+ }
5349
+ },
5350
+ {
5351
+ name: "fee_management_program",
5352
+ address: "DuYyXguB5PVSKg6E2p4XPrrXZSCJnuBhoGpkGCBN5bBb"
5353
+ },
5354
+ {
5355
+ name: "token_program",
5356
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
5357
+ },
5358
+ {
5359
+ name: "system_program",
5360
+ address: "11111111111111111111111111111111"
4949
5361
  },
4950
5362
  {
4951
5363
  name: "rent",
@@ -6055,6 +6467,18 @@ var question_market_default = {
6055
6467
  {
6056
6468
  name: "creator",
6057
6469
  type: "pubkey"
6470
+ },
6471
+ {
6472
+ name: "agents_fee",
6473
+ type: "u64"
6474
+ },
6475
+ {
6476
+ name: "company_fee",
6477
+ type: "u64"
6478
+ },
6479
+ {
6480
+ name: "botmm_revenue",
6481
+ type: "u64"
6058
6482
  }
6059
6483
  ]
6060
6484
  }
@@ -8621,6 +9045,174 @@ var clob_exchange_default = {
8621
9045
  }
8622
9046
  ]
8623
9047
  },
9048
+ {
9049
+ name: "batch_collect_redeem_early",
9050
+ docs: [
9051
+ "Batch collect fee tokens from winning users after question resolution,",
9052
+ "redeem them via CTF, and distribute USDS via fee_management."
9053
+ ],
9054
+ discriminator: [
9055
+ 87,
9056
+ 149,
9057
+ 45,
9058
+ 245,
9059
+ 249,
9060
+ 25,
9061
+ 207,
9062
+ 82
9063
+ ],
9064
+ accounts: [
9065
+ {
9066
+ name: "operator",
9067
+ signer: true
9068
+ },
9069
+ {
9070
+ name: "payer",
9071
+ writable: true,
9072
+ signer: true
9073
+ },
9074
+ {
9075
+ name: "clob_config",
9076
+ writable: true,
9077
+ pda: {
9078
+ seeds: [
9079
+ {
9080
+ kind: "const",
9081
+ value: [
9082
+ 99,
9083
+ 108,
9084
+ 111,
9085
+ 98,
9086
+ 95,
9087
+ 99,
9088
+ 111,
9089
+ 110,
9090
+ 102,
9091
+ 105,
9092
+ 103
9093
+ ]
9094
+ }
9095
+ ]
9096
+ }
9097
+ },
9098
+ {
9099
+ name: "condition",
9100
+ writable: true
9101
+ },
9102
+ {
9103
+ name: "collateral_vault",
9104
+ writable: true,
9105
+ pda: {
9106
+ seeds: [
9107
+ {
9108
+ kind: "const",
9109
+ value: [
9110
+ 99,
9111
+ 111,
9112
+ 108,
9113
+ 108,
9114
+ 97,
9115
+ 116,
9116
+ 101,
9117
+ 114,
9118
+ 97,
9119
+ 108,
9120
+ 95,
9121
+ 118,
9122
+ 97,
9123
+ 117,
9124
+ 108,
9125
+ 116
9126
+ ]
9127
+ },
9128
+ {
9129
+ kind: "account",
9130
+ path: "condition.collateral_mint",
9131
+ account: "Condition"
9132
+ }
9133
+ ],
9134
+ program: {
9135
+ kind: "account",
9136
+ path: "conditional_tokens_program"
9137
+ }
9138
+ }
9139
+ },
9140
+ {
9141
+ name: "vault_token_account",
9142
+ writable: true
9143
+ },
9144
+ {
9145
+ name: "fee_recipient",
9146
+ docs: [
9147
+ "CLOB's USDS ATA \u2014 receives USDS payout from redeem, then distribute_fee draws from it."
9148
+ ],
9149
+ writable: true
9150
+ },
9151
+ {
9152
+ name: "yes_mint",
9153
+ writable: true
9154
+ },
9155
+ {
9156
+ name: "no_mint",
9157
+ writable: true
9158
+ },
9159
+ {
9160
+ name: "clob_yes_ata",
9161
+ docs: [
9162
+ "CLOB's YES ATA (Token-2022) \u2014 must be pre-initialized (created during prior matchOrders)."
9163
+ ],
9164
+ writable: true
9165
+ },
9166
+ {
9167
+ name: "clob_no_ata",
9168
+ docs: [
9169
+ "CLOB's NO ATA (Token-2022) \u2014 must be pre-initialized."
9170
+ ],
9171
+ writable: true
9172
+ },
9173
+ {
9174
+ name: "clob_yes_position",
9175
+ writable: true
9176
+ },
9177
+ {
9178
+ name: "clob_no_position",
9179
+ writable: true
9180
+ },
9181
+ {
9182
+ name: "ix_sysvar"
9183
+ },
9184
+ {
9185
+ name: "conditional_tokens_program",
9186
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
9187
+ },
9188
+ {
9189
+ name: "token_program",
9190
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
9191
+ },
9192
+ {
9193
+ name: "token_2022_program",
9194
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
9195
+ },
9196
+ {
9197
+ name: "system_program",
9198
+ address: "11111111111111111111111111111111"
9199
+ }
9200
+ ],
9201
+ args: [
9202
+ {
9203
+ name: "ix_index",
9204
+ type: "u8"
9205
+ },
9206
+ {
9207
+ name: "order_count",
9208
+ type: "u8"
9209
+ },
9210
+ {
9211
+ name: "outcome_index",
9212
+ type: "u8"
9213
+ }
9214
+ ]
9215
+ },
8624
9216
  {
8625
9217
  name: "cancel_order",
8626
9218
  docs: [
@@ -8834,7 +9426,7 @@ var clob_exchange_default = {
8834
9426
  {
8835
9427
  name: "match_complementary",
8836
9428
  docs: [
8837
- "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
9429
+ "COMPLEMENTARY match: 1 taker (BUY or SELL) + N makers (opposite side) via remaining_accounts."
8838
9430
  ],
8839
9431
  discriminator: [
8840
9432
  100,
@@ -9127,9 +9719,6 @@ var clob_exchange_default = {
9127
9719
  },
9128
9720
  {
9129
9721
  name: "clob_usdc_ata",
9130
- docs: [
9131
- "USDC ATA owned by clob_config \u2014 receives USDC from vault after merge"
9132
- ],
9133
9722
  writable: true,
9134
9723
  pda: {
9135
9724
  seeds: [
@@ -9406,9 +9995,6 @@ var clob_exchange_default = {
9406
9995
  },
9407
9996
  {
9408
9997
  name: "clob_usdc_ata",
9409
- docs: [
9410
- "USDC ATA owned by clob_config \u2014 receives combined USDC, then split_position pulls from here"
9411
- ],
9412
9998
  writable: true,
9413
9999
  pda: {
9414
10000
  seeds: [
@@ -9466,30 +10052,18 @@ var clob_exchange_default = {
9466
10052
  },
9467
10053
  {
9468
10054
  name: "clob_yes_ata",
9469
- docs: [
9470
- "YES Token-2022 ATA owned by clob_config \u2014 receives YES from split, then transferred to taker"
9471
- ],
9472
10055
  writable: true
9473
10056
  },
9474
10057
  {
9475
10058
  name: "clob_no_ata",
9476
- docs: [
9477
- "NO Token-2022 ATA owned by clob_config \u2014 receives NO from split, then transferred to makers"
9478
- ],
9479
10059
  writable: true
9480
10060
  },
9481
10061
  {
9482
10062
  name: "clob_yes_position",
9483
- docs: [
9484
- "YES Position PDA for clob_config (set by CTF split_position init_if_needed)"
9485
- ],
9486
10063
  writable: true
9487
10064
  },
9488
10065
  {
9489
10066
  name: "clob_no_position",
9490
- docs: [
9491
- "NO Position PDA for clob_config (set by CTF split_position init_if_needed)"
9492
- ],
9493
10067
  writable: true
9494
10068
  },
9495
10069
  {
@@ -10525,11 +11099,18 @@ var fee_management_default = {
10525
11099
  {
10526
11100
  name: "market_oracle_vault",
10527
11101
  docs: [
10528
- "Writable: tokens are transferred here when is_admin=false.",
11102
+ "Writable: tokens are transferred here (investors share) when is_admin=false.",
10529
11103
  "For admin questions pass any writable account (no transfer occurs)."
10530
11104
  ],
10531
11105
  writable: true
10532
11106
  },
11107
+ {
11108
+ name: "referral_vault",
11109
+ docs: [
11110
+ "Must match fee_config.referral_vault."
11111
+ ],
11112
+ writable: true
11113
+ },
10533
11114
  {
10534
11115
  name: "token_program",
10535
11116
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -10547,40 +11128,104 @@ var fee_management_default = {
10547
11128
  ]
10548
11129
  },
10549
11130
  {
10550
- name: "initialize",
11131
+ name: "init_question_fee",
10551
11132
  discriminator: [
10552
- 175,
10553
- 175,
10554
- 109,
10555
- 31,
10556
- 13,
10557
- 152,
10558
- 155,
10559
- 237
11133
+ 115,
11134
+ 49,
11135
+ 110,
11136
+ 164,
11137
+ 33,
11138
+ 202,
11139
+ 115,
11140
+ 79
10560
11141
  ],
10561
11142
  accounts: [
10562
- {
10563
- name: "authority",
10564
- signer: true
10565
- },
10566
11143
  {
10567
11144
  name: "payer",
10568
11145
  writable: true,
10569
11146
  signer: true
10570
11147
  },
10571
11148
  {
10572
- name: "fee_config",
11149
+ name: "question_fee",
10573
11150
  writable: true,
10574
11151
  pda: {
10575
11152
  seeds: [
10576
11153
  {
10577
11154
  kind: "const",
10578
11155
  value: [
10579
- 102,
10580
- 101,
11156
+ 113,
11157
+ 117,
10581
11158
  101,
10582
- 95,
10583
- 99,
11159
+ 115,
11160
+ 116,
11161
+ 105,
11162
+ 111,
11163
+ 110,
11164
+ 95,
11165
+ 102,
11166
+ 101,
11167
+ 101
11168
+ ]
11169
+ },
11170
+ {
11171
+ kind: "arg",
11172
+ path: "condition_id"
11173
+ }
11174
+ ]
11175
+ }
11176
+ },
11177
+ {
11178
+ name: "system_program",
11179
+ address: "11111111111111111111111111111111"
11180
+ }
11181
+ ],
11182
+ args: [
11183
+ {
11184
+ name: "condition_id",
11185
+ type: {
11186
+ array: [
11187
+ "u8",
11188
+ 32
11189
+ ]
11190
+ }
11191
+ }
11192
+ ]
11193
+ },
11194
+ {
11195
+ name: "initialize",
11196
+ discriminator: [
11197
+ 175,
11198
+ 175,
11199
+ 109,
11200
+ 31,
11201
+ 13,
11202
+ 152,
11203
+ 155,
11204
+ 237
11205
+ ],
11206
+ accounts: [
11207
+ {
11208
+ name: "authority",
11209
+ signer: true
11210
+ },
11211
+ {
11212
+ name: "payer",
11213
+ writable: true,
11214
+ signer: true
11215
+ },
11216
+ {
11217
+ name: "fee_config",
11218
+ writable: true,
11219
+ pda: {
11220
+ seeds: [
11221
+ {
11222
+ kind: "const",
11223
+ value: [
11224
+ 102,
11225
+ 101,
11226
+ 101,
11227
+ 95,
11228
+ 99,
10584
11229
  111,
10585
11230
  110,
10586
11231
  102,
@@ -11240,6 +11885,19 @@ var fee_management_default = {
11240
11885
  235
11241
11886
  ]
11242
11887
  },
11888
+ {
11889
+ name: "QuestionFeeInitialized",
11890
+ discriminator: [
11891
+ 147,
11892
+ 167,
11893
+ 20,
11894
+ 219,
11895
+ 32,
11896
+ 142,
11897
+ 227,
11898
+ 171
11899
+ ]
11900
+ },
11243
11901
  {
11244
11902
  name: "QuestionFeeUpdated",
11245
11903
  discriminator: [
@@ -11311,7 +11969,8 @@ var fee_management_default = {
11311
11969
  {
11312
11970
  name: "investors_market_rev",
11313
11971
  docs: [
11314
- "Market revenue split: investors + company (out of FEE_DENOMINATOR = 1_000_000)"
11972
+ "Market revenue split \u2014 three parts must sum to FEE_DENOMINATOR (10_000).",
11973
+ "investors_market_rev + company_market_rev + referral_market_rev == 10_000"
11315
11974
  ],
11316
11975
  type: "u32"
11317
11976
  },
@@ -11322,7 +11981,7 @@ var fee_management_default = {
11322
11981
  {
11323
11982
  name: "agents_presale_rev",
11324
11983
  docs: [
11325
- "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 1_000_000)"
11984
+ "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 10_000)"
11326
11985
  ],
11327
11986
  type: "u32"
11328
11987
  },
@@ -11347,12 +12006,26 @@ var fee_management_default = {
11347
12006
  name: "bump",
11348
12007
  type: "u8"
11349
12008
  },
12009
+ {
12010
+ name: "referral_market_rev",
12011
+ docs: [
12012
+ "Share of market trading fees routed to referral_vault (e.g. 2_000 = 20%)"
12013
+ ],
12014
+ type: "u32"
12015
+ },
12016
+ {
12017
+ name: "referral_vault",
12018
+ docs: [
12019
+ "ATA of referral program config PDA \u2014 receives referral_market_rev% of trading fees"
12020
+ ],
12021
+ type: "pubkey"
12022
+ },
11350
12023
  {
11351
12024
  name: "_reserved",
11352
12025
  type: {
11353
12026
  array: [
11354
12027
  "u8",
11355
- 64
12028
+ 28
11356
12029
  ]
11357
12030
  }
11358
12031
  }
@@ -11479,6 +12152,14 @@ var fee_management_default = {
11479
12152
  {
11480
12153
  name: "company_presale_rev",
11481
12154
  type: "u32"
12155
+ },
12156
+ {
12157
+ name: "referral_market_rev",
12158
+ type: "u32"
12159
+ },
12160
+ {
12161
+ name: "referral_vault",
12162
+ type: "pubkey"
11482
12163
  }
11483
12164
  ]
11484
12165
  }
@@ -11622,7 +12303,7 @@ var fee_management_default = {
11622
12303
  {
11623
12304
  name: "merge_fee",
11624
12305
  docs: [
11625
- "Fees out of FEE_DENOMINATOR (1_000_000). E.g. 2_000 = 0.2%"
12306
+ "Fees out of FEE_DENOMINATOR (10_000). E.g. 200 = 2%, 2_000 = 20%"
11626
12307
  ],
11627
12308
  type: "u64"
11628
12309
  },
@@ -11641,6 +12322,35 @@ var fee_management_default = {
11641
12322
  ]
11642
12323
  }
11643
12324
  },
12325
+ {
12326
+ name: "QuestionFeeInitialized",
12327
+ type: {
12328
+ kind: "struct",
12329
+ fields: [
12330
+ {
12331
+ name: "condition_id",
12332
+ type: {
12333
+ array: [
12334
+ "u8",
12335
+ 32
12336
+ ]
12337
+ }
12338
+ },
12339
+ {
12340
+ name: "swap_fee",
12341
+ type: "u64"
12342
+ },
12343
+ {
12344
+ name: "redeem_fee",
12345
+ type: "u64"
12346
+ },
12347
+ {
12348
+ name: "merge_fee",
12349
+ type: "u64"
12350
+ }
12351
+ ]
12352
+ }
12353
+ },
11644
12354
  {
11645
12355
  name: "QuestionFeeUpdated",
11646
12356
  type: {
@@ -11710,6 +12420,14 @@ var fee_management_default = {
11710
12420
  {
11711
12421
  name: "company_presale_rev",
11712
12422
  type: "u32"
12423
+ },
12424
+ {
12425
+ name: "referral_market_rev",
12426
+ type: "u32"
12427
+ },
12428
+ {
12429
+ name: "referral_vault",
12430
+ type: "pubkey"
11713
12431
  }
11714
12432
  ]
11715
12433
  }
@@ -15058,94 +15776,592 @@ var admin_contract_default = {
15058
15776
  ]
15059
15777
  };
15060
15778
 
15061
- // src/sdk.ts
15062
- var XMarketSDK = class {
15063
- // lazy-init in get admin()
15064
- constructor(config, wallet, marketOwner) {
15065
- this.networkConfig = config;
15066
- this.provider = new anchor5__namespace.AnchorProvider(
15067
- new web3_js.Connection(config.rpcUrl, "confirmed"),
15068
- wallet,
15069
- { commitment: "confirmed", preflightCommitment: "confirmed" }
15070
- );
15071
- anchor5__namespace.setProvider(this.provider);
15072
- this._programIds = config.programIds;
15073
- this._marketOwner = marketOwner ?? wallet.publicKey;
15074
- }
15075
- _withAddress(idl, address) {
15076
- return { ...idl, address: address.toBase58() };
15077
- }
15078
- get oracle() {
15079
- if (!this._oracle) {
15080
- const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
15081
- this._oracle = new OracleClient(program, this.provider, this._programIds);
15082
- }
15083
- return this._oracle;
15084
- }
15085
- get hook() {
15086
- if (!this._hook) {
15087
- const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
15088
- this._hook = new HookClient(program, this.provider, this._programIds);
15089
- }
15090
- return this._hook;
15091
- }
15092
- get market() {
15093
- if (!this._market) {
15094
- const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
15095
- this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
15096
- this._market.ctfClient = this.ctf;
15097
- }
15098
- return this._market;
15099
- }
15100
- get ctf() {
15101
- if (!this._ctf) {
15102
- const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
15103
- this._ctf = new CtfClient(program, this.provider, this._programIds);
15104
- }
15105
- return this._ctf;
15106
- }
15107
- get clob() {
15108
- if (!this._clob) {
15109
- const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
15110
- this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
15111
- if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
15112
- this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
15113
- this._clob.feeClient = this.fee;
15114
- }
15115
- }
15116
- return this._clob;
15117
- }
15118
- get fee() {
15119
- if (!this._fee) {
15120
- if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
15121
- const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
15122
- this._fee = new FeeManagementClient(program, this.provider, this._programIds);
15123
- }
15124
- return this._fee;
15125
- }
15126
- get presale() {
15127
- if (!this._presale) {
15128
- if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
15129
- const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
15130
- this._presale = new PresaleClient(program, this.provider, this._programIds);
15131
- }
15132
- return this._presale;
15133
- }
15134
- get marketOracle() {
15135
- if (!this._marketOracle) {
15136
- if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
15137
- const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
15138
- this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
15139
- }
15140
- return this._marketOracle;
15141
- }
15142
- get admin() {
15143
- if (!this._admin) {
15144
- if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
15145
- const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
15146
- this._admin = new AdminClient(program, this.provider, this._programIds);
15147
- }
15148
- return this._admin;
15779
+ // src/idls/referral.json
15780
+ var referral_default = {
15781
+ address: "7b5ohWDqrQ2KRcDJMWwj1dwgRkt5ZJdMavSmrXn9oBgL",
15782
+ metadata: {
15783
+ name: "referral",
15784
+ version: "0.1.0",
15785
+ spec: "0.1.0",
15786
+ description: "Referral program for XMarket \u2014 whitelist-gated batch USDS distribution"
15787
+ },
15788
+ instructions: [
15789
+ {
15790
+ name: "add_to_whitelist",
15791
+ discriminator: [
15792
+ 157,
15793
+ 211,
15794
+ 52,
15795
+ 54,
15796
+ 144,
15797
+ 81,
15798
+ 5,
15799
+ 55
15800
+ ],
15801
+ accounts: [
15802
+ {
15803
+ name: "owner",
15804
+ signer: true
15805
+ },
15806
+ {
15807
+ name: "payer",
15808
+ writable: true,
15809
+ signer: true
15810
+ },
15811
+ {
15812
+ name: "config",
15813
+ writable: true,
15814
+ pda: {
15815
+ seeds: [
15816
+ {
15817
+ kind: "const",
15818
+ value: [
15819
+ 114,
15820
+ 101,
15821
+ 102,
15822
+ 101,
15823
+ 114,
15824
+ 114,
15825
+ 97,
15826
+ 108,
15827
+ 95,
15828
+ 99,
15829
+ 111,
15830
+ 110,
15831
+ 102,
15832
+ 105,
15833
+ 103
15834
+ ]
15835
+ },
15836
+ {
15837
+ kind: "account",
15838
+ path: "config.owner",
15839
+ account: "ReferralConfig"
15840
+ }
15841
+ ]
15842
+ }
15843
+ }
15844
+ ],
15845
+ args: [
15846
+ {
15847
+ name: "address",
15848
+ type: "pubkey"
15849
+ }
15850
+ ]
15851
+ },
15852
+ {
15853
+ name: "batch_send_usds",
15854
+ discriminator: [
15855
+ 255,
15856
+ 33,
15857
+ 77,
15858
+ 124,
15859
+ 42,
15860
+ 207,
15861
+ 250,
15862
+ 162
15863
+ ],
15864
+ accounts: [
15865
+ {
15866
+ name: "authority",
15867
+ docs: [
15868
+ "Whitelisted caller (authority, signs tx)"
15869
+ ],
15870
+ signer: true
15871
+ },
15872
+ {
15873
+ name: "config",
15874
+ pda: {
15875
+ seeds: [
15876
+ {
15877
+ kind: "const",
15878
+ value: [
15879
+ 114,
15880
+ 101,
15881
+ 102,
15882
+ 101,
15883
+ 114,
15884
+ 114,
15885
+ 97,
15886
+ 108,
15887
+ 95,
15888
+ 99,
15889
+ 111,
15890
+ 110,
15891
+ 102,
15892
+ 105,
15893
+ 103
15894
+ ]
15895
+ },
15896
+ {
15897
+ kind: "account",
15898
+ path: "config.owner",
15899
+ account: "ReferralConfig"
15900
+ }
15901
+ ]
15902
+ }
15903
+ },
15904
+ {
15905
+ name: "referral_vault",
15906
+ docs: [
15907
+ "Referral vault \u2014 source of transfers (ATA owned by config PDA)"
15908
+ ],
15909
+ writable: true,
15910
+ pda: {
15911
+ seeds: [
15912
+ {
15913
+ kind: "account",
15914
+ path: "config"
15915
+ },
15916
+ {
15917
+ kind: "const",
15918
+ value: [
15919
+ 6,
15920
+ 221,
15921
+ 246,
15922
+ 225,
15923
+ 215,
15924
+ 101,
15925
+ 161,
15926
+ 147,
15927
+ 217,
15928
+ 203,
15929
+ 225,
15930
+ 70,
15931
+ 206,
15932
+ 235,
15933
+ 121,
15934
+ 172,
15935
+ 28,
15936
+ 180,
15937
+ 133,
15938
+ 237,
15939
+ 95,
15940
+ 91,
15941
+ 55,
15942
+ 145,
15943
+ 58,
15944
+ 140,
15945
+ 245,
15946
+ 133,
15947
+ 126,
15948
+ 255,
15949
+ 0,
15950
+ 169
15951
+ ]
15952
+ },
15953
+ {
15954
+ kind: "account",
15955
+ path: "config.collateral_mint",
15956
+ account: "ReferralConfig"
15957
+ }
15958
+ ],
15959
+ program: {
15960
+ kind: "const",
15961
+ value: [
15962
+ 140,
15963
+ 151,
15964
+ 37,
15965
+ 143,
15966
+ 78,
15967
+ 36,
15968
+ 137,
15969
+ 241,
15970
+ 187,
15971
+ 61,
15972
+ 16,
15973
+ 41,
15974
+ 20,
15975
+ 142,
15976
+ 13,
15977
+ 131,
15978
+ 11,
15979
+ 90,
15980
+ 19,
15981
+ 153,
15982
+ 218,
15983
+ 255,
15984
+ 16,
15985
+ 132,
15986
+ 4,
15987
+ 142,
15988
+ 123,
15989
+ 216,
15990
+ 219,
15991
+ 233,
15992
+ 248,
15993
+ 89
15994
+ ]
15995
+ }
15996
+ }
15997
+ },
15998
+ {
15999
+ name: "token_program",
16000
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
16001
+ }
16002
+ ],
16003
+ args: [
16004
+ {
16005
+ name: "amounts",
16006
+ type: {
16007
+ vec: "u64"
16008
+ }
16009
+ }
16010
+ ]
16011
+ },
16012
+ {
16013
+ name: "initialize",
16014
+ discriminator: [
16015
+ 175,
16016
+ 175,
16017
+ 109,
16018
+ 31,
16019
+ 13,
16020
+ 152,
16021
+ 155,
16022
+ 237
16023
+ ],
16024
+ accounts: [
16025
+ {
16026
+ name: "owner",
16027
+ writable: true,
16028
+ signer: true
16029
+ },
16030
+ {
16031
+ name: "payer",
16032
+ writable: true,
16033
+ signer: true
16034
+ },
16035
+ {
16036
+ name: "config",
16037
+ writable: true,
16038
+ pda: {
16039
+ seeds: [
16040
+ {
16041
+ kind: "const",
16042
+ value: [
16043
+ 114,
16044
+ 101,
16045
+ 102,
16046
+ 101,
16047
+ 114,
16048
+ 114,
16049
+ 97,
16050
+ 108,
16051
+ 95,
16052
+ 99,
16053
+ 111,
16054
+ 110,
16055
+ 102,
16056
+ 105,
16057
+ 103
16058
+ ]
16059
+ },
16060
+ {
16061
+ kind: "account",
16062
+ path: "owner"
16063
+ }
16064
+ ]
16065
+ }
16066
+ },
16067
+ {
16068
+ name: "collateral_mint"
16069
+ },
16070
+ {
16071
+ name: "system_program",
16072
+ address: "11111111111111111111111111111111"
16073
+ }
16074
+ ],
16075
+ args: []
16076
+ },
16077
+ {
16078
+ name: "remove_from_whitelist",
16079
+ discriminator: [
16080
+ 7,
16081
+ 144,
16082
+ 216,
16083
+ 239,
16084
+ 243,
16085
+ 236,
16086
+ 193,
16087
+ 235
16088
+ ],
16089
+ accounts: [
16090
+ {
16091
+ name: "owner",
16092
+ signer: true
16093
+ },
16094
+ {
16095
+ name: "payer",
16096
+ writable: true,
16097
+ signer: true
16098
+ },
16099
+ {
16100
+ name: "config",
16101
+ writable: true,
16102
+ pda: {
16103
+ seeds: [
16104
+ {
16105
+ kind: "const",
16106
+ value: [
16107
+ 114,
16108
+ 101,
16109
+ 102,
16110
+ 101,
16111
+ 114,
16112
+ 114,
16113
+ 97,
16114
+ 108,
16115
+ 95,
16116
+ 99,
16117
+ 111,
16118
+ 110,
16119
+ 102,
16120
+ 105,
16121
+ 103
16122
+ ]
16123
+ },
16124
+ {
16125
+ kind: "account",
16126
+ path: "config.owner",
16127
+ account: "ReferralConfig"
16128
+ }
16129
+ ]
16130
+ }
16131
+ }
16132
+ ],
16133
+ args: [
16134
+ {
16135
+ name: "address",
16136
+ type: "pubkey"
16137
+ }
16138
+ ]
16139
+ }
16140
+ ],
16141
+ accounts: [
16142
+ {
16143
+ name: "ReferralConfig",
16144
+ discriminator: [
16145
+ 102,
16146
+ 148,
16147
+ 171,
16148
+ 235,
16149
+ 148,
16150
+ 83,
16151
+ 250,
16152
+ 140
16153
+ ]
16154
+ }
16155
+ ],
16156
+ events: [
16157
+ {
16158
+ name: "BatchSent",
16159
+ discriminator: [
16160
+ 116,
16161
+ 64,
16162
+ 207,
16163
+ 63,
16164
+ 56,
16165
+ 97,
16166
+ 15,
16167
+ 100
16168
+ ]
16169
+ },
16170
+ {
16171
+ name: "ReferralInitialized",
16172
+ discriminator: [
16173
+ 129,
16174
+ 190,
16175
+ 249,
16176
+ 4,
16177
+ 198,
16178
+ 5,
16179
+ 141,
16180
+ 226
16181
+ ]
16182
+ }
16183
+ ],
16184
+ types: [
16185
+ {
16186
+ name: "BatchSent",
16187
+ type: {
16188
+ kind: "struct",
16189
+ fields: [
16190
+ {
16191
+ name: "config",
16192
+ type: "pubkey"
16193
+ },
16194
+ {
16195
+ name: "sent_by",
16196
+ type: "pubkey"
16197
+ },
16198
+ {
16199
+ name: "recipients",
16200
+ type: "u8"
16201
+ }
16202
+ ]
16203
+ }
16204
+ },
16205
+ {
16206
+ name: "ReferralConfig",
16207
+ type: {
16208
+ kind: "struct",
16209
+ fields: [
16210
+ {
16211
+ name: "version",
16212
+ type: "u8"
16213
+ },
16214
+ {
16215
+ name: "owner",
16216
+ type: "pubkey"
16217
+ },
16218
+ {
16219
+ name: "collateral_mint",
16220
+ type: "pubkey"
16221
+ },
16222
+ {
16223
+ name: "whitelist",
16224
+ type: {
16225
+ array: [
16226
+ "pubkey",
16227
+ 10
16228
+ ]
16229
+ }
16230
+ },
16231
+ {
16232
+ name: "whitelist_len",
16233
+ type: "u8"
16234
+ },
16235
+ {
16236
+ name: "bump",
16237
+ type: "u8"
16238
+ },
16239
+ {
16240
+ name: "_reserved",
16241
+ type: {
16242
+ array: [
16243
+ "u8",
16244
+ 64
16245
+ ]
16246
+ }
16247
+ }
16248
+ ]
16249
+ }
16250
+ },
16251
+ {
16252
+ name: "ReferralInitialized",
16253
+ type: {
16254
+ kind: "struct",
16255
+ fields: [
16256
+ {
16257
+ name: "config",
16258
+ type: "pubkey"
16259
+ },
16260
+ {
16261
+ name: "owner",
16262
+ type: "pubkey"
16263
+ }
16264
+ ]
16265
+ }
16266
+ }
16267
+ ]
16268
+ };
16269
+
16270
+ // src/sdk.ts
16271
+ var XMarketSDK = class {
16272
+ constructor(config, wallet, marketOwner) {
16273
+ this.networkConfig = config;
16274
+ this.provider = new anchor5__namespace.AnchorProvider(
16275
+ new web3_js.Connection(config.rpcUrl, "confirmed"),
16276
+ wallet,
16277
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
16278
+ );
16279
+ anchor5__namespace.setProvider(this.provider);
16280
+ this._programIds = config.programIds;
16281
+ this._marketOwner = marketOwner ?? wallet.publicKey;
16282
+ }
16283
+ _withAddress(idl, address) {
16284
+ return { ...idl, address: address.toBase58() };
16285
+ }
16286
+ get oracle() {
16287
+ if (!this._oracle) {
16288
+ const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
16289
+ this._oracle = new OracleClient(program, this.provider, this._programIds);
16290
+ }
16291
+ return this._oracle;
16292
+ }
16293
+ get hook() {
16294
+ if (!this._hook) {
16295
+ const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
16296
+ this._hook = new HookClient(program, this.provider, this._programIds);
16297
+ }
16298
+ return this._hook;
16299
+ }
16300
+ get market() {
16301
+ if (!this._market) {
16302
+ const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
16303
+ this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
16304
+ this._market.ctfClient = this.ctf;
16305
+ }
16306
+ return this._market;
16307
+ }
16308
+ get ctf() {
16309
+ if (!this._ctf) {
16310
+ const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
16311
+ this._ctf = new CtfClient(program, this.provider, this._programIds);
16312
+ }
16313
+ return this._ctf;
16314
+ }
16315
+ get clob() {
16316
+ if (!this._clob) {
16317
+ const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
16318
+ this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
16319
+ if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
16320
+ this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
16321
+ this._clob.feeClient = this.fee;
16322
+ }
16323
+ }
16324
+ return this._clob;
16325
+ }
16326
+ get fee() {
16327
+ if (!this._fee) {
16328
+ if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
16329
+ const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
16330
+ this._fee = new FeeManagementClient(program, this.provider, this._programIds);
16331
+ }
16332
+ return this._fee;
16333
+ }
16334
+ get presale() {
16335
+ if (!this._presale) {
16336
+ if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
16337
+ const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
16338
+ this._presale = new PresaleClient(program, this.provider, this._programIds);
16339
+ }
16340
+ return this._presale;
16341
+ }
16342
+ get marketOracle() {
16343
+ if (!this._marketOracle) {
16344
+ if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
16345
+ const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
16346
+ this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
16347
+ }
16348
+ return this._marketOracle;
16349
+ }
16350
+ get admin() {
16351
+ if (!this._admin) {
16352
+ if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
16353
+ const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
16354
+ this._admin = new AdminClient(program, this.provider, this._programIds);
16355
+ }
16356
+ return this._admin;
16357
+ }
16358
+ get referral() {
16359
+ if (!this._referral) {
16360
+ if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
16361
+ const program = new anchor5__namespace.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
16362
+ this._referral = new ReferralClient(program, this.provider, this._programIds);
16363
+ }
16364
+ return this._referral;
15149
16365
  }
15150
16366
  };
15151
16367
  var MAX_APPROVE_AMOUNT = new BN4__default.default("18446744073709551615");
@@ -15235,12 +16451,14 @@ exports.OracleClient = OracleClient;
15235
16451
  exports.PDA = PDA;
15236
16452
  exports.PresaleClient = PresaleClient;
15237
16453
  exports.QuestionStatus = QuestionStatus;
16454
+ exports.ReferralClient = ReferralClient;
15238
16455
  exports.SEEDS = SEEDS;
15239
16456
  exports.UnauthorizedError = UnauthorizedError;
15240
16457
  exports.XMarketError = XMarketError;
15241
16458
  exports.XMarketSDK = XMarketSDK;
15242
16459
  exports.buildApproveAllOutcomeTokensTx = buildApproveAllOutcomeTokensTx;
15243
16460
  exports.buildApproveCollateralTx = buildApproveCollateralTx;
16461
+ exports.buildBatchedCollectFeeEd25519Instruction = buildBatchedCollectFeeEd25519Instruction;
15244
16462
  exports.buildBatchedEd25519Instruction = buildBatchedEd25519Instruction;
15245
16463
  exports.buildCreateUserAtasTx = buildCreateUserAtasTx;
15246
16464
  exports.buildOrder = buildOrder;
@@ -15251,6 +16469,7 @@ exports.generateContentHash = generateContentHash;
15251
16469
  exports.generateQuestionId = generateQuestionId;
15252
16470
  exports.getOrderSignBytes = getOrderSignBytes;
15253
16471
  exports.orderAmountsFromPrice = orderAmountsFromPrice;
16472
+ exports.serializeCollectFeeOrderToBytes = serializeCollectFeeOrderToBytes;
15254
16473
  exports.serializeOrderToBytes = serializeOrderToBytes;
15255
16474
  exports.serializeSignedOrder = serializeSignedOrder;
15256
16475
  exports.signOrder = signOrder;