@theliem/xmarket-sdk 3.4.2 → 3.6.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
@@ -563,6 +563,7 @@ declare class ClobClient {
563
563
  ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
564
564
  private _sendLegacyTxSig;
565
565
  private _sendLegacyTx;
566
+ private _ensureClobOutcomeAtas;
566
567
  /**
567
568
  * Send a match transaction as versioned (v0) with optional ALT.
568
569
  * Both operator wallet and payer (this.provider.wallet) sign.
@@ -595,13 +596,20 @@ declare class ClobClient {
595
596
  buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
596
597
  marketOracleVault?: PublicKey;
597
598
  fillAmount?: anchor.BN;
598
- }): Promise<TransactionInstruction[]>;
599
+ }, useTakerPrice?: boolean): Promise<TransactionInstruction[]>;
599
600
  /**
600
601
  * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
601
602
  * Phase 1: register taker + all makers in parallel.
602
603
  * Phase 2: 1 atomic match tx.
603
604
  */
604
605
  private matchComplementary;
606
+ /**
607
+ * 1 SELL taker vs N BUY makers.
608
+ * Rust program only supports BUY-as-taker, so we decompose into N instructions
609
+ * (BUY_i as taker, SELL as single maker) combined into one atomic transaction.
610
+ * Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
611
+ */
612
+ private matchComplementarySellVsMultiBuy;
605
613
  /**
606
614
  * MINT: 1 YES buyer (taker) + N NO buyers (makers).
607
615
  * Phase 1: register taker + all NO makers in parallel.
@@ -638,6 +646,48 @@ declare class ClobClient {
638
646
  matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
639
647
  marketOracleVault?: PublicKey;
640
648
  }): Promise<TxResult>;
649
+ /**
650
+ * High-level match: caller passes price + quantity + keypair — SDK builds,
651
+ * signs, and submits in one call. No manual amount calculation needed.
652
+ *
653
+ * Amounts are computed from each order's own limit `price` (percentage, e.g. 51 for 51%).
654
+ * NEVER pass averageMatchedPrice — that is an engine output, not an order input.
655
+ *
656
+ * @param taker { keypair, condition, tokenId, side, price, quantity, nonce?, expiry? }
657
+ * @param makers Array of same shape
658
+ * @param decimals Collateral decimals (default 9 for USDS)
659
+ */
660
+ matchOrdersFromPrice(taker: {
661
+ keypair: {
662
+ publicKey: PublicKey;
663
+ secretKey: Uint8Array;
664
+ };
665
+ condition: PublicKey;
666
+ tokenId: number;
667
+ side: 0 | 1;
668
+ price: number;
669
+ quantity: number;
670
+ nonce?: BN;
671
+ expiry?: BN;
672
+ fee?: BN;
673
+ taker?: PublicKey;
674
+ }, makers: Array<{
675
+ keypair: {
676
+ publicKey: PublicKey;
677
+ secretKey: Uint8Array;
678
+ };
679
+ condition: PublicKey;
680
+ tokenId: number;
681
+ side: 0 | 1;
682
+ price: number;
683
+ quantity: number;
684
+ nonce?: BN;
685
+ expiry?: BN;
686
+ fee?: BN;
687
+ taker?: PublicKey;
688
+ }>, decimals?: number, opts?: {
689
+ marketOracleVault?: PublicKey;
690
+ }): Promise<TxResult>;
641
691
  fetchConfig(): Promise<ClobConfig | null>;
642
692
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
643
693
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -939,6 +989,51 @@ declare function buildOrder(params: {
939
989
  fee?: BN;
940
990
  taker?: PublicKey;
941
991
  }): Order;
992
+ /**
993
+ * Compute makerAmount / takerAmount from a limit price and quantity.
994
+ *
995
+ * ALWAYS use the order's own limit price (e.g., 51 for a 51% limit order).
996
+ * NEVER pass `averageMatchedPrice` — that is an output of the matching engine,
997
+ * not an order input. Using avgPrice here causes crossing checks to fail
998
+ * for any maker whose price equals the limit price exactly.
999
+ *
1000
+ * BUY YES (side=0): makerAmount = USDS spent = qty × price/100
1001
+ * takerAmount = YES received = qty
1002
+ * SELL YES (side=1): makerAmount = YES given = qty
1003
+ * takerAmount = USDS received = qty × price/100
1004
+ *
1005
+ * @param side 0 = BUY, 1 = SELL
1006
+ * @param price Limit price in percentage cents (e.g., 51 for 51% = $0.51/token)
1007
+ * @param quantity Whole token count (e.g., 11 for 11 YES tokens)
1008
+ * @param decimals Collateral token decimals (default 9 for USDS)
1009
+ */
1010
+ declare function orderAmountsFromPrice(side: 0 | 1, price: number, quantity: number, decimals?: number): {
1011
+ makerAmount: BN;
1012
+ takerAmount: BN;
1013
+ };
1014
+ /**
1015
+ * Build a fully-populated Order from human-readable price + quantity.
1016
+ * Amounts are computed using the limit price — never use averageMatchedPrice.
1017
+ *
1018
+ * @param params.side 0 = BUY, 1 = SELL
1019
+ * @param params.price Limit price in percentage (e.g., 51 for 51%)
1020
+ * @param params.quantity Whole token count (e.g., 11 for 11 YES tokens)
1021
+ * @param params.decimals Collateral decimals (default 9 for USDS)
1022
+ */
1023
+ declare function buildOrderFromPrice(params: {
1024
+ maker: PublicKey;
1025
+ condition: PublicKey;
1026
+ tokenId: number;
1027
+ side: 0 | 1;
1028
+ price: number;
1029
+ quantity: number;
1030
+ decimals?: number;
1031
+ nonce?: BN;
1032
+ expiry?: BN;
1033
+ createdAt?: BN;
1034
+ fee?: BN;
1035
+ taker?: PublicKey;
1036
+ }): Order;
942
1037
  /**
943
1038
  * Sign an order with a Keypair.
944
1039
  * Uses Ed25519 (nacl.sign.detached) over the 178-byte canonical message.
@@ -1005,4 +1100,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1005
1100
  */
1006
1101
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1007
1102
 
1008
- 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, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1103
+ 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, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.d.ts CHANGED
@@ -563,6 +563,7 @@ declare class ClobClient {
563
563
  ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
564
564
  private _sendLegacyTxSig;
565
565
  private _sendLegacyTx;
566
+ private _ensureClobOutcomeAtas;
566
567
  /**
567
568
  * Send a match transaction as versioned (v0) with optional ALT.
568
569
  * Both operator wallet and payer (this.provider.wallet) sign.
@@ -595,13 +596,20 @@ declare class ClobClient {
595
596
  buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
596
597
  marketOracleVault?: PublicKey;
597
598
  fillAmount?: anchor.BN;
598
- }): Promise<TransactionInstruction[]>;
599
+ }, useTakerPrice?: boolean): Promise<TransactionInstruction[]>;
599
600
  /**
600
601
  * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
601
602
  * Phase 1: register taker + all makers in parallel.
602
603
  * Phase 2: 1 atomic match tx.
603
604
  */
604
605
  private matchComplementary;
606
+ /**
607
+ * 1 SELL taker vs N BUY makers.
608
+ * Rust program only supports BUY-as-taker, so we decompose into N instructions
609
+ * (BUY_i as taker, SELL as single maker) combined into one atomic transaction.
610
+ * Engine must use limitPrice for BUY.makerAmount to pass per-pair crossing check.
611
+ */
612
+ private matchComplementarySellVsMultiBuy;
605
613
  /**
606
614
  * MINT: 1 YES buyer (taker) + N NO buyers (makers).
607
615
  * Phase 1: register taker + all NO makers in parallel.
@@ -638,6 +646,48 @@ declare class ClobClient {
638
646
  matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
639
647
  marketOracleVault?: PublicKey;
640
648
  }): Promise<TxResult>;
649
+ /**
650
+ * High-level match: caller passes price + quantity + keypair — SDK builds,
651
+ * signs, and submits in one call. No manual amount calculation needed.
652
+ *
653
+ * Amounts are computed from each order's own limit `price` (percentage, e.g. 51 for 51%).
654
+ * NEVER pass averageMatchedPrice — that is an engine output, not an order input.
655
+ *
656
+ * @param taker { keypair, condition, tokenId, side, price, quantity, nonce?, expiry? }
657
+ * @param makers Array of same shape
658
+ * @param decimals Collateral decimals (default 9 for USDS)
659
+ */
660
+ matchOrdersFromPrice(taker: {
661
+ keypair: {
662
+ publicKey: PublicKey;
663
+ secretKey: Uint8Array;
664
+ };
665
+ condition: PublicKey;
666
+ tokenId: number;
667
+ side: 0 | 1;
668
+ price: number;
669
+ quantity: number;
670
+ nonce?: BN;
671
+ expiry?: BN;
672
+ fee?: BN;
673
+ taker?: PublicKey;
674
+ }, makers: Array<{
675
+ keypair: {
676
+ publicKey: PublicKey;
677
+ secretKey: Uint8Array;
678
+ };
679
+ condition: PublicKey;
680
+ tokenId: number;
681
+ side: 0 | 1;
682
+ price: number;
683
+ quantity: number;
684
+ nonce?: BN;
685
+ expiry?: BN;
686
+ fee?: BN;
687
+ taker?: PublicKey;
688
+ }>, decimals?: number, opts?: {
689
+ marketOracleVault?: PublicKey;
690
+ }): Promise<TxResult>;
641
691
  fetchConfig(): Promise<ClobConfig | null>;
642
692
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
643
693
  fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
@@ -939,6 +989,51 @@ declare function buildOrder(params: {
939
989
  fee?: BN;
940
990
  taker?: PublicKey;
941
991
  }): Order;
992
+ /**
993
+ * Compute makerAmount / takerAmount from a limit price and quantity.
994
+ *
995
+ * ALWAYS use the order's own limit price (e.g., 51 for a 51% limit order).
996
+ * NEVER pass `averageMatchedPrice` — that is an output of the matching engine,
997
+ * not an order input. Using avgPrice here causes crossing checks to fail
998
+ * for any maker whose price equals the limit price exactly.
999
+ *
1000
+ * BUY YES (side=0): makerAmount = USDS spent = qty × price/100
1001
+ * takerAmount = YES received = qty
1002
+ * SELL YES (side=1): makerAmount = YES given = qty
1003
+ * takerAmount = USDS received = qty × price/100
1004
+ *
1005
+ * @param side 0 = BUY, 1 = SELL
1006
+ * @param price Limit price in percentage cents (e.g., 51 for 51% = $0.51/token)
1007
+ * @param quantity Whole token count (e.g., 11 for 11 YES tokens)
1008
+ * @param decimals Collateral token decimals (default 9 for USDS)
1009
+ */
1010
+ declare function orderAmountsFromPrice(side: 0 | 1, price: number, quantity: number, decimals?: number): {
1011
+ makerAmount: BN;
1012
+ takerAmount: BN;
1013
+ };
1014
+ /**
1015
+ * Build a fully-populated Order from human-readable price + quantity.
1016
+ * Amounts are computed using the limit price — never use averageMatchedPrice.
1017
+ *
1018
+ * @param params.side 0 = BUY, 1 = SELL
1019
+ * @param params.price Limit price in percentage (e.g., 51 for 51%)
1020
+ * @param params.quantity Whole token count (e.g., 11 for 11 YES tokens)
1021
+ * @param params.decimals Collateral decimals (default 9 for USDS)
1022
+ */
1023
+ declare function buildOrderFromPrice(params: {
1024
+ maker: PublicKey;
1025
+ condition: PublicKey;
1026
+ tokenId: number;
1027
+ side: 0 | 1;
1028
+ price: number;
1029
+ quantity: number;
1030
+ decimals?: number;
1031
+ nonce?: BN;
1032
+ expiry?: BN;
1033
+ createdAt?: BN;
1034
+ fee?: BN;
1035
+ taker?: PublicKey;
1036
+ }): Order;
942
1037
  /**
943
1038
  * Sign an order with a Keypair.
944
1039
  * Uses Ed25519 (nacl.sign.detached) over the 178-byte canonical message.
@@ -1005,4 +1100,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1005
1100
  */
1006
1101
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1007
1102
 
1008
- 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, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1103
+ 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, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };