@theliem/xmarket-sdk 1.0.12 → 3.0.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.
@@ -816,27 +816,7 @@
816
816
  "writable": true
817
817
  },
818
818
  {
819
- "name": "clob_authority",
820
- "pda": {
821
- "seeds": [
822
- {
823
- "kind": "const",
824
- "value": [
825
- 99,
826
- 108,
827
- 111,
828
- 98,
829
- 95,
830
- 99,
831
- 111,
832
- 110,
833
- 102,
834
- 105,
835
- 103
836
- ]
837
- }
838
- ]
839
- }
819
+ "name": "fee_recipient"
840
820
  },
841
821
  {
842
822
  "name": "conditional_tokens_program",
@@ -1055,27 +1035,7 @@
1055
1035
  "writable": true
1056
1036
  },
1057
1037
  {
1058
- "name": "clob_authority",
1059
- "pda": {
1060
- "seeds": [
1061
- {
1062
- "kind": "const",
1063
- "value": [
1064
- 99,
1065
- 108,
1066
- 111,
1067
- 98,
1068
- 95,
1069
- 99,
1070
- 111,
1071
- 110,
1072
- 102,
1073
- 105,
1074
- 103
1075
- ]
1076
- }
1077
- ]
1078
- }
1038
+ "name": "fee_recipient"
1079
1039
  },
1080
1040
  {
1081
1041
  "name": "conditional_tokens_program",
@@ -1589,10 +1549,6 @@
1589
1549
  {
1590
1550
  "name": "usdc_transferred",
1591
1551
  "type": "u64"
1592
- },
1593
- {
1594
- "name": "fee",
1595
- "type": "u64"
1596
1552
  }
1597
1553
  ]
1598
1554
  }
package/dist/index.d.mts CHANGED
@@ -12,7 +12,7 @@ interface ProgramIds {
12
12
  }
13
13
  interface CollateralConfig {
14
14
  mint: PublicKey;
15
- /** Token decimals (USDC = 6) */
15
+ /** Token decimals */
16
16
  decimals: number;
17
17
  }
18
18
  interface NetworkConfig {
@@ -21,11 +21,7 @@ interface NetworkConfig {
21
21
  programIds: ProgramIds;
22
22
  defaultCollateral: CollateralConfig;
23
23
  }
24
- type NetworkName = "devnet" | "localnet" | "mainnet";
25
- declare const DEVNET_CONFIG: NetworkConfig;
26
- declare const LOCALNET_CONFIG: NetworkConfig;
27
- declare const MAINNET_CONFIG: NetworkConfig;
28
- declare const NETWORK_CONFIGS: Record<NetworkName, NetworkConfig>;
24
+ type NetworkName = string;
29
25
 
30
26
  interface TxResult {
31
27
  signature: string;
@@ -169,8 +165,8 @@ interface OrderStatus {
169
165
  * Operator validates + submits matched order pairs on-chain.
170
166
  *
171
167
  * Semantics (mirrors EVM makerAmount/takerAmount):
172
- * BUY (side=1): makerAmount = USDC paid, takerAmount = CTF tokens received
173
- * SELL (side=0): makerAmount = CTF tokens given, takerAmount = USDC received
168
+ * BUY (side=0): makerAmount = USDC paid, takerAmount = CTF tokens received
169
+ * SELL (side=1): makerAmount = CTF tokens given, takerAmount = USDC received
174
170
  */
175
171
  interface Order {
176
172
  /** Maker's wallet public key */
@@ -179,7 +175,7 @@ interface Order {
179
175
  condition: PublicKey;
180
176
  /** Outcome token: 0 = NO, 1 = YES */
181
177
  tokenId: number;
182
- /** Side: 0 = SELL (give tokens, want USDC), 1 = BUY (give USDC, want tokens) */
178
+ /** Side: 0 = BUY (give USDC, want tokens), 1 = SELL (give tokens, want USDC) — matches EVM convention */
183
179
  side: number;
184
180
  /** Amount the maker puts in: BUY → USDC, SELL → CTF tokens */
185
181
  makerAmount: BN;
@@ -191,7 +187,7 @@ interface Order {
191
187
  expiry: BN;
192
188
  /** Creation timestamp (Unix seconds) */
193
189
  createdAt: BN;
194
- /** Fee from taker order transferred to treasury. 0 = use global fee_rate_bps */
190
+ /** Fixed USDC amount (9 decimals) taker pays to treasury after all fills. 0 = no fee. Set by operator off-chain. */
195
191
  fee: BN;
196
192
  /** Directed order: only this pubkey can be counterparty. PublicKey.default() = public */
197
193
  taker: PublicKey;
@@ -552,45 +548,8 @@ declare class ClobClient {
552
548
  isOrderCancelled(maker: PublicKey, nonce: anchor.BN): Promise<boolean>;
553
549
  }
554
550
 
555
- interface XMarketSDKConfig {
556
- /**
557
- * Network to connect to.
558
- * - `"devnet"` — public devnet, programs deployed
559
- * - `"localnet"` — local test validator (same program IDs as devnet)
560
- * - `"mainnet"` — mainnet-beta (hook + clob IDs TBD)
561
- * - `NetworkConfig` — fully custom config
562
- */
563
- network: NetworkName | NetworkConfig;
564
- wallet: anchor.Wallet;
565
- /**
566
- * Owner public key used to derive QuestionMarket + Oracle config PDAs.
567
- * Defaults to wallet pubkey.
568
- */
569
- marketOwner?: PublicKey;
570
- }
571
- /**
572
- * Top-level SDK entry point.
573
- *
574
- * ```ts
575
- * // Quickstart: devnet
576
- * const sdk = XMarketSDK.devnet(wallet);
577
- *
578
- * // Create a question market
579
- * await sdk.market.createQuestion({ content: "...", ... }, oraclePubkey);
580
- *
581
- * // Split collateral into YES + NO tokens
582
- * await sdk.ctf.splitPosition(conditionPda, usdcMint, new BN(100_000));
583
- *
584
- * // Match orders on the CLOB
585
- * await sdk.clob.matchMintOrders(yesOrder, noOrder, fillAmount, usdcMint);
586
- *
587
- * // Inspect active network config
588
- * console.log(sdk.networkConfig.name, sdk.networkConfig.programIds);
589
- * ```
590
- */
591
551
  declare class XMarketSDK {
592
552
  readonly provider: anchor.AnchorProvider;
593
- /** Active network configuration (program IDs, RPC, collateral) */
594
553
  readonly networkConfig: NetworkConfig;
595
554
  private readonly _programIds;
596
555
  private readonly _marketOwner;
@@ -599,51 +558,13 @@ declare class XMarketSDK {
599
558
  private _market?;
600
559
  private _ctf?;
601
560
  private _clob?;
602
- constructor(config: XMarketSDKConfig);
561
+ constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
603
562
  private _withAddress;
604
- /** Oracle program client */
605
563
  get oracle(): OracleClient;
606
- /** Transfer-hook program client */
607
564
  get hook(): HookClient;
608
- /** QuestionMarket program client */
609
565
  get market(): MarketClient;
610
- /** Conditional tokens (CTF) program client */
611
566
  get ctf(): CtfClient;
612
- /** CLOB exchange program client */
613
567
  get clob(): ClobClient;
614
- /**
615
- * Connect to devnet.
616
- * ```ts
617
- * const sdk = XMarketSDK.devnet(wallet);
618
- * ```
619
- */
620
- static devnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
621
- /**
622
- * Connect to localhost test validator.
623
- * ```ts
624
- * const sdk = XMarketSDK.localnet(wallet);
625
- * ```
626
- */
627
- static localnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
628
- /**
629
- * Connect to mainnet-beta.
630
- * ```ts
631
- * const sdk = XMarketSDK.mainnet(wallet);
632
- * ```
633
- */
634
- static mainnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
635
- /**
636
- * Custom network (e.g. custom RPC, custom program IDs for a fork).
637
- * ```ts
638
- * const sdk = XMarketSDK.custom({
639
- * name: "staging",
640
- * rpcUrl: "https://my-rpc.com",
641
- * programIds: { ... },
642
- * defaultCollateral: { mint: ..., decimals: 6 },
643
- * }, wallet);
644
- * ```
645
- */
646
- static custom(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
647
568
  }
648
569
 
649
570
  declare const SEEDS: {
@@ -815,4 +736,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
815
736
  */
816
737
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
817
738
 
818
- export { AccountNotFoundError, ClobClient, type ClobConfig, type ClobWhitelistEntry, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DEVNET_CONFIG, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, LOCALNET_CONFIG, MAINNET_CONFIG, MAX_APPROVE_AMOUNT, MarketClient, type MatchType, NETWORK_CONFIGS, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, type ProgramIds, type Question, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, XMarketError, XMarketSDK, type XMarketSDKConfig, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
739
+ export { AccountNotFoundError, ClobClient, type ClobConfig, type ClobWhitelistEntry, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, type ProgramIds, type Question, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.d.ts CHANGED
@@ -12,7 +12,7 @@ interface ProgramIds {
12
12
  }
13
13
  interface CollateralConfig {
14
14
  mint: PublicKey;
15
- /** Token decimals (USDC = 6) */
15
+ /** Token decimals */
16
16
  decimals: number;
17
17
  }
18
18
  interface NetworkConfig {
@@ -21,11 +21,7 @@ interface NetworkConfig {
21
21
  programIds: ProgramIds;
22
22
  defaultCollateral: CollateralConfig;
23
23
  }
24
- type NetworkName = "devnet" | "localnet" | "mainnet";
25
- declare const DEVNET_CONFIG: NetworkConfig;
26
- declare const LOCALNET_CONFIG: NetworkConfig;
27
- declare const MAINNET_CONFIG: NetworkConfig;
28
- declare const NETWORK_CONFIGS: Record<NetworkName, NetworkConfig>;
24
+ type NetworkName = string;
29
25
 
30
26
  interface TxResult {
31
27
  signature: string;
@@ -169,8 +165,8 @@ interface OrderStatus {
169
165
  * Operator validates + submits matched order pairs on-chain.
170
166
  *
171
167
  * Semantics (mirrors EVM makerAmount/takerAmount):
172
- * BUY (side=1): makerAmount = USDC paid, takerAmount = CTF tokens received
173
- * SELL (side=0): makerAmount = CTF tokens given, takerAmount = USDC received
168
+ * BUY (side=0): makerAmount = USDC paid, takerAmount = CTF tokens received
169
+ * SELL (side=1): makerAmount = CTF tokens given, takerAmount = USDC received
174
170
  */
175
171
  interface Order {
176
172
  /** Maker's wallet public key */
@@ -179,7 +175,7 @@ interface Order {
179
175
  condition: PublicKey;
180
176
  /** Outcome token: 0 = NO, 1 = YES */
181
177
  tokenId: number;
182
- /** Side: 0 = SELL (give tokens, want USDC), 1 = BUY (give USDC, want tokens) */
178
+ /** Side: 0 = BUY (give USDC, want tokens), 1 = SELL (give tokens, want USDC) — matches EVM convention */
183
179
  side: number;
184
180
  /** Amount the maker puts in: BUY → USDC, SELL → CTF tokens */
185
181
  makerAmount: BN;
@@ -191,7 +187,7 @@ interface Order {
191
187
  expiry: BN;
192
188
  /** Creation timestamp (Unix seconds) */
193
189
  createdAt: BN;
194
- /** Fee from taker order transferred to treasury. 0 = use global fee_rate_bps */
190
+ /** Fixed USDC amount (9 decimals) taker pays to treasury after all fills. 0 = no fee. Set by operator off-chain. */
195
191
  fee: BN;
196
192
  /** Directed order: only this pubkey can be counterparty. PublicKey.default() = public */
197
193
  taker: PublicKey;
@@ -552,45 +548,8 @@ declare class ClobClient {
552
548
  isOrderCancelled(maker: PublicKey, nonce: anchor.BN): Promise<boolean>;
553
549
  }
554
550
 
555
- interface XMarketSDKConfig {
556
- /**
557
- * Network to connect to.
558
- * - `"devnet"` — public devnet, programs deployed
559
- * - `"localnet"` — local test validator (same program IDs as devnet)
560
- * - `"mainnet"` — mainnet-beta (hook + clob IDs TBD)
561
- * - `NetworkConfig` — fully custom config
562
- */
563
- network: NetworkName | NetworkConfig;
564
- wallet: anchor.Wallet;
565
- /**
566
- * Owner public key used to derive QuestionMarket + Oracle config PDAs.
567
- * Defaults to wallet pubkey.
568
- */
569
- marketOwner?: PublicKey;
570
- }
571
- /**
572
- * Top-level SDK entry point.
573
- *
574
- * ```ts
575
- * // Quickstart: devnet
576
- * const sdk = XMarketSDK.devnet(wallet);
577
- *
578
- * // Create a question market
579
- * await sdk.market.createQuestion({ content: "...", ... }, oraclePubkey);
580
- *
581
- * // Split collateral into YES + NO tokens
582
- * await sdk.ctf.splitPosition(conditionPda, usdcMint, new BN(100_000));
583
- *
584
- * // Match orders on the CLOB
585
- * await sdk.clob.matchMintOrders(yesOrder, noOrder, fillAmount, usdcMint);
586
- *
587
- * // Inspect active network config
588
- * console.log(sdk.networkConfig.name, sdk.networkConfig.programIds);
589
- * ```
590
- */
591
551
  declare class XMarketSDK {
592
552
  readonly provider: anchor.AnchorProvider;
593
- /** Active network configuration (program IDs, RPC, collateral) */
594
553
  readonly networkConfig: NetworkConfig;
595
554
  private readonly _programIds;
596
555
  private readonly _marketOwner;
@@ -599,51 +558,13 @@ declare class XMarketSDK {
599
558
  private _market?;
600
559
  private _ctf?;
601
560
  private _clob?;
602
- constructor(config: XMarketSDKConfig);
561
+ constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
603
562
  private _withAddress;
604
- /** Oracle program client */
605
563
  get oracle(): OracleClient;
606
- /** Transfer-hook program client */
607
564
  get hook(): HookClient;
608
- /** QuestionMarket program client */
609
565
  get market(): MarketClient;
610
- /** Conditional tokens (CTF) program client */
611
566
  get ctf(): CtfClient;
612
- /** CLOB exchange program client */
613
567
  get clob(): ClobClient;
614
- /**
615
- * Connect to devnet.
616
- * ```ts
617
- * const sdk = XMarketSDK.devnet(wallet);
618
- * ```
619
- */
620
- static devnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
621
- /**
622
- * Connect to localhost test validator.
623
- * ```ts
624
- * const sdk = XMarketSDK.localnet(wallet);
625
- * ```
626
- */
627
- static localnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
628
- /**
629
- * Connect to mainnet-beta.
630
- * ```ts
631
- * const sdk = XMarketSDK.mainnet(wallet);
632
- * ```
633
- */
634
- static mainnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
635
- /**
636
- * Custom network (e.g. custom RPC, custom program IDs for a fork).
637
- * ```ts
638
- * const sdk = XMarketSDK.custom({
639
- * name: "staging",
640
- * rpcUrl: "https://my-rpc.com",
641
- * programIds: { ... },
642
- * defaultCollateral: { mint: ..., decimals: 6 },
643
- * }, wallet);
644
- * ```
645
- */
646
- static custom(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
647
568
  }
648
569
 
649
570
  declare const SEEDS: {
@@ -815,4 +736,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
815
736
  */
816
737
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
817
738
 
818
- export { AccountNotFoundError, ClobClient, type ClobConfig, type ClobWhitelistEntry, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DEVNET_CONFIG, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, LOCALNET_CONFIG, MAINNET_CONFIG, MAX_APPROVE_AMOUNT, MarketClient, type MatchType, NETWORK_CONFIGS, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, type ProgramIds, type Question, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, XMarketError, XMarketSDK, type XMarketSDKConfig, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
739
+ export { AccountNotFoundError, ClobClient, type ClobConfig, type ClobWhitelistEntry, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, type ProgramIds, type Question, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ var oracleIdl = require('./oracle-FZJJIJGI.json');
8
8
  var hookIdl = require('./hook-THBRGUM6.json');
9
9
  var questionMarketIdl = require('./question_market-CB6ZUZ5E.json');
10
10
  var conditionalTokensIdl = require('./conditional_tokens-3O5V46N5.json');
11
- var clobExchangeIdl = require('./clob_exchange-ATSH42KC.json');
11
+ var clobExchangeIdl = require('./clob_exchange-MQF4NI27.json');
12
12
  var BN4 = require('bn.js');
13
13
  var nacl = require('tweetnacl');
14
14
 
@@ -42,53 +42,6 @@ var BN4__default = /*#__PURE__*/_interopDefault(BN4);
42
42
  var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
43
43
 
44
44
  // src/sdk.ts
45
- var DEVNET_CONFIG = {
46
- name: "devnet",
47
- rpcUrl: "https://api.devnet.solana.com",
48
- programIds: {
49
- oracle: new web3_js.PublicKey("FzLnnbKtQCTKviEbrDYMLZYXNDHQdjSSa4Ybj4jAbrUL"),
50
- conditionalTokens: new web3_js.PublicKey("A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"),
51
- questionMarket: new web3_js.PublicKey("FCvCbWoLpzNYKzQnXYXCo1yz9DTpgUs11QqHVqnqtWhA"),
52
- hook: new web3_js.PublicKey("F7y5MfW8d5kqR25QHDhUQ9LrKCiZUZVF6Pdnw15q5zZW"),
53
- clobExchange: new web3_js.PublicKey("Cs4GY1yZVxjxhhyUum3AupMuS3bo4yKRXifgLTTAh1sf")
54
- },
55
- defaultCollateral: {
56
- mint: new web3_js.PublicKey("53osACZSom79AHf6nK4eq8DL6viMZmyVERYPDB6S6Eck"),
57
- decimals: 9
58
- }
59
- };
60
- var LOCALNET_CONFIG = {
61
- name: "localnet",
62
- rpcUrl: "http://localhost:8899",
63
- programIds: { ...DEVNET_CONFIG.programIds },
64
- defaultCollateral: {
65
- mint: new web3_js.PublicKey("6Gk4qsruSjunenwzP4L5DQukawfVNvdr9rPX2qG77jmH"),
66
- decimals: 6
67
- }
68
- };
69
- var MAINNET_CONFIG = {
70
- name: "mainnet",
71
- rpcUrl: "https://api.mainnet-beta.solana.com",
72
- programIds: {
73
- oracle: new web3_js.PublicKey("E667trvbHmZEnptjnjXp9x8e1Fpji3viHo1J1DGPKijh"),
74
- conditionalTokens: new web3_js.PublicKey("3WFSX7zPLrJSU811h7awgqXTZuKhUR1Fi1VBDayHhk4s"),
75
- questionMarket: new web3_js.PublicKey("GiQh2xBmEiM4gYq4U9PMSaUJNq1T9TfEJL5cXvNYhtGm"),
76
- hook: new web3_js.PublicKey("11111111111111111111111111111111"),
77
- // not yet deployed
78
- clobExchange: new web3_js.PublicKey("11111111111111111111111111111111")
79
- // not yet deployed
80
- },
81
- defaultCollateral: {
82
- mint: new web3_js.PublicKey("EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"),
83
- // USDC mainnet
84
- decimals: 6
85
- }
86
- };
87
- var NETWORK_CONFIGS = {
88
- devnet: DEVNET_CONFIG,
89
- localnet: LOCALNET_CONFIG,
90
- mainnet: MAINNET_CONFIG
91
- };
92
45
  var SEEDS = {
93
46
  config: Buffer.from("config"),
94
47
  question: Buffer.from("question"),
@@ -1322,14 +1275,13 @@ var ClobClient = class {
1322
1275
  *
1323
1276
  * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
1324
1277
  */
1325
- async matchMintOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
1278
+ async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
1326
1279
  const condition = yesSigned.order.condition;
1327
1280
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1328
1281
  const [noMint] = PDA.noMint(condition, this.programIds);
1329
1282
  const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1330
1283
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1331
1284
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1332
- const [clobAuthority] = PDA.clobConfig(this.programIds);
1333
1285
  const buyerYes = yesSigned.order.maker;
1334
1286
  const buyerYesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, buyerYes);
1335
1287
  const buyerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, buyerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
@@ -1372,12 +1324,19 @@ var ClobClient = class {
1372
1324
  yesMint,
1373
1325
  noMint,
1374
1326
  mintAuthority,
1375
- clobAuthority,
1327
+ feeRecipient,
1376
1328
  conditionalTokensProgram: this.programIds.conditionalTokens,
1377
1329
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1378
1330
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1379
1331
  systemProgram: web3_js.SystemProgram.programId
1380
1332
  }).remainingAccounts(makerAccounts).instruction();
1333
+ const frKey = feeRecipient.toBase58();
1334
+ for (const k of matchIx.keys) {
1335
+ if (k.pubkey.toBase58() === frKey) {
1336
+ k.isWritable = true;
1337
+ break;
1338
+ }
1339
+ }
1381
1340
  const sig = await this._sendMatchTx(
1382
1341
  [...ed25519Ixs, matchIx],
1383
1342
  lookupTable,
@@ -1395,13 +1354,12 @@ var ClobClient = class {
1395
1354
  *
1396
1355
  * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
1397
1356
  */
1398
- async matchMergeOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
1357
+ async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
1399
1358
  const condition = yesSigned.order.condition;
1400
1359
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1401
1360
  const [noMint] = PDA.noMint(condition, this.programIds);
1402
1361
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1403
1362
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1404
- const [clobAuthority] = PDA.clobConfig(this.programIds);
1405
1363
  const sellerYes = yesSigned.order.maker;
1406
1364
  const sellerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, sellerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1407
1365
  const [sellerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
@@ -1443,12 +1401,19 @@ var ClobClient = class {
1443
1401
  vaultTokenAccount,
1444
1402
  yesMint,
1445
1403
  noMint,
1446
- clobAuthority,
1404
+ feeRecipient,
1447
1405
  conditionalTokensProgram: this.programIds.conditionalTokens,
1448
1406
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1449
1407
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1450
1408
  systemProgram: web3_js.SystemProgram.programId
1451
1409
  }).remainingAccounts(makerAccounts).instruction();
1410
+ const frKeyM = feeRecipient.toBase58();
1411
+ for (const k of matchIx.keys) {
1412
+ if (k.pubkey.toBase58() === frKeyM) {
1413
+ k.isWritable = true;
1414
+ break;
1415
+ }
1416
+ }
1452
1417
  const sig = await this._sendMatchTx(
1453
1418
  [...ed25519Ixs, matchIx],
1454
1419
  lookupTable,
@@ -1471,8 +1436,8 @@ var ClobClient = class {
1471
1436
  if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
1472
1437
  const t = taker.order;
1473
1438
  const m0 = makers[0].order;
1474
- const SIDE_BUY = 1;
1475
- const SIDE_SELL = 0;
1439
+ const SIDE_BUY = 0;
1440
+ const SIDE_SELL = 1;
1476
1441
  if (t.tokenId === m0.tokenId) {
1477
1442
  if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
1478
1443
  return this.matchComplementary(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
@@ -1494,9 +1459,9 @@ var ClobClient = class {
1494
1459
  throw new InvalidParamError("MINT/MERGE: all makers must be the NO side (tokenId=0)");
1495
1460
  }
1496
1461
  if (allBuy) {
1497
- return this.matchMintOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
1462
+ return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
1498
1463
  }
1499
- return this.matchMergeOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
1464
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
1500
1465
  }
1501
1466
  // ─── Whitelist admin ─────────────────────────────────────────────────────────
1502
1467
  /** Add an address to the CLOB whitelist (owner only). */
@@ -1595,23 +1560,21 @@ var ClobClient = class {
1595
1560
  return status?.isCancelled === true;
1596
1561
  }
1597
1562
  };
1598
- var XMarketSDK = class _XMarketSDK {
1599
- constructor(config) {
1600
- this.networkConfig = typeof config.network === "string" ? NETWORK_CONFIGS[config.network] : config.network;
1563
+ var XMarketSDK = class {
1564
+ constructor(config, wallet, marketOwner) {
1565
+ this.networkConfig = config;
1601
1566
  this.provider = new anchor4__namespace.AnchorProvider(
1602
- new web3_js.Connection(this.networkConfig.rpcUrl, "confirmed"),
1603
- config.wallet,
1567
+ new web3_js.Connection(config.rpcUrl, "confirmed"),
1568
+ wallet,
1604
1569
  { commitment: "confirmed", preflightCommitment: "confirmed" }
1605
1570
  );
1606
1571
  anchor4__namespace.setProvider(this.provider);
1607
- this._programIds = this.networkConfig.programIds;
1608
- this._marketOwner = config.marketOwner ?? config.wallet.publicKey;
1572
+ this._programIds = config.programIds;
1573
+ this._marketOwner = marketOwner ?? wallet.publicKey;
1609
1574
  }
1610
- // ─── Lazy-initialised clients ─────────────────────────────────────────────
1611
1575
  _withAddress(idl, address) {
1612
1576
  return { ...idl, address: address.toBase58() };
1613
1577
  }
1614
- /** Oracle program client */
1615
1578
  get oracle() {
1616
1579
  if (!this._oracle) {
1617
1580
  const program = new anchor4__namespace.Program(this._withAddress(oracleIdl__default.default, this._programIds.oracle), this.provider);
@@ -1619,7 +1582,6 @@ var XMarketSDK = class _XMarketSDK {
1619
1582
  }
1620
1583
  return this._oracle;
1621
1584
  }
1622
- /** Transfer-hook program client */
1623
1585
  get hook() {
1624
1586
  if (!this._hook) {
1625
1587
  const program = new anchor4__namespace.Program(this._withAddress(hookIdl__default.default, this._programIds.hook), this.provider);
@@ -1627,7 +1589,6 @@ var XMarketSDK = class _XMarketSDK {
1627
1589
  }
1628
1590
  return this._hook;
1629
1591
  }
1630
- /** QuestionMarket program client */
1631
1592
  get market() {
1632
1593
  if (!this._market) {
1633
1594
  const program = new anchor4__namespace.Program(this._withAddress(questionMarketIdl__default.default, this._programIds.questionMarket), this.provider);
@@ -1636,7 +1597,6 @@ var XMarketSDK = class _XMarketSDK {
1636
1597
  }
1637
1598
  return this._market;
1638
1599
  }
1639
- /** Conditional tokens (CTF) program client */
1640
1600
  get ctf() {
1641
1601
  if (!this._ctf) {
1642
1602
  const program = new anchor4__namespace.Program(this._withAddress(conditionalTokensIdl__default.default, this._programIds.conditionalTokens), this.provider);
@@ -1644,7 +1604,6 @@ var XMarketSDK = class _XMarketSDK {
1644
1604
  }
1645
1605
  return this._ctf;
1646
1606
  }
1647
- /** CLOB exchange program client */
1648
1607
  get clob() {
1649
1608
  if (!this._clob) {
1650
1609
  const program = new anchor4__namespace.Program(this._withAddress(clobExchangeIdl__default.default, this._programIds.clobExchange), this.provider);
@@ -1652,48 +1611,6 @@ var XMarketSDK = class _XMarketSDK {
1652
1611
  }
1653
1612
  return this._clob;
1654
1613
  }
1655
- // ─── Factory helpers ──────────────────────────────────────────────────────
1656
- /**
1657
- * Connect to devnet.
1658
- * ```ts
1659
- * const sdk = XMarketSDK.devnet(wallet);
1660
- * ```
1661
- */
1662
- static devnet(wallet, marketOwner) {
1663
- return new _XMarketSDK({ network: "devnet", wallet, marketOwner });
1664
- }
1665
- /**
1666
- * Connect to localhost test validator.
1667
- * ```ts
1668
- * const sdk = XMarketSDK.localnet(wallet);
1669
- * ```
1670
- */
1671
- static localnet(wallet, marketOwner) {
1672
- return new _XMarketSDK({ network: "localnet", wallet, marketOwner });
1673
- }
1674
- /**
1675
- * Connect to mainnet-beta.
1676
- * ```ts
1677
- * const sdk = XMarketSDK.mainnet(wallet);
1678
- * ```
1679
- */
1680
- static mainnet(wallet, marketOwner) {
1681
- return new _XMarketSDK({ network: "mainnet", wallet, marketOwner });
1682
- }
1683
- /**
1684
- * Custom network (e.g. custom RPC, custom program IDs for a fork).
1685
- * ```ts
1686
- * const sdk = XMarketSDK.custom({
1687
- * name: "staging",
1688
- * rpcUrl: "https://my-rpc.com",
1689
- * programIds: { ... },
1690
- * defaultCollateral: { mint: ..., decimals: 6 },
1691
- * }, wallet);
1692
- * ```
1693
- */
1694
- static custom(config, wallet, marketOwner) {
1695
- return new _XMarketSDK({ network: config, wallet, marketOwner });
1696
- }
1697
1614
  };
1698
1615
  function buildOrder(params) {
1699
1616
  return {
@@ -1762,7 +1679,7 @@ function detectMatchType(a, b) {
1762
1679
  return _detectMatchType(_a, _b);
1763
1680
  }
1764
1681
  function _detectMatchType(a, b) {
1765
- const SIDE_BUY = 1;
1682
+ const SIDE_BUY = 0;
1766
1683
  if (a.tokenId === b.tokenId) {
1767
1684
  const aBuy2 = a.side === SIDE_BUY;
1768
1685
  const bBuy2 = b.side === SIDE_BUY;
@@ -1826,15 +1743,11 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
1826
1743
  exports.AccountNotFoundError = AccountNotFoundError;
1827
1744
  exports.ClobClient = ClobClient;
1828
1745
  exports.CtfClient = CtfClient;
1829
- exports.DEVNET_CONFIG = DEVNET_CONFIG;
1830
1746
  exports.HookClient = HookClient;
1831
1747
  exports.IX_SYSVAR = IX_SYSVAR;
1832
1748
  exports.InvalidParamError = InvalidParamError;
1833
- exports.LOCALNET_CONFIG = LOCALNET_CONFIG;
1834
- exports.MAINNET_CONFIG = MAINNET_CONFIG;
1835
1749
  exports.MAX_APPROVE_AMOUNT = MAX_APPROVE_AMOUNT;
1836
1750
  exports.MarketClient = MarketClient;
1837
- exports.NETWORK_CONFIGS = NETWORK_CONFIGS;
1838
1751
  exports.OracleClient = OracleClient;
1839
1752
  exports.PDA = PDA;
1840
1753
  exports.QuestionStatus = QuestionStatus;