@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.js CHANGED
@@ -1,10 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var anchor4 = require('@coral-xyz/anchor');
3
+ var anchor5 = require('@coral-xyz/anchor');
4
4
  var web3_js = require('@solana/web3.js');
5
5
  var crypto = require('crypto');
6
6
  var splToken = require('@solana/spl-token');
7
- var BN4 = require('bn.js');
7
+ var BN5 = require('bn.js');
8
8
  var nacl = require('tweetnacl');
9
9
 
10
10
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -27,8 +27,8 @@ function _interopNamespace(e) {
27
27
  return Object.freeze(n);
28
28
  }
29
29
 
30
- var anchor4__namespace = /*#__PURE__*/_interopNamespace(anchor4);
31
- var BN4__default = /*#__PURE__*/_interopDefault(BN4);
30
+ var anchor5__namespace = /*#__PURE__*/_interopNamespace(anchor5);
31
+ var BN5__default = /*#__PURE__*/_interopDefault(BN5);
32
32
  var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
33
33
 
34
34
  // src/sdk.ts
@@ -171,6 +171,14 @@ var PDA = class {
171
171
  programIds.clobExchange
172
172
  );
173
173
  }
174
+ static orderRecord(maker, nonce, programIds) {
175
+ const nonceBuf = Buffer.alloc(8);
176
+ nonceBuf.writeBigUInt64LE(BigInt(nonce.toString()));
177
+ return web3_js.PublicKey.findProgramAddressSync(
178
+ [Buffer.from("order_record"), maker.toBuffer(), nonceBuf],
179
+ programIds.clobExchange
180
+ );
181
+ }
174
182
  // ─── Fee Management ─────────────────────────────────────────────────────────
