@theliem/xmarket-sdk 3.12.0 → 3.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -13,6 +13,7 @@ interface ProgramIds {
13
13
  presale?: PublicKey;
14
14
  marketOracle?: PublicKey;
15
15
  adminContract?: PublicKey;
16
+ referral?: PublicKey;
16
17
  }
17
18
  interface CollateralConfig {
18
19
  mint: PublicKey;
@@ -162,7 +163,7 @@ interface OrderStatus {
162
163
  filledAmount: BN;
163
164
  bump: number;
164
165
  }
165
- /** Per-question fee rates, all out of FEE_DENOMINATOR (1_000_000). E.g. 2_000 = 0.2% */
166
+ /** Per-question fee rates, all out of FEE_DENOMINATOR (10_000). E.g. 200 = 2%, 2_000 = 20% */
166
167
  interface QuestionFee {
167
168
  conditionId: Uint8Array;
168
169
  mergeFee: BN;
@@ -170,7 +171,7 @@ interface QuestionFee {
170
171
  swapFee: BN;
171
172
  bump: number;
172
173
  }
173
- declare const FEE_DENOMINATOR = 1000000;
174
+ declare const FEE_DENOMINATOR = 10000;
174
175
  /**
175
176
  * Off-chain order struct passed as instruction data.
176
177
  * Operator validates + submits matched order pairs on-chain.
@@ -214,6 +215,21 @@ interface SignedOrder {
214
215
  /** Ed25519 signature (64 bytes) from order.maker over serializeOrderToBytes() */
215
216
  signature: Uint8Array;
216
217
  }
218
+ /** Authorization for CLOB to collect fee_amount winning tokens after question resolution. */
219
+ interface CollectFeeOrder {
220
+ user: PublicKey;
221
+ condition: PublicKey;
222
+ tokenMint: PublicKey;
223
+ amount: BN;
224
+ nonce: BN;
225
+ /** Unix timestamp, 0 = no expiry */
226
+ expiry: BN;
227
+ }
228
+ interface SignedCollectFeeOrder {
229
+ order: CollectFeeOrder;
230
+ /** Ed25519 signature (64 bytes) from order.user over serializeCollectFeeOrderToBytes() */
231
+ signature: Uint8Array;
232
+ }
217
233
  declare class XMarketError extends Error {
218
234
  code?: string | undefined;
219
235
  constructor(message: string, code?: string | undefined);
@@ -476,8 +492,24 @@ declare class MarketClient {
476
492
  * @param creator presale creator pubkey (stored in question)
477
493
  * @param currencyMint collateral mint
478
494
  */
479
- approvePresale(presalePda: PublicKey, contentHash: Uint8Array, hookProgram: PublicKey, authorizedClob: PublicKey, expirationTime: anchor.BN, creator: PublicKey, currencyMint: PublicKey, caller?: PublicKey, payer?: PublicKey): Promise<{
480
- tx: Transaction;
495
+ approvePresale(params: {
496
+ presalePda: PublicKey;
497
+ contentHash: Uint8Array;
498
+ hookProgram: PublicKey;
499
+ authorizedClob: PublicKey;
500
+ expirationTime: anchor.BN;
501
+ creator: PublicKey;
502
+ currencyMint: PublicKey;
503
+ /** Revenue distribution — required: approvePresale now distributes 80/10/10 automatically */
504
+ referralAddress: PublicKey;
505
+ companyAddress: PublicKey;
506
+ adminOwner: PublicKey;
507
+ caller?: PublicKey;
508
+ payer?: PublicKey;
509
+ /** Provide an ALT to use VersionedTransaction (required: 31 accounts exceeds legacy tx limit) */
510
+ lookupTable?: AddressLookupTableAccount;
511
+ }): Promise<{
512
+ tx: Transaction | VersionedTransaction;
481
513
  questionPda: PublicKey;
482
514
  conditionPda: PublicKey;
483
515
  marketOraclePda: PublicKey;
@@ -513,27 +545,66 @@ declare class FeeManagementClient {
513
545
  private readonly provider;
514
546
  private readonly programIds;
515
547
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
516
- initFeeConfig(admin: PublicKey, companyAddress: PublicKey, referralAddress: PublicKey, presaleRevenueAddress: PublicKey, investorsMarketRev: number, companyMarketRev: number, agentsPresaleRev: number, companyPresaleRev: number, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
548
+ initFeeConfig(params: {
549
+ admin: PublicKey;
550
+ companyAddress: PublicKey;
551
+ referralAddress: PublicKey;
552
+ presaleRevenueAddress: PublicKey;
553
+ investorsMarketRev: number;
554
+ companyMarketRev: number;
555
+ agentsPresaleRev: number;
556
+ companyPresaleRev: number;
557
+ /** Share routed to referral vault (e.g. 2_000 = 20%). Must satisfy referral+company+investors=10_000 */
558
+ referralMarketRev: number;
559
+ referralVault: PublicKey;
560
+ authority: PublicKey;
561
+ payer: PublicKey;
562
+ }): Promise<TxResult>;
517
563
  fetchFeeConfig(owner: PublicKey): Promise<any | null>;
518
564
  /**
519
- * Fetch per-question fees for a condition.
520
- * Returns null if no fees have been set yet.
565
+ * Fetch per-market fees for a condition.
566
+ * Returns null if fees have not been initialized yet.
567
+ * Fees are set automatically via CPI when create_question_admin / approve_presale runs.
568
+ * Defaults: swapFee=200 (2%), redeemFee=0, mergeFee=2000 (20%), out of FEE_DENOMINATOR=10_000.
521
569
  */
570
+ getMarketFee(conditionPda: PublicKey): Promise<QuestionFee | null>;
522
571
  fetchQuestionFee(conditionPda: PublicKey): Promise<QuestionFee | null>;
523
572
  /**
524
- * Set per-question fees for a condition.
573
+ * Set per-question fees for a condition (whitelist-only edit after market creation).
525
574
  * @param conditionPda - condition PDA from the question
526
- * @param mergeFee - fee out of FEE_DENOMINATOR (1_000_000), e.g. 2_000 = 0.2%
575
+ * @param mergeFee - fee out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
527
576
  * @param redeemFee - fee out of FEE_DENOMINATOR
528
- * @param swapFee - trading fee out of FEE_DENOMINATOR
577
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
529
578
  * @param feeConfigOwner - pubkey that owns the fee_config PDA (usually market deployer)
530
579
  * @param authority - signer authorized in fee_config whitelist / admin / owner
531
580
  * @param payer - rent + tx fee payer
532
581
  */
533
- updateFeeConfig(companyAddress: PublicKey, referralAddress: PublicKey, presaleRevenueAddress: PublicKey, investorsMarketRev: number, companyMarketRev: number, agentsPresaleRev: number, companyPresaleRev: number, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
582
+ updateFeeConfig(params: {
583
+ companyAddress: PublicKey;
584
+ referralAddress: PublicKey;
585
+ presaleRevenueAddress: PublicKey;
586
+ investorsMarketRev: number;
587
+ companyMarketRev: number;
588
+ agentsPresaleRev: number;
589
+ companyPresaleRev: number;
590
+ referralMarketRev: number;
591
+ referralVault: PublicKey;
592
+ authority: PublicKey;
593
+ payer: PublicKey;
594
+ }): Promise<TxResult>;
534
595
  setMarketFeeOverride(conditionPda: PublicKey, investors: number, company: number, isAdmin: boolean, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
535
- buildDistributeFeeIx(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TransactionInstruction>;
536
- distributeFee(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TxResult>;
596
+ /**
597
+ * Build editMarketFee transaction (whitelist-only).
598
+ * @param conditionPda - condition PDA (market identifier)
599
+ * @param mergeFee - out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
600
+ * @param redeemFee - out of FEE_DENOMINATOR
601
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
602
+ * @param feeConfigOwner - owner of fee_config PDA
603
+ * @param authority - whitelisted signer (signs tx externally)
604
+ * @param payer - fee payer (can differ from authority)
605
+ */
606
+ buildEditMarketFeeTx(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer?: PublicKey): Promise<Transaction>;
607
+ /** @deprecated use buildEditMarketFeeTx */
537
608
  setQuestionFee(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
538
609
  }
539
610
 
@@ -547,6 +618,8 @@ declare class ClobClient {
547
618
  feeConfigOwner?: PublicKey;
548
619
  /** Cached company_address from fee_config to avoid repeated RPC calls */
549
620
  private _companyAddress?;
621
+ /** Cached referral_vault from fee_config */
622
+ private _referralVault?;
550
623
  /** ALT cache: condition.toBase58() → loaded ALT account */
551
624
  private _altCache;
552
625
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -555,6 +628,7 @@ declare class ClobClient {
555
628
  };
556
629
  });
557
630
  private companyAddress;
631
+ private referralVault;
558
632
  get walletPubkey(): PublicKey;
559
633
  /**
560
634
  * Get or create an ALT for a condition.
@@ -717,6 +791,23 @@ declare class ClobClient {
717
791
  buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
718
792
  marketOracleVault?: PublicKey;
719
793
  }): Promise<VersionedTransaction>;
794
+ /**
795
+ * Build VersionedTransaction for batchCollectRedeemEarly.
796
+ *
797
+ * Flow: Ed25519 ix (user sigs) + batchCollectRedeemEarly ix.
798
+ * Each SignedCollectFeeOrder authorizes CLOB to collect `amount` winning tokens
799
+ * from that user, redeem via CTF, then distribute as fees.
800
+ *
801
+ * @param signedOrders - Array of { order, signature } from winning users
802
+ * @param condition - Market condition PDA
803
+ * @param outcomeIndex - 0 = NO wins, 1 = YES wins
804
+ * @param operator - Whitelisted operator pubkey (must sign)
805
+ * @param payer - Fee payer pubkey (must sign)
806
+ * @param opts.marketOracleVault - MarketOracle vault for fee distribution
807
+ */
808
+ buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
809
+ marketOracleVault?: PublicKey;
810
+ }): Promise<VersionedTransaction>;
720
811
  fetchConfig(): Promise<ClobConfig | null>;
721
812
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
722
813
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -865,6 +956,46 @@ declare class AdminClient {
865
956
  distributeMarket(conditionId: Uint8Array, amount: anchor.BN, collateralMint: PublicKey, marketOracleVault: PublicKey, owner: PublicKey, claimer?: PublicKey, payer?: PublicKey): Promise<Transaction>;
866
957
  }
867
958
 
959
+ interface ReferralConfigInfo {
960
+ owner: PublicKey;
961
+ collateralMint: PublicKey;
962
+ whitelist: PublicKey[];
963
+ bump: number;
964
+ }
965
+ declare class ReferralClient {
966
+ private readonly program;
967
+ private readonly provider;
968
+ private readonly programIds;
969
+ constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
970
+ get walletPubkey(): PublicKey;
971
+ referralVault(owner: PublicKey, collateralMint: PublicKey): PublicKey;
972
+ fetchConfig(owner: PublicKey): Promise<ReferralConfigInfo | null>;
973
+ /**
974
+ * Build initialize tx — creates referral config PDA.
975
+ * Also prepends an ATA creation instruction for the referral vault (idempotent).
976
+ * Build-tx pattern.
977
+ */
978
+ buildInitializeTx(collateralMint: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<{
979
+ tx: Transaction;
980
+ configPda: PublicKey;
981
+ vaultAta: PublicKey;
982
+ }>;
983
+ /** Build add-to-whitelist tx. Build-tx pattern. */
984
+ buildAddToWhitelistTx(address: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
985
+ /** Build remove-from-whitelist tx. Build-tx pattern. */
986
+ buildRemoveFromWhitelistTx(address: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
987
+ /**
988
+ * Build batchSendUsds tx. Build-tx pattern.
989
+ * @param recipients - wallet addresses to send to
990
+ * @param amounts - corresponding amounts in token smallest units
991
+ * @param configOwner - owner of referral config (used to derive config + vault)
992
+ * @param collateralMint - token mint
993
+ * @param authority - whitelisted signer
994
+ * @param payer - fee payer (can differ from authority)
995
+ */
996
+ buildBatchSendUsdsTx(recipients: PublicKey[], amounts: BN[], configOwner: PublicKey, collateralMint: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
997
+ }
998
+
868
999
  declare class XMarketSDK {
869
1000
  readonly provider: anchor.AnchorProvider;
870
1001
  readonly networkConfig: NetworkConfig;
@@ -879,6 +1010,7 @@ declare class XMarketSDK {
879
1010
  private _presale?;
880
1011
  private _marketOracle?;
881
1012
  private _admin?;
1013
+ private _referral?;
882
1014
  constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
883
1015
  private _withAddress;
884
1016
  get oracle(): OracleClient;
@@ -890,6 +1022,7 @@ declare class XMarketSDK {
890
1022
  get presale(): PresaleClient;
891
1023
  get marketOracle(): MarketOracleClient;
892
1024
  get admin(): AdminClient;
1025
+ get referral(): ReferralClient;
893
1026
  }
894
1027
 
895
1028
  declare const SEEDS: {
@@ -910,6 +1043,7 @@ declare const SEEDS: {
910
1043
  readonly clobConfig: Buffer<ArrayBuffer>;
911
1044
  readonly order: Buffer<ArrayBuffer>;
912
1045
  readonly feeConfig: Buffer<ArrayBuffer>;
1046
+ readonly referralConfig: Buffer<ArrayBuffer>;
913
1047
  readonly questionFee: Buffer<ArrayBuffer>;
914
1048
  readonly marketFee: Buffer<ArrayBuffer>;
915
1049
  readonly presale: Buffer<ArrayBuffer>;
@@ -949,6 +1083,7 @@ declare class PDA {
949
1083
  static userBuyRecord(presalePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
950
1084
  static marketOraclePda(questionPda: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
951
1085
  static userClaimRecord(marketOraclePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
1086
+ static referralConfig(owner: PublicKey, programIds: Pick<ProgramIds, "referral">): [PublicKey, number];
952
1087
  static adminConfig(owner: PublicKey, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
953
1088
  static claimRecord(conditionId: Uint8Array, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
954
1089
  }
@@ -989,6 +1124,25 @@ declare function buildBatchedEd25519Instruction(orders: SignedOrder[]): Transact
989
1124
  * Pass this as `ixSysvar` to all match_* instruction accounts.
990
1125
  */
991
1126
  declare const IX_SYSVAR: _solana_web3_js.PublicKey;
1127
+ /**
1128
+ * Convert SignedOrder to the shape anchor expects for SignedOrder struct.
1129
+ * The signature must be passed as a fixed-size array of 64 numbers.
1130
+ */
1131
+ /**
1132
+ * Serialize a CollectFeeOrder to 120 bytes — must match Rust `CollectFeeOrder::to_signable_bytes()`.
1133
+ * [0..32] user pubkey
1134
+ * [32..64] condition pubkey
1135
+ * [64..96] token_mint pubkey
1136
+ * [96..104] amount (u64 le)
1137
+ * [104..112] nonce (u64 le)
1138
+ * [112..120] expiry (i64 le)
1139
+ */
1140
+ declare function serializeCollectFeeOrderToBytes(order: CollectFeeOrder): Uint8Array;
1141
+ /**
1142
+ * Build a batched Ed25519 precompile instruction for N signed CollectFeeOrders.
1143
+ * Same layout as buildBatchedEd25519Instruction but with 120-byte messages.
1144
+ */
1145
+ declare function buildBatchedCollectFeeEd25519Instruction(orders: SignedCollectFeeOrder[]): TransactionInstruction;
992
1146
 
993
1147
  /**
994
1148
  * High-level order utilities — build, sign, serialize, verify, detect match type.
@@ -1141,4 +1295,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1141
1295
  */
1142
1296
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1143
1297
 
1144
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1298
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.d.ts CHANGED
@@ -13,6 +13,7 @@ interface ProgramIds {
13
13
  presale?: PublicKey;
14
14
  marketOracle?: PublicKey;
15
15
  adminContract?: PublicKey;
16
+ referral?: PublicKey;
16
17
  }
17
18
  interface CollateralConfig {
18
19
  mint: PublicKey;
@@ -162,7 +163,7 @@ interface OrderStatus {
162
163
  filledAmount: BN;
163
164
  bump: number;
164
165
  }
165
- /** Per-question fee rates, all out of FEE_DENOMINATOR (1_000_000). E.g. 2_000 = 0.2% */
166
+ /** Per-question fee rates, all out of FEE_DENOMINATOR (10_000). E.g. 200 = 2%, 2_000 = 20% */
166
167
  interface QuestionFee {
167
168
  conditionId: Uint8Array;
168
169
  mergeFee: BN;
@@ -170,7 +171,7 @@ interface QuestionFee {
170
171
  swapFee: BN;
171
172
  bump: number;
172
173
  }
173
- declare const FEE_DENOMINATOR = 1000000;
174
+ declare const FEE_DENOMINATOR = 10000;
174
175
  /**
175
176
  * Off-chain order struct passed as instruction data.
176
177
  * Operator validates + submits matched order pairs on-chain.
@@ -214,6 +215,21 @@ interface SignedOrder {
214
215
  /** Ed25519 signature (64 bytes) from order.maker over serializeOrderToBytes() */
215
216
  signature: Uint8Array;
216
217
  }
218
+ /** Authorization for CLOB to collect fee_amount winning tokens after question resolution. */
219
+ interface CollectFeeOrder {
220
+ user: PublicKey;
221
+ condition: PublicKey;
222
+ tokenMint: PublicKey;
223
+ amount: BN;
224
+ nonce: BN;
225
+ /** Unix timestamp, 0 = no expiry */
226
+ expiry: BN;
227
+ }
228
+ interface SignedCollectFeeOrder {
229
+ order: CollectFeeOrder;
230
+ /** Ed25519 signature (64 bytes) from order.user over serializeCollectFeeOrderToBytes() */
231
+ signature: Uint8Array;
232
+ }
217
233
  declare class XMarketError extends Error {
218
234
  code?: string | undefined;
219
235
  constructor(message: string, code?: string | undefined);
@@ -476,8 +492,24 @@ declare class MarketClient {
476
492
  * @param creator presale creator pubkey (stored in question)
477
493
  * @param currencyMint collateral mint
478
494
  */
479
- approvePresale(presalePda: PublicKey, contentHash: Uint8Array, hookProgram: PublicKey, authorizedClob: PublicKey, expirationTime: anchor.BN, creator: PublicKey, currencyMint: PublicKey, caller?: PublicKey, payer?: PublicKey): Promise<{
480
- tx: Transaction;
495
+ approvePresale(params: {
496
+ presalePda: PublicKey;
497
+ contentHash: Uint8Array;
498
+ hookProgram: PublicKey;
499
+ authorizedClob: PublicKey;
500
+ expirationTime: anchor.BN;
501
+ creator: PublicKey;
502
+ currencyMint: PublicKey;
503
+ /** Revenue distribution — required: approvePresale now distributes 80/10/10 automatically */
504
+ referralAddress: PublicKey;
505
+ companyAddress: PublicKey;
506
+ adminOwner: PublicKey;
507
+ caller?: PublicKey;
508
+ payer?: PublicKey;
509
+ /** Provide an ALT to use VersionedTransaction (required: 31 accounts exceeds legacy tx limit) */
510
+ lookupTable?: AddressLookupTableAccount;
511
+ }): Promise<{
512
+ tx: Transaction | VersionedTransaction;
481
513
  questionPda: PublicKey;
482
514
  conditionPda: PublicKey;
483
515
  marketOraclePda: PublicKey;
@@ -513,27 +545,66 @@ declare class FeeManagementClient {
513
545
  private readonly provider;
514
546
  private readonly programIds;
515
547
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
516
- initFeeConfig(admin: PublicKey, companyAddress: PublicKey, referralAddress: PublicKey, presaleRevenueAddress: PublicKey, investorsMarketRev: number, companyMarketRev: number, agentsPresaleRev: number, companyPresaleRev: number, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
548
+ initFeeConfig(params: {
549
+ admin: PublicKey;
550
+ companyAddress: PublicKey;
551
+ referralAddress: PublicKey;
552
+ presaleRevenueAddress: PublicKey;
553
+ investorsMarketRev: number;
554
+ companyMarketRev: number;
555
+ agentsPresaleRev: number;
556
+ companyPresaleRev: number;
557
+ /** Share routed to referral vault (e.g. 2_000 = 20%). Must satisfy referral+company+investors=10_000 */
558
+ referralMarketRev: number;
559
+ referralVault: PublicKey;
560
+ authority: PublicKey;
561
+ payer: PublicKey;
562
+ }): Promise<TxResult>;
517
563
  fetchFeeConfig(owner: PublicKey): Promise<any | null>;
518
564
  /**
519
- * Fetch per-question fees for a condition.
520
- * Returns null if no fees have been set yet.
565
+ * Fetch per-market fees for a condition.
566
+ * Returns null if fees have not been initialized yet.
567
+ * Fees are set automatically via CPI when create_question_admin / approve_presale runs.
568
+ * Defaults: swapFee=200 (2%), redeemFee=0, mergeFee=2000 (20%), out of FEE_DENOMINATOR=10_000.
521
569
  */
570
+ getMarketFee(conditionPda: PublicKey): Promise<QuestionFee | null>;
522
571
  fetchQuestionFee(conditionPda: PublicKey): Promise<QuestionFee | null>;
523
572
  /**
524
- * Set per-question fees for a condition.
573
+ * Set per-question fees for a condition (whitelist-only edit after market creation).
525
574
  * @param conditionPda - condition PDA from the question
526
- * @param mergeFee - fee out of FEE_DENOMINATOR (1_000_000), e.g. 2_000 = 0.2%
575
+ * @param mergeFee - fee out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
527
576
  * @param redeemFee - fee out of FEE_DENOMINATOR
528
- * @param swapFee - trading fee out of FEE_DENOMINATOR
577
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
529
578
  * @param feeConfigOwner - pubkey that owns the fee_config PDA (usually market deployer)
530
579
  * @param authority - signer authorized in fee_config whitelist / admin / owner
531
580
  * @param payer - rent + tx fee payer
532
581
  */
533
- updateFeeConfig(companyAddress: PublicKey, referralAddress: PublicKey, presaleRevenueAddress: PublicKey, investorsMarketRev: number, companyMarketRev: number, agentsPresaleRev: number, companyPresaleRev: number, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
582
+ updateFeeConfig(params: {
583
+ companyAddress: PublicKey;
584
+ referralAddress: PublicKey;
585
+ presaleRevenueAddress: PublicKey;
586
+ investorsMarketRev: number;
587
+ companyMarketRev: number;
588
+ agentsPresaleRev: number;
589
+ companyPresaleRev: number;
590
+ referralMarketRev: number;
591
+ referralVault: PublicKey;
592
+ authority: PublicKey;
593
+ payer: PublicKey;
594
+ }): Promise<TxResult>;
534
595
  setMarketFeeOverride(conditionPda: PublicKey, investors: number, company: number, isAdmin: boolean, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
535
- buildDistributeFeeIx(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TransactionInstruction>;
536
- distributeFee(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TxResult>;
596
+ /**
597
+ * Build editMarketFee transaction (whitelist-only).
598
+ * @param conditionPda - condition PDA (market identifier)
599
+ * @param mergeFee - out of FEE_DENOMINATOR (10_000), e.g. 2_000 = 20%
600
+ * @param redeemFee - out of FEE_DENOMINATOR
601
+ * @param swapFee - trading fee out of FEE_DENOMINATOR, e.g. 200 = 2%
602
+ * @param feeConfigOwner - owner of fee_config PDA
603
+ * @param authority - whitelisted signer (signs tx externally)
604
+ * @param payer - fee payer (can differ from authority)
605
+ */
606
+ buildEditMarketFeeTx(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer?: PublicKey): Promise<Transaction>;
607
+ /** @deprecated use buildEditMarketFeeTx */
537
608
  setQuestionFee(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
538
609
  }
539
610
 
@@ -547,6 +618,8 @@ declare class ClobClient {
547
618
  feeConfigOwner?: PublicKey;
548
619
  /** Cached company_address from fee_config to avoid repeated RPC calls */
549
620
  private _companyAddress?;
621
+ /** Cached referral_vault from fee_config */
622
+ private _referralVault?;
550
623
  /** ALT cache: condition.toBase58() → loaded ALT account */
551
624
  private _altCache;
552
625
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -555,6 +628,7 @@ declare class ClobClient {
555
628
  };
556
629
  });
557
630
  private companyAddress;
631
+ private referralVault;
558
632
  get walletPubkey(): PublicKey;
559
633
  /**
560
634
  * Get or create an ALT for a condition.
@@ -717,6 +791,23 @@ declare class ClobClient {
717
791
  buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
718
792
  marketOracleVault?: PublicKey;
719
793
  }): Promise<VersionedTransaction>;
794
+ /**
795
+ * Build VersionedTransaction for batchCollectRedeemEarly.
796
+ *
797
+ * Flow: Ed25519 ix (user sigs) + batchCollectRedeemEarly ix.
798
+ * Each SignedCollectFeeOrder authorizes CLOB to collect `amount` winning tokens
799
+ * from that user, redeem via CTF, then distribute as fees.
800
+ *
801
+ * @param signedOrders - Array of { order, signature } from winning users
802
+ * @param condition - Market condition PDA
803
+ * @param outcomeIndex - 0 = NO wins, 1 = YES wins
804
+ * @param operator - Whitelisted operator pubkey (must sign)
805
+ * @param payer - Fee payer pubkey (must sign)
806
+ * @param opts.marketOracleVault - MarketOracle vault for fee distribution
807
+ */
808
+ buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
809
+ marketOracleVault?: PublicKey;
810
+ }): Promise<VersionedTransaction>;
720
811
  fetchConfig(): Promise<ClobConfig | null>;
721
812
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
722
813
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -865,6 +956,46 @@ declare class AdminClient {
865
956
  distributeMarket(conditionId: Uint8Array, amount: anchor.BN, collateralMint: PublicKey, marketOracleVault: PublicKey, owner: PublicKey, claimer?: PublicKey, payer?: PublicKey): Promise<Transaction>;
866
957
  }
867
958
 
959
+ interface ReferralConfigInfo {
960
+ owner: PublicKey;
961
+ collateralMint: PublicKey;
962
+ whitelist: PublicKey[];
963
+ bump: number;
964
+ }
965
+ declare class ReferralClient {
966
+ private readonly program;
967
+ private readonly provider;
968
+ private readonly programIds;
969
+ constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
970
+ get walletPubkey(): PublicKey;
971
+ referralVault(owner: PublicKey, collateralMint: PublicKey): PublicKey;
972
+ fetchConfig(owner: PublicKey): Promise<ReferralConfigInfo | null>;
973
+ /**
974
+ * Build initialize tx — creates referral config PDA.
975
+ * Also prepends an ATA creation instruction for the referral vault (idempotent).
976
+ * Build-tx pattern.
977
+ */
978
+ buildInitializeTx(collateralMint: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<{
979
+ tx: Transaction;
980
+ configPda: PublicKey;
981
+ vaultAta: PublicKey;
982
+ }>;
983
+ /** Build add-to-whitelist tx. Build-tx pattern. */
984
+ buildAddToWhitelistTx(address: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
985
+ /** Build remove-from-whitelist tx. Build-tx pattern. */
986
+ buildRemoveFromWhitelistTx(address: PublicKey, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
987
+ /**
988
+ * Build batchSendUsds tx. Build-tx pattern.
989
+ * @param recipients - wallet addresses to send to
990
+ * @param amounts - corresponding amounts in token smallest units
991
+ * @param configOwner - owner of referral config (used to derive config + vault)
992
+ * @param collateralMint - token mint
993
+ * @param authority - whitelisted signer
994
+ * @param payer - fee payer (can differ from authority)
995
+ */
996
+ buildBatchSendUsdsTx(recipients: PublicKey[], amounts: BN[], configOwner: PublicKey, collateralMint: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
997
+ }
998
+
868
999
  declare class XMarketSDK {
869
1000
  readonly provider: anchor.AnchorProvider;
870
1001
  readonly networkConfig: NetworkConfig;
@@ -879,6 +1010,7 @@ declare class XMarketSDK {
879
1010
  private _presale?;
880
1011
  private _marketOracle?;
881
1012
  private _admin?;
1013
+ private _referral?;
882
1014
  constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
883
1015
  private _withAddress;
884
1016
  get oracle(): OracleClient;
@@ -890,6 +1022,7 @@ declare class XMarketSDK {
890
1022
  get presale(): PresaleClient;
891
1023
  get marketOracle(): MarketOracleClient;
892
1024
  get admin(): AdminClient;
1025
+ get referral(): ReferralClient;
893
1026
  }
894
1027
 
895
1028
  declare const SEEDS: {
@@ -910,6 +1043,7 @@ declare const SEEDS: {
910
1043
  readonly clobConfig: Buffer<ArrayBuffer>;
911
1044
  readonly order: Buffer<ArrayBuffer>;
912
1045
  readonly feeConfig: Buffer<ArrayBuffer>;
1046
+ readonly referralConfig: Buffer<ArrayBuffer>;
913
1047
  readonly questionFee: Buffer<ArrayBuffer>;
914
1048
  readonly marketFee: Buffer<ArrayBuffer>;
915
1049
  readonly presale: Buffer<ArrayBuffer>;
@@ -949,6 +1083,7 @@ declare class PDA {
949
1083
  static userBuyRecord(presalePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
950
1084
  static marketOraclePda(questionPda: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
951
1085
  static userClaimRecord(marketOraclePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
1086
+ static referralConfig(owner: PublicKey, programIds: Pick<ProgramIds, "referral">): [PublicKey, number];
952
1087
  static adminConfig(owner: PublicKey, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
953
1088
  static claimRecord(conditionId: Uint8Array, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
954
1089
  }
@@ -989,6 +1124,25 @@ declare function buildBatchedEd25519Instruction(orders: SignedOrder[]): Transact
989
1124
  * Pass this as `ixSysvar` to all match_* instruction accounts.
990
1125
  */
991
1126
  declare const IX_SYSVAR: _solana_web3_js.PublicKey;
1127
+ /**
1128
+ * Convert SignedOrder to the shape anchor expects for SignedOrder struct.
1129
+ * The signature must be passed as a fixed-size array of 64 numbers.
1130
+ */
1131
+ /**
1132
+ * Serialize a CollectFeeOrder to 120 bytes — must match Rust `CollectFeeOrder::to_signable_bytes()`.
1133
+ * [0..32] user pubkey
1134
+ * [32..64] condition pubkey
1135
+ * [64..96] token_mint pubkey
1136
+ * [96..104] amount (u64 le)
1137
+ * [104..112] nonce (u64 le)
1138
+ * [112..120] expiry (i64 le)
1139
+ */
1140
+ declare function serializeCollectFeeOrderToBytes(order: CollectFeeOrder): Uint8Array;
1141
+ /**
1142
+ * Build a batched Ed25519 precompile instruction for N signed CollectFeeOrders.
1143
+ * Same layout as buildBatchedEd25519Instruction but with 120-byte messages.
1144
+ */
1145
+ declare function buildBatchedCollectFeeEd25519Instruction(orders: SignedCollectFeeOrder[]): TransactionInstruction;
992
1146
 
993
1147
  /**
994
1148
  * High-level order utilities — build, sign, serialize, verify, detect match type.
@@ -1141,4 +1295,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1141
1295
  */
1142
1296
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1143
1297
 
1144
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1298
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };