@theliem/xmarket-sdk 3.13.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.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);
@@ -2896,6 +3066,98 @@ var AdminClient = class {
2896
3066
  }).transaction();
2897
3067
  }
2898
3068
  };
3069
+ var ReferralClient = class {
3070
+ constructor(program, provider, programIds) {
3071
+ this.program = program;
3072
+ this.provider = provider;
3073
+ this.programIds = programIds;
3074
+ }
3075
+ get walletPubkey() {
3076
+ return this.provider.wallet.publicKey;
3077
+ }
3078
+ referralVault(owner, collateralMint) {
3079
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3080
+ return getAssociatedTokenAddressSync(collateralMint, configPda, true);
3081
+ }
3082
+ async fetchConfig(owner) {
3083
+ try {
3084
+ const [pda] = PDA.referralConfig(owner, this.programIds);
3085
+ const acc = await this.program.account.referralConfig.fetch(pda);
3086
+ return {
3087
+ owner: acc.owner,
3088
+ collateralMint: acc.collateralMint,
3089
+ whitelist: acc.whitelist.slice(0, acc.whitelistLen),
3090
+ bump: acc.bump
3091
+ };
3092
+ } catch {
3093
+ return null;
3094
+ }
3095
+ }
3096
+ /**
3097
+ * Build initialize tx — creates referral config PDA.
3098
+ * Also prepends an ATA creation instruction for the referral vault (idempotent).
3099
+ * Build-tx pattern.
3100
+ */
3101
+ async buildInitializeTx(collateralMint, owner = this.walletPubkey, payer = owner) {
3102
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3103
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3104
+ const vaultAta = getAssociatedTokenAddressSync(collateralMint, configPda, true);
3105
+ const createVaultIx = createAssociatedTokenAccountIdempotentInstruction(
3106
+ payer,
3107
+ vaultAta,
3108
+ configPda,
3109
+ collateralMint
3110
+ );
3111
+ const initTx = await this.program.methods.initialize().accounts({
3112
+ owner,
3113
+ payer,
3114
+ config: configPda,
3115
+ collateralMint,
3116
+ systemProgram: SystemProgram.programId
3117
+ }).transaction();
3118
+ const tx = new Transaction().add(createVaultIx, ...initTx.instructions);
3119
+ return { tx, configPda, vaultAta };
3120
+ }
3121
+ /** Build add-to-whitelist tx. Build-tx pattern. */
3122
+ async buildAddToWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3123
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3124
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3125
+ return this.program.methods.addToWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3126
+ }
3127
+ /** Build remove-from-whitelist tx. Build-tx pattern. */
3128
+ async buildRemoveFromWhitelistTx(address, owner = this.walletPubkey, payer = owner) {
3129
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3130
+ const [configPda] = PDA.referralConfig(owner, this.programIds);
3131
+ return this.program.methods.removeFromWhitelist(address).accounts({ owner, payer, config: configPda }).transaction();
3132
+ }
3133
+ /**
3134
+ * Build batchSendUsds tx. Build-tx pattern.
3135
+ * @param recipients - wallet addresses to send to
3136
+ * @param amounts - corresponding amounts in token smallest units
3137
+ * @param configOwner - owner of referral config (used to derive config + vault)
3138
+ * @param collateralMint - token mint
3139
+ * @param authority - whitelisted signer
3140
+ * @param payer - fee payer (can differ from authority)
3141
+ */
3142
+ async buildBatchSendUsdsTx(recipients, amounts, configOwner, collateralMint, authority = this.walletPubkey, payer = authority) {
3143
+ if (!this.programIds.referral) throw new Error("referral program ID not configured");
3144
+ if (recipients.length !== amounts.length) throw new Error("recipients and amounts must have same length");
3145
+ if (recipients.length === 0) throw new Error("recipients array is empty");
3146
+ const [configPda] = PDA.referralConfig(configOwner, this.programIds);
3147
+ const referralVault = getAssociatedTokenAddressSync(collateralMint, configPda, true);
3148
+ const recipientAtas = recipients.map(
3149
+ (wallet) => getAssociatedTokenAddressSync(collateralMint, wallet)
3150
+ );
3151
+ return this.program.methods.batchSendUsds(amounts).accounts({
3152
+ authority,
3153
+ config: configPda,
3154
+ referralVault,
3155
+ tokenProgram: TOKEN_PROGRAM_ID
3156
+ }).remainingAccounts(
3157
+ recipientAtas.map((ata) => ({ pubkey: ata, isSigner: false, isWritable: true }))
3158
+ ).transaction();
3159
+ }
3160
+ };
2899
3161
 
