@theliem/xmarket-sdk 3.13.0 → 3.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -24,6 +24,7 @@ var SEEDS = {
24
24
  clobConfig: Buffer.from("clob_config"),
25
25
  order: Buffer.from("order"),
26
26
  feeConfig: Buffer.from("fee_config"),
27
+ referralConfig: Buffer.from("referral_config"),
27
28
  questionFee: Buffer.from("question_fee"),
28
29
  marketFee: Buffer.from("market_fee"),
29
30
  // Presale
@@ -224,6 +225,14 @@ var PDA = class {
224
225
  programIds.marketOracle
225
226
  );
226
227
  }
228
+ // ─── Referral Program ────────────────────────────────────────────────────
229
+ static referralConfig(owner, programIds) {
230
+ if (!programIds.referral) throw new Error("referral program ID not configured");
231
+ return PublicKey.findProgramAddressSync(
232
+ [SEEDS.referralConfig, owner.toBuffer()],
233
+ programIds.referral
234
+ );
235
+ }
227
236
  // ─── Admin Contract ──────────────────────────────────────────────────────
228
237
  static adminConfig(owner, programIds) {
229
238
  if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
@@ -1362,6 +1371,49 @@ function buildBatchedEd25519Instruction(orders) {
1362
1371
  });
1363
1372
  }
1364
1373
  var IX_SYSVAR = SYSVAR_INSTRUCTIONS_PUBKEY;
