@theliem/xmarket-sdk 3.3.0 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.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
@@ -59,7 +59,10 @@ var SEEDS = {
59
59
  userBuy: Buffer.from("user_buy"),
60
60
  // Market Oracle
61
61
  marketOracle: Buffer.from("market_oracle"),
62
- userClaim: Buffer.from("user_claim")
62
+ userClaim: Buffer.from("user_claim"),
63
+ // Admin Contract
64
+ adminConfig: Buffer.from("admin_config"),
65
+ claimRecord: Buffer.from("claim_record")
63
66
  };
64
67
  var PDA = class {
65
68
  // ─── Question Market ────────────────────────────────────────────────────────
@@ -171,6 +174,14 @@ var PDA = class {
171
174
  programIds.clobExchange
172
175
  );
173
176
  }
177
+ static orderRecord(maker, nonce, programIds) {
178
+ const nonceBuf = Buffer.alloc(8);
179
+ nonceBuf.writeBigUInt64LE(BigInt(nonce.toString()));
180
+ return web3_js.PublicKey.findProgramAddressSync(
181
+ [Buffer.from("order_record"), maker.toBuffer(), nonceBuf],
182
+ programIds.clobExchange
183
+ );
184
+ }
174
185
  // ─── Fee Management ─────────────────────────────────────────────────────────
175
186
  static feeConfig(owner, programIds) {
176
187
  if (!programIds.feeManagement) throw new Error("feeManagement program ID not configured");
@@ -239,6 +250,21 @@ var PDA = class {
239
250
  programIds.marketOracle
240
251
  );
241
252
  }
253
+ // ─── Admin Contract ──────────────────────────────────────────────────────
254
+ static adminConfig(owner, programIds) {
255
+ if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
256
+ return web3_js.PublicKey.findProgramAddressSync(
257
+ [SEEDS.adminConfig, owner.toBuffer()],
258
+ programIds.adminContract
259
+ );
260
+ }
261
+ static claimRecord(conditionId, programIds) {
262
+ if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
263
+ return web3_js.PublicKey.findProgramAddressSync(
264
+ [SEEDS.claimRecord, conditionId],
265
+ programIds.adminContract
266
+ );
267
+ }
242
268
  };
243
269
  function generateQuestionId(content, salt) {
244
270
  const input = content + (salt ?? Date.now());
@@ -299,7 +325,7 @@ var OracleClient = class {
299
325
  return this.program.methods.resolveQuestion(
300
326
  Array.from(questionId),
301
327
  outcomeCount,
302
- payoutNumerators.map((n) => new anchor4__namespace.BN(n))
328
+ payoutNumerators.map((n) => new anchor5__namespace.BN(n))
303
329
  ).accounts({
304
330
  reporter,
305
331
  oracleConfig,
@@ -566,7 +592,7 @@ var MarketClient = class {
566
592
  contentHash: Array.from(contentHash),
567
593
  hookProgram: params.hookProgram,
568
594
  authorizedClob: params.authorizedClob,
569
- expirationTime: new anchor4__namespace.BN(params.expirationTime)
595
+ expirationTime: new anchor5__namespace.BN(params.expirationTime)
570
596
  }).accounts({
571
597
  creator,
572
598
  payer,
@@ -634,6 +660,22 @@ var MarketClient = class {
634
660
  config: this.configPda
635
661
  }).transaction();
636
662
  }
663
+ async growConfig(owner = this.walletPubkey, payer = owner) {
664
+ return this.program.methods.growConfig().accounts({
665
+ payer,
666
+ owner,
667
+ config: this.configPda,
668
+ systemProgram: web3_js.SystemProgram.programId
669
+ }).transaction();
670
+ }
671
+ async restoreConfig(snapshot, owner = this.walletPubkey, payer = owner) {
672
+ return this.program.methods.restoreConfig(Array.from(snapshot)).accounts({
673
+ payer,
674
+ owner,
675
+ config: this.configPda,
676
+ systemProgram: web3_js.SystemProgram.programId
677
+ }).transaction();
678
+ }
637
679
  // ─── Queries ─────────────────────────────────────────────────────────────────
638
680
  async fetchConfig() {
639
681
  try {
@@ -825,13 +867,26 @@ var MarketClient = class {
825
867
  * Whitelist-only: distribute presale vault → 10% agents + 10% company + 80% botmm.
826
868
  * Closes presale_vault ATA and presale PDA after distribution; lamports returned to payer.
827
869
  */
828
- async collectPresaleRevenue(presalePda, currencyMint, referralAddress, companyAddress, botmmAddress, caller = this.walletPubkey, payer = this.walletPubkey) {
870
+ async collectPresaleRevenue(params) {
871
+ const {
872
+ presalePda,
873
+ currencyMint,
874
+ conditionId,
875
+ referralAddress,
876
+ companyAddress,
877
+ adminOwner
878
+ } = params;
879
+ const caller = params.caller ?? this.walletPubkey;
880
+ const payer = params.payer ?? this.walletPubkey;
829
881
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
882
+ if (!this.programIds.adminContract) throw new Error("adminContract program ID not configured");
830
883
  const presaleVault = splToken.getAssociatedTokenAddressSync(currencyMint, presalePda, true);
831
884
  const referralTokenAccount = splToken.getAssociatedTokenAddressSync(currencyMint, referralAddress);
832
885
  const companyTokenAccount = splToken.getAssociatedTokenAddressSync(currencyMint, companyAddress);
833
- const botmmTokenAccount = splToken.getAssociatedTokenAddressSync(currencyMint, botmmAddress);
834
- return this.program.methods.collectPresaleRevenue().accounts({
886
+ const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
887
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
888
+ const adminVault = splToken.getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
889
+ return this.program.methods.collectPresaleRevenue(Array.from(conditionId)).accounts({
835
890
  caller,
836
891
  config: this.configPda,
837
892
  presale: presalePda,
@@ -839,9 +894,12 @@ var MarketClient = class {
839
894
  currencyMint,
840
895
  referralTokenAccount,
841
896
  companyTokenAccount,
842
- botmmTokenAccount,
897
+ adminVault,
898
+ adminConfig,
899
+ claimRecord,
843
900
  payer,
844
901
  presaleProgram: this.programIds.presale,
902
+ adminProgram: this.programIds.adminContract,
845
903
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
846
904
  associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
847
905
  systemProgram: web3_js.SystemProgram.programId
@@ -1033,7 +1091,21 @@ var CtfClient = class {
1033
1091
  const userYesAta = splToken.getAssociatedTokenAddressSync(yesMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
1034
1092
  const userNoAta = splToken.getAssociatedTokenAddressSync(noMint, user, false, splToken.TOKEN_2022_PROGRAM_ID);
1035
1093
  const userCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, user);
1036
- return this.program.methods.redeemPositions().accounts({
1094
+ const createYesAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(
1095
+ payer,
1096
+ userYesAta,
1097
+ user,
1098
+ yesMint,
1099
+ splToken.TOKEN_2022_PROGRAM_ID
1100
+ );
1101
+ const createNoAtaIx = splToken.createAssociatedTokenAccountIdempotentInstruction(
1102
+ payer,
1103
+ userNoAta,
1104
+ user,
1105
+ noMint,
1106
+ splToken.TOKEN_2022_PROGRAM_ID
1107
+ );
1108
+ const redeemIx = await this.program.methods.redeemPositions().accounts({
1037
1109
  user,
1038
1110
  payer,
1039
1111
  condition,
@@ -1049,14 +1121,17 @@ var CtfClient = class {
1049
1121
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
1050
1122
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1051
1123
  systemProgram: web3_js.SystemProgram.programId
1052
- }).transaction();
1124
+ }).instruction();
1125
+ const tx = new web3_js.Transaction();
1126
+ tx.add(createYesAtaIx, createNoAtaIx, redeemIx);
1127
+ return tx;
1053
1128
  }
1054
1129
  /**
1055
1130
  * Oracle directly resolves a condition with payout numerators.
1056
1131
  * Bypasses QuestionMarket — only for oracle-owned conditions.
1057
1132
  */
1058
1133
  async reportPayouts(condition, payoutNumerators) {
1059
- const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor4__namespace.BN(n))).accounts({
1134
+ const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor5__namespace.BN(n))).accounts({
1060
1135
  oracle: this.walletPubkey,
1061
1136
  condition
1062
1137
  }).rpc();
@@ -1287,57 +1362,60 @@ var ClobClient = class {
1287
1362
  }
1288
1363
  /**
1289
1364
  * 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.
1365
+ * Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
1293
1366
  */
1294
- async ensureAlt(condition, collateralMint, buyerPubkey, buyerNonce, makers) {
1367
+ async ensureAlt(condition, collateralMint, takerSigned, makers) {
1295
1368
  const cacheKey = condition.toBase58();
1296
1369
  if (this._altCache.has(cacheKey)) {
1297
1370
  return this._altCache.get(cacheKey);
1298
1371
  }
1299
1372
  const { connection } = this.provider;
1300
1373
  const payer = this.walletPubkey;
1374
+ const taker = takerSigned.order.maker;
1375
+ const takerNonce = takerSigned.order.nonce;
1376
+ const tokenId = takerSigned.order.tokenId;
1301
1377
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1378
+ const [noMint] = PDA.noMint(condition, this.programIds);
1302
1379
  const [extraAccountMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
1303
1380
  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);
1381
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1382
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1383
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1306
1384
  const clobConfigPda = this.configPda();
1385
+ const outcomeMint = tokenId === 1 ? yesMint : noMint;
1307
1386
  const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
1308
1387
  const addresses = [
1309
- // instruction program IDs — must be in ALT to keep static keys minimal
1310
1388
  web3_js.Ed25519Program.programId,
1311
1389
  this.programIds.clobExchange,
1312
- // other programs
1313
1390
  this.programIds.conditionalTokens,
1314
1391
  this.programIds.hook,
1315
1392
  splToken.TOKEN_PROGRAM_ID,
1316
1393
  splToken.TOKEN_2022_PROGRAM_ID,
1317
1394
  web3_js.SystemProgram.programId,
1318
1395
  web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
1319
- // config PDAs
1320
1396
  clobConfigPda,
1321
1397
  hookConfig,
1322
- // condition PDAs
1323
1398
  condition,
1324
1399
  yesMint,
1400
+ noMint,
1325
1401
  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
1402
+ taker,
1403
+ splToken.getAssociatedTokenAddressSync(collateralMint, taker),
1404
+ splToken.getAssociatedTokenAddressSync(outcomeMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID),
1405
+ takerPosition,
1406
+ takerOrderStatus,
1407
+ takerOrderRecord
1332
1408
  ];
1333
1409
  if (feeRecipientAddr) addresses.push(feeRecipientAddr);
1334
1410
  for (const m of makers) {
1335
1411
  const seller = m.order.maker;
1336
- const [sellerPos] = PDA.position(condition, 1, seller, this.programIds);
1412
+ const [sellerPos] = PDA.position(condition, tokenId, seller, this.programIds);
1337
1413
  const [sellerStatus] = PDA.orderStatus(seller, m.order.nonce, this.programIds);
1414
+ const [sellerRecord] = PDA.orderRecord(seller, m.order.nonce, this.programIds);
1338
1415
  addresses.push(
1339
1416
  seller,
1340
- splToken.getAssociatedTokenAddressSync(yesMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID),
1417
+ sellerRecord,
1418
+ splToken.getAssociatedTokenAddressSync(outcomeMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID),
1341
1419
  splToken.getAssociatedTokenAddressSync(collateralMint, seller),
1342
1420
  sellerPos,
1343
1421
  sellerStatus
@@ -1385,34 +1463,42 @@ var ClobClient = class {
1385
1463
  }
1386
1464
  throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
1387
1465
  }
1388
- async _sendLegacyTx(instructions) {
1466
+ async _sendLegacyTxSig(instructions) {
1389
1467
  const { connection } = this.provider;
1390
1468
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1391
- const { Transaction: Transaction7 } = await import('@solana/web3.js');
1392
- const tx = new Transaction7();
1469
+ const { Transaction: Transaction8 } = await import('@solana/web3.js');
1470
+ const tx = new Transaction8();
1393
1471
  tx.recentBlockhash = blockhash;
1394
1472
  tx.feePayer = this.walletPubkey;
1395
1473
  tx.add(...instructions);
1396
1474
  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");
1475
+ const sig = await connection.sendRawTransaction(signed.serialize(), { skipPreflight: true });
1476
+ const result = await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, "confirmed");
1477
+ if (result.value.err) {
1478
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1479
+ const logs = txInfo?.meta?.logMessages ?? [];
1480
+ const err = new Error(`Register tx failed: ${JSON.stringify(result.value.err)}
1481
+ ${logs.join("\n")}`);
1482
+ err.logs = logs;
1483
+ throw err;
1484
+ }
1485
+ return sig;
1486
+ }
1487
+ async _sendLegacyTx(instructions) {
1488
+ await this._sendLegacyTxSig(instructions);
1399
1489
  }
1400
1490
  /**
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).
1491
+ * Send a match transaction as versioned (v0) with optional ALT.
1492
+ * Both operator wallet and payer (this.provider.wallet) sign.
1408
1493
  */
1409
1494
  async sendMatchTx(instructions, lookupTable, whitelistedWallet) {
1410
1495
  const { connection } = this.provider;
1411
1496
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1497
+ const cuLimit = web3_js.ComputeBudgetProgram.setComputeUnitLimit({ units: 8e5 });
1412
1498
  const message = new web3_js.TransactionMessage({
1413
1499
  payerKey: this.walletPubkey,
1414
1500
  recentBlockhash: blockhash,
1415
- instructions
1501
+ instructions: [cuLimit, ...instructions]
1416
1502
  }).compileToV0Message(lookupTable ? [lookupTable] : []);
1417
1503
  const vtx = new web3_js.VersionedTransaction(message);
1418
1504
  const signers = [this.provider.wallet.payer];
@@ -1421,19 +1507,67 @@ var ClobClient = class {
1421
1507
  }
1422
1508
  vtx.sign(signers);
1423
1509
  const sig = await connection.sendRawTransaction(vtx.serialize(), {
1424
- skipPreflight: false
1510
+ skipPreflight: true
1425
1511
  });
1426
- await connection.confirmTransaction(
1512
+ const result = await connection.confirmTransaction(
1427
1513
  { signature: sig, blockhash, lastValidBlockHeight },
1428
1514
  "confirmed"
1429
1515
  );
1516
+ if (result.value.err) {
1517
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1518
+ const logs = txInfo?.meta?.logMessages ?? [];
1519
+ const err = new Error(`Match tx failed: ${JSON.stringify(result.value.err)}
1520
+ ${logs.join("\n")}`);
1521
+ err.logs = logs;
1522
+ throw err;
1523
+ }
1430
1524
  return sig;
1431
1525
  }
1432
1526
  configPda() {
1433
1527
  return PDA.clobConfig(this.programIds)[0];
1434
1528
  }
1435
- // ─── Instructions ────────────────────────────────────────────────────────────
1436
- /** One-time setup. Caller becomes admin. */
1529
+ // ─── Register / Cancel ───────────────────────────────────────────────────────
1530
+ /**
1531
+ * Register a signed order on-chain.
1532
+ * Sends Ed25519 precompile ix + register_order ix in one legacy tx.
1533
+ * Called at match time (engine-triggered), not at order placement.
1534
+ */
1535
+ async registerOrder(signed) {
1536
+ const nonce = signed.order.nonce;
1537
+ const orderSigner = signed.order.maker;
1538
+ const [orderRecord] = PDA.orderRecord(orderSigner, nonce, this.programIds);
1539
+ const ed25519Ix = buildBatchedEd25519Instruction([signed]);
1540
+ const [orderStatus] = PDA.orderStatus(orderSigner, nonce, this.programIds);
1541
+ const registerIx = await this.program.methods.registerOrder(nonce).accounts({
1542
+ payer: this.walletPubkey,
1543
+ clobConfig: this.configPda(),
1544
+ ixSysvar: IX_SYSVAR,
1545
+ orderSigner,
1546
+ orderRecord,
1547
+ orderStatus,
1548
+ systemProgram: web3_js.SystemProgram.programId
1549
+ }).instruction();
1550
+ return this._sendLegacyTxSig([ed25519Ix, registerIx]);
1551
+ }
1552
+ /** Register only if the PDA doesn't exist yet (idempotent). */
1553
+ async registerOrderIfNeeded(signed) {
1554
+ const [pda] = PDA.orderRecord(signed.order.maker, signed.order.nonce, this.programIds);
1555
+ const existing = await this.program.account.signedOrderRecord.fetchNullable(pda);
1556
+ if (!existing) {
1557
+ await this.registerOrder(signed);
1558
+ }
1559
+ }
1560
+ /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
1561
+ async cancelOrder(nonce) {
1562
+ const [orderRecord] = PDA.orderRecord(this.walletPubkey, nonce, this.programIds);
1563
+ const sig = await this.program.methods.cancelOrder(nonce).accounts({
1564
+ maker: this.walletPubkey,
1565
+ orderRecord,
1566
+ systemProgram: web3_js.SystemProgram.programId
1567
+ }).rpc();
1568
+ return { signature: sig };
1569
+ }
1570
+ // ─── Admin ───────────────────────────────────────────────────────────────────
1437
1571
  async initialize(operators, feeRecipient, feeRateBps) {
1438
1572
  const sig = await this.program.methods.initializeClob(
1439
1573
  operators,
@@ -1447,7 +1581,6 @@ var ClobClient = class {
1447
1581
  }).rpc();
1448
1582
  return { signature: sig };
1449
1583
  }
1450
- /** Admin adds an operator to the whitelist. */
1451
1584
  async addOperator(operator) {
1452
1585
  const sig = await this.program.methods.addOperator(operator).accounts({
1453
1586
  admin: this.walletPubkey,
@@ -1455,7 +1588,6 @@ var ClobClient = class {
1455
1588
  }).rpc();
1456
1589
  return { signature: sig };
1457
1590
  }
1458
- /** Admin removes an operator from the whitelist. */
1459
1591
  async removeOperator(operator) {
1460
1592
  const sig = await this.program.methods.removeOperator(operator).accounts({
1461
1593
  admin: this.walletPubkey,
@@ -1463,7 +1595,6 @@ var ClobClient = class {
1463
1595
  }).rpc();
1464
1596
  return { signature: sig };
1465
1597
  }
1466
- /** Admin pause/unpause the CLOB. */
1467
1598
  async setPaused(paused) {
1468
1599
  const sig = await this.program.methods.setPaused(paused).accounts({
1469
1600
  admin: this.walletPubkey,
@@ -1471,9 +1602,6 @@ var ClobClient = class {
1471
1602
  }).rpc();
1472
1603
  return { signature: sig };
1473
1604
  }
1474
- /**
1475
- * Emergency reset of CLOB config (upgrade authority only).
1476
- */
1477
1605
  async forceResetClob(programData, newAdmin, newOperators, newFeeRecipient, newFeeRateBps) {
1478
1606
  const sig = await this.program.methods.forceResetClob(newAdmin, newOperators, newFeeRecipient, newFeeRateBps).accounts({
1479
1607
  upgradeAuthority: this.walletPubkey,
@@ -1482,31 +1610,44 @@ var ClobClient = class {
1482
1610
  }).rpc();
1483
1611
  return { signature: sig };
1484
1612
  }
1613
+ // ─── Match instructions ───────────────────────────────────────────────────────
1485
1614
  /**
1486
- * COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
1487
- *
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.
1615
+ * Build match_complementary instruction (no Ed25519 OrderRecord PDAs used).
1496
1616
  *
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.
1617
+ * remaining_accounts layout:
1618
+ * [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
1619
+ * [extraAccountMetaList, hookConfig, hookProgram]
1620
+ * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
1500
1621
  */
1501
- async buildMatchComplementaryIxs(buySigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1502
- const condition = buySigned.order.condition;
1503
- const tokenId = buySigned.order.tokenId;
1622
+ async buildMatchComplementaryIxs(takerSigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1623
+ const condition = takerSigned.order.condition;
1624
+ const tokenId = takerSigned.order.tokenId;
1625
+ const taker = takerSigned.order.maker;
1626
+ const takerNonce = takerSigned.order.nonce;
1627
+ const fillAmount = opts?.fillAmount ?? new anchor5__namespace.BN("18446744073709551615");
1504
1628
  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);
1629
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1630
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, taker);
1631
+ const takerTokenAccount = splToken.getAssociatedTokenAddressSync(outcomeMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID);
1632
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1633
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1634
+ const makerAccounts = [];
1635
+ for (const ms of makersSigned) {
1636
+ const seller = ms.order.maker;
1637
+ const [sellerRecord] = PDA.orderRecord(seller, ms.order.nonce, this.programIds);
1638
+ const sellerToken = splToken.getAssociatedTokenAddressSync(outcomeMint, seller, false, splToken.TOKEN_2022_PROGRAM_ID);
1639
+ const sellerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, seller);
1640
+ const [sellerPosition] = PDA.position(condition, tokenId, seller, this.programIds);
1641
+ const [sellerStatus] = PDA.orderStatus(seller, ms.order.nonce, this.programIds);
1642
+ makerAccounts.push(
1643
+ { pubkey: seller, isSigner: false, isWritable: false },
1644
+ { pubkey: sellerRecord, isSigner: false, isWritable: false },
1645
+ { pubkey: sellerToken, isSigner: false, isWritable: true },
1646
+ { pubkey: sellerCollateral, isSigner: false, isWritable: true },
1647
+ { pubkey: sellerPosition, isSigner: false, isWritable: true },
1648
+ { pubkey: sellerStatus, isSigner: false, isWritable: true }
1649
+ );
1650
+ }
1510
1651
  const [extraAccountMetaList] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
1511
1652
  const [hookConfig] = PDA.hookConfig(this.programIds);
1512
1653
  const hookAccounts = [
@@ -1514,22 +1655,8 @@ var ClobClient = class {
1514
1655
  { pubkey: hookConfig, isSigner: false, isWritable: false },
1515
1656
  { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
1516
1657
  ];
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
1658
  let feeAccounts = [];
1532
- if (buySigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1659
+ if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1533
1660
  const companyAddr = await this.companyAddress();
1534
1661
  if (companyAddr) {
1535
1662
  const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
@@ -1542,31 +1669,38 @@ var ClobClient = class {
1542
1669
  ];
1543
1670
  }
1544
1671
  }
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({
1672
+ const matchIx = await this.program.methods.matchComplementary(takerNonce, fillAmount).accounts({
1548
1673
  operator,
1549
1674
  payer: this.walletPubkey,
1550
1675
  clobConfig: this.configPda(),
1551
- ixSysvar: IX_SYSVAR,
1552
1676
  condition,
1553
- buyer,
1554
- buyerCollateral,
1555
- buyerTokenAccount,
1556
- buyerPosition,
1557
- buyOrderStatus,
1558
- outcomeMint,
1677
+ taker,
1678
+ takerOrderRecord,
1679
+ takerCollateral,
1680
+ takerTokenAccount,
1681
+ takerPosition,
1682
+ takerOrderStatus,
1559
1683
  feeRecipient,
1684
+ outcomeMint,
1560
1685
  conditionalTokensProgram: this.programIds.conditionalTokens,
1561
1686
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
1562
1687
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
1563
1688
  systemProgram: web3_js.SystemProgram.programId
1564
- }).remainingAccounts([...hookAccounts, ...makerAccounts, ...feeAccounts]).instruction();
1565
- return [ed25519Ix, matchIx];
1689
+ }).remainingAccounts([...makerAccounts, ...hookAccounts, ...feeAccounts]).instruction();
1690
+ return [matchIx];
1566
1691
  }
1567
- async matchComplementary(buySigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1692
+ /**
1693
+ * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
1694
+ * Phase 1: register taker + all makers in parallel.
1695
+ * Phase 2: 1 atomic match tx.
1696
+ */
1697
+ async matchComplementary(takerSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1698
+ await Promise.all([
1699
+ this.registerOrderIfNeeded(takerSigned),
1700
+ ...makersSigned.map((m) => this.registerOrderIfNeeded(m))
1701
+ ]);
1568
1702
  const ixs = await this.buildMatchComplementaryIxs(
1569
- buySigned,
1703
+ takerSigned,
1570
1704
  makersSigned,
1571
1705
  collateralMint,
1572
1706
  feeRecipient,
@@ -1577,160 +1711,167 @@ var ClobClient = class {
1577
1711
  return { signature: sig };
1578
1712
  }
1579
1713
  /**
1580
- * MINT match: 1 YES buyer (taker) + N NO buyers (makers).
1581
- *
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[])
1714
+ * MINT: 1 YES buyer (taker) + N NO buyers (makers).
1715
+ * Phase 1: register taker + all NO makers in parallel.
1716
+ * Phase 2: 1 atomic match tx.
1586
1717
  *
1587
- * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
1718
+ * remaining_accounts per NO maker (5):
1719
+ * [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
1588
1720
  */
1589
- async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1721
+ async matchMintOrders(yesSigned, noMakers, collateralMint, _feeRecipient, operatorWallet, lookupTable) {
1722
+ await Promise.all([
1723
+ this.registerOrderIfNeeded(yesSigned),
1724
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1725
+ ]);
1590
1726
  const condition = yesSigned.order.condition;
1727
+ const taker = yesSigned.order.maker;
1728
+ const takerNonce = yesSigned.order.nonce;
1729
+ const fillAmount = new anchor5__namespace.BN("18446744073709551615");
1591
1730
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1592
1731
  const [noMint] = PDA.noMint(condition, this.programIds);
1593
1732
  const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1594
1733
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1595
1734
  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,
1735
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1736
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, taker);
1737
+ const takerYesToken = splToken.getAssociatedTokenAddressSync(yesMint, taker, false, splToken.TOKEN_2022_PROGRAM_ID);
1738
+ const [takerYesPosition] = PDA.position(condition, 1, taker, this.programIds);
1739
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1740
+ const remainingAccounts = [];
1741
+ for (const nm of noMakers) {
1742
+ const noMaker = nm.order.maker;
1743
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1744
+ const noToken = splToken.getAssociatedTokenAddressSync(noMint, noMaker, false, splToken.TOKEN_2022_PROGRAM_ID);
1745
+ const noCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, noMaker);
1746
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1747
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1748
+ remainingAccounts.push(
1749
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1750
+ { pubkey: noToken, isSigner: false, isWritable: true },
1751
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1752
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1753
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1754
+ );
1755
+ }
1756
+ const matchIx = await this.program.methods.matchMintOrders(takerNonce, fillAmount).accounts({
1757
+ operator: operatorWallet.publicKey,
1622
1758
  payer: this.walletPubkey,
1623
1759
  clobConfig: this.configPda(),
1624
- ixSysvar: IX_SYSVAR,
1625
1760
  condition,
1626
- buyerYes,
1627
- buyerYesCollateral,
1628
- buyerYesTokenAccount,
1629
- buyerYesPosition,
1630
- yesOrderStatus,
1761
+ taker,
1762
+ takerOrderRecord,
1763
+ takerCollateral,
1764
+ takerYesToken,
1765
+ takerYesPosition,
1766
+ takerOrderStatus,
1631
1767
  collateralVault,
1632
1768
  vaultTokenAccount,
1633
1769
  yesMint,
1634
1770
  noMint,
1635
1771
  mintAuthority,
1772
+ clobAuthority: this.configPda(),
1636
1773
  conditionalTokensProgram: this.programIds.conditionalTokens,
1637
1774
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1638
1775
  systemProgram: web3_js.SystemProgram.programId
1639
- }).remainingAccounts(makerAccounts).instruction();
1640
- const sig = await this.sendMatchTx(
1641
- [...ed25519Ixs, matchIx],
1642
- lookupTable,
1643
- operatorWallet
1644
- );
1776
+ }).remainingAccounts(remainingAccounts).instruction();
1777
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1645
1778
  return { signature: sig };
1646
1779
  }
1647
1780
  /**
1648
- * MERGE match: 1 YES seller (taker) + N NO sellers (makers).
1781
+ * MERGE: 1 YES seller (taker) + N NO sellers (makers).
1782
+ * Phase 1: register taker + all NO makers in parallel.
1783
+ * Phase 2: 1 atomic match tx.
1649
1784
  *
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[])
1654
- *
1655
- * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
1785
+ * remaining_accounts per NO maker (5):
1786
+ * [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
1787
+ * After all makers, optional 5 fee accounts.
1656
1788
  */
1657
- async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1789
+ async matchMergeOrders(yesSigned, noMakers, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1790
+ await Promise.all([
1791
+ this.registerOrderIfNeeded(yesSigned),
1792
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1793
+ ]);
1658
1794
  const condition = yesSigned.order.condition;
1795
+ const sellerYes = yesSigned.order.maker;
1796
+ const takerNonce = yesSigned.order.nonce;
1797
+ const fillAmount = new anchor5__namespace.BN("18446744073709551615");
1659
1798
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1660
1799
  const [noMint] = PDA.noMint(condition, this.programIds);
1800
+ const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1661
1801
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1662
1802
  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,
1803
+ const [takerOrderRecord] = PDA.orderRecord(sellerYes, takerNonce, this.programIds);
1804
+ const takerYesToken = splToken.getAssociatedTokenAddressSync(yesMint, sellerYes, false, splToken.TOKEN_2022_PROGRAM_ID);
1805
+ const [takerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
1806
+ const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, sellerYes);
1807
+ const [takerOrderStatus] = PDA.orderStatus(sellerYes, takerNonce, this.programIds);
1808
+ const remainingAccounts = [];
1809
+ for (const nm of noMakers) {
1810
+ const noMaker = nm.order.maker;
1811
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1812
+ const noToken = splToken.getAssociatedTokenAddressSync(noMint, noMaker, false, splToken.TOKEN_2022_PROGRAM_ID);
1813
+ const noCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, noMaker);
1814
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1815
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1816
+ remainingAccounts.push(
1817
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1818
+ { pubkey: noToken, isSigner: false, isWritable: true },
1819
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1820
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1821
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1822
+ );
1823
+ }
1824
+ if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1825
+ const companyAddr = await this.companyAddress();
1826
+ if (companyAddr) {
1827
+ const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1828
+ remainingAccounts.push(
1829
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1830
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1831
+ { pubkey: PDA.marketFeeOverride(condition, this.programIds)[0], isSigner: false, isWritable: false },
1832
+ { pubkey: splToken.getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1833
+ { pubkey: oracleVault, isSigner: false, isWritable: true }
1834
+ );
1835
+ }
1836
+ }
1837
+ const matchIx = await this.program.methods.matchMergeOrders(takerNonce, fillAmount).accounts({
1838
+ operator: operatorWallet.publicKey,
1689
1839
  payer: this.walletPubkey,
1690
1840
  clobConfig: this.configPda(),
1691
- ixSysvar: IX_SYSVAR,
1692
1841
  condition,
1693
- sellerYes,
1694
- sellerYesTokenAccount,
1695
- sellerYesPosition,
1696
- sellerYesCollateral,
1697
- yesOrderStatus,
1842
+ taker: sellerYes,
1843
+ takerOrderRecord,
1844
+ takerYesToken,
1845
+ takerYesPosition,
1846
+ takerCollateral,
1847
+ takerOrderStatus,
1698
1848
  collateralVault,
1699
1849
  vaultTokenAccount,
1700
1850
  yesMint,
1701
1851
  noMint,
1852
+ mintAuthority,
1702
1853
  feeRecipient,
1854
+ clobAuthority: this.configPda(),
1703
1855
  conditionalTokensProgram: this.programIds.conditionalTokens,
1704
1856
  collateralTokenProgram: splToken.TOKEN_PROGRAM_ID,
1705
1857
  systemProgram: web3_js.SystemProgram.programId
1706
- }).remainingAccounts(makerAccounts).instruction();
1707
- const sig = await this.sendMatchTx(
1708
- [...ed25519Ixs, matchIx],
1709
- lookupTable,
1710
- operatorWallet
1711
- );
1858
+ }).remainingAccounts(remainingAccounts).instruction();
1859
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1712
1860
  return { signature: sig };
1713
1861
  }
1714
1862
  /**
1715
- * Auto-detect match type and execute 1-taker + N-makers in a single transaction.
1716
- *
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 BUY → MINT
1720
- * taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL → MERGE
1721
- * Otherwise → throws InvalidParamError
1863
+ * Auto-detect match type and execute 2-phase:
1864
+ * Phase 1 — register all orders (taker + makers) on-chain in parallel.
1865
+ * Phase 2 1 atomic match transaction.
1722
1866
  *
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.
1867
+ * Detection (pure, no RPC):
1868
+ * taker.tokenId === makers[0].tokenId:
1869
+ * taker BUY + all makers SELL → COMPLEMENTARY
1870
+ * taker.tokenId !== makers[0].tokenId + all BUY → MINT
1871
+ * taker.tokenId !== makers[0].tokenId + all SELL MERGE
1730
1872
  *
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).
1873
+ * @param opts.marketOracleVault Oracle vault ATA for presale markets.
1874
+ * Omit for admin markets (payer used as placeholder).
1734
1875
  */
1735
1876
  async matchOrders(taker, makers, opts) {
1736
1877
  if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
@@ -1742,8 +1883,7 @@ var ClobClient = class {
1742
1883
  const alt = await this.ensureAlt(
1743
1884
  taker.order.condition,
1744
1885
  collateralMint,
1745
- taker.order.maker,
1746
- taker.order.nonce,
1886
+ taker,
1747
1887
  makers
1748
1888
  );
1749
1889
  const t = taker.order;
@@ -1755,9 +1895,9 @@ var ClobClient = class {
1755
1895
  return this.matchComplementary(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1756
1896
  }
1757
1897
  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");
1898
+ return this.matchComplementary(makers[0], [taker, ...makers.slice(1)], collateralMint, feeRecipient, operatorWallet, alt, opts);
1759
1899
  }
1760
- throw new InvalidParamError("COMPLEMENTARY requires taker=BUY, makers=SELL on same tokenId");
1900
+ throw new InvalidParamError("COMPLEMENTARY requires one BUY and one SELL on same tokenId");
1761
1901
  }
1762
1902
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
1763
1903
  const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
@@ -1765,7 +1905,7 @@ var ClobClient = class {
1765
1905
  if (t.tokenId !== 1) throw new InvalidParamError("MINT/MERGE: taker must be YES (tokenId=1)");
1766
1906
  if (!makers.every((m) => m.order.tokenId === 0)) throw new InvalidParamError("MINT/MERGE: makers must be NO (tokenId=0)");
1767
1907
  if (allBuy) return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1768
- return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1908
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1769
1909
  }
1770
1910
  // ─── Queries ─────────────────────────────────────────────────────────────────
1771
1911
  async fetchConfig() {
@@ -1799,6 +1939,15 @@ var ClobClient = class {
1799
1939
  return null;
1800
1940
  }
1801
1941
  }
1942
+ async fetchOrderRecord(maker, nonce) {
1943
+ try {
1944
+ const [pda] = PDA.orderRecord(maker, nonce, this.programIds);
1945
+ const acc = await this.program.account.signedOrderRecord.fetch(pda);
1946
+ return acc;
1947
+ } catch {
1948
+ return null;
1949
+ }
1950
+ }
1802
1951
  };
1803
1952
  var FeeManagementClient = class {
1804
1953
  constructor(program, provider, programIds) {
@@ -2142,6 +2291,139 @@ var MarketOracleClient = class {
2142
2291
  }
2143
2292
  }
2144
2293
  };
2294
+ var AdminClient = class {
2295
+ constructor(program, provider, programIds) {
2296
+ this.program = program;
2297
+ this.provider = provider;
2298
+ this.programIds = programIds;
2299
+ }
2300
+ get walletPubkey() {
2301
+ return this.provider.wallet.publicKey;
2302
+ }
2303
+ get configPda() {
2304
+ const [pda] = PDA.adminConfig(this.walletPubkey, this.programIds);
2305
+ return pda;
2306
+ }
2307
+ configPdaFor(owner) {
2308
+ const [pda] = PDA.adminConfig(owner, this.programIds);
2309
+ return pda;
2310
+ }
2311
+ adminVault(owner, collateralMint) {
2312
+ const configPda = this.configPdaFor(owner);
2313
+ return splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
2314
+ }
2315
+ // ─── Fetch ────────────────────────────────────────────────────────────────
2316
+ async fetchConfig(owner = this.walletPubkey) {
2317
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2318
+ try {
2319
+ const acc = await this.program.account.adminConfig.fetch(configPda);
2320
+ return {
2321
+ version: acc.version,
2322
+ owner: acc.owner,
2323
+ collateralMint: acc.collateralMint,
2324
+ authorizedCaller: acc.authorizedCaller,
2325
+ adminWhitelist: acc.adminWhitelist.slice(0, acc.adminWhitelistLen),
2326
+ whitelist: acc.whitelist.slice(0, acc.whitelistLen),
2327
+ bump: acc.bump
2328
+ };
2329
+ } catch {
2330
+ return null;
2331
+ }
2332
+ }
2333
+ async fetchClaimRecord(conditionId) {
2334
+ const [pda] = PDA.claimRecord(conditionId, this.programIds);
2335
+ try {
2336
+ const acc = await this.program.account.claimRecord.fetch(pda);
2337
+ return {
2338
+ conditionId: acc.conditionId,
2339
+ amount: acc.amount,
2340
+ bump: acc.bump
2341
+ };
2342
+ } catch {
2343
+ return null;
2344
+ }
2345
+ }
2346
+ // ─── Instructions ─────────────────────────────────────────────────────────
2347
+ async initialize(authorizedCaller, collateralMint, owner = this.walletPubkey) {
2348
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2349
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
2350
+ return this.program.methods.initialize(authorizedCaller).accounts({
2351
+ owner,
2352
+ config: configPda,
2353
+ collateralMint,
2354
+ adminVault: vault,
2355
+ tokenProgram: splToken.TOKEN_PROGRAM_ID,
2356
+ associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
2357
+ systemProgram: web3_js.SystemProgram.programId
2358
+ }).transaction();
2359
+ }
2360
+ async addAdmin(address, owner = this.walletPubkey) {
2361
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2362
+ return this.program.methods.addAdmin(address).accounts({ owner, config: configPda }).transaction();
2363
+ }
2364
+ async removeAdmin(address, owner = this.walletPubkey) {
2365
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2366
+ return this.program.methods.removeAdmin(address).accounts({ owner, config: configPda }).transaction();
2367
+ }
2368
+ async addToWhitelist(address, owner, admin = this.walletPubkey, payer = admin) {
2369
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2370
+ return this.program.methods.addToWhitelist(address).accounts({ admin, payer, config: configPda }).transaction();
2371
+ }
2372
+ async removeFromWhitelist(address, owner, admin = this.walletPubkey, payer = admin) {
2373
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2374
+ return this.program.methods.removeFromWhitelist(address).accounts({ admin, payer, config: configPda }).transaction();
2375
+ }
2376
+ /**
2377
+ * Normally called via CPI from question_market (authorized_caller signs).
2378
+ * For testing: initialize with authorizedCaller = wallet, call directly.
2379
+ */
2380
+ async setPresaleAmount(conditionId, amount, owner = this.walletPubkey, caller = this.walletPubkey, payer = caller) {
2381
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2382
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
2383
+ return this.program.methods.setPresaleAmount(Array.from(conditionId), amount).accounts({
2384
+ caller,
2385
+ payer,
2386
+ config: configPda,
2387
+ claimRecord,
2388
+ systemProgram: web3_js.SystemProgram.programId
2389
+ }).transaction();
2390
+ }
2391
+ async claim(conditionId, collateralMint, owner, claimer = this.walletPubkey, payer = claimer) {
2392
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2393
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
2394
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, configPda, true);
2395
+ const claimerAta = splToken.getAssociatedTokenAddressSync(collateralMint, claimer);
2396
+ return this.program.methods.claim(Array.from(conditionId)).accounts({
2397
+ claimer,
2398
+ payer,
2399
+ config: configPda,
2400
+ adminVault: vault,
2401
+ claimRecord,
2402
+ claimerTokenAccount: claimerAta,
2403
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
2404
+ }).transaction();
2405
+ }
2406
+ async updateConfig(authorizedCaller, owner = this.walletPubkey) {
2407
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2408
+ return this.program.methods.updateConfig(authorizedCaller).accounts({ owner, config: configPda }).transaction();
2409
+ }
2410
+ /**
2411
+ * BOTMM sends USDC from their wallet to the market_oracle vault for a condition.
2412
+ * Whitelist-only. No amount validation — caller responsible.
2413
+ */
2414
+ async distributeMarket(conditionId, amount, collateralMint, marketOracleVault, owner, claimer = this.walletPubkey, payer = claimer) {
2415
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2416
+ const claimerTokenAcct = splToken.getAssociatedTokenAddressSync(collateralMint, claimer);
2417
+ return this.program.methods.distributeMarket(Array.from(conditionId), amount).accounts({
2418
+ claimer,
2419
+ payer,
2420
+ config: configPda,
2421
+ claimerTokenAccount: claimerTokenAcct,
2422
+ marketOracleVault,
2423
+ tokenProgram: splToken.TOKEN_PROGRAM_ID
2424
+ }).transaction();
2425
+ }
2426
+ };
2145
2427
 
2146
2428
  // src/idls/oracle.json
2147
2429
  var oracle_default = {
@@ -2838,6 +3120,11 @@ var hook_default = {
2838
3120
  name: "owner",
2839
3121
  signer: true
2840
3122
  },
3123
+ {
3124
+ name: "payer",
3125
+ writable: true,
3126
+ signer: true
3127
+ },
2841
3128
  {
2842
3129
  name: "hook_config",
2843
3130
  writable: true,
@@ -2969,6 +3256,11 @@ var hook_default = {
2969
3256
  name: "owner",
2970
3257
  signer: true
2971
3258
  },
3259
+ {
3260
+ name: "payer",
3261
+ writable: true,
3262
+ signer: true
3263
+ },
2972
3264
  {
2973
3265
  name: "hook_config",
2974
3266
  writable: true,
@@ -3177,6 +3469,11 @@ var hook_default = {
3177
3469
  name: "owner",
3178
3470
  signer: true
3179
3471
  },
3472
+ {
3473
+ name: "payer",
3474
+ writable: true,
3475
+ signer: true
3476
+ },
3180
3477
  {
3181
3478
  name: "hook_config",
3182
3479
  writable: true,
@@ -3228,10 +3525,6 @@ var hook_default = {
3228
3525
  types: [
3229
3526
  {
3230
3527
  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
3528
  type: {
3236
3529
  kind: "struct",
3237
3530
  fields: [
@@ -3241,16 +3534,10 @@ var hook_default = {
3241
3534
  },
3242
3535
  {
3243
3536
  name: "owner",
3244
- docs: [
3245
- "Owner who can update the whitelist"
3246
- ],
3247
3537
  type: "pubkey"
3248
3538
  },
3249
3539
  {
3250
3540
  name: "whitelist",
3251
- docs: [
3252
- "Programs allowed to initiate or receive YES/NO token transfers."
3253
- ],
3254
3541
  type: {
3255
3542
  array: [
3256
3543
  "pubkey",
@@ -3264,16 +3551,10 @@ var hook_default = {
3264
3551
  },
3265
3552
  {
3266
3553
  name: "is_frozen",
3267
- docs: [
3268
- "If true, whitelist can no longer be modified (locked forever)"
3269
- ],
3270
3554
  type: "bool"
3271
3555
  },
3272
3556
  {
3273
3557
  name: "bump",
3274
- docs: [
3275
- "Bump for this PDA"
3276
- ],
3277
3558
  type: "u8"
3278
3559
  },
3279
3560
  {
@@ -3709,7 +3990,7 @@ var question_market_default = {
3709
3990
  {
3710
3991
  name: "presale_vault",
3711
3992
  docs: [
3712
- "Presale USDC vault \u2014 closed inside presale program"
3993
+ "Presale USDC vault \u2014 read balance before CPI, closed inside presale program"
3713
3994
  ],
3714
3995
  writable: true
3715
3996
  },
@@ -3719,24 +4000,66 @@ var question_market_default = {
3719
4000
  {
3720
4001
  name: "referral_token_account",
3721
4002
  docs: [
3722
- "Referral address USDC token account"
4003
+ "Referral address USDC token account (10%)"
3723
4004
  ],
3724
4005
  writable: true
3725
4006
  },
3726
4007
  {
3727
4008
  name: "company_token_account",
3728
4009
  docs: [
3729
- "Company address USDC token account"
4010
+ "Company address USDC token account (10%)"
3730
4011
  ],
3731
4012
  writable: true
3732
4013
  },
3733
4014
  {
3734
- name: "botmm_token_account",
4015
+ name: "admin_vault",
3735
4016
  docs: [
3736
- "BOTMM token account (receives ~80%)"
4017
+ "admin_contract vault ATA \u2014 receives 80% instead of BOTMM wallet directly"
3737
4018
  ],
3738
4019
  writable: true
3739
4020
  },
4021
+ {
4022
+ name: "admin_config",
4023
+ docs: [
4024
+ "admin_contract config PDA"
4025
+ ]
4026
+ },
4027
+ {
4028
+ name: "claim_record",
4029
+ docs: [
4030
+ "ClaimRecord PDA for this conditionId (created by admin_contract CPI)"
4031
+ ],
4032
+ writable: true,
4033
+ pda: {
4034
+ seeds: [
4035
+ {
4036
+ kind: "const",
4037
+ value: [
4038
+ 99,
4039
+ 108,
4040
+ 97,
4041
+ 105,
4042
+ 109,
4043
+ 95,
4044
+ 114,
4045
+ 101,
4046
+ 99,
4047
+ 111,
4048
+ 114,
4049
+ 100
4050
+ ]
4051
+ },
4052
+ {
4053
+ kind: "arg",
4054
+ path: "condition_id"
4055
+ }
4056
+ ],
4057
+ program: {
4058
+ kind: "account",
4059
+ path: "admin_program"
4060
+ }
4061
+ }
4062
+ },
3740
4063
  {
3741
4064
  name: "payer",
3742
4065
  docs: [
@@ -3748,6 +4071,10 @@ var question_market_default = {
3748
4071
  name: "presale_program",
3749
4072
  address: "2Rnw1VoEtsUMQ7wkvYZjDehqSqRob6uNkeymDfvKrquB"
3750
4073
  },
4074
+ {
4075
+ name: "admin_program",
4076
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T"
4077
+ },
3751
4078
  {
3752
4079
  name: "token_program",
3753
4080
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -3761,9 +4088,19 @@ var question_market_default = {
3761
4088
  address: "11111111111111111111111111111111"
3762
4089
  }
3763
4090
  ],
3764
- args: []
3765
- },
3766
- {
4091
+ args: [
4092
+ {
4093
+ name: "condition_id",
4094
+ type: {
4095
+ array: [
4096
+ "u8",
4097
+ 32
4098
+ ]
4099
+ }
4100
+ }
4101
+ ]
4102
+ },
4103
+ {
3767
4104
  name: "collect_trading_fee",
3768
4105
  discriminator: [
3769
4106
  97,
@@ -4183,6 +4520,58 @@ var question_market_default = {
4183
4520
  }
4184
4521
  ]
4185
4522
  },
4523
+ {
4524
+ name: "grow_config",
4525
+ discriminator: [
4526
+ 190,
4527
+ 5,
4528
+ 0,
4529
+ 130,
4530
+ 65,
4531
+ 253,
4532
+ 94,
4533
+ 228
4534
+ ],
4535
+ accounts: [
4536
+ {
4537
+ name: "payer",
4538
+ writable: true,
4539
+ signer: true
4540
+ },
4541
+ {
4542
+ name: "owner",
4543
+ signer: true
4544
+ },
4545
+ {
4546
+ name: "config",
4547
+ writable: true,
4548
+ pda: {
4549
+ seeds: [
4550
+ {
4551
+ kind: "const",
4552
+ value: [
4553
+ 99,
4554
+ 111,
4555
+ 110,
4556
+ 102,
4557
+ 105,
4558
+ 103
4559
+ ]
4560
+ },
4561
+ {
4562
+ kind: "account",
4563
+ path: "owner"
4564
+ }
4565
+ ]
4566
+ }
4567
+ },
4568
+ {
4569
+ name: "system_program",
4570
+ address: "11111111111111111111111111111111"
4571
+ }
4572
+ ],
4573
+ args: []
4574
+ },
4186
4575
  {
4187
4576
  name: "initialize",
4188
4577
  discriminator: [
@@ -4551,6 +4940,63 @@ var question_market_default = {
4551
4940
  }
4552
4941
  ]
4553
4942
  },
4943
+ {
4944
+ name: "restore_config",
4945
+ discriminator: [
4946
+ 95,
4947
+ 203,
4948
+ 226,
4949
+ 92,
4950
+ 60,
4951
+ 222,
4952
+ 192,
4953
+ 221
4954
+ ],
4955
+ accounts: [
4956
+ {
4957
+ name: "payer",
4958
+ writable: true,
4959
+ signer: true
4960
+ },
4961
+ {
4962
+ name: "owner",
4963
+ signer: true
4964
+ },
4965
+ {
4966
+ name: "config",
4967
+ writable: true,
4968
+ pda: {
4969
+ seeds: [
4970
+ {
4971
+ kind: "const",
4972
+ value: [
4973
+ 99,
4974
+ 111,
4975
+ 110,
4976
+ 102,
4977
+ 105,
4978
+ 103
4979
+ ]
4980
+ },
4981
+ {
4982
+ kind: "account",
4983
+ path: "owner"
4984
+ }
4985
+ ]
4986
+ }
4987
+ },
4988
+ {
4989
+ name: "system_program",
4990
+ address: "11111111111111111111111111111111"
4991
+ }
4992
+ ],
4993
+ args: [
4994
+ {
4995
+ name: "snapshot",
4996
+ type: "bytes"
4997
+ }
4998
+ ]
4999
+ },
4554
5000
  {
4555
5001
  name: "update_config",
4556
5002
  discriminator: [
@@ -5583,7 +6029,7 @@ var question_market_default = {
5583
6029
  type: {
5584
6030
  array: [
5585
6031
  "pubkey",
5586
- 10
6032
+ 30
5587
6033
  ]
5588
6034
  }
5589
6035
  },
@@ -7685,9 +8131,6 @@ var clob_exchange_default = {
7685
8131
  instructions: [
7686
8132
  {
7687
8133
  name: "add_operator",
7688
- docs: [
7689
- "Add an authorized operator (off-chain matching engine)."
7690
- ],
7691
8134
  discriminator: [
7692
8135
  149,
7693
8136
  142,
@@ -7736,11 +8179,75 @@ var clob_exchange_default = {
7736
8179
  ]
7737
8180
  },
7738
8181
  {
7739
- name: "force_reset_clob",
8182
+ name: "cancel_order",
7740
8183
  docs: [
7741
- "Force-reset the CLOB config (upgrade authority only).",
7742
- "Use when the original admin keypair is lost."
8184
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
8185
+ ],
8186
+ discriminator: [
8187
+ 95,
8188
+ 129,
8189
+ 237,
8190
+ 240,
8191
+ 8,
8192
+ 49,
8193
+ 223,
8194
+ 132
8195
+ ],
8196
+ accounts: [
8197
+ {
8198
+ name: "maker",
8199
+ docs: [
8200
+ "Must be the order maker/signer"
8201
+ ],
8202
+ signer: true
8203
+ },
8204
+ {
8205
+ name: "order_record",
8206
+ writable: true,
8207
+ pda: {
8208
+ seeds: [
8209
+ {
8210
+ kind: "const",
8211
+ value: [
8212
+ 111,
8213
+ 114,
8214
+ 100,
8215
+ 101,
8216
+ 114,
8217
+ 95,
8218
+ 114,
8219
+ 101,
8220
+ 99,
8221
+ 111,
8222
+ 114,
8223
+ 100
8224
+ ]
8225
+ },
8226
+ {
8227
+ kind: "account",
8228
+ path: "maker"
8229
+ },
8230
+ {
8231
+ kind: "arg",
8232
+ path: "nonce"
8233
+ }
8234
+ ]
8235
+ }
8236
+ },
8237
+ {
8238
+ name: "system_program",
8239
+ address: "11111111111111111111111111111111"
8240
+ }
7743
8241
  ],
8242
+ args: [
8243
+ {
8244
+ name: "nonce",
8245
+ type: "u64"
8246
+ }
8247
+ ]
8248
+ },
8249
+ {
8250
+ name: "force_reset_clob",
7744
8251
  discriminator: [
7745
8252
  96,
7746
8253
  95,
@@ -7815,9 +8322,6 @@ var clob_exchange_default = {
7815
8322
  },
7816
8323
  {
7817
8324
  name: "initialize_clob",
7818
- docs: [
7819
- "Initialize the CLOB global config."
7820
- ],
7821
8325
  discriminator: [
7822
8326
  35,
7823
8327
  69,
@@ -7887,10 +8391,7 @@ var clob_exchange_default = {
7887
8391
  {
7888
8392
  name: "match_complementary",
7889
8393
  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)."
8394
+ "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
7894
8395
  ],
7895
8396
  discriminator: [
7896
8397
  100,
@@ -7905,24 +8406,15 @@ var clob_exchange_default = {
7905
8406
  accounts: [
7906
8407
  {
7907
8408
  name: "operator",
7908
- docs: [
7909
- "Authorized operator (whitelisted signer)"
7910
- ],
7911
8409
  signer: true
7912
8410
  },
7913
8411
  {
7914
8412
  name: "payer",
7915
- docs: [
7916
- "Fee payer \u2014 pays tx fee and PDA rent"
7917
- ],
7918
8413
  writable: true,
7919
8414
  signer: true
7920
8415
  },
7921
8416
  {
7922
8417
  name: "clob_config",
7923
- docs: [
7924
- "CLOB config PDA \u2014 also used as the signing authority for CTF CPIs."
7925
- ],
7926
8418
  writable: true,
7927
8419
  pda: {
7928
8420
  seeds: [
@@ -7945,27 +8437,14 @@ var clob_exchange_default = {
7945
8437
  ]
7946
8438
  }
7947
8439
  },
7948
- {
7949
- name: "ix_sysvar",
7950
- address: "Sysvar1nstructions1111111111111111111111111"
7951
- },
7952
8440
  {
7953
8441
  name: "condition"
7954
8442
  },
7955
8443
  {
7956
- name: "buyer"
7957
- },
7958
- {
7959
- name: "buyer_collateral",
7960
- writable: true
7961
- },
7962
- {
7963
- name: "buyer_token_account",
7964
- writable: true
8444
+ name: "taker"
7965
8445
  },
7966
8446
  {
7967
- name: "buy_order_status",
7968
- writable: true,
8447
+ name: "taker_order_record",
7969
8448
  pda: {
7970
8449
  seeds: [
7971
8450
  {
@@ -7975,33 +8454,41 @@ var clob_exchange_default = {
7975
8454
  114,
7976
8455
  100,
7977
8456
  101,
7978
- 114
8457
+ 114,
8458
+ 95,
8459
+ 114,
8460
+ 101,
8461
+ 99,
8462
+ 111,
8463
+ 114,
8464
+ 100
7979
8465
  ]
7980
8466
  },
7981
8467
  {
7982
8468
  kind: "account",
7983
- path: "buyer"
8469
+ path: "taker"
7984
8470
  },
7985
8471
  {
7986
8472
  kind: "arg",
7987
- path: "buy_signed.order.nonce"
8473
+ path: "taker_nonce"
7988
8474
  }
7989
8475
  ]
7990
8476
  }
7991
8477
  },
7992
8478
  {
7993
- name: "seller"
8479
+ name: "taker_collateral",
8480
+ writable: true
7994
8481
  },
7995
8482
  {
7996
- name: "seller_token_account",
8483
+ name: "taker_token_account",
7997
8484
  writable: true
7998
8485
  },
7999
8486
  {
8000
- name: "seller_collateral",
8487
+ name: "taker_position",
8001
8488
  writable: true
8002
8489
  },
8003
8490
  {
8004
- name: "sell_order_status",
8491
+ name: "taker_order_status",
8005
8492
  writable: true,
8006
8493
  pda: {
8007
8494
  seeds: [
@@ -8017,11 +8504,11 @@ var clob_exchange_default = {
8017
8504
  },
8018
8505
  {
8019
8506
  kind: "account",
8020
- path: "seller"
8507
+ path: "taker"
8021
8508
  },
8022
8509
  {
8023
8510
  kind: "arg",
8024
- path: "sell_signed.order.nonce"
8511
+ path: "taker_nonce"
8025
8512
  }
8026
8513
  ]
8027
8514
  }
@@ -8034,17 +8521,9 @@ var clob_exchange_default = {
8034
8521
  name: "outcome_mint",
8035
8522
  writable: true
8036
8523
  },
8037
- {
8038
- name: "seller_position",
8039
- writable: true
8040
- },
8041
- {
8042
- name: "buyer_position",
8043
- writable: true
8044
- },
8045
8524
  {
8046
8525
  name: "conditional_tokens_program",
8047
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8526
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8048
8527
  },
8049
8528
  {
8050
8529
  name: "token_program",
@@ -8061,20 +8540,8 @@ var clob_exchange_default = {
8061
8540
  ],
8062
8541
  args: [
8063
8542
  {
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
- }
8543
+ name: "taker_nonce",
8544
+ type: "u64"
8078
8545
  },
8079
8546
  {
8080
8547
  name: "fill_amount",
@@ -8085,9 +8552,7 @@ var clob_exchange_default = {
8085
8552
  {
8086
8553
  name: "match_merge_orders",
8087
8554
  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."
8555
+ "MERGE match: 1 taker (YES SELL) + N makers (NO SELL) via remaining_accounts."
8091
8556
  ],
8092
8557
  discriminator: [
8093
8558
  105,
@@ -8102,16 +8567,10 @@ var clob_exchange_default = {
8102
8567
  accounts: [
8103
8568
  {
8104
8569
  name: "operator",
8105
- docs: [
8106
- "Authorized operator (whitelisted signer)"
8107
- ],
8108
8570
  signer: true
8109
8571
  },
8110
8572
  {
8111
8573
  name: "payer",
8112
- docs: [
8113
- "Fee payer \u2014 pays tx fee and PDA rent"
8114
- ],
8115
8574
  writable: true,
8116
8575
  signer: true
8117
8576
  },
@@ -8138,40 +8597,14 @@ var clob_exchange_default = {
8138
8597
  ]
8139
8598
  }
8140
8599
  },
8141
- {
8142
- name: "ix_sysvar",
8143
- address: "Sysvar1nstructions1111111111111111111111111"
8144
- },
8145
8600
  {
8146
8601
  name: "condition"
8147
8602
  },
8148
8603
  {
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
8604
+ name: "taker"
8171
8605
  },
8172
8606
  {
8173
- name: "yes_order_status",
8174
- writable: true,
8607
+ name: "taker_order_record",
8175
8608
  pda: {
8176
8609
  seeds: [
8177
8610
  {
@@ -8181,37 +8614,41 @@ var clob_exchange_default = {
8181
8614
  114,
8182
8615
  100,
8183
8616
  101,
8184
- 114
8185
- ]
8186
- },
8187
- {
8188
- kind: "account",
8189
- path: "seller_yes"
8190
- },
8191
- {
8617
+ 114,
8618
+ 95,
8619
+ 114,
8620
+ 101,
8621
+ 99,
8622
+ 111,
8623
+ 114,
8624
+ 100
8625
+ ]
8626
+ },
8627
+ {
8628
+ kind: "account",
8629
+ path: "taker"
8630
+ },
8631
+ {
8192
8632
  kind: "arg",
8193
- path: "yes_signed.order.nonce"
8633
+ path: "taker_nonce"
8194
8634
  }
8195
8635
  ]
8196
8636
  }
8197
8637
  },
8198
8638
  {
8199
- name: "seller_no"
8200
- },
8201
- {
8202
- name: "seller_no_token_account",
8639
+ name: "taker_yes_token",
8203
8640
  writable: true
8204
8641
  },
8205
8642
  {
8206
- name: "seller_no_position",
8643
+ name: "taker_yes_position",
8207
8644
  writable: true
8208
8645
  },
8209
8646
  {
8210
- name: "seller_no_collateral",
8647
+ name: "taker_collateral",
8211
8648
  writable: true
8212
8649
  },
8213
8650
  {
8214
- name: "no_order_status",
8651
+ name: "taker_order_status",
8215
8652
  writable: true,
8216
8653
  pda: {
8217
8654
  seeds: [
@@ -8227,11 +8664,11 @@ var clob_exchange_default = {
8227
8664
  },
8228
8665
  {
8229
8666
  kind: "account",
8230
- path: "seller_no"
8667
+ path: "taker"
8231
8668
  },
8232
8669
  {
8233
8670
  kind: "arg",
8234
- path: "no_signed.order.nonce"
8671
+ path: "taker_nonce"
8235
8672
  }
8236
8673
  ]
8237
8674
  }
@@ -8258,16 +8695,10 @@ var clob_exchange_default = {
8258
8695
  },
8259
8696
  {
8260
8697
  name: "fee_recipient",
8261
- docs: [
8262
- "Fee recipient (receives spread)"
8263
- ],
8264
8698
  writable: true
8265
8699
  },
8266
8700
  {
8267
8701
  name: "clob_authority",
8268
- docs: [
8269
- "CLOB authority PDA"
8270
- ],
8271
8702
  pda: {
8272
8703
  seeds: [
8273
8704
  {
@@ -8291,7 +8722,7 @@ var clob_exchange_default = {
8291
8722
  },
8292
8723
  {
8293
8724
  name: "conditional_tokens_program",
8294
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8725
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8295
8726
  },
8296
8727
  {
8297
8728
  name: "collateral_token_program",
@@ -8304,20 +8735,8 @@ var clob_exchange_default = {
8304
8735
  ],
8305
8736
  args: [
8306
8737
  {
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
- }
8738
+ name: "taker_nonce",
8739
+ type: "u64"
8321
8740
  },
8322
8741
  {
8323
8742
  name: "fill_amount",
@@ -8328,9 +8747,7 @@ var clob_exchange_default = {
8328
8747
  {
8329
8748
  name: "match_mint_orders",
8330
8749
  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."
8750
+ "MINT match: 1 taker (YES BUY) + N makers (NO BUY) via remaining_accounts."
8334
8751
  ],
8335
8752
  discriminator: [
8336
8753
  146,
@@ -8345,16 +8762,10 @@ var clob_exchange_default = {
8345
8762
  accounts: [
8346
8763
  {
8347
8764
  name: "operator",
8348
- docs: [
8349
- "Authorized operator (whitelisted signer)"
8350
- ],
8351
8765
  signer: true
8352
8766
  },
8353
8767
  {
8354
8768
  name: "payer",
8355
- docs: [
8356
- "Fee payer \u2014 pays tx fee and PDA rent"
8357
- ],
8358
8769
  writable: true,
8359
8770
  signer: true
8360
8771
  },
@@ -8381,31 +8792,14 @@ var clob_exchange_default = {
8381
8792
  ]
8382
8793
  }
8383
8794
  },
8384
- {
8385
- name: "ix_sysvar",
8386
- address: "Sysvar1nstructions1111111111111111111111111"
8387
- },
8388
8795
  {
8389
8796
  name: "condition"
8390
8797
  },
8391
8798
  {
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
8799
+ name: "taker"
8401
8800
  },
8402
8801
  {
8403
- name: "buyer_yes_position",
8404
- writable: true
8405
- },
8406
- {
8407
- name: "yes_order_status",
8408
- writable: true,
8802
+ name: "taker_order_record",
8409
8803
  pda: {
8410
8804
  seeds: [
8411
8805
  {
@@ -8415,37 +8809,41 @@ var clob_exchange_default = {
8415
8809
  114,
8416
8810
  100,
8417
8811
  101,
8418
- 114
8812
+ 114,
8813
+ 95,
8814
+ 114,
8815
+ 101,
8816
+ 99,
8817
+ 111,
8818
+ 114,
8819
+ 100
8419
8820
  ]
8420
8821
  },
8421
8822
  {
8422
8823
  kind: "account",
8423
- path: "buyer_yes"
8824
+ path: "taker"
8424
8825
  },
8425
8826
  {
8426
8827
  kind: "arg",
8427
- path: "yes_signed.order.nonce"
8828
+ path: "taker_nonce"
8428
8829
  }
8429
8830
  ]
8430
8831
  }
8431
8832
  },
8432
8833
  {
8433
- name: "buyer_no"
8434
- },
8435
- {
8436
- name: "buyer_no_collateral",
8834
+ name: "taker_collateral",
8437
8835
  writable: true
8438
8836
  },
8439
8837
  {
8440
- name: "buyer_no_token_account",
8838
+ name: "taker_yes_token",
8441
8839
  writable: true
8442
8840
  },
8443
8841
  {
8444
- name: "buyer_no_position",
8842
+ name: "taker_yes_position",
8445
8843
  writable: true
8446
8844
  },
8447
8845
  {
8448
- name: "no_order_status",
8846
+ name: "taker_order_status",
8449
8847
  writable: true,
8450
8848
  pda: {
8451
8849
  seeds: [
@@ -8461,11 +8859,11 @@ var clob_exchange_default = {
8461
8859
  },
8462
8860
  {
8463
8861
  kind: "account",
8464
- path: "buyer_no"
8862
+ path: "taker"
8465
8863
  },
8466
8864
  {
8467
8865
  kind: "arg",
8468
- path: "no_signed.order.nonce"
8866
+ path: "taker_nonce"
8469
8867
  }
8470
8868
  ]
8471
8869
  }
@@ -8492,9 +8890,6 @@ var clob_exchange_default = {
8492
8890
  },
8493
8891
  {
8494
8892
  name: "clob_authority",
8495
- docs: [
8496
- "CLOB authority PDA (signs CTF CPI)"
8497
- ],
8498
8893
  pda: {
8499
8894
  seeds: [
8500
8895
  {
@@ -8518,7 +8913,7 @@ var clob_exchange_default = {
8518
8913
  },
8519
8914
  {
8520
8915
  name: "conditional_tokens_program",
8521
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8916
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8522
8917
  },
8523
8918
  {
8524
8919
  name: "collateral_token_program",
@@ -8531,32 +8926,194 @@ var clob_exchange_default = {
8531
8926
  ],
8532
8927
  args: [
8533
8928
  {
8534
- name: "yes_signed",
8535
- type: {
8536
- defined: {
8537
- name: "SignedOrder"
8538
- }
8929
+ name: "taker_nonce",
8930
+ type: "u64"
8931
+ },
8932
+ {
8933
+ name: "fill_amount",
8934
+ type: "u64"
8935
+ }
8936
+ ]
8937
+ },
8938
+ {
8939
+ name: "register_order",
8940
+ docs: [
8941
+ "Register a signed order on-chain (Ed25519 verify at registration time).",
8942
+ "ix[0] must be Ed25519 precompile with 1 entry for order.signer."
8943
+ ],
8944
+ discriminator: [
8945
+ 92,
8946
+ 37,
8947
+ 29,
8948
+ 46,
8949
+ 77,
8950
+ 250,
8951
+ 219,
8952
+ 6
8953
+ ],
8954
+ accounts: [
8955
+ {
8956
+ name: "payer",
8957
+ docs: [
8958
+ "Operator pays rent for the OrderRecord PDA."
8959
+ ],
8960
+ writable: true,
8961
+ signer: true
8962
+ },
8963
+ {
8964
+ name: "clob_config",
8965
+ pda: {
8966
+ seeds: [
8967
+ {
8968
+ kind: "const",
8969
+ value: [
8970
+ 99,
8971
+ 108,
8972
+ 111,
8973
+ 98,
8974
+ 95,
8975
+ 99,
8976
+ 111,
8977
+ 110,
8978
+ 102,
8979
+ 105,
8980
+ 103
8981
+ ]
8982
+ }
8983
+ ]
8539
8984
  }
8540
8985
  },
8541
8986
  {
8542
- name: "no_signed",
8543
- type: {
8544
- defined: {
8545
- name: "SignedOrder"
8546
- }
8987
+ name: "ix_sysvar",
8988
+ address: "Sysvar1nstructions1111111111111111111111111"
8989
+ },
8990
+ {
8991
+ name: "order_signer"
8992
+ },
8993
+ {
8994
+ name: "order_record",
8995
+ writable: true,
8996
+ pda: {
8997
+ seeds: [
8998
+ {
8999
+ kind: "const",
9000
+ value: [
9001
+ 111,
9002
+ 114,
9003
+ 100,
9004
+ 101,
9005
+ 114,
9006
+ 95,
9007
+ 114,
9008
+ 101,
9009
+ 99,
9010
+ 111,
9011
+ 114,
9012
+ 100
9013
+ ]
9014
+ },
9015
+ {
9016
+ kind: "account",
9017
+ path: "order_signer"
9018
+ },
9019
+ {
9020
+ kind: "arg",
9021
+ path: "nonce"
9022
+ }
9023
+ ]
8547
9024
  }
8548
9025
  },
8549
9026
  {
8550
- name: "fill_amount",
9027
+ name: "order_status",
9028
+ writable: true,
9029
+ pda: {
9030
+ seeds: [
9031
+ {
9032
+ kind: "const",
9033
+ value: [
9034
+ 111,
9035
+ 114,
9036
+ 100,
9037
+ 101,
9038
+ 114
9039
+ ]
9040
+ },
9041
+ {
9042
+ kind: "account",
9043
+ path: "order_signer"
9044
+ },
9045
+ {
9046
+ kind: "arg",
9047
+ path: "nonce"
9048
+ }
9049
+ ]
9050
+ }
9051
+ },
9052
+ {
9053
+ name: "system_program",
9054
+ address: "11111111111111111111111111111111"
9055
+ }
9056
+ ],
9057
+ args: [
9058
+ {
9059
+ name: "nonce",
8551
9060
  type: "u64"
8552
9061
  }
8553
9062
  ]
8554
9063
  },
8555
9064
  {
8556
- name: "remove_operator",
8557
- docs: [
8558
- "Remove an operator."
9065
+ name: "reinit_clob",
9066
+ discriminator: [
9067
+ 41,
9068
+ 95,
9069
+ 240,
9070
+ 222,
9071
+ 95,
9072
+ 170,
9073
+ 14,
9074
+ 224
9075
+ ],
9076
+ accounts: [
9077
+ {
9078
+ name: "upgrade_authority",
9079
+ writable: true,
9080
+ signer: true
9081
+ },
9082
+ {
9083
+ name: "program_data"
9084
+ },
9085
+ {
9086
+ name: "clob_config",
9087
+ writable: true
9088
+ }
8559
9089
  ],
9090
+ args: [
9091
+ {
9092
+ name: "new_admin",
9093
+ type: "pubkey"
9094
+ },
9095
+ {
9096
+ name: "new_operators",
9097
+ type: {
9098
+ vec: "pubkey"
9099
+ }
9100
+ },
9101
+ {
9102
+ name: "new_fee_recipient",
9103
+ type: "pubkey"
9104
+ },
9105
+ {
9106
+ name: "new_fee_rate_bps",
9107
+ type: "u16"
9108
+ },
9109
+ {
9110
+ name: "conditional_tokens_program",
9111
+ type: "pubkey"
9112
+ }
9113
+ ]
9114
+ },
9115
+ {
9116
+ name: "remove_operator",
8560
9117
  discriminator: [
8561
9118
  84,
8562
9119
  183,
@@ -8606,9 +9163,6 @@ var clob_exchange_default = {
8606
9163
  },
8607
9164
  {
8608
9165
  name: "set_paused",
8609
- docs: [
8610
- "Pause or unpause the CLOB (admin only)."
8611
- ],
8612
9166
  discriminator: [
8613
9167
  91,
8614
9168
  60,
@@ -8683,6 +9237,19 @@ var clob_exchange_default = {
8683
9237
  65,
8684
9238
  3
8685
9239
  ]
9240
+ },
9241
+ {
9242
+ name: "SignedOrderRecord",
9243
+ discriminator: [
9244
+ 16,
9245
+ 167,
9246
+ 189,
9247
+ 166,
9248
+ 85,
9249
+ 0,
9250
+ 231,
9251
+ 55
9252
+ ]
8686
9253
  }
8687
9254
  ],
8688
9255
  events: [
@@ -8877,29 +9444,13 @@ var clob_exchange_default = {
8877
9444
  type: "pubkey"
8878
9445
  },
8879
9446
  {
8880
- name: "buyer",
8881
- type: "pubkey"
8882
- },
8883
- {
8884
- name: "seller",
9447
+ name: "taker",
8885
9448
  type: "pubkey"
8886
9449
  },
8887
- {
8888
- name: "token_id",
8889
- type: "u8"
8890
- },
8891
9450
  {
8892
9451
  name: "fill_amount",
8893
9452
  type: "u64"
8894
9453
  },
8895
- {
8896
- name: "price_bps",
8897
- type: "u64"
8898
- },
8899
- {
8900
- name: "usdc_transferred",
8901
- type: "u64"
8902
- },
8903
9454
  {
8904
9455
  name: "fee",
8905
9456
  type: "u64"
@@ -9050,33 +9601,13 @@ var clob_exchange_default = {
9050
9601
  type: "pubkey"
9051
9602
  },
9052
9603
  {
9053
- name: "seller_yes",
9054
- type: "pubkey"
9055
- },
9056
- {
9057
- name: "seller_no",
9604
+ name: "taker",
9058
9605
  type: "pubkey"
9059
9606
  },
9060
9607
  {
9061
9608
  name: "fill_amount",
9062
9609
  type: "u64"
9063
9610
  },
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
9611
  {
9081
9612
  name: "fee",
9082
9613
  type: "u64"
@@ -9097,173 +9628,108 @@ var clob_exchange_default = {
9097
9628
  name: "buyer_yes",
9098
9629
  type: "pubkey"
9099
9630
  },
9100
- {
9101
- name: "buyer_no",
9102
- type: "pubkey"
9103
- },
9104
9631
  {
9105
9632
  name: "fill_amount",
9106
9633
  type: "u64"
9107
- },
9634
+ }
9635
+ ]
9636
+ }
9637
+ },
9638
+ {
9639
+ name: "OrderStatus",
9640
+ docs: [
9641
+ "Tracks the fill state of an order for replay protection.",
9642
+ 'PDA seeds: [b"order", maker_pubkey, nonce_le_bytes]',
9643
+ "",
9644
+ "Created on first fill (init_if_needed). A missing PDA means the order",
9645
+ "has never been touched (remaining = order.amount)."
9646
+ ],
9647
+ type: {
9648
+ kind: "struct",
9649
+ fields: [
9108
9650
  {
9109
- name: "yes_price_bps",
9110
- type: "u64"
9651
+ name: "maker",
9652
+ type: "pubkey"
9111
9653
  },
9112
9654
  {
9113
- name: "no_price_bps",
9655
+ name: "nonce",
9114
9656
  type: "u64"
9115
9657
  },
9116
9658
  {
9117
- name: "yes_cost",
9659
+ name: "filled_amount",
9118
9660
  type: "u64"
9119
9661
  },
9120
9662
  {
9121
- name: "no_cost",
9122
- type: "u64"
9663
+ name: "bump",
9664
+ type: "u8"
9123
9665
  }
9124
9666
  ]
9125
9667
  }
9126
9668
  },
9127
9669
  {
9128
- name: "Order",
9670
+ name: "SignedOrderRecord",
9129
9671
  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_*."
9672
+ "On-chain verified order record.",
9673
+ "Created by `register_order` after Ed25519 signature verification.",
9674
+ "Read by match instructions via remaining_accounts.",
9675
+ "Closed (rent returned) when order is fully filled or cancelled.",
9676
+ "",
9677
+ 'PDA seeds: [b"order_record", maker, nonce_le_bytes]'
9132
9678
  ],
9133
9679
  type: {
9134
9680
  kind: "struct",
9135
9681
  fields: [
9136
9682
  {
9137
9683
  name: "maker",
9138
- docs: [
9139
- "Maker's wallet pubkey"
9140
- ],
9141
9684
  type: "pubkey"
9142
9685
  },
9143
9686
  {
9144
9687
  name: "condition",
9145
- docs: [
9146
- "Condition PDA this order belongs to"
9147
- ],
9148
9688
  type: "pubkey"
9149
9689
  },
9150
9690
  {
9151
9691
  name: "token_id",
9152
- docs: [
9153
- "Outcome token: 0=NO, 1=YES"
9154
- ],
9155
9692
  type: "u8"
9156
9693
  },
9157
9694
  {
9158
9695
  name: "side",
9159
- docs: [
9160
- "Side: 0=SELL (maker gives tokens, wants USDC), 1=BUY (maker gives USDC, wants tokens)"
9161
- ],
9162
9696
  type: "u8"
9163
9697
  },
9164
9698
  {
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
- ],
9699
+ name: "maker_amount",
9171
9700
  type: "u64"
9172
9701
  },
9173
9702
  {
9174
- name: "amount",
9175
- docs: [
9176
- "Maximum order size in token units (YES or NO tokens, 0 decimals)."
9177
- ],
9703
+ name: "taker_amount",
9178
9704
  type: "u64"
9179
9705
  },
9180
9706
  {
9181
9707
  name: "nonce",
9182
- docs: [
9183
- "Unique nonce per maker \u2014 used for OrderStatus PDA derivation & replay protection."
9184
- ],
9185
9708
  type: "u64"
9186
9709
  },
9187
9710
  {
9188
9711
  name: "expiry",
9189
- docs: [
9190
- "Unix timestamp after which the order is invalid (0 = no expiry)."
9191
- ],
9192
9712
  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
9713
  },
9216
9714
  {
9217
- name: "nonce",
9218
- docs: [
9219
- "Order nonce (unique per maker)"
9220
- ],
9221
- type: "u64"
9715
+ name: "created_at",
9716
+ type: "i64"
9222
9717
  },
9223
9718
  {
9224
- name: "filled_amount",
9225
- docs: [
9226
- "Amount of collateral (USDC) already filled"
9227
- ],
9719
+ name: "fee",
9228
9720
  type: "u64"
9229
9721
  },
9230
9722
  {
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: [
9723
+ name: "taker",
9724
+ type: "pubkey"
9725
+ },
9251
9726
  {
9252
- name: "order",
9253
- type: {
9254
- defined: {
9255
- name: "Order"
9256
- }
9257
- }
9727
+ name: "signer",
9728
+ type: "pubkey"
9258
9729
  },
9259
9730
  {
9260
- name: "signature",
9261
- type: {
9262
- array: [
9263
- "u8",
9264
- 64
9265
- ]
9266
- }
9731
+ name: "bump",
9732
+ type: "u8"
9267
9733
  }
9268
9734
  ]
9269
9735
  }
@@ -9420,8 +9886,10 @@ var fee_management_default = {
9420
9886
  {
9421
9887
  name: "market_oracle_vault",
9422
9888
  docs: [
9423
- "For admin questions \u2014 not used; pass any account non-writable (no transfer occurs)."
9424
- ]
9889
+ "Writable: tokens are transferred here when is_admin=false.",
9890
+ "For admin questions pass any writable account (no transfer occurs)."
9891
+ ],
9892
+ writable: true
9425
9893
  },
9426
9894
  {
9427
9895
  name: "token_program",
@@ -12978,85 +13446,1067 @@ var market_oracle_default = {
12978
13446
  ]
12979
13447
  };
12980
13448
 
12981
- // src/sdk.ts
12982
- var XMarketSDK = class {
12983
- constructor(config, wallet, marketOwner) {
12984
- this.networkConfig = config;
12985
- this.provider = new anchor4__namespace.AnchorProvider(
12986
- new web3_js.Connection(config.rpcUrl, "confirmed"),
12987
- wallet,
12988
- { commitment: "confirmed", preflightCommitment: "confirmed" }
12989
- );
12990
- anchor4__namespace.setProvider(this.provider);
12991
- this._programIds = config.programIds;
12992
- this._marketOwner = marketOwner ?? wallet.publicKey;
12993
- }
12994
- _withAddress(idl, address) {
12995
- return { ...idl, address: address.toBase58() };
12996
- }
12997
- get oracle() {
12998
- if (!this._oracle) {
12999
- const program = new anchor4__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
13000
- this._oracle = new OracleClient(program, this.provider, this._programIds);
13001
- }
13002
- return this._oracle;
13003
- }
13004
- get hook() {
13005
- if (!this._hook) {
13006
- const program = new anchor4__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
13007
- this._hook = new HookClient(program, this.provider, this._programIds);
13008
- }
13009
- return this._hook;
13010
- }
13011
- get market() {
13012
- if (!this._market) {
13013
- const program = new anchor4__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
13014
- this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
13015
- this._market.ctfClient = this.ctf;
13016
- }
13017
- return this._market;
13018
- }
13019
- get ctf() {
13020
- if (!this._ctf) {
13021
- const program = new anchor4__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
13022
- this._ctf = new CtfClient(program, this.provider, this._programIds);
13023
- }
13024
- return this._ctf;
13025
- }
13026
- get clob() {
13027
- if (!this._clob) {
13028
- const program = new anchor4__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
13029
- this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
13030
- if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
13031
- this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
13032
- this._clob.feeClient = this.fee;
13033
- }
13034
- }
13035
- return this._clob;
13036
- }
13037
- get fee() {
13038
- if (!this._fee) {
13039
- 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);
13041
- this._fee = new FeeManagementClient(program, this.provider, this._programIds);
13042
- }
13043
- return this._fee;
13044
- }
13045
- get presale() {
13046
- if (!this._presale) {
13047
- 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);
13049
- this._presale = new PresaleClient(program, this.provider, this._programIds);
13050
- }
13051
- return this._presale;
13052
- }
13053
- get marketOracle() {
13054
- if (!this._marketOracle) {
13055
- 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);
13057
- this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
13058
- }
13059
- return this._marketOracle;
13449
+ // src/idls/admin_contract.json
13450
+ var admin_contract_default = {
13451
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T",
13452
+ metadata: {
13453
+ name: "admin_contract",
13454
+ version: "0.1.0",
13455
+ spec: "0.1.0",
13456
+ description: "Admin contract for XMarket \u2014 whitelist, presale revenue custody, claim"
13457
+ },
13458
+ instructions: [
13459
+ {
13460
+ name: "add_admin",
13461
+ discriminator: [
13462
+ 177,
13463
+ 236,
13464
+ 33,
13465
+ 205,
13466
+ 124,
13467
+ 152,
13468
+ 55,
13469
+ 186
13470
+ ],
13471
+ accounts: [
13472
+ {
13473
+ name: "owner",
13474
+ signer: true
13475
+ },
13476
+ {
13477
+ name: "config",
13478
+ writable: true,
13479
+ pda: {
13480
+ seeds: [
13481
+ {
13482
+ kind: "const",
13483
+ value: [
13484
+ 97,
13485
+ 100,
13486
+ 109,
13487
+ 105,
13488
+ 110,
13489
+ 95,
13490
+ 99,
13491
+ 111,
13492
+ 110,
13493
+ 102,
13494
+ 105,
13495
+ 103
13496
+ ]
13497
+ },
13498
+ {
13499
+ kind: "account",
13500
+ path: "config.owner",
13501
+ account: "AdminConfig"
13502
+ }
13503
+ ]
13504
+ }
13505
+ }
13506
+ ],
13507
+ args: [
13508
+ {
13509
+ name: "address",
13510
+ type: "pubkey"
13511
+ }
13512
+ ]
13513
+ },
13514
+ {
13515
+ name: "add_to_whitelist",
13516
+ discriminator: [
13517
+ 157,
13518
+ 211,
13519
+ 52,
13520
+ 54,
13521
+ 144,
13522
+ 81,
13523
+ 5,
13524
+ 55
13525
+ ],
13526
+ accounts: [
13527
+ {
13528
+ name: "admin",
13529
+ signer: true
13530
+ },
13531
+ {
13532
+ name: "payer",
13533
+ writable: true,
13534
+ signer: true
13535
+ },
13536
+ {
13537
+ name: "config",
13538
+ writable: true,
13539
+ pda: {
13540
+ seeds: [
13541
+ {
13542
+ kind: "const",
13543
+ value: [
13544
+ 97,
13545
+ 100,
13546
+ 109,
13547
+ 105,
13548
+ 110,
13549
+ 95,
13550
+ 99,
13551
+ 111,
13552
+ 110,
13553
+ 102,
13554
+ 105,
13555
+ 103
13556
+ ]
13557
+ },
13558
+ {
13559
+ kind: "account",
13560
+ path: "config.owner",
13561
+ account: "AdminConfig"
13562
+ }
13563
+ ]
13564
+ }
13565
+ }
13566
+ ],
13567
+ args: [
13568
+ {
13569
+ name: "address",
13570
+ type: "pubkey"
13571
+ }
13572
+ ]
13573
+ },
13574
+ {
13575
+ name: "claim",
13576
+ discriminator: [
13577
+ 62,
13578
+ 198,
13579
+ 214,
13580
+ 193,
13581
+ 213,
13582
+ 159,
13583
+ 108,
13584
+ 210
13585
+ ],
13586
+ accounts: [
13587
+ {
13588
+ name: "claimer",
13589
+ signer: true
13590
+ },
13591
+ {
13592
+ name: "payer",
13593
+ writable: true,
13594
+ signer: true
13595
+ },
13596
+ {
13597
+ name: "config",
13598
+ pda: {
13599
+ seeds: [
13600
+ {
13601
+ kind: "const",
13602
+ value: [
13603
+ 97,
13604
+ 100,
13605
+ 109,
13606
+ 105,
13607
+ 110,
13608
+ 95,
13609
+ 99,
13610
+ 111,
13611
+ 110,
13612
+ 102,
13613
+ 105,
13614
+ 103
13615
+ ]
13616
+ },
13617
+ {
13618
+ kind: "account",
13619
+ path: "config.owner",
13620
+ account: "AdminConfig"
13621
+ }
13622
+ ]
13623
+ }
13624
+ },
13625
+ {
13626
+ name: "admin_vault",
13627
+ docs: [
13628
+ "ATA owned by config PDA"
13629
+ ],
13630
+ writable: true,
13631
+ pda: {
13632
+ seeds: [
13633
+ {
13634
+ kind: "account",
13635
+ path: "config"
13636
+ },
13637
+ {
13638
+ kind: "const",
13639
+ value: [
13640
+ 6,
13641
+ 221,
13642
+ 246,
13643
+ 225,
13644
+ 215,
13645
+ 101,
13646
+ 161,
13647
+ 147,
13648
+ 217,
13649
+ 203,
13650
+ 225,
13651
+ 70,
13652
+ 206,
13653
+ 235,
13654
+ 121,
13655
+ 172,
13656
+ 28,
13657
+ 180,
13658
+ 133,
13659
+ 237,
13660
+ 95,
13661
+ 91,
13662
+ 55,
13663
+ 145,
13664
+ 58,
13665
+ 140,
13666
+ 245,
13667
+ 133,
13668
+ 126,
13669
+ 255,
13670
+ 0,
13671
+ 169
13672
+ ]
13673
+ },
13674
+ {
13675
+ kind: "account",
13676
+ path: "config.collateral_mint",
13677
+ account: "AdminConfig"
13678
+ }
13679
+ ],
13680
+ program: {
13681
+ kind: "const",
13682
+ value: [
13683
+ 140,
13684
+ 151,
13685
+ 37,
13686
+ 143,
13687
+ 78,
13688
+ 36,
13689
+ 137,
13690
+ 241,
13691
+ 187,
13692
+ 61,
13693
+ 16,
13694
+ 41,
13695
+ 20,
13696
+ 142,
13697
+ 13,
13698
+ 131,
13699
+ 11,
13700
+ 90,
13701
+ 19,
13702
+ 153,
13703
+ 218,
13704
+ 255,
13705
+ 16,
13706
+ 132,
13707
+ 4,
13708
+ 142,
13709
+ 123,
13710
+ 216,
13711
+ 219,
13712
+ 233,
13713
+ 248,
13714
+ 89
13715
+ ]
13716
+ }
13717
+ }
13718
+ },
13719
+ {
13720
+ name: "claim_record",
13721
+ writable: true,
13722
+ pda: {
13723
+ seeds: [
13724
+ {
13725
+ kind: "const",
13726
+ value: [
13727
+ 99,
13728
+ 108,
13729
+ 97,
13730
+ 105,
13731
+ 109,
13732
+ 95,
13733
+ 114,
13734
+ 101,
13735
+ 99,
13736
+ 111,
13737
+ 114,
13738
+ 100
13739
+ ]
13740
+ },
13741
+ {
13742
+ kind: "arg",
13743
+ path: "condition_id"
13744
+ }
13745
+ ]
13746
+ }
13747
+ },
13748
+ {
13749
+ name: "claimer_token_account",
13750
+ docs: [
13751
+ "Claimer's USDC token account (receives payout)"
13752
+ ],
13753
+ writable: true
13754
+ },
13755
+ {
13756
+ name: "token_program",
13757
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13758
+ }
13759
+ ],
13760
+ args: [
13761
+ {
13762
+ name: "condition_id",
13763
+ type: {
13764
+ array: [
13765
+ "u8",
13766
+ 32
13767
+ ]
13768
+ }
13769
+ }
13770
+ ]
13771
+ },
13772
+ {
13773
+ name: "distribute_market",
13774
+ discriminator: [
13775
+ 130,
13776
+ 221,
13777
+ 123,
13778
+ 201,
13779
+ 185,
13780
+ 168,
13781
+ 63,
13782
+ 19
13783
+ ],
13784
+ accounts: [
13785
+ {
13786
+ name: "claimer",
13787
+ docs: [
13788
+ "BOTMM \u2014 must be in whitelist"
13789
+ ],
13790
+ signer: true
13791
+ },
13792
+ {
13793
+ name: "payer",
13794
+ writable: true,
13795
+ signer: true
13796
+ },
13797
+ {
13798
+ name: "config",
13799
+ pda: {
13800
+ seeds: [
13801
+ {
13802
+ kind: "const",
13803
+ value: [
13804
+ 97,
13805
+ 100,
13806
+ 109,
13807
+ 105,
13808
+ 110,
13809
+ 95,
13810
+ 99,
13811
+ 111,
13812
+ 110,
13813
+ 102,
13814
+ 105,
13815
+ 103
13816
+ ]
13817
+ },
13818
+ {
13819
+ kind: "account",
13820
+ path: "config.owner",
13821
+ account: "AdminConfig"
13822
+ }
13823
+ ]
13824
+ }
13825
+ },
13826
+ {
13827
+ name: "claimer_token_account",
13828
+ docs: [
13829
+ "BOTMM's USDC token account (source \u2014 claimer signs)"
13830
+ ],
13831
+ writable: true
13832
+ },
13833
+ {
13834
+ name: "market_oracle_vault",
13835
+ docs: [
13836
+ "market_oracle vault \u2014 MST holder reward pool for this condition"
13837
+ ],
13838
+ writable: true
13839
+ },
13840
+ {
13841
+ name: "token_program",
13842
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13843
+ }
13844
+ ],
13845
+ args: [
13846
+ {
13847
+ name: "condition_id",
13848
+ type: {
13849
+ array: [
13850
+ "u8",
13851
+ 32
13852
+ ]
13853
+ }
13854
+ },
13855
+ {
13856
+ name: "amount",
13857
+ type: "u64"
13858
+ }
13859
+ ]
13860
+ },
13861
+ {
13862
+ name: "initialize",
13863
+ discriminator: [
13864
+ 175,
13865
+ 175,
13866
+ 109,
13867
+ 31,
13868
+ 13,
13869
+ 152,
13870
+ 155,
13871
+ 237
13872
+ ],
13873
+ accounts: [
13874
+ {
13875
+ name: "owner",
13876
+ writable: true,
13877
+ signer: true
13878
+ },
13879
+ {
13880
+ name: "config",
13881
+ writable: true,
13882
+ pda: {
13883
+ seeds: [
13884
+ {
13885
+ kind: "const",
13886
+ value: [
13887
+ 97,
13888
+ 100,
13889
+ 109,
13890
+ 105,
13891
+ 110,
13892
+ 95,
13893
+ 99,
13894
+ 111,
13895
+ 110,
13896
+ 102,
13897
+ 105,
13898
+ 103
13899
+ ]
13900
+ },
13901
+ {
13902
+ kind: "account",
13903
+ path: "owner"
13904
+ }
13905
+ ]
13906
+ }
13907
+ },
13908
+ {
13909
+ name: "collateral_mint"
13910
+ },
13911
+ {
13912
+ name: "admin_vault",
13913
+ docs: [
13914
+ "ATA owned by config PDA \u2014 holds USDC for unclaimed presale revenue"
13915
+ ],
13916
+ writable: true,
13917
+ pda: {
13918
+ seeds: [
13919
+ {
13920
+ kind: "account",
13921
+ path: "config"
13922
+ },
13923
+ {
13924
+ kind: "const",
13925
+ value: [
13926
+ 6,
13927
+ 221,
13928
+ 246,
13929
+ 225,
13930
+ 215,
13931
+ 101,
13932
+ 161,
13933
+ 147,
13934
+ 217,
13935
+ 203,
13936
+ 225,
13937
+ 70,
13938
+ 206,
13939
+ 235,
13940
+ 121,
13941
+ 172,
13942
+ 28,
13943
+ 180,
13944
+ 133,
13945
+ 237,
13946
+ 95,
13947
+ 91,
13948
+ 55,
13949
+ 145,
13950
+ 58,
13951
+ 140,
13952
+ 245,
13953
+ 133,
13954
+ 126,
13955
+ 255,
13956
+ 0,
13957
+ 169
13958
+ ]
13959
+ },
13960
+ {
13961
+ kind: "account",
13962
+ path: "collateral_mint"
13963
+ }
13964
+ ],
13965
+ program: {
13966
+ kind: "const",
13967
+ value: [
13968
+ 140,
13969
+ 151,
13970
+ 37,
13971
+ 143,
13972
+ 78,
13973
+ 36,
13974
+ 137,
13975
+ 241,
13976
+ 187,
13977
+ 61,
13978
+ 16,
13979
+ 41,
13980
+ 20,
13981
+ 142,
13982
+ 13,
13983
+ 131,
13984
+ 11,
13985
+ 90,
13986
+ 19,
13987
+ 153,
13988
+ 218,
13989
+ 255,
13990
+ 16,
13991
+ 132,
13992
+ 4,
13993
+ 142,
13994
+ 123,
13995
+ 216,
13996
+ 219,
13997
+ 233,
13998
+ 248,
13999
+ 89
14000
+ ]
14001
+ }
14002
+ }
14003
+ },
14004
+ {
14005
+ name: "token_program",
14006
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
14007
+ },
14008
+ {
14009
+ name: "associated_token_program",
14010
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
14011
+ },
14012
+ {
14013
+ name: "system_program",
14014
+ address: "11111111111111111111111111111111"
14015
+ }
14016
+ ],
14017
+ args: [
14018
+ {
14019
+ name: "authorized_caller",
14020
+ type: "pubkey"
14021
+ }
14022
+ ]
14023
+ },
14024
+ {
14025
+ name: "remove_admin",
14026
+ discriminator: [
14027
+ 74,
14028
+ 202,
14029
+ 71,
14030
+ 106,
14031
+ 252,
14032
+ 31,
14033
+ 72,
14034
+ 183
14035
+ ],
14036
+ accounts: [
14037
+ {
14038
+ name: "owner",
14039
+ signer: true
14040
+ },
14041
+ {
14042
+ name: "config",
14043
+ writable: true,
14044
+ pda: {
14045
+ seeds: [
14046
+ {
14047
+ kind: "const",
14048
+ value: [
14049
+ 97,
14050
+ 100,
14051
+ 109,
14052
+ 105,
14053
+ 110,
14054
+ 95,
14055
+ 99,
14056
+ 111,
14057
+ 110,
14058
+ 102,
14059
+ 105,
14060
+ 103
14061
+ ]
14062
+ },
14063
+ {
14064
+ kind: "account",
14065
+ path: "config.owner",
14066
+ account: "AdminConfig"
14067
+ }
14068
+ ]
14069
+ }
14070
+ }
14071
+ ],
14072
+ args: [
14073
+ {
14074
+ name: "address",
14075
+ type: "pubkey"
14076
+ }
14077
+ ]
14078
+ },
14079
+ {
14080
+ name: "remove_from_whitelist",
14081
+ discriminator: [
14082
+ 7,
14083
+ 144,
14084
+ 216,
14085
+ 239,
14086
+ 243,
14087
+ 236,
14088
+ 193,
14089
+ 235
14090
+ ],
14091
+ accounts: [
14092
+ {
14093
+ name: "admin",
14094
+ signer: true
14095
+ },
14096
+ {
14097
+ name: "payer",
14098
+ writable: true,
14099
+ signer: true
14100
+ },
14101
+ {
14102
+ name: "config",
14103
+ writable: true,
14104
+ pda: {
14105
+ seeds: [
14106
+ {
14107
+ kind: "const",
14108
+ value: [
14109
+ 97,
14110
+ 100,
14111
+ 109,
14112
+ 105,
14113
+ 110,
14114
+ 95,
14115
+ 99,
14116
+ 111,
14117
+ 110,
14118
+ 102,
14119
+ 105,
14120
+ 103
14121
+ ]
14122
+ },
14123
+ {
14124
+ kind: "account",
14125
+ path: "config.owner",
14126
+ account: "AdminConfig"
14127
+ }
14128
+ ]
14129
+ }
14130
+ }
14131
+ ],
14132
+ args: [
14133
+ {
14134
+ name: "address",
14135
+ type: "pubkey"
14136
+ }
14137
+ ]
14138
+ },
14139
+ {
14140
+ name: "set_presale_amount",
14141
+ discriminator: [
14142
+ 73,
14143
+ 71,
14144
+ 238,
14145
+ 3,
14146
+ 202,
14147
+ 163,
14148
+ 8,
14149
+ 254
14150
+ ],
14151
+ accounts: [
14152
+ {
14153
+ name: "caller",
14154
+ docs: [
14155
+ "question_market config PDA \u2014 signs this CPI call via seeds"
14156
+ ],
14157
+ signer: true
14158
+ },
14159
+ {
14160
+ name: "payer",
14161
+ writable: true,
14162
+ signer: true
14163
+ },
14164
+ {
14165
+ name: "config",
14166
+ pda: {
14167
+ seeds: [
14168
+ {
14169
+ kind: "const",
14170
+ value: [
14171
+ 97,
14172
+ 100,
14173
+ 109,
14174
+ 105,
14175
+ 110,
14176
+ 95,
14177
+ 99,
14178
+ 111,
14179
+ 110,
14180
+ 102,
14181
+ 105,
14182
+ 103
14183
+ ]
14184
+ },
14185
+ {
14186
+ kind: "account",
14187
+ path: "config.owner",
14188
+ account: "AdminConfig"
14189
+ }
14190
+ ]
14191
+ }
14192
+ },
14193
+ {
14194
+ name: "claim_record",
14195
+ writable: true,
14196
+ pda: {
14197
+ seeds: [
14198
+ {
14199
+ kind: "const",
14200
+ value: [
14201
+ 99,
14202
+ 108,
14203
+ 97,
14204
+ 105,
14205
+ 109,
14206
+ 95,
14207
+ 114,
14208
+ 101,
14209
+ 99,
14210
+ 111,
14211
+ 114,
14212
+ 100
14213
+ ]
14214
+ },
14215
+ {
14216
+ kind: "arg",
14217
+ path: "condition_id"
14218
+ }
14219
+ ]
14220
+ }
14221
+ },
14222
+ {
14223
+ name: "system_program",
14224
+ address: "11111111111111111111111111111111"
14225
+ }
14226
+ ],
14227
+ args: [
14228
+ {
14229
+ name: "condition_id",
14230
+ type: {
14231
+ array: [
14232
+ "u8",
14233
+ 32
14234
+ ]
14235
+ }
14236
+ },
14237
+ {
14238
+ name: "amount",
14239
+ type: "u64"
14240
+ }
14241
+ ]
14242
+ },
14243
+ {
14244
+ name: "update_config",
14245
+ discriminator: [
14246
+ 29,
14247
+ 158,
14248
+ 252,
14249
+ 191,
14250
+ 10,
14251
+ 83,
14252
+ 219,
14253
+ 99
14254
+ ],
14255
+ accounts: [
14256
+ {
14257
+ name: "owner",
14258
+ signer: true
14259
+ },
14260
+ {
14261
+ name: "config",
14262
+ writable: true,
14263
+ pda: {
14264
+ seeds: [
14265
+ {
14266
+ kind: "const",
14267
+ value: [
14268
+ 97,
14269
+ 100,
14270
+ 109,
14271
+ 105,
14272
+ 110,
14273
+ 95,
14274
+ 99,
14275
+ 111,
14276
+ 110,
14277
+ 102,
14278
+ 105,
14279
+ 103
14280
+ ]
14281
+ },
14282
+ {
14283
+ kind: "account",
14284
+ path: "config.owner",
14285
+ account: "AdminConfig"
14286
+ }
14287
+ ]
14288
+ }
14289
+ }
14290
+ ],
14291
+ args: [
14292
+ {
14293
+ name: "authorized_caller",
14294
+ type: "pubkey"
14295
+ }
14296
+ ]
14297
+ }
14298
+ ],
14299
+ accounts: [
14300
+ {
14301
+ name: "AdminConfig",
14302
+ discriminator: [
14303
+ 156,
14304
+ 10,
14305
+ 79,
14306
+ 161,
14307
+ 71,
14308
+ 9,
14309
+ 62,
14310
+ 77
14311
+ ]
14312
+ },
14313
+ {
14314
+ name: "ClaimRecord",
14315
+ discriminator: [
14316
+ 57,
14317
+ 229,
14318
+ 0,
14319
+ 9,
14320
+ 65,
14321
+ 62,
14322
+ 96,
14323
+ 7
14324
+ ]
14325
+ }
14326
+ ],
14327
+ types: [
14328
+ {
14329
+ name: "AdminConfig",
14330
+ type: {
14331
+ kind: "struct",
14332
+ fields: [
14333
+ {
14334
+ name: "version",
14335
+ type: "u8"
14336
+ },
14337
+ {
14338
+ name: "owner",
14339
+ type: "pubkey"
14340
+ },
14341
+ {
14342
+ name: "collateral_mint",
14343
+ type: "pubkey"
14344
+ },
14345
+ {
14346
+ name: "authorized_caller",
14347
+ docs: [
14348
+ "question_market config PDA \u2014 only this can call set_presale_amount"
14349
+ ],
14350
+ type: "pubkey"
14351
+ },
14352
+ {
14353
+ name: "admin_whitelist",
14354
+ type: {
14355
+ array: [
14356
+ "pubkey",
14357
+ 10
14358
+ ]
14359
+ }
14360
+ },
14361
+ {
14362
+ name: "admin_whitelist_len",
14363
+ type: "u8"
14364
+ },
14365
+ {
14366
+ name: "whitelist",
14367
+ type: {
14368
+ array: [
14369
+ "pubkey",
14370
+ 30
14371
+ ]
14372
+ }
14373
+ },
14374
+ {
14375
+ name: "whitelist_len",
14376
+ type: "u8"
14377
+ },
14378
+ {
14379
+ name: "bump",
14380
+ type: "u8"
14381
+ },
14382
+ {
14383
+ name: "_reserved",
14384
+ type: {
14385
+ array: [
14386
+ "u8",
14387
+ 64
14388
+ ]
14389
+ }
14390
+ }
14391
+ ]
14392
+ }
14393
+ },
14394
+ {
14395
+ name: "ClaimRecord",
14396
+ type: {
14397
+ kind: "struct",
14398
+ fields: [
14399
+ {
14400
+ name: "condition_id",
14401
+ type: {
14402
+ array: [
14403
+ "u8",
14404
+ 32
14405
+ ]
14406
+ }
14407
+ },
14408
+ {
14409
+ name: "amount",
14410
+ type: "u64"
14411
+ },
14412
+ {
14413
+ name: "bump",
14414
+ type: "u8"
14415
+ }
14416
+ ]
14417
+ }
14418
+ }
14419
+ ]
14420
+ };
14421
+
14422
+ // src/sdk.ts
14423
+ var XMarketSDK = class {
14424
+ // lazy-init in get admin()
14425
+ constructor(config, wallet, marketOwner) {
14426
+ this.networkConfig = config;
14427
+ this.provider = new anchor5__namespace.AnchorProvider(
14428
+ new web3_js.Connection(config.rpcUrl, "confirmed"),
14429
+ wallet,
14430
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
14431
+ );
14432
+ anchor5__namespace.setProvider(this.provider);
14433
+ this._programIds = config.programIds;
14434
+ this._marketOwner = marketOwner ?? wallet.publicKey;
14435
+ }
14436
+ _withAddress(idl, address) {
14437
+ return { ...idl, address: address.toBase58() };
14438
+ }
14439
+ get oracle() {
14440
+ if (!this._oracle) {
14441
+ const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
14442
+ this._oracle = new OracleClient(program, this.provider, this._programIds);
14443
+ }
14444
+ return this._oracle;
14445
+ }
14446
+ get hook() {
14447
+ if (!this._hook) {
14448
+ const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
14449
+ this._hook = new HookClient(program, this.provider, this._programIds);
14450
+ }
14451
+ return this._hook;
14452
+ }
14453
+ get market() {
14454
+ if (!this._market) {
14455
+ const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
14456
+ this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
14457
+ this._market.ctfClient = this.ctf;
14458
+ }
14459
+ return this._market;
14460
+ }
14461
+ get ctf() {
14462
+ if (!this._ctf) {
14463
+ const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
14464
+ this._ctf = new CtfClient(program, this.provider, this._programIds);
14465
+ }
14466
+ return this._ctf;
14467
+ }
14468
+ get clob() {
14469
+ if (!this._clob) {
14470
+ const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
14471
+ this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
14472
+ if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
14473
+ this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
14474
+ this._clob.feeClient = this.fee;
14475
+ }
14476
+ }
14477
+ return this._clob;
14478
+ }
14479
+ get fee() {
14480
+ if (!this._fee) {
14481
+ if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
14482
+ const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
14483
+ this._fee = new FeeManagementClient(program, this.provider, this._programIds);
14484
+ }
14485
+ return this._fee;
14486
+ }
14487
+ get presale() {
14488
+ if (!this._presale) {
14489
+ if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
14490
+ const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
14491
+ this._presale = new PresaleClient(program, this.provider, this._programIds);
14492
+ }
14493
+ return this._presale;
14494
+ }
14495
+ get marketOracle() {
14496
+ if (!this._marketOracle) {
14497
+ if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
14498
+ const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
14499
+ this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
14500
+ }
14501
+ return this._marketOracle;
14502
+ }
14503
+ get admin() {
14504
+ if (!this._admin) {
14505
+ if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
14506
+ const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
14507
+ this._admin = new AdminClient(program, this.provider, this._programIds);
14508
+ }
14509
+ return this._admin;
13060
14510
  }
13061
14511
  };
13062
14512
  function buildOrder(params) {
@@ -13067,10 +14517,10 @@ function buildOrder(params) {
13067
14517
  side: params.side,
13068
14518
  makerAmount: params.makerAmount,
13069
14519
  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),
14520
+ nonce: params.nonce ?? new BN5__default.default(Date.now()),
14521
+ expiry: params.expiry ?? new BN5__default.default(0),
14522
+ createdAt: params.createdAt ?? new BN5__default.default(Math.floor(Date.now() / 1e3)),
14523
+ fee: params.fee ?? new BN5__default.default(0),
13074
14524
  taker: params.taker ?? new web3_js.PublicKey(new Uint8Array(32)),
13075
14525
  signer: params.maker
13076
14526
  };
@@ -13093,8 +14543,8 @@ function serializeSignedOrder(signed) {
13093
14543
  function deserializeSignedOrder(bytes) {
13094
14544
  if (bytes.length !== 242) throw new InvalidParamError("SignedOrder must be 242 bytes");
13095
14545
  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");
14546
+ const readU64 = (offset) => new BN5__default.default(bytes.slice(offset, offset + 8), "le");
14547
+ const readI64 = (offset) => new BN5__default.default(bytes.slice(offset, offset + 8), "le");
13098
14548
  const order = {
13099
14549
  maker: readPubkey(0),
13100
14550
  condition: readPubkey(32),
@@ -13143,7 +14593,7 @@ function _detectMatchType(a, b) {
13143
14593
  "Orders with different tokenIds must both be BUY (MINT) or both SELL (MERGE)"
13144
14594
  );
13145
14595
  }
13146
- var MAX_APPROVE_AMOUNT = new BN4__default.default("18446744073709551615");
14596
+ var MAX_APPROVE_AMOUNT = new BN5__default.default("18446744073709551615");
13147
14597
  function buildApproveCollateralTx(collateralMint, signer, payer, delegate, amount = MAX_APPROVE_AMOUNT) {
13148
14598
  const ownerAta = splToken.getAssociatedTokenAddressSync(collateralMint, signer, false, splToken.TOKEN_PROGRAM_ID);
13149
14599
  const approveIx = splToken.createApproveInstruction(
@@ -13188,6 +14638,7 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
13188
14638
  }
13189
14639
 
13190
14640
  exports.AccountNotFoundError = AccountNotFoundError;
14641
+ exports.AdminClient = AdminClient;
13191
14642
  exports.ClobClient = ClobClient;
13192
14643
  exports.CtfClient = CtfClient;
13193
14644
  exports.FEE_DENOMINATOR = FEE_DENOMINATOR;