@theliem/xmarket-sdk 3.3.0 → 3.3.1

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
@@ -431,6 +431,8 @@ declare class MarketClient {
431
431
  removeAdmin(owner?: PublicKey): Promise<Transaction>;
432
432
  addToWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
433
433
  removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
434
+ growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
435
+ restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
434
436
  fetchConfig(): Promise<QuestionMarketConfig | null>;
435
437
  fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
436
438
  questionPda(questionId: Uint8Array): PublicKey;
@@ -546,103 +548,101 @@ declare class ClobClient {
546
548
  get walletPubkey(): PublicKey;
547
549
  /**
548
550
  * Get or create an ALT for a condition.
549
- * First call: creates + extends ALT on-chain, waits for activation (~2s).
550
- * Subsequent calls for same condition: returns cached ALT instantly.
551
- * BE devs never interact with this — called automatically by matchOrders.
551
+ * Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
552
552
  */
553
- ensureAlt(condition: PublicKey, collateralMint: PublicKey, buyerPubkey: PublicKey, buyerNonce: anchor.BN, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
553
+ ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
554
+ private _sendLegacyTxSig;
554
555
  private _sendLegacyTx;
555
556
  /**
556
- * Send a match transaction as versioned (v0).
557
- * Pass a pre-built AddressLookupTableAccount to compress account keys and
558
- * stay under the 1232-byte limit — required for match_complementary which
559
- * has ~25 accounts + 2 Ed25519 precompile instructions (~1697 bytes raw).
560
- *
561
- * If `whitelistedWallet` is provided and differs from `this.provider.wallet`,
562
- * both wallets sign the transaction (whitelisted operator + payer).
557
+ * Send a match transaction as versioned (v0) with optional ALT.
558
+ * Both operator wallet and payer (this.provider.wallet) sign.
563
559
  */
564
560
  sendMatchTx(instructions: TransactionInstruction[], lookupTable?: AddressLookupTableAccount, whitelistedWallet?: anchor.Wallet): Promise<string>;
565
561
  configPda(): PublicKey;
566
- /** One-time setup. Caller becomes admin. */
562
+ /**
563
+ * Register a signed order on-chain.
564
+ * Sends Ed25519 precompile ix + register_order ix in one legacy tx.
565
+ * Called at match time (engine-triggered), not at order placement.
566
+ */
567
+ registerOrder(signed: SignedOrder): Promise<string>;
568
+ /** Register only if the PDA doesn't exist yet (idempotent). */
569
+ private registerOrderIfNeeded;
570
+ /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
571
+ cancelOrder(nonce: anchor.BN): Promise<TxResult>;
567
572
  initialize(operators: PublicKey[], feeRecipient: PublicKey, feeRateBps: number): Promise<TxResult>;
568
- /** Admin adds an operator to the whitelist. */
569
573
  addOperator(operator: PublicKey): Promise<TxResult>;
570
- /** Admin removes an operator from the whitelist. */
571
574
  removeOperator(operator: PublicKey): Promise<TxResult>;
572
- /** Admin pause/unpause the CLOB. */
573
575
  setPaused(paused: boolean): Promise<TxResult>;
574
- /**
575
- * Emergency reset of CLOB config (upgrade authority only).
576
- */
577
576
  forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
578
577
  /**
579
- * COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
580
- *
581
- * Transaction structure:
582
- * ix[0] Ed25519(taker/buyer)
583
- * ix[1+i] Ed25519(maker_i/seller_i)
584
- * ix[N+1] match_complementary(buyNonce, makerNonces[])
585
- *
586
- * remaining_accounts: [hook×3] [seller×5 × N]
587
- */
588
- /** Build Ed25519 + matchComplementary instructions without sending.
578
+ * Build match_complementary instruction (no Ed25519 OrderRecord PDAs used).
589
579
  *
590
- * If `buySigned.order.fee > 0` and `feeClient` + `feeConfigOwner` are wired in,
591
- * automatically appends 5 fee_management remaining_accounts so the program CPIs
592
- * to distribute_fee internally. No manual `feeDistribute` param needed.
580
+ * remaining_accounts layout:
581
+ * [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
582
+ * [extraAccountMetaList, hookConfig, hookProgram]
583
+ * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
593
584
  */
594
- buildMatchComplementaryIxs(buySigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
585
+ buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
595
586
  marketOracleVault?: PublicKey;
587
+ fillAmount?: anchor.BN;
596
588
  }): Promise<TransactionInstruction[]>;
589
+ /**
590
+ * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
591
+ * Phase 1: register taker + all makers in parallel.
592
+ * Phase 2: 1 atomic match tx.
593
+ */
597
594
  private matchComplementary;
598
595
  /**
599
- * MINT match: 1 YES buyer (taker) + N NO buyers (makers).
596
+ * MINT: 1 YES buyer (taker) + N NO buyers (makers).
597
+ * Phase 1: register taker + all NO makers in parallel.
598
+ * Phase 2: 1 atomic match tx.
600
599
  *
601
- * Transaction structure:
602
- * ix[0] Ed25519(taker/YES buyer)
603
- * ix[1+i] Ed25519(maker_i/NO buyer)
604
- * ix[N+1] match_mint_orders(yesNonce, makerNonces[])
605
- *
606
- * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
600
+ * remaining_accounts per NO maker (5):
601
+ * [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
607
602
  */
608
603
  private matchMintOrders;
609
604
  /**
610
- * MERGE match: 1 YES seller (taker) + N NO sellers (makers).
611
- *
612
- * Transaction structure:
613
- * ix[0] Ed25519(taker/YES seller)
614
- * ix[1+i] Ed25519(maker_i/NO seller)
615
- * ix[N+1] match_merge_orders(yesNonce, makerNonces[])
605
+ * MERGE: 1 YES seller (taker) + N NO sellers (makers).
606
+ * Phase 1: register taker + all NO makers in parallel.
607
+ * Phase 2: 1 atomic match tx.
616
608
  *
617
- * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
609
+ * remaining_accounts per NO maker (5):
610
+ * [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
611
+ * After all makers, optional 5 fee accounts.
618
612
  */
619
613
  private matchMergeOrders;
620
614
  /**
621
- * Auto-detect match type and execute 1-taker + N-makers in a single transaction.
615
+ * Auto-detect match type and execute 2-phase:
616
+ * Phase 1 — register all orders (taker + makers) on-chain in parallel.
617
+ * Phase 2 — 1 atomic match transaction.
622
618
  *
623
- * Detection (pure, no RPC) based on taker.order vs makers[0].order:
624
- * taker.tokenId === makers[0].tokenId: taker BUY + all makers SELL → COMPLEMENTARY
625
- * taker.tokenId !== makers[0].tokenId + taker BUY + all makers BUYMINT
626
- * taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL MERGE
627
- * Otherwisethrows InvalidParamError
628
- *
629
- * All makers must have the same tokenId and side as makers[0].
630
- */
631
- /**
632
- * Auto-detect match type and execute in a single transaction.
633
- * ALT is managed automatically (created on first call per condition, cached thereafter).
634
- * feeRecipient and collateralMint are derived from on-chain config.
635
- * Fee distribution (distribute_fee CPI) fires automatically when order.fee > 0.
619
+ * Detection (pure, no RPC):
620
+ * taker.tokenId === makers[0].tokenId:
621
+ * taker BUY + all makers SELLCOMPLEMENTARY
622
+ * taker.tokenId !== makers[0].tokenId + all BUY MINT
623
+ * taker.tokenId !== makers[0].tokenId + all SELL MERGE
636
624
  *
637
- * @param opts.marketOracleVault Required for presale markets (is_admin=false).
638
- * Pass the ATA of the market_oracle PDA so 50% of fee goes there.
639
- * For admin markets (is_admin=true) omit — payer is used as placeholder (no transfer).
625
+ * @param opts.marketOracleVault Oracle vault ATA for presale markets.
626
+ * Omit for admin markets (payer used as placeholder).
640
627
  */
641
628
  matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
642
629
  marketOracleVault?: PublicKey;
643
630
  }): Promise<TxResult>;