2900
3162
  // src/idls/oracle.json
2901
3163
  var oracle_default = {
@@ -8758,92 +9020,260 @@ var clob_exchange_default = {
8758
9020
  ]
8759
9021
  },
8760
9022
  {
8761
- name: "cancel_order",
9023
+ name: "batch_collect_redeem_early",
8762
9024
  docs: [
8763
- "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
9025
+ "Batch collect fee tokens from winning users after question resolution,",
9026
+ "redeem them via CTF, and distribute USDS via fee_management."
8764
9027
  ],
8765
9028
  discriminator: [
8766
- 95,
8767
- 129,
8768
- 237,
8769
- 240,
8770
- 8,
8771
- 49,
8772
- 223,
8773
- 132
9029
+ 87,
9030
+ 149,
9031
+ 45,
9032
+ 245,
9033
+ 249,
9034
+ 25,
9035
+ 207,
9036
+ 82
8774
9037
  ],
8775
9038
  accounts: [
8776
9039
  {
8777
- name: "maker",
8778
- docs: [
8779
- "Must be the order maker/signer"
8780
- ],
9040
+ name: "operator",
8781
9041
  signer: true
8782
9042
  },
8783
9043
  {
8784
- name: "order_record",
9044
+ name: "payer",
9045
+ writable: true,
9046
+ signer: true
9047
+ },
9048
+ {
9049
+ name: "clob_config",
8785
9050
  writable: true,
8786
9051
  pda: {
8787
9052
  seeds: [
8788
9053
  {
8789
9054
  kind: "const",
8790
9055
  value: [
9056
+ 99,
9057
+ 108,
8791
9058
  111,
8792
- 114,
8793
- 100,
8794
- 101,
8795
- 114,
9059
+ 98,
8796
9060
  95,
8797
- 114,
8798
- 101,
8799
9061
  99,
8800
9062
  111,
8801
- 114,
8802
- 100
9063
+ 110,
9064
+ 102,
9065
+ 105,
9066
+ 103
8803
9067
  ]
8804
- },
8805
- {
8806
- kind: "account",
8807
- path: "maker"
8808
- },
8809
- {
8810
- kind: "arg",
8811
- path: "nonce"
8812
9068
  }
8813
9069
  ]
8814
9070
  }
8815
9071
  },
8816
9072
  {
8817
- name: "system_program",
8818
- address: "11111111111111111111111111111111"
8819
- }
8820
- ],
8821
- args: [
8822
- {
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
8839
- ],
8840
- accounts: [
9073
+ name: "condition",
9074
+ writable: true
9075
+ },
8841
9076
  {
8842
- name: "upgrade_authority",
8843
- docs: [
8844
- "Must be the upgrade authority (deployer). Checked in handler via",
8845
- "programdata account so we don't hardcode the pubkey."
8846
- ],
9077
+ name: "collateral_vault",
9078
+ writable: true,
9079
+ pda: {
9080
+ seeds: [
9081
+ {
9082
+ kind: "const",
9083
+ value: [
9084
+ 99,
9085
+ 111,
9086
+ 108,
9087
+ 108,
9088
+ 97,
9089
+ 116,
9090
+ 101,
9091
+ 114,
9092
+ 97,
9093
+ 108,
9094
+ 95,
9095
+ 118,
9096
+ 97,
9097
+ 117,
9098
+ 108,
9099
+ 116
9100
+ ]
9101
+ },
9102
+ {
9103
+ kind: "account",
9104
+ path: "condition.collateral_mint",
9105
+ account: "Condition"
9106
+ }
9107
+ ],
9108
+ program: {
9109
+ kind: "account",
9110
+ path: "conditional_tokens_program"
9111
+ }
9112
+ }
9113
+ },
9114
+ {
9115
+ name: "vault_token_account",
9116
+ writable: true
9117
+ },
9118
+ {
9119
+ name: "fee_recipient",
9120
+ docs: [
9121
+ "CLOB's USDS ATA \u2014 receives USDS payout from redeem, then distribute_fee draws from it."
9122
+ ],
9123
+ writable: true
9124
+ },
9125
+ {
9126
+ name: "yes_mint",
9127
+ writable: true
9128
+ },
9129
+ {
9130
+ name: "no_mint",
9131
+ writable: true
9132
+ },
9133
+ {
9134
+ name: "clob_yes_ata",
9135
+ docs: [
9136
+ "CLOB's YES ATA (Token-2022) \u2014 must be pre-initialized (created during prior matchOrders)."
9137
+ ],
9138
+ writable: true
9139
+ },
9140
+ {
9141
+ name: "clob_no_ata",
9142
+ docs: [
9143
+ "CLOB's NO ATA (Token-2022) \u2014 must be pre-initialized."
9144
+ ],
9145
+ writable: true
9146
+ },
9147
+ {
9148
+ name: "clob_yes_position",
9149
+ writable: true
9150
+ },
9151
+ {
9152
+ name: "clob_no_position",
9153
+ writable: true
9154
+ },
9155
+ {
9156
+ name: "ix_sysvar"
9157
+ },
9158
+ {
9159
+ name: "conditional_tokens_program",
9160
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
9161
+ },
9162
+ {
9163
+ name: "token_program",
9164
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
9165
+ },
9166
+ {
9167
+ name: "token_2022_program",
9168
+ address: "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb"
9169
+ },
9170
+ {
9171
+ name: "system_program",
9172
+ address: "11111111111111111111111111111111"
9173
+ }
9174
+ ],
9175
+ args: [
9176
+ {
9177
+ name: "ix_index",
9178
+ type: "u8"
9179
+ },
9180
+ {
9181
+ name: "order_count",
9182
+ type: "u8"
9183
+ },
9184
+ {
9185
+ name: "outcome_index",
9186
+ type: "u8"
9187
+ }
9188
+ ]
9189
+ },
9190
+ {
9191
+ name: "cancel_order",
9192
+ docs: [
9193
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
9194
+ ],
9195
+ discriminator: [
9196
+ 95,
9197
+ 129,
9198
+ 237,
9199
+ 240,
9200
+ 8,
9201
+ 49,
9202
+ 223,
9203
+ 132
9204
+ ],
9205
+ accounts: [
9206
+ {
9207
+ name: "maker",
9208
+ docs: [
9209
+ "Must be the order maker/signer"
9210
+ ],
9211
+ signer: true
9212
+ },
9213
+ {
9214
+ name: "order_record",
9215
+ writable: true,
9216
+ pda: {
9217
+ seeds: [
9218
+ {
9219
+ kind: "const",
9220
+ value: [
9221
+ 111,
9222
+ 114,
9223
+ 100,
9224
+ 101,
9225
+ 114,
9226
+ 95,
9227
+ 114,
9228
+ 101,
9229
+ 99,
9230
+ 111,
9231
+ 114,
9232
+ 100
9233
+ ]
9234
+ },
9235
+ {
9236
+ kind: "account",
9237
+ path: "maker"
9238
+ },
9239
+ {
9240
+ kind: "arg",
9241
+ path: "nonce"
9242
+ }
9243
+ ]
9244
+ }
9245
+ },
9246
+ {
9247
+ name: "system_program",
9248
+ address: "11111111111111111111111111111111"
9249
+ }
9250
+ ],
9251
+ args: [
9252
+ {
9253
+ name: "nonce",
9254
+ type: "u64"
9255
+ }
9256
+ ]
9257
+ },
9258
+ {
9259
+ name: "force_reset_clob",
9260
+ discriminator: [
9261
+ 96,
9262
+ 95,
9263
+ 187,
9264
+ 95,
9265
+ 65,
9266
+ 135,
9267
+ 120,
9268
+ 204
9269
+ ],
9270
+ accounts: [
9271
+ {
9272
+ name: "upgrade_authority",
9273
+ docs: [
9274
+ "Must be the upgrade authority (deployer). Checked in handler via",
9275
+ "programdata account so we don't hardcode the pubkey."
9276
+ ],
8847
9277
  writable: true,
8848
9278
  signer: true
8849
9279
  },
@@ -8970,7 +9400,7 @@ var clob_exchange_default = {
8970
9400
  {
8971
9401
  name: "match_complementary",
8972
9402
  docs: [
8973
- "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
9403
+ "COMPLEMENTARY match: 1 taker (BUY or SELL) + N makers (opposite side) via remaining_accounts."
8974
9404
  ],
8975
9405
  discriminator: [
8976
9406
  100,
@@ -9263,9 +9693,6 @@ var clob_exchange_default = {
9263
9693
  },
9264
9694
  {
9265
9695
  name: "clob_usdc_ata",
9266
- docs: [
9267
- "USDC ATA owned by clob_config \u2014 receives USDC from vault after merge"
9268
- ],
9269
9696
  writable: true,
9270
9697
  pda: {
9271
9698
  seeds: [
@@ -9542,9 +9969,6 @@ var clob_exchange_default = {
9542
9969
  },
9543
9970
  {
9544
9971
  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
9972
  writable: true,
9549
9973
  pda: {
9550
9974
  seeds: [
@@ -9602,30 +10026,18 @@ var clob_exchange_default = {
9602
10026
  },
9603
10027
  {
9604
10028
  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
10029
  writable: true
9609
10030
  },
9610
10031
  {
9611
10032
  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
10033
  writable: true
9616
10034
  },
9617
10035
  {
9618
10036
  name: "clob_yes_position",
9619
- docs: [
9620
- "YES Position PDA for clob_config (set by CTF split_position init_if_needed)"
9621
- ],
9622
10037
  writable: true
9623
10038
  },
9624
10039
  {
9625
10040
  name: "clob_no_position",
9626
- docs: [
9627
- "NO Position PDA for clob_config (set by CTF split_position init_if_needed)"
9628
- ],
9629
10041
  writable: true
9630
10042
  },
9631
10043
  {
@@ -10661,11 +11073,18 @@ var fee_management_default = {
10661
11073
  {
10662
11074
  name: "market_oracle_vault",
10663
11075
  docs: [
10664
- "Writable: tokens are transferred here when is_admin=false.",
11076
+ "Writable: tokens are transferred here (investors share) when is_admin=false.",
10665
11077
  "For admin questions pass any writable account (no transfer occurs)."
10666
11078
  ],
10667
11079
  writable: true
10668
11080
  },
11081
+ {
11082
+ name: "referral_vault",
11083
+ docs: [
11084
+ "Must match fee_config.referral_vault."
11085
+ ],
11086
+ writable: true
11087
+ },
10669
11088
  {
10670
11089
  name: "token_program",
10671
11090
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -11524,7 +11943,8 @@ var fee_management_default = {
11524
11943
  {
11525
11944
  name: "investors_market_rev",
11526
11945
  docs: [
11527
- "Market revenue split: investors + company (out of FEE_DENOMINATOR = 1_000_000)"
11946
+ "Market revenue split \u2014 three parts must sum to FEE_DENOMINATOR (10_000).",
11947
+ "investors_market_rev + company_market_rev + referral_market_rev == 10_000"
11528
11948
  ],
11529
11949
  type: "u32"
11530
11950
  },
@@ -11535,7 +11955,7 @@ var fee_management_default = {
11535
11955
  {
11536
11956
  name: "agents_presale_rev",
11537
11957
  docs: [
11538
- "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 1_000_000)"
11958
+ "Presale revenue split: agents + company (out of FEE_DENOMINATOR = 10_000)"
11539
11959
  ],
11540
11960
  type: "u32"
11541
11961
  },
@@ -11560,12 +11980,26 @@ var fee_management_default = {
11560
11980
  name: "bump",
11561
11981
  type: "u8"
11562
11982
  },
11983
+ {
11984
+ name: "referral_market_rev",
11985
+ docs: [
11986
+ "Share of market trading fees routed to referral_vault (e.g. 2_000 = 20%)"
11987
+ ],
11988
+ type: "u32"
11989
+ },
11990
+ {
11991
+ name: "referral_vault",
11992
+ docs: [
11993
+ "ATA of referral program config PDA \u2014 receives referral_market_rev% of trading fees"
11994
+ ],
11995
+ type: "pubkey"
11996
+ },
11563
11997
  {
11564
11998
  name: "_reserved",
11565
11999
  type: {
11566
12000
  array: [
11567
12001
  "u8",
11568
- 64
12002
+ 28
11569
12003
  ]
11570
12004
  }
11571
12005
  }
@@ -11692,6 +12126,14 @@ var fee_management_default = {
11692
12126
  {
11693
12127
  name: "company_presale_rev",
11694
12128
  type: "u32"
12129
+ },
12130
+ {
12131
+ name: "referral_market_rev",
12132
+ type: "u32"
12133
+ },
12134
+ {
12135
+ name: "referral_vault",
12136
+ type: "pubkey"
11695
12137
  }
11696
12138
  ]
11697
12139
  }
@@ -11952,6 +12394,14 @@ var fee_management_default = {
11952
12394
  {
11953
12395
  name: "company_presale_rev",
11954
12396
  type: "u32"
12397
+ },
12398
+ {
12399
+ name: "referral_market_rev",
12400
+ type: "u32"
12401
+ },
12402
+ {
12403
+ name: "referral_vault",
12404
+ type: "pubkey"
11955
12405
  }
11956
12406
  ]
11957
12407
  }
@@ -15300,27 +15750,517 @@ var admin_contract_default = {
15300
15750
  ]
15301
15751
  };
15302
15752
 
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
- }
15317
- _withAddress(idl, address) {
15318
- return { ...idl, address: address.toBase58() };
15319
- }
15320
- get oracle() {
15321
- if (!this._oracle) {
15322
- const program = new anchor5.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
15323
- this._oracle = new OracleClient(program, this.provider, this._programIds);
15753
+ // src/idls/referral.json
15754
+ var referral_default = {
15755
+ address: "7b5ohWDqrQ2KRcDJMWwj1dwgRkt5ZJdMavSmrXn9oBgL",
15756
+ metadata: {
15757
+ name: "referral",
15758
+ version: "0.1.0",
15759
+ spec: "0.1.0",
15760
+ description: "Referral program for XMarket \u2014 whitelist-gated batch USDS distribution"
15761
+ },
15762
+ instructions: [
15763
+ {
15764
+ name: "add_to_whitelist",
15765
+ discriminator: [
15766
+ 157,
15767
+ 211,
15768
+ 52,
15769
+ 54,
15770
+ 144,
15771
+ 81,
15772
+ 5,
15773
+ 55
15774
+ ],
15775
+ accounts: [
15776
+ {
15777
+ name: "owner",
15778
+ signer: true
15779
+ },
15780
+ {
15781
+ name: "payer",
15782
+ writable: true,
15783
+ signer: true
15784
+ },
15785
+ {
15786
+ name: "config",
15787
+ writable: true,
15788
+ pda: {
15789
+ seeds: [
15790
+ {
15791
+ kind: "const",
15792
+ value: [
15793
+ 114,
15794
+ 101,
15795
+ 102,
15796
+ 101,
15797
+ 114,
15798
+ 114,
15799
+ 97,
15800
+ 108,
15801
+ 95,
15802
+ 99,
15803
+ 111,
15804
+ 110,
15805
+ 102,
15806
+ 105,
15807
+ 103
15808
+ ]
15809
+ },
15810
+ {
15811
+ kind: "account",
15812
+ path: "config.owner",
15813
+ account: "ReferralConfig"
15814
+ }
15815
+ ]
15816
+ }
15817
+ }
15818
+ ],
15819
+ args: [
15820
+ {
15821
+ name: "address",
15822
+ type: "pubkey"
15823
+ }
15824
+ ]
15825
+ },
15826
+ {
15827
+ name: "batch_send_usds",
15828
+ discriminator: [
15829
+ 255,
15830
+ 33,
15831
+ 77,
15832
+ 124,
15833
+ 42,
15834
+ 207,
15835
+ 250,
15836
+ 162
15837
+ ],
15838
+ accounts: [
15839
+ {
15840
+ name: "authority",
15841
+ docs: [
15842
+ "Whitelisted caller (authority, signs tx)"
15843
+ ],
15844
+ signer: true
15845
+ },
15846
+ {
15847
+ name: "config",
15848
+ pda: {
15849
+ seeds: [
15850
+ {
15851
+ kind: "const",
15852
+ value: [
15853
+ 114,
15854
+ 101,
15855
+ 102,
15856
+ 101,
15857
+ 114,
15858
+ 114,
15859
+ 97,
15860
+ 108,
15861
+ 95,
15862
+ 99,
15863
+ 111,
15864
+ 110,
15865
+ 102,
15866
+ 105,
15867
+ 103
15868
+ ]
15869
+ },
15870
+ {
15871
+ kind: "account",
15872
+ path: "config.owner",
15873
+ account: "ReferralConfig"
15874
+ }
15875
+ ]
15876
+ }
15877
+ },
15878
+ {
15879
+ name: "referral_vault",
15880
+ docs: [
15881
+ "Referral vault \u2014 source of transfers (ATA owned by config PDA)"
15882
+ ],
15883
+ writable: true,
15884
+ pda: {
15885
+ seeds: [
15886
+ {
15887
+ kind: "account",
15888
+ path: "config"
15889
+ },
15890
+ {
15891
+ kind: "const",
15892
+ value: [
15893
+ 6,
15894
+ 221,
15895
+ 246,
15896
+ 225,
15897
+ 215,
15898
+ 101,
15899
+ 161,
15900
+ 147,
15901
+ 217,
15902
+ 203,
15903
+ 225,
15904
+ 70,
15905
+ 206,
15906
+ 235,
15907
+ 121,
15908
+ 172,
15909
+ 28,
15910
+ 180,
15911
+ 133,
15912
+ 237,
15913
+ 95,
15914
+ 91,
15915
+ 55,
15916
+ 145,
15917
+ 58,
15918
+ 140,
15919
+ 245,
15920
+ 133,
15921
+ 126,
15922
+ 255,
15923
+ 0,
15924
+ 169
15925
+ ]
15926
+ },
15927
+ {
15928
+ kind: "account",
15929
+ path: "config.collateral_mint",
15930
+ account: "ReferralConfig"
15931
+ }
15932
+ ],
15933
+ program: {
15934
+ kind: "const",
15935
+ value: [
15936
+ 140,
15937
+ 151,
15938
+ 37,
15939
+ 143,
15940
+ 78,
15941
+ 36,
15942
+ 137,
15943
+ 241,
15944
+ 187,
15945
+ 61,
15946
+ 16,
15947
+ 41,
15948
+ 20,
15949
+ 142,
15950
+ 13,
15951
+ 131,
15952
+ 11,
15953
+ 90,
15954
+ 19,
15955
+ 153,
15956
+ 218,
15957
+ 255,
15958
+ 16,
15959
+ 132,
15960
+ 4,
15961
+ 142,
15962
+ 123,
15963
+ 216,
15964
+ 219,
15965
+ 233,
15966
+ 248,
15967
+ 89
15968
+ ]
15969
+ }
15970
+ }
15971
+ },
15972
+ {
15973
+ name: "token_program",
15974
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
15975
+ }
15976
+ ],
15977
+ args: [
15978
+ {
15979
+ name: "amounts",
15980
+ type: {
15981
+ vec: "u64"
15982
+ }
15983
+ }
15984
+ ]
15985
+ },
15986
+ {
15987
+ name: "initialize",
15988
+ discriminator: [
15989
+ 175,
15990
+ 175,
15991
+ 109,
15992
+ 31,
15993
+ 13,
15994
+ 152,
15995
+ 155,
15996
+ 237
15997
+ ],
15998
+ accounts: [
15999
+ {
16000
+ name: "owner",
16001
+ writable: true,
16002
+ signer: true
16003
+ },
16004
+ {
16005
+ name: "payer",
16006
+ writable: true,
16007
+ signer: true
16008
+ },
16009
+ {
16010
+ name: "config",
16011
+ writable: true,
16012
+ pda: {
16013
+ seeds: [
16014
+ {
16015
+ kind: "const",
16016
+ value: [
16017
+ 114,
16018
+ 101,
16019
+ 102,
16020
+ 101,
16021
+ 114,
16022
+ 114,
16023
+ 97,
16024
+ 108,
16025
+ 95,
16026
+ 99,
16027
+ 111,
16028
+ 110,
16029
+ 102,
16030
+ 105,
16031
+ 103
16032
+ ]
16033
+ },
16034
+ {
16035
+ kind: "account",
16036
+ path: "owner"
16037
+ }
16038
+ ]
16039
+ }
16040
+ },
16041
+ {
16042
+ name: "collateral_mint"
16043
+ },
16044
+ {
16045
+ name: "system_program",
16046
+ address: "11111111111111111111111111111111"
16047
+ }
16048
+ ],
16049
+ args: []
16050
+ },
16051
+ {
16052
+ name: "remove_from_whitelist",
16053
+ discriminator: [
16054
+ 7,
16055
+ 144,
16056
+ 216,
16057
+ 239,
16058
+ 243,
16059
+ 236,
16060
+ 193,
16061
+ 235
16062
+ ],
16063
+ accounts: [
16064
+ {
16065
+ name: "owner",
16066
+ signer: true
16067
+ },
16068
+ {
16069
+ name: "payer",
16070
+ writable: true,
16071
+ signer: true
16072
+ },
16073
+ {
16074
+ name: "config",
16075
+ writable: true,
16076
+ pda: {
16077
+ seeds: [
16078
+ {
16079
+ kind: "const",
16080
+ value: [
16081
+ 114,
16082
+ 101,
16083
+ 102,
16084
+ 101,
16085
+ 114,
16086
+ 114,
16087
+ 97,
16088
+ 108,
16089
+ 95,
16090
+ 99,
16091
+ 111,
16092
+ 110,
16093
+ 102,
16094
+ 105,
16095
+ 103
16096
+ ]
16097
+ },
16098
+ {
16099
+ kind: "account",
16100
+ path: "config.owner",
16101
+ account: "ReferralConfig"
16102
+ }
16103
+ ]
16104
+ }
16105
+ }
16106
+ ],
16107
+ args: [
16108
+ {
16109
+ name: "address",
16110
+ type: "pubkey"
16111
+ }
16112
+ ]
16113
+ }
16114
+ ],
16115
+ accounts: [
16116
+ {
16117
+ name: "ReferralConfig",
16118
+ discriminator: [
16119
+ 102,
16120
+ 148,
16121
+ 171,
16122
+ 235,
16123
+ 148,
16124
+ 83,
16125
+ 250,
16126
+ 140
16127
+ ]
16128
+ }
16129
+ ],
16130
+ events: [
16131
+ {
16132
+ name: "BatchSent",
16133
+ discriminator: [
16134
+ 116,
16135
+ 64,
16136
+ 207,
16137
+ 63,
16138
+ 56,
16139
+ 97,
16140
+ 15,
16141
+ 100
16142
+ ]
16143
+ },
16144
+ {
16145
+ name: "ReferralInitialized",
16146
+ discriminator: [
16147
+ 129,
16148
+ 190,
16149
+ 249,
16150
+ 4,
16151
+ 198,
16152
+ 5,
16153
+ 141,
16154
+ 226
16155
+ ]
16156
+ }
16157
+ ],
16158
+ types: [
16159
+ {
16160
+ name: "BatchSent",
16161
+ type: {
16162
+ kind: "struct",
16163
+ fields: [
16164
+ {
16165
+ name: "config",
16166
+ type: "pubkey"
16167
+ },
16168
+ {
16169
+ name: "sent_by",
16170
+ type: "pubkey"
16171
+ },
16172
+ {
16173
+ name: "recipients",
16174
+ type: "u8"
16175
+ }
16176
+ ]
16177
+ }
16178
+ },
16179
+ {
16180
+ name: "ReferralConfig",
16181
+ type: {
16182
+ kind: "struct",
16183
+ fields: [
16184
+ {
16185
+ name: "version",
16186
+ type: "u8"
16187
+ },
16188
+ {
16189
+ name: "owner",
16190
+ type: "pubkey"
16191
+ },
16192
+ {
16193
+ name: "collateral_mint",
16194
+ type: "pubkey"
16195
+ },
16196
+ {
16197
+ name: "whitelist",
16198
+ type: {
16199
+ array: [
16200
+ "pubkey",
16201
+ 10
16202
+ ]
16203
+ }
16204
+ },
16205
+ {
16206
+ name: "whitelist_len",
16207
+ type: "u8"
16208
+ },
16209
+ {
16210
+ name: "bump",
16211
+ type: "u8"
16212
+ },
16213
+ {
16214
+ name: "_reserved",
16215
+ type: {
16216
+ array: [
16217
+ "u8",
16218
+ 64
16219
+ ]
16220
+ }
16221
+ }
16222
+ ]
16223
+ }
16224
+ },
16225
+ {
16226
+ name: "ReferralInitialized",
16227
+ type: {
16228
+ kind: "struct",
16229
+ fields: [
16230
+ {
16231
+ name: "config",
16232
+ type: "pubkey"
16233
+ },
16234
+ {
16235
+ name: "owner",
16236
+ type: "pubkey"
16237
+ }
16238
+ ]
16239
+ }
16240
+ }
16241
+ ]
16242
+ };
16243
+
16244
+ // src/sdk.ts
16245
+ var XMarketSDK = class {
16246
+ constructor(config, wallet, marketOwner) {
16247
+ this.networkConfig = config;
16248
+ this.provider = new anchor5.AnchorProvider(
16249
+ new Connection(config.rpcUrl, "confirmed"),
16250
+ wallet,
16251
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
16252
+ );
16253
+ anchor5.setProvider(this.provider);
16254
+ this._programIds = config.programIds;
16255
+ this._marketOwner = marketOwner ?? wallet.publicKey;
16256
+ }
16257
+ _withAddress(idl, address) {
16258
+ return { ...idl, address: address.toBase58() };
16259
+ }
16260
+ get oracle() {
16261
+ if (!this._oracle) {
16262
+ const program = new anchor5.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
16263
+ this._oracle = new OracleClient(program, this.provider, this._programIds);
15324
16264
  }
15325
16265
  return this._oracle;
15326
16266
  }
@@ -15389,6 +16329,14 @@ var XMarketSDK = class {
15389
16329
  }
15390
16330
  return this._admin;
15391
16331
  }
16332
+ get referral() {
16333
+ if (!this._referral) {
16334
+ if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
16335
+ const program = new anchor5.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
16336
+ this._referral = new ReferralClient(program, this.provider, this._programIds);
16337
+ }
16338
+ return this._referral;
16339
+ }
15392
16340
  };
15393
16341
  var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
15394
16342
  function buildCreateUserAtasTx(condition, user, payer, programIds) {
@@ -15461,6 +16409,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
15461
16409
  return tx;
15462
16410
  }
15463
16411
 
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 };
16412
+ 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
16413
  //# sourceMappingURL=index.mjs.map
15466
16414
  //# sourceMappingURL=index.mjs.map