1374
+ function serializeCollectFeeOrderToBytes(order) {
1375
+ const buf = new Uint8Array(120);
1376
+ buf.set(order.user.toBytes(), 0);
1377
+ buf.set(order.condition.toBytes(), 32);
1378
+ buf.set(order.tokenMint.toBytes(), 64);
1379
+ buf.set(order.amount.toArrayLike(Buffer, "le", 8), 96);
1380
+ buf.set(order.nonce.toArrayLike(Buffer, "le", 8), 104);
1381
+ buf.set(order.expiry.toArrayLike(Buffer, "le", 8), 112);
1382
+ return buf;
1383
+ }
1384
+ function buildBatchedCollectFeeEd25519Instruction(orders) {
1385
+ const N = orders.length;
1386
+ if (N === 0) throw new Error("At least 1 order required");
1387
+ const MSG_SIZE = 120;
1388
+ const SIG_SIZE = 64;
1389
+ const PK_SIZE = 32;
1390
+ const HEADER = 2 + N * 14;
1391
+ const sigBase = HEADER;
1392
+ const pkBase = sigBase + N * SIG_SIZE;
1393
+ const msgBase = pkBase + N * PK_SIZE;
1394
+ const totalSize = msgBase + N * MSG_SIZE;
1395
+ const data = Buffer.alloc(totalSize);
1396
+ data[0] = N;
1397
+ data[1] = 0;
1398
+ for (let i = 0; i < N; i++) {
1399
+ const e = 2 + i * 14;
1400
+ data.writeUInt16LE(sigBase + i * SIG_SIZE, e);
1401
+ data.writeUInt16LE(65535, e + 2);
1402
+ data.writeUInt16LE(pkBase + i * PK_SIZE, e + 4);
1403
+ data.writeUInt16LE(65535, e + 6);
1404
+ data.writeUInt16LE(msgBase + i * MSG_SIZE, e + 8);
1405
+ data.writeUInt16LE(MSG_SIZE, e + 10);
1406
+ data.writeUInt16LE(65535, e + 12);
1407
+ data.set(orders[i].signature, sigBase + i * SIG_SIZE);
1408
+ data.set(orders[i].order.user.toBytes(), pkBase + i * PK_SIZE);
1409
+ data.set(serializeCollectFeeOrderToBytes(orders[i].order), msgBase + i * MSG_SIZE);
1410
+ }
1411
+ return new TransactionInstruction({
1412
+ keys: [],
1413
+ programId: Ed25519Program.programId,
1414
+ data
1415
+ });
1416
+ }
1365
1417
  function buildOrder(params) {
1366
1418
  return {
1367
1419
  maker: params.maker,
@@ -1479,10 +1531,17 @@ var ClobClient = class {
1479
1531
  if (!this.feeClient || !this.feeConfigOwner) return void 0;
1480
1532
  if (!this._companyAddress) {
1481
1533
  const cfg = await this.feeClient.fetchFeeConfig(this.feeConfigOwner);
1482
- if (cfg) this._companyAddress = cfg.companyAddress;
1534
+ if (cfg) {
1535
+ this._companyAddress = cfg.companyAddress;
1536
+ this._referralVault = cfg.referralVault;
1537
+ }
1483
1538
  }
1484
1539
  return this._companyAddress;
1485
1540
  }
1541
+ async referralVault() {
1542
+ await this.companyAddress();
1543
+ return this._referralVault;
1544
+ }
1486
1545
  get walletPubkey() {
1487
1546
  return this.provider.wallet.publicKey;
1488
1547
  }
@@ -1573,6 +1632,7 @@ var ClobClient = class {
1573
1632
  }
1574
1633
  if (this.programIds.feeManagement && this.feeConfigOwner) {
1575
1634
  const companyAddr = await this.companyAddress();
1635
+ const refVault = await this.referralVault();
1576
1636
  addresses.push(
1577
1637
  this.programIds.feeManagement,
1578
1638
  PDA.feeConfig(this.feeConfigOwner, this.programIds)[0],
@@ -1582,6 +1642,10 @@ var ClobClient = class {
1582
1642
  addresses.push(getAssociatedTokenAddressSync(collateralMint, companyAddr));
1583
1643
  }
1584
1644
  addresses.push(payer);
1645
+ if (refVault) {
1646
+ addresses.push(refVault);
1647
+ }
1648
+ addresses.push(TOKEN_PROGRAM_ID);
1585
1649
  }
1586
1650
  const slot = await connection.getSlot("finalized");
1587
1651
  const [createIx, altAddress] = AddressLookupTableProgram.createLookupTable({
@@ -1616,8 +1680,8 @@ var ClobClient = class {
1616
1680
  async _sendLegacyTxSig(instructions) {
1617
1681
  const { connection } = this.provider;
1618
1682
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1619
- const { Transaction: Transaction8 } = await import('@solana/web3.js');
1620
- const tx = new Transaction8();
1683
+ const { Transaction: Transaction10 } = await import('@solana/web3.js');
1684
+ const tx = new Transaction10();
1621
1685
  tx.recentBlockhash = blockhash;
1622
1686
  tx.feePayer = this.walletPubkey;
1623
1687
  tx.add(...instructions);
@@ -1643,10 +1707,10 @@ ${logs.join("\n")}`);
1643
1707
  connection.getAccountInfo(clobYesAta),
1644
1708
  connection.getAccountInfo(clobNoAta)
1645
1709
  ]);
1646
- const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction3 } = await import('@solana/spl-token');
1710
+ const { createAssociatedTokenAccountIdempotentInstruction: createAssociatedTokenAccountIdempotentInstruction4 } = await import('@solana/spl-token');
1647
1711
  const ixs = [];
1648
1712
  if (!yesInfo) {
1649
- ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1713
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1650
1714
  this.walletPubkey,
1651
1715
  clobYesAta,
1652
1716
  clobConfig,
@@ -1655,7 +1719,7 @@ ${logs.join("\n")}`);
1655
1719
  ));
1656
1720
  }
1657
1721
  if (!noInfo) {
1658
- ixs.push(createAssociatedTokenAccountIdempotentInstruction3(
1722
+ ixs.push(createAssociatedTokenAccountIdempotentInstruction4(
1659
1723
  this.walletPubkey,
1660
1724
  clobNoAta,
1661
1725
  clobConfig,
@@ -1839,7 +1903,8 @@ ${logs.join("\n")}`);
1839
1903
  let feeAccounts = [];
1840
1904
  if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1841
1905
  const companyAddr = await this.companyAddress();
1842
- if (companyAddr) {
1906
+ const refVault = await this.referralVault();
1907
+ if (companyAddr && refVault) {
1843
1908
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
1844
1909
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
1845
1910
  if (feeOverrideExists) {
@@ -1849,7 +1914,8 @@ ${logs.join("\n")}`);
1849
1914
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1850
1915
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
1851
1916
  { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1852
- { pubkey: oracleVault, isSigner: false, isWritable: true }
1917
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
1918
+ { pubkey: refVault, isSigner: false, isWritable: true }
1853
1919
  ];
1854
1920
  }
1855
1921
  }
@@ -2093,7 +2159,8 @@ ${logs.join("\n")}`);
2093
2159
  );
2094
2160
  if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
2095
2161
  const companyAddr = await this.companyAddress();
2096
- if (companyAddr) {
2162
+ const refVault = await this.referralVault();
2163
+ if (companyAddr && refVault) {
2097
2164
  const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2098
2165
  const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2099
2166
  if (feeOverrideExists) {
@@ -2103,7 +2170,9 @@ ${logs.join("\n")}`);
2103
2170
  { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2104
2171
  { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2105
2172
  { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2106
- { pubkey: oracleVault, isSigner: false, isWritable: true }
2173
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2174
+ { pubkey: refVault, isSigner: false, isWritable: true },
2175
+ { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
2107
2176
  );
2108
2177
  }
2109
2178
  }
@@ -2374,6 +2443,103 @@ ${logs.join("\n")}`);
2374
2443
  }
2375
2444
  return this._buildUnsignedVtx(ixs, alt, payer);
2376
2445
  }
2446
+ // ─── batchCollectRedeemEarly ─────────────────────────────────────────────────
2447
+ /**
2448
+ * Build VersionedTransaction for batchCollectRedeemEarly.
2449
+ *
2450
+ * Flow: Ed25519 ix (user sigs) + batchCollectRedeemEarly ix.
2451
+ * Each SignedCollectFeeOrder authorizes CLOB to collect `amount` winning tokens
2452
+ * from that user, redeem via CTF, then distribute as fees.
2453
+ *
2454
+ * @param signedOrders - Array of { order, signature } from winning users
2455
+ * @param condition - Market condition PDA
2456
+ * @param outcomeIndex - 0 = NO wins, 1 = YES wins
2457
+ * @param operator - Whitelisted operator pubkey (must sign)
2458
+ * @param payer - Fee payer pubkey (must sign)
2459
+ * @param opts.marketOracleVault - MarketOracle vault for fee distribution
2460
+ */
2461
+ async buildBatchCollectRedeemEarlyTx(signedOrders, condition, outcomeIndex, operator, payer, opts) {
2462
+ if (signedOrders.length === 0) throw new InvalidParamError("At least 1 order required");
2463
+ const collateralMint = this.networkConfig.defaultCollateral.mint;
2464
+ const cfg = await this.fetchConfig();
2465
+ if (!cfg) throw new InvalidParamError("CLOB config not found on-chain");
2466
+ const clobConfig = this.configPda();
2467
+ const [yesMint] = PDA.yesMint(condition, this.programIds);
2468
+ const [noMint] = PDA.noMint(condition, this.programIds);
2469
+ const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
2470
+ const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
2471
+ const clobYesAta = getAssociatedTokenAddressSync(yesMint, clobConfig, true, TOKEN_2022_PROGRAM_ID);
2472
+ const clobNoAta = getAssociatedTokenAddressSync(noMint, clobConfig, true, TOKEN_2022_PROGRAM_ID);
2473
+ const outcomeMint = outcomeIndex === 1 ? yesMint : noMint;
2474
+ const [extraAccountMeta] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
2475
+ const [hookConfig] = PDA.hookConfig(this.programIds);
2476
+ const [clobYesPosition] = PDA.position(condition, 1, clobConfig, this.programIds);
2477
+ const [clobNoPosition] = PDA.position(condition, 0, clobConfig, this.programIds);
2478
+ const userAccounts = [];
2479
+ for (const { order } of signedOrders) {
2480
+ const userTokenAta = getAssociatedTokenAddressSync(outcomeMint, order.user, false, TOKEN_2022_PROGRAM_ID);
2481
+ const [userPosition] = PDA.position(condition, outcomeIndex, order.user, this.programIds);
2482
+ userAccounts.push(
2483
+ { pubkey: order.user, isSigner: false, isWritable: false },
2484
+ { pubkey: userTokenAta, isSigner: false, isWritable: true },
2485
+ { pubkey: userPosition, isSigner: false, isWritable: true }
2486
+ );
2487
+ }
2488
+ const hookAccounts = [
2489
+ { pubkey: extraAccountMeta, isSigner: false, isWritable: false },
2490
+ { pubkey: hookConfig, isSigner: false, isWritable: false },
2491
+ { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
2492
+ ];
2493
+ let feeAccounts = [];
2494
+ if (this.programIds.feeManagement && this.feeConfigOwner) {
2495
+ const companyAddr = await this.companyAddress();
2496
+ const refVault = await this.referralVault();
2497
+ if (companyAddr && refVault) {
2498
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2499
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2500
+ if (feeOverrideExists) {
2501
+ const oracleVault = opts?.marketOracleVault ?? payer;
2502
+ feeAccounts = [
2503
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2504
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2505
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2506
+ { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2507
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2508
+ { pubkey: refVault, isSigner: false, isWritable: true }
2509
+ ];
2510
+ }
2511
+ }
2512
+ }
2513
+ await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2514
+ const ed25519Ix = buildBatchedCollectFeeEd25519Instruction(signedOrders);
2515
+ const collectIx = await this.program.methods.batchCollectRedeemEarly(
2516
+ 2,
2517
+ // ix_index: Ed25519 ix is ix[2] (cuLimit=0, heapFrame=1, ed25519=2)
2518
+ signedOrders.length,
2519
+ outcomeIndex
2520
+ ).accounts({
2521
+ operator,
2522
+ payer,
2523
+ clobConfig,
2524
+ condition,
2525
+ collateralVault,
2526
+ vaultTokenAccount,
2527
+ feeRecipient: cfg.feeRecipient,
2528
+ yesMint,
2529
+ noMint,
2530
+ clobYesAta,
2531
+ clobNoAta,
2532
+ clobYesPosition,
2533
+ clobNoPosition,
2534
+ ixSysvar: IX_SYSVAR,
2535
+ conditionalTokensProgram: this.programIds.conditionalTokens,
2536
+ tokenProgram: TOKEN_PROGRAM_ID,
2537
+ token2022Program: TOKEN_2022_PROGRAM_ID,
2538
+ systemProgram: SystemProgram.programId
2539
+ }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2540
+ const cachedAlt = this._altCache.get(condition.toBase58());
2541
+ return this._buildUnsignedVtx([ed25519Ix, collectIx], cachedAlt, payer);
2542
+ }
2377
2543
  // ─── Queries ─────────────────────────────────────────────────────────────────
2378
2544
  async fetchConfig() {
2379
2545
  try {
@@ -2422,20 +2588,22 @@ var FeeManagementClient = class {
2422
2588
  this.provider = provider;
2423
2589
  this.programIds = programIds;
2424
2590
  }
2425
- async initFeeConfig(admin, companyAddress, referralAddress, presaleRevenueAddress, investorsMarketRev, companyMarketRev, agentsPresaleRev, companyPresaleRev, authority, payer) {
2426
- const [feeConfigPda] = PDA.feeConfig(authority, this.programIds);
2591
+ async initFeeConfig(params) {
2592
+ const [feeConfigPda] = PDA.feeConfig(params.authority, this.programIds);
2427
2593
  const sig = await this.program.methods.initialize({
2428
- admin,
2429
- companyAddress,
2430
- referralAddress,
2431
- presaleRevenueAddress,
2432
- investorsMarketRev,
2433
- companyMarketRev,
2434
- agentsPresaleRev,
2435
- companyPresaleRev
2594
+ admin: params.admin,
2595
+ companyAddress: params.companyAddress,
2596
+ referralAddress: params.referralAddress,
2597
+ presaleRevenueAddress: params.presaleRevenueAddress,
2598
+ investorsMarketRev: params.investorsMarketRev,
2599
+ companyMarketRev: params.companyMarketRev,
2600
+ agentsPresaleRev: params.agentsPresaleRev,
2601
+ companyPresaleRev: params.companyPresaleRev,
2602
+ referralMarketRev: params.referralMarketRev,
2603
+ referralVault: params.referralVault
2436
2604
  }).accounts({
2437
- authority,
2438
- payer,
2605
+ authority: params.authority,
2606
+ payer: params.payer,
2439
2607
  feeConfig: feeConfigPda,
2440
2608
  systemProgram: SystemProgram.programId
2441
2609
  }).signers([]).rpc();
@@ -2483,19 +2651,21 @@ var FeeManagementClient = class {
2483
2651
  * @param authority - signer authorized in fee_config whitelist / admin / owner
2484
2652
  * @param payer - rent + tx fee payer
2485
2653
  */
2486
- async updateFeeConfig(companyAddress, referralAddress, presaleRevenueAddress, investorsMarketRev, companyMarketRev, agentsPresaleRev, companyPresaleRev, authority, payer) {
2487
- const [feeConfigPda] = PDA.feeConfig(authority, this.programIds);
2654
+ async updateFeeConfig(params) {
2655
+ const [feeConfigPda] = PDA.feeConfig(params.authority, this.programIds);
2488
2656
  const sig = await this.program.methods.updateConfig({
2489
- companyAddress,
2490
- referralAddress,
2491
- presaleRevenueAddress,
2492
- investorsMarketRev,
2493
- companyMarketRev,
2494
- agentsPresaleRev,
2495
- companyPresaleRev
2657
+ companyAddress: params.companyAddress,
2658
+ referralAddress: params.referralAddress,
2659
+ presaleRevenueAddress: params.presaleRevenueAddress,
2660
+ investorsMarketRev: params.investorsMarketRev,
2661
+ companyMarketRev: params.companyMarketRev,
2662
+ agentsPresaleRev: params.agentsPresaleRev,
2663
+ companyPresaleRev: params.companyPresaleRev,
2664
+ referralMarketRev: params.referralMarketRev,
2665
+ referralVault: params.referralVault
2496
2666
  }).accounts({
2497
- authority,
2498
- payer,
2667
+ authority: params.authority,
2668
+ payer: params.payer,
2499
2669
  feeConfig: feeConfigPda
2500
2670
  }).signers([]).rpc();
2501
2671
  return { signature: sig };
@@ -2512,33 +2682,33 @@ var FeeManagementClient = class {
2512
2682
  }).signers([]).rpc();
2513
2683
  return { signature: sig };
2514
2684
  }
2515
- async buildDistributeFeeIx(conditionPda, amount, feeConfigOwner, sourceAta, companyAta, marketOracleVault, authority) {
2685
+ /**
2686
+ * Build editMarketFee transaction (whitelist-only).
2687
+ * @param conditionPda - condition PDA (market identifier)
2688
+ * @param mergeFee - out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
2689
+ * @param redeemFee - out of FEE_DENOMINATOR
2690
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
2691
+ * @param feeConfigOwner - owner of fee_config PDA
2692
+ * @param authority - whitelisted signer (signs tx externally)
2693
+ * @param payer - fee payer (can differ from authority)
2694
+ */
2695
+ async buildEditMarketFeeTx(conditionPda, mergeFee, redeemFee, swapFee, feeConfigOwner, authority, payer = authority) {
2516
2696
  const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2517
- const [marketFeeOverridePda] = PDA.marketFeeOverride(conditionPda, this.programIds);
2518
- return this.program.methods.distributeFee(conditionPda, amount).accounts({
2519
- feeConfig: feeConfigPda,
2520
- marketFeeOverride: marketFeeOverridePda,
2697
+ const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
2698
+ return this.program.methods.setQuestionFee(
2699
+ Array.from(conditionPda.toBytes()),
2700
+ mergeFee,
2701
+ redeemFee,
2702
+ swapFee
2703
+ ).accounts({
2521
2704
  authority,
2522
- sourceAta,
2523
- companyAta,
2524
- marketOracleVault,
2525
- tokenProgram: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
2526
- }).instruction();
2527
- }
2528
- async distributeFee(conditionPda, amount, feeConfigOwner, sourceAta, companyAta, marketOracleVault, authority) {
2529
- const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2530
- const [marketFeeOverridePda] = PDA.marketFeeOverride(conditionPda, this.programIds);
2531
- const sig = await this.program.methods.distributeFee(conditionPda, amount).accounts({
2705
+ payer,
2532
2706
  feeConfig: feeConfigPda,
2533
- marketFeeOverride: marketFeeOverridePda,
2534
- authority,
2535
- sourceAta,
2536
- companyAta,
2537
- marketOracleVault,
2538
- tokenProgram: new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
2539
- }).signers([]).rpc();
2540
- return { signature: sig };
2707
+ questionFee: questionFeePda,
2708
+ systemProgram: SystemProgram.programId
2709
+ }).transaction();
2541
2710
  }
2711
+ /** @deprecated use buildEditMarketFeeTx */
2542
2712
  async setQuestionFee(conditionPda, mergeFee, redeemFee, swapFee, feeConfigOwner, authority, payer) {
2543
2713
  const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2544
2714
  const [questionFeePda] = PDA.questionFee(conditionPda, this.programIds);
@@ -2556,6 +2726,25 @@ var FeeManagementClient = class {
2556
2726
  }).signers([]).rpc();
2557
2727
  return { signature: sig };
2558
2728
  }
2729
+ /**
2730
+ * Build addToWhitelist tx — authority (admin/owner) signs externally.
2731
+ * Whitelist members can call editMarketFee / setQuestionFee.
2732
+ */
2733
+ /** Build addToWhitelist tx — authority (admin/owner) signs externally. */
2734
+ async buildAddToWhitelistTx(address, feeConfigOwner, authority) {
2735
+ const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2736
+ return this.program.methods.addToWhitelist(address).accounts({ authority, feeConfig: feeConfigPda }).transaction();
2737
+ }
2738
+ /** Build removeFromWhitelist tx — authority (admin/owner) signs externally. */
2739
+ async buildRemoveFromWhitelistTx(address, feeConfigOwner, authority) {
2740
+ const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2741
+ return this.program.methods.removeFromWhitelist(address).accounts({ authority, feeConfig: feeConfigPda }).transaction();
2742
+ }
2743
+ /** Build setAdmin tx — only owner signs externally. */
2744
+ async buildSetAdminTx(newAdmin, feeConfigOwner, authority) {
2745
+ const [feeConfigPda] = PDA.feeConfig(feeConfigOwner, this.programIds);
2746
+ return this.program.methods.setAdmin(newAdmin).accounts({ authority, feeConfig: feeConfigPda }).transaction();
2747
+ }
2559
2748
  };
2560
2749
  var PresaleClient = class {
2561
2750
  constructor(program, provider, programIds) {
@@ -2896,6 +3085,98 @@ var AdminClient = class {
2896
3085
  }).transaction();
2897
3086
  }
2898
3087
  };
3088
+ var ReferralClient = class {
3089
+ constructor(program, provider, programIds) {
3090
+ this.program = program;
3091
+ this.provider = provider;
3092
+ this.programIds = programIds;
3093
+ }
3094
+ get walletPubkey() {
3095
+ return this.provider.wallet.publicKey;
3096
+ }
3097
+ referralVault(owner, collateralMint) {
3098
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3099
+ return getAssociatedTokenAddressSync(collateralMint, configPda, true);
3100
+ }
3101
+ async fetchConfig(owner) {
3102
+ try {
3103
+ const [pda] = PDA.referralConfig(owner, this.programIds);
3104
+ const acc = await this.program.account.referralConfig.fetch(pda);
3105
+ return {
3106
+ owner: acc.owner,
3107
+ collateralMint: acc.collateralMint,
3108
+ whitelist: acc.whitelist.slice(0, acc.whitelistLen),
3109
+ bump: acc.bump
3110
+ };
3111
+ } catch {
3112
+ return null;
3113
+ }
3114
+ }
3115
+ /**
3116
+ * Build initialize tx — creates referral config PDA.
3117
+ * Also prepends an ATA creation instruction for the referral vault (idempotent).
3118
+ * Build-tx pattern.
3119
+ */
3120
+ async buildInitializeTx(collateralMint, owner = this.walletPubkey, payer = owner) {
3121
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3122
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3123
+ const vaultAta = getAssociatedTokenAddressSync(collateralMint, configPda, true);
3124
+ const createVaultIx = createAssociatedTokenAccountIdempotentInstruction(
3125
+ payer,
3126
+ vaultAta,
3127
+ configPda,
3128
+ collateralMint
3129
+ );
3130
+ const initTx = await this.program.methods.initialize().accounts({
3131
+ owner,
3132
+ payer,
3133
+ config: configPda,
3134
+ collateralMint,
3135
+ systemProgram: SystemProgram.programId
3136
+ }).transaction();
3137
+ const tx = new Transaction().add(createVaultIx, ...initTx.instructions);
3138
+ return { tx, configPda, vaultAta };
3139
+ }
3140
+ /** Build add-to-whitelist tx. Build-tx pattern. */
3141
+ async buildAddToWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3142
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3143
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3144
+ return this.program.methods.addToWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3145
+ }
3146
+ /** Build remove-from-whitelist tx. Build-tx pattern. */
3147
+ async buildRemoveFromWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3148
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3149
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3150
+ return this.program.methods.removeFromWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3151
+ }
3152
+ /**
3153
+ * Build batchSendUsds tx. Build-tx pattern.
3154
+ * @param recipients - wallet addresses to send to
3155
+ * @param amounts - corresponding amounts in token smallest units
3156
+ * @param configOwner - owner of referral config (used to derive config + vault)
3157
+ * @param collateralMint - token mint
3158
+ * @param authority - whitelisted signer
3159
+ * @param payer - fee payer (can differ from authority)
3160
+ */
3161
+ async buildBatchSendUsdsTx(recipients, amounts, configOwner, collateralMint, authority = this.walletPubkey, payer = authority) {
3162
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3163
+ if (recipients.length !== amounts.length) throw new Error("recipients and amounts must have same length");
3164
+ if (recipients.length === 0) throw new Error("recipients array is empty");
3165
+ const [configPda] = PDA.referralConfig(configOwner, this.programIds);
3166
+ const referralVault = getAssociatedTokenAddressSync(collateralMint, configPda, true);
3167
+ const recipientAtas = recipients.map(
3168
+ (wallet) => getAssociatedTokenAddressSync(collateralMint, wallet)
3169
+ );
3170
+ return this.program.methods.batchSendUsds(amounts).accounts({
3171
+ authority,
3172
+ config: configPda,
3173
+ referralVault,
3174
+ tokenProgram: TOKEN_PROGRAM_ID
3175
+ }).remainingAccounts(
3176
+ recipientAtas.map((ata) => ({ pubkey: ata, isSigner: false, isWritable: true }))
3177
+ ).transaction();
3178
+ }
3179
+ };
2899
3180
 
2900
3181
  // src/idls/oracle.json
2901
3182
  var oracle_default = {
@@ -8758,84 +9039,252 @@ var clob_exchange_default = {
8758
9039
  ]
8759
9040
  },
8760
9041
  {
8761
- name: "cancel_order",
9042
+ name: "batch_collect_redeem_early",
8762
9043
  docs: [
8763
- "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
9044
+ "Batch collect fee tokens from winning users after question resolution,",
9045
+ "redeem them via CTF, and distribute USDS via fee_management."
8764
9046
  ],
8765
9047
  discriminator: [
8766
- 95,
8767
- 129,
8768
- 237,
8769
- 240,
8770
- 8,
8771
- 49,
8772
- 223,
8773
- 132
9048
+ 87,
9049
+ 149,
9050
+ 45,
9051
+ 245,
9052
+ 249,
9053
+ 25,
9054
+ 207,
9055
+ 82
8774
9056
  ],
8775
9057
  accounts: [
8776
9058
  {
8777
- name: "maker",
8778
- docs: [
8779
- "Must be the order maker/signer"
8780
- ],
9059
+ name: "operator",
8781
9060
  signer: true
8782
9061
  },
8783
9062
  {
8784
- name: "order_record",
9063
+ name: "payer",
9064
+ writable: true,
9065
+ signer: true
9066
+ },
9067
+ {
9068
+ name: "clob_config",
8785
9069
  writable: true,
8786
9070
  pda: {
8787
9071
  seeds: [
8788
9072
  {
8789
9073
  kind: "const",
8790
9074
  value: [
9075
+ 99,
9076
+ 108,
8791
9077
  111,
8792
- 114,
8793
- 100,
8794
- 101,
8795
- 114,
9078
+ 98,
8796
9079
  95,
8797
- 114,
8798
- 101,
8799
9080
  99,
8800
9081
  111,
8801
- 114,
8802
- 100
9082
+ 110,
9083
+ 102,
9084
+ 105,
9085
+ 103
8803
9086
  ]
8804
- },
8805
- {
8806
- kind: "account",
8807
- path: "maker"
8808
- },
8809
- {
8810
- kind: "arg",
8811
- path: "nonce"
8812
9087
  }
8813
9088
  ]
8814
9089
  }
8815
9090
  },
8816
9091
  {
8817
- name: "system_program",
8818
- address: "11111111111111111111111111111111"
8819
- }
8820
- ],
8821
- args: [
9092
+ name: "condition",
9093
+ writable: true
9094
+ },
8822
9095
  {
8823
- name: "nonce",
8824
- type: "u64"
8825
- }
8826
- ]
8827
- },
8828
- {
8829
- name: "force_reset_clob",
8830
- discriminator: [
8831
- 96,
8832
- 95,
8833
- 187,
8834
- 95,
8835
- 65,
8836
- 135,
8837
- 120,
8838
- 204
9096
+ name: "collateral_vault",
9097
+ writable: true,
9098
+ pda: {
9099
+ seeds: [
9100
+ {
9101
+ kind: "const",
9102
+ value: [
9103
+ 99,
9104
+ 111,
9105
+ 108,
9106
+ 108,
9107
+ 97,
9108
+ 116,
9109
+ 101,
9110
+ 114,
9111
+ 97,
9112
+ 108,
9113
+ 95,
9114
+ 118,
9115
+ 97,
9116
+ 117,
9117
+ 108,
9118
+ 116
9119
+ ]
9120
+ },
9121
+ {
9122
+ kind: "account",
9123
+ path: "condition.collateral_mint",
9124
+ account: "Condition"
9125
+ }
9126
+ ],
9127
+ program: {
9128
+ kind: "account",
9129
+ path: "conditional_tokens_program"
9130
+ }
9131
+ }
9132
+ },
9133
+ {
9134
+ name: "vault_token_account",
9135
+ writable: true
9136
+ },
9137
+ {
9138
+ name: "fee_recipient",
9139
+ docs: [
9140
+ "CLOB's USDS ATA \u2014 receives USDS payout from redeem, then distribute_fee draws from it."
9141
+ ],
9142
+ writable: true
9143
+ },
9144
+ {
9145
+ name: "yes_mint",
9146
+ writable: true
9147
+ },
9148
+ {
9149
+ name: "no_mint",
9150
+ writable: true
9151
+ },
9152
+ {
9153
+ name: "clob_yes_ata",
9154
+ docs: [
9155
+ "CLOB's YES ATA (Token-2022) \u2014 must be pre-initialized (created during prior matchOrders)."
9156
+ ],
9157
+ writable: true
9158
+ },
9159
+ {
9160
+ name: "clob_no_ata",
9161
+ docs: [
9162
+ "CLOB's NO ATA (Token-2022) \u2014 must be pre-initialized."
9163
+ ],
9164
+ writable: true
9165
+ },
9166
+ {
9167
+ name: "clob_yes_position",
9168
+ writable: true
9169
+ },
9170
+ {
9171
+ name: "clob_no_position",
9172
+ writable: true
9173
+ },
9174
+ {
9175
+ name: "ix_sysvar"
9176
+ },
9177
+ {
9178
+ name: "conditional_tokens_program",
9179
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
9180
+ },
9181
+ {
9182
+ name: "token_program",
9183
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
9184
+ },
9185
+ {
9186
+ name: "token_2022_program",
9187
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
9188
+ },
9189
+ {
9190
+ name: "system_program",
9191
+ address: "11111111111111111111111111111111"
9192
+ }
9193
+ ],
9194
+ args: [
9195
+ {
9196
+ name: "ix_index",
9197
+ type: "u8"
9198
+ },
9199
+ {
9200
+ name: "order_count",
9201
+ type: "u8"
9202
+ },
9203
+ {
9204
+ name: "outcome_index",
9205
+ type: "u8"
9206
+ }
9207
+ ]
9208
+ },
9209
+ {
9210
+ name: "cancel_order",
9211
+ docs: [
9212
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
9213
+ ],
9214
+ discriminator: [
9215
+ 95,
9216
+ 129,
9217
+ 237,
9218
+ 240,
9219
+ 8,
9220
+ 49,
9221
+ 223,
9222
+ 132
9223
+ ],
9224
+ accounts: [
9225
+ {
9226
+ name: "maker",
9227
+ docs: [
9228
+ "Must be the order maker/signer"
9229
+ ],
9230
+ signer: true
9231
+ },
9232
+ {
9233
+ name: "order_record",
9234
+ writable: true,
9235
+ pda: {
9236
+ seeds: [
9237
+ {
9238
+ kind: "const",
9239
+ value: [
9240
+ 111,
9241
+ 114,
9242
+ 100,
9243
+ 101,
9244
+ 114,
9245
+ 95,
9246
+ 114,
9247
+ 101,
9248
+ 99,
9249
+ 111,
9250
+ 114,
9251
+ 100
9252
+ ]
9253
+ },
9254
+ {
9255
+ kind: "account",
9256
+ path: "maker"
9257
+ },
9258
+ {
9259
+ kind: "arg",
9260
+ path: "nonce"
9261
+ }
9262
+ ]
9263
+ }
9264
+ },
9265
+ {
9266
+ name: "system_program",
9267
+ address: "11111111111111111111111111111111"
9268
+ }
9269
+ ],
9270
+ args: [
9271
+ {
9272
+ name: "nonce",
9273
+ type: "u64"
9274
+ }
9275
+ ]
9276
+ },
9277
+ {
9278
+ name: "force_reset_clob",
9279
+ discriminator: [
9280
+ 96,
9281
+ 95,
9282
+ 187,
9283
+ 95,
9284
+ 65,
9285
+ 135,
9286
+ 120,
9287
+ 204
8839
9288
  ],
8840
9289
  accounts: [
8841
9290
  {
@@ -8970,7 +9419,7 @@ var clob_exchange_default = {
8970
9419
  {
8971
9420
  name: "match_complementary",
8972
9421
  docs: [
8973
- "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
9422
+ "COMPLEMENTARY match: 1 taker (BUY or SELL) + N makers (opposite side) via remaining_accounts."
8974
9423
  ],
8975
9424
  discriminator: [
8976
9425
  100,
@@ -9263,9 +9712,6 @@ var clob_exchange_default = {
9263
9712
  },
9264
9713
  {
9265
9714
  name: "clob_usdc_ata",
9266
- docs: [
9267
- "USDC ATA owned by clob_config \u2014 receives USDC from vault after merge"
9268
- ],
9269
9715
  writable: true,
9270
9716
  pda: {
9271
9717
  seeds: [
@@ -9542,9 +9988,6 @@ var clob_exchange_default = {
9542
9988
  },
9543
9989
  {
9544
9990
  name: "clob_usdc_ata",
9545
- docs: [
9546
- "USDC ATA owned by clob_config \u2014 receives combined USDC, then split_position pulls from here"
9547
- ],
9548
9991
  writable: true,
9549
9992
  pda: {
9550
9993
  seeds: [
@@ -9602,30 +10045,18 @@ var clob_exchange_default = {
9602
10045
  },
9603
10046
  {
9604
10047
  name: "clob_yes_ata",
9605
- docs: [
9606
- "YES Token-2022 ATA owned by clob_config \u2014 receives YES from split, then transferred to taker"
9607
- ],
9608
10048
  writable: true
9609
10049
  },
9610
10050
  {
9611
10051
  name: "clob_no_ata",
9612
- docs: [
9613
- "NO Token-2022 ATA owned by clob_config \u2014 receives NO from split, then transferred to makers"
9614
- ],
9615
10052
  writable: true
9616
10053
  },
9617
10054
  {
9618
10055
  name: "clob_yes_position",
9619
- docs: [
9620
- "YES Position PDA for clob_config (set by CTF split_position init_if_needed)"
9621
- ],
9622
10056
  writable: true
9623
10057
  },
9624
10058
  {
9625
10059
  name: "clob_no_position",
9626
- docs: [
9627
- "NO Position PDA for clob_config (set by CTF split_position init_if_needed)"
9628
- ],
9629
10060
  writable: true
9630
10061
  },
9631
10062
  {
@@ -10539,11 +10970,6 @@ var fee_management_default = {
10539
10970
  name: "authority",
10540
10971
  signer: true
10541
10972
  },
10542
- {
10543
- name: "payer",
10544
- writable: true,
10545
- signer: true
10546
- },
10547
10973
  {
10548
10974
  name: "fee_config",
10549
10975
  writable: true,
@@ -10661,11 +11087,18 @@ var fee_management_default = {
10661
11087
  {
10662
11088
  name: "market_oracle_vault",
10663
11089
  docs: [
10664
- "Writable: tokens are transferred here when is_admin=false.",
11090
+ "Writable: tokens are transferred here (investors share) when is_admin=false.",
10665
11091
  "For admin questions pass any writable account (no transfer occurs)."
10666
11092
  ],
10667
11093
  writable: true
10668
11094
  },
11095
+ {
11096
+ name: "referral_vault",
11097
+ docs: [
11098
+ "Must match fee_config.referral_vault."
11099
+ ],
11100
+ writable: true
11101
+ },
10669
11102
  {
10670
11103
  name: "token_program",
10671
11104
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -10828,11 +11261,6 @@ var fee_management_default = {
10828
11261
  name: "authority",
10829
11262
  signer: true
10830
11263
  },
10831
- {
10832
- name: "payer",
10833
- writable: true,
10834
- signer: true
10835
- },
10836
11264
  {
10837
11265
  name: "fee_config",
10838
11266
  writable: true,
@@ -10886,11 +11314,6 @@ var fee_management_default = {
10886
11314
  name: "authority",
10887
11315
  signer: true
10888
11316
  },
10889
- {
10890
- name: "payer",
10891
- writable: true,
10892
- signer: true
10893
- },
10894
11317
  {
10895
11318
  name: "fee_config",
10896
11319
  writable: true,
@@ -11524,7 +11947,8 @@ var fee_management_default = {
11524
11947
  {
11525
11948
  name: "investors_market_rev",
11526
11949
  docs: [
11527
- "Market revenue split: investors + company (out of FEE_DENOMINATOR = 1_000_000)"
11950
+ "Market revenue split \u2014 three parts must sum to FEE_DENOMINATOR (10_000).",
11951
+ "investors_market_rev + company_market_rev + referral_market_rev == 10_000"
11528
11952
  ],
11529
11953
  type: "u32"
11530
11954
  },
@@ -11535,7 +11959,7 @@ var fee_management_default = {
11535
11959
  {
11536
11960
  name: "agents_presale_rev",
11537
11961
  docs: [
11538
- "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 1_000_000)"
11962
+ "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 10_000)"
11539
11963
  ],
11540
11964
  type: "u32"
11541
11965
  },
@@ -11560,12 +11984,26 @@ var fee_management_default = {
11560
11984
  name: "bump",
11561
11985
  type: "u8"
11562
11986
  },
11987
+ {
11988
+ name: "referral_market_rev",
11989
+ docs: [
11990
+ "Share of market trading fees routed to referral_vault (e.g. 2_000 = 20%)"
11991
+ ],
11992
+ type: "u32"
11993
+ },
11994
+ {
11995
+ name: "referral_vault",
11996
+ docs: [
11997
+ "ATA of referral program config PDA \u2014 receives referral_market_rev% of trading fees"
11998
+ ],
11999
+ type: "pubkey"
12000
+ },
11563
12001
  {
11564
12002
  name: "_reserved",
11565
12003
  type: {
11566
12004
  array: [
11567
12005
  "u8",
11568
- 64
12006
+ 28
11569
12007
  ]
11570
12008
  }
11571
12009
  }
@@ -11692,6 +12130,14 @@ var fee_management_default = {
11692
12130
  {
11693
12131
  name: "company_presale_rev",
11694
12132
  type: "u32"
12133
+ },
12134
+ {
12135
+ name: "referral_market_rev",
12136
+ type: "u32"
12137
+ },
12138
+ {
12139
+ name: "referral_vault",
12140
+ type: "pubkey"
11695
12141
  }
11696
12142
  ]
11697
12143
  }
@@ -11952,6 +12398,14 @@ var fee_management_default = {
11952
12398
  {
11953
12399
  name: "company_presale_rev",
11954
12400
  type: "u32"
12401
+ },
12402
+ {
12403
+ name: "referral_market_rev",
12404
+ type: "u32"
12405
+ },
12406
+ {
12407
+ name: "referral_vault",
12408
+ type: "pubkey"
11955
12409
  }
11956
12410
  ]
11957
12411
  }
@@ -15300,20 +15754,510 @@ var admin_contract_default = {
15300
15754
  ]
15301
15755
  };
15302
15756
 
15303
- // src/sdk.ts
15304
- var XMarketSDK = class {
15305
- // lazy-init in get admin()
15306
- constructor(config, wallet, marketOwner) {
15307
- this.networkConfig = config;
15308
- this.provider = new anchor5.AnchorProvider(
15309
- new Connection(config.rpcUrl, "confirmed"),
15310
- wallet,
15311
- { commitment: "confirmed", preflightCommitment: "confirmed" }
15312
- );
15313
- anchor5.setProvider(this.provider);
15314
- this._programIds = config.programIds;
15315
- this._marketOwner = marketOwner ?? wallet.publicKey;
15316
- }
15757
+ // src/idls/referral.json
15758
+ var referral_default = {
15759
+ address: "7b5ohWDqrQ2KRcDJMWwj1dwgRkt5ZJdMavSmrXn9oBgL",
15760
+ metadata: {
15761
+ name: "referral",
15762
+ version: "0.1.0",
15763
+ spec: "0.1.0",
15764
+ description: "Referral program for XMarket \u2014 whitelist-gated batch USDS distribution"
15765
+ },
15766
+ instructions: [
15767
+ {
15768
+ name: "add_to_whitelist",
15769
+ discriminator: [
15770
+ 157,
15771
+ 211,
15772
+ 52,
15773
+ 54,
15774
+ 144,
15775
+ 81,
15776
+ 5,
15777
+ 55
15778
+ ],
15779
+ accounts: [
15780
+ {
15781
+ name: "owner",
15782
+ signer: true
15783
+ },
15784
+ {
15785
+ name: "payer",
15786
+ writable: true,
15787
+ signer: true
15788
+ },
15789
+ {
15790
+ name: "config",
15791
+ writable: true,
15792
+ pda: {
15793
+ seeds: [
15794
+ {
15795
+ kind: "const",
15796
+ value: [
15797
+ 114,
15798
+ 101,
15799
+ 102,
15800
+ 101,
15801
+ 114,
15802
+ 114,
15803
+ 97,
15804
+ 108,
15805
+ 95,
15806
+ 99,
15807
+ 111,
15808
+ 110,
15809
+ 102,
15810
+ 105,
15811
+ 103
15812
+ ]
15813
+ },
15814
+ {
15815
+ kind: "account",
15816
+ path: "config.owner",
15817
+ account: "ReferralConfig"
15818
+ }
15819
+ ]
15820
+ }
15821
+ }
15822
+ ],
15823
+ args: [
15824
+ {
15825
+ name: "address",
15826
+ type: "pubkey"
15827
+ }
15828
+ ]
15829
+ },
15830
+ {
15831
+ name: "batch_send_usds",
15832
+ discriminator: [
15833
+ 255,
15834
+ 33,
15835
+ 77,
15836
+ 124,
15837
+ 42,
15838
+ 207,
15839
+ 250,
15840
+ 162
15841
+ ],
15842
+ accounts: [
15843
+ {
15844
+ name: "authority",
15845
+ docs: [
15846
+ "Whitelisted caller (authority, signs tx)"
15847
+ ],
15848
+ signer: true
15849
+ },
15850
+ {
15851
+ name: "config",
15852
+ pda: {
15853
+ seeds: [
15854
+ {
15855
+ kind: "const",
15856
+ value: [
15857
+ 114,
15858
+ 101,
15859
+ 102,
15860
+ 101,
15861
+ 114,
15862
+ 114,
15863
+ 97,
15864
+ 108,
15865
+ 95,
15866
+ 99,
15867
+ 111,
15868
+ 110,
15869
+ 102,
15870
+ 105,
15871
+ 103
15872
+ ]
15873
+ },
15874
+ {
15875
+ kind: "account",
15876
+ path: "config.owner",
15877
+ account: "ReferralConfig"
15878
+ }
15879
+ ]
15880
+ }
15881
+ },
15882
+ {
15883
+ name: "referral_vault",
15884
+ docs: [
15885
+ "Referral vault \u2014 source of transfers (ATA owned by config PDA)"
15886
+ ],
15887
+ writable: true,
15888
+ pda: {
15889
+ seeds: [
15890
+ {
15891
+ kind: "account",
15892
+ path: "config"
15893
+ },
15894
+ {
15895
+ kind: "const",
15896
+ value: [
15897
+ 6,
15898
+ 221,
15899
+ 246,
15900
+ 225,
15901
+ 215,
15902
+ 101,
15903
+ 161,
15904
+ 147,
15905
+ 217,
15906
+ 203,
15907
+ 225,
15908
+ 70,
15909
+ 206,
15910
+ 235,
15911
+ 121,
15912
+ 172,
15913
+ 28,
15914
+ 180,
15915
+ 133,
15916
+ 237,
15917
+ 95,
15918
+ 91,
15919
+ 55,
15920
+ 145,
15921
+ 58,
15922
+ 140,
15923
+ 245,
15924
+ 133,
15925
+ 126,
15926
+ 255,
15927
+ 0,
15928
+ 169
15929
+ ]
15930
+ },
15931
+ {
15932
+ kind: "account",
15933
+ path: "config.collateral_mint",
15934
+ account: "ReferralConfig"
15935
+ }
15936
+ ],
15937
+ program: {
15938
+ kind: "const",
15939
+ value: [
15940
+ 140,
15941
+ 151,
15942
+ 37,
15943
+ 143,
15944
+ 78,
15945
+ 36,
15946
+ 137,
15947
+ 241,
15948
+ 187,
15949
+ 61,
15950
+ 16,
15951
+ 41,
15952
+ 20,
15953
+ 142,
15954
+ 13,
15955
+ 131,
15956
+ 11,
15957
+ 90,
15958
+ 19,
15959
+ 153,
15960
+ 218,
15961
+ 255,
15962
+ 16,
15963
+ 132,
15964
+ 4,
15965
+ 142,
15966
+ 123,
15967
+ 216,
15968
+ 219,
15969
+ 233,
15970
+ 248,
15971
+ 89
15972
+ ]
15973
+ }
15974
+ }
15975
+ },
15976
+ {
15977
+ name: "token_program",
15978
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
15979
+ }
15980
+ ],
15981
+ args: [
15982
+ {
15983
+ name: "amounts",
15984
+ type: {
15985
+ vec: "u64"
15986
+ }
15987
+ }
15988
+ ]
15989
+ },
15990
+ {
15991
+ name: "initialize",
15992
+ discriminator: [
15993
+ 175,
15994
+ 175,
15995
+ 109,
15996
+ 31,
15997
+ 13,
15998
+ 152,
15999
+ 155,
16000
+ 237
16001
+ ],
16002
+ accounts: [
16003
+ {
16004
+ name: "owner",
16005
+ writable: true,
16006
+ signer: true
16007
+ },
16008
+ {
16009
+ name: "payer",
16010
+ writable: true,
16011
+ signer: true
16012
+ },
16013
+ {
16014
+ name: "config",
16015
+ writable: true,
16016
+ pda: {
16017
+ seeds: [
16018
+ {
16019
+ kind: "const",
16020
+ value: [
16021
+ 114,
16022
+ 101,
16023
+ 102,
16024
+ 101,
16025
+ 114,
16026
+ 114,
16027
+ 97,
16028
+ 108,
16029
+ 95,
16030
+ 99,
16031
+ 111,
16032
+ 110,
16033
+ 102,
16034
+ 105,
16035
+ 103
16036
+ ]
16037
+ },
16038
+ {
16039
+ kind: "account",
16040
+ path: "owner"
16041
+ }
16042
+ ]
16043
+ }
16044
+ },
16045
+ {
16046
+ name: "collateral_mint"
16047
+ },
16048
+ {
16049
+ name: "system_program",
16050
+ address: "11111111111111111111111111111111"
16051
+ }
16052
+ ],
16053
+ args: []
16054
+ },
16055
+ {
16056
+ name: "remove_from_whitelist",
16057
+ discriminator: [
16058
+ 7,
16059
+ 144,
16060
+ 216,
16061
+ 239,
16062
+ 243,
16063
+ 236,
16064
+ 193,
16065
+ 235
16066
+ ],
16067
+ accounts: [
16068
+ {
16069
+ name: "owner",
16070
+ signer: true
16071
+ },
16072
+ {
16073
+ name: "payer",
16074
+ writable: true,
16075
+ signer: true
16076
+ },
16077
+ {
16078
+ name: "config",
16079
+ writable: true,
16080
+ pda: {
16081
+ seeds: [
16082
+ {
16083
+ kind: "const",
16084
+ value: [
16085
+ 114,
16086
+ 101,
16087
+ 102,
16088
+ 101,
16089
+ 114,
16090
+ 114,
16091
+ 97,
16092
+ 108,
16093
+ 95,
16094
+ 99,
16095
+ 111,
16096
+ 110,
16097
+ 102,
16098
+ 105,
16099
+ 103
16100
+ ]
16101
+ },
16102
+ {
16103
+ kind: "account",
16104
+ path: "config.owner",
16105
+ account: "ReferralConfig"
16106
+ }
16107
+ ]
16108
+ }
16109
+ }
16110
+ ],
16111
+ args: [
16112
+ {
16113
+ name: "address",
16114
+ type: "pubkey"
16115
+ }
16116
+ ]
16117
+ }
16118
+ ],
16119
+ accounts: [
16120
+ {
16121
+ name: "ReferralConfig",
16122
+ discriminator: [
16123
+ 102,
16124
+ 148,
16125
+ 171,
16126
+ 235,
16127
+ 148,
16128
+ 83,
16129
+ 250,
16130
+ 140
16131
+ ]
16132
+ }
16133
+ ],
16134
+ events: [
16135
+ {
16136
+ name: "BatchSent",
16137
+ discriminator: [
16138
+ 116,
16139
+ 64,
16140
+ 207,
16141
+ 63,
16142
+ 56,
16143
+ 97,
16144
+ 15,
16145
+ 100
16146
+ ]
16147
+ },
16148
+ {
16149
+ name: "ReferralInitialized",
16150
+ discriminator: [
16151
+ 129,
16152
+ 190,
16153
+ 249,
16154
+ 4,
16155
+ 198,
16156
+ 5,
16157
+ 141,
16158
+ 226
16159
+ ]
16160
+ }
16161
+ ],
16162
+ types: [
16163
+ {
16164
+ name: "BatchSent",
16165
+ type: {
16166
+ kind: "struct",
16167
+ fields: [
16168
+ {
16169
+ name: "config",
16170
+ type: "pubkey"
16171
+ },
16172
+ {
16173
+ name: "sent_by",
16174
+ type: "pubkey"
16175
+ },
16176
+ {
16177
+ name: "recipients",
16178
+ type: "u8"
16179
+ }
16180
+ ]
16181
+ }
16182
+ },
16183
+ {
16184
+ name: "ReferralConfig",
16185
+ type: {
16186
+ kind: "struct",
16187
+ fields: [
16188
+ {
16189
+ name: "version",
16190
+ type: "u8"
16191
+ },
16192
+ {
16193
+ name: "owner",
16194
+ type: "pubkey"
16195
+ },
16196
+ {
16197
+ name: "collateral_mint",
16198
+ type: "pubkey"
16199
+ },
16200
+ {
16201
+ name: "whitelist",
16202
+ type: {
16203
+ array: [
16204
+ "pubkey",
16205
+ 10
16206
+ ]
16207
+ }
16208
+ },
16209
+ {
16210
+ name: "whitelist_len",
16211
+ type: "u8"
16212
+ },
16213
+ {
16214
+ name: "bump",
16215
+ type: "u8"
16216
+ },
16217
+ {
16218
+ name: "_reserved",
16219
+ type: {
16220
+ array: [
16221
+ "u8",
16222
+ 64
16223
+ ]
16224
+ }
16225
+ }
16226
+ ]
16227
+ }
16228
+ },
16229
+ {
16230
+ name: "ReferralInitialized",
16231
+ type: {
16232
+ kind: "struct",
16233
+ fields: [
16234
+ {
16235
+ name: "config",
16236
+ type: "pubkey"
16237
+ },
16238
+ {
16239
+ name: "owner",
16240
+ type: "pubkey"
16241
+ }
16242
+ ]
16243
+ }
16244
+ }
16245
+ ]
16246
+ };
16247
+
16248
+ // src/sdk.ts
16249
+ var XMarketSDK = class {
16250
+ constructor(config, wallet, marketOwner) {
16251
+ this.networkConfig = config;
16252
+ this.provider = new anchor5.AnchorProvider(
16253
+ new Connection(config.rpcUrl, "confirmed"),
16254
+ wallet,
16255
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
16256
+ );
16257
+ anchor5.setProvider(this.provider);
16258
+ this._programIds = config.programIds;
16259
+ this._marketOwner = marketOwner ?? wallet.publicKey;
16260
+ }
15317
16261
  _withAddress(idl, address) {
15318
16262
  return { ...idl, address: address.toBase58() };
15319
16263
  }
@@ -15389,6 +16333,14 @@ var XMarketSDK = class {
15389
16333
  }
15390
16334
  return this._admin;
15391
16335
  }
16336
+ get referral() {
16337
+ if (!this._referral) {
16338
+ if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
16339
+ const program = new anchor5.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
16340
+ this._referral = new ReferralClient(program, this.provider, this._programIds);
16341
+ }
16342
+ return this._referral;
16343
+ }
15392
16344
  };
15393
16345
  var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
15394
16346
  function buildCreateUserAtasTx(condition, user, payer, programIds) {
@@ -15461,6 +16413,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
15461
16413
  return tx;
15462
16414
  }
15463
16415
 
15464
- export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, FEE_DENOMINATOR, FeeManagementClient, HookClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
16416
+ export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, FEE_DENOMINATOR, FeeManagementClient, HookClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, ReferralClient, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
15465
16417
  //# sourceMappingURL=index.mjs.map
15466
16418
  //# sourceMappingURL=index.mjs.map