@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.mjs CHANGED
@@ -1,8 +1,8 @@
1
- import * as anchor4 from '@coral-xyz/anchor';
2
- import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, TransactionMessage, VersionedTransaction, Connection, Transaction } from '@solana/web3.js';
1
+ import * as anchor5 from '@coral-xyz/anchor';
2
+ import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, Transaction, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, TransactionMessage, VersionedTransaction, Connection } from '@solana/web3.js';
3
3
  import { createHash } from 'crypto';
4
- import { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createApproveInstruction } from '@solana/spl-token';
5
- import BN4 from 'bn.js';
4
+ import { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createAssociatedTokenAccountIdempotentInstruction, createApproveInstruction } from '@solana/spl-token';
5
+ import BN5 from 'bn.js';
6
6
  import * as nacl from 'tweetnacl';
7
7
 
8
8
  // src/sdk.ts
@@ -33,7 +33,10 @@ var SEEDS = {
33
33
  userBuy: Buffer.from("user_buy"),
34
34
  // Market Oracle
35
35
  marketOracle: Buffer.from("market_oracle"),
36
- userClaim: Buffer.from("user_claim")
36
+ userClaim: Buffer.from("user_claim"),
37
+ // Admin Contract
38
+ adminConfig: Buffer.from("admin_config"),
39
+ claimRecord: Buffer.from("claim_record")
37
40
  };
38
41
  var PDA = class {
39
42
  // ─── Question Market ────────────────────────────────────────────────────────
@@ -145,6 +148,14 @@ var PDA = class {
145
148
  programIds.clobExchange
146
149
  );
147
150
  }
151
+ static orderRecord(maker, nonce, programIds) {
152
+ const nonceBuf = Buffer.alloc(8);
153
+ nonceBuf.writeBigUInt64LE(BigInt(nonce.toString()));
154
+ return PublicKey.findProgramAddressSync(
155
+ [Buffer.from("order_record"), maker.toBuffer(), nonceBuf],
156
+ programIds.clobExchange
157
+ );
158
+ }
148
159
  // ─── Fee Management ─────────────────────────────────────────────────────────
149
160
  static feeConfig(owner, programIds) {
150
161
  if (!programIds.feeManagement) throw new Error("feeManagement program ID not configured");
@@ -213,6 +224,21 @@ var PDA = class {
213
224
  programIds.marketOracle
214
225
  );
215
226
  }
227
+ // ─── Admin Contract ──────────────────────────────────────────────────────
228
+ static adminConfig(owner, programIds) {
229
+ if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
230
+ return PublicKey.findProgramAddressSync(
231
+ [SEEDS.adminConfig, owner.toBuffer()],
232
+ programIds.adminContract
233
+ );
234
+ }
235
+ static claimRecord(conditionId, programIds) {
236
+ if (!programIds.adminContract) throw new Error("adminContract program ID not configured");
237
+ return PublicKey.findProgramAddressSync(
238
+ [SEEDS.claimRecord, conditionId],
239
+ programIds.adminContract
240
+ );
241
+ }
216
242
  };