644
631
  fetchConfig(): Promise<ClobConfig | null>;
645
632
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
633
+ fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
634
+ maker: PublicKey;
635
+ condition: PublicKey;
636
+ tokenId: number;
637
+ side: number;
638
+ makerAmount: anchor.BN;
639
+ takerAmount: anchor.BN;
640
+ nonce: anchor.BN;
641
+ expiry: anchor.BN;
642
+ fee: anchor.BN;
643
+ taker: PublicKey;
644
+ signer: PublicKey;
645
+ } | null>;
646
646
  }
647
647
 
648
648
  interface PresaleInfo {
@@ -802,6 +802,7 @@ declare class PDA {
802
802
  static extraAccountMetaList(mint: PublicKey, programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
803
803
  static clobConfig(programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
804
804
  static orderStatus(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
805
+ static orderRecord(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
805
806
  static feeConfig(owner: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
806
807
  static questionFee(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
807
808
  static marketFeeOverride(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
package/dist/index.d.ts CHANGED
@@ -431,6 +431,8 @@ declare class MarketClient {
431
431
  removeAdmin(owner?: PublicKey): Promise<Transaction>;
432
432
  addToWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
433
433
  removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
434
+ growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
435
+ restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
434
436
  fetchConfig(): Promise<QuestionMarketConfig | null>;
435
437
  fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
436
438
  questionPda(questionId: Uint8Array): PublicKey;
@@ -546,103 +548,101 @@ declare class ClobClient {
546
548
  get walletPubkey(): PublicKey;
547
549
  /**
548
550
  * Get or create an ALT for a condition.
549
- * First call: creates + extends ALT on-chain, waits for activation (~2s).
550
- * Subsequent calls for same condition: returns cached ALT instantly.
551
- * BE devs never interact with this — called automatically by matchOrders.
551
+ * Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
552
552
  */
553
- ensureAlt(condition: PublicKey, collateralMint: PublicKey, buyerPubkey: PublicKey, buyerNonce: anchor.BN, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
553
+ ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
554
+ private _sendLegacyTxSig;
554
555
  private _sendLegacyTx;
555
556
  /**
556
- * Send a match transaction as versioned (v0).
557
- * Pass a pre-built AddressLookupTableAccount to compress account keys and
558
- * stay under the 1232-byte limit — required for match_complementary which
559
- * has ~25 accounts + 2 Ed25519 precompile instructions (~1697 bytes raw).
560
- *
561
- * If `whitelistedWallet` is provided and differs from `this.provider.wallet`,
562
- * both wallets sign the transaction (whitelisted operator + payer).
557
+ * Send a match transaction as versioned (v0) with optional ALT.
558
+ * Both operator wallet and payer (this.provider.wallet) sign.
563
559
  */
564
560
  sendMatchTx(instructions: TransactionInstruction[], lookupTable?: AddressLookupTableAccount, whitelistedWallet?: anchor.Wallet): Promise<string>;
565
561
  configPda(): PublicKey;
566
- /** One-time setup. Caller becomes admin. */
562
+ /**
563
+ * Register a signed order on-chain.
564
+ * Sends Ed25519 precompile ix + register_order ix in one legacy tx.
565
+ * Called at match time (engine-triggered), not at order placement.
566
+ */
567
+ registerOrder(signed: SignedOrder): Promise<string>;
568
+ /** Register only if the PDA doesn't exist yet (idempotent). */
569
+ private registerOrderIfNeeded;
570
+ /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
571
+ cancelOrder(nonce: anchor.BN): Promise<TxResult>;
567
572
  initialize(operators: PublicKey[], feeRecipient: PublicKey, feeRateBps: number): Promise<TxResult>;
568
- /** Admin adds an operator to the whitelist. */
569
573
  addOperator(operator: PublicKey): Promise<TxResult>;
570
- /** Admin removes an operator from the whitelist. */
571
574
  removeOperator(operator: PublicKey): Promise<TxResult>;
572
- /** Admin pause/unpause the CLOB. */
573
575
  setPaused(paused: boolean): Promise<TxResult>;
574
- /**
575
- * Emergency reset of CLOB config (upgrade authority only).
576
- */
577
576
  forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
578
577
  /**
579
- * COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
580
- *
581
- * Transaction structure:
582
- * ix[0] Ed25519(taker/buyer)
583
- * ix[1+i] Ed25519(maker_i/seller_i)
584
- * ix[N+1] match_complementary(buyNonce, makerNonces[])
585
- *
586
- * remaining_accounts: [hook×3] [seller×5 × N]
587
- */
588
- /** Build Ed25519 + matchComplementary instructions without sending.
578
+ * Build match_complementary instruction (no Ed25519 OrderRecord PDAs used).
589
579
  *
590
- * If `buySigned.order.fee > 0` and `feeClient` + `feeConfigOwner` are wired in,
591
- * automatically appends 5 fee_management remaining_accounts so the program CPIs
592
- * to distribute_fee internally. No manual `feeDistribute` param needed.
580
+ * remaining_accounts layout:
581
+ * [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
582
+ * [extraAccountMetaList, hookConfig, hookProgram]
583
+ * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
593
584
  */
594
- buildMatchComplementaryIxs(buySigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
585
+ buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
595
586
  marketOracleVault?: PublicKey;
587
+ fillAmount?: anchor.BN;
596
588
  }): Promise<TransactionInstruction[]>;
589
+ /**
590
+ * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
591
+ * Phase 1: register taker + all makers in parallel.
592
+ * Phase 2: 1 atomic match tx.
593
+ */
597
594
  private matchComplementary;
598
595
  /**
599
- * MINT match: 1 YES buyer (taker) + N NO buyers (makers).
596
+ * MINT: 1 YES buyer (taker) + N NO buyers (makers).
597
+ * Phase 1: register taker + all NO makers in parallel.
598
+ * Phase 2: 1 atomic match tx.
600
599
  *
601
- * Transaction structure:
602
- * ix[0] Ed25519(taker/YES buyer)
603
- * ix[1+i] Ed25519(maker_i/NO buyer)
604
- * ix[N+1] match_mint_orders(yesNonce, makerNonces[])
605
- *
606
- * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
600
+ * remaining_accounts per NO maker (5):
601
+ * [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
607
602
  */
608
603
  private matchMintOrders;
609
604
  /**
610
- * MERGE match: 1 YES seller (taker) + N NO sellers (makers).
611
- *
612
- * Transaction structure:
613
- * ix[0] Ed25519(taker/YES seller)
614
- * ix[1+i] Ed25519(maker_i/NO seller)
615
- * ix[N+1] match_merge_orders(yesNonce, makerNonces[])
605
+ * MERGE: 1 YES seller (taker) + N NO sellers (makers).
606
+ * Phase 1: register taker + all NO makers in parallel.
607
+ * Phase 2: 1 atomic match tx.
616
608
  *
617
- * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
609
+ * remaining_accounts per NO maker (5):
610
+ * [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
611
+ * After all makers, optional 5 fee accounts.
618
612
  */
619
613
  private matchMergeOrders;
620
614
  /**
621
- * Auto-detect match type and execute 1-taker + N-makers in a single transaction.
615
+ * Auto-detect match type and execute 2-phase:
616
+ * Phase 1 — register all orders (taker + makers) on-chain in parallel.
617
+ * Phase 2 — 1 atomic match transaction.
622
618
  *
623
- * Detection (pure, no RPC) based on taker.order vs makers[0].order:
624
- * taker.tokenId === makers[0].tokenId: taker BUY + all makers SELL → COMPLEMENTARY
625
- * taker.tokenId !== makers[0].tokenId + taker BUY + all makers BUYMINT
626
- * taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL MERGE
627
- * Otherwisethrows InvalidParamError
628
- *
629
- * All makers must have the same tokenId and side as makers[0].
630
- */
631
- /**
632
- * Auto-detect match type and execute in a single transaction.
633
- * ALT is managed automatically (created on first call per condition, cached thereafter).
634
- * feeRecipient and collateralMint are derived from on-chain config.
635
- * Fee distribution (distribute_fee CPI) fires automatically when order.fee > 0.
619
+ * Detection (pure, no RPC):
620
+ * taker.tokenId === makers[0].tokenId:
621
+ * taker BUY + all makers SELLCOMPLEMENTARY
622
+ * taker.tokenId !== makers[0].tokenId + all BUY MINT
623
+ * taker.tokenId !== makers[0].tokenId + all SELL MERGE
636
624
  *
637
- * @param opts.marketOracleVault Required for presale markets (is_admin=false).
638
- * Pass the ATA of the market_oracle PDA so 50% of fee goes there.
639
- * For admin markets (is_admin=true) omit — payer is used as placeholder (no transfer).
625
+ * @param opts.marketOracleVault Oracle vault ATA for presale markets.
626
+ * Omit for admin markets (payer used as placeholder).
640
627
  */
641
628
  matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
642
629
  marketOracleVault?: PublicKey;
643
630
  }): Promise<TxResult>;
644
631
  fetchConfig(): Promise<ClobConfig | null>;
645
632
  fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
633
+ fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
634
+ maker: PublicKey;
635
+ condition: PublicKey;
636
+ tokenId: number;
637
+ side: number;
638
+ makerAmount: anchor.BN;
639
+ takerAmount: anchor.BN;
640
+ nonce: anchor.BN;
641
+ expiry: anchor.BN;
642
+ fee: anchor.BN;
643
+ taker: PublicKey;
644
+ signer: PublicKey;
645
+ } | null>;
646
646
  }
647
647
 
648
648
  interface PresaleInfo {
@@ -802,6 +802,7 @@ declare class PDA {
802
802
  static extraAccountMetaList(mint: PublicKey, programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
803
803
  static clobConfig(programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
804
804
  static orderStatus(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
805
+ static orderRecord(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
805
806
  static feeConfig(owner: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
806
807
  static questionFee(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
807
808
  static marketFeeOverride(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];