175
183
  static feeConfig(owner, programIds) {
176
184
  if (!programIds.feeManagement) throw new Error("feeManagement program ID not configured");
@@ -299,7 +307,7 @@ var OracleClient = class {
299
307
  return this.program.methods.resolveQuestion(
300
308
  Array.from(questionId),
301
309
  outcomeCount,
302
- payoutNumerators.map((n) => new anchor4__namespace.BN(n))
310
+ payoutNumerators.map((n) => new anchor5__namespace.BN(n))
303
311
  ).accounts({
304
312
  reporter,
305
313
  oracleConfig,
@@ -566,7 +574,7 @@ var MarketClient = class {
566
574
  contentHash: Array.from(contentHash),
567
575
  hookProgram: params.hookProgram,
568
576
  authorizedClob: params.authorizedClob,
569
- expirationTime: new anchor4__namespace.BN(params.expirationTime)
577
+ expirationTime: new anchor5__namespace.BN(params.expirationTime)
570
578
  }).accounts({
571
579
  creator,
572
580
  payer,
@@ -634,6 +642,22 @@ var MarketClient = class {
634
642
  config: this.configPda
635
643
  }).transaction();
636
644
  }
645
+ async growConfig(owner = this.walletPubkey, payer = owner) {
646
+ return this.program.methods.growConfig().accounts({
647
+ payer,
648
+ owner,
649
+ config: this.configPda,
650
+ systemProgram: web3_js.SystemProgram.programId
651
+ }).transaction();
652
+ }
653
+ async restoreConfig(snapshot, owner = this.walletPubkey, payer = owner) {
654
+ return this.program.methods.restoreConfig(Array.from(snapshot)).accounts({
655
+ payer,
656
+ owner,
657
+ config: this.configPda,
658
+ systemProgram: web3_js.SystemProgram.programId
659
+ }).transaction();
660
+ }
637
661
  // ─── Queries ─────────────────────────────────────────────────────────────────
638
662
  async fetchConfig() {
639
663
  try {
@@ -1033,7 +1057,21 @@ var CtfClient = class {
1033
1057
  const userYesAta = splToken.getAssociatedTokenAddressSync(yesMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
1034
1058
  const userNoAta = splToken.getAssociatedTokenAddressSync(noMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
1035
1059
  const userCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, user);
1036
- return this.program.methods.redeemPositions().accounts({
1060
+ const createYesAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(
1061
+ payer,
1062
+ userYesAta,
1063
+ user,
1064
+ yesMint,
1065
+ splToken.TOKEN_2022_PROGRAM_ID
1066
+ );
1067
+ const createNoAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(
1068
+ payer,
1069
+ userNoAta,
1070
+ user,
1071
+ noMint,
1072
+ splToken.TOKEN_2022_PROGRAM_ID
1073
+ );
1074
+ const redeemIx = await this.program.methods.redeemPositions().accounts({
1037
1075
  user,
1038
1076
  payer,
1039
1077
  condition,
@@ -1049,14 +1087,17 @@ var CtfClient = class {
1049
1087
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
1050
1088
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1051
1089
  systemProgram: web3_js.SystemProgram.programId
1052
- }).transaction();
1090
+ }).instruction();
1091
+ const tx = new web3_js.Transaction();
1092
+ tx.add(createYesAtaIx, createNoAtaIx, redeemIx);
1093
+ return tx;
1053
1094
  }
1054
1095
  /**
1055
1096
  * Oracle directly resolves a condition with payout numerators.
1056
1097
  * Bypasses QuestionMarket — only for oracle-owned conditions.
1057
1098
  */
1058
1099
  async reportPayouts(condition, payoutNumerators) {
1059
- const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor4__namespace.BN(n))).accounts({
1100
+ const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor5__namespace.BN(n))).accounts({
1060
1101
  oracle: this.walletPubkey,
1061
1102
  condition
1062
1103
  }).rpc();
@@ -1287,57 +1328,60 @@ var ClobClient = class {
1287
1328
  }
1288
1329
  /**
1289
1330
  * Get or create an ALT for a condition.
1290
- * First call: creates + extends ALT on-chain, waits for activation (~2s).
1291
- * Subsequent calls for same condition: returns cached ALT instantly.
1292
- * BE devs never interact with this — called automatically by matchOrders.
1331
+ * Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
1293
1332
  */
1294
- async ensureAlt(condition, collateralMint, buyerPubkey, buyerNonce, makers) {
1333
+ async ensureAlt(condition, collateralMint, takerSigned, makers) {
1295
1334
  const cacheKey = condition.toBase58();
1296
1335
  if (this._altCache.has(cacheKey)) {
1297
1336
  return this._altCache.get(cacheKey);
1298
1337
  }
1299
1338
  const { connection } = this.provider;
1300
1339
  const payer = this.walletPubkey;
1340
+ const taker = takerSigned.order.maker;
1341
+ const takerNonce = takerSigned.order.nonce;
1342
+ const tokenId = takerSigned.order.tokenId;
1301
1343
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1344
+ const [noMint] = PDA.noMint(condition, this.programIds);
1302
1345
  const [extraAccountMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
1303
1346
  const [hookConfig] = PDA.hookConfig(this.programIds);
1304
- const [buyOrderStatus] = PDA.orderStatus(buyerPubkey, buyerNonce, this.programIds);
1305
- const [buyerPosition] = PDA.position(condition, 1, buyerPubkey, this.programIds);
1347
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1348
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1349
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1306
1350
  const clobConfigPda = this.configPda();
1351
+ const outcomeMint = tokenId === 1 ? yesMint : noMint;
1307
1352
  const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
1308
1353
  const addresses = [
1309
- // instruction program IDs — must be in ALT to keep static keys minimal
1310
1354
  web3_js.Ed25519Program.programId,
1311
1355
  this.programIds.clobExchange,
1312
- // other programs
1313
1356
  this.programIds.conditionalTokens,
1314
1357
  this.programIds.hook,
1315
1358
  splToken.TOKEN_PROGRAM_ID,
1316
1359
  splToken.TOKEN_2022_PROGRAM_ID,
1317
1360
  web3_js.SystemProgram.programId,
1318
1361
  web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
1319
- // config PDAs
1320
1362
  clobConfigPda,
1321
1363
  hookConfig,
1322
- // condition PDAs
1323
1364
  condition,
1324
1365
  yesMint,
1366
+ noMint,
1325
1367
  extraAccountMeta,
1326
- // buyer pubkey + ATAs + PDAs
1327
- buyerPubkey,
1328
- splToken.getAssociatedTokenAddressSync(collateralMint, buyerPubkey),
1329
- splToken.getAssociatedTokenAddressSync(yesMint, buyerPubkey, false, splToken.TOKEN_2022_PROGRAM_ID),
1330
- buyerPosition,
1331
- buyOrderStatus
1368
+ taker,
1369
+ splToken.getAssociatedTokenAddressSync(collateralMint, taker),
1370
+ splToken.getAssociatedTokenAddressSync(outcomeMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID),
1371
+ takerPosition,
1372
+ takerOrderStatus,
1373
+ takerOrderRecord
1332
1374
  ];
1333
1375
  if (feeRecipientAddr) addresses.push(feeRecipientAddr);
1334
1376
  for (const m of makers) {
1335
1377
  const seller = m.order.maker;
1336
- const [sellerPos] = PDA.position(condition, 1, seller, this.programIds);
1378
+ const [sellerPos] = PDA.position(condition, tokenId, seller, this.programIds);
1337
1379
  const [sellerStatus] = PDA.orderStatus(seller, m.order.nonce, this.programIds);
1380
+ const [sellerRecord] = PDA.orderRecord(seller, m.order.nonce, this.programIds);
1338
1381
  addresses.push(
1339
1382
  seller,
1340
- splToken.getAssociatedTokenAddressSync(yesMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID),
1383
+ sellerRecord,
1384
+ splToken.getAssociatedTokenAddressSync(outcomeMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID),
1341
1385
  splToken.getAssociatedTokenAddressSync(collateralMint, seller),
1342
1386
  sellerPos,
1343
1387
  sellerStatus
@@ -1385,7 +1429,7 @@ var ClobClient = class {
1385
1429
  }
1386
1430
  throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
1387
1431
  }
1388
- async _sendLegacyTx(instructions) {
1432
+ async _sendLegacyTxSig(instructions) {
1389
1433
  const { connection } = this.provider;
1390
1434
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1391
1435
  const { Transaction: Transaction7 } = await import('@solana/web3.js');
@@ -1394,25 +1438,33 @@ var ClobClient = class {
1394
1438
  tx.feePayer = this.walletPubkey;
1395
1439
  tx.add(...instructions);
1396
1440
  const signed = await this.provider.wallet.signTransaction(tx);
1397
- const sig = await connection.sendRawTransaction(signed.serialize());
1398
- await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, "confirmed");
1441
+ const sig = await connection.sendRawTransaction(signed.serialize(), { skipPreflight: true });
1442
+ const result = await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, "confirmed");
1443
+ if (result.value.err) {
1444
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1445
+ const logs = txInfo?.meta?.logMessages ?? [];
1446
+ const err = new Error(`Register tx failed: ${JSON.stringify(result.value.err)}
1447
+ ${logs.join("\n")}`);
1448
+ err.logs = logs;
1449
+ throw err;
1450
+ }
1451
+ return sig;
1452
+ }
1453
+ async _sendLegacyTx(instructions) {
1454
+ await this._sendLegacyTxSig(instructions);
1399
1455
  }
1400
1456
  /**
1401
- * Send a match transaction as versioned (v0).
1402
- * Pass a pre-built AddressLookupTableAccount to compress account keys and
1403
- * stay under the 1232-byte limit — required for match_complementary which
1404
- * has ~25 accounts + 2 Ed25519 precompile instructions (~1697 bytes raw).
1405
- *
1406
- * If `whitelistedWallet` is provided and differs from `this.provider.wallet`,
1407
- * both wallets sign the transaction (whitelisted operator + payer).
1457
+ * Send a match transaction as versioned (v0) with optional ALT.
1458
+ * Both operator wallet and payer (this.provider.wallet) sign.
1408
1459
  */
1409
1460
  async sendMatchTx(instructions, lookupTable, whitelistedWallet) {
1410
1461
  const { connection } = this.provider;
1411
1462
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1463
+ const cuLimit = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 8e5 });
1412
1464
  const message = new web3_js.TransactionMessage({
1413
1465
  payerKey: this.walletPubkey,
1414
1466
  recentBlockhash: blockhash,
1415
- instructions
1467
+ instructions: [cuLimit, ...instructions]
1416
1468
  }).compileToV0Message(lookupTable ? [lookupTable] : []);
1417
1469
  const vtx = new web3_js.VersionedTransaction(message);
1418
1470
  const signers = [this.provider.wallet.payer];
@@ -1421,19 +1473,67 @@ var ClobClient = class {
1421
1473
  }
1422
1474
  vtx.sign(signers);
1423
1475
  const sig = await connection.sendRawTransaction(vtx.serialize(), {
1424
- skipPreflight: false
1476
+ skipPreflight: true
1425
1477
  });
1426
- await connection.confirmTransaction(
1478
+ const result = await connection.confirmTransaction(
1427
1479
  { signature: sig, blockhash, lastValidBlockHeight },
1428
1480
  "confirmed"
1429
1481
  );
1482
+ if (result.value.err) {
1483
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1484
+ const logs = txInfo?.meta?.logMessages ?? [];
1485
+ const err = new Error(`Match tx failed: ${JSON.stringify(result.value.err)}
1486
+ ${logs.join("\n")}`);
1487
+ err.logs = logs;
1488
+ throw err;
1489
+ }
1430
1490
  return sig;
1431
1491
  }
1432
1492
  configPda() {
1433
1493
  return PDA.clobConfig(this.programIds)[0];
1434
1494
  }
1435
- // ─── Instructions ────────────────────────────────────────────────────────────
1436
- /** One-time setup. Caller becomes admin. */
1495
+ // ─── Register / Cancel ───────────────────────────────────────────────────────
1496
+ /**
1497
+ * Register a signed order on-chain.
1498
+ * Sends Ed25519 precompile ix + register_order ix in one legacy tx.
1499
+ * Called at match time (engine-triggered), not at order placement.
1500
+ */
1501
+ async registerOrder(signed) {
1502
+ const nonce = signed.order.nonce;
1503
+ const orderSigner = signed.order.maker;
1504
+ const [orderRecord] = PDA.orderRecord(orderSigner, nonce, this.programIds);
1505
+ const ed25519Ix = buildBatchedEd25519Instruction([signed]);
1506
+ const [orderStatus] = PDA.orderStatus(orderSigner, nonce, this.programIds);
1507
+ const registerIx = await this.program.methods.registerOrder(nonce).accounts({
1508
+ payer: this.walletPubkey,
1509
+ clobConfig: this.configPda(),
1510
+ ixSysvar: IX_SYSVAR,
1511
+ orderSigner,
1512
+ orderRecord,
1513
+ orderStatus,
1514
+ systemProgram: web3_js.SystemProgram.programId
1515
+ }).instruction();
1516
+ return this._sendLegacyTxSig([ed25519Ix, registerIx]);
1517
+ }
1518
+ /** Register only if the PDA doesn't exist yet (idempotent). */
1519
+ async registerOrderIfNeeded(signed) {
1520
+ const [pda] = PDA.orderRecord(signed.order.maker, signed.order.nonce, this.programIds);
1521
+ const existing = await this.program.account.signedOrderRecord.fetchNullable(pda);
1522
+ if (!existing) {
1523
+ await this.registerOrder(signed);
1524
+ }
1525
+ }
1526
+ /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
1527
+ async cancelOrder(nonce) {
1528
+ const [orderRecord] = PDA.orderRecord(this.walletPubkey, nonce, this.programIds);
1529
+ const sig = await this.program.methods.cancelOrder(nonce).accounts({
1530
+ maker: this.walletPubkey,
1531
+ orderRecord,
1532
+ systemProgram: web3_js.SystemProgram.programId
1533
+ }).rpc();
1534
+ return { signature: sig };
1535
+ }
1536
+ // ─── Admin ───────────────────────────────────────────────────────────────────
1437
1537
  async initialize(operators, feeRecipient, feeRateBps) {
1438
1538
  const sig = await this.program.methods.initializeClob(
1439
1539
  operators,
@@ -1447,7 +1547,6 @@ var ClobClient = class {
1447
1547
  }).rpc();
1448
1548
  return { signature: sig };
1449
1549
  }
1450
- /** Admin adds an operator to the whitelist. */
1451
1550
  async addOperator(operator) {
1452
1551
  const sig = await this.program.methods.addOperator(operator).accounts({
1453
1552
  admin: this.walletPubkey,
@@ -1455,7 +1554,6 @@ var ClobClient = class {
1455
1554
  }).rpc();
1456
1555
  return { signature: sig };
1457
1556
  }
1458
- /** Admin removes an operator from the whitelist. */
1459
1557
  async removeOperator(operator) {
1460
1558
  const sig = await this.program.methods.removeOperator(operator).accounts({
1461
1559
  admin: this.walletPubkey,
@@ -1463,7 +1561,6 @@ var ClobClient = class {
1463
1561
  }).rpc();
1464
1562
  return { signature: sig };
1465
1563
  }
1466
- /** Admin pause/unpause the CLOB. */
1467
1564
  async setPaused(paused) {
1468
1565
  const sig = await this.program.methods.setPaused(paused).accounts({
1469
1566
  admin: this.walletPubkey,
@@ -1471,9 +1568,6 @@ var ClobClient = class {
1471
1568
  }).rpc();
1472
1569
  return { signature: sig };
1473
1570
  }
1474
- /**
1475
- * Emergency reset of CLOB config (upgrade authority only).
1476
- */
1477
1571
  async forceResetClob(programData, newAdmin, newOperators, newFeeRecipient, newFeeRateBps) {
1478
1572
  const sig = await this.program.methods.forceResetClob(newAdmin, newOperators, newFeeRecipient, newFeeRateBps).accounts({
1479
1573
  upgradeAuthority: this.walletPubkey,
@@ -1482,31 +1576,44 @@ var ClobClient = class {
1482
1576
  }).rpc();
1483
1577
  return { signature: sig };
1484
1578
  }
1579
+ // ─── Match instructions ───────────────────────────────────────────────────────
1485
1580
  /**
1486
- * COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
1581
+ * Build match_complementary instruction (no Ed25519 OrderRecord PDAs used).
1487
1582
  *
1488
- * Transaction structure:
1489
- * ix[0] Ed25519(taker/buyer)
1490
- * ix[1+i] Ed25519(maker_i/seller_i)
1491
- * ix[N+1] match_complementary(buyNonce, makerNonces[])
1492
- *
1493
- * remaining_accounts: [hook×3] [seller×5 × N]
1494
- */
1495
- /** Build Ed25519 + matchComplementary instructions without sending.
1496
- *
1497
- * If `buySigned.order.fee > 0` and `feeClient` + `feeConfigOwner` are wired in,
1498
- * automatically appends 5 fee_management remaining_accounts so the program CPIs
1499
- * to distribute_fee internally. No manual `feeDistribute` param needed.
1583
+ * remaining_accounts layout:
1584
+ * [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
1585
+ * [extraAccountMetaList, hookConfig, hookProgram]
1586
+ * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
1500
1587
  */
1501
- async buildMatchComplementaryIxs(buySigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1502
- const condition = buySigned.order.condition;
1503
- const tokenId = buySigned.order.tokenId;
1588
+ async buildMatchComplementaryIxs(takerSigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1589
+ const condition = takerSigned.order.condition;
1590
+ const tokenId = takerSigned.order.tokenId;
1591
+ const taker = takerSigned.order.maker;
1592
+ const takerNonce = takerSigned.order.nonce;
1593
+ const fillAmount = opts?.fillAmount ?? new anchor5__namespace.BN("18446744073709551615");
1504
1594
  const [outcomeMint] = tokenId === 1 ? PDA.yesMint(condition, this.programIds) : PDA.noMint(condition, this.programIds);
1505
- const buyer = buySigned.order.maker;
1506
- const buyerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, buyer);
1507
- const buyerTokenAccount = splToken.getAssociatedTokenAddressSync(outcomeMint, buyer, false, splToken.TOKEN_2022_PROGRAM_ID);
1508
- const [buyerPosition] = PDA.position(condition, tokenId, buyer, this.programIds);
1509
- const [buyOrderStatus] = PDA.orderStatus(buyer, buySigned.order.nonce, this.programIds);
1595
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1596
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, taker);
1597
+ const takerTokenAccount = splToken.getAssociatedTokenAddressSync(outcomeMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID);
1598
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1599
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1600
+ const makerAccounts = [];
1601
+ for (const ms of makersSigned) {
1602
+ const seller = ms.order.maker;
1603
+ const [sellerRecord] = PDA.orderRecord(seller, ms.order.nonce, this.programIds);
1604
+ const sellerToken = splToken.getAssociatedTokenAddressSync(outcomeMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID);
1605
+ const sellerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, seller);
1606
+ const [sellerPosition] = PDA.position(condition, tokenId, seller, this.programIds);
1607
+ const [sellerStatus] = PDA.orderStatus(seller, ms.order.nonce, this.programIds);
1608
+ makerAccounts.push(
1609
+ { pubkey: seller, isSigner: false, isWritable: false },
1610
+ { pubkey: sellerRecord, isSigner: false, isWritable: false },
1611
+ { pubkey: sellerToken, isSigner: false, isWritable: true },
1612
+ { pubkey: sellerCollateral, isSigner: false, isWritable: true },
1613
+ { pubkey: sellerPosition, isSigner: false, isWritable: true },
1614
+ { pubkey: sellerStatus, isSigner: false, isWritable: true }
1615
+ );
1616
+ }
1510
1617
  const [extraAccountMetaList] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
1511
1618
  const [hookConfig] = PDA.hookConfig(this.programIds);
1512
1619
  const hookAccounts = [
@@ -1514,22 +1621,8 @@ var ClobClient = class {
1514
1621
  { pubkey: hookConfig, isSigner: false, isWritable: false },
1515
1622
  { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
1516
1623
  ];
1517
- const makerAccounts = makersSigned.flatMap((m) => {
1518
- const seller = m.order.maker;
1519
- const sellerTokenAccount = splToken.getAssociatedTokenAddressSync(outcomeMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID);
1520
- const [sellerPosition] = PDA.position(condition, tokenId, seller, this.programIds);
1521
- const sellerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, seller);
1522
- const [sellOrderStatus] = PDA.orderStatus(seller, m.order.nonce, this.programIds);
1523
- return [
1524
- { pubkey: seller, isSigner: false, isWritable: false },
1525
- { pubkey: sellerTokenAccount, isSigner: false, isWritable: true },
1526
- { pubkey: sellerPosition, isSigner: false, isWritable: true },
1527
- { pubkey: sellerCollateral, isSigner: false, isWritable: true },
1528
- { pubkey: sellOrderStatus, isSigner: false, isWritable: true }
1529
- ];
1530
- });
1531
1624
  let feeAccounts = [];
1532
- if (buySigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1625
+ if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1533
1626
  const companyAddr = await this.companyAddress();
1534
1627
  if (companyAddr) {
1535
1628
  const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
@@ -1542,31 +1635,38 @@ var ClobClient = class {
1542
1635
  ];
1543
1636
  }
1544
1637
  }
1545
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1546
- const ed25519Ix = buildBatchedEd25519Instruction([buySigned, ...makersSigned]);
1547
- const matchIx = await this.program.methods.matchComplementary(buySigned.order.nonce, makerNonces).accounts({
1638
+ const matchIx = await this.program.methods.matchComplementary(takerNonce, fillAmount).accounts({
1548
1639
  operator,
1549
1640
  payer: this.walletPubkey,
1550
1641
  clobConfig: this.configPda(),
1551
- ixSysvar: IX_SYSVAR,
1552
1642
  condition,
1553
- buyer,
1554
- buyerCollateral,
1555
- buyerTokenAccount,
1556
- buyerPosition,
1557
- buyOrderStatus,
1558
- outcomeMint,
1643
+ taker,
1644
+ takerOrderRecord,
1645
+ takerCollateral,
1646
+ takerTokenAccount,
1647
+ takerPosition,
1648
+ takerOrderStatus,
1559
1649
  feeRecipient,
1650
+ outcomeMint,
1560
1651
  conditionalTokensProgram: this.programIds.conditionalTokens,
1561
1652
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
1562
1653
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1563
1654
  systemProgram: web3_js.SystemProgram.programId
1564
- }).remainingAccounts([...hookAccounts, ...makerAccounts, ...feeAccounts]).instruction();
1565
- return [ed25519Ix, matchIx];
1655
+ }).remainingAccounts([...makerAccounts, ...hookAccounts, ...feeAccounts]).instruction();
1656
+ return [matchIx];
1566
1657
  }
1567
- async matchComplementary(buySigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1658
+ /**
1659
+ * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
1660
+ * Phase 1: register taker + all makers in parallel.
1661
+ * Phase 2: 1 atomic match tx.
1662
+ */
1663
+ async matchComplementary(takerSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1664
+ await Promise.all([
1665
+ this.registerOrderIfNeeded(takerSigned),
1666
+ ...makersSigned.map((m) => this.registerOrderIfNeeded(m))
1667
+ ]);
1568
1668
  const ixs = await this.buildMatchComplementaryIxs(
1569
- buySigned,
1669
+ takerSigned,
1570
1670
  makersSigned,
1571
1671
  collateralMint,
1572
1672
  feeRecipient,
@@ -1577,160 +1677,167 @@ var ClobClient = class {
1577
1677
  return { signature: sig };
1578
1678
  }
1579
1679
  /**
1580
- * MINT match: 1 YES buyer (taker) + N NO buyers (makers).
1680
+ * MINT: 1 YES buyer (taker) + N NO buyers (makers).
1681
+ * Phase 1: register taker + all NO makers in parallel.
1682
+ * Phase 2: 1 atomic match tx.
1581
1683
  *
1582
- * Transaction structure:
1583
- * ix[0] Ed25519(taker/YES buyer)
1584
- * ix[1+i] Ed25519(maker_i/NO buyer)
1585
- * ix[N+1] match_mint_orders(yesNonce, makerNonces[])
1586
- *
1587
- * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
1684
+ * remaining_accounts per NO maker (5):
1685
+ * [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
1588
1686
  */
1589
- async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1687
+ async matchMintOrders(yesSigned, noMakers, collateralMint, _feeRecipient, operatorWallet, lookupTable) {
1688
+ await Promise.all([
1689
+ this.registerOrderIfNeeded(yesSigned),
1690
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1691
+ ]);
1590
1692
  const condition = yesSigned.order.condition;
1693
+ const taker = yesSigned.order.maker;
1694
+ const takerNonce = yesSigned.order.nonce;
1695
+ const fillAmount = new anchor5__namespace.BN("18446744073709551615");
1591
1696
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1592
1697
  const [noMint] = PDA.noMint(condition, this.programIds);
1593
1698
  const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1594
1699
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1595
1700
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1596
- const buyerYes = yesSigned.order.maker;
1597
- const buyerYesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, buyerYes);
1598
- const buyerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, buyerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1599
- const [buyerYesPosition] = PDA.position(condition, 1, buyerYes, this.programIds);
1600
- const [yesOrderStatus] = PDA.orderStatus(buyerYes, yesSigned.order.nonce, this.programIds);
1601
- const makerAccounts = makersSigned.flatMap((m) => {
1602
- const maker = m.order.maker;
1603
- const makerUsdcAta = splToken.getAssociatedTokenAddressSync(collateralMint, maker);
1604
- const makerNoAta = splToken.getAssociatedTokenAddressSync(noMint, maker, false, splToken.TOKEN_2022_PROGRAM_ID);
1605
- const [makerNoPosition] = PDA.position(condition, 0, maker, this.programIds);
1606
- const [makerOrderStatus] = PDA.orderStatus(maker, m.order.nonce, this.programIds);
1607
- return [
1608
- { pubkey: maker, isSigner: false, isWritable: false },
1609
- { pubkey: makerUsdcAta, isSigner: false, isWritable: true },
1610
- { pubkey: makerNoAta, isSigner: false, isWritable: true },
1611
- { pubkey: makerNoPosition, isSigner: false, isWritable: true },
1612
- { pubkey: makerOrderStatus, isSigner: false, isWritable: true }
1613
- ];
1614
- });
1615
- const operator = operatorWallet.publicKey;
1616
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1617
- const ed25519Ixs = [
1618
- buildBatchedEd25519Instruction([yesSigned, ...makersSigned])
1619
- ];
1620
- const matchIx = await this.program.methods.matchMintOrders(yesSigned.order.nonce, makerNonces).accounts({
1621
- operator,
1701
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1702
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, taker);
1703
+ const takerYesToken = splToken.getAssociatedTokenAddressSync(yesMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID);
1704
+ const [takerYesPosition] = PDA.position(condition, 1, taker, this.programIds);
1705
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1706
+ const remainingAccounts = [];
1707
+ for (const nm of noMakers) {
1708
+ const noMaker = nm.order.maker;
1709
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1710
+ const noToken = splToken.getAssociatedTokenAddressSync(noMint, noMaker, false, splToken.TOKEN_2022_PROGRAM_ID);
1711
+ const noCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, noMaker);
1712
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1713
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1714
+ remainingAccounts.push(
1715
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1716
+ { pubkey: noToken, isSigner: false, isWritable: true },
1717
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1718
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1719
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1720
+ );
1721
+ }
1722
+ const matchIx = await this.program.methods.matchMintOrders(takerNonce, fillAmount).accounts({
1723
+ operator: operatorWallet.publicKey,
1622
1724
  payer: this.walletPubkey,
1623
1725
  clobConfig: this.configPda(),
1624
- ixSysvar: IX_SYSVAR,
1625
1726
  condition,
1626
- buyerYes,
1627
- buyerYesCollateral,
1628
- buyerYesTokenAccount,
1629
- buyerYesPosition,
1630
- yesOrderStatus,
1727
+ taker,
1728
+ takerOrderRecord,
1729
+ takerCollateral,
1730
+ takerYesToken,
1731
+ takerYesPosition,
1732
+ takerOrderStatus,
1631
1733
  collateralVault,
1632
1734
  vaultTokenAccount,
1633
1735
  yesMint,
1634
1736
  noMint,
1635
1737
  mintAuthority,
1738
+ clobAuthority: this.configPda(),
1636
1739
  conditionalTokensProgram: this.programIds.conditionalTokens,
1637
1740
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1638
1741
  systemProgram: web3_js.SystemProgram.programId
1639
- }).remainingAccounts(makerAccounts).instruction();
1640
- const sig = await this.sendMatchTx(
1641
- [...ed25519Ixs, matchIx],
1642
- lookupTable,
1643
- operatorWallet
1644
- );
1742
+ }).remainingAccounts(remainingAccounts).instruction();
1743
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1645
1744
  return { signature: sig };
1646
1745
  }
1647
1746
  /**
1648
- * MERGE match: 1 YES seller (taker) + N NO sellers (makers).
1649
- *
1650
- * Transaction structure:
1651
- * ix[0] Ed25519(taker/YES seller)
1652
- * ix[1+i] Ed25519(maker_i/NO seller)
1653
- * ix[N+1] match_merge_orders(yesNonce, makerNonces[])
1747
+ * MERGE: 1 YES seller (taker) + N NO sellers (makers).
1748
+ * Phase 1: register taker + all NO makers in parallel.
1749
+ * Phase 2: 1 atomic match tx.
1654
1750
  *
1655
- * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
1751
+ * remaining_accounts per NO maker (5):
1752
+ * [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
1753
+ * After all makers, optional 5 fee accounts.
1656
1754
  */
1657
- async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1755
+ async matchMergeOrders(yesSigned, noMakers, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1756
+ await Promise.all([
1757
+ this.registerOrderIfNeeded(yesSigned),
1758
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1759
+ ]);
1658
1760
  const condition = yesSigned.order.condition;
1761
+ const sellerYes = yesSigned.order.maker;
1762
+ const takerNonce = yesSigned.order.nonce;
1763
+ const fillAmount = new anchor5__namespace.BN("18446744073709551615");
1659
1764
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1660
1765
  const [noMint] = PDA.noMint(condition, this.programIds);
1766
+ const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1661
1767
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1662
1768
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1663
- const sellerYes = yesSigned.order.maker;
1664
- const sellerYesTokenAccount = splToken.getAssociatedTokenAddressSync(yesMint, sellerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1665
- const [sellerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
1666
- const sellerYesCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, sellerYes);
1667
- const [yesOrderStatus] = PDA.orderStatus(sellerYes, yesSigned.order.nonce, this.programIds);
1668
- const makerAccounts = makersSigned.flatMap((m) => {
1669
- const maker = m.order.maker;
1670
- const makerNoAta = splToken.getAssociatedTokenAddressSync(noMint, maker, false, splToken.TOKEN_2022_PROGRAM_ID);
1671
- const [makerNoPosition] = PDA.position(condition, 0, maker, this.programIds);
1672
- const makerUsdcAta = splToken.getAssociatedTokenAddressSync(collateralMint, maker);
1673
- const [makerOrderStatus] = PDA.orderStatus(maker, m.order.nonce, this.programIds);
1674
- return [
1675
- { pubkey: maker, isSigner: false, isWritable: false },
1676
- { pubkey: makerNoAta, isSigner: false, isWritable: true },
1677
- { pubkey: makerNoPosition, isSigner: false, isWritable: true },
1678
- { pubkey: makerUsdcAta, isSigner: false, isWritable: true },
1679
- { pubkey: makerOrderStatus, isSigner: false, isWritable: true }
1680
- ];
1681
- });
1682
- const operator = operatorWallet.publicKey;
1683
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1684
- const ed25519Ixs = [
1685
- buildBatchedEd25519Instruction([yesSigned, ...makersSigned])
1686
- ];
1687
- const matchIx = await this.program.methods.matchMergeOrders(yesSigned.order.nonce, makerNonces).accounts({
1688
- operator,
1769
+ const [takerOrderRecord] = PDA.orderRecord(sellerYes, takerNonce, this.programIds);
1770
+ const takerYesToken = splToken.getAssociatedTokenAddressSync(yesMint, sellerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1771
+ const [takerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
1772
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, sellerYes);
1773
+ const [takerOrderStatus] = PDA.orderStatus(sellerYes, takerNonce, this.programIds);
1774
+ const remainingAccounts = [];
1775
+ for (const nm of noMakers) {
1776
+ const noMaker = nm.order.maker;
1777
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1778
+ const noToken = splToken.getAssociatedTokenAddressSync(noMint, noMaker, false, splToken.TOKEN_2022_PROGRAM_ID);
1779
+ const noCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, noMaker);
1780
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1781
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1782
+ remainingAccounts.push(
1783
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1784
+ { pubkey: noToken, isSigner: false, isWritable: true },
1785
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1786
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1787
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1788
+ );
1789
+ }
1790
+ if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1791
+ const companyAddr = await this.companyAddress();
1792
+ if (companyAddr) {
1793
+ const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1794
+ remainingAccounts.push(
1795
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1796
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1797
+ { pubkey: PDA.marketFeeOverride(condition, this.programIds)[0], isSigner: false, isWritable: false },
1798
+ { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1799
+ { pubkey: oracleVault, isSigner: false, isWritable: true }
1800
+ );
1801
+ }
1802
+ }
1803
+ const matchIx = await this.program.methods.matchMergeOrders(takerNonce, fillAmount).accounts({
1804
+ operator: operatorWallet.publicKey,
1689
1805
  payer: this.walletPubkey,
1690
1806
  clobConfig: this.configPda(),
1691
- ixSysvar: IX_SYSVAR,
1692
1807
  condition,
1693
- sellerYes,
1694
- sellerYesTokenAccount,
1695
- sellerYesPosition,
1696
- sellerYesCollateral,
1697
- yesOrderStatus,
1808
+ taker: sellerYes,
1809
+ takerOrderRecord,
1810
+ takerYesToken,
1811
+ takerYesPosition,
1812
+ takerCollateral,
1813
+ takerOrderStatus,
1698
1814
  collateralVault,
1699
1815
  vaultTokenAccount,
1700
1816
  yesMint,
1701
1817
  noMint,
1818
+ mintAuthority,
1702
1819
  feeRecipient,
1820
+ clobAuthority: this.configPda(),
1703
1821
  conditionalTokensProgram: this.programIds.conditionalTokens,
1704
1822
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1705
1823
  systemProgram: web3_js.SystemProgram.programId
1706
- }).remainingAccounts(makerAccounts).instruction();
1707
- const sig = await this.sendMatchTx(
1708
- [...ed25519Ixs, matchIx],
1709
- lookupTable,
1710
- operatorWallet
1711
- );
1824
+ }).remainingAccounts(remainingAccounts).instruction();
1825
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1712
1826
  return { signature: sig };
1713
1827
  }
1714
1828
  /**
1715
- * Auto-detect match type and execute 1-taker + N-makers in a single transaction.
1829
+ * Auto-detect match type and execute 2-phase:
1830
+ * Phase 1 — register all orders (taker + makers) on-chain in parallel.
1831
+ * Phase 2 — 1 atomic match transaction.
1716
1832
  *
1717
- * Detection (pure, no RPC) based on taker.order vs makers[0].order:
1718
- * taker.tokenId === makers[0].tokenId: taker BUY + all makers SELL → COMPLEMENTARY
1719
- * taker.tokenId !== makers[0].tokenId + taker BUY + all makers BUYMINT
1720
- * taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL MERGE
1721
- * Otherwisethrows InvalidParamError
1833
+ * Detection (pure, no RPC):
1834
+ * taker.tokenId === makers[0].tokenId:
1835
+ * taker BUY + all makers SELLCOMPLEMENTARY
1836
+ * taker.tokenId !== makers[0].tokenId + all BUY MINT
1837
+ * taker.tokenId !== makers[0].tokenId + all SELL MERGE
1722
1838
  *
1723
- * All makers must have the same tokenId and side as makers[0].
1724
- */
1725
- /**
1726
- * Auto-detect match type and execute in a single transaction.
1727
- * ALT is managed automatically (created on first call per condition, cached thereafter).
1728
- * feeRecipient and collateralMint are derived from on-chain config.
1729
- * Fee distribution (distribute_fee CPI) fires automatically when order.fee > 0.
1730
- *
1731
- * @param opts.marketOracleVault Required for presale markets (is_admin=false).
1732
- * Pass the ATA of the market_oracle PDA so 50% of fee goes there.
1733
- * For admin markets (is_admin=true) omit — payer is used as placeholder (no transfer).
1839
+ * @param opts.marketOracleVault Oracle vault ATA for presale markets.
1840
+ * Omit for admin markets (payer used as placeholder).
1734
1841
  */
1735
1842
  async matchOrders(taker, makers, opts) {
1736
1843
  if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
@@ -1742,8 +1849,7 @@ var ClobClient = class {
1742
1849
  const alt = await this.ensureAlt(
1743
1850
  taker.order.condition,
1744
1851
  collateralMint,
1745
- taker.order.maker,
1746
- taker.order.nonce,
1852
+ taker,
1747
1853
  makers
1748
1854
  );
1749
1855
  const t = taker.order;
@@ -1754,9 +1860,6 @@ var ClobClient = class {
1754
1860
  if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
1755
1861
  return this.matchComplementary(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1756
1862
  }
1757
- if (t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_BUY)) {
1758
- throw new InvalidParamError("COMPLEMENTARY N-maker: taker must be the BUY side");
1759
- }
1760
1863
  throw new InvalidParamError("COMPLEMENTARY requires taker=BUY, makers=SELL on same tokenId");
1761
1864
  }
1762
1865
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
@@ -1765,7 +1868,7 @@ var ClobClient = class {
1765
1868
  if (t.tokenId !== 1) throw new InvalidParamError("MINT/MERGE: taker must be YES (tokenId=1)");
1766
1869
  if (!makers.every((m) => m.order.tokenId === 0)) throw new InvalidParamError("MINT/MERGE: makers must be NO (tokenId=0)");
1767
1870
  if (allBuy) return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1768
- return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1871
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1769
1872
  }
1770
1873
  // ─── Queries ─────────────────────────────────────────────────────────────────
1771
1874
  async fetchConfig() {
@@ -1799,6 +1902,15 @@ var ClobClient = class {
1799
1902
  return null;
1800
1903
  }
1801
1904
  }
1905
+ async fetchOrderRecord(maker, nonce) {
1906
+ try {
1907
+ const [pda] = PDA.orderRecord(maker, nonce, this.programIds);
1908
+ const acc = await this.program.account.signedOrderRecord.fetch(pda);
1909
+ return acc;
1910
+ } catch {
1911
+ return null;
1912
+ }
1913
+ }
1802
1914
  };
1803
1915
  var FeeManagementClient = class {
1804
1916
  constructor(program, provider, programIds) {
@@ -2838,6 +2950,11 @@ var hook_default = {
2838
2950
  name: "owner",
2839
2951
  signer: true
2840
2952
  },
2953
+ {
2954
+ name: "payer",
2955
+ writable: true,
2956
+ signer: true
2957
+ },
2841
2958
  {
2842
2959
  name: "hook_config",
2843
2960
  writable: true,
@@ -2969,6 +3086,11 @@ var hook_default = {
2969
3086
  name: "owner",
2970
3087
  signer: true
2971
3088
  },
3089
+ {
3090
+ name: "payer",
3091
+ writable: true,
3092
+ signer: true
3093
+ },
2972
3094
  {
2973
3095
  name: "hook_config",
2974
3096
  writable: true,
@@ -3177,6 +3299,11 @@ var hook_default = {
3177
3299
  name: "owner",
3178
3300
  signer: true
3179
3301
  },
3302
+ {
3303
+ name: "payer",
3304
+ writable: true,
3305
+ signer: true
3306
+ },
3180
3307
  {
3181
3308
  name: "hook_config",
3182
3309
  writable: true,
@@ -3228,10 +3355,6 @@ var hook_default = {
3228
3355
  types: [
3229
3356
  {
3230
3357
  name: "HookConfig",
3231
- docs: [
3232
- "Global config for the Hook program.",
3233
- "Stores the whitelist of programs allowed to transfer YES/NO Token-2022 tokens."
3234
- ],
3235
3358
  type: {
3236
3359
  kind: "struct",
3237
3360
  fields: [
@@ -3241,16 +3364,10 @@ var hook_default = {
3241
3364
  },
3242
3365
  {
3243
3366
  name: "owner",
3244
- docs: [
3245
- "Owner who can update the whitelist"
3246
- ],
3247
3367
  type: "pubkey"
3248
3368
  },
3249
3369
  {
3250
3370
  name: "whitelist",
3251
- docs: [
3252
- "Programs allowed to initiate or receive YES/NO token transfers."
3253
- ],
3254
3371
  type: {
3255
3372
  array: [
3256
3373
  "pubkey",
@@ -3264,16 +3381,10 @@ var hook_default = {
3264
3381
  },
3265
3382
  {
3266
3383
  name: "is_frozen",
3267
- docs: [
3268
- "If true, whitelist can no longer be modified (locked forever)"
3269
- ],
3270
3384
  type: "bool"
3271
3385
  },
3272
3386
  {
3273
3387
  name: "bump",
3274
- docs: [
3275
- "Bump for this PDA"
3276
- ],
3277
3388
  type: "u8"
3278
3389
  },
3279
3390
  {
@@ -4183,6 +4294,58 @@ var question_market_default = {
4183
4294
  }
4184
4295
  ]
4185
4296
  },
4297
+ {
4298
+ name: "grow_config",
4299
+ discriminator: [
4300
+ 190,
4301
+ 5,
4302
+ 0,
4303
+ 130,
4304
+ 65,
4305
+ 253,
4306
+ 94,
4307
+ 228
4308
+ ],
4309
+ accounts: [
4310
+ {
4311
+ name: "payer",
4312
+ writable: true,
4313
+ signer: true
4314
+ },
4315
+ {
4316
+ name: "owner",
4317
+ signer: true
4318
+ },
4319
+ {
4320
+ name: "config",
4321
+ writable: true,
4322
+ pda: {
4323
+ seeds: [
4324
+ {
4325
+ kind: "const",
4326
+ value: [
4327
+ 99,
4328
+ 111,
4329
+ 110,
4330
+ 102,
4331
+ 105,
4332
+ 103
4333
+ ]
4334
+ },
4335
+ {
4336
+ kind: "account",
4337
+ path: "owner"
4338
+ }
4339
+ ]
4340
+ }
4341
+ },
4342
+ {
4343
+ name: "system_program",
4344
+ address: "11111111111111111111111111111111"
4345
+ }
4346
+ ],
4347
+ args: []
4348
+ },
4186
4349
  {
4187
4350
  name: "initialize",
4188
4351
  discriminator: [
@@ -4551,6 +4714,63 @@ var question_market_default = {
4551
4714
  }
4552
4715
  ]
4553
4716
  },
4717
+ {
4718
+ name: "restore_config",
4719
+ discriminator: [
4720
+ 95,
4721
+ 203,
4722
+ 226,
4723
+ 92,
4724
+ 60,
4725
+ 222,
4726
+ 192,
4727
+ 221
4728
+ ],
4729
+ accounts: [
4730
+ {
4731
+ name: "payer",
4732
+ writable: true,
4733
+ signer: true
4734
+ },
4735
+ {
4736
+ name: "owner",
4737
+ signer: true
4738
+ },
4739
+ {
4740
+ name: "config",
4741
+ writable: true,
4742
+ pda: {
4743
+ seeds: [
4744
+ {
4745
+ kind: "const",
4746
+ value: [
4747
+ 99,
4748
+ 111,
4749
+ 110,
4750
+ 102,
4751
+ 105,
4752
+ 103
4753
+ ]
4754
+ },
4755
+ {
4756
+ kind: "account",
4757
+ path: "owner"
4758
+ }
4759
+ ]
4760
+ }
4761
+ },
4762
+ {
4763
+ name: "system_program",
4764
+ address: "11111111111111111111111111111111"
4765
+ }
4766
+ ],
4767
+ args: [
4768
+ {
4769
+ name: "snapshot",
4770
+ type: "bytes"
4771
+ }
4772
+ ]
4773
+ },
4554
4774
  {
4555
4775
  name: "update_config",
4556
4776
  discriminator: [
@@ -5583,7 +5803,7 @@ var question_market_default = {
5583
5803
  type: {
5584
5804
  array: [
5585
5805
  "pubkey",
5586
- 10
5806
+ 30
5587
5807
  ]
5588
5808
  }
5589
5809
  },
@@ -7685,9 +7905,6 @@ var clob_exchange_default = {
7685
7905
  instructions: [
7686
7906
  {
7687
7907
  name: "add_operator",
7688
- docs: [
7689
- "Add an authorized operator (off-chain matching engine)."
7690
- ],
7691
7908
  discriminator: [
7692
7909
  149,
7693
7910
  142,
@@ -7736,13 +7953,77 @@ var clob_exchange_default = {
7736
7953
  ]
7737
7954
  },
7738
7955
  {
7739
- name: "force_reset_clob",
7956
+ name: "cancel_order",
7740
7957
  docs: [
7741
- "Force-reset the CLOB config (upgrade authority only).",
7742
- "Use when the original admin keypair is lost."
7958
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
7743
7959
  ],
7744
7960
  discriminator: [
7745
- 96,
7961
+ 95,
7962
+ 129,
7963
+ 237,
7964
+ 240,
7965
+ 8,
7966
+ 49,
7967
+ 223,
7968
+ 132
7969
+ ],
7970
+ accounts: [
7971
+ {
7972
+ name: "maker",
7973
+ docs: [
7974
+ "Must be the order maker/signer"
7975
+ ],
7976
+ signer: true
7977
+ },
7978
+ {
7979
+ name: "order_record",
7980
+ writable: true,
7981
+ pda: {
7982
+ seeds: [
7983
+ {
7984
+ kind: "const",
7985
+ value: [
7986
+ 111,
7987
+ 114,
7988
+ 100,
7989
+ 101,
7990
+ 114,
7991
+ 95,
7992
+ 114,
7993
+ 101,
7994
+ 99,
7995
+ 111,
7996
+ 114,
7997
+ 100
7998
+ ]
7999
+ },
8000
+ {
8001
+ kind: "account",
8002
+ path: "maker"
8003
+ },
8004
+ {
8005
+ kind: "arg",
8006
+ path: "nonce"
8007
+ }
8008
+ ]
8009
+ }
8010
+ },
8011
+ {
8012
+ name: "system_program",
8013
+ address: "11111111111111111111111111111111"
8014
+ }
8015
+ ],
8016
+ args: [
8017
+ {
8018
+ name: "nonce",
8019
+ type: "u64"
8020
+ }
8021
+ ]
8022
+ },
8023
+ {
8024
+ name: "force_reset_clob",
8025
+ discriminator: [
8026
+ 96,
7746
8027
  95,
7747
8028
  187,
7748
8029
  95,
@@ -7815,9 +8096,6 @@ var clob_exchange_default = {
7815
8096
  },
7816
8097
  {
7817
8098
  name: "initialize_clob",
7818
- docs: [
7819
- "Initialize the CLOB global config."
7820
- ],
7821
8099
  discriminator: [
7822
8100
  35,
7823
8101
  69,
@@ -7887,10 +8165,7 @@ var clob_exchange_default = {
7887
8165
  {
7888
8166
  name: "match_complementary",
7889
8167
  docs: [
7890
- "COMPLEMENTARY match: one buyer of YES/NO tokens meets one seller.",
7891
- "Operator verifies signatures off-chain, executes atomically on-chain.",
7892
- "",
7893
- "Execution price = seller's ask (maker-fills-taker model)."
8168
+ "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
7894
8169
  ],
7895
8170
  discriminator: [
7896
8171
  100,
@@ -7905,24 +8180,15 @@ var clob_exchange_default = {
7905
8180
  accounts: [
7906
8181
  {
7907
8182
  name: "operator",
7908
- docs: [
7909
- "Authorized operator (whitelisted signer)"
7910
- ],
7911
8183
  signer: true
7912
8184
  },
7913
8185
  {
7914
8186
  name: "payer",
7915
- docs: [
7916
- "Fee payer \u2014 pays tx fee and PDA rent"
7917
- ],
7918
8187
  writable: true,
7919
8188
  signer: true
7920
8189
  },
7921
8190
  {
7922
8191
  name: "clob_config",
7923
- docs: [
7924
- "CLOB config PDA \u2014 also used as the signing authority for CTF CPIs."
7925
- ],
7926
8192
  writable: true,
7927
8193
  pda: {
7928
8194
  seeds: [
@@ -7945,27 +8211,14 @@ var clob_exchange_default = {
7945
8211
  ]
7946
8212
  }
7947
8213
  },
7948
- {
7949
- name: "ix_sysvar",
7950
- address: "Sysvar1nstructions1111111111111111111111111"
7951
- },
7952
8214
  {
7953
8215
  name: "condition"
7954
8216
  },
7955
8217
  {
7956
- name: "buyer"
8218
+ name: "taker"
7957
8219
  },
7958
8220
  {
7959
- name: "buyer_collateral",
7960
- writable: true
7961
- },
7962
- {
7963
- name: "buyer_token_account",
7964
- writable: true
7965
- },
7966
- {
7967
- name: "buy_order_status",
7968
- writable: true,
8221
+ name: "taker_order_record",
7969
8222
  pda: {
7970
8223
  seeds: [
7971
8224
  {
@@ -7975,33 +8228,41 @@ var clob_exchange_default = {
7975
8228
  114,
7976
8229
  100,
7977
8230
  101,
7978
- 114
8231
+ 114,
8232
+ 95,
8233
+ 114,
8234
+ 101,
8235
+ 99,
8236
+ 111,
8237
+ 114,
8238
+ 100
7979
8239
  ]
7980
8240
  },
7981
8241
  {
7982
8242
  kind: "account",
7983
- path: "buyer"
8243
+ path: "taker"
7984
8244
  },
7985
8245
  {
7986
8246
  kind: "arg",
7987
- path: "buy_signed.order.nonce"
8247
+ path: "taker_nonce"
7988
8248
  }
7989
8249
  ]
7990
8250
  }
7991
8251
  },
7992
8252
  {
7993
- name: "seller"
8253
+ name: "taker_collateral",
8254
+ writable: true
7994
8255
  },
7995
8256
  {
7996
- name: "seller_token_account",
8257
+ name: "taker_token_account",
7997
8258
  writable: true
7998
8259
  },
7999
8260
  {
8000
- name: "seller_collateral",
8261
+ name: "taker_position",
8001
8262
  writable: true
8002
8263
  },
8003
8264
  {
8004
- name: "sell_order_status",
8265
+ name: "taker_order_status",
8005
8266
  writable: true,
8006
8267
  pda: {
8007
8268
  seeds: [
@@ -8017,11 +8278,11 @@ var clob_exchange_default = {
8017
8278
  },
8018
8279
  {
8019
8280
  kind: "account",
8020
- path: "seller"
8281
+ path: "taker"
8021
8282
  },
8022
8283
  {
8023
8284
  kind: "arg",
8024
- path: "sell_signed.order.nonce"
8285
+ path: "taker_nonce"
8025
8286
  }
8026
8287
  ]
8027
8288
  }
@@ -8034,17 +8295,9 @@ var clob_exchange_default = {
8034
8295
  name: "outcome_mint",
8035
8296
  writable: true
8036
8297
  },
8037
- {
8038
- name: "seller_position",
8039
- writable: true
8040
- },
8041
- {
8042
- name: "buyer_position",
8043
- writable: true
8044
- },
8045
8298
  {
8046
8299
  name: "conditional_tokens_program",
8047
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8300
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8048
8301
  },
8049
8302
  {
8050
8303
  name: "token_program",
@@ -8061,20 +8314,8 @@ var clob_exchange_default = {
8061
8314
  ],
8062
8315
  args: [
8063
8316
  {
8064
- name: "buy_signed",
8065
- type: {
8066
- defined: {
8067
- name: "SignedOrder"
8068
- }
8069
- }
8070
- },
8071
- {
8072
- name: "sell_signed",
8073
- type: {
8074
- defined: {
8075
- name: "SignedOrder"
8076
- }
8077
- }
8317
+ name: "taker_nonce",
8318
+ type: "u64"
8078
8319
  },
8079
8320
  {
8080
8321
  name: "fill_amount",
@@ -8085,9 +8326,7 @@ var clob_exchange_default = {
8085
8326
  {
8086
8327
  name: "match_merge_orders",
8087
8328
  docs: [
8088
- "MERGE match: two sellers on complementary sides (one sells YES, one sells NO).",
8089
- "Their combined 1 YES + 1 NO is merged back into 1 USDC.",
8090
- "Requires: yes_price_bps + no_price_bps <= 10_000."
8329
+ "MERGE match: 1 taker (YES SELL) + N makers (NO SELL) via remaining_accounts."
8091
8330
  ],
8092
8331
  discriminator: [
8093
8332
  105,
@@ -8102,16 +8341,10 @@ var clob_exchange_default = {
8102
8341
  accounts: [
8103
8342
  {
8104
8343
  name: "operator",
8105
- docs: [
8106
- "Authorized operator (whitelisted signer)"
8107
- ],
8108
8344
  signer: true
8109
8345
  },
8110
8346
  {
8111
8347
  name: "payer",
8112
- docs: [
8113
- "Fee payer \u2014 pays tx fee and PDA rent"
8114
- ],
8115
8348
  writable: true,
8116
8349
  signer: true
8117
8350
  },
@@ -8138,40 +8371,14 @@ var clob_exchange_default = {
8138
8371
  ]
8139
8372
  }
8140
8373
  },
8141
- {
8142
- name: "ix_sysvar",
8143
- address: "Sysvar1nstructions1111111111111111111111111"
8144
- },
8145
8374
  {
8146
8375
  name: "condition"
8147
8376
  },
8148
8377
  {
8149
- name: "seller_yes"
8150
- },
8151
- {
8152
- name: "seller_yes_token_account",
8153
- docs: [
8154
- "Seller YES's YES token account (tokens leave here)"
8155
- ],
8156
- writable: true
8157
- },
8158
- {
8159
- name: "seller_yes_position",
8160
- docs: [
8161
- "Seller YES's YES Position PDA"
8162
- ],
8163
- writable: true
8164
- },
8165
- {
8166
- name: "seller_yes_collateral",
8167
- docs: [
8168
- "Seller YES receives USDC here"
8169
- ],
8170
- writable: true
8378
+ name: "taker"
8171
8379
  },
8172
8380
  {
8173
- name: "yes_order_status",
8174
- writable: true,
8381
+ name: "taker_order_record",
8175
8382
  pda: {
8176
8383
  seeds: [
8177
8384
  {
@@ -8181,37 +8388,41 @@ var clob_exchange_default = {
8181
8388
  114,
8182
8389
  100,
8183
8390
  101,
8184
- 114
8391
+ 114,
8392
+ 95,
8393
+ 114,
8394
+ 101,
8395
+ 99,
8396
+ 111,
8397
+ 114,
8398
+ 100
8185
8399
  ]
8186
8400
  },
8187
8401
  {
8188
8402
  kind: "account",
8189
- path: "seller_yes"
8403
+ path: "taker"
8190
8404
  },
8191
8405
  {
8192
8406
  kind: "arg",
8193
- path: "yes_signed.order.nonce"
8407
+ path: "taker_nonce"
8194
8408
  }
8195
8409
  ]
8196
8410
  }
8197
8411
  },
8198
8412
  {
8199
- name: "seller_no"
8200
- },
8201
- {
8202
- name: "seller_no_token_account",
8413
+ name: "taker_yes_token",
8203
8414
  writable: true
8204
8415
  },
8205
8416
  {
8206
- name: "seller_no_position",
8417
+ name: "taker_yes_position",
8207
8418
  writable: true
8208
8419
  },
8209
8420
  {
8210
- name: "seller_no_collateral",
8421
+ name: "taker_collateral",
8211
8422
  writable: true
8212
8423
  },
8213
8424
  {
8214
- name: "no_order_status",
8425
+ name: "taker_order_status",
8215
8426
  writable: true,
8216
8427
  pda: {
8217
8428
  seeds: [
@@ -8227,11 +8438,11 @@ var clob_exchange_default = {
8227
8438
  },
8228
8439
  {
8229
8440
  kind: "account",
8230
- path: "seller_no"
8441
+ path: "taker"
8231
8442
  },
8232
8443
  {
8233
8444
  kind: "arg",
8234
- path: "no_signed.order.nonce"
8445
+ path: "taker_nonce"
8235
8446
  }
8236
8447
  ]
8237
8448
  }
@@ -8258,16 +8469,10 @@ var clob_exchange_default = {
8258
8469
  },
8259
8470
  {
8260
8471
  name: "fee_recipient",
8261
- docs: [
8262
- "Fee recipient (receives spread)"
8263
- ],
8264
8472
  writable: true
8265
8473
  },
8266
8474
  {
8267
8475
  name: "clob_authority",
8268
- docs: [
8269
- "CLOB authority PDA"
8270
- ],
8271
8476
  pda: {
8272
8477
  seeds: [
8273
8478
  {
@@ -8291,7 +8496,7 @@ var clob_exchange_default = {
8291
8496
  },
8292
8497
  {
8293
8498
  name: "conditional_tokens_program",
8294
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8499
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8295
8500
  },
8296
8501
  {
8297
8502
  name: "collateral_token_program",
@@ -8304,20 +8509,8 @@ var clob_exchange_default = {
8304
8509
  ],
8305
8510
  args: [
8306
8511
  {
8307
- name: "yes_signed",
8308
- type: {
8309
- defined: {
8310
- name: "SignedOrder"
8311
- }
8312
- }
8313
- },
8314
- {
8315
- name: "no_signed",
8316
- type: {
8317
- defined: {
8318
- name: "SignedOrder"
8319
- }
8320
- }
8512
+ name: "taker_nonce",
8513
+ type: "u64"
8321
8514
  },
8322
8515
  {
8323
8516
  name: "fill_amount",
@@ -8328,9 +8521,7 @@ var clob_exchange_default = {
8328
8521
  {
8329
8522
  name: "match_mint_orders",
8330
8523
  docs: [
8331
- "MINT match: two buyers on complementary sides (one buys YES, one buys NO).",
8332
- "Their combined USDC is used to split 1 USDC \u2192 1 YES + 1 NO.",
8333
- "Requires: yes_price_bps + no_price_bps >= 10_000."
8524
+ "MINT match: 1 taker (YES BUY) + N makers (NO BUY) via remaining_accounts."
8334
8525
  ],
8335
8526
  discriminator: [
8336
8527
  146,
@@ -8345,16 +8536,10 @@ var clob_exchange_default = {
8345
8536
  accounts: [
8346
8537
  {
8347
8538
  name: "operator",
8348
- docs: [
8349
- "Authorized operator (whitelisted signer)"
8350
- ],
8351
8539
  signer: true
8352
8540
  },
8353
8541
  {
8354
8542
  name: "payer",
8355
- docs: [
8356
- "Fee payer \u2014 pays tx fee and PDA rent"
8357
- ],
8358
8543
  writable: true,
8359
8544
  signer: true
8360
8545
  },
@@ -8381,31 +8566,14 @@ var clob_exchange_default = {
8381
8566
  ]
8382
8567
  }
8383
8568
  },
8384
- {
8385
- name: "ix_sysvar",
8386
- address: "Sysvar1nstructions1111111111111111111111111"
8387
- },
8388
8569
  {
8389
8570
  name: "condition"
8390
8571
  },
8391
8572
  {
8392
- name: "buyer_yes"
8393
- },
8394
- {
8395
- name: "buyer_yes_collateral",
8396
- writable: true
8397
- },
8398
- {
8399
- name: "buyer_yes_token_account",
8400
- writable: true
8401
- },
8402
- {
8403
- name: "buyer_yes_position",
8404
- writable: true
8573
+ name: "taker"
8405
8574
  },
8406
8575
  {
8407
- name: "yes_order_status",
8408
- writable: true,
8576
+ name: "taker_order_record",
8409
8577
  pda: {
8410
8578
  seeds: [
8411
8579
  {
@@ -8415,37 +8583,41 @@ var clob_exchange_default = {
8415
8583
  114,
8416
8584
  100,
8417
8585
  101,
8418
- 114
8586
+ 114,
8587
+ 95,
8588
+ 114,
8589
+ 101,
8590
+ 99,
8591
+ 111,
8592
+ 114,
8593
+ 100
8419
8594
  ]
8420
8595
  },
8421
8596
  {
8422
8597
  kind: "account",
8423
- path: "buyer_yes"
8598
+ path: "taker"
8424
8599
  },
8425
8600
  {
8426
8601
  kind: "arg",
8427
- path: "yes_signed.order.nonce"
8602
+ path: "taker_nonce"
8428
8603
  }
8429
8604
  ]
8430
8605
  }
8431
8606
  },
8432
8607
  {
8433
- name: "buyer_no"
8434
- },
8435
- {
8436
- name: "buyer_no_collateral",
8608
+ name: "taker_collateral",
8437
8609
  writable: true
8438
8610
  },
8439
8611
  {
8440
- name: "buyer_no_token_account",
8612
+ name: "taker_yes_token",
8441
8613
  writable: true
8442
8614
  },
8443
8615
  {
8444
- name: "buyer_no_position",
8616
+ name: "taker_yes_position",
8445
8617
  writable: true
8446
8618
  },
8447
8619
  {
8448
- name: "no_order_status",
8620
+ name: "taker_order_status",
8449
8621
  writable: true,
8450
8622
  pda: {
8451
8623
  seeds: [
@@ -8461,11 +8633,11 @@ var clob_exchange_default = {
8461
8633
  },
8462
8634
  {
8463
8635
  kind: "account",
8464
- path: "buyer_no"
8636
+ path: "taker"
8465
8637
  },
8466
8638
  {
8467
8639
  kind: "arg",
8468
- path: "no_signed.order.nonce"
8640
+ path: "taker_nonce"
8469
8641
  }
8470
8642
  ]
8471
8643
  }
@@ -8492,9 +8664,6 @@ var clob_exchange_default = {
8492
8664
  },
8493
8665
  {
8494
8666
  name: "clob_authority",
8495
- docs: [
8496
- "CLOB authority PDA (signs CTF CPI)"
8497
- ],
8498
8667
  pda: {
8499
8668
  seeds: [
8500
8669
  {
@@ -8518,7 +8687,7 @@ var clob_exchange_default = {
8518
8687
  },
8519
8688
  {
8520
8689
  name: "conditional_tokens_program",
8521
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8690
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8522
8691
  },
8523
8692
  {
8524
8693
  name: "collateral_token_program",
@@ -8531,32 +8700,194 @@ var clob_exchange_default = {
8531
8700
  ],
8532
8701
  args: [
8533
8702
  {
8534
- name: "yes_signed",
8535
- type: {
8536
- defined: {
8537
- name: "SignedOrder"
8538
- }
8703
+ name: "taker_nonce",
8704
+ type: "u64"
8705
+ },
8706
+ {
8707
+ name: "fill_amount",
8708
+ type: "u64"
8709
+ }
8710
+ ]
8711
+ },
8712
+ {
8713
+ name: "register_order",
8714
+ docs: [
8715
+ "Register a signed order on-chain (Ed25519 verify at registration time).",
8716
+ "ix[0] must be Ed25519 precompile with 1 entry for order.signer."
8717
+ ],
8718
+ discriminator: [
8719
+ 92,
8720
+ 37,
8721
+ 29,
8722
+ 46,
8723
+ 77,
8724
+ 250,
8725
+ 219,
8726
+ 6
8727
+ ],
8728
+ accounts: [
8729
+ {
8730
+ name: "payer",
8731
+ docs: [
8732
+ "Operator pays rent for the OrderRecord PDA."
8733
+ ],
8734
+ writable: true,
8735
+ signer: true
8736
+ },
8737
+ {
8738
+ name: "clob_config",
8739
+ pda: {
8740
+ seeds: [
8741
+ {
8742
+ kind: "const",
8743
+ value: [
8744
+ 99,
8745
+ 108,
8746
+ 111,
8747
+ 98,
8748
+ 95,
8749
+ 99,
8750
+ 111,
8751
+ 110,
8752
+ 102,
8753
+ 105,
8754
+ 103
8755
+ ]
8756
+ }
8757
+ ]
8539
8758
  }
8540
8759
  },
8541
8760
  {
8542
- name: "no_signed",
8543
- type: {
8544
- defined: {
8545
- name: "SignedOrder"
8546
- }
8761
+ name: "ix_sysvar",
8762
+ address: "Sysvar1nstructions1111111111111111111111111"
8763
+ },
8764
+ {
8765
+ name: "order_signer"
8766
+ },
8767
+ {
8768
+ name: "order_record",
8769
+ writable: true,
8770
+ pda: {
8771
+ seeds: [
8772
+ {
8773
+ kind: "const",
8774
+ value: [
8775
+ 111,
8776
+ 114,
8777
+ 100,
8778
+ 101,
8779
+ 114,
8780
+ 95,
8781
+ 114,
8782
+ 101,
8783
+ 99,
8784
+ 111,
8785
+ 114,
8786
+ 100
8787
+ ]
8788
+ },
8789
+ {
8790
+ kind: "account",
8791
+ path: "order_signer"
8792
+ },
8793
+ {
8794
+ kind: "arg",
8795
+ path: "nonce"
8796
+ }
8797
+ ]
8547
8798
  }
8548
8799
  },
8549
8800
  {
8550
- name: "fill_amount",
8801
+ name: "order_status",
8802
+ writable: true,
8803
+ pda: {
8804
+ seeds: [
8805
+ {
8806
+ kind: "const",
8807
+ value: [
8808
+ 111,
8809
+ 114,
8810
+ 100,
8811
+ 101,
8812
+ 114
8813
+ ]
8814
+ },
8815
+ {
8816
+ kind: "account",
8817
+ path: "order_signer"
8818
+ },
8819
+ {
8820
+ kind: "arg",
8821
+ path: "nonce"
8822
+ }
8823
+ ]
8824
+ }
8825
+ },
8826
+ {
8827
+ name: "system_program",
8828
+ address: "11111111111111111111111111111111"
8829
+ }
8830
+ ],
8831
+ args: [
8832
+ {
8833
+ name: "nonce",
8551
8834
  type: "u64"
8552
8835
  }
8553
8836
  ]
8554
8837
  },
8555
8838
  {
8556
- name: "remove_operator",
8557
- docs: [
8558
- "Remove an operator."
8839
+ name: "reinit_clob",
8840
+ discriminator: [
8841
+ 41,
8842
+ 95,
8843
+ 240,
8844
+ 222,
8845
+ 95,
8846
+ 170,
8847
+ 14,
8848
+ 224
8849
+ ],
8850
+ accounts: [
8851
+ {
8852
+ name: "upgrade_authority",
8853
+ writable: true,
8854
+ signer: true
8855
+ },
8856
+ {
8857
+ name: "program_data"
8858
+ },
8859
+ {
8860
+ name: "clob_config",
8861
+ writable: true
8862
+ }
8559
8863
  ],
8864
+ args: [
8865
+ {
8866
+ name: "new_admin",
8867
+ type: "pubkey"
8868
+ },
8869
+ {
8870
+ name: "new_operators",
8871
+ type: {
8872
+ vec: "pubkey"
8873
+ }
8874
+ },
8875
+ {
8876
+ name: "new_fee_recipient",
8877
+ type: "pubkey"
8878
+ },
8879
+ {
8880
+ name: "new_fee_rate_bps",
8881
+ type: "u16"
8882
+ },
8883
+ {
8884
+ name: "conditional_tokens_program",
8885
+ type: "pubkey"
8886
+ }
8887
+ ]
8888
+ },
8889
+ {
8890
+ name: "remove_operator",
8560
8891
  discriminator: [
8561
8892
  84,
8562
8893
  183,
@@ -8606,9 +8937,6 @@ var clob_exchange_default = {
8606
8937
  },
8607
8938
  {
8608
8939
  name: "set_paused",
8609
- docs: [
8610
- "Pause or unpause the CLOB (admin only)."
8611
- ],
8612
8940
  discriminator: [
8613
8941
  91,
8614
8942
  60,
@@ -8683,6 +9011,19 @@ var clob_exchange_default = {
8683
9011
  65,
8684
9012
  3
8685
9013
  ]
9014
+ },
9015
+ {
9016
+ name: "SignedOrderRecord",
9017
+ discriminator: [
9018
+ 16,
9019
+ 167,
9020
+ 189,
9021
+ 166,
9022
+ 85,
9023
+ 0,
9024
+ 231,
9025
+ 55
9026
+ ]
8686
9027
  }
8687
9028
  ],
8688
9029
  events: [
@@ -8877,29 +9218,13 @@ var clob_exchange_default = {
8877
9218
  type: "pubkey"
8878
9219
  },
8879
9220
  {
8880
- name: "buyer",
8881
- type: "pubkey"
8882
- },
8883
- {
8884
- name: "seller",
9221
+ name: "taker",
8885
9222
  type: "pubkey"
8886
9223
  },
8887
- {
8888
- name: "token_id",
8889
- type: "u8"
8890
- },
8891
9224
  {
8892
9225
  name: "fill_amount",
8893
9226
  type: "u64"
8894
9227
  },
8895
- {
8896
- name: "price_bps",
8897
- type: "u64"
8898
- },
8899
- {
8900
- name: "usdc_transferred",
8901
- type: "u64"
8902
- },
8903
9228
  {
8904
9229
  name: "fee",
8905
9230
  type: "u64"
@@ -9050,33 +9375,13 @@ var clob_exchange_default = {
9050
9375
  type: "pubkey"
9051
9376
  },
9052
9377
  {
9053
- name: "seller_yes",
9054
- type: "pubkey"
9055
- },
9056
- {
9057
- name: "seller_no",
9378
+ name: "taker",
9058
9379
  type: "pubkey"
9059
9380
  },
9060
9381
  {
9061
9382
  name: "fill_amount",
9062
9383
  type: "u64"
9063
9384
  },
9064
- {
9065
- name: "yes_price_bps",
9066
- type: "u64"
9067
- },
9068
- {
9069
- name: "no_price_bps",
9070
- type: "u64"
9071
- },
9072
- {
9073
- name: "yes_payout",
9074
- type: "u64"
9075
- },
9076
- {
9077
- name: "no_payout",
9078
- type: "u64"
9079
- },
9080
9385
  {
9081
9386
  name: "fee",
9082
9387
  type: "u64"
@@ -9097,173 +9402,108 @@ var clob_exchange_default = {
9097
9402
  name: "buyer_yes",
9098
9403
  type: "pubkey"
9099
9404
  },
9100
- {
9101
- name: "buyer_no",
9102
- type: "pubkey"
9103
- },
9104
9405
  {
9105
9406
  name: "fill_amount",
9106
9407
  type: "u64"
9107
- },
9408
+ }
9409
+ ]
9410
+ }
9411
+ },
9412
+ {
9413
+ name: "OrderStatus",
9414
+ docs: [
9415
+ "Tracks the fill state of an order for replay protection.",
9416
+ 'PDA seeds: [b"order", maker_pubkey, nonce_le_bytes]',
9417
+ "",
9418
+ "Created on first fill (init_if_needed). A missing PDA means the order",
9419
+ "has never been touched (remaining = order.amount)."
9420
+ ],
9421
+ type: {
9422
+ kind: "struct",
9423
+ fields: [
9108
9424
  {
9109
- name: "yes_price_bps",
9110
- type: "u64"
9425
+ name: "maker",
9426
+ type: "pubkey"
9111
9427
  },
9112
9428
  {
9113
- name: "no_price_bps",
9429
+ name: "nonce",
9114
9430
  type: "u64"
9115
9431
  },
9116
9432
  {
9117
- name: "yes_cost",
9433
+ name: "filled_amount",
9118
9434
  type: "u64"
9119
9435
  },
9120
9436
  {
9121
- name: "no_cost",
9122
- type: "u64"
9437
+ name: "bump",
9438
+ type: "u8"
9123
9439
  }
9124
9440
  ]
9125
9441
  }
9126
9442
  },
9127
9443
  {
9128
- name: "Order",
9444
+ name: "SignedOrderRecord",
9129
9445
  docs: [
9130
- "Signed order message \u2014 passed as instruction data (not stored on-chain).",
9131
- "The operator verifies the maker's off-chain signature before calling match_*."
9446
+ "On-chain verified order record.",
9447
+ "Created by `register_order` after Ed25519 signature verification.",
9448
+ "Read by match instructions via remaining_accounts.",
9449
+ "Closed (rent returned) when order is fully filled or cancelled.",
9450
+ "",
9451
+ 'PDA seeds: [b"order_record", maker, nonce_le_bytes]'
9132
9452
  ],
9133
9453
  type: {
9134
9454
  kind: "struct",
9135
9455
  fields: [
9136
9456
  {
9137
9457
  name: "maker",
9138
- docs: [
9139
- "Maker's wallet pubkey"
9140
- ],
9141
9458
  type: "pubkey"
9142
9459
  },
9143
9460
  {
9144
9461
  name: "condition",
9145
- docs: [
9146
- "Condition PDA this order belongs to"
9147
- ],
9148
9462
  type: "pubkey"
9149
9463
  },
9150
9464
  {
9151
9465
  name: "token_id",
9152
- docs: [
9153
- "Outcome token: 0=NO, 1=YES"
9154
- ],
9155
9466
  type: "u8"
9156
9467
  },
9157
9468
  {
9158
9469
  name: "side",
9159
- docs: [
9160
- "Side: 0=SELL (maker gives tokens, wants USDC), 1=BUY (maker gives USDC, wants tokens)"
9161
- ],
9162
9470
  type: "u8"
9163
9471
  },
9164
9472
  {
9165
- name: "price_bps",
9166
- docs: [
9167
- "Price in basis points (0-10000). e.g. 6000 = 60 cents per $1 of exposure.",
9168
- "For a BUY: maker pays price_bps / 10000 USDC per token.",
9169
- "For a SELL: maker wants price_bps / 10000 USDC per token."
9170
- ],
9473
+ name: "maker_amount",
9171
9474
  type: "u64"
9172
9475
  },
9173
9476
  {
9174
- name: "amount",
9175
- docs: [
9176
- "Maximum order size in token units (YES or NO tokens, 0 decimals)."
9177
- ],
9477
+ name: "taker_amount",
9178
9478
  type: "u64"
9179
9479
  },
9180
9480
  {
9181
9481
  name: "nonce",
9182
- docs: [
9183
- "Unique nonce per maker \u2014 used for OrderStatus PDA derivation & replay protection."
9184
- ],
9185
9482
  type: "u64"
9186
9483
  },
9187
9484
  {
9188
9485
  name: "expiry",
9189
- docs: [
9190
- "Unix timestamp after which the order is invalid (0 = no expiry)."
9191
- ],
9192
9486
  type: "i64"
9193
- }
9194
- ]
9195
- }
9196
- },
9197
- {
9198
- name: "OrderStatus",
9199
- docs: [
9200
- "Tracks the fill state of an order for replay protection.",
9201
- 'PDA seeds: [b"order", maker_pubkey, nonce_le_bytes]',
9202
- "",
9203
- "Created on first fill (init_if_needed). A missing PDA means the order",
9204
- "has never been touched (remaining = order.amount)."
9205
- ],
9206
- type: {
9207
- kind: "struct",
9208
- fields: [
9209
- {
9210
- name: "maker",
9211
- docs: [
9212
- "The maker who created the order"
9213
- ],
9214
- type: "pubkey"
9215
9487
  },
9216
9488
  {
9217
- name: "nonce",
9218
- docs: [
9219
- "Order nonce (unique per maker)"
9220
- ],
9221
- type: "u64"
9489
+ name: "created_at",
9490
+ type: "i64"
9222
9491
  },
9223
9492
  {
9224
- name: "filled_amount",
9225
- docs: [
9226
- "Amount of collateral (USDC) already filled"
9227
- ],
9493
+ name: "fee",
9228
9494
  type: "u64"
9229
9495
  },
9230
9496
  {
9231
- name: "bump",
9232
- docs: [
9233
- "Bump for this PDA"
9234
- ],
9235
- type: "u8"
9236
- }
9237
- ]
9238
- }
9239
- },
9240
- {
9241
- name: "SignedOrder",
9242
- docs: [
9243
- "Order + 64-byte Ed25519 signature over `order.to_signable_bytes()`.",
9244
- "Passed as instruction data to all match_* instructions.",
9245
- "On-chain: the program verifies the signature exists in the tx",
9246
- "via Ed25519 precompile instructions at known indices."
9247
- ],
9248
- type: {
9249
- kind: "struct",
9250
- fields: [
9497
+ name: "taker",
9498
+ type: "pubkey"
9499
+ },
9251
9500
  {
9252
- name: "order",
9253
- type: {
9254
- defined: {
9255
- name: "Order"
9256
- }
9257
- }
9501
+ name: "signer",
9502
+ type: "pubkey"
9258
9503
  },
9259
9504
  {
9260
- name: "signature",
9261
- type: {
9262
- array: [
9263
- "u8",
9264
- 64
9265
- ]
9266
- }
9505
+ name: "bump",
9506
+ type: "u8"
9267
9507
  }
9268
9508
  ]
9269
9509
  }
@@ -9420,8 +9660,10 @@ var fee_management_default = {
9420
9660
  {
9421
9661
  name: "market_oracle_vault",
9422
9662
  docs: [
9423
- "For admin questions \u2014 not used; pass any account non-writable (no transfer occurs)."
9424
- ]
9663
+ "Writable: tokens are transferred here when is_admin=false.",
9664
+ "For admin questions pass any writable account (no transfer occurs)."
9665
+ ],
9666
+ writable: true
9425
9667
  },
9426
9668
  {
9427
9669
  name: "token_program",
@@ -12982,12 +13224,12 @@ var market_oracle_default = {
12982
13224
  var XMarketSDK = class {
12983
13225
  constructor(config, wallet, marketOwner) {
12984
13226
  this.networkConfig = config;
12985
- this.provider = new anchor4__namespace.AnchorProvider(
13227
+ this.provider = new anchor5__namespace.AnchorProvider(
12986
13228
  new web3_js.Connection(config.rpcUrl, "confirmed"),
12987
13229
  wallet,
12988
13230
  { commitment: "confirmed", preflightCommitment: "confirmed" }
12989
13231
  );
12990
- anchor4__namespace.setProvider(this.provider);
13232
+ anchor5__namespace.setProvider(this.provider);
12991
13233
  this._programIds = config.programIds;
12992
13234
  this._marketOwner = marketOwner ?? wallet.publicKey;
12993
13235
  }
@@ -12996,21 +13238,21 @@ var XMarketSDK = class {
12996
13238
  }
12997
13239
  get oracle() {
12998
13240
  if (!this._oracle) {
12999
- const program = new anchor4__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
13241
+ const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
13000
13242
  this._oracle = new OracleClient(program, this.provider, this._programIds);
13001
13243
  }
13002
13244
  return this._oracle;
13003
13245
  }
13004
13246
  get hook() {
13005
13247
  if (!this._hook) {
13006
- const program = new anchor4__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
13248
+ const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
13007
13249
  this._hook = new HookClient(program, this.provider, this._programIds);
13008
13250
  }
13009
13251
  return this._hook;
13010
13252
  }
13011
13253
  get market() {
13012
13254
  if (!this._market) {
13013
- const program = new anchor4__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
13255
+ const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
13014
13256
  this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
13015
13257
  this._market.ctfClient = this.ctf;
13016
13258
  }
@@ -13018,14 +13260,14 @@ var XMarketSDK = class {
13018
13260
  }
13019
13261
  get ctf() {
13020
13262
  if (!this._ctf) {
13021
- const program = new anchor4__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
13263
+ const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
13022
13264
  this._ctf = new CtfClient(program, this.provider, this._programIds);
13023
13265
  }
13024
13266
  return this._ctf;
13025
13267
  }
13026
13268
  get clob() {
13027
13269
  if (!this._clob) {
13028
- const program = new anchor4__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
13270
+ const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
13029
13271
  this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
13030
13272
  if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
13031
13273
  this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
@@ -13037,7 +13279,7 @@ var XMarketSDK = class {
13037
13279
  get fee() {
13038
13280
  if (!this._fee) {
13039
13281
  if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
13040
- const program = new anchor4__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
13282
+ const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
13041
13283
  this._fee = new FeeManagementClient(program, this.provider, this._programIds);
13042
13284
  }
13043
13285
  return this._fee;
@@ -13045,7 +13287,7 @@ var XMarketSDK = class {
13045
13287
  get presale() {
13046
13288
  if (!this._presale) {
13047
13289
  if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
13048
- const program = new anchor4__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
13290
+ const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
13049
13291
  this._presale = new PresaleClient(program, this.provider, this._programIds);
13050
13292
  }
13051
13293
  return this._presale;
@@ -13053,7 +13295,7 @@ var XMarketSDK = class {
13053
13295
  get marketOracle() {
13054
13296
  if (!this._marketOracle) {
13055
13297
  if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
13056
- const program = new anchor4__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
13298
+ const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
13057
13299
  this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
13058
13300
  }
13059
13301
  return this._marketOracle;
@@ -13067,10 +13309,10 @@ function buildOrder(params) {
13067
13309
  side: params.side,
13068
13310
  makerAmount: params.makerAmount,
13069
13311
  takerAmount: params.takerAmount,
13070
- nonce: params.nonce ?? new BN4__default.default(Date.now()),
13071
- expiry: params.expiry ?? new BN4__default.default(0),
13072
- createdAt: params.createdAt ?? new BN4__default.default(Math.floor(Date.now() / 1e3)),
13073
- fee: params.fee ?? new BN4__default.default(0),
13312
+ nonce: params.nonce ?? new BN5__default.default(Date.now()),
13313
+ expiry: params.expiry ?? new BN5__default.default(0),
13314
+ createdAt: params.createdAt ?? new BN5__default.default(Math.floor(Date.now() / 1e3)),
13315
+ fee: params.fee ?? new BN5__default.default(0),
13074
13316
  taker: params.taker ?? new web3_js.PublicKey(new Uint8Array(32)),
13075
13317
  signer: params.maker
13076
13318
  };
@@ -13093,8 +13335,8 @@ function serializeSignedOrder(signed) {
13093
13335
  function deserializeSignedOrder(bytes) {
13094
13336
  if (bytes.length !== 242) throw new InvalidParamError("SignedOrder must be 242 bytes");
13095
13337
  const readPubkey = (offset) => new web3_js.PublicKey(bytes.slice(offset, offset + 32));
13096
- const readU64 = (offset) => new BN4__default.default(bytes.slice(offset, offset + 8), "le");
13097
- const readI64 = (offset) => new BN4__default.default(bytes.slice(offset, offset + 8), "le");
13338
+ const readU64 = (offset) => new BN5__default.default(bytes.slice(offset, offset + 8), "le");
13339
+ const readI64 = (offset) => new BN5__default.default(bytes.slice(offset, offset + 8), "le");
13098
13340
  const order = {
13099
13341
  maker: readPubkey(0),
13100
13342
  condition: readPubkey(32),
@@ -13143,7 +13385,7 @@ function _detectMatchType(a, b) {
13143
13385
  "Orders with different tokenIds must both be BUY (MINT) or both SELL (MERGE)"
13144
13386
  );
13145
13387
  }
13146
- var MAX_APPROVE_AMOUNT = new BN4__default.default("18446744073709551615");
13388
+ var MAX_APPROVE_AMOUNT = new BN5__default.default("18446744073709551615");
13147
13389
  function buildApproveCollateralTx(collateralMint, signer, payer, delegate, amount = MAX_APPROVE_AMOUNT) {
13148
13390
  const ownerAta = splToken.getAssociatedTokenAddressSync(collateralMint, signer, false, splToken.TOKEN_PROGRAM_ID);
13149
13391
  const approveIx = splToken.createApproveInstruction(