217
243
  function generateQuestionId(content, salt) {
218
244
  const input = content + (salt ?? Date.now());
@@ -273,7 +299,7 @@ var OracleClient = class {
273
299
  return this.program.methods.resolveQuestion(
274
300
  Array.from(questionId),
275
301
  outcomeCount,
276
- payoutNumerators.map((n) => new anchor4.BN(n))
302
+ payoutNumerators.map((n) => new anchor5.BN(n))
277
303
  ).accounts({
278
304
  reporter,
279
305
  oracleConfig,
@@ -540,7 +566,7 @@ var MarketClient = class {
540
566
  contentHash: Array.from(contentHash),
541
567
  hookProgram: params.hookProgram,
542
568
  authorizedClob: params.authorizedClob,
543
- expirationTime: new anchor4.BN(params.expirationTime)
569
+ expirationTime: new anchor5.BN(params.expirationTime)
544
570
  }).accounts({
545
571
  creator,
546
572
  payer,
@@ -608,6 +634,22 @@ var MarketClient = class {
608
634
  config: this.configPda
609
635
  }).transaction();
610
636
  }
637
+ async growConfig(owner = this.walletPubkey, payer = owner) {
638
+ return this.program.methods.growConfig().accounts({
639
+ payer,
640
+ owner,
641
+ config: this.configPda,
642
+ systemProgram: SystemProgram.programId
643
+ }).transaction();
644
+ }
645
+ async restoreConfig(snapshot, owner = this.walletPubkey, payer = owner) {
646
+ return this.program.methods.restoreConfig(Array.from(snapshot)).accounts({
647
+ payer,
648
+ owner,
649
+ config: this.configPda,
650
+ systemProgram: SystemProgram.programId
651
+ }).transaction();
652
+ }
611
653
  // ─── Queries ─────────────────────────────────────────────────────────────────
612
654
  async fetchConfig() {
613
655
  try {
@@ -799,13 +841,26 @@ var MarketClient = class {
799
841
  * Whitelist-only: distribute presale vault → 10% agents + 10% company + 80% botmm.
800
842
  * Closes presale_vault ATA and presale PDA after distribution; lamports returned to payer.
801
843
  */
802
- async collectPresaleRevenue(presalePda, currencyMint, referralAddress, companyAddress, botmmAddress, caller = this.walletPubkey, payer = this.walletPubkey) {
844
+ async collectPresaleRevenue(params) {
845
+ const {
846
+ presalePda,
847
+ currencyMint,
848
+ conditionId,
849
+ referralAddress,
850
+ companyAddress,
851
+ adminOwner
852
+ } = params;
853
+ const caller = params.caller ?? this.walletPubkey;
854
+ const payer = params.payer ?? this.walletPubkey;
803
855
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
856
+ if (!this.programIds.adminContract) throw new Error("adminContract program ID not configured");
804
857
  const presaleVault = getAssociatedTokenAddressSync(currencyMint, presalePda, true);
805
858
  const referralTokenAccount = getAssociatedTokenAddressSync(currencyMint, referralAddress);
806
859
  const companyTokenAccount = getAssociatedTokenAddressSync(currencyMint, companyAddress);
807
- const botmmTokenAccount = getAssociatedTokenAddressSync(currencyMint, botmmAddress);
808
- return this.program.methods.collectPresaleRevenue().accounts({
860
+ const [adminConfig] = PDA.adminConfig(adminOwner, this.programIds);
861
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
862
+ const adminVault = getAssociatedTokenAddressSync(currencyMint, adminConfig, true);
863
+ return this.program.methods.collectPresaleRevenue(Array.from(conditionId)).accounts({
809
864
  caller,
810
865
  config: this.configPda,
811
866
  presale: presalePda,
@@ -813,9 +868,12 @@ var MarketClient = class {
813
868
  currencyMint,
814
869
  referralTokenAccount,
815
870
  companyTokenAccount,
816
- botmmTokenAccount,
871
+ adminVault,
872
+ adminConfig,
873
+ claimRecord,
817
874
  payer,
818
875
  presaleProgram: this.programIds.presale,
876
+ adminProgram: this.programIds.adminContract,
819
877
  tokenProgram: TOKEN_PROGRAM_ID,
820
878
  associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
821
879
  systemProgram: SystemProgram.programId
@@ -1007,7 +1065,21 @@ var CtfClient = class {
1007
1065
  const userYesAta = getAssociatedTokenAddressSync(yesMint, user, false, TOKEN_2022_PROGRAM_ID);
1008
1066
  const userNoAta = getAssociatedTokenAddressSync(noMint, user, false, TOKEN_2022_PROGRAM_ID);
1009
1067
  const userCollateral = getAssociatedTokenAddressSync(collateralMint, user);
1010
- return this.program.methods.redeemPositions().accounts({
1068
+ const createYesAtaIx = createAssociatedTokenAccountIdempotentInstruction(
1069
+ payer,
1070
+ userYesAta,
1071
+ user,
1072
+ yesMint,
1073
+ TOKEN_2022_PROGRAM_ID
1074
+ );
1075
+ const createNoAtaIx = createAssociatedTokenAccountIdempotentInstruction(
1076
+ payer,
1077
+ userNoAta,
1078
+ user,
1079
+ noMint,
1080
+ TOKEN_2022_PROGRAM_ID
1081
+ );
1082
+ const redeemIx = await this.program.methods.redeemPositions().accounts({
1011
1083
  user,
1012
1084
  payer,
1013
1085
  condition,
@@ -1023,14 +1095,17 @@ var CtfClient = class {
1023
1095
  tokenProgram: TOKEN_PROGRAM_ID,
1024
1096
  token2022Program: TOKEN_2022_PROGRAM_ID,
1025
1097
  systemProgram: SystemProgram.programId
1026
- }).transaction();
1098
+ }).instruction();
1099
+ const tx = new Transaction();
1100
+ tx.add(createYesAtaIx, createNoAtaIx, redeemIx);
1101
+ return tx;
1027
1102
  }
1028
1103
  /**
1029
1104
  * Oracle directly resolves a condition with payout numerators.
1030
1105
  * Bypasses QuestionMarket — only for oracle-owned conditions.
1031
1106
  */
1032
1107
  async reportPayouts(condition, payoutNumerators) {
1033
- const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor4.BN(n))).accounts({
1108
+ const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor5.BN(n))).accounts({
1034
1109
  oracle: this.walletPubkey,
1035
1110
  condition
1036
1111
  }).rpc();
@@ -1261,57 +1336,60 @@ var ClobClient = class {
1261
1336
  }
1262
1337
  /**
1263
1338
  * Get or create an ALT for a condition.
1264
- * First call: creates + extends ALT on-chain, waits for activation (~2s).
1265
- * Subsequent calls for same condition: returns cached ALT instantly.
1266
- * BE devs never interact with this — called automatically by matchOrders.
1339
+ * Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
1267
1340
  */
1268
- async ensureAlt(condition, collateralMint, buyerPubkey, buyerNonce, makers) {
1341
+ async ensureAlt(condition, collateralMint, takerSigned, makers) {
1269
1342
  const cacheKey = condition.toBase58();
1270
1343
  if (this._altCache.has(cacheKey)) {
1271
1344
  return this._altCache.get(cacheKey);
1272
1345
  }
1273
1346
  const { connection } = this.provider;
1274
1347
  const payer = this.walletPubkey;
1348
+ const taker = takerSigned.order.maker;
1349
+ const takerNonce = takerSigned.order.nonce;
1350
+ const tokenId = takerSigned.order.tokenId;
1275
1351
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1352
+ const [noMint] = PDA.noMint(condition, this.programIds);
1276
1353
  const [extraAccountMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
1277
1354
  const [hookConfig] = PDA.hookConfig(this.programIds);
1278
- const [buyOrderStatus] = PDA.orderStatus(buyerPubkey, buyerNonce, this.programIds);
1279
- const [buyerPosition] = PDA.position(condition, 1, buyerPubkey, this.programIds);
1355
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1356
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1357
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1280
1358
  const clobConfigPda = this.configPda();
1359
+ const outcomeMint = tokenId === 1 ? yesMint : noMint;
1281
1360
  const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
1282
1361
  const addresses = [
1283
- // instruction program IDs — must be in ALT to keep static keys minimal
1284
1362
  Ed25519Program.programId,
1285
1363
  this.programIds.clobExchange,
1286
- // other programs
1287
1364
  this.programIds.conditionalTokens,
1288
1365
  this.programIds.hook,
1289
1366
  TOKEN_PROGRAM_ID,
1290
1367
  TOKEN_2022_PROGRAM_ID,
1291
1368
  SystemProgram.programId,
1292
1369
  SYSVAR_INSTRUCTIONS_PUBKEY,
1293
- // config PDAs
1294
1370
  clobConfigPda,
1295
1371
  hookConfig,
1296
- // condition PDAs
1297
1372
  condition,
1298
1373
  yesMint,
1374
+ noMint,
1299
1375
  extraAccountMeta,
1300
- // buyer pubkey + ATAs + PDAs
1301
- buyerPubkey,
1302
- getAssociatedTokenAddressSync(collateralMint, buyerPubkey),
1303
- getAssociatedTokenAddressSync(yesMint, buyerPubkey, false, TOKEN_2022_PROGRAM_ID),
1304
- buyerPosition,
1305
- buyOrderStatus
1376
+ taker,
1377
+ getAssociatedTokenAddressSync(collateralMint, taker),
1378
+ getAssociatedTokenAddressSync(outcomeMint, taker, false, TOKEN_2022_PROGRAM_ID),
1379
+ takerPosition,
1380
+ takerOrderStatus,
1381
+ takerOrderRecord
1306
1382
  ];
1307
1383
  if (feeRecipientAddr) addresses.push(feeRecipientAddr);
1308
1384
  for (const m of makers) {
1309
1385
  const seller = m.order.maker;
1310
- const [sellerPos] = PDA.position(condition, 1, seller, this.programIds);
1386
+ const [sellerPos] = PDA.position(condition, tokenId, seller, this.programIds);
1311
1387
  const [sellerStatus] = PDA.orderStatus(seller, m.order.nonce, this.programIds);
1388
+ const [sellerRecord] = PDA.orderRecord(seller, m.order.nonce, this.programIds);
1312
1389
  addresses.push(
1313
1390
  seller,
1314
- getAssociatedTokenAddressSync(yesMint, seller, false, TOKEN_2022_PROGRAM_ID),
1391
+ sellerRecord,
1392
+ getAssociatedTokenAddressSync(outcomeMint, seller, false, TOKEN_2022_PROGRAM_ID),
1315
1393
  getAssociatedTokenAddressSync(collateralMint, seller),
1316
1394
  sellerPos,
1317
1395
  sellerStatus
@@ -1359,34 +1437,42 @@ var ClobClient = class {
1359
1437
  }
1360
1438
  throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
1361
1439
  }
1362
- async _sendLegacyTx(instructions) {
1440
+ async _sendLegacyTxSig(instructions) {
1363
1441
  const { connection } = this.provider;
1364
1442
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1365
- const { Transaction: Transaction7 } = await import('@solana/web3.js');
1366
- const tx = new Transaction7();
1443
+ const { Transaction: Transaction8 } = await import('@solana/web3.js');
1444
+ const tx = new Transaction8();
1367
1445
  tx.recentBlockhash = blockhash;
1368
1446
  tx.feePayer = this.walletPubkey;
1369
1447
  tx.add(...instructions);
1370
1448
  const signed = await this.provider.wallet.signTransaction(tx);
1371
- const sig = await connection.sendRawTransaction(signed.serialize());
1372
- await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, "confirmed");
1449
+ const sig = await connection.sendRawTransaction(signed.serialize(), { skipPreflight: true });
1450
+ const result = await connection.confirmTransaction({ signature: sig, blockhash, lastValidBlockHeight }, "confirmed");
1451
+ if (result.value.err) {
1452
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1453
+ const logs = txInfo?.meta?.logMessages ?? [];
1454
+ const err = new Error(`Register tx failed: ${JSON.stringify(result.value.err)}
1455
+ ${logs.join("\n")}`);
1456
+ err.logs = logs;
1457
+ throw err;
1458
+ }
1459
+ return sig;
1460
+ }
1461
+ async _sendLegacyTx(instructions) {
1462
+ await this._sendLegacyTxSig(instructions);
1373
1463
  }
1374
1464
  /**
1375
- * Send a match transaction as versioned (v0).
1376
- * Pass a pre-built AddressLookupTableAccount to compress account keys and
1377
- * stay under the 1232-byte limit — required for match_complementary which
1378
- * has ~25 accounts + 2 Ed25519 precompile instructions (~1697 bytes raw).
1379
- *
1380
- * If `whitelistedWallet` is provided and differs from `this.provider.wallet`,
1381
- * both wallets sign the transaction (whitelisted operator + payer).
1465
+ * Send a match transaction as versioned (v0) with optional ALT.
1466
+ * Both operator wallet and payer (this.provider.wallet) sign.
1382
1467
  */
1383
1468
  async sendMatchTx(instructions, lookupTable, whitelistedWallet) {
1384
1469
  const { connection } = this.provider;
1385
1470
  const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash();
1471
+ const cuLimit = ComputeBudgetProgram.setComputeUnitLimit({ units: 8e5 });
1386
1472
  const message = new TransactionMessage({
1387
1473
  payerKey: this.walletPubkey,
1388
1474
  recentBlockhash: blockhash,
1389
- instructions
1475
+ instructions: [cuLimit, ...instructions]
1390
1476
  }).compileToV0Message(lookupTable ? [lookupTable] : []);
1391
1477
  const vtx = new VersionedTransaction(message);
1392
1478
  const signers = [this.provider.wallet.payer];
@@ -1395,19 +1481,67 @@ var ClobClient = class {
1395
1481
  }
1396
1482
  vtx.sign(signers);
1397
1483
  const sig = await connection.sendRawTransaction(vtx.serialize(), {
1398
- skipPreflight: false
1484
+ skipPreflight: true
1399
1485
  });
1400
- await connection.confirmTransaction(
1486
+ const result = await connection.confirmTransaction(
1401
1487
  { signature: sig, blockhash, lastValidBlockHeight },
1402
1488
  "confirmed"
1403
1489
  );
1490
+ if (result.value.err) {
1491
+ const txInfo = await connection.getTransaction(sig, { maxSupportedTransactionVersion: 0 });
1492
+ const logs = txInfo?.meta?.logMessages ?? [];
1493
+ const err = new Error(`Match tx failed: ${JSON.stringify(result.value.err)}
1494
+ ${logs.join("\n")}`);
1495
+ err.logs = logs;
1496
+ throw err;
1497
+ }
1404
1498
  return sig;
1405
1499
  }
1406
1500
  configPda() {
1407
1501
  return PDA.clobConfig(this.programIds)[0];
1408
1502
  }
1409
- // ─── Instructions ────────────────────────────────────────────────────────────
1410
- /** One-time setup. Caller becomes admin. */
1503
+ // ─── Register / Cancel ───────────────────────────────────────────────────────
1504
+ /**
1505
+ * Register a signed order on-chain.
1506
+ * Sends Ed25519 precompile ix + register_order ix in one legacy tx.
1507
+ * Called at match time (engine-triggered), not at order placement.
1508
+ */
1509
+ async registerOrder(signed) {
1510
+ const nonce = signed.order.nonce;
1511
+ const orderSigner = signed.order.maker;
1512
+ const [orderRecord] = PDA.orderRecord(orderSigner, nonce, this.programIds);
1513
+ const ed25519Ix = buildBatchedEd25519Instruction([signed]);
1514
+ const [orderStatus] = PDA.orderStatus(orderSigner, nonce, this.programIds);
1515
+ const registerIx = await this.program.methods.registerOrder(nonce).accounts({
1516
+ payer: this.walletPubkey,
1517
+ clobConfig: this.configPda(),
1518
+ ixSysvar: IX_SYSVAR,
1519
+ orderSigner,
1520
+ orderRecord,
1521
+ orderStatus,
1522
+ systemProgram: SystemProgram.programId
1523
+ }).instruction();
1524
+ return this._sendLegacyTxSig([ed25519Ix, registerIx]);
1525
+ }
1526
+ /** Register only if the PDA doesn't exist yet (idempotent). */
1527
+ async registerOrderIfNeeded(signed) {
1528
+ const [pda] = PDA.orderRecord(signed.order.maker, signed.order.nonce, this.programIds);
1529
+ const existing = await this.program.account.signedOrderRecord.fetchNullable(pda);
1530
+ if (!existing) {
1531
+ await this.registerOrder(signed);
1532
+ }
1533
+ }
1534
+ /** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
1535
+ async cancelOrder(nonce) {
1536
+ const [orderRecord] = PDA.orderRecord(this.walletPubkey, nonce, this.programIds);
1537
+ const sig = await this.program.methods.cancelOrder(nonce).accounts({
1538
+ maker: this.walletPubkey,
1539
+ orderRecord,
1540
+ systemProgram: SystemProgram.programId
1541
+ }).rpc();
1542
+ return { signature: sig };
1543
+ }
1544
+ // ─── Admin ───────────────────────────────────────────────────────────────────
1411
1545
  async initialize(operators, feeRecipient, feeRateBps) {
1412
1546
  const sig = await this.program.methods.initializeClob(
1413
1547
  operators,
@@ -1421,7 +1555,6 @@ var ClobClient = class {
1421
1555
  }).rpc();
1422
1556
  return { signature: sig };
1423
1557
  }
1424
- /** Admin adds an operator to the whitelist. */
1425
1558
  async addOperator(operator) {
1426
1559
  const sig = await this.program.methods.addOperator(operator).accounts({
1427
1560
  admin: this.walletPubkey,
@@ -1429,7 +1562,6 @@ var ClobClient = class {
1429
1562
  }).rpc();
1430
1563
  return { signature: sig };
1431
1564
  }
1432
- /** Admin removes an operator from the whitelist. */
1433
1565
  async removeOperator(operator) {
1434
1566
  const sig = await this.program.methods.removeOperator(operator).accounts({
1435
1567
  admin: this.walletPubkey,
@@ -1437,7 +1569,6 @@ var ClobClient = class {
1437
1569
  }).rpc();
1438
1570
  return { signature: sig };
1439
1571
  }
1440
- /** Admin pause/unpause the CLOB. */
1441
1572
  async setPaused(paused) {
1442
1573
  const sig = await this.program.methods.setPaused(paused).accounts({
1443
1574
  admin: this.walletPubkey,
@@ -1445,9 +1576,6 @@ var ClobClient = class {
1445
1576
  }).rpc();
1446
1577
  return { signature: sig };
1447
1578
  }
1448
- /**
1449
- * Emergency reset of CLOB config (upgrade authority only).
1450
- */
1451
1579
  async forceResetClob(programData, newAdmin, newOperators, newFeeRecipient, newFeeRateBps) {
1452
1580
  const sig = await this.program.methods.forceResetClob(newAdmin, newOperators, newFeeRecipient, newFeeRateBps).accounts({
1453
1581
  upgradeAuthority: this.walletPubkey,
@@ -1456,31 +1584,44 @@ var ClobClient = class {
1456
1584
  }).rpc();
1457
1585
  return { signature: sig };
1458
1586
  }
1587
+ // ─── Match instructions ───────────────────────────────────────────────────────
1459
1588
  /**
1460
- * COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
1461
- *
1462
- * Transaction structure:
1463
- * ix[0] Ed25519(taker/buyer)
1464
- * ix[1+i] Ed25519(maker_i/seller_i)
1465
- * ix[N+1] match_complementary(buyNonce, makerNonces[])
1466
- *
1467
- * remaining_accounts: [hook×3] [seller×5 × N]
1468
- */
1469
- /** Build Ed25519 + matchComplementary instructions without sending.
1589
+ * Build match_complementary instruction (no Ed25519 OrderRecord PDAs used).
1470
1590
  *
1471
- * If `buySigned.order.fee > 0` and `feeClient` + `feeConfigOwner` are wired in,
1472
- * automatically appends 5 fee_management remaining_accounts so the program CPIs
1473
- * to distribute_fee internally. No manual `feeDistribute` param needed.
1591
+ * remaining_accounts layout:
1592
+ * [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
1593
+ * [extraAccountMetaList, hookConfig, hookProgram]
1594
+ * [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
1474
1595
  */
1475
- async buildMatchComplementaryIxs(buySigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1476
- const condition = buySigned.order.condition;
1477
- const tokenId = buySigned.order.tokenId;
1596
+ async buildMatchComplementaryIxs(takerSigned, makersSigned, collateralMint, feeRecipient, operator, opts) {
1597
+ const condition = takerSigned.order.condition;
1598
+ const tokenId = takerSigned.order.tokenId;
1599
+ const taker = takerSigned.order.maker;
1600
+ const takerNonce = takerSigned.order.nonce;
1601
+ const fillAmount = opts?.fillAmount ?? new anchor5.BN("18446744073709551615");
1478
1602
  const [outcomeMint] = tokenId === 1 ? PDA.yesMint(condition, this.programIds) : PDA.noMint(condition, this.programIds);
1479
- const buyer = buySigned.order.maker;
1480
- const buyerCollateral = getAssociatedTokenAddressSync(collateralMint, buyer);
1481
- const buyerTokenAccount = getAssociatedTokenAddressSync(outcomeMint, buyer, false, TOKEN_2022_PROGRAM_ID);
1482
- const [buyerPosition] = PDA.position(condition, tokenId, buyer, this.programIds);
1483
- const [buyOrderStatus] = PDA.orderStatus(buyer, buySigned.order.nonce, this.programIds);
1603
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1604
+ const takerCollateral = getAssociatedTokenAddressSync(collateralMint, taker);
1605
+ const takerTokenAccount = getAssociatedTokenAddressSync(outcomeMint, taker, false, TOKEN_2022_PROGRAM_ID);
1606
+ const [takerPosition] = PDA.position(condition, tokenId, taker, this.programIds);
1607
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1608
+ const makerAccounts = [];
1609
+ for (const ms of makersSigned) {
1610
+ const seller = ms.order.maker;
1611
+ const [sellerRecord] = PDA.orderRecord(seller, ms.order.nonce, this.programIds);
1612
+ const sellerToken = getAssociatedTokenAddressSync(outcomeMint, seller, false, TOKEN_2022_PROGRAM_ID);
1613
+ const sellerCollateral = getAssociatedTokenAddressSync(collateralMint, seller);
1614
+ const [sellerPosition] = PDA.position(condition, tokenId, seller, this.programIds);
1615
+ const [sellerStatus] = PDA.orderStatus(seller, ms.order.nonce, this.programIds);
1616
+ makerAccounts.push(
1617
+ { pubkey: seller, isSigner: false, isWritable: false },
1618
+ { pubkey: sellerRecord, isSigner: false, isWritable: false },
1619
+ { pubkey: sellerToken, isSigner: false, isWritable: true },
1620
+ { pubkey: sellerCollateral, isSigner: false, isWritable: true },
1621
+ { pubkey: sellerPosition, isSigner: false, isWritable: true },
1622
+ { pubkey: sellerStatus, isSigner: false, isWritable: true }
1623
+ );
1624
+ }
1484
1625
  const [extraAccountMetaList] = PDA.extraAccountMetaList(outcomeMint, this.programIds);
1485
1626
  const [hookConfig] = PDA.hookConfig(this.programIds);
1486
1627
  const hookAccounts = [
@@ -1488,22 +1629,8 @@ var ClobClient = class {
1488
1629
  { pubkey: hookConfig, isSigner: false, isWritable: false },
1489
1630
  { pubkey: this.programIds.hook, isSigner: false, isWritable: false }
1490
1631
  ];
1491
- const makerAccounts = makersSigned.flatMap((m) => {
1492
- const seller = m.order.maker;
1493
- const sellerTokenAccount = getAssociatedTokenAddressSync(outcomeMint, seller, false, TOKEN_2022_PROGRAM_ID);
1494
- const [sellerPosition] = PDA.position(condition, tokenId, seller, this.programIds);
1495
- const sellerCollateral = getAssociatedTokenAddressSync(collateralMint, seller);
1496
- const [sellOrderStatus] = PDA.orderStatus(seller, m.order.nonce, this.programIds);
1497
- return [
1498
- { pubkey: seller, isSigner: false, isWritable: false },
1499
- { pubkey: sellerTokenAccount, isSigner: false, isWritable: true },
1500
- { pubkey: sellerPosition, isSigner: false, isWritable: true },
1501
- { pubkey: sellerCollateral, isSigner: false, isWritable: true },
1502
- { pubkey: sellOrderStatus, isSigner: false, isWritable: true }
1503
- ];
1504
- });
1505
1632
  let feeAccounts = [];
1506
- if (buySigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1633
+ if (takerSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1507
1634
  const companyAddr = await this.companyAddress();
1508
1635
  if (companyAddr) {
1509
1636
  const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
@@ -1516,31 +1643,38 @@ var ClobClient = class {
1516
1643
  ];
1517
1644
  }
1518
1645
  }
1519
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1520
- const ed25519Ix = buildBatchedEd25519Instruction([buySigned, ...makersSigned]);
1521
- const matchIx = await this.program.methods.matchComplementary(buySigned.order.nonce, makerNonces).accounts({
1646
+ const matchIx = await this.program.methods.matchComplementary(takerNonce, fillAmount).accounts({
1522
1647
  operator,
1523
1648
  payer: this.walletPubkey,
1524
1649
  clobConfig: this.configPda(),
1525
- ixSysvar: IX_SYSVAR,
1526
1650
  condition,
1527
- buyer,
1528
- buyerCollateral,
1529
- buyerTokenAccount,
1530
- buyerPosition,
1531
- buyOrderStatus,
1532
- outcomeMint,
1651
+ taker,
1652
+ takerOrderRecord,
1653
+ takerCollateral,
1654
+ takerTokenAccount,
1655
+ takerPosition,
1656
+ takerOrderStatus,
1533
1657
  feeRecipient,
1658
+ outcomeMint,
1534
1659
  conditionalTokensProgram: this.programIds.conditionalTokens,
1535
1660
  tokenProgram: TOKEN_PROGRAM_ID,
1536
1661
  token2022Program: TOKEN_2022_PROGRAM_ID,
1537
1662
  systemProgram: SystemProgram.programId
1538
- }).remainingAccounts([...hookAccounts, ...makerAccounts, ...feeAccounts]).instruction();
1539
- return [ed25519Ix, matchIx];
1663
+ }).remainingAccounts([...makerAccounts, ...hookAccounts, ...feeAccounts]).instruction();
1664
+ return [matchIx];
1540
1665
  }
1541
- async matchComplementary(buySigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1666
+ /**
1667
+ * COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
1668
+ * Phase 1: register taker + all makers in parallel.
1669
+ * Phase 2: 1 atomic match tx.
1670
+ */
1671
+ async matchComplementary(takerSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1672
+ await Promise.all([
1673
+ this.registerOrderIfNeeded(takerSigned),
1674
+ ...makersSigned.map((m) => this.registerOrderIfNeeded(m))
1675
+ ]);
1542
1676
  const ixs = await this.buildMatchComplementaryIxs(
1543
- buySigned,
1677
+ takerSigned,
1544
1678
  makersSigned,
1545
1679
  collateralMint,
1546
1680
  feeRecipient,
@@ -1551,160 +1685,167 @@ var ClobClient = class {
1551
1685
  return { signature: sig };
1552
1686
  }
1553
1687
  /**
1554
- * MINT match: 1 YES buyer (taker) + N NO buyers (makers).
1555
- *
1556
- * Transaction structure:
1557
- * ix[0] Ed25519(taker/YES buyer)
1558
- * ix[1+i] Ed25519(maker_i/NO buyer)
1559
- * ix[N+1] match_mint_orders(yesNonce, makerNonces[])
1688
+ * MINT: 1 YES buyer (taker) + N NO buyers (makers).
1689
+ * Phase 1: register taker + all NO makers in parallel.
1690
+ * Phase 2: 1 atomic match tx.
1560
1691
  *
1561
- * remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
1692
+ * remaining_accounts per NO maker (5):
1693
+ * [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
1562
1694
  */
1563
- async matchMintOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1695
+ async matchMintOrders(yesSigned, noMakers, collateralMint, _feeRecipient, operatorWallet, lookupTable) {
1696
+ await Promise.all([
1697
+ this.registerOrderIfNeeded(yesSigned),
1698
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1699
+ ]);
1564
1700
  const condition = yesSigned.order.condition;
1701
+ const taker = yesSigned.order.maker;
1702
+ const takerNonce = yesSigned.order.nonce;
1703
+ const fillAmount = new anchor5.BN("18446744073709551615");
1565
1704
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1566
1705
  const [noMint] = PDA.noMint(condition, this.programIds);
1567
1706
  const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1568
1707
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1569
1708
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1570
- const buyerYes = yesSigned.order.maker;
1571
- const buyerYesCollateral = getAssociatedTokenAddressSync(collateralMint, buyerYes);
1572
- const buyerYesTokenAccount = getAssociatedTokenAddressSync(yesMint, buyerYes, false, TOKEN_2022_PROGRAM_ID);
1573
- const [buyerYesPosition] = PDA.position(condition, 1, buyerYes, this.programIds);
1574
- const [yesOrderStatus] = PDA.orderStatus(buyerYes, yesSigned.order.nonce, this.programIds);
1575
- const makerAccounts = makersSigned.flatMap((m) => {
1576
- const maker = m.order.maker;
1577
- const makerUsdcAta = getAssociatedTokenAddressSync(collateralMint, maker);
1578
- const makerNoAta = getAssociatedTokenAddressSync(noMint, maker, false, TOKEN_2022_PROGRAM_ID);
1579
- const [makerNoPosition] = PDA.position(condition, 0, maker, this.programIds);
1580
- const [makerOrderStatus] = PDA.orderStatus(maker, m.order.nonce, this.programIds);
1581
- return [
1582
- { pubkey: maker, isSigner: false, isWritable: false },
1583
- { pubkey: makerUsdcAta, isSigner: false, isWritable: true },
1584
- { pubkey: makerNoAta, isSigner: false, isWritable: true },
1585
- { pubkey: makerNoPosition, isSigner: false, isWritable: true },
1586
- { pubkey: makerOrderStatus, isSigner: false, isWritable: true }
1587
- ];
1588
- });
1589
- const operator = operatorWallet.publicKey;
1590
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1591
- const ed25519Ixs = [
1592
- buildBatchedEd25519Instruction([yesSigned, ...makersSigned])
1593
- ];
1594
- const matchIx = await this.program.methods.matchMintOrders(yesSigned.order.nonce, makerNonces).accounts({
1595
- operator,
1709
+ const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
1710
+ const takerCollateral = getAssociatedTokenAddressSync(collateralMint, taker);
1711
+ const takerYesToken = getAssociatedTokenAddressSync(yesMint, taker, false, TOKEN_2022_PROGRAM_ID);
1712
+ const [takerYesPosition] = PDA.position(condition, 1, taker, this.programIds);
1713
+ const [takerOrderStatus] = PDA.orderStatus(taker, takerNonce, this.programIds);
1714
+ const remainingAccounts = [];
1715
+ for (const nm of noMakers) {
1716
+ const noMaker = nm.order.maker;
1717
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1718
+ const noToken = getAssociatedTokenAddressSync(noMint, noMaker, false, TOKEN_2022_PROGRAM_ID);
1719
+ const noCollateral = getAssociatedTokenAddressSync(collateralMint, noMaker);
1720
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1721
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1722
+ remainingAccounts.push(
1723
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1724
+ { pubkey: noToken, isSigner: false, isWritable: true },
1725
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1726
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1727
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1728
+ );
1729
+ }
1730
+ const matchIx = await this.program.methods.matchMintOrders(takerNonce, fillAmount).accounts({
1731
+ operator: operatorWallet.publicKey,
1596
1732
  payer: this.walletPubkey,
1597
1733
  clobConfig: this.configPda(),
1598
- ixSysvar: IX_SYSVAR,
1599
1734
  condition,
1600
- buyerYes,
1601
- buyerYesCollateral,
1602
- buyerYesTokenAccount,
1603
- buyerYesPosition,
1604
- yesOrderStatus,
1735
+ taker,
1736
+ takerOrderRecord,
1737
+ takerCollateral,
1738
+ takerYesToken,
1739
+ takerYesPosition,
1740
+ takerOrderStatus,
1605
1741
  collateralVault,
1606
1742
  vaultTokenAccount,
1607
1743
  yesMint,
1608
1744
  noMint,
1609
1745
  mintAuthority,
1746
+ clobAuthority: this.configPda(),
1610
1747
  conditionalTokensProgram: this.programIds.conditionalTokens,
1611
1748
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1612
1749
  systemProgram: SystemProgram.programId
1613
- }).remainingAccounts(makerAccounts).instruction();
1614
- const sig = await this.sendMatchTx(
1615
- [...ed25519Ixs, matchIx],
1616
- lookupTable,
1617
- operatorWallet
1618
- );
1750
+ }).remainingAccounts(remainingAccounts).instruction();
1751
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1619
1752
  return { signature: sig };
1620
1753
  }
1621
1754
  /**
1622
- * MERGE match: 1 YES seller (taker) + N NO sellers (makers).
1755
+ * MERGE: 1 YES seller (taker) + N NO sellers (makers).
1756
+ * Phase 1: register taker + all NO makers in parallel.
1757
+ * Phase 2: 1 atomic match tx.
1623
1758
  *
1624
- * Transaction structure:
1625
- * ix[0] Ed25519(taker/YES seller)
1626
- * ix[1+i] Ed25519(maker_i/NO seller)
1627
- * ix[N+1] match_merge_orders(yesNonce, makerNonces[])
1628
- *
1629
- * remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
1759
+ * remaining_accounts per NO maker (5):
1760
+ * [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
1761
+ * After all makers, optional 5 fee accounts.
1630
1762
  */
1631
- async matchMergeOrders(yesSigned, makersSigned, collateralMint, feeRecipient, operatorWallet, lookupTable) {
1763
+ async matchMergeOrders(yesSigned, noMakers, collateralMint, feeRecipient, operatorWallet, lookupTable, opts) {
1764
+ await Promise.all([
1765
+ this.registerOrderIfNeeded(yesSigned),
1766
+ ...noMakers.map((m) => this.registerOrderIfNeeded(m))
1767
+ ]);
1632
1768
  const condition = yesSigned.order.condition;
1769
+ const sellerYes = yesSigned.order.maker;
1770
+ const takerNonce = yesSigned.order.nonce;
1771
+ const fillAmount = new anchor5.BN("18446744073709551615");
1633
1772
  const [yesMint] = PDA.yesMint(condition, this.programIds);
1634
1773
  const [noMint] = PDA.noMint(condition, this.programIds);
1774
+ const [mintAuthority] = PDA.mintAuthority(condition, this.programIds);
1635
1775
  const [collateralVault] = PDA.collateralVault(collateralMint, this.programIds);
1636
1776
  const [vaultTokenAccount] = PDA.vaultToken(collateralMint, this.programIds);
1637
- const sellerYes = yesSigned.order.maker;
1638
- const sellerYesTokenAccount = getAssociatedTokenAddressSync(yesMint, sellerYes, false, TOKEN_2022_PROGRAM_ID);
1639
- const [sellerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
1640
- const sellerYesCollateral = getAssociatedTokenAddressSync(collateralMint, sellerYes);
1641
- const [yesOrderStatus] = PDA.orderStatus(sellerYes, yesSigned.order.nonce, this.programIds);
1642
- const makerAccounts = makersSigned.flatMap((m) => {
1643
- const maker = m.order.maker;
1644
- const makerNoAta = getAssociatedTokenAddressSync(noMint, maker, false, TOKEN_2022_PROGRAM_ID);
1645
- const [makerNoPosition] = PDA.position(condition, 0, maker, this.programIds);
1646
- const makerUsdcAta = getAssociatedTokenAddressSync(collateralMint, maker);
1647
- const [makerOrderStatus] = PDA.orderStatus(maker, m.order.nonce, this.programIds);
1648
- return [
1649
- { pubkey: maker, isSigner: false, isWritable: false },
1650
- { pubkey: makerNoAta, isSigner: false, isWritable: true },
1651
- { pubkey: makerNoPosition, isSigner: false, isWritable: true },
1652
- { pubkey: makerUsdcAta, isSigner: false, isWritable: true },
1653
- { pubkey: makerOrderStatus, isSigner: false, isWritable: true }
1654
- ];
1655
- });
1656
- const operator = operatorWallet.publicKey;
1657
- const makerNonces = makersSigned.map((m) => m.order.nonce);
1658
- const ed25519Ixs = [
1659
- buildBatchedEd25519Instruction([yesSigned, ...makersSigned])
1660
- ];
1661
- const matchIx = await this.program.methods.matchMergeOrders(yesSigned.order.nonce, makerNonces).accounts({
1662
- operator,
1777
+ const [takerOrderRecord] = PDA.orderRecord(sellerYes, takerNonce, this.programIds);
1778
+ const takerYesToken = getAssociatedTokenAddressSync(yesMint, sellerYes, false, TOKEN_2022_PROGRAM_ID);
1779
+ const [takerYesPosition] = PDA.position(condition, 1, sellerYes, this.programIds);
1780
+ const takerCollateral = getAssociatedTokenAddressSync(collateralMint, sellerYes);
1781
+ const [takerOrderStatus] = PDA.orderStatus(sellerYes, takerNonce, this.programIds);
1782
+ const remainingAccounts = [];
1783
+ for (const nm of noMakers) {
1784
+ const noMaker = nm.order.maker;
1785
+ const [noRecord] = PDA.orderRecord(noMaker, nm.order.nonce, this.programIds);
1786
+ const noToken = getAssociatedTokenAddressSync(noMint, noMaker, false, TOKEN_2022_PROGRAM_ID);
1787
+ const noCollateral = getAssociatedTokenAddressSync(collateralMint, noMaker);
1788
+ const [noPosition] = PDA.position(condition, 0, noMaker, this.programIds);
1789
+ const [noStatus] = PDA.orderStatus(noMaker, nm.order.nonce, this.programIds);
1790
+ remainingAccounts.push(
1791
+ { pubkey: noRecord, isSigner: false, isWritable: false },
1792
+ { pubkey: noToken, isSigner: false, isWritable: true },
1793
+ { pubkey: noCollateral, isSigner: false, isWritable: true },
1794
+ { pubkey: noPosition, isSigner: false, isWritable: true },
1795
+ { pubkey: noStatus, isSigner: false, isWritable: true }
1796
+ );
1797
+ }
1798
+ if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
1799
+ const companyAddr = await this.companyAddress();
1800
+ if (companyAddr) {
1801
+ const oracleVault = opts?.marketOracleVault ?? this.walletPubkey;
1802
+ remainingAccounts.push(
1803
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
1804
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
1805
+ { pubkey: PDA.marketFeeOverride(condition, this.programIds)[0], isSigner: false, isWritable: false },
1806
+ { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
1807
+ { pubkey: oracleVault, isSigner: false, isWritable: true }
1808
+ );
1809
+ }
1810
+ }
1811
+ const matchIx = await this.program.methods.matchMergeOrders(takerNonce, fillAmount).accounts({
1812
+ operator: operatorWallet.publicKey,
1663
1813
  payer: this.walletPubkey,
1664
1814
  clobConfig: this.configPda(),
1665
- ixSysvar: IX_SYSVAR,
1666
1815
  condition,
1667
- sellerYes,
1668
- sellerYesTokenAccount,
1669
- sellerYesPosition,
1670
- sellerYesCollateral,
1671
- yesOrderStatus,
1816
+ taker: sellerYes,
1817
+ takerOrderRecord,
1818
+ takerYesToken,
1819
+ takerYesPosition,
1820
+ takerCollateral,
1821
+ takerOrderStatus,
1672
1822
  collateralVault,
1673
1823
  vaultTokenAccount,
1674
1824
  yesMint,
1675
1825
  noMint,
1826
+ mintAuthority,
1676
1827
  feeRecipient,
1828
+ clobAuthority: this.configPda(),
1677
1829
  conditionalTokensProgram: this.programIds.conditionalTokens,
1678
1830
  collateralTokenProgram: TOKEN_PROGRAM_ID,
1679
1831
  systemProgram: SystemProgram.programId
1680
- }).remainingAccounts(makerAccounts).instruction();
1681
- const sig = await this.sendMatchTx(
1682
- [...ed25519Ixs, matchIx],
1683
- lookupTable,
1684
- operatorWallet
1685
- );
1832
+ }).remainingAccounts(remainingAccounts).instruction();
1833
+ const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
1686
1834
  return { signature: sig };
1687
1835
  }
1688
1836
  /**
1689
- * Auto-detect match type and execute 1-taker + N-makers in a single transaction.
1690
- *
1691
- * Detection (pure, no RPC) based on taker.order vs makers[0].order:
1692
- * taker.tokenId === makers[0].tokenId: taker BUY + all makers SELL → COMPLEMENTARY
1693
- * taker.tokenId !== makers[0].tokenId + taker BUY + all makers BUY → MINT
1694
- * taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL → MERGE
1695
- * Otherwise → throws InvalidParamError
1837
+ * Auto-detect match type and execute 2-phase:
1838
+ * Phase 1 — register all orders (taker + makers) on-chain in parallel.
1839
+ * Phase 2 1 atomic match transaction.
1696
1840
  *
1697
- * All makers must have the same tokenId and side as makers[0].
1698
- */
1699
- /**
1700
- * Auto-detect match type and execute in a single transaction.
1701
- * ALT is managed automatically (created on first call per condition, cached thereafter).
1702
- * feeRecipient and collateralMint are derived from on-chain config.
1703
- * Fee distribution (distribute_fee CPI) fires automatically when order.fee > 0.
1841
+ * Detection (pure, no RPC):
1842
+ * taker.tokenId === makers[0].tokenId:
1843
+ * taker BUY + all makers SELL → COMPLEMENTARY
1844
+ * taker.tokenId !== makers[0].tokenId + all BUY → MINT
1845
+ * taker.tokenId !== makers[0].tokenId + all SELL MERGE
1704
1846
  *
1705
- * @param opts.marketOracleVault Required for presale markets (is_admin=false).
1706
- * Pass the ATA of the market_oracle PDA so 50% of fee goes there.
1707
- * For admin markets (is_admin=true) omit — payer is used as placeholder (no transfer).
1847
+ * @param opts.marketOracleVault Oracle vault ATA for presale markets.
1848
+ * Omit for admin markets (payer used as placeholder).
1708
1849
  */
1709
1850
  async matchOrders(taker, makers, opts) {
1710
1851
  if (makers.length === 0) throw new InvalidParamError("At least 1 maker required");
@@ -1716,8 +1857,7 @@ var ClobClient = class {
1716
1857
  const alt = await this.ensureAlt(
1717
1858
  taker.order.condition,
1718
1859
  collateralMint,
1719
- taker.order.maker,
1720
- taker.order.nonce,
1860
+ taker,
1721
1861
  makers
1722
1862
  );
1723
1863
  const t = taker.order;
@@ -1729,9 +1869,9 @@ var ClobClient = class {
1729
1869
  return this.matchComplementary(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1730
1870
  }
1731
1871
  if (t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_BUY)) {
1732
- throw new InvalidParamError("COMPLEMENTARY N-maker: taker must be the BUY side");
1872
+ return this.matchComplementary(makers[0], [taker, ...makers.slice(1)], collateralMint, feeRecipient, operatorWallet, alt, opts);
1733
1873
  }
1734
- throw new InvalidParamError("COMPLEMENTARY requires taker=BUY, makers=SELL on same tokenId");
1874
+ throw new InvalidParamError("COMPLEMENTARY requires one BUY and one SELL on same tokenId");
1735
1875
  }
1736
1876
  const allBuy = t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_BUY);
1737
1877
  const allSell = t.side === SIDE_SELL && makers.every((m) => m.order.side === SIDE_SELL);
@@ -1739,7 +1879,7 @@ var ClobClient = class {
1739
1879
  if (t.tokenId !== 1) throw new InvalidParamError("MINT/MERGE: taker must be YES (tokenId=1)");
1740
1880
  if (!makers.every((m) => m.order.tokenId === 0)) throw new InvalidParamError("MINT/MERGE: makers must be NO (tokenId=0)");
1741
1881
  if (allBuy) return this.matchMintOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1742
- return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt);
1882
+ return this.matchMergeOrders(taker, makers, collateralMint, feeRecipient, operatorWallet, alt, opts);
1743
1883
  }
1744
1884
  // ─── Queries ─────────────────────────────────────────────────────────────────
1745
1885
  async fetchConfig() {
@@ -1773,6 +1913,15 @@ var ClobClient = class {
1773
1913
  return null;
1774
1914
  }
1775
1915
  }
1916
+ async fetchOrderRecord(maker, nonce) {
1917
+ try {
1918
+ const [pda] = PDA.orderRecord(maker, nonce, this.programIds);
1919
+ const acc = await this.program.account.signedOrderRecord.fetch(pda);
1920
+ return acc;
1921
+ } catch {
1922
+ return null;
1923
+ }
1924
+ }
1776
1925
  };
1777
1926
  var FeeManagementClient = class {
1778
1927
  constructor(program, provider, programIds) {
@@ -2116,6 +2265,139 @@ var MarketOracleClient = class {
2116
2265
  }
2117
2266
  }
2118
2267
  };
2268
+ var AdminClient = class {
2269
+ constructor(program, provider, programIds) {
2270
+ this.program = program;
2271
+ this.provider = provider;
2272
+ this.programIds = programIds;
2273
+ }
2274
+ get walletPubkey() {
2275
+ return this.provider.wallet.publicKey;
2276
+ }
2277
+ get configPda() {
2278
+ const [pda] = PDA.adminConfig(this.walletPubkey, this.programIds);
2279
+ return pda;
2280
+ }
2281
+ configPdaFor(owner) {
2282
+ const [pda] = PDA.adminConfig(owner, this.programIds);
2283
+ return pda;
2284
+ }
2285
+ adminVault(owner, collateralMint) {
2286
+ const configPda = this.configPdaFor(owner);
2287
+ return getAssociatedTokenAddressSync(collateralMint, configPda, true);
2288
+ }
2289
+ // ─── Fetch ────────────────────────────────────────────────────────────────
2290
+ async fetchConfig(owner = this.walletPubkey) {
2291
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2292
+ try {
2293
+ const acc = await this.program.account.adminConfig.fetch(configPda);
2294
+ return {
2295
+ version: acc.version,
2296
+ owner: acc.owner,
2297
+ collateralMint: acc.collateralMint,
2298
+ authorizedCaller: acc.authorizedCaller,
2299
+ adminWhitelist: acc.adminWhitelist.slice(0, acc.adminWhitelistLen),
2300
+ whitelist: acc.whitelist.slice(0, acc.whitelistLen),
2301
+ bump: acc.bump
2302
+ };
2303
+ } catch {
2304
+ return null;
2305
+ }
2306
+ }
2307
+ async fetchClaimRecord(conditionId) {
2308
+ const [pda] = PDA.claimRecord(conditionId, this.programIds);
2309
+ try {
2310
+ const acc = await this.program.account.claimRecord.fetch(pda);
2311
+ return {
2312
+ conditionId: acc.conditionId,
2313
+ amount: acc.amount,
2314
+ bump: acc.bump
2315
+ };
2316
+ } catch {
2317
+ return null;
2318
+ }
2319
+ }
2320
+ // ─── Instructions ─────────────────────────────────────────────────────────
2321
+ async initialize(authorizedCaller, collateralMint, owner = this.walletPubkey) {
2322
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2323
+ const vault = getAssociatedTokenAddressSync(collateralMint, configPda, true);
2324
+ return this.program.methods.initialize(authorizedCaller).accounts({
2325
+ owner,
2326
+ config: configPda,
2327
+ collateralMint,
2328
+ adminVault: vault,
2329
+ tokenProgram: TOKEN_PROGRAM_ID,
2330
+ associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
2331
+ systemProgram: SystemProgram.programId
2332
+ }).transaction();
2333
+ }
2334
+ async addAdmin(address, owner = this.walletPubkey) {
2335
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2336
+ return this.program.methods.addAdmin(address).accounts({ owner, config: configPda }).transaction();
2337
+ }
2338
+ async removeAdmin(address, owner = this.walletPubkey) {
2339
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2340
+ return this.program.methods.removeAdmin(address).accounts({ owner, config: configPda }).transaction();
2341
+ }
2342
+ async addToWhitelist(address, owner, admin = this.walletPubkey, payer = admin) {
2343
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2344
+ return this.program.methods.addToWhitelist(address).accounts({ admin, payer, config: configPda }).transaction();
2345
+ }
2346
+ async removeFromWhitelist(address, owner, admin = this.walletPubkey, payer = admin) {
2347
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2348
+ return this.program.methods.removeFromWhitelist(address).accounts({ admin, payer, config: configPda }).transaction();
2349
+ }
2350
+ /**
2351
+ * Normally called via CPI from question_market (authorized_caller signs).
2352
+ * For testing: initialize with authorizedCaller = wallet, call directly.
2353
+ */
2354
+ async setPresaleAmount(conditionId, amount, owner = this.walletPubkey, caller = this.walletPubkey, payer = caller) {
2355
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2356
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
2357
+ return this.program.methods.setPresaleAmount(Array.from(conditionId), amount).accounts({
2358
+ caller,
2359
+ payer,
2360
+ config: configPda,
2361
+ claimRecord,
2362
+ systemProgram: SystemProgram.programId
2363
+ }).transaction();
2364
+ }
2365
+ async claim(conditionId, collateralMint, owner, claimer = this.walletPubkey, payer = claimer) {
2366
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2367
+ const [claimRecord] = PDA.claimRecord(conditionId, this.programIds);
2368
+ const vault = getAssociatedTokenAddressSync(collateralMint, configPda, true);
2369
+ const claimerAta = getAssociatedTokenAddressSync(collateralMint, claimer);
2370
+ return this.program.methods.claim(Array.from(conditionId)).accounts({
2371
+ claimer,
2372
+ payer,
2373
+ config: configPda,
2374
+ adminVault: vault,
2375
+ claimRecord,
2376
+ claimerTokenAccount: claimerAta,
2377
+ tokenProgram: TOKEN_PROGRAM_ID
2378
+ }).transaction();
2379
+ }
2380
+ async updateConfig(authorizedCaller, owner = this.walletPubkey) {
2381
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2382
+ return this.program.methods.updateConfig(authorizedCaller).accounts({ owner, config: configPda }).transaction();
2383
+ }
2384
+ /**
2385
+ * BOTMM sends USDC from their wallet to the market_oracle vault for a condition.
2386
+ * Whitelist-only. No amount validation — caller responsible.
2387
+ */
2388
+ async distributeMarket(conditionId, amount, collateralMint, marketOracleVault, owner, claimer = this.walletPubkey, payer = claimer) {
2389
+ const [configPda] = PDA.adminConfig(owner, this.programIds);
2390
+ const claimerTokenAcct = getAssociatedTokenAddressSync(collateralMint, claimer);
2391
+ return this.program.methods.distributeMarket(Array.from(conditionId), amount).accounts({
2392
+ claimer,
2393
+ payer,
2394
+ config: configPda,
2395
+ claimerTokenAccount: claimerTokenAcct,
2396
+ marketOracleVault,
2397
+ tokenProgram: TOKEN_PROGRAM_ID
2398
+ }).transaction();
2399
+ }
2400
+ };
2119
2401
 
2120
2402
  // src/idls/oracle.json
2121
2403
  var oracle_default = {
@@ -2812,6 +3094,11 @@ var hook_default = {
2812
3094
  name: "owner",
2813
3095
  signer: true
2814
3096
  },
3097
+ {
3098
+ name: "payer",
3099
+ writable: true,
3100
+ signer: true
3101
+ },
2815
3102
  {
2816
3103
  name: "hook_config",
2817
3104
  writable: true,
@@ -2943,6 +3230,11 @@ var hook_default = {
2943
3230
  name: "owner",
2944
3231
  signer: true
2945
3232
  },
3233
+ {
3234
+ name: "payer",
3235
+ writable: true,
3236
+ signer: true
3237
+ },
2946
3238
  {
2947
3239
  name: "hook_config",
2948
3240
  writable: true,
@@ -3151,6 +3443,11 @@ var hook_default = {
3151
3443
  name: "owner",
3152
3444
  signer: true
3153
3445
  },
3446
+ {
3447
+ name: "payer",
3448
+ writable: true,
3449
+ signer: true
3450
+ },
3154
3451
  {
3155
3452
  name: "hook_config",
3156
3453
  writable: true,
@@ -3202,10 +3499,6 @@ var hook_default = {
3202
3499
  types: [
3203
3500
  {
3204
3501
  name: "HookConfig",
3205
- docs: [
3206
- "Global config for the Hook program.",
3207
- "Stores the whitelist of programs allowed to transfer YES/NO Token-2022 tokens."
3208
- ],
3209
3502
  type: {
3210
3503
  kind: "struct",
3211
3504
  fields: [
@@ -3215,16 +3508,10 @@ var hook_default = {
3215
3508
  },
3216
3509
  {
3217
3510
  name: "owner",
3218
- docs: [
3219
- "Owner who can update the whitelist"
3220
- ],
3221
3511
  type: "pubkey"
3222
3512
  },
3223
3513
  {
3224
3514
  name: "whitelist",
3225
- docs: [
3226
- "Programs allowed to initiate or receive YES/NO token transfers."
3227
- ],
3228
3515
  type: {
3229
3516
  array: [
3230
3517
  "pubkey",
@@ -3238,16 +3525,10 @@ var hook_default = {
3238
3525
  },
3239
3526
  {
3240
3527
  name: "is_frozen",
3241
- docs: [
3242
- "If true, whitelist can no longer be modified (locked forever)"
3243
- ],
3244
3528
  type: "bool"
3245
3529
  },
3246
3530
  {
3247
3531
  name: "bump",
3248
- docs: [
3249
- "Bump for this PDA"
3250
- ],
3251
3532
  type: "u8"
3252
3533
  },
3253
3534
  {
@@ -3683,7 +3964,7 @@ var question_market_default = {
3683
3964
  {
3684
3965
  name: "presale_vault",
3685
3966
  docs: [
3686
- "Presale USDC vault \u2014 closed inside presale program"
3967
+ "Presale USDC vault \u2014 read balance before CPI, closed inside presale program"
3687
3968
  ],
3688
3969
  writable: true
3689
3970
  },
@@ -3693,24 +3974,66 @@ var question_market_default = {
3693
3974
  {
3694
3975
  name: "referral_token_account",
3695
3976
  docs: [
3696
- "Referral address USDC token account"
3977
+ "Referral address USDC token account (10%)"
3697
3978
  ],
3698
3979
  writable: true
3699
3980
  },
3700
3981
  {
3701
3982
  name: "company_token_account",
3702
3983
  docs: [
3703
- "Company address USDC token account"
3984
+ "Company address USDC token account (10%)"
3704
3985
  ],
3705
3986
  writable: true
3706
3987
  },
3707
3988
  {
3708
- name: "botmm_token_account",
3989
+ name: "admin_vault",
3709
3990
  docs: [
3710
- "BOTMM token account (receives ~80%)"
3991
+ "admin_contract vault ATA \u2014 receives 80% instead of BOTMM wallet directly"
3711
3992
  ],
3712
3993
  writable: true
3713
3994
  },
3995
+ {
3996
+ name: "admin_config",
3997
+ docs: [
3998
+ "admin_contract config PDA"
3999
+ ]
4000
+ },
4001
+ {
4002
+ name: "claim_record",
4003
+ docs: [
4004
+ "ClaimRecord PDA for this conditionId (created by admin_contract CPI)"
4005
+ ],
4006
+ writable: true,
4007
+ pda: {
4008
+ seeds: [
4009
+ {
4010
+ kind: "const",
4011
+ value: [
4012
+ 99,
4013
+ 108,
4014
+ 97,
4015
+ 105,
4016
+ 109,
4017
+ 95,
4018
+ 114,
4019
+ 101,
4020
+ 99,
4021
+ 111,
4022
+ 114,
4023
+ 100
4024
+ ]
4025
+ },
4026
+ {
4027
+ kind: "arg",
4028
+ path: "condition_id"
4029
+ }
4030
+ ],
4031
+ program: {
4032
+ kind: "account",
4033
+ path: "admin_program"
4034
+ }
4035
+ }
4036
+ },
3714
4037
  {
3715
4038
  name: "payer",
3716
4039
  docs: [
@@ -3722,6 +4045,10 @@ var question_market_default = {
3722
4045
  name: "presale_program",
3723
4046
  address: "2Rnw1VoEtsUMQ7wkvYZjDehqSqRob6uNkeymDfvKrquB"
3724
4047
  },
4048
+ {
4049
+ name: "admin_program",
4050
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T"
4051
+ },
3725
4052
  {
3726
4053
  name: "token_program",
3727
4054
  address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
@@ -3735,9 +4062,19 @@ var question_market_default = {
3735
4062
  address: "11111111111111111111111111111111"
3736
4063
  }
3737
4064
  ],
3738
- args: []
3739
- },
3740
- {
4065
+ args: [
4066
+ {
4067
+ name: "condition_id",
4068
+ type: {
4069
+ array: [
4070
+ "u8",
4071
+ 32
4072
+ ]
4073
+ }
4074
+ }
4075
+ ]
4076
+ },
4077
+ {
3741
4078
  name: "collect_trading_fee",
3742
4079
  discriminator: [
3743
4080
  97,
@@ -4157,6 +4494,58 @@ var question_market_default = {
4157
4494
  }
4158
4495
  ]
4159
4496
  },
4497
+ {
4498
+ name: "grow_config",
4499
+ discriminator: [
4500
+ 190,
4501
+ 5,
4502
+ 0,
4503
+ 130,
4504
+ 65,
4505
+ 253,
4506
+ 94,
4507
+ 228
4508
+ ],
4509
+ accounts: [
4510
+ {
4511
+ name: "payer",
4512
+ writable: true,
4513
+ signer: true
4514
+ },
4515
+ {
4516
+ name: "owner",
4517
+ signer: true
4518
+ },
4519
+ {
4520
+ name: "config",
4521
+ writable: true,
4522
+ pda: {
4523
+ seeds: [
4524
+ {
4525
+ kind: "const",
4526
+ value: [
4527
+ 99,
4528
+ 111,
4529
+ 110,
4530
+ 102,
4531
+ 105,
4532
+ 103
4533
+ ]
4534
+ },
4535
+ {
4536
+ kind: "account",
4537
+ path: "owner"
4538
+ }
4539
+ ]
4540
+ }
4541
+ },
4542
+ {
4543
+ name: "system_program",
4544
+ address: "11111111111111111111111111111111"
4545
+ }
4546
+ ],
4547
+ args: []
4548
+ },
4160
4549
  {
4161
4550
  name: "initialize",
4162
4551
  discriminator: [
@@ -4525,6 +4914,63 @@ var question_market_default = {
4525
4914
  }
4526
4915
  ]
4527
4916
  },
4917
+ {
4918
+ name: "restore_config",
4919
+ discriminator: [
4920
+ 95,
4921
+ 203,
4922
+ 226,
4923
+ 92,
4924
+ 60,
4925
+ 222,
4926
+ 192,
4927
+ 221
4928
+ ],
4929
+ accounts: [
4930
+ {
4931
+ name: "payer",
4932
+ writable: true,
4933
+ signer: true
4934
+ },
4935
+ {
4936
+ name: "owner",
4937
+ signer: true
4938
+ },
4939
+ {
4940
+ name: "config",
4941
+ writable: true,
4942
+ pda: {
4943
+ seeds: [
4944
+ {
4945
+ kind: "const",
4946
+ value: [
4947
+ 99,
4948
+ 111,
4949
+ 110,
4950
+ 102,
4951
+ 105,
4952
+ 103
4953
+ ]
4954
+ },
4955
+ {
4956
+ kind: "account",
4957
+ path: "owner"
4958
+ }
4959
+ ]
4960
+ }
4961
+ },
4962
+ {
4963
+ name: "system_program",
4964
+ address: "11111111111111111111111111111111"
4965
+ }
4966
+ ],
4967
+ args: [
4968
+ {
4969
+ name: "snapshot",
4970
+ type: "bytes"
4971
+ }
4972
+ ]
4973
+ },
4528
4974
  {
4529
4975
  name: "update_config",
4530
4976
  discriminator: [
@@ -5557,7 +6003,7 @@ var question_market_default = {
5557
6003
  type: {
5558
6004
  array: [
5559
6005
  "pubkey",
5560
- 10
6006
+ 30
5561
6007
  ]
5562
6008
  }
5563
6009
  },
@@ -7659,9 +8105,6 @@ var clob_exchange_default = {
7659
8105
  instructions: [
7660
8106
  {
7661
8107
  name: "add_operator",
7662
- docs: [
7663
- "Add an authorized operator (off-chain matching engine)."
7664
- ],
7665
8108
  discriminator: [
7666
8109
  149,
7667
8110
  142,
@@ -7710,11 +8153,75 @@ var clob_exchange_default = {
7710
8153
  ]
7711
8154
  },
7712
8155
  {
7713
- name: "force_reset_clob",
8156
+ name: "cancel_order",
7714
8157
  docs: [
7715
- "Force-reset the CLOB config (upgrade authority only).",
7716
- "Use when the original admin keypair is lost."
8158
+ "Cancel an order \u2014 close OrderRecord PDA, return rent to maker."
8159
+ ],
8160
+ discriminator: [
8161
+ 95,
8162
+ 129,
8163
+ 237,
8164
+ 240,
8165
+ 8,
8166
+ 49,
8167
+ 223,
8168
+ 132
8169
+ ],
8170
+ accounts: [
8171
+ {
8172
+ name: "maker",
8173
+ docs: [
8174
+ "Must be the order maker/signer"
8175
+ ],
8176
+ signer: true
8177
+ },
8178
+ {
8179
+ name: "order_record",
8180
+ writable: true,
8181
+ pda: {
8182
+ seeds: [
8183
+ {
8184
+ kind: "const",
8185
+ value: [
8186
+ 111,
8187
+ 114,
8188
+ 100,
8189
+ 101,
8190
+ 114,
8191
+ 95,
8192
+ 114,
8193
+ 101,
8194
+ 99,
8195
+ 111,
8196
+ 114,
8197
+ 100
8198
+ ]
8199
+ },
8200
+ {
8201
+ kind: "account",
8202
+ path: "maker"
8203
+ },
8204
+ {
8205
+ kind: "arg",
8206
+ path: "nonce"
8207
+ }
8208
+ ]
8209
+ }
8210
+ },
8211
+ {
8212
+ name: "system_program",
8213
+ address: "11111111111111111111111111111111"
8214
+ }
7717
8215
  ],
8216
+ args: [
8217
+ {
8218
+ name: "nonce",
8219
+ type: "u64"
8220
+ }
8221
+ ]
8222
+ },
8223
+ {
8224
+ name: "force_reset_clob",
7718
8225
  discriminator: [
7719
8226
  96,
7720
8227
  95,
@@ -7789,9 +8296,6 @@ var clob_exchange_default = {
7789
8296
  },
7790
8297
  {
7791
8298
  name: "initialize_clob",
7792
- docs: [
7793
- "Initialize the CLOB global config."
7794
- ],
7795
8299
  discriminator: [
7796
8300
  35,
7797
8301
  69,
@@ -7861,10 +8365,7 @@ var clob_exchange_default = {
7861
8365
  {
7862
8366
  name: "match_complementary",
7863
8367
  docs: [
7864
- "COMPLEMENTARY match: one buyer of YES/NO tokens meets one seller.",
7865
- "Operator verifies signatures off-chain, executes atomically on-chain.",
7866
- "",
7867
- "Execution price = seller's ask (maker-fills-taker model)."
8368
+ "COMPLEMENTARY match: 1 taker (BUY) + N makers (SELL) via remaining_accounts."
7868
8369
  ],
7869
8370
  discriminator: [
7870
8371
  100,
@@ -7879,24 +8380,15 @@ var clob_exchange_default = {
7879
8380
  accounts: [
7880
8381
  {
7881
8382
  name: "operator",
7882
- docs: [
7883
- "Authorized operator (whitelisted signer)"
7884
- ],
7885
8383
  signer: true
7886
8384
  },
7887
8385
  {
7888
8386
  name: "payer",
7889
- docs: [
7890
- "Fee payer \u2014 pays tx fee and PDA rent"
7891
- ],
7892
8387
  writable: true,
7893
8388
  signer: true
7894
8389
  },
7895
8390
  {
7896
8391
  name: "clob_config",
7897
- docs: [
7898
- "CLOB config PDA \u2014 also used as the signing authority for CTF CPIs."
7899
- ],
7900
8392
  writable: true,
7901
8393
  pda: {
7902
8394
  seeds: [
@@ -7919,27 +8411,14 @@ var clob_exchange_default = {
7919
8411
  ]
7920
8412
  }
7921
8413
  },
7922
- {
7923
- name: "ix_sysvar",
7924
- address: "Sysvar1nstructions1111111111111111111111111"
7925
- },
7926
8414
  {
7927
8415
  name: "condition"
7928
8416
  },
7929
8417
  {
7930
- name: "buyer"
7931
- },
7932
- {
7933
- name: "buyer_collateral",
7934
- writable: true
7935
- },
7936
- {
7937
- name: "buyer_token_account",
7938
- writable: true
8418
+ name: "taker"
7939
8419
  },
7940
8420
  {
7941
- name: "buy_order_status",
7942
- writable: true,
8421
+ name: "taker_order_record",
7943
8422
  pda: {
7944
8423
  seeds: [
7945
8424
  {
@@ -7949,33 +8428,41 @@ var clob_exchange_default = {
7949
8428
  114,
7950
8429
  100,
7951
8430
  101,
7952
- 114
8431
+ 114,
8432
+ 95,
8433
+ 114,
8434
+ 101,
8435
+ 99,
8436
+ 111,
8437
+ 114,
8438
+ 100
7953
8439
  ]
7954
8440
  },
7955
8441
  {
7956
8442
  kind: "account",
7957
- path: "buyer"
8443
+ path: "taker"
7958
8444
  },
7959
8445
  {
7960
8446
  kind: "arg",
7961
- path: "buy_signed.order.nonce"
8447
+ path: "taker_nonce"
7962
8448
  }
7963
8449
  ]
7964
8450
  }
7965
8451
  },
7966
8452
  {
7967
- name: "seller"
8453
+ name: "taker_collateral",
8454
+ writable: true
7968
8455
  },
7969
8456
  {
7970
- name: "seller_token_account",
8457
+ name: "taker_token_account",
7971
8458
  writable: true
7972
8459
  },
7973
8460
  {
7974
- name: "seller_collateral",
8461
+ name: "taker_position",
7975
8462
  writable: true
7976
8463
  },
7977
8464
  {
7978
- name: "sell_order_status",
8465
+ name: "taker_order_status",
7979
8466
  writable: true,
7980
8467
  pda: {
7981
8468
  seeds: [
@@ -7991,11 +8478,11 @@ var clob_exchange_default = {
7991
8478
  },
7992
8479
  {
7993
8480
  kind: "account",
7994
- path: "seller"
8481
+ path: "taker"
7995
8482
  },
7996
8483
  {
7997
8484
  kind: "arg",
7998
- path: "sell_signed.order.nonce"
8485
+ path: "taker_nonce"
7999
8486
  }
8000
8487
  ]
8001
8488
  }
@@ -8008,17 +8495,9 @@ var clob_exchange_default = {
8008
8495
  name: "outcome_mint",
8009
8496
  writable: true
8010
8497
  },
8011
- {
8012
- name: "seller_position",
8013
- writable: true
8014
- },
8015
- {
8016
- name: "buyer_position",
8017
- writable: true
8018
- },
8019
8498
  {
8020
8499
  name: "conditional_tokens_program",
8021
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8500
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8022
8501
  },
8023
8502
  {
8024
8503
  name: "token_program",
@@ -8035,20 +8514,8 @@ var clob_exchange_default = {
8035
8514
  ],
8036
8515
  args: [
8037
8516
  {
8038
- name: "buy_signed",
8039
- type: {
8040
- defined: {
8041
- name: "SignedOrder"
8042
- }
8043
- }
8044
- },
8045
- {
8046
- name: "sell_signed",
8047
- type: {
8048
- defined: {
8049
- name: "SignedOrder"
8050
- }
8051
- }
8517
+ name: "taker_nonce",
8518
+ type: "u64"
8052
8519
  },
8053
8520
  {
8054
8521
  name: "fill_amount",
@@ -8059,9 +8526,7 @@ var clob_exchange_default = {
8059
8526
  {
8060
8527
  name: "match_merge_orders",
8061
8528
  docs: [
8062
- "MERGE match: two sellers on complementary sides (one sells YES, one sells NO).",
8063
- "Their combined 1 YES + 1 NO is merged back into 1 USDC.",
8064
- "Requires: yes_price_bps + no_price_bps <= 10_000."
8529
+ "MERGE match: 1 taker (YES SELL) + N makers (NO SELL) via remaining_accounts."
8065
8530
  ],
8066
8531
  discriminator: [
8067
8532
  105,
@@ -8076,16 +8541,10 @@ var clob_exchange_default = {
8076
8541
  accounts: [
8077
8542
  {
8078
8543
  name: "operator",
8079
- docs: [
8080
- "Authorized operator (whitelisted signer)"
8081
- ],
8082
8544
  signer: true
8083
8545
  },
8084
8546
  {
8085
8547
  name: "payer",
8086
- docs: [
8087
- "Fee payer \u2014 pays tx fee and PDA rent"
8088
- ],
8089
8548
  writable: true,
8090
8549
  signer: true
8091
8550
  },
@@ -8112,40 +8571,14 @@ var clob_exchange_default = {
8112
8571
  ]
8113
8572
  }
8114
8573
  },
8115
- {
8116
- name: "ix_sysvar",
8117
- address: "Sysvar1nstructions1111111111111111111111111"
8118
- },
8119
8574
  {
8120
8575
  name: "condition"
8121
8576
  },
8122
8577
  {
8123
- name: "seller_yes"
8124
- },
8125
- {
8126
- name: "seller_yes_token_account",
8127
- docs: [
8128
- "Seller YES's YES token account (tokens leave here)"
8129
- ],
8130
- writable: true
8131
- },
8132
- {
8133
- name: "seller_yes_position",
8134
- docs: [
8135
- "Seller YES's YES Position PDA"
8136
- ],
8137
- writable: true
8138
- },
8139
- {
8140
- name: "seller_yes_collateral",
8141
- docs: [
8142
- "Seller YES receives USDC here"
8143
- ],
8144
- writable: true
8578
+ name: "taker"
8145
8579
  },
8146
8580
  {
8147
- name: "yes_order_status",
8148
- writable: true,
8581
+ name: "taker_order_record",
8149
8582
  pda: {
8150
8583
  seeds: [
8151
8584
  {
@@ -8155,37 +8588,41 @@ var clob_exchange_default = {
8155
8588
  114,
8156
8589
  100,
8157
8590
  101,
8158
- 114
8159
- ]
8160
- },
8161
- {
8162
- kind: "account",
8163
- path: "seller_yes"
8164
- },
8165
- {
8591
+ 114,
8592
+ 95,
8593
+ 114,
8594
+ 101,
8595
+ 99,
8596
+ 111,
8597
+ 114,
8598
+ 100
8599
+ ]
8600
+ },
8601
+ {
8602
+ kind: "account",
8603
+ path: "taker"
8604
+ },
8605
+ {
8166
8606
  kind: "arg",
8167
- path: "yes_signed.order.nonce"
8607
+ path: "taker_nonce"
8168
8608
  }
8169
8609
  ]
8170
8610
  }
8171
8611
  },
8172
8612
  {
8173
- name: "seller_no"
8174
- },
8175
- {
8176
- name: "seller_no_token_account",
8613
+ name: "taker_yes_token",
8177
8614
  writable: true
8178
8615
  },
8179
8616
  {
8180
- name: "seller_no_position",
8617
+ name: "taker_yes_position",
8181
8618
  writable: true
8182
8619
  },
8183
8620
  {
8184
- name: "seller_no_collateral",
8621
+ name: "taker_collateral",
8185
8622
  writable: true
8186
8623
  },
8187
8624
  {
8188
- name: "no_order_status",
8625
+ name: "taker_order_status",
8189
8626
  writable: true,
8190
8627
  pda: {
8191
8628
  seeds: [
@@ -8201,11 +8638,11 @@ var clob_exchange_default = {
8201
8638
  },
8202
8639
  {
8203
8640
  kind: "account",
8204
- path: "seller_no"
8641
+ path: "taker"
8205
8642
  },
8206
8643
  {
8207
8644
  kind: "arg",
8208
- path: "no_signed.order.nonce"
8645
+ path: "taker_nonce"
8209
8646
  }
8210
8647
  ]
8211
8648
  }
@@ -8232,16 +8669,10 @@ var clob_exchange_default = {
8232
8669
  },
8233
8670
  {
8234
8671
  name: "fee_recipient",
8235
- docs: [
8236
- "Fee recipient (receives spread)"
8237
- ],
8238
8672
  writable: true
8239
8673
  },
8240
8674
  {
8241
8675
  name: "clob_authority",
8242
- docs: [
8243
- "CLOB authority PDA"
8244
- ],
8245
8676
  pda: {
8246
8677
  seeds: [
8247
8678
  {
@@ -8265,7 +8696,7 @@ var clob_exchange_default = {
8265
8696
  },
8266
8697
  {
8267
8698
  name: "conditional_tokens_program",
8268
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8699
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8269
8700
  },
8270
8701
  {
8271
8702
  name: "collateral_token_program",
@@ -8278,20 +8709,8 @@ var clob_exchange_default = {
8278
8709
  ],
8279
8710
  args: [
8280
8711
  {
8281
- name: "yes_signed",
8282
- type: {
8283
- defined: {
8284
- name: "SignedOrder"
8285
- }
8286
- }
8287
- },
8288
- {
8289
- name: "no_signed",
8290
- type: {
8291
- defined: {
8292
- name: "SignedOrder"
8293
- }
8294
- }
8712
+ name: "taker_nonce",
8713
+ type: "u64"
8295
8714
  },
8296
8715
  {
8297
8716
  name: "fill_amount",
@@ -8302,9 +8721,7 @@ var clob_exchange_default = {
8302
8721
  {
8303
8722
  name: "match_mint_orders",
8304
8723
  docs: [
8305
- "MINT match: two buyers on complementary sides (one buys YES, one buys NO).",
8306
- "Their combined USDC is used to split 1 USDC \u2192 1 YES + 1 NO.",
8307
- "Requires: yes_price_bps + no_price_bps >= 10_000."
8724
+ "MINT match: 1 taker (YES BUY) + N makers (NO BUY) via remaining_accounts."
8308
8725
  ],
8309
8726
  discriminator: [
8310
8727
  146,
@@ -8319,16 +8736,10 @@ var clob_exchange_default = {
8319
8736
  accounts: [
8320
8737
  {
8321
8738
  name: "operator",
8322
- docs: [
8323
- "Authorized operator (whitelisted signer)"
8324
- ],
8325
8739
  signer: true
8326
8740
  },
8327
8741
  {
8328
8742
  name: "payer",
8329
- docs: [
8330
- "Fee payer \u2014 pays tx fee and PDA rent"
8331
- ],
8332
8743
  writable: true,
8333
8744
  signer: true
8334
8745
  },
@@ -8355,31 +8766,14 @@ var clob_exchange_default = {
8355
8766
  ]
8356
8767
  }
8357
8768
  },
8358
- {
8359
- name: "ix_sysvar",
8360
- address: "Sysvar1nstructions1111111111111111111111111"
8361
- },
8362
8769
  {
8363
8770
  name: "condition"
8364
8771
  },
8365
8772
  {
8366
- name: "buyer_yes"
8367
- },
8368
- {
8369
- name: "buyer_yes_collateral",
8370
- writable: true
8371
- },
8372
- {
8373
- name: "buyer_yes_token_account",
8374
- writable: true
8773
+ name: "taker"
8375
8774
  },
8376
8775
  {
8377
- name: "buyer_yes_position",
8378
- writable: true
8379
- },
8380
- {
8381
- name: "yes_order_status",
8382
- writable: true,
8776
+ name: "taker_order_record",
8383
8777
  pda: {
8384
8778
  seeds: [
8385
8779
  {
@@ -8389,37 +8783,41 @@ var clob_exchange_default = {
8389
8783
  114,
8390
8784
  100,
8391
8785
  101,
8392
- 114
8786
+ 114,
8787
+ 95,
8788
+ 114,
8789
+ 101,
8790
+ 99,
8791
+ 111,
8792
+ 114,
8793
+ 100
8393
8794
  ]
8394
8795
  },
8395
8796
  {
8396
8797
  kind: "account",
8397
- path: "buyer_yes"
8798
+ path: "taker"
8398
8799
  },
8399
8800
  {
8400
8801
  kind: "arg",
8401
- path: "yes_signed.order.nonce"
8802
+ path: "taker_nonce"
8402
8803
  }
8403
8804
  ]
8404
8805
  }
8405
8806
  },
8406
8807
  {
8407
- name: "buyer_no"
8408
- },
8409
- {
8410
- name: "buyer_no_collateral",
8808
+ name: "taker_collateral",
8411
8809
  writable: true
8412
8810
  },
8413
8811
  {
8414
- name: "buyer_no_token_account",
8812
+ name: "taker_yes_token",
8415
8813
  writable: true
8416
8814
  },
8417
8815
  {
8418
- name: "buyer_no_position",
8816
+ name: "taker_yes_position",
8419
8817
  writable: true
8420
8818
  },
8421
8819
  {
8422
- name: "no_order_status",
8820
+ name: "taker_order_status",
8423
8821
  writable: true,
8424
8822
  pda: {
8425
8823
  seeds: [
@@ -8435,11 +8833,11 @@ var clob_exchange_default = {
8435
8833
  },
8436
8834
  {
8437
8835
  kind: "account",
8438
- path: "buyer_no"
8836
+ path: "taker"
8439
8837
  },
8440
8838
  {
8441
8839
  kind: "arg",
8442
- path: "no_signed.order.nonce"
8840
+ path: "taker_nonce"
8443
8841
  }
8444
8842
  ]
8445
8843
  }
@@ -8466,9 +8864,6 @@ var clob_exchange_default = {
8466
8864
  },
8467
8865
  {
8468
8866
  name: "clob_authority",
8469
- docs: [
8470
- "CLOB authority PDA (signs CTF CPI)"
8471
- ],
8472
8867
  pda: {
8473
8868
  seeds: [
8474
8869
  {
@@ -8492,7 +8887,7 @@ var clob_exchange_default = {
8492
8887
  },
8493
8888
  {
8494
8889
  name: "conditional_tokens_program",
8495
- address: "7boT4uqXGRMbDPzA7Q9znqbfYNB6auoXUcDnUfxyZAU"
8890
+ address: "A6N1F8MRsdgcojAx8p6FaECvw8mo8w6qJcWsbKQBANK4"
8496
8891
  },
8497
8892
  {
8498
8893
  name: "collateral_token_program",
@@ -8505,32 +8900,194 @@ var clob_exchange_default = {
8505
8900
  ],
8506
8901
  args: [
8507
8902
  {
8508
- name: "yes_signed",
8509
- type: {
8510
- defined: {
8511
- name: "SignedOrder"
8512
- }
8903
+ name: "taker_nonce",
8904
+ type: "u64"
8905
+ },
8906
+ {
8907
+ name: "fill_amount",
8908
+ type: "u64"
8909
+ }
8910
+ ]
8911
+ },
8912
+ {
8913
+ name: "register_order",
8914
+ docs: [
8915
+ "Register a signed order on-chain (Ed25519 verify at registration time).",
8916
+ "ix[0] must be Ed25519 precompile with 1 entry for order.signer."
8917
+ ],
8918
+ discriminator: [
8919
+ 92,
8920
+ 37,
8921
+ 29,
8922
+ 46,
8923
+ 77,
8924
+ 250,
8925
+ 219,
8926
+ 6
8927
+ ],
8928
+ accounts: [
8929
+ {
8930
+ name: "payer",
8931
+ docs: [
8932
+ "Operator pays rent for the OrderRecord PDA."
8933
+ ],
8934
+ writable: true,
8935
+ signer: true
8936
+ },
8937
+ {
8938
+ name: "clob_config",
8939
+ pda: {
8940
+ seeds: [
8941
+ {
8942
+ kind: "const",
8943
+ value: [
8944
+ 99,
8945
+ 108,
8946
+ 111,
8947
+ 98,
8948
+ 95,
8949
+ 99,
8950
+ 111,
8951
+ 110,
8952
+ 102,
8953
+ 105,
8954
+ 103
8955
+ ]
8956
+ }
8957
+ ]
8513
8958
  }
8514
8959
  },
8515
8960
  {
8516
- name: "no_signed",
8517
- type: {
8518
- defined: {
8519
- name: "SignedOrder"
8520
- }
8961
+ name: "ix_sysvar",
8962
+ address: "Sysvar1nstructions1111111111111111111111111"
8963
+ },
8964
+ {
8965
+ name: "order_signer"
8966
+ },
8967
+ {
8968
+ name: "order_record",
8969
+ writable: true,
8970
+ pda: {
8971
+ seeds: [
8972
+ {
8973
+ kind: "const",
8974
+ value: [
8975
+ 111,
8976
+ 114,
8977
+ 100,
8978
+ 101,
8979
+ 114,
8980
+ 95,
8981
+ 114,
8982
+ 101,
8983
+ 99,
8984
+ 111,
8985
+ 114,
8986
+ 100
8987
+ ]
8988
+ },
8989
+ {
8990
+ kind: "account",
8991
+ path: "order_signer"
8992
+ },
8993
+ {
8994
+ kind: "arg",
8995
+ path: "nonce"
8996
+ }
8997
+ ]
8521
8998
  }
8522
8999
  },
8523
9000
  {
8524
- name: "fill_amount",
9001
+ name: "order_status",
9002
+ writable: true,
9003
+ pda: {
9004
+ seeds: [
9005
+ {
9006
+ kind: "const",
9007
+ value: [
9008
+ 111,
9009
+ 114,
9010
+ 100,
9011
+ 101,
9012
+ 114
9013
+ ]
9014
+ },
9015
+ {
9016
+ kind: "account",
9017
+ path: "order_signer"
9018
+ },
9019
+ {
9020
+ kind: "arg",
9021
+ path: "nonce"
9022
+ }
9023
+ ]
9024
+ }
9025
+ },
9026
+ {
9027
+ name: "system_program",
9028
+ address: "11111111111111111111111111111111"
9029
+ }
9030
+ ],
9031
+ args: [
9032
+ {
9033
+ name: "nonce",
8525
9034
  type: "u64"
8526
9035
  }
8527
9036
  ]
8528
9037
  },
8529
9038
  {
8530
- name: "remove_operator",
8531
- docs: [
8532
- "Remove an operator."
9039
+ name: "reinit_clob",
9040
+ discriminator: [
9041
+ 41,
9042
+ 95,
9043
+ 240,
9044
+ 222,
9045
+ 95,
9046
+ 170,
9047
+ 14,
9048
+ 224
9049
+ ],
9050
+ accounts: [
9051
+ {
9052
+ name: "upgrade_authority",
9053
+ writable: true,
9054
+ signer: true
9055
+ },
9056
+ {
9057
+ name: "program_data"
9058
+ },
9059
+ {
9060
+ name: "clob_config",
9061
+ writable: true
9062
+ }
8533
9063
  ],
9064
+ args: [
9065
+ {
9066
+ name: "new_admin",
9067
+ type: "pubkey"
9068
+ },
9069
+ {
9070
+ name: "new_operators",
9071
+ type: {
9072
+ vec: "pubkey"
9073
+ }
9074
+ },
9075
+ {
9076
+ name: "new_fee_recipient",
9077
+ type: "pubkey"
9078
+ },
9079
+ {
9080
+ name: "new_fee_rate_bps",
9081
+ type: "u16"
9082
+ },
9083
+ {
9084
+ name: "conditional_tokens_program",
9085
+ type: "pubkey"
9086
+ }
9087
+ ]
9088
+ },
9089
+ {
9090
+ name: "remove_operator",
8534
9091
  discriminator: [
8535
9092
  84,
8536
9093
  183,
@@ -8580,9 +9137,6 @@ var clob_exchange_default = {
8580
9137
  },
8581
9138
  {
8582
9139
  name: "set_paused",
8583
- docs: [
8584
- "Pause or unpause the CLOB (admin only)."
8585
- ],
8586
9140
  discriminator: [
8587
9141
  91,
8588
9142
  60,
@@ -8657,6 +9211,19 @@ var clob_exchange_default = {
8657
9211
  65,
8658
9212
  3
8659
9213
  ]
9214
+ },
9215
+ {
9216
+ name: "SignedOrderRecord",
9217
+ discriminator: [
9218
+ 16,
9219
+ 167,
9220
+ 189,
9221
+ 166,
9222
+ 85,
9223
+ 0,
9224
+ 231,
9225
+ 55
9226
+ ]
8660
9227
  }
8661
9228
  ],
8662
9229
  events: [
@@ -8851,29 +9418,13 @@ var clob_exchange_default = {
8851
9418
  type: "pubkey"
8852
9419
  },
8853
9420
  {
8854
- name: "buyer",
8855
- type: "pubkey"
8856
- },
8857
- {
8858
- name: "seller",
9421
+ name: "taker",
8859
9422
  type: "pubkey"
8860
9423
  },
8861
- {
8862
- name: "token_id",
8863
- type: "u8"
8864
- },
8865
9424
  {
8866
9425
  name: "fill_amount",
8867
9426
  type: "u64"
8868
9427
  },
8869
- {
8870
- name: "price_bps",
8871
- type: "u64"
8872
- },
8873
- {
8874
- name: "usdc_transferred",
8875
- type: "u64"
8876
- },
8877
9428
  {
8878
9429
  name: "fee",
8879
9430
  type: "u64"
@@ -9024,33 +9575,13 @@ var clob_exchange_default = {
9024
9575
  type: "pubkey"
9025
9576
  },
9026
9577
  {
9027
- name: "seller_yes",
9028
- type: "pubkey"
9029
- },
9030
- {
9031
- name: "seller_no",
9578
+ name: "taker",
9032
9579
  type: "pubkey"
9033
9580
  },
9034
9581
  {
9035
9582
  name: "fill_amount",
9036
9583
  type: "u64"
9037
9584
  },
9038
- {
9039
- name: "yes_price_bps",
9040
- type: "u64"
9041
- },
9042
- {
9043
- name: "no_price_bps",
9044
- type: "u64"
9045
- },
9046
- {
9047
- name: "yes_payout",
9048
- type: "u64"
9049
- },
9050
- {
9051
- name: "no_payout",
9052
- type: "u64"
9053
- },
9054
9585
  {
9055
9586
  name: "fee",
9056
9587
  type: "u64"
@@ -9071,173 +9602,108 @@ var clob_exchange_default = {
9071
9602
  name: "buyer_yes",
9072
9603
  type: "pubkey"
9073
9604
  },
9074
- {
9075
- name: "buyer_no",
9076
- type: "pubkey"
9077
- },
9078
9605
  {
9079
9606
  name: "fill_amount",
9080
9607
  type: "u64"
9081
- },
9608
+ }
9609
+ ]
9610
+ }
9611
+ },
9612
+ {
9613
+ name: "OrderStatus",
9614
+ docs: [
9615
+ "Tracks the fill state of an order for replay protection.",
9616
+ 'PDA seeds: [b"order", maker_pubkey, nonce_le_bytes]',
9617
+ "",
9618
+ "Created on first fill (init_if_needed). A missing PDA means the order",
9619
+ "has never been touched (remaining = order.amount)."
9620
+ ],
9621
+ type: {
9622
+ kind: "struct",
9623
+ fields: [
9082
9624
  {
9083
- name: "yes_price_bps",
9084
- type: "u64"
9625
+ name: "maker",
9626
+ type: "pubkey"
9085
9627
  },
9086
9628
  {
9087
- name: "no_price_bps",
9629
+ name: "nonce",
9088
9630
  type: "u64"
9089
9631
  },
9090
9632
  {
9091
- name: "yes_cost",
9633
+ name: "filled_amount",
9092
9634
  type: "u64"
9093
9635
  },
9094
9636
  {
9095
- name: "no_cost",
9096
- type: "u64"
9637
+ name: "bump",
9638
+ type: "u8"
9097
9639
  }
9098
9640
  ]
9099
9641
  }
9100
9642
  },
9101
9643
  {
9102
- name: "Order",
9644
+ name: "SignedOrderRecord",
9103
9645
  docs: [
9104
- "Signed order message \u2014 passed as instruction data (not stored on-chain).",
9105
- "The operator verifies the maker's off-chain signature before calling match_*."
9646
+ "On-chain verified order record.",
9647
+ "Created by `register_order` after Ed25519 signature verification.",
9648
+ "Read by match instructions via remaining_accounts.",
9649
+ "Closed (rent returned) when order is fully filled or cancelled.",
9650
+ "",
9651
+ 'PDA seeds: [b"order_record", maker, nonce_le_bytes]'
9106
9652
  ],
9107
9653
  type: {
9108
9654
  kind: "struct",
9109
9655
  fields: [
9110
9656
  {
9111
9657
  name: "maker",
9112
- docs: [
9113
- "Maker's wallet pubkey"
9114
- ],
9115
9658
  type: "pubkey"
9116
9659
  },
9117
9660
  {
9118
9661
  name: "condition",
9119
- docs: [
9120
- "Condition PDA this order belongs to"
9121
- ],
9122
9662
  type: "pubkey"
9123
9663
  },
9124
9664
  {
9125
9665
  name: "token_id",
9126
- docs: [
9127
- "Outcome token: 0=NO, 1=YES"
9128
- ],
9129
9666
  type: "u8"
9130
9667
  },
9131
9668
  {
9132
9669
  name: "side",
9133
- docs: [
9134
- "Side: 0=SELL (maker gives tokens, wants USDC), 1=BUY (maker gives USDC, wants tokens)"
9135
- ],
9136
9670
  type: "u8"
9137
9671
  },
9138
9672
  {
9139
- name: "price_bps",
9140
- docs: [
9141
- "Price in basis points (0-10000). e.g. 6000 = 60 cents per $1 of exposure.",
9142
- "For a BUY: maker pays price_bps / 10000 USDC per token.",
9143
- "For a SELL: maker wants price_bps / 10000 USDC per token."
9144
- ],
9673
+ name: "maker_amount",
9145
9674
  type: "u64"
9146
9675
  },
9147
9676
  {
9148
- name: "amount",
9149
- docs: [
9150
- "Maximum order size in token units (YES or NO tokens, 0 decimals)."
9151
- ],
9677
+ name: "taker_amount",
9152
9678
  type: "u64"
9153
9679
  },
9154
9680
  {
9155
9681
  name: "nonce",
9156
- docs: [
9157
- "Unique nonce per maker \u2014 used for OrderStatus PDA derivation & replay protection."
9158
- ],
9159
9682
  type: "u64"
9160
9683
  },
9161
9684
  {
9162
9685
  name: "expiry",
9163
- docs: [
9164
- "Unix timestamp after which the order is invalid (0 = no expiry)."
9165
- ],
9166
9686
  type: "i64"
9167
- }
9168
- ]
9169
- }
9170
- },
9171
- {
9172
- name: "OrderStatus",
9173
- docs: [
9174
- "Tracks the fill state of an order for replay protection.",
9175
- 'PDA seeds: [b"order", maker_pubkey, nonce_le_bytes]',
9176
- "",
9177
- "Created on first fill (init_if_needed). A missing PDA means the order",
9178
- "has never been touched (remaining = order.amount)."
9179
- ],
9180
- type: {
9181
- kind: "struct",
9182
- fields: [
9183
- {
9184
- name: "maker",
9185
- docs: [
9186
- "The maker who created the order"
9187
- ],
9188
- type: "pubkey"
9189
9687
  },
9190
9688
  {
9191
- name: "nonce",
9192
- docs: [
9193
- "Order nonce (unique per maker)"
9194
- ],
9195
- type: "u64"
9689
+ name: "created_at",
9690
+ type: "i64"
9196
9691
  },
9197
9692
  {
9198
- name: "filled_amount",
9199
- docs: [
9200
- "Amount of collateral (USDC) already filled"
9201
- ],
9693
+ name: "fee",
9202
9694
  type: "u64"
9203
9695
  },
9204
9696
  {
9205
- name: "bump",
9206
- docs: [
9207
- "Bump for this PDA"
9208
- ],
9209
- type: "u8"
9210
- }
9211
- ]
9212
- }
9213
- },
9214
- {
9215
- name: "SignedOrder",
9216
- docs: [
9217
- "Order + 64-byte Ed25519 signature over `order.to_signable_bytes()`.",
9218
- "Passed as instruction data to all match_* instructions.",
9219
- "On-chain: the program verifies the signature exists in the tx",
9220
- "via Ed25519 precompile instructions at known indices."
9221
- ],
9222
- type: {
9223
- kind: "struct",
9224
- fields: [
9697
+ name: "taker",
9698
+ type: "pubkey"
9699
+ },
9225
9700
  {
9226
- name: "order",
9227
- type: {
9228
- defined: {
9229
- name: "Order"
9230
- }
9231
- }
9701
+ name: "signer",
9702
+ type: "pubkey"
9232
9703
  },
9233
9704
  {
9234
- name: "signature",
9235
- type: {
9236
- array: [
9237
- "u8",
9238
- 64
9239
- ]
9240
- }
9705
+ name: "bump",
9706
+ type: "u8"
9241
9707
  }
9242
9708
  ]
9243
9709
  }
@@ -9394,8 +9860,10 @@ var fee_management_default = {
9394
9860
  {
9395
9861
  name: "market_oracle_vault",
9396
9862
  docs: [
9397
- "For admin questions \u2014 not used; pass any account non-writable (no transfer occurs)."
9398
- ]
9863
+ "Writable: tokens are transferred here when is_admin=false.",
9864
+ "For admin questions pass any writable account (no transfer occurs)."
9865
+ ],
9866
+ writable: true
9399
9867
  },
9400
9868
  {
9401
9869
  name: "token_program",
@@ -12952,85 +13420,1067 @@ var market_oracle_default = {
12952
13420
  ]
12953
13421
  };
12954
13422
 
12955
- // src/sdk.ts
12956
- var XMarketSDK = class {
12957
- constructor(config, wallet, marketOwner) {
12958
- this.networkConfig = config;
12959
- this.provider = new anchor4.AnchorProvider(
12960
- new Connection(config.rpcUrl, "confirmed"),
12961
- wallet,
12962
- { commitment: "confirmed", preflightCommitment: "confirmed" }
12963
- );
12964
- anchor4.setProvider(this.provider);
12965
- this._programIds = config.programIds;
12966
- this._marketOwner = marketOwner ?? wallet.publicKey;
12967
- }
12968
- _withAddress(idl, address) {
12969
- return { ...idl, address: address.toBase58() };
12970
- }
12971
- get oracle() {
12972
- if (!this._oracle) {
12973
- const program = new anchor4.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
12974
- this._oracle = new OracleClient(program, this.provider, this._programIds);
12975
- }
12976
- return this._oracle;
12977
- }
12978
- get hook() {
12979
- if (!this._hook) {
12980
- const program = new anchor4.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
12981
- this._hook = new HookClient(program, this.provider, this._programIds);
12982
- }
12983
- return this._hook;
12984
- }
12985
- get market() {
12986
- if (!this._market) {
12987
- const program = new anchor4.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
12988
- this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
12989
- this._market.ctfClient = this.ctf;
12990
- }
12991
- return this._market;
12992
- }
12993
- get ctf() {
12994
- if (!this._ctf) {
12995
- const program = new anchor4.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
12996
- this._ctf = new CtfClient(program, this.provider, this._programIds);
12997
- }
12998
- return this._ctf;
12999
- }
13000
- get clob() {
13001
- if (!this._clob) {
13002
- const program = new anchor4.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
13003
- this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
13004
- if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
13005
- this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
13006
- this._clob.feeClient = this.fee;
13007
- }
13008
- }
13009
- return this._clob;
13010
- }
13011
- get fee() {
13012
- if (!this._fee) {
13013
- if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
13014
- const program = new anchor4.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
13015
- this._fee = new FeeManagementClient(program, this.provider, this._programIds);
13016
- }
13017
- return this._fee;
13018
- }
13019
- get presale() {
13020
- if (!this._presale) {
13021
- if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
13022
- const program = new anchor4.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
13023
- this._presale = new PresaleClient(program, this.provider, this._programIds);
13024
- }
13025
- return this._presale;
13026
- }
13027
- get marketOracle() {
13028
- if (!this._marketOracle) {
13029
- if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
13030
- const program = new anchor4.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
13031
- this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
13032
- }
13033
- return this._marketOracle;
13423
+ // src/idls/admin_contract.json
13424
+ var admin_contract_default = {
13425
+ address: "4NdD5962SfGqofmeyjfifJpdGnwTAiKaUKB5Z42UDc9T",
13426
+ metadata: {
13427
+ name: "admin_contract",
13428
+ version: "0.1.0",
13429
+ spec: "0.1.0",
13430
+ description: "Admin contract for XMarket \u2014 whitelist, presale revenue custody, claim"
13431
+ },
13432
+ instructions: [
13433
+ {
13434
+ name: "add_admin",
13435
+ discriminator: [
13436
+ 177,
13437
+ 236,
13438
+ 33,
13439
+ 205,
13440
+ 124,
13441
+ 152,
13442
+ 55,
13443
+ 186
13444
+ ],
13445
+ accounts: [
13446
+ {
13447
+ name: "owner",
13448
+ signer: true
13449
+ },
13450
+ {
13451
+ name: "config",
13452
+ writable: true,
13453
+ pda: {
13454
+ seeds: [
13455
+ {
13456
+ kind: "const",
13457
+ value: [
13458
+ 97,
13459
+ 100,
13460
+ 109,
13461
+ 105,
13462
+ 110,
13463
+ 95,
13464
+ 99,
13465
+ 111,
13466
+ 110,
13467
+ 102,
13468
+ 105,
13469
+ 103
13470
+ ]
13471
+ },
13472
+ {
13473
+ kind: "account",
13474
+ path: "config.owner",
13475
+ account: "AdminConfig"
13476
+ }
13477
+ ]
13478
+ }
13479
+ }
13480
+ ],
13481
+ args: [
13482
+ {
13483
+ name: "address",
13484
+ type: "pubkey"
13485
+ }
13486
+ ]
13487
+ },
13488
+ {
13489
+ name: "add_to_whitelist",
13490
+ discriminator: [
13491
+ 157,
13492
+ 211,
13493
+ 52,
13494
+ 54,
13495
+ 144,
13496
+ 81,
13497
+ 5,
13498
+ 55
13499
+ ],
13500
+ accounts: [
13501
+ {
13502
+ name: "admin",
13503
+ signer: true
13504
+ },
13505
+ {
13506
+ name: "payer",
13507
+ writable: true,
13508
+ signer: true
13509
+ },
13510
+ {
13511
+ name: "config",
13512
+ writable: true,
13513
+ pda: {
13514
+ seeds: [
13515
+ {
13516
+ kind: "const",
13517
+ value: [
13518
+ 97,
13519
+ 100,
13520
+ 109,
13521
+ 105,
13522
+ 110,
13523
+ 95,
13524
+ 99,
13525
+ 111,
13526
+ 110,
13527
+ 102,
13528
+ 105,
13529
+ 103
13530
+ ]
13531
+ },
13532
+ {
13533
+ kind: "account",
13534
+ path: "config.owner",
13535
+ account: "AdminConfig"
13536
+ }
13537
+ ]
13538
+ }
13539
+ }
13540
+ ],
13541
+ args: [
13542
+ {
13543
+ name: "address",
13544
+ type: "pubkey"
13545
+ }
13546
+ ]
13547
+ },
13548
+ {
13549
+ name: "claim",
13550
+ discriminator: [
13551
+ 62,
13552
+ 198,
13553
+ 214,
13554
+ 193,
13555
+ 213,
13556
+ 159,
13557
+ 108,
13558
+ 210
13559
+ ],
13560
+ accounts: [
13561
+ {
13562
+ name: "claimer",
13563
+ signer: true
13564
+ },
13565
+ {
13566
+ name: "payer",
13567
+ writable: true,
13568
+ signer: true
13569
+ },
13570
+ {
13571
+ name: "config",
13572
+ pda: {
13573
+ seeds: [
13574
+ {
13575
+ kind: "const",
13576
+ value: [
13577
+ 97,
13578
+ 100,
13579
+ 109,
13580
+ 105,
13581
+ 110,
13582
+ 95,
13583
+ 99,
13584
+ 111,
13585
+ 110,
13586
+ 102,
13587
+ 105,
13588
+ 103
13589
+ ]
13590
+ },
13591
+ {
13592
+ kind: "account",
13593
+ path: "config.owner",
13594
+ account: "AdminConfig"
13595
+ }
13596
+ ]
13597
+ }
13598
+ },
13599
+ {
13600
+ name: "admin_vault",
13601
+ docs: [
13602
+ "ATA owned by config PDA"
13603
+ ],
13604
+ writable: true,
13605
+ pda: {
13606
+ seeds: [
13607
+ {
13608
+ kind: "account",
13609
+ path: "config"
13610
+ },
13611
+ {
13612
+ kind: "const",
13613
+ value: [
13614
+ 6,
13615
+ 221,
13616
+ 246,
13617
+ 225,
13618
+ 215,
13619
+ 101,
13620
+ 161,
13621
+ 147,
13622
+ 217,
13623
+ 203,
13624
+ 225,
13625
+ 70,
13626
+ 206,
13627
+ 235,
13628
+ 121,
13629
+ 172,
13630
+ 28,
13631
+ 180,
13632
+ 133,
13633
+ 237,
13634
+ 95,
13635
+ 91,
13636
+ 55,
13637
+ 145,
13638
+ 58,
13639
+ 140,
13640
+ 245,
13641
+ 133,
13642
+ 126,
13643
+ 255,
13644
+ 0,
13645
+ 169
13646
+ ]
13647
+ },
13648
+ {
13649
+ kind: "account",
13650
+ path: "config.collateral_mint",
13651
+ account: "AdminConfig"
13652
+ }
13653
+ ],
13654
+ program: {
13655
+ kind: "const",
13656
+ value: [
13657
+ 140,
13658
+ 151,
13659
+ 37,
13660
+ 143,
13661
+ 78,
13662
+ 36,
13663
+ 137,
13664
+ 241,
13665
+ 187,
13666
+ 61,
13667
+ 16,
13668
+ 41,
13669
+ 20,
13670
+ 142,
13671
+ 13,
13672
+ 131,
13673
+ 11,
13674
+ 90,
13675
+ 19,
13676
+ 153,
13677
+ 218,
13678
+ 255,
13679
+ 16,
13680
+ 132,
13681
+ 4,
13682
+ 142,
13683
+ 123,
13684
+ 216,
13685
+ 219,
13686
+ 233,
13687
+ 248,
13688
+ 89
13689
+ ]
13690
+ }
13691
+ }
13692
+ },
13693
+ {
13694
+ name: "claim_record",
13695
+ writable: true,
13696
+ pda: {
13697
+ seeds: [
13698
+ {
13699
+ kind: "const",
13700
+ value: [
13701
+ 99,
13702
+ 108,
13703
+ 97,
13704
+ 105,
13705
+ 109,
13706
+ 95,
13707
+ 114,
13708
+ 101,
13709
+ 99,
13710
+ 111,
13711
+ 114,
13712
+ 100
13713
+ ]
13714
+ },
13715
+ {
13716
+ kind: "arg",
13717
+ path: "condition_id"
13718
+ }
13719
+ ]
13720
+ }
13721
+ },
13722
+ {
13723
+ name: "claimer_token_account",
13724
+ docs: [
13725
+ "Claimer's USDC token account (receives payout)"
13726
+ ],
13727
+ writable: true
13728
+ },
13729
+ {
13730
+ name: "token_program",
13731
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13732
+ }
13733
+ ],
13734
+ args: [
13735
+ {
13736
+ name: "condition_id",
13737
+ type: {
13738
+ array: [
13739
+ "u8",
13740
+ 32
13741
+ ]
13742
+ }
13743
+ }
13744
+ ]
13745
+ },
13746
+ {
13747
+ name: "distribute_market",
13748
+ discriminator: [
13749
+ 130,
13750
+ 221,
13751
+ 123,
13752
+ 201,
13753
+ 185,
13754
+ 168,
13755
+ 63,
13756
+ 19
13757
+ ],
13758
+ accounts: [
13759
+ {
13760
+ name: "claimer",
13761
+ docs: [
13762
+ "BOTMM \u2014 must be in whitelist"
13763
+ ],
13764
+ signer: true
13765
+ },
13766
+ {
13767
+ name: "payer",
13768
+ writable: true,
13769
+ signer: true
13770
+ },
13771
+ {
13772
+ name: "config",
13773
+ pda: {
13774
+ seeds: [
13775
+ {
13776
+ kind: "const",
13777
+ value: [
13778
+ 97,
13779
+ 100,
13780
+ 109,
13781
+ 105,
13782
+ 110,
13783
+ 95,
13784
+ 99,
13785
+ 111,
13786
+ 110,
13787
+ 102,
13788
+ 105,
13789
+ 103
13790
+ ]
13791
+ },
13792
+ {
13793
+ kind: "account",
13794
+ path: "config.owner",
13795
+ account: "AdminConfig"
13796
+ }
13797
+ ]
13798
+ }
13799
+ },
13800
+ {
13801
+ name: "claimer_token_account",
13802
+ docs: [
13803
+ "BOTMM's USDC token account (source \u2014 claimer signs)"
13804
+ ],
13805
+ writable: true
13806
+ },
13807
+ {
13808
+ name: "market_oracle_vault",
13809
+ docs: [
13810
+ "market_oracle vault \u2014 MST holder reward pool for this condition"
13811
+ ],
13812
+ writable: true
13813
+ },
13814
+ {
13815
+ name: "token_program",
13816
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13817
+ }
13818
+ ],
13819
+ args: [
13820
+ {
13821
+ name: "condition_id",
13822
+ type: {
13823
+ array: [
13824
+ "u8",
13825
+ 32
13826
+ ]
13827
+ }
13828
+ },
13829
+ {
13830
+ name: "amount",
13831
+ type: "u64"
13832
+ }
13833
+ ]
13834
+ },
13835
+ {
13836
+ name: "initialize",
13837
+ discriminator: [
13838
+ 175,
13839
+ 175,
13840
+ 109,
13841
+ 31,
13842
+ 13,
13843
+ 152,
13844
+ 155,
13845
+ 237
13846
+ ],
13847
+ accounts: [
13848
+ {
13849
+ name: "owner",
13850
+ writable: true,
13851
+ signer: true
13852
+ },
13853
+ {
13854
+ name: "config",
13855
+ writable: true,
13856
+ pda: {
13857
+ seeds: [
13858
+ {
13859
+ kind: "const",
13860
+ value: [
13861
+ 97,
13862
+ 100,
13863
+ 109,
13864
+ 105,
13865
+ 110,
13866
+ 95,
13867
+ 99,
13868
+ 111,
13869
+ 110,
13870
+ 102,
13871
+ 105,
13872
+ 103
13873
+ ]
13874
+ },
13875
+ {
13876
+ kind: "account",
13877
+ path: "owner"
13878
+ }
13879
+ ]
13880
+ }
13881
+ },
13882
+ {
13883
+ name: "collateral_mint"
13884
+ },
13885
+ {
13886
+ name: "admin_vault",
13887
+ docs: [
13888
+ "ATA owned by config PDA \u2014 holds USDC for unclaimed presale revenue"
13889
+ ],
13890
+ writable: true,
13891
+ pda: {
13892
+ seeds: [
13893
+ {
13894
+ kind: "account",
13895
+ path: "config"
13896
+ },
13897
+ {
13898
+ kind: "const",
13899
+ value: [
13900
+ 6,
13901
+ 221,
13902
+ 246,
13903
+ 225,
13904
+ 215,
13905
+ 101,
13906
+ 161,
13907
+ 147,
13908
+ 217,
13909
+ 203,
13910
+ 225,
13911
+ 70,
13912
+ 206,
13913
+ 235,
13914
+ 121,
13915
+ 172,
13916
+ 28,
13917
+ 180,
13918
+ 133,
13919
+ 237,
13920
+ 95,
13921
+ 91,
13922
+ 55,
13923
+ 145,
13924
+ 58,
13925
+ 140,
13926
+ 245,
13927
+ 133,
13928
+ 126,
13929
+ 255,
13930
+ 0,
13931
+ 169
13932
+ ]
13933
+ },
13934
+ {
13935
+ kind: "account",
13936
+ path: "collateral_mint"
13937
+ }
13938
+ ],
13939
+ program: {
13940
+ kind: "const",
13941
+ value: [
13942
+ 140,
13943
+ 151,
13944
+ 37,
13945
+ 143,
13946
+ 78,
13947
+ 36,
13948
+ 137,
13949
+ 241,
13950
+ 187,
13951
+ 61,
13952
+ 16,
13953
+ 41,
13954
+ 20,
13955
+ 142,
13956
+ 13,
13957
+ 131,
13958
+ 11,
13959
+ 90,
13960
+ 19,
13961
+ 153,
13962
+ 218,
13963
+ 255,
13964
+ 16,
13965
+ 132,
13966
+ 4,
13967
+ 142,
13968
+ 123,
13969
+ 216,
13970
+ 219,
13971
+ 233,
13972
+ 248,
13973
+ 89
13974
+ ]
13975
+ }
13976
+ }
13977
+ },
13978
+ {
13979
+ name: "token_program",
13980
+ address: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
13981
+ },
13982
+ {
13983
+ name: "associated_token_program",
13984
+ address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
13985
+ },
13986
+ {
13987
+ name: "system_program",
13988
+ address: "11111111111111111111111111111111"
13989
+ }
13990
+ ],
13991
+ args: [
13992
+ {
13993
+ name: "authorized_caller",
13994
+ type: "pubkey"
13995
+ }
13996
+ ]
13997
+ },
13998
+ {
13999
+ name: "remove_admin",
14000
+ discriminator: [
14001
+ 74,
14002
+ 202,
14003
+ 71,
14004
+ 106,
14005
+ 252,
14006
+ 31,
14007
+ 72,
14008
+ 183
14009
+ ],
14010
+ accounts: [
14011
+ {
14012
+ name: "owner",
14013
+ signer: true
14014
+ },
14015
+ {
14016
+ name: "config",
14017
+ writable: true,
14018
+ pda: {
14019
+ seeds: [
14020
+ {
14021
+ kind: "const",
14022
+ value: [
14023
+ 97,
14024
+ 100,
14025
+ 109,
14026
+ 105,
14027
+ 110,
14028
+ 95,
14029
+ 99,
14030
+ 111,
14031
+ 110,
14032
+ 102,
14033
+ 105,
14034
+ 103
14035
+ ]
14036
+ },
14037
+ {
14038
+ kind: "account",
14039
+ path: "config.owner",
14040
+ account: "AdminConfig"
14041
+ }
14042
+ ]
14043
+ }
14044
+ }
14045
+ ],
14046
+ args: [
14047
+ {
14048
+ name: "address",
14049
+ type: "pubkey"
14050
+ }
14051
+ ]
14052
+ },
14053
+ {
14054
+ name: "remove_from_whitelist",
14055
+ discriminator: [
14056
+ 7,
14057
+ 144,
14058
+ 216,
14059
+ 239,
14060
+ 243,
14061
+ 236,
14062
+ 193,
14063
+ 235
14064
+ ],
14065
+ accounts: [
14066
+ {
14067
+ name: "admin",
14068
+ signer: true
14069
+ },
14070
+ {
14071
+ name: "payer",
14072
+ writable: true,
14073
+ signer: true
14074
+ },
14075
+ {
14076
+ name: "config",
14077
+ writable: true,
14078
+ pda: {
14079
+ seeds: [
14080
+ {
14081
+ kind: "const",
14082
+ value: [
14083
+ 97,
14084
+ 100,
14085
+ 109,
14086
+ 105,
14087
+ 110,
14088
+ 95,
14089
+ 99,
14090
+ 111,
14091
+ 110,
14092
+ 102,
14093
+ 105,
14094
+ 103
14095
+ ]
14096
+ },
14097
+ {
14098
+ kind: "account",
14099
+ path: "config.owner",
14100
+ account: "AdminConfig"
14101
+ }
14102
+ ]
14103
+ }
14104
+ }
14105
+ ],
14106
+ args: [
14107
+ {
14108
+ name: "address",
14109
+ type: "pubkey"
14110
+ }
14111
+ ]
14112
+ },
14113
+ {
14114
+ name: "set_presale_amount",
14115
+ discriminator: [
14116
+ 73,
14117
+ 71,
14118
+ 238,
14119
+ 3,
14120
+ 202,
14121
+ 163,
14122
+ 8,
14123
+ 254
14124
+ ],
14125
+ accounts: [
14126
+ {
14127
+ name: "caller",
14128
+ docs: [
14129
+ "question_market config PDA \u2014 signs this CPI call via seeds"
14130
+ ],
14131
+ signer: true
14132
+ },
14133
+ {
14134
+ name: "payer",
14135
+ writable: true,
14136
+ signer: true
14137
+ },
14138
+ {
14139
+ name: "config",
14140
+ pda: {
14141
+ seeds: [
14142
+ {
14143
+ kind: "const",
14144
+ value: [
14145
+ 97,
14146
+ 100,
14147
+ 109,
14148
+ 105,
14149
+ 110,
14150
+ 95,
14151
+ 99,
14152
+ 111,
14153
+ 110,
14154
+ 102,
14155
+ 105,
14156
+ 103
14157
+ ]
14158
+ },
14159
+ {
14160
+ kind: "account",
14161
+ path: "config.owner",
14162
+ account: "AdminConfig"
14163
+ }
14164
+ ]
14165
+ }
14166
+ },
14167
+ {
14168
+ name: "claim_record",
14169
+ writable: true,
14170
+ pda: {
14171
+ seeds: [
14172
+ {
14173
+ kind: "const",
14174
+ value: [
14175
+ 99,
14176
+ 108,
14177
+ 97,
14178
+ 105,
14179
+ 109,
14180
+ 95,
14181
+ 114,
14182
+ 101,
14183
+ 99,
14184
+ 111,
14185
+ 114,
14186
+ 100
14187
+ ]
14188
+ },
14189
+ {
14190
+ kind: "arg",
14191
+ path: "condition_id"
14192
+ }
14193
+ ]
14194
+ }
14195
+ },
14196
+ {
14197
+ name: "system_program",
14198
+ address: "11111111111111111111111111111111"
14199
+ }
14200
+ ],
14201
+ args: [
14202
+ {
14203
+ name: "condition_id",
14204
+ type: {
14205
+ array: [
14206
+ "u8",
14207
+ 32
14208
+ ]
14209
+ }
14210
+ },
14211
+ {
14212
+ name: "amount",
14213
+ type: "u64"
14214
+ }
14215
+ ]
14216
+ },
14217
+ {
14218
+ name: "update_config",
14219
+ discriminator: [
14220
+ 29,
14221
+ 158,
14222
+ 252,
14223
+ 191,
14224
+ 10,
14225
+ 83,
14226
+ 219,
14227
+ 99
14228
+ ],
14229
+ accounts: [
14230
+ {
14231
+ name: "owner",
14232
+ signer: true
14233
+ },
14234
+ {
14235
+ name: "config",
14236
+ writable: true,
14237
+ pda: {
14238
+ seeds: [
14239
+ {
14240
+ kind: "const",
14241
+ value: [
14242
+ 97,
14243
+ 100,
14244
+ 109,
14245
+ 105,
14246
+ 110,
14247
+ 95,
14248
+ 99,
14249
+ 111,
14250
+ 110,
14251
+ 102,
14252
+ 105,
14253
+ 103
14254
+ ]
14255
+ },
14256
+ {
14257
+ kind: "account",
14258
+ path: "config.owner",
14259
+ account: "AdminConfig"
14260
+ }
14261
+ ]
14262
+ }
14263
+ }
14264
+ ],
14265
+ args: [
14266
+ {
14267
+ name: "authorized_caller",
14268
+ type: "pubkey"
14269
+ }
14270
+ ]
14271
+ }
14272
+ ],
14273
+ accounts: [
14274
+ {
14275
+ name: "AdminConfig",
14276
+ discriminator: [
14277
+ 156,
14278
+ 10,
14279
+ 79,
14280
+ 161,
14281
+ 71,
14282
+ 9,
14283
+ 62,
14284
+ 77
14285
+ ]
14286
+ },
14287
+ {
14288
+ name: "ClaimRecord",
14289
+ discriminator: [
14290
+ 57,
14291
+ 229,
14292
+ 0,
14293
+ 9,
14294
+ 65,
14295
+ 62,
14296
+ 96,
14297
+ 7
14298
+ ]
14299
+ }
14300
+ ],
14301
+ types: [
14302
+ {
14303
+ name: "AdminConfig",
14304
+ type: {
14305
+ kind: "struct",
14306
+ fields: [
14307
+ {
14308
+ name: "version",
14309
+ type: "u8"
14310
+ },
14311
+ {
14312
+ name: "owner",
14313
+ type: "pubkey"
14314
+ },
14315
+ {
14316
+ name: "collateral_mint",
14317
+ type: "pubkey"
14318
+ },
14319
+ {
14320
+ name: "authorized_caller",
14321
+ docs: [
14322
+ "question_market config PDA \u2014 only this can call set_presale_amount"
14323
+ ],
14324
+ type: "pubkey"
14325
+ },
14326
+ {
14327
+ name: "admin_whitelist",
14328
+ type: {
14329
+ array: [
14330
+ "pubkey",
14331
+ 10
14332
+ ]
14333
+ }
14334
+ },
14335
+ {
14336
+ name: "admin_whitelist_len",
14337
+ type: "u8"
14338
+ },
14339
+ {
14340
+ name: "whitelist",
14341
+ type: {
14342
+ array: [
14343
+ "pubkey",
14344
+ 30
14345
+ ]
14346
+ }
14347
+ },
14348
+ {
14349
+ name: "whitelist_len",
14350
+ type: "u8"
14351
+ },
14352
+ {
14353
+ name: "bump",
14354
+ type: "u8"
14355
+ },
14356
+ {
14357
+ name: "_reserved",
14358
+ type: {
14359
+ array: [
14360
+ "u8",
14361
+ 64
14362
+ ]
14363
+ }
14364
+ }
14365
+ ]
14366
+ }
14367
+ },
14368
+ {
14369
+ name: "ClaimRecord",
14370
+ type: {
14371
+ kind: "struct",
14372
+ fields: [
14373
+ {
14374
+ name: "condition_id",
14375
+ type: {
14376
+ array: [
14377
+ "u8",
14378
+ 32
14379
+ ]
14380
+ }
14381
+ },
14382
+ {
14383
+ name: "amount",
14384
+ type: "u64"
14385
+ },
14386
+ {
14387
+ name: "bump",
14388
+ type: "u8"
14389
+ }
14390
+ ]
14391
+ }
14392
+ }
14393
+ ]
14394
+ };
14395
+
14396
+ // src/sdk.ts
14397
+ var XMarketSDK = class {
14398
+ // lazy-init in get admin()
14399
+ constructor(config, wallet, marketOwner) {
14400
+ this.networkConfig = config;
14401
+ this.provider = new anchor5.AnchorProvider(
14402
+ new Connection(config.rpcUrl, "confirmed"),
14403
+ wallet,
14404
+ { commitment: "confirmed", preflightCommitment: "confirmed" }
14405
+ );
14406
+ anchor5.setProvider(this.provider);
14407
+ this._programIds = config.programIds;
14408
+ this._marketOwner = marketOwner ?? wallet.publicKey;
14409
+ }
14410
+ _withAddress(idl, address) {
14411
+ return { ...idl, address: address.toBase58() };
14412
+ }
14413
+ get oracle() {
14414
+ if (!this._oracle) {
14415
+ const program = new anchor5.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
14416
+ this._oracle = new OracleClient(program, this.provider, this._programIds);
14417
+ }
14418
+ return this._oracle;
14419
+ }
14420
+ get hook() {
14421
+ if (!this._hook) {
14422
+ const program = new anchor5.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
14423
+ this._hook = new HookClient(program, this.provider, this._programIds);
14424
+ }
14425
+ return this._hook;
14426
+ }
14427
+ get market() {
14428
+ if (!this._market) {
14429
+ const program = new anchor5.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
14430
+ this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
14431
+ this._market.ctfClient = this.ctf;
14432
+ }
14433
+ return this._market;
14434
+ }
14435
+ get ctf() {
14436
+ if (!this._ctf) {
14437
+ const program = new anchor5.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
14438
+ this._ctf = new CtfClient(program, this.provider, this._programIds);
14439
+ }
14440
+ return this._ctf;
14441
+ }
14442
+ get clob() {
14443
+ if (!this._clob) {
14444
+ const program = new anchor5.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
14445
+ this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
14446
+ if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
14447
+ this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
14448
+ this._clob.feeClient = this.fee;
14449
+ }
14450
+ }
14451
+ return this._clob;
14452
+ }
14453
+ get fee() {
14454
+ if (!this._fee) {
14455
+ if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
14456
+ const program = new anchor5.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
14457
+ this._fee = new FeeManagementClient(program, this.provider, this._programIds);
14458
+ }
14459
+ return this._fee;
14460
+ }
14461
+ get presale() {
14462
+ if (!this._presale) {
14463
+ if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
14464
+ const program = new anchor5.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
14465
+ this._presale = new PresaleClient(program, this.provider, this._programIds);
14466
+ }
14467
+ return this._presale;
14468
+ }
14469
+ get marketOracle() {
14470
+ if (!this._marketOracle) {
14471
+ if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
14472
+ const program = new anchor5.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
14473
+ this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
14474
+ }
14475
+ return this._marketOracle;
14476
+ }
14477
+ get admin() {
14478
+ if (!this._admin) {
14479
+ if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
14480
+ const program = new anchor5.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
14481
+ this._admin = new AdminClient(program, this.provider, this._programIds);
14482
+ }
14483
+ return this._admin;
13034
14484
  }
13035
14485
  };
13036
14486
  function buildOrder(params) {
@@ -13041,10 +14491,10 @@ function buildOrder(params) {
13041
14491
  side: params.side,
13042
14492
  makerAmount: params.makerAmount,
13043
14493
  takerAmount: params.takerAmount,
13044
- nonce: params.nonce ?? new BN4(Date.now()),
13045
- expiry: params.expiry ?? new BN4(0),
13046
- createdAt: params.createdAt ?? new BN4(Math.floor(Date.now() / 1e3)),
13047
- fee: params.fee ?? new BN4(0),
14494
+ nonce: params.nonce ?? new BN5(Date.now()),
14495
+ expiry: params.expiry ?? new BN5(0),
14496
+ createdAt: params.createdAt ?? new BN5(Math.floor(Date.now() / 1e3)),
14497
+ fee: params.fee ?? new BN5(0),
13048
14498
  taker: params.taker ?? new PublicKey(new Uint8Array(32)),
13049
14499
  signer: params.maker
13050
14500
  };
@@ -13067,8 +14517,8 @@ function serializeSignedOrder(signed) {
13067
14517
  function deserializeSignedOrder(bytes) {
13068
14518
  if (bytes.length !== 242) throw new InvalidParamError("SignedOrder must be 242 bytes");
13069
14519
  const readPubkey = (offset) => new PublicKey(bytes.slice(offset, offset + 32));
13070
- const readU64 = (offset) => new BN4(bytes.slice(offset, offset + 8), "le");
13071
- const readI64 = (offset) => new BN4(bytes.slice(offset, offset + 8), "le");
14520
+ const readU64 = (offset) => new BN5(bytes.slice(offset, offset + 8), "le");
14521
+ const readI64 = (offset) => new BN5(bytes.slice(offset, offset + 8), "le");
13072
14522
  const order = {
13073
14523
  maker: readPubkey(0),
13074
14524
  condition: readPubkey(32),
@@ -13117,7 +14567,7 @@ function _detectMatchType(a, b) {
13117
14567
  "Orders with different tokenIds must both be BUY (MINT) or both SELL (MERGE)"
13118
14568
  );
13119
14569
  }
13120
- var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
14570
+ var MAX_APPROVE_AMOUNT = new BN5("18446744073709551615");
13121
14571
  function buildApproveCollateralTx(collateralMint, signer, payer, delegate, amount = MAX_APPROVE_AMOUNT) {
13122
14572
  const ownerAta = getAssociatedTokenAddressSync(collateralMint, signer, false, TOKEN_PROGRAM_ID);
13123
14573
  const approveIx = createApproveInstruction(
@@ -13161,6 +14611,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
13161
14611
  return tx;
13162
14612
  }
13163
14613
 
13164
- export { AccountNotFoundError, ClobClient, CtfClient, FEE_DENOMINATOR, FeeManagementClient, HookClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
14614
+ export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, FEE_DENOMINATOR, FeeManagementClient, HookClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
13165
14615
  //# sourceMappingURL=index.mjs.map
13166
14616
  //# sourceMappingURL=index.mjs.map