@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.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;
@@ -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);
@@ -529,7 +545,21 @@ declare class FeeManagementClient {
529
545
  private readonly provider;
530
546
  private readonly programIds;
531
547
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
532
- 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>;
533
563
  fetchFeeConfig(owner: PublicKey): Promise<any | null>;
534
564
  /**
535
565
  * Fetch per-market fees for a condition.
@@ -549,10 +579,32 @@ declare class FeeManagementClient {
549
579
  * @param authority - signer authorized in fee_config whitelist / admin / owner
550
580
  * @param payer - rent + tx fee payer
551
581
  */
552
- 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>;
553
595
  setMarketFeeOverride(conditionPda: PublicKey, investors: number, company: number, isAdmin: boolean, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
554
- buildDistributeFeeIx(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TransactionInstruction>;
555
- 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 */
556
608
  setQuestionFee(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
557
609
  }
558
610
 
@@ -566,6 +618,8 @@ declare class ClobClient {
566
618
  feeConfigOwner?: PublicKey;
567
619
  /** Cached company_address from fee_config to avoid repeated RPC calls */
568
620
  private _companyAddress?;
621
+ /** Cached referral_vault from fee_config */
622
+ private _referralVault?;
569
623
  /** ALT cache: condition.toBase58() → loaded ALT account */
570
624
  private _altCache;
571
625
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -574,6 +628,7 @@ declare class ClobClient {
574
628
  };
575
629
  });
576
630
  private companyAddress;
631
+ private referralVault;
577
632
  get walletPubkey(): PublicKey;
578
633
  /**
579
634
  * Get or create an ALT for a condition.
@@ -736,6 +791,23 @@ declare class ClobClient {
736
791
  buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
737
792
  marketOracleVault?: PublicKey;
738
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>;
739
811
  fetchConfig(): Promise<ClobConfig | null>;
740
812
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
741
813
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -884,6 +956,46 @@ declare class AdminClient {
884
956
  distributeMarket(conditionId: Uint8Array, amount: anchor.BN, collateralMint: PublicKey, marketOracleVault: PublicKey, owner: PublicKey, claimer?: PublicKey, payer?: PublicKey): Promise<Transaction>;
885
957
  }
886
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
+
887
999
  declare class XMarketSDK {
888
1000
  readonly provider: anchor.AnchorProvider;
889
1001
  readonly networkConfig: NetworkConfig;
@@ -898,6 +1010,7 @@ declare class XMarketSDK {
898
1010
  private _presale?;
899
1011
  private _marketOracle?;
900
1012
  private _admin?;
1013
+ private _referral?;
901
1014
  constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
902
1015
  private _withAddress;
903
1016
  get oracle(): OracleClient;
@@ -909,6 +1022,7 @@ declare class XMarketSDK {
909
1022
  get presale(): PresaleClient;
910
1023
  get marketOracle(): MarketOracleClient;
911
1024
  get admin(): AdminClient;
1025
+ get referral(): ReferralClient;
912
1026
  }
913
1027
 
914
1028
  declare const SEEDS: {
@@ -929,6 +1043,7 @@ declare const SEEDS: {
929
1043
  readonly clobConfig: Buffer<ArrayBuffer>;
930
1044
  readonly order: Buffer<ArrayBuffer>;
931
1045
  readonly feeConfig: Buffer<ArrayBuffer>;
1046
+ readonly referralConfig: Buffer<ArrayBuffer>;
932
1047
  readonly questionFee: Buffer<ArrayBuffer>;
933
1048
  readonly marketFee: Buffer<ArrayBuffer>;
934
1049
  readonly presale: Buffer<ArrayBuffer>;
@@ -968,6 +1083,7 @@ declare class PDA {
968
1083
  static userBuyRecord(presalePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
969
1084
  static marketOraclePda(questionPda: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
970
1085
  static userClaimRecord(marketOraclePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
1086
+ static referralConfig(owner: PublicKey, programIds: Pick<ProgramIds, "referral">): [PublicKey, number];
971
1087
  static adminConfig(owner: PublicKey, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
972
1088
  static claimRecord(conditionId: Uint8Array, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
973
1089
  }
@@ -1008,6 +1124,25 @@ declare function buildBatchedEd25519Instruction(orders: SignedOrder[]): Transact
1008
1124
  * Pass this as `ixSysvar` to all match_* instruction accounts.
1009
1125
  */
1010
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;
1011
1146
 
1012
1147
  /**
1013
1148
  * High-level order utilities — build, sign, serialize, verify, detect match type.
@@ -1160,4 +1295,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1160
1295
  */
1161
1296
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1162
1297
 
1163
- 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;
@@ -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);
@@ -529,7 +545,21 @@ declare class FeeManagementClient {
529
545
  private readonly provider;
530
546
  private readonly programIds;
531
547
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
532
- 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>;
533
563
  fetchFeeConfig(owner: PublicKey): Promise<any | null>;
534
564
  /**
535
565
  * Fetch per-market fees for a condition.
@@ -549,10 +579,32 @@ declare class FeeManagementClient {
549
579
  * @param authority - signer authorized in fee_config whitelist / admin / owner
550
580
  * @param payer - rent + tx fee payer
551
581
  */
552
- 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>;
553
595
  setMarketFeeOverride(conditionPda: PublicKey, investors: number, company: number, isAdmin: boolean, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
554
- buildDistributeFeeIx(conditionPda: PublicKey, amount: BN, feeConfigOwner: PublicKey, sourceAta: PublicKey, companyAta: PublicKey, marketOracleVault: PublicKey, authority: PublicKey): Promise<TransactionInstruction>;
555
- 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 */
556
608
  setQuestionFee(conditionPda: PublicKey, mergeFee: BN, redeemFee: BN, swapFee: BN, feeConfigOwner: PublicKey, authority: PublicKey, payer: PublicKey): Promise<TxResult>;
557
609
  }
558
610
 
@@ -566,6 +618,8 @@ declare class ClobClient {
566
618
  feeConfigOwner?: PublicKey;
567
619
  /** Cached company_address from fee_config to avoid repeated RPC calls */
568
620
  private _companyAddress?;
621
+ /** Cached referral_vault from fee_config */
622
+ private _referralVault?;
569
623
  /** ALT cache: condition.toBase58() → loaded ALT account */
570
624
  private _altCache;
571
625
  constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
@@ -574,6 +628,7 @@ declare class ClobClient {
574
628
  };
575
629
  });
576
630
  private companyAddress;
631
+ private referralVault;
577
632
  get walletPubkey(): PublicKey;
578
633
  /**
579
634
  * Get or create an ALT for a condition.
@@ -736,6 +791,23 @@ declare class ClobClient {
736
791
  buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
737
792
  marketOracleVault?: PublicKey;
738
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>;
739
811
  fetchConfig(): Promise<ClobConfig | null>;
740
812
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
741
813
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -884,6 +956,46 @@ declare class AdminClient {
884
956
  distributeMarket(conditionId: Uint8Array, amount: anchor.BN, collateralMint: PublicKey, marketOracleVault: PublicKey, owner: PublicKey, claimer?: PublicKey, payer?: PublicKey): Promise<Transaction>;
885
957
  }
886
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
+
887
999
  declare class XMarketSDK {
888
1000
  readonly provider: anchor.AnchorProvider;
889
1001
  readonly networkConfig: NetworkConfig;
@@ -898,6 +1010,7 @@ declare class XMarketSDK {
898
1010
  private _presale?;
899
1011
  private _marketOracle?;
900
1012
  private _admin?;
1013
+ private _referral?;
901
1014
  constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
902
1015
  private _withAddress;
903
1016
  get oracle(): OracleClient;
@@ -909,6 +1022,7 @@ declare class XMarketSDK {
909
1022
  get presale(): PresaleClient;
910
1023
  get marketOracle(): MarketOracleClient;
911
1024
  get admin(): AdminClient;
1025
+ get referral(): ReferralClient;
912
1026
  }
913
1027
 
914
1028
  declare const SEEDS: {
@@ -929,6 +1043,7 @@ declare const SEEDS: {
929
1043
  readonly clobConfig: Buffer<ArrayBuffer>;
930
1044
  readonly order: Buffer<ArrayBuffer>;
931
1045
  readonly feeConfig: Buffer<ArrayBuffer>;
1046
+ readonly referralConfig: Buffer<ArrayBuffer>;
932
1047
  readonly questionFee: Buffer<ArrayBuffer>;
933
1048
  readonly marketFee: Buffer<ArrayBuffer>;
934
1049
  readonly presale: Buffer<ArrayBuffer>;
@@ -968,6 +1083,7 @@ declare class PDA {
968
1083
  static userBuyRecord(presalePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
969
1084
  static marketOraclePda(questionPda: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
970
1085
  static userClaimRecord(marketOraclePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
1086
+ static referralConfig(owner: PublicKey, programIds: Pick<ProgramIds, "referral">): [PublicKey, number];
971
1087
  static adminConfig(owner: PublicKey, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
972
1088
  static claimRecord(conditionId: Uint8Array, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
973
1089
  }
@@ -1008,6 +1124,25 @@ declare function buildBatchedEd25519Instruction(orders: SignedOrder[]): Transact
1008
1124
  * Pass this as `ixSysvar` to all match_* instruction accounts.
1009
1125
  */
1010
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;
1011
1146
 
1012
1147
  /**
1013
1148
  * High-level order utilities — build, sign, serialize, verify, detect match type.
@@ -1160,4 +1295,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1160
1295
  */
1161
1296
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1162
1297
 
1163
- 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 };