@theliem/xmarket-sdk 3.28.0 → 3.29.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +540 -1
- package/dist/index.d.ts +540 -1
- package/dist/index.js +9397 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +9394 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1222,6 +1222,545 @@ declare class XMarketSDK {
|
|
|
1222
1222
|
get dispute(): DisputeClient;
|
|
1223
1223
|
}
|
|
1224
1224
|
|
|
1225
|
+
declare class CtfClientV2 {
|
|
1226
|
+
private readonly program;
|
|
1227
|
+
private readonly provider;
|
|
1228
|
+
private readonly programIds;
|
|
1229
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
1230
|
+
get walletPubkey(): PublicKey;
|
|
1231
|
+
/**
|
|
1232
|
+
* Create a Condition directly (bypasses QuestionMarket).
|
|
1233
|
+
* V2: uses plain SPL TOKEN_PROGRAM_ID for YES/NO mints — no hook program.
|
|
1234
|
+
* oracle is UncheckedAccount — set it to any pubkey (e.g. user wallet)
|
|
1235
|
+
* so that wallet can later sign reportPayouts.
|
|
1236
|
+
* payer covers rent for condition + mints.
|
|
1237
|
+
*/
|
|
1238
|
+
prepareCondition(questionId: Uint8Array, oracle: PublicKey, collateralMint: PublicKey, authorizedClob: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<{
|
|
1239
|
+
signature: string;
|
|
1240
|
+
conditionPda: PublicKey;
|
|
1241
|
+
yesMint: PublicKey;
|
|
1242
|
+
noMint: PublicKey;
|
|
1243
|
+
}>;
|
|
1244
|
+
/** One-time setup. Caller becomes the CTF owner. Can only be called once. */
|
|
1245
|
+
initializeCtfConfig(): Promise<TxResult>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Create the shared collateral vault for a given collateral mint (e.g. USDC).
|
|
1248
|
+
* Only callable by the CTF owner (as stored in ctf_config).
|
|
1249
|
+
* authority defaults to the wallet — pass a different signer if needed.
|
|
1250
|
+
*/
|
|
1251
|
+
initializeVault(collateralMint: PublicKey): Promise<TxResult>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Initialize an empty Position account (balance = 0) for a user.
|
|
1254
|
+
* Needed before redeemPositions when the user only holds the opposite outcome
|
|
1255
|
+
* (e.g. buyer received YES via CLOB match but never had a NO position).
|
|
1256
|
+
*
|
|
1257
|
+
* Idempotent — call `fetchPosition` first to skip if already initialized.
|
|
1258
|
+
*/
|
|
1259
|
+
initPosition(condition: PublicKey, outcomeIndex: number, user?: PublicKey): Promise<TxResult>;
|
|
1260
|
+
/**
|
|
1261
|
+
* Split `amount` collateral into equal YES + NO tokens.
|
|
1262
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
1263
|
+
* ATAs created automatically via `init_if_needed`.
|
|
1264
|
+
*/
|
|
1265
|
+
splitPosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1266
|
+
/**
|
|
1267
|
+
* Merge `amount` YES + NO tokens back into collateral.
|
|
1268
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
1269
|
+
* Both token balances must be ≥ amount.
|
|
1270
|
+
*/
|
|
1271
|
+
mergePosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1272
|
+
/**
|
|
1273
|
+
* After condition resolves: burn outcome tokens proportional to payout
|
|
1274
|
+
* and receive USDC. Works for winning, losing, or both positions.
|
|
1275
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
1276
|
+
*/
|
|
1277
|
+
redeemPositions(condition: PublicKey, collateralMint: PublicKey, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1278
|
+
/**
|
|
1279
|
+
* Oracle directly resolves a condition with payout numerators.
|
|
1280
|
+
* Bypasses QuestionMarket — only for oracle-owned conditions.
|
|
1281
|
+
*/
|
|
1282
|
+
reportPayouts(condition: PublicKey, payoutNumerators: number[]): Promise<TxResult>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Build the `transfer_position` instruction for use in a CLOB CPI.
|
|
1285
|
+
* V2: uses TOKEN_PROGRAM_ID (plain SPL) for outcome mints.
|
|
1286
|
+
*
|
|
1287
|
+
* This instruction requires `clob_authority` (the CLOB's PDA) to sign.
|
|
1288
|
+
* A PDA can only sign from within its own program via CPI — this method
|
|
1289
|
+
* CANNOT be called directly from a wallet transaction.
|
|
1290
|
+
*/
|
|
1291
|
+
transferPositionIx(condition: PublicKey, outcomeMint: PublicKey, fromUser: PublicKey, fromTokenAccount: PublicKey, fromPosition: PublicKey, toUser: PublicKey, toTokenAccount: PublicKey, toPosition: PublicKey, payer: PublicKey, clobAuthority: PublicKey, outcomeIndex: number, amount: anchor.BN): Promise<TransactionInstruction>;
|
|
1292
|
+
/**
|
|
1293
|
+
* Update the authorized CLOB on a condition.
|
|
1294
|
+
* Only callable by the condition's oracle (the wallet that signed createQuestion).
|
|
1295
|
+
*/
|
|
1296
|
+
updateAuthorizedClob(condition: PublicKey, newAuthorizedClob: PublicKey): Promise<TxResult>;
|
|
1297
|
+
fetchCtfConfig(): Promise<CtfConfig | null>;
|
|
1298
|
+
fetchCondition(conditionPda: PublicKey): Promise<Condition | null>;
|
|
1299
|
+
fetchVault(collateralMint: PublicKey): Promise<CollateralVault | null>;
|
|
1300
|
+
fetchPosition(condition: PublicKey, outcomeIndex: number, owner?: PublicKey): Promise<Position | null>;
|
|
1301
|
+
/** YES = outcome index 1, NO = outcome index 0. */
|
|
1302
|
+
fetchBothPositions(condition: PublicKey, owner?: PublicKey): Promise<{
|
|
1303
|
+
yes: Position | null;
|
|
1304
|
+
no: Position | null;
|
|
1305
|
+
}>;
|
|
1306
|
+
/** Thin wrapper: fetch position for a single outcome token (0=NO, 1=YES). */
|
|
1307
|
+
fetchTokenBalance(condition: PublicKey, tokenId: number, owner?: PublicKey): Promise<Position | null>;
|
|
1308
|
+
yesMintPda(condition: PublicKey): PublicKey;
|
|
1309
|
+
noMintPda(condition: PublicKey): PublicKey;
|
|
1310
|
+
mintAuthorityPda(condition: PublicKey): PublicKey;
|
|
1311
|
+
collateralVaultPda(collateralMint: PublicKey): PublicKey;
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
declare class MarketClientV2 {
|
|
1315
|
+
private readonly program;
|
|
1316
|
+
private readonly provider;
|
|
1317
|
+
private readonly programIds;
|
|
1318
|
+
readonly configPda: PublicKey;
|
|
1319
|
+
/** Injected by XMarketSDKV2 after construction — enables fetchQuestionBalances. */
|
|
1320
|
+
ctfClient?: CtfClientV2;
|
|
1321
|
+
/** Injected by XMarketSDKV2 — fee config owner (= market owner) for MarketFeeOverride PDA derivation */
|
|
1322
|
+
feeConfigOwner?: PublicKey;
|
|
1323
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, ownerPubkey: PublicKey);
|
|
1324
|
+
get walletPubkey(): PublicKey;
|
|
1325
|
+
initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
1326
|
+
/**
|
|
1327
|
+
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
1328
|
+
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
1329
|
+
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
1330
|
+
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
1331
|
+
*/
|
|
1332
|
+
createQuestionAdmin(params: Omit<CreateQuestionParams, "hookProgram">, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
1333
|
+
tx: Transaction;
|
|
1334
|
+
questionPda: PublicKey;
|
|
1335
|
+
conditionPda: PublicKey;
|
|
1336
|
+
questionId: Uint8Array;
|
|
1337
|
+
}>;
|
|
1338
|
+
approveQuestion(questionPda: PublicKey, admin?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1339
|
+
updateConfig(params: {
|
|
1340
|
+
newAdmin?: PublicKey;
|
|
1341
|
+
newOracle?: PublicKey;
|
|
1342
|
+
isPaused?: boolean;
|
|
1343
|
+
newConditionalTokensProgram?: PublicKey;
|
|
1344
|
+
}, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1345
|
+
/** Set the admin (owner only). Replaces any existing admin. */
|
|
1346
|
+
addAdmin(newAdmin: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
1347
|
+
/** Clear the admin (owner only). Sets admin to default pubkey. */
|
|
1348
|
+
removeAdmin(owner?: PublicKey): Promise<Transaction>;
|
|
1349
|
+
addToWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1350
|
+
removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1351
|
+
growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1352
|
+
restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1353
|
+
bumpPresaleCount(count: number, authority: PublicKey): Promise<Transaction>;
|
|
1354
|
+
fetchConfig(): Promise<QuestionMarketConfig | null>;
|
|
1355
|
+
fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
|
|
1356
|
+
questionPda(questionId: Uint8Array): PublicKey;
|
|
1357
|
+
private _parseStatus;
|
|
1358
|
+
/**
|
|
1359
|
+
* Convenience: fetch YES and NO token balances for a question.
|
|
1360
|
+
* Returns null for each if question not approved or position not initialized.
|
|
1361
|
+
* Requires ctfClient to be injected (done automatically by XMarketSDKV2).
|
|
1362
|
+
*/
|
|
1363
|
+
fetchQuestionBalances(questionPda: PublicKey, owner: PublicKey): Promise<{
|
|
1364
|
+
yes: Position | null;
|
|
1365
|
+
no: Position | null;
|
|
1366
|
+
}>;
|
|
1367
|
+
/**
|
|
1368
|
+
* Any user creates a presale + initial buy (question-market::create_presale).
|
|
1369
|
+
* Reads agents_rev / company_rev from fee_config.
|
|
1370
|
+
*
|
|
1371
|
+
* @param feeConfig fee_management fee_config PDA (owner = feeConfigOwner)
|
|
1372
|
+
* @param currencyMint collateral token (e.g. USDC)
|
|
1373
|
+
* @param presaleIndex config.presale_count — fetch config first or pass 0 for first presale
|
|
1374
|
+
*/
|
|
1375
|
+
createPresale(params: {
|
|
1376
|
+
price: anchor.BN;
|
|
1377
|
+
startTime: anchor.BN;
|
|
1378
|
+
endTime: anchor.BN;
|
|
1379
|
+
initialBuyAmount: anchor.BN;
|
|
1380
|
+
}, feeConfig: PublicKey, currencyMint: PublicKey, presaleIndex: anchor.BN, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
1381
|
+
tx: Transaction;
|
|
1382
|
+
presalePda: PublicKey;
|
|
1383
|
+
qtMint: PublicKey;
|
|
1384
|
+
}>;
|
|
1385
|
+
/**
|
|
1386
|
+
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
1387
|
+
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
1388
|
+
*
|
|
1389
|
+
* @param presalePda the presale account
|
|
1390
|
+
* @param contentHash 32-byte hash for question content
|
|
1391
|
+
* @param authorizedClob clob program allowed to do CTF transfers
|
|
1392
|
+
* @param expirationTime Unix seconds
|
|
1393
|
+
* @param creator presale creator pubkey (stored in question)
|
|
1394
|
+
* @param currencyMint collateral mint
|
|
1395
|
+
*/
|
|
1396
|
+
approvePresale(params: {
|
|
1397
|
+
presalePda: PublicKey;
|
|
1398
|
+
contentHash: Uint8Array;
|
|
1399
|
+
authorizedClob: PublicKey;
|
|
1400
|
+
expirationTime: anchor.BN;
|
|
1401
|
+
creator: PublicKey;
|
|
1402
|
+
currencyMint: PublicKey;
|
|
1403
|
+
/** Revenue distribution — required: approvePresale now distributes 80/10/10 automatically */
|
|
1404
|
+
referralAddress: PublicKey;
|
|
1405
|
+
companyAddress: PublicKey;
|
|
1406
|
+
adminOwner: PublicKey;
|
|
1407
|
+
caller?: PublicKey;
|
|
1408
|
+
payer?: PublicKey;
|
|
1409
|
+
/** Provide an ALT to use VersionedTransaction (required: 31 accounts exceeds legacy tx limit) */
|
|
1410
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1411
|
+
}): Promise<{
|
|
1412
|
+
tx: Transaction | VersionedTransaction;
|
|
1413
|
+
questionPda: PublicKey;
|
|
1414
|
+
conditionPda: PublicKey;
|
|
1415
|
+
marketOraclePda: PublicKey;
|
|
1416
|
+
marketOracleVault: PublicKey;
|
|
1417
|
+
}>;
|
|
1418
|
+
/**
|
|
1419
|
+
* Whitelist-only: reject presale so users can refund.
|
|
1420
|
+
*/
|
|
1421
|
+
rejectPresale(presalePda: PublicKey, caller?: PublicKey): Promise<Transaction>;
|
|
1422
|
+
/**
|
|
1423
|
+
* Whitelist-only: distribute presale vault → 10% agents + 10% company + 80% botmm.
|
|
1424
|
+
* Closes presale_vault ATA and presale PDA after distribution; lamports returned to payer.
|
|
1425
|
+
*/
|
|
1426
|
+
collectPresaleRevenue(params: {
|
|
1427
|
+
presalePda: PublicKey;
|
|
1428
|
+
currencyMint: PublicKey;
|
|
1429
|
+
conditionId: Uint8Array;
|
|
1430
|
+
referralAddress: PublicKey;
|
|
1431
|
+
companyAddress: PublicKey;
|
|
1432
|
+
adminOwner: PublicKey;
|
|
1433
|
+
caller?: PublicKey;
|
|
1434
|
+
payer?: PublicKey;
|
|
1435
|
+
}): Promise<Transaction>;
|
|
1436
|
+
/**
|
|
1437
|
+
* Whitelist-only: snapshot MST supply so holders can claim trading fees.
|
|
1438
|
+
* Call after oracle resolves the question.
|
|
1439
|
+
*/
|
|
1440
|
+
collectTradingFee(marketOraclePda: PublicKey, qtMint: PublicKey, caller?: PublicKey): Promise<Transaction>;
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
/**
|
|
1444
|
+
* ClobClientV2 — V2 variant of ClobClient.
|
|
1445
|
+
* Key differences from ClobClient (v1):
|
|
1446
|
+
* - No hookClient dependency (Token-2022 hook removed)
|
|
1447
|
+
* - YES/NO token ATAs use TOKEN_PROGRAM_ID (plain SPL) instead of TOKEN_2022_PROGRAM_ID
|
|
1448
|
+
* - No hook accounts in remainingAccounts for any match instruction
|
|
1449
|
+
* - No extraAccountMetaList / hookConfig PDAs included in ALTs or remainingAccounts
|
|
1450
|
+
*/
|
|
1451
|
+
declare class ClobClientV2 {
|
|
1452
|
+
private readonly program;
|
|
1453
|
+
private readonly provider;
|
|
1454
|
+
private readonly programIds;
|
|
1455
|
+
private readonly networkConfig;
|
|
1456
|
+
/** Injected by XMarketSDKV2 after construction — enables auto fee distribution */
|
|
1457
|
+
feeClient?: FeeManagementClient;
|
|
1458
|
+
feeConfigOwner?: PublicKey;
|
|
1459
|
+
/** Injected by XMarketSDKV2 — enables auto-derive of marketOracleVault for presale markets */
|
|
1460
|
+
ctfClient?: CtfClientV2;
|
|
1461
|
+
qmConfigPda?: PublicKey;
|
|
1462
|
+
/** Cached company_address from fee_config to avoid repeated RPC calls */
|
|
1463
|
+
private _companyAddress?;
|
|
1464
|
+
/** Cached referral_vault from fee_config */
|
|
1465
|
+
private _referralVault?;
|
|
1466
|
+
/** Cache: conditionPda.toBase58() → marketOracleVault ATA */
|
|
1467
|
+
private _marketOracleVaultCache;
|
|
1468
|
+
/** ALT cache: condition.toBase58() → loaded ALT account */
|
|
1469
|
+
private _altCache;
|
|
1470
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
|
|
1471
|
+
defaultCollateral: {
|
|
1472
|
+
mint: PublicKey;
|
|
1473
|
+
};
|
|
1474
|
+
});
|
|
1475
|
+
private companyAddress;
|
|
1476
|
+
private referralVault;
|
|
1477
|
+
/**
|
|
1478
|
+
* Derive marketOracleVault ATA for a condition, cached per condition.
|
|
1479
|
+
* Works for presale markets (market_oracle initialized by approvePresale).
|
|
1480
|
+
* Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
|
|
1481
|
+
*/
|
|
1482
|
+
private getMarketOracleVault;
|
|
1483
|
+
/**
|
|
1484
|
+
* Returns a createATA ix for the oracle vault when:
|
|
1485
|
+
* - takerFee > 0
|
|
1486
|
+
* - marketFeeOverride exists for the condition
|
|
1487
|
+
* - oracle vault ATA is not yet initialized
|
|
1488
|
+
* Idempotent — safe to call every tx; returns null if vault already exists.
|
|
1489
|
+
*/
|
|
1490
|
+
private buildInitOracleVaultIfNeeded;
|
|
1491
|
+
get walletPubkey(): PublicKey;
|
|
1492
|
+
/**
|
|
1493
|
+
* Get or create an ALT for a condition.
|
|
1494
|
+
* V2: no hook accounts — TOKEN_2022_PROGRAM_ID and hook PDAs are excluded.
|
|
1495
|
+
* Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
|
|
1496
|
+
*/
|
|
1497
|
+
ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
|
|
1498
|
+
private _sendLegacyTxSig;
|
|
1499
|
+
private _sendLegacyTx;
|
|
1500
|
+
private _ensureClobOutcomeAtas;
|
|
1501
|
+
/**
|
|
1502
|
+
* Send a match transaction as versioned (v0) with optional ALT.
|
|
1503
|
+
* Both operator wallet and payer (this.provider.wallet) sign.
|
|
1504
|
+
*/
|
|
1505
|
+
sendMatchTx(instructions: TransactionInstruction[], lookupTable?: AddressLookupTableAccount, whitelistedWallet?: anchor.Wallet): Promise<string>;
|
|
1506
|
+
configPda(): PublicKey;
|
|
1507
|
+
/**
|
|
1508
|
+
* Register a signed order on-chain.
|
|
1509
|
+
* Sends Ed25519 precompile ix + register_order ix in one legacy tx.
|
|
1510
|
+
* Called at match time (engine-triggered), not at order placement.
|
|
1511
|
+
*/
|
|
1512
|
+
registerOrder(signed: SignedOrder): Promise<string>;
|
|
1513
|
+
/** Register only if the PDA doesn't exist yet (idempotent). */
|
|
1514
|
+
private registerOrderIfNeeded;
|
|
1515
|
+
/**
|
|
1516
|
+
* Build a legacy Transaction to register a CollectFeeOrder on-chain.
|
|
1517
|
+
* Must be signed and sent before calling buildBatchCollectRedeemEarlyTx.
|
|
1518
|
+
*
|
|
1519
|
+
* Flow: [Ed25519 ix (1 user sig) + register_collect_fee_order ix]
|
|
1520
|
+
* Caller signs with payer keypair and sends.
|
|
1521
|
+
*/
|
|
1522
|
+
buildRegisterCollectFeeOrderTx(signedOrder: SignedCollectFeeOrder, payer: PublicKey): Promise<Transaction>;
|
|
1523
|
+
/**
|
|
1524
|
+
* Register a CollectFeeOrder on-chain and send immediately (operator-signed flow).
|
|
1525
|
+
* Idempotent — skips if PDA already exists.
|
|
1526
|
+
*/
|
|
1527
|
+
registerCollectFeeOrderIfNeeded(signedOrder: SignedCollectFeeOrder): Promise<void>;
|
|
1528
|
+
/** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
|
|
1529
|
+
cancelOrder(nonce: anchor.BN): Promise<TxResult>;
|
|
1530
|
+
initialize(operators: PublicKey[], feeRecipient: PublicKey, feeRateBps: number): Promise<TxResult>;
|
|
1531
|
+
addOperator(operator: PublicKey): Promise<TxResult>;
|
|
1532
|
+
removeOperator(operator: PublicKey): Promise<TxResult>;
|
|
1533
|
+
setPaused(paused: boolean): Promise<TxResult>;
|
|
1534
|
+
forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
|
|
1535
|
+
/**
|
|
1536
|
+
* Build match_complementary instruction (no Ed25519 — OrderRecord PDAs used).
|
|
1537
|
+
* V2: no hook accounts in remainingAccounts.
|
|
1538
|
+
*
|
|
1539
|
+
* remaining_accounts layout:
|
|
1540
|
+
* [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
|
|
1541
|
+
* [feeManagement, fee_config, mkt_override, company_ata, oracle_vault, referral_vault] (when fee > 0)
|
|
1542
|
+
*/
|
|
1543
|
+
buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
|
|
1544
|
+
marketOracleVault?: PublicKey;
|
|
1545
|
+
fillAmount?: anchor.BN;
|
|
1546
|
+
}, useTakerPrice?: boolean, skipCrossingCheck?: boolean): Promise<TransactionInstruction[]>;
|
|
1547
|
+
/**
|
|
1548
|
+
* COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
|
|
1549
|
+
* Phase 1: register taker + all makers in parallel.
|
|
1550
|
+
* Phase 2: 1 atomic match tx.
|
|
1551
|
+
*/
|
|
1552
|
+
private matchComplementary;
|
|
1553
|
+
/**
|
|
1554
|
+
* 1 SELL taker vs N BUY makers.
|
|
1555
|
+
* Program now supports SELL-as-taker natively → 1 instruction with all BUY makers
|
|
1556
|
+
* in remaining_accounts (same structure as BUY taker case).
|
|
1557
|
+
*/
|
|
1558
|
+
private matchComplementarySellVsMultiBuy;
|
|
1559
|
+
/**
|
|
1560
|
+
* MINT: 1 YES buyer (taker) + N NO buyers (makers).
|
|
1561
|
+
* V2: no hook accounts in remainingAccounts.
|
|
1562
|
+
*
|
|
1563
|
+
* remaining_accounts per NO maker (6):
|
|
1564
|
+
* [maker, order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
|
|
1565
|
+
*/
|
|
1566
|
+
private _buildMintIx;
|
|
1567
|
+
private matchMintOrders;
|
|
1568
|
+
/**
|
|
1569
|
+
* MERGE: 1 YES seller (taker) + N NO sellers (makers).
|
|
1570
|
+
* V2: no hook accounts in remainingAccounts.
|
|
1571
|
+
*
|
|
1572
|
+
* remaining_accounts per NO maker (6):
|
|
1573
|
+
* [maker, order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
|
|
1574
|
+
* After all makers, optional 6 fee accounts.
|
|
1575
|
+
*/
|
|
1576
|
+
private _buildMergeIx;
|
|
1577
|
+
private matchMergeOrders;
|
|
1578
|
+
/**
|
|
1579
|
+
* Auto-detect match type and execute 2-phase:
|
|
1580
|
+
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
|
1581
|
+
* Phase 2 — 1 atomic match transaction.
|
|
1582
|
+
*
|
|
1583
|
+
* Detection (pure, no RPC):
|
|
1584
|
+
* taker.tokenId === makers[0].tokenId:
|
|
1585
|
+
* taker BUY + all makers SELL → COMPLEMENTARY
|
|
1586
|
+
* taker.tokenId !== makers[0].tokenId + all BUY → MINT
|
|
1587
|
+
* taker.tokenId !== makers[0].tokenId + all SELL → MERGE
|
|
1588
|
+
*
|
|
1589
|
+
* @param opts.marketOracleVault Oracle vault ATA for presale markets.
|
|
1590
|
+
* Omit for admin markets (payer used as placeholder).
|
|
1591
|
+
*/
|
|
1592
|
+
matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
|
|
1593
|
+
marketOracleVault?: PublicKey;
|
|
1594
|
+
operatorWallet?: anchor.Wallet;
|
|
1595
|
+
}): Promise<TxResult>;
|
|
1596
|
+
/**
|
|
1597
|
+
* High-level match: caller passes price + quantity + keypair — SDK builds,
|
|
1598
|
+
* signs, and submits in one call. No manual amount calculation needed.
|
|
1599
|
+
*/
|
|
1600
|
+
matchOrdersFromPrice(taker: {
|
|
1601
|
+
keypair: {
|
|
1602
|
+
publicKey: PublicKey;
|
|
1603
|
+
secretKey: Uint8Array;
|
|
1604
|
+
};
|
|
1605
|
+
condition: PublicKey;
|
|
1606
|
+
tokenId: number;
|
|
1607
|
+
side: 0 | 1;
|
|
1608
|
+
price: number;
|
|
1609
|
+
quantity: number;
|
|
1610
|
+
nonce?: BN;
|
|
1611
|
+
expiry?: BN;
|
|
1612
|
+
fee?: BN;
|
|
1613
|
+
taker?: PublicKey;
|
|
1614
|
+
}, makers: Array<{
|
|
1615
|
+
keypair: {
|
|
1616
|
+
publicKey: PublicKey;
|
|
1617
|
+
secretKey: Uint8Array;
|
|
1618
|
+
};
|
|
1619
|
+
condition: PublicKey;
|
|
1620
|
+
tokenId: number;
|
|
1621
|
+
side: 0 | 1;
|
|
1622
|
+
price: number;
|
|
1623
|
+
quantity: number;
|
|
1624
|
+
nonce?: BN;
|
|
1625
|
+
expiry?: BN;
|
|
1626
|
+
fee?: BN;
|
|
1627
|
+
taker?: PublicKey;
|
|
1628
|
+
}>, decimals?: number, opts?: {
|
|
1629
|
+
marketOracleVault?: PublicKey;
|
|
1630
|
+
operatorWallet?: anchor.Wallet;
|
|
1631
|
+
}): Promise<TxResult>;
|
|
1632
|
+
/**
|
|
1633
|
+
* Build an unsigned VersionedTransaction for a set of match instructions.
|
|
1634
|
+
*/
|
|
1635
|
+
private _buildUnsignedVtx;
|
|
1636
|
+
/**
|
|
1637
|
+
* Build unsigned VersionedTransaction(s) for matching orders.
|
|
1638
|
+
* V2: no hookClient, no hook init ixs prepended.
|
|
1639
|
+
*
|
|
1640
|
+
* @param operator - Whitelisted CLOB operator pubkey (must sign)
|
|
1641
|
+
* @param payer - Fee payer pubkey (must sign, pays tx fee + rent)
|
|
1642
|
+
*/
|
|
1643
|
+
buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
|
|
1644
|
+
marketOracleVault?: PublicKey;
|
|
1645
|
+
}): Promise<VersionedTransaction>;
|
|
1646
|
+
/**
|
|
1647
|
+
* Build VersionedTransaction for batchCollectRedeemEarly.
|
|
1648
|
+
* V2: no hook accounts in remainingAccounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
1649
|
+
*
|
|
1650
|
+
* @param signedOrders - Array of { order, signature } (used to derive record PDAs)
|
|
1651
|
+
* @param condition - Market condition PDA
|
|
1652
|
+
* @param outcomeIndex - 0 = NO wins, 1 = YES wins
|
|
1653
|
+
* @param operator - Whitelisted operator pubkey (must sign)
|
|
1654
|
+
* @param payer - Fee payer pubkey (must sign)
|
|
1655
|
+
* @param opts.marketOracleVault - MarketOracle vault for fee distribution
|
|
1656
|
+
*/
|
|
1657
|
+
buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1658
|
+
marketOracleVault?: PublicKey;
|
|
1659
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1660
|
+
}): Promise<VersionedTransaction>;
|
|
1661
|
+
/**
|
|
1662
|
+
* Build a Transaction to register a RedeemFeeOrder on-chain (Ed25519 verify + PDA).
|
|
1663
|
+
* Must be sent before calling buildBatchRedeemWithFeeTx / buildBatchMergeWithFeeTx.
|
|
1664
|
+
*/
|
|
1665
|
+
buildRegisterRedeemFeeOrderTx(signedOrder: SignedRedeemFeeOrder, payer: PublicKey): Promise<anchor.web3.Transaction>;
|
|
1666
|
+
/**
|
|
1667
|
+
* Build a VersionedTransaction for batchRedeemWithFee.
|
|
1668
|
+
* V2: no hook accounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
1669
|
+
*
|
|
1670
|
+
* Each pair has a YES order + NO order for the same user (same signer or different).
|
|
1671
|
+
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
1672
|
+
*/
|
|
1673
|
+
buildBatchRedeemWithFeeTx(orderPairs: RedeemFeeOrderPair[], condition: PublicKey, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1674
|
+
marketOracleVault?: PublicKey;
|
|
1675
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1676
|
+
}): Promise<VersionedTransaction>;
|
|
1677
|
+
/**
|
|
1678
|
+
* Build a VersionedTransaction for batchMergeWithFee (pre-resolution merge with fee).
|
|
1679
|
+
* V2: no hook accounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
1680
|
+
*
|
|
1681
|
+
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
1682
|
+
*/
|
|
1683
|
+
buildBatchMergeWithFeeTx(orderPairs: RedeemFeeOrderPair[], condition: PublicKey, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1684
|
+
marketOracleVault?: PublicKey;
|
|
1685
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1686
|
+
}): Promise<VersionedTransaction>;
|
|
1687
|
+
/**
|
|
1688
|
+
* Build ALT for batchCollectRedeemEarly — includes per-user accounts so all
|
|
1689
|
+
* remaining_accounts fit as 1-byte ALT indices instead of 32-byte inline addresses.
|
|
1690
|
+
* V2: no hook program or hook PDAs included.
|
|
1691
|
+
*/
|
|
1692
|
+
buildAltForCollectBatch(condition: PublicKey, payer: PublicKey, collateralMint: PublicKey, signedOrders: SignedCollectFeeOrder[], outcomeIndex: 0 | 1): Promise<AddressLookupTableAccount>;
|
|
1693
|
+
/**
|
|
1694
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
1695
|
+
* V2: no hook program or hook PDAs included.
|
|
1696
|
+
*/
|
|
1697
|
+
buildAltForCondition(condition: PublicKey, _payer: PublicKey, collateralMint?: PublicKey): Promise<AddressLookupTableAccount>;
|
|
1698
|
+
fetchConfig(): Promise<ClobConfig | null>;
|
|
1699
|
+
fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
|
|
1700
|
+
fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
|
|
1701
|
+
maker: PublicKey;
|
|
1702
|
+
condition: PublicKey;
|
|
1703
|
+
tokenId: number;
|
|
1704
|
+
side: number;
|
|
1705
|
+
makerAmount: anchor.BN;
|
|
1706
|
+
takerAmount: anchor.BN;
|
|
1707
|
+
nonce: anchor.BN;
|
|
1708
|
+
expiry: anchor.BN;
|
|
1709
|
+
fee: anchor.BN;
|
|
1710
|
+
taker: PublicKey;
|
|
1711
|
+
signer: PublicKey;
|
|
1712
|
+
} | null>;
|
|
1713
|
+
}
|
|
1714
|
+
|
|
1715
|
+
/**
|
|
1716
|
+
* XMarketSDKV2 — V2 variant of XMarketSDK.
|
|
1717
|
+
*
|
|
1718
|
+
* Key differences from XMarketSDK (v1):
|
|
1719
|
+
* - Uses V2 program IDs (conditionalTokens, clobExchange, questionMarket)
|
|
1720
|
+
* - CtfClientV2: plain SPL TOKEN_PROGRAM_ID for YES/NO mints, no hook
|
|
1721
|
+
* - ClobClientV2: no hookClient, no hook accounts in match instructions
|
|
1722
|
+
* - MarketClientV2: no hookProgram param in createQuestionAdmin / approvePresale
|
|
1723
|
+
* - No HookClient (sdk.hook throws a clear error)
|
|
1724
|
+
*
|
|
1725
|
+
* Usage:
|
|
1726
|
+
* const sdk = new XMarketSDKV2(DEVNET_V2_CONFIG, wallet, marketOwner);
|
|
1727
|
+
* await sdk.market.createQuestionAdmin(params, oracle); // no hookProgram
|
|
1728
|
+
* await sdk.clob.matchOrders(taker, makers); // no hook in remainingAccounts
|
|
1729
|
+
*/
|
|
1730
|
+
declare class XMarketSDKV2 {
|
|
1731
|
+
readonly provider: anchor.AnchorProvider;
|
|
1732
|
+
readonly networkConfig: NetworkConfig;
|
|
1733
|
+
private readonly _programIds;
|
|
1734
|
+
private readonly _marketOwner;
|
|
1735
|
+
private _oracle?;
|
|
1736
|
+
private _market?;
|
|
1737
|
+
private _ctf?;
|
|
1738
|
+
private _clob?;
|
|
1739
|
+
private _fee?;
|
|
1740
|
+
private _presale?;
|
|
1741
|
+
private _marketOracle?;
|
|
1742
|
+
private _admin?;
|
|
1743
|
+
private _referral?;
|
|
1744
|
+
private _dispute?;
|
|
1745
|
+
constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
|
|
1746
|
+
private _withAddress;
|
|
1747
|
+
get oracle(): OracleClient;
|
|
1748
|
+
/**
|
|
1749
|
+
* V2 does not use a hook program — calling this getter throws an error.
|
|
1750
|
+
* The hook is not needed for plain SPL YES/NO mints.
|
|
1751
|
+
*/
|
|
1752
|
+
get hook(): never;
|
|
1753
|
+
get market(): MarketClientV2;
|
|
1754
|
+
get ctf(): CtfClientV2;
|
|
1755
|
+
get clob(): ClobClientV2;
|
|
1756
|
+
get fee(): FeeManagementClient;
|
|
1757
|
+
get presale(): PresaleClient;
|
|
1758
|
+
get marketOracle(): MarketOracleClient;
|
|
1759
|
+
get admin(): AdminClient;
|
|
1760
|
+
get referral(): ReferralClient;
|
|
1761
|
+
get dispute(): DisputeClient;
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1225
1764
|
declare const SEEDS: {
|
|
1226
1765
|
readonly config: Buffer<ArrayBuffer>;
|
|
1227
1766
|
readonly question: Buffer<ArrayBuffer>;
|
|
@@ -1516,4 +2055,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
|
|
|
1516
2055
|
*/
|
|
1517
2056
|
declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
|
|
1518
2057
|
|
|
1519
|
-
export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, type FeesShareEstimate, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|
|
2058
|
+
export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, ClobClientV2, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, CtfClientV2, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, type FeesShareEstimate, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketClientV2, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, XMarketSDKV2, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|