@theliem/xmarket-sdk 3.0.0 → 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
@@ -165,8 +165,8 @@ interface OrderStatus {
165
165
  * Operator validates + submits matched order pairs on-chain.
166
166
  *
167
167
  * Semantics (mirrors EVM makerAmount/takerAmount):
168
- * BUY (side=1): makerAmount = USDC paid, takerAmount = CTF tokens received
169
- * 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
170
170
  */
171
171
  interface Order {
172
172
  /** Maker's wallet public key */
@@ -175,7 +175,7 @@ interface Order {
175
175
  condition: PublicKey;
176
176
  /** Outcome token: 0 = NO, 1 = YES */
177
177
  tokenId: number;
178
- /** 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 */
179
179
  side: number;
180
180
  /** Amount the maker puts in: BUY → USDC, SELL → CTF tokens */
181
181
  makerAmount: BN;
@@ -187,7 +187,7 @@ interface Order {
187
187
  expiry: BN;
188
188
  /** Creation timestamp (Unix seconds) */
189
189
  createdAt: BN;
190
- /** 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. */
191
191
  fee: BN;
192
192
  /** Directed order: only this pubkey can be counterparty. PublicKey.default() = public */
193
193
  taker: PublicKey;
package/dist/index.d.ts CHANGED
@@ -165,8 +165,8 @@ interface OrderStatus {
165
165
  * Operator validates + submits matched order pairs on-chain.
166
166
  *
167
167
  * Semantics (mirrors EVM makerAmount/takerAmount):
168
- * BUY (side=1): makerAmount = USDC paid, takerAmount = CTF tokens received
169
- * 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
170
170
  */
171
171
  interface Order {
172
172
  /** Maker's wallet public key */
@@ -175,7 +175,7 @@ interface Order {
175
175
  condition: PublicKey;
176
176
  /** Outcome token: 0 = NO, 1 = YES */
177
177
  tokenId: number;
178
- /** 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 */
179
179
  side: number;
180
180
  /** Amount the maker puts in: BUY → USDC, SELL → CTF tokens */
181
181
  makerAmount: BN;
@@ -187,7 +187,7 @@ interface Order {
187
187
  expiry: BN;
188
188
  /** Creation timestamp (Unix seconds) */
189
189
  createdAt: BN;
190
- /** 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. */
191
191
  fee: BN;
192
192
  /** Directed order: only this pubkey can be counterparty. PublicKey.default() = public */
193
193
  taker: PublicKey;
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
 
@@ -1275,14 +1275,13 @@ var ClobClient = class {
1275
1275
  *
1276
1276
  * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
1277
1277
  */
1278
- async matchMintOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
1278
+ async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
1279
1279
  const condition = yesSigned.order.condition;
1280
1280
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1281
1281
  const [noMint] = PDA.noMint(condition, this.programIds);
1282
1282
  const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1283
1283
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1284
1284
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1285
- const [clobAuthority] = PDA.clobConfig(this.programIds);
1286
1285
  const buyerYes = yesSigned.order.maker;
1287
1286
  const buyerYesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, buyerYes);
1288
1287
  const buyerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, buyerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
@@ -1325,12 +1324,19 @@ var ClobClient = class {
1325
1324
  yesMint,
1326
1325
  noMint,
1327
1326
  mintAuthority,
1328
- clobAuthority,
1327
+ feeRecipient,
1329
1328
  conditionalTokensProgram: this.programIds.conditionalTokens,
1330
1329
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1331
1330
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1332
1331
  systemProgram: web3_js.SystemProgram.programId
1333
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
+ }
1334
1340
  const sig = await this._sendMatchTx(
1335
1341
  [...ed25519Ixs, matchIx],
1336
1342
  lookupTable,
@@ -1348,13 +1354,12 @@ var ClobClient = class {
1348
1354
  *
1349
1355
  * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
1350
1356
  */
1351
- async matchMergeOrders(yesSigned, makersSigned, collateralMint, whitelistedWallet, lookupTable) {
1357
+ async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, whitelistedWallet, lookupTable) {
1352
1358
  const condition = yesSigned.order.condition;
1353
1359
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1354
1360
  const [noMint] = PDA.noMint(condition, this.programIds);
1355
1361
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1356
1362
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1357
- const [clobAuthority] = PDA.clobConfig(this.programIds);
1358
1363
  const sellerYes = yesSigned.order.maker;
1359
1364
  const sellerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, sellerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1360
1365
  const [sellerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
@@ -1396,12 +1401,19 @@ var ClobClient = class {
1396
1401
  vaultTokenAccount,
1397
1402
  yesMint,
1398
1403
  noMint,
1399
- clobAuthority,
1404
+ feeRecipient,
1400
1405
  conditionalTokensProgram: this.programIds.conditionalTokens,
1401
1406
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1402
1407
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1403
1408
  systemProgram: web3_js.SystemProgram.programId
1404
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
+ }
1405
1417
  const sig = await this._sendMatchTx(
1406
1418
  [...ed25519Ixs, matchIx],
1407
1419
  lookupTable,
@@ -1424,8 +1436,8 @@ var ClobClient = class {
1424
1436
  if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
1425
1437
  const t = taker.order;
1426
1438
  const m0 = makers[0].order;
1427
- const SIDE_BUY = 1;
1428
- const SIDE_SELL = 0;
1439
+ const SIDE_BUY = 0;
1440
+ const SIDE_SELL = 1;
1429
1441
  if (t.tokenId === m0.tokenId) {
1430
1442
  if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
1431
1443
  return this.matchComplementary(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
@@ -1447,9 +1459,9 @@ var ClobClient = class {
1447
1459
  throw new InvalidParamError("MINT/MERGE: all makers must be the NO side (tokenId=0)");
1448
1460
  }
1449
1461
  if (allBuy) {
1450
- return this.matchMintOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
1462
+ return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
1451
1463
  }
1452
- return this.matchMergeOrders(taker, makers, collateralMint, whitelistedWallet, lookupTable);
1464
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, whitelistedWallet, lookupTable);
1453
1465
  }
1454
1466
  // ─── Whitelist admin ─────────────────────────────────────────────────────────
1455
1467
  /** Add an address to the CLOB whitelist (owner only). */
@@ -1667,7 +1679,7 @@ function detectMatchType(a, b) {
1667
1679
  return _detectMatchType(_a, _b);
1668
1680
  }
1669
1681
  function _detectMatchType(a, b) {
1670
- const SIDE_BUY = 1;
1682
+ const SIDE_BUY = 0;
1671
1683
  if (a.tokenId === b.tokenId) {
1672
1684
  const aBuy2 = a.side === SIDE_BUY;
1673
1685
  const bBuy2 = b.side === SIDE_BUY;