@theliem/xmarket-sdk 3.27.0 → 3.29.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.d.mts +748 -235
- package/dist/index.d.ts +748 -235
- package/dist/index.js +3146 -1583
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3142 -1583
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import * as anchor from '@coral-xyz/anchor';
|
|
2
2
|
import * as _solana_web3_js from '@solana/web3.js';
|
|
3
|
-
import { PublicKey, Transaction,
|
|
3
|
+
import { PublicKey, Transaction, Keypair, TransactionInstruction, AddressLookupTableAccount, VersionedTransaction } from '@solana/web3.js';
|
|
4
4
|
import BN from 'bn.js';
|
|
5
5
|
|
|
6
6
|
interface ProgramIds {
|
|
7
7
|
oracle: PublicKey;
|
|
8
8
|
conditionalTokens: PublicKey;
|
|
9
9
|
questionMarket: PublicKey;
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Transfer-hook program (Token-2022).
|
|
12
|
+
* Optional in V2 — V2 programs use plain SPL token (TOKEN_PROGRAM_ID), no transfer hook.
|
|
13
|
+
*/
|
|
14
|
+
hook?: PublicKey;
|
|
11
15
|
clobExchange: PublicKey;
|
|
12
16
|
feeManagement?: PublicKey;
|
|
13
17
|
presale?: PublicKey;
|
|
@@ -297,53 +301,7 @@ declare class OracleClient {
|
|
|
297
301
|
fetchQuestionResult(questionId: Uint8Array, ownerPubkey?: PublicKey): Promise<QuestionResult | null>;
|
|
298
302
|
}
|
|
299
303
|
|
|
300
|
-
declare class
|
|
301
|
-
private readonly program;
|
|
302
|
-
private readonly provider;
|
|
303
|
-
private readonly programIds;
|
|
304
|
-
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
305
|
-
get walletPubkey(): PublicKey;
|
|
306
|
-
configPda(): PublicKey;
|
|
307
|
-
/** One-time setup. Caller becomes owner. */
|
|
308
|
-
initialize(initialWhitelist: PublicKey[]): Promise<TxResult>;
|
|
309
|
-
/**
|
|
310
|
-
* Returns initializeExtraAccountMetaList instruction if the account doesn't exist yet, else null.
|
|
311
|
-
* Used by ClobClient to auto-prepend when extraAccountMetaList is missing.
|
|
312
|
-
*/
|
|
313
|
-
buildInitHookIxIfNeeded(mint: PublicKey, payer: PublicKey): Promise<TransactionInstruction | null>;
|
|
314
|
-
/**
|
|
315
|
-
* Register extra account metas for a Token-2022 YES/NO mint.
|
|
316
|
-
* Must be called once per mint after CTF creates it.
|
|
317
|
-
*/
|
|
318
|
-
initializeExtraAccountMetaList(mint: PublicKey): Promise<TxResult>;
|
|
319
|
-
/** Owner adds a program to the transfer whitelist. */
|
|
320
|
-
addToWhitelist(program: PublicKey): Promise<TxResult>;
|
|
321
|
-
/** Owner removes a program from the transfer whitelist. */
|
|
322
|
-
removeFromWhitelist(program: PublicKey): Promise<TxResult>;
|
|
323
|
-
/** Permanently freeze the whitelist — no further changes allowed. */
|
|
324
|
-
freezeWhitelist(): Promise<TxResult>;
|
|
325
|
-
/**
|
|
326
|
-
* SPL Transfer-Hook `execute` — invoked automatically by Token-2022 on every
|
|
327
|
-
* YES/NO token transfer. Validates the destination against the whitelist.
|
|
328
|
-
*
|
|
329
|
-
* Calling this directly is useful for:
|
|
330
|
-
* - Off-chain simulation ("would this transfer be allowed?")
|
|
331
|
-
* - Integration tests that verify whitelist enforcement
|
|
332
|
-
*
|
|
333
|
-
* Token-2022 calls this automatically; you normally don't call it manually.
|
|
334
|
-
*
|
|
335
|
-
* @param sourceToken - Source token account (tokens leaving)
|
|
336
|
-
* @param mint - The YES/NO Token-2022 mint
|
|
337
|
-
* @param destinationToken - Destination token account (tokens arriving)
|
|
338
|
-
* @param owner - Authority that authorized the transfer
|
|
339
|
-
* @param amount - Token amount being transferred
|
|
340
|
-
*/
|
|
341
|
-
execute(sourceToken: PublicKey, mint: PublicKey, destinationToken: PublicKey, owner: PublicKey, amount: anchor.BN): Promise<TxResult>;
|
|
342
|
-
fetchConfig(): Promise<HookConfig | null>;
|
|
343
|
-
isWhitelisted(program: PublicKey): Promise<boolean>;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
declare class CtfClient {
|
|
304
|
+
declare class CtfClientV2 {
|
|
347
305
|
private readonly program;
|
|
348
306
|
private readonly provider;
|
|
349
307
|
private readonly programIds;
|
|
@@ -351,11 +309,12 @@ declare class CtfClient {
|
|
|
351
309
|
get walletPubkey(): PublicKey;
|
|
352
310
|
/**
|
|
353
311
|
* Create a Condition directly (bypasses QuestionMarket).
|
|
312
|
+
* V2: uses plain SPL TOKEN_PROGRAM_ID for YES/NO mints — no hook program.
|
|
354
313
|
* oracle is UncheckedAccount — set it to any pubkey (e.g. user wallet)
|
|
355
314
|
* so that wallet can later sign reportPayouts.
|
|
356
315
|
* payer covers rent for condition + mints.
|
|
357
316
|
*/
|
|
358
|
-
prepareCondition(questionId: Uint8Array, oracle: PublicKey, collateralMint: PublicKey,
|
|
317
|
+
prepareCondition(questionId: Uint8Array, oracle: PublicKey, collateralMint: PublicKey, authorizedClob: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<{
|
|
359
318
|
signature: string;
|
|
360
319
|
conditionPda: PublicKey;
|
|
361
320
|
yesMint: PublicKey;
|
|
@@ -379,17 +338,20 @@ declare class CtfClient {
|
|
|
379
338
|
initPosition(condition: PublicKey, outcomeIndex: number, user?: PublicKey): Promise<TxResult>;
|
|
380
339
|
/**
|
|
381
340
|
* Split `amount` collateral into equal YES + NO tokens.
|
|
341
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
382
342
|
* ATAs created automatically via `init_if_needed`.
|
|
383
343
|
*/
|
|
384
344
|
splitPosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
385
345
|
/**
|
|
386
346
|
* Merge `amount` YES + NO tokens back into collateral.
|
|
347
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
387
348
|
* Both token balances must be ≥ amount.
|
|
388
349
|
*/
|
|
389
350
|
mergePosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
390
351
|
/**
|
|
391
352
|
* After condition resolves: burn outcome tokens proportional to payout
|
|
392
353
|
* and receive USDC. Works for winning, losing, or both positions.
|
|
354
|
+
* V2: uses TOKEN_PROGRAM_ID for YES/NO mints (plain SPL, no Token-2022).
|
|
393
355
|
*/
|
|
394
356
|
redeemPositions(condition: PublicKey, collateralMint: PublicKey, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
395
357
|
/**
|
|
@@ -399,27 +361,11 @@ declare class CtfClient {
|
|
|
399
361
|
reportPayouts(condition: PublicKey, payoutNumerators: number[]): Promise<TxResult>;
|
|
400
362
|
/**
|
|
401
363
|
* Build the `transfer_position` instruction for use in a CLOB CPI.
|
|
364
|
+
* V2: uses TOKEN_PROGRAM_ID (plain SPL) for outcome mints.
|
|
402
365
|
*
|
|
403
366
|
* This instruction requires `clob_authority` (the CLOB's PDA) to sign.
|
|
404
367
|
* A PDA can only sign from within its own program via CPI — this method
|
|
405
368
|
* CANNOT be called directly from a wallet transaction.
|
|
406
|
-
*
|
|
407
|
-
* Use-cases:
|
|
408
|
-
* - Custom CLOB implementations that call CTF.transfer_position via CPI
|
|
409
|
-
* - Anchor CPI builders in other Rust programs
|
|
410
|
-
*
|
|
411
|
-
* @param condition - Condition PDA
|
|
412
|
-
* @param outcomeMint - YES or NO mint
|
|
413
|
-
* @param fromUser - Source wallet
|
|
414
|
-
* @param fromTokenAccount - Source ATA
|
|
415
|
-
* @param fromPosition - Source Position PDA
|
|
416
|
-
* @param toUser - Destination wallet
|
|
417
|
-
* @param toTokenAccount - Destination ATA (created if needed — payer covers rent)
|
|
418
|
-
* @param toPosition - Destination Position PDA
|
|
419
|
-
* @param payer - Pays rent for toPosition + toTokenAccount creation
|
|
420
|
-
* @param clobAuthority - CLOB config PDA (must sign via CPI)
|
|
421
|
-
* @param outcomeIndex - 0 = NO, 1 = YES
|
|
422
|
-
* @param amount - Token amount to transfer
|
|
423
369
|
*/
|
|
424
370
|
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>;
|
|
425
371
|
/**
|
|
@@ -444,24 +390,25 @@ declare class CtfClient {
|
|
|
444
390
|
collateralVaultPda(collateralMint: PublicKey): PublicKey;
|
|
445
391
|
}
|
|
446
392
|
|
|
447
|
-
declare class
|
|
393
|
+
declare class MarketClientV2 {
|
|
448
394
|
private readonly program;
|
|
449
395
|
private readonly provider;
|
|
450
396
|
private readonly programIds;
|
|
451
397
|
readonly configPda: PublicKey;
|
|
452
|
-
/** Injected by
|
|
453
|
-
ctfClient?:
|
|
454
|
-
/** Injected by
|
|
398
|
+
/** Injected by XMarketSDKV2 after construction — enables fetchQuestionBalances. */
|
|
399
|
+
ctfClient?: CtfClientV2;
|
|
400
|
+
/** Injected by XMarketSDKV2 — fee config owner (= market owner) for MarketFeeOverride PDA derivation */
|
|
455
401
|
feeConfigOwner?: PublicKey;
|
|
456
402
|
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, ownerPubkey: PublicKey);
|
|
457
403
|
get walletPubkey(): PublicKey;
|
|
458
404
|
initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
459
405
|
/**
|
|
460
406
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
407
|
+
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
461
408
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
462
409
|
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
463
410
|
*/
|
|
464
|
-
createQuestionAdmin(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
411
|
+
createQuestionAdmin(params: Omit<CreateQuestionParams, "hookProgram">, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
465
412
|
tx: Transaction;
|
|
466
413
|
questionPda: PublicKey;
|
|
467
414
|
conditionPda: PublicKey;
|
|
@@ -490,7 +437,7 @@ declare class MarketClient {
|
|
|
490
437
|
/**
|
|
491
438
|
* Convenience: fetch YES and NO token balances for a question.
|
|
492
439
|
* Returns null for each if question not approved or position not initialized.
|
|
493
|
-
* Requires ctfClient to be injected (done automatically by
|
|
440
|
+
* Requires ctfClient to be injected (done automatically by XMarketSDKV2).
|
|
494
441
|
*/
|
|
495
442
|
fetchQuestionBalances(questionPda: PublicKey, owner: PublicKey): Promise<{
|
|
496
443
|
yes: Position | null;
|
|
@@ -516,10 +463,10 @@ declare class MarketClient {
|
|
|
516
463
|
}>;
|
|
517
464
|
/**
|
|
518
465
|
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
466
|
+
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
519
467
|
*
|
|
520
468
|
* @param presalePda the presale account
|
|
521
469
|
* @param contentHash 32-byte hash for question content
|
|
522
|
-
* @param hookProgram token-2022 transfer hook program
|
|
523
470
|
* @param authorizedClob clob program allowed to do CTF transfers
|
|
524
471
|
* @param expirationTime Unix seconds
|
|
525
472
|
* @param creator presale creator pubkey (stored in question)
|
|
@@ -528,7 +475,6 @@ declare class MarketClient {
|
|
|
528
475
|
approvePresale(params: {
|
|
529
476
|
presalePda: PublicKey;
|
|
530
477
|
contentHash: Uint8Array;
|
|
531
|
-
hookProgram: PublicKey;
|
|
532
478
|
authorizedClob: PublicKey;
|
|
533
479
|
expirationTime: anchor.BN;
|
|
534
480
|
creator: PublicKey;
|
|
@@ -651,19 +597,25 @@ declare class FeeManagementClient {
|
|
|
651
597
|
buildSetAdminTx(newAdmin: PublicKey, feeConfigOwner: PublicKey, authority: PublicKey): Promise<Transaction>;
|
|
652
598
|
}
|
|
653
599
|
|
|
654
|
-
|
|
600
|
+
/**
|
|
601
|
+
* ClobClientV2 — V2 variant of ClobClient.
|
|
602
|
+
* Key differences from ClobClient (v1):
|
|
603
|
+
* - No hookClient dependency (Token-2022 hook removed)
|
|
604
|
+
* - YES/NO token ATAs use TOKEN_PROGRAM_ID (plain SPL) instead of TOKEN_2022_PROGRAM_ID
|
|
605
|
+
* - No hook accounts in remainingAccounts for any match instruction
|
|
606
|
+
* - No extraAccountMetaList / hookConfig PDAs included in ALTs or remainingAccounts
|
|
607
|
+
*/
|
|
608
|
+
declare class ClobClientV2 {
|
|
655
609
|
private readonly program;
|
|
656
610
|
private readonly provider;
|
|
657
611
|
private readonly programIds;
|
|
658
612
|
private readonly networkConfig;
|
|
659
|
-
/** Injected by
|
|
613
|
+
/** Injected by XMarketSDKV2 after construction — enables auto fee distribution */
|
|
660
614
|
feeClient?: FeeManagementClient;
|
|
661
615
|
feeConfigOwner?: PublicKey;
|
|
662
|
-
/** Injected by
|
|
663
|
-
ctfClient?:
|
|
616
|
+
/** Injected by XMarketSDKV2 — enables auto-derive of marketOracleVault for presale markets */
|
|
617
|
+
ctfClient?: CtfClientV2;
|
|
664
618
|
qmConfigPda?: PublicKey;
|
|
665
|
-
/** Injected by XMarketSDK — enables auto-init extraAccountMetaList if missing */
|
|
666
|
-
hookClient?: HookClient;
|
|
667
619
|
/** Cached company_address from fee_config to avoid repeated RPC calls */
|
|
668
620
|
private _companyAddress?;
|
|
669
621
|
/** Cached referral_vault from fee_config */
|
|
@@ -696,6 +648,7 @@ declare class ClobClient {
|
|
|
696
648
|
get walletPubkey(): PublicKey;
|
|
697
649
|
/**
|
|
698
650
|
* Get or create an ALT for a condition.
|
|
651
|
+
* V2: no hook accounts — TOKEN_2022_PROGRAM_ID and hook PDAs are excluded.
|
|
699
652
|
* Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
|
|
700
653
|
*/
|
|
701
654
|
ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
|
|
@@ -738,11 +691,11 @@ declare class ClobClient {
|
|
|
738
691
|
forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
|
|
739
692
|
/**
|
|
740
693
|
* Build match_complementary instruction (no Ed25519 — OrderRecord PDAs used).
|
|
694
|
+
* V2: no hook accounts in remainingAccounts.
|
|
741
695
|
*
|
|
742
696
|
* remaining_accounts layout:
|
|
743
697
|
* [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
|
|
744
|
-
* [
|
|
745
|
-
* [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
|
|
698
|
+
* [feeManagement, fee_config, mkt_override, company_ata, oracle_vault, referral_vault] (when fee > 0)
|
|
746
699
|
*/
|
|
747
700
|
buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
|
|
748
701
|
marketOracleVault?: PublicKey;
|
|
@@ -762,25 +715,21 @@ declare class ClobClient {
|
|
|
762
715
|
private matchComplementarySellVsMultiBuy;
|
|
763
716
|
/**
|
|
764
717
|
* MINT: 1 YES buyer (taker) + N NO buyers (makers).
|
|
765
|
-
*
|
|
766
|
-
* Phase 2: 1 atomic match tx.
|
|
718
|
+
* V2: no hook accounts in remainingAccounts.
|
|
767
719
|
*
|
|
768
|
-
* remaining_accounts per NO maker (
|
|
769
|
-
* [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
|
|
720
|
+
* remaining_accounts per NO maker (6):
|
|
721
|
+
* [maker, order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
|
|
770
722
|
*/
|
|
771
|
-
/** Build the match_mint_orders instruction (no signing, no sending). */
|
|
772
723
|
private _buildMintIx;
|
|
773
724
|
private matchMintOrders;
|
|
774
725
|
/**
|
|
775
726
|
* MERGE: 1 YES seller (taker) + N NO sellers (makers).
|
|
776
|
-
*
|
|
777
|
-
* Phase 2: 1 atomic match tx.
|
|
727
|
+
* V2: no hook accounts in remainingAccounts.
|
|
778
728
|
*
|
|
779
|
-
* remaining_accounts per NO maker (
|
|
780
|
-
* [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
|
|
781
|
-
* After all makers, optional
|
|
729
|
+
* remaining_accounts per NO maker (6):
|
|
730
|
+
* [maker, order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
|
|
731
|
+
* After all makers, optional 6 fee accounts.
|
|
782
732
|
*/
|
|
783
|
-
/** Build the match_merge_orders instruction (no signing, no sending). */
|
|
784
733
|
private _buildMergeIx;
|
|
785
734
|
private matchMergeOrders;
|
|
786
735
|
/**
|
|
@@ -804,13 +753,6 @@ declare class ClobClient {
|
|
|
804
753
|
/**
|
|
805
754
|
* High-level match: caller passes price + quantity + keypair — SDK builds,
|
|
806
755
|
* signs, and submits in one call. No manual amount calculation needed.
|
|
807
|
-
*
|
|
808
|
-
* Amounts are computed from each order's own limit `price` (percentage, e.g. 51 for 51%).
|
|
809
|
-
* NEVER pass averageMatchedPrice — that is an engine output, not an order input.
|
|
810
|
-
*
|
|
811
|
-
* @param taker { keypair, condition, tokenId, side, price, quantity, nonce?, expiry? }
|
|
812
|
-
* @param makers Array of same shape
|
|
813
|
-
* @param decimals Collateral decimals (default 9 for USDS)
|
|
814
756
|
*/
|
|
815
757
|
matchOrdersFromPrice(taker: {
|
|
816
758
|
keypair: {
|
|
@@ -846,21 +788,11 @@ declare class ClobClient {
|
|
|
846
788
|
}): Promise<TxResult>;
|
|
847
789
|
/**
|
|
848
790
|
* Build an unsigned VersionedTransaction for a set of match instructions.
|
|
849
|
-
* Callers sign and send externally — mirrors createQuestionAdmin pattern.
|
|
850
791
|
*/
|
|
851
792
|
private _buildUnsignedVtx;
|
|
852
793
|
/**
|
|
853
794
|
* Build unsigned VersionedTransaction(s) for matching orders.
|
|
854
|
-
*
|
|
855
|
-
* Mirrors createQuestionAdmin pattern — SDK registers orders internally but
|
|
856
|
-
* returns the match tx unsigned. BE signs with both keypairs and sends:
|
|
857
|
-
*
|
|
858
|
-
* const [vtx] = await sdk.clob.buildMatchOrdersTx(taker, makers, operatorPk, payerPk);
|
|
859
|
-
* vtx.sign([feePayerKeypair, operatorKeypair]);
|
|
860
|
-
* await connection.sendRawTransaction(vtx.serialize());
|
|
861
|
-
*
|
|
862
|
-
* All match types pack into a single VersionedTransaction — same as createQuestionAdmin pattern.
|
|
863
|
-
* NO-taker MINT/MERGE decomposes into N instructions but all packed in 1 tx.
|
|
795
|
+
* V2: no hookClient, no hook init ixs prepended.
|
|
864
796
|
*
|
|
865
797
|
* @param operator - Whitelisted CLOB operator pubkey (must sign)
|
|
866
798
|
* @param payer - Fee payer pubkey (must sign, pays tx fee + rent)
|
|
@@ -870,12 +802,7 @@ declare class ClobClient {
|
|
|
870
802
|
}): Promise<VersionedTransaction>;
|
|
871
803
|
/**
|
|
872
804
|
* Build VersionedTransaction for batchCollectRedeemEarly.
|
|
873
|
-
*
|
|
874
|
-
* Prerequisite: each user's CollectFeeOrder must be registered on-chain via
|
|
875
|
-
* buildRegisterCollectFeeOrderTx (one tx per user).
|
|
876
|
-
*
|
|
877
|
-
* Flow: batchCollectRedeemEarly ix reads CollectFeeOrderRecord PDAs — no Ed25519 inline.
|
|
878
|
-
* No tx-size limit from signatures, supports 10+ orders in one tx.
|
|
805
|
+
* V2: no hook accounts in remainingAccounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
879
806
|
*
|
|
880
807
|
* @param signedOrders - Array of { order, signature } (used to derive record PDAs)
|
|
881
808
|
* @param condition - Market condition PDA
|
|
@@ -891,16 +818,13 @@ declare class ClobClient {
|
|
|
891
818
|
/**
|
|
892
819
|
* Build a Transaction to register a RedeemFeeOrder on-chain (Ed25519 verify + PDA).
|
|
893
820
|
* Must be sent before calling buildBatchRedeemWithFeeTx / buildBatchMergeWithFeeTx.
|
|
894
|
-
*
|
|
895
|
-
* ix[0]: batched Ed25519 { pubkey=order.user, sig, msg=128 bytes }
|
|
896
|
-
* ix[1]: register_redeem_fee_order(nonce)
|
|
897
821
|
*/
|
|
898
822
|
buildRegisterRedeemFeeOrderTx(signedOrder: SignedRedeemFeeOrder, payer: PublicKey): Promise<anchor.web3.Transaction>;
|
|
899
823
|
/**
|
|
900
824
|
* Build a VersionedTransaction for batchRedeemWithFee.
|
|
901
|
-
*
|
|
902
|
-
* After resolution: YES holder taker_amount > 0, NO holder taker_amount = 0 (or vice versa).
|
|
825
|
+
* V2: no hook accounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
903
826
|
*
|
|
827
|
+
* Each pair has a YES order + NO order for the same user (same signer or different).
|
|
904
828
|
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
905
829
|
*/
|
|
906
830
|
buildBatchRedeemWithFeeTx(orderPairs: RedeemFeeOrderPair[], condition: PublicKey, operator: PublicKey, payer: PublicKey, opts?: {
|
|
@@ -909,8 +833,7 @@ declare class ClobClient {
|
|
|
909
833
|
}): Promise<VersionedTransaction>;
|
|
910
834
|
/**
|
|
911
835
|
* Build a VersionedTransaction for batchMergeWithFee (pre-resolution merge with fee).
|
|
912
|
-
*
|
|
913
|
-
* Only yes_signer receives net USDS (mirrors EVM _matchMergeOrder).
|
|
836
|
+
* V2: no hook accounts, uses TOKEN_PROGRAM_ID for outcome mints.
|
|
914
837
|
*
|
|
915
838
|
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
916
839
|
*/
|
|
@@ -921,11 +844,12 @@ declare class ClobClient {
|
|
|
921
844
|
/**
|
|
922
845
|
* Build ALT for batchCollectRedeemEarly — includes per-user accounts so all
|
|
923
846
|
* remaining_accounts fit as 1-byte ALT indices instead of 32-byte inline addresses.
|
|
847
|
+
* V2: no hook program or hook PDAs included.
|
|
924
848
|
*/
|
|
925
849
|
buildAltForCollectBatch(condition: PublicKey, payer: PublicKey, collateralMint: PublicKey, signedOrders: SignedCollectFeeOrder[], outcomeIndex: 0 | 1): Promise<AddressLookupTableAccount>;
|
|
926
850
|
/**
|
|
927
851
|
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
928
|
-
*
|
|
852
|
+
* V2: no hook program or hook PDAs included.
|
|
929
853
|
*/
|
|
930
854
|
buildAltForCondition(condition: PublicKey, _payer: PublicKey, collateralMint?: PublicKey): Promise<AddressLookupTableAccount>;
|
|
931
855
|
fetchConfig(): Promise<ClobConfig | null>;
|
|
@@ -1015,6 +939,22 @@ interface UserClaimRecord {
|
|
|
1015
939
|
hasClaimed: boolean;
|
|
1016
940
|
bump: number;
|
|
1017
941
|
}
|
|
942
|
+
interface FeesShareEstimate {
|
|
943
|
+
/** Net USDS user will receive if they claim now */
|
|
944
|
+
share: anchor.BN;
|
|
945
|
+
/** Total accumulated fees (vault + already claimed) */
|
|
946
|
+
effectiveTotal: anchor.BN;
|
|
947
|
+
/** Current vault balance */
|
|
948
|
+
vaultBalance: anchor.BN;
|
|
949
|
+
/** User's current MST balance */
|
|
950
|
+
userQtBalance: anchor.BN;
|
|
951
|
+
/** Snapshotted total MST supply (0 if not yet distributed) */
|
|
952
|
+
qtTotalSupply: anchor.BN;
|
|
953
|
+
/** True if fees_distributed — claim is on-chain executable */
|
|
954
|
+
feesDistributed: boolean;
|
|
955
|
+
/** True if user already claimed */
|
|
956
|
+
hasClaimed: boolean;
|
|
957
|
+
}
|
|
1018
958
|
declare class MarketOracleClient {
|
|
1019
959
|
private readonly program;
|
|
1020
960
|
private readonly provider;
|
|
@@ -1034,6 +974,19 @@ declare class MarketOracleClient {
|
|
|
1034
974
|
* presaleAddress is used as the questionId seed in the question PDA.
|
|
1035
975
|
*/
|
|
1036
976
|
getOracleVaultBalance(presaleAddress: PublicKey, qmConfigPda: PublicKey, collateralMint: PublicKey): Promise<number>;
|
|
977
|
+
/**
|
|
978
|
+
* Estimate the USDS share a user would receive if they called claimFeesShare now.
|
|
979
|
+
* Works both before and after fees_distributed — no extra params needed.
|
|
980
|
+
*
|
|
981
|
+
* When fees not yet distributed, auto-resolves qtMint via:
|
|
982
|
+
* oracle.question (questionPda) → raw account bytes[8..40] = presalePda
|
|
983
|
+
* → PDA.qtMint(presalePda) → qtMint
|
|
984
|
+
*
|
|
985
|
+
* Formula mirrors on-chain claim_fees_share_handler:
|
|
986
|
+
* effective_total = vault_balance + oracle.total_claimed
|
|
987
|
+
* share = user_qt_balance * effective_total / oracle.qt_total_supply
|
|
988
|
+
*/
|
|
989
|
+
estimateFeesShare(marketOraclePda: PublicKey, user: PublicKey): Promise<FeesShareEstimate | null>;
|
|
1037
990
|
fetchUserClaimRecord(marketOraclePda: PublicKey, user: PublicKey): Promise<UserClaimRecord | null>;
|
|
1038
991
|
}
|
|
1039
992
|
|
|
@@ -1162,13 +1115,27 @@ declare class DisputeClient {
|
|
|
1162
1115
|
buildResolveDisputeTx(conditionId: Uint8Array, amount: anchor.BN, isRefunded: boolean, owner: PublicKey, admin?: PublicKey): Promise<Transaction>;
|
|
1163
1116
|
}
|
|
1164
1117
|
|
|
1165
|
-
|
|
1118
|
+
/**
|
|
1119
|
+
* XMarketSDKV2 — V2 variant of XMarketSDK.
|
|
1120
|
+
*
|
|
1121
|
+
* Key differences from XMarketSDK (v1):
|
|
1122
|
+
* - Uses V2 program IDs (conditionalTokens, clobExchange, questionMarket)
|
|
1123
|
+
* - CtfClientV2: plain SPL TOKEN_PROGRAM_ID for YES/NO mints, no hook
|
|
1124
|
+
* - ClobClientV2: no hookClient, no hook accounts in match instructions
|
|
1125
|
+
* - MarketClientV2: no hookProgram param in createQuestionAdmin / approvePresale
|
|
1126
|
+
* - No HookClient (sdk.hook throws a clear error)
|
|
1127
|
+
*
|
|
1128
|
+
* Usage:
|
|
1129
|
+
* const sdk = new XMarketSDKV2(DEVNET_V2_CONFIG, wallet, marketOwner);
|
|
1130
|
+
* await sdk.market.createQuestionAdmin(params, oracle); // no hookProgram
|
|
1131
|
+
* await sdk.clob.matchOrders(taker, makers); // no hook in remainingAccounts
|
|
1132
|
+
*/
|
|
1133
|
+
declare class XMarketSDKV2 {
|
|
1166
1134
|
readonly provider: anchor.AnchorProvider;
|
|
1167
1135
|
readonly networkConfig: NetworkConfig;
|
|
1168
1136
|
private readonly _programIds;
|
|
1169
1137
|
private readonly _marketOwner;
|
|
1170
1138
|
private _oracle?;
|
|
1171
|
-
private _hook?;
|
|
1172
1139
|
private _market?;
|
|
1173
1140
|
private _ctf?;
|
|
1174
1141
|
private _clob?;
|
|
@@ -1181,10 +1148,14 @@ declare class XMarketSDK {
|
|
|
1181
1148
|
constructor(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey);
|
|
1182
1149
|
private _withAddress;
|
|
1183
1150
|
get oracle(): OracleClient;
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1151
|
+
/**
|
|
1152
|
+
* V2 does not use a hook program — calling this getter throws an error.
|
|
1153
|
+
* The hook is not needed for plain SPL YES/NO mints.
|
|
1154
|
+
*/
|
|
1155
|
+
get hook(): never;
|
|
1156
|
+
get market(): MarketClientV2;
|
|
1157
|
+
get ctf(): CtfClientV2;
|
|
1158
|
+
get clob(): ClobClientV2;
|
|
1188
1159
|
get fee(): FeeManagementClient;
|
|
1189
1160
|
get presale(): PresaleClient;
|
|
1190
1161
|
get marketOracle(): MarketOracleClient;
|
|
@@ -1193,75 +1164,645 @@ declare class XMarketSDK {
|
|
|
1193
1164
|
get dispute(): DisputeClient;
|
|
1194
1165
|
}
|
|
1195
1166
|
|
|
1196
|
-
declare
|
|
1197
|
-
readonly
|
|
1198
|
-
readonly
|
|
1199
|
-
readonly
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1251
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1167
|
+
declare class HookClient {
|
|
1168
|
+
private readonly program;
|
|
1169
|
+
private readonly provider;
|
|
1170
|
+
private readonly programIds;
|
|
1171
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
1172
|
+
get walletPubkey(): PublicKey;
|
|
1173
|
+
configPda(): PublicKey;
|
|
1174
|
+
/** One-time setup. Caller becomes owner. */
|
|
1175
|
+
initialize(initialWhitelist: PublicKey[]): Promise<TxResult>;
|
|
1176
|
+
/**
|
|
1177
|
+
* Returns initializeExtraAccountMetaList instruction if the account doesn't exist yet, else null.
|
|
1178
|
+
* Used by ClobClient to auto-prepend when extraAccountMetaList is missing.
|
|
1179
|
+
*/
|
|
1180
|
+
buildInitHookIxIfNeeded(mint: PublicKey, payer: PublicKey): Promise<TransactionInstruction | null>;
|
|
1181
|
+
/**
|
|
1182
|
+
* Register extra account metas for a Token-2022 YES/NO mint.
|
|
1183
|
+
* Must be called once per mint after CTF creates it.
|
|
1184
|
+
*/
|
|
1185
|
+
initializeExtraAccountMetaList(mint: PublicKey): Promise<TxResult>;
|
|
1186
|
+
/** Owner adds a program to the transfer whitelist. */
|
|
1187
|
+
addToWhitelist(program: PublicKey): Promise<TxResult>;
|
|
1188
|
+
/** Owner removes a program from the transfer whitelist. */
|
|
1189
|
+
removeFromWhitelist(program: PublicKey): Promise<TxResult>;
|
|
1190
|
+
/** Permanently freeze the whitelist — no further changes allowed. */
|
|
1191
|
+
freezeWhitelist(): Promise<TxResult>;
|
|
1192
|
+
/**
|
|
1193
|
+
* SPL Transfer-Hook `execute` — invoked automatically by Token-2022 on every
|
|
1194
|
+
* YES/NO token transfer. Validates the destination against the whitelist.
|
|
1195
|
+
*
|
|
1196
|
+
* Calling this directly is useful for:
|
|
1197
|
+
* - Off-chain simulation ("would this transfer be allowed?")
|
|
1198
|
+
* - Integration tests that verify whitelist enforcement
|
|
1199
|
+
*
|
|
1200
|
+
* Token-2022 calls this automatically; you normally don't call it manually.
|
|
1201
|
+
*
|
|
1202
|
+
* @param sourceToken - Source token account (tokens leaving)
|
|
1203
|
+
* @param mint - The YES/NO Token-2022 mint
|
|
1204
|
+
* @param destinationToken - Destination token account (tokens arriving)
|
|
1205
|
+
* @param owner - Authority that authorized the transfer
|
|
1206
|
+
* @param amount - Token amount being transferred
|
|
1207
|
+
*/
|
|
1208
|
+
execute(sourceToken: PublicKey, mint: PublicKey, destinationToken: PublicKey, owner: PublicKey, amount: anchor.BN): Promise<TxResult>;
|
|
1209
|
+
fetchConfig(): Promise<HookConfig | null>;
|
|
1210
|
+
isWhitelisted(program: PublicKey): Promise<boolean>;
|
|
1211
|
+
}
|
|
1212
|
+
|
|
1213
|
+
declare class CtfClient {
|
|
1214
|
+
private readonly program;
|
|
1215
|
+
private readonly provider;
|
|
1216
|
+
private readonly programIds;
|
|
1217
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
1218
|
+
get walletPubkey(): PublicKey;
|
|
1219
|
+
/**
|
|
1220
|
+
* Create a Condition directly (bypasses QuestionMarket).
|
|
1221
|
+
* oracle is UncheckedAccount — set it to any pubkey (e.g. user wallet)
|
|
1222
|
+
* so that wallet can later sign reportPayouts.
|
|
1223
|
+
* payer covers rent for condition + mints.
|
|
1224
|
+
*/
|
|
1225
|
+
prepareCondition(questionId: Uint8Array, oracle: PublicKey, collateralMint: PublicKey, hookProgram: PublicKey, authorizedClob: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<{
|
|
1226
|
+
signature: string;
|
|
1227
|
+
conditionPda: PublicKey;
|
|
1228
|
+
yesMint: PublicKey;
|
|
1229
|
+
noMint: PublicKey;
|
|
1230
|
+
}>;
|
|
1231
|
+
/** One-time setup. Caller becomes the CTF owner. Can only be called once. */
|
|
1232
|
+
initializeCtfConfig(): Promise<TxResult>;
|
|
1233
|
+
/**
|
|
1234
|
+
* Create the shared collateral vault for a given collateral mint (e.g. USDC).
|
|
1235
|
+
* Only callable by the CTF owner (as stored in ctf_config).
|
|
1236
|
+
* authority defaults to the wallet — pass a different signer if needed.
|
|
1237
|
+
*/
|
|
1238
|
+
initializeVault(collateralMint: PublicKey): Promise<TxResult>;
|
|
1239
|
+
/**
|
|
1240
|
+
* Initialize an empty Position account (balance = 0) for a user.
|
|
1241
|
+
* Needed before redeemPositions when the user only holds the opposite outcome
|
|
1242
|
+
* (e.g. buyer received YES via CLOB match but never had a NO position).
|
|
1243
|
+
*
|
|
1244
|
+
* Idempotent — call `fetchPosition` first to skip if already initialized.
|
|
1245
|
+
*/
|
|
1246
|
+
initPosition(condition: PublicKey, outcomeIndex: number, user?: PublicKey): Promise<TxResult>;
|
|
1247
|
+
/**
|
|
1248
|
+
* Split `amount` collateral into equal YES + NO tokens.
|
|
1249
|
+
* ATAs created automatically via `init_if_needed`.
|
|
1250
|
+
*/
|
|
1251
|
+
splitPosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1252
|
+
/**
|
|
1253
|
+
* Merge `amount` YES + NO tokens back into collateral.
|
|
1254
|
+
* Both token balances must be ≥ amount.
|
|
1255
|
+
*/
|
|
1256
|
+
mergePosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1257
|
+
/**
|
|
1258
|
+
* After condition resolves: burn outcome tokens proportional to payout
|
|
1259
|
+
* and receive USDC. Works for winning, losing, or both positions.
|
|
1260
|
+
*/
|
|
1261
|
+
redeemPositions(condition: PublicKey, collateralMint: PublicKey, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1262
|
+
/**
|
|
1263
|
+
* Oracle directly resolves a condition with payout numerators.
|
|
1264
|
+
* Bypasses QuestionMarket — only for oracle-owned conditions.
|
|
1265
|
+
*/
|
|
1266
|
+
reportPayouts(condition: PublicKey, payoutNumerators: number[]): Promise<TxResult>;
|
|
1267
|
+
/**
|
|
1268
|
+
* Build the `transfer_position` instruction for use in a CLOB CPI.
|
|
1269
|
+
*
|
|
1270
|
+
* This instruction requires `clob_authority` (the CLOB's PDA) to sign.
|
|
1271
|
+
* A PDA can only sign from within its own program via CPI — this method
|
|
1272
|
+
* CANNOT be called directly from a wallet transaction.
|
|
1273
|
+
*
|
|
1274
|
+
* Use-cases:
|
|
1275
|
+
* - Custom CLOB implementations that call CTF.transfer_position via CPI
|
|
1276
|
+
* - Anchor CPI builders in other Rust programs
|
|
1277
|
+
*
|
|
1278
|
+
* @param condition - Condition PDA
|
|
1279
|
+
* @param outcomeMint - YES or NO mint
|
|
1280
|
+
* @param fromUser - Source wallet
|
|
1281
|
+
* @param fromTokenAccount - Source ATA
|
|
1282
|
+
* @param fromPosition - Source Position PDA
|
|
1283
|
+
* @param toUser - Destination wallet
|
|
1284
|
+
* @param toTokenAccount - Destination ATA (created if needed — payer covers rent)
|
|
1285
|
+
* @param toPosition - Destination Position PDA
|
|
1286
|
+
* @param payer - Pays rent for toPosition + toTokenAccount creation
|
|
1287
|
+
* @param clobAuthority - CLOB config PDA (must sign via CPI)
|
|
1288
|
+
* @param outcomeIndex - 0 = NO, 1 = YES
|
|
1289
|
+
* @param amount - Token amount to transfer
|
|
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 MarketClient {
|
|
1315
|
+
private readonly program;
|
|
1316
|
+
private readonly provider;
|
|
1317
|
+
private readonly programIds;
|
|
1318
|
+
readonly configPda: PublicKey;
|
|
1319
|
+
/** Injected by XMarketSDK after construction — enables fetchQuestionBalances. */
|
|
1320
|
+
ctfClient?: CtfClient;
|
|
1321
|
+
/** Injected by XMarketSDK — 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
|
+
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
1329
|
+
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
1330
|
+
*/
|
|
1331
|
+
createQuestionAdmin(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
1332
|
+
tx: Transaction;
|
|
1333
|
+
questionPda: PublicKey;
|
|
1334
|
+
conditionPda: PublicKey;
|
|
1335
|
+
questionId: Uint8Array;
|
|
1336
|
+
}>;
|
|
1337
|
+
approveQuestion(questionPda: PublicKey, admin?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1338
|
+
updateConfig(params: {
|
|
1339
|
+
newAdmin?: PublicKey;
|
|
1340
|
+
newOracle?: PublicKey;
|
|
1341
|
+
isPaused?: boolean;
|
|
1342
|
+
newConditionalTokensProgram?: PublicKey;
|
|
1343
|
+
}, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1344
|
+
/** Set the admin (owner only). Replaces any existing admin. */
|
|
1345
|
+
addAdmin(newAdmin: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
1346
|
+
/** Clear the admin (owner only). Sets admin to default pubkey. */
|
|
1347
|
+
removeAdmin(owner?: PublicKey): Promise<Transaction>;
|
|
1348
|
+
addToWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1349
|
+
removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1350
|
+
growConfig(owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1351
|
+
restoreConfig(snapshot: Buffer, owner?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
1352
|
+
bumpPresaleCount(count: number, authority: PublicKey): Promise<Transaction>;
|
|
1353
|
+
fetchConfig(): Promise<QuestionMarketConfig | null>;
|
|
1354
|
+
fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
|
|
1355
|
+
questionPda(questionId: Uint8Array): PublicKey;
|
|
1356
|
+
private _parseStatus;
|
|
1357
|
+
/**
|
|
1358
|
+
* Convenience: fetch YES and NO token balances for a question.
|
|
1359
|
+
* Returns null for each if question not approved or position not initialized.
|
|
1360
|
+
* Requires ctfClient to be injected (done automatically by XMarketSDK).
|
|
1361
|
+
*/
|
|
1362
|
+
fetchQuestionBalances(questionPda: PublicKey, owner: PublicKey): Promise<{
|
|
1363
|
+
yes: Position | null;
|
|
1364
|
+
no: Position | null;
|
|
1365
|
+
}>;
|
|
1366
|
+
/**
|
|
1367
|
+
* Any user creates a presale + initial buy (question-market::create_presale).
|
|
1368
|
+
* Reads agents_rev / company_rev from fee_config.
|
|
1369
|
+
*
|
|
1370
|
+
* @param feeConfig fee_management fee_config PDA (owner = feeConfigOwner)
|
|
1371
|
+
* @param currencyMint collateral token (e.g. USDC)
|
|
1372
|
+
* @param presaleIndex config.presale_count — fetch config first or pass 0 for first presale
|
|
1373
|
+
*/
|
|
1374
|
+
createPresale(params: {
|
|
1375
|
+
price: anchor.BN;
|
|
1376
|
+
startTime: anchor.BN;
|
|
1377
|
+
endTime: anchor.BN;
|
|
1378
|
+
initialBuyAmount: anchor.BN;
|
|
1379
|
+
}, feeConfig: PublicKey, currencyMint: PublicKey, presaleIndex: anchor.BN, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
1380
|
+
tx: Transaction;
|
|
1381
|
+
presalePda: PublicKey;
|
|
1382
|
+
qtMint: PublicKey;
|
|
1383
|
+
}>;
|
|
1384
|
+
/**
|
|
1385
|
+
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
1386
|
+
*
|
|
1387
|
+
* @param presalePda the presale account
|
|
1388
|
+
* @param contentHash 32-byte hash for question content
|
|
1389
|
+
* @param hookProgram token-2022 transfer hook program
|
|
1390
|
+
* @param authorizedClob clob program allowed to do CTF transfers
|
|
1391
|
+
* @param expirationTime Unix seconds
|
|
1392
|
+
* @param creator presale creator pubkey (stored in question)
|
|
1393
|
+
* @param currencyMint collateral mint
|
|
1394
|
+
*/
|
|
1395
|
+
approvePresale(params: {
|
|
1396
|
+
presalePda: PublicKey;
|
|
1397
|
+
contentHash: Uint8Array;
|
|
1398
|
+
hookProgram: PublicKey;
|
|
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
|
+
declare class ClobClient {
|
|
1444
|
+
private readonly program;
|
|
1445
|
+
private readonly provider;
|
|
1446
|
+
private readonly programIds;
|
|
1447
|
+
private readonly networkConfig;
|
|
1448
|
+
/** Injected by XMarketSDK after construction — enables auto fee distribution */
|
|
1449
|
+
feeClient?: FeeManagementClient;
|
|
1450
|
+
feeConfigOwner?: PublicKey;
|
|
1451
|
+
/** Injected by XMarketSDK — enables auto-derive of marketOracleVault for presale markets */
|
|
1452
|
+
ctfClient?: CtfClient;
|
|
1453
|
+
qmConfigPda?: PublicKey;
|
|
1454
|
+
/** Injected by XMarketSDK — enables auto-init extraAccountMetaList if missing */
|
|
1455
|
+
hookClient?: HookClient;
|
|
1456
|
+
/** Cached company_address from fee_config to avoid repeated RPC calls */
|
|
1457
|
+
private _companyAddress?;
|
|
1458
|
+
/** Cached referral_vault from fee_config */
|
|
1459
|
+
private _referralVault?;
|
|
1460
|
+
/** Cache: conditionPda.toBase58() → marketOracleVault ATA */
|
|
1461
|
+
private _marketOracleVaultCache;
|
|
1462
|
+
/** ALT cache: condition.toBase58() → loaded ALT account */
|
|
1463
|
+
private _altCache;
|
|
1464
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, networkConfig: {
|
|
1465
|
+
defaultCollateral: {
|
|
1466
|
+
mint: PublicKey;
|
|
1467
|
+
};
|
|
1468
|
+
});
|
|
1469
|
+
private companyAddress;
|
|
1470
|
+
private referralVault;
|
|
1471
|
+
/**
|
|
1472
|
+
* Derive marketOracleVault ATA for a condition, cached per condition.
|
|
1473
|
+
* Works for presale markets (market_oracle initialized by approvePresale).
|
|
1474
|
+
* Returns undefined if ctfClient/qmConfigPda not injected or marketOracle not configured.
|
|
1475
|
+
*/
|
|
1476
|
+
private getMarketOracleVault;
|
|
1477
|
+
/**
|
|
1478
|
+
* Returns a createATA ix for the oracle vault when:
|
|
1479
|
+
* - takerFee > 0
|
|
1480
|
+
* - marketFeeOverride exists for the condition
|
|
1481
|
+
* - oracle vault ATA is not yet initialized
|
|
1482
|
+
* Idempotent — safe to call every tx; returns null if vault already exists.
|
|
1483
|
+
*/
|
|
1484
|
+
private buildInitOracleVaultIfNeeded;
|
|
1485
|
+
get walletPubkey(): PublicKey;
|
|
1486
|
+
/**
|
|
1487
|
+
* Get or create an ALT for a condition.
|
|
1488
|
+
* Includes order_record PDAs for taker + all makers so match tx stays under 1232 bytes.
|
|
1489
|
+
*/
|
|
1490
|
+
ensureAlt(condition: PublicKey, collateralMint: PublicKey, takerSigned: SignedOrder, makers: SignedOrder[]): Promise<AddressLookupTableAccount>;
|
|
1491
|
+
private _sendLegacyTxSig;
|
|
1492
|
+
private _sendLegacyTx;
|
|
1493
|
+
private _ensureClobOutcomeAtas;
|
|
1494
|
+
/**
|
|
1495
|
+
* Send a match transaction as versioned (v0) with optional ALT.
|
|
1496
|
+
* Both operator wallet and payer (this.provider.wallet) sign.
|
|
1497
|
+
*/
|
|
1498
|
+
sendMatchTx(instructions: TransactionInstruction[], lookupTable?: AddressLookupTableAccount, whitelistedWallet?: anchor.Wallet): Promise<string>;
|
|
1499
|
+
configPda(): PublicKey;
|
|
1500
|
+
/**
|
|
1501
|
+
* Register a signed order on-chain.
|
|
1502
|
+
* Sends Ed25519 precompile ix + register_order ix in one legacy tx.
|
|
1503
|
+
* Called at match time (engine-triggered), not at order placement.
|
|
1504
|
+
*/
|
|
1505
|
+
registerOrder(signed: SignedOrder): Promise<string>;
|
|
1506
|
+
/** Register only if the PDA doesn't exist yet (idempotent). */
|
|
1507
|
+
private registerOrderIfNeeded;
|
|
1508
|
+
/**
|
|
1509
|
+
* Build a legacy Transaction to register a CollectFeeOrder on-chain.
|
|
1510
|
+
* Must be signed and sent before calling buildBatchCollectRedeemEarlyTx.
|
|
1511
|
+
*
|
|
1512
|
+
* Flow: [Ed25519 ix (1 user sig) + register_collect_fee_order ix]
|
|
1513
|
+
* Caller signs with payer keypair and sends.
|
|
1514
|
+
*/
|
|
1515
|
+
buildRegisterCollectFeeOrderTx(signedOrder: SignedCollectFeeOrder, payer: PublicKey): Promise<Transaction>;
|
|
1516
|
+
/**
|
|
1517
|
+
* Register a CollectFeeOrder on-chain and send immediately (operator-signed flow).
|
|
1518
|
+
* Idempotent — skips if PDA already exists.
|
|
1519
|
+
*/
|
|
1520
|
+
registerCollectFeeOrderIfNeeded(signedOrder: SignedCollectFeeOrder): Promise<void>;
|
|
1521
|
+
/** Cancel an order — closes its OrderRecord PDA and returns rent to maker. */
|
|
1522
|
+
cancelOrder(nonce: anchor.BN): Promise<TxResult>;
|
|
1523
|
+
initialize(operators: PublicKey[], feeRecipient: PublicKey, feeRateBps: number): Promise<TxResult>;
|
|
1524
|
+
addOperator(operator: PublicKey): Promise<TxResult>;
|
|
1525
|
+
removeOperator(operator: PublicKey): Promise<TxResult>;
|
|
1526
|
+
setPaused(paused: boolean): Promise<TxResult>;
|
|
1527
|
+
forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
|
|
1528
|
+
/**
|
|
1529
|
+
* Build match_complementary instruction (no Ed25519 — OrderRecord PDAs used).
|
|
1530
|
+
*
|
|
1531
|
+
* remaining_accounts layout:
|
|
1532
|
+
* [seller, order_record, seller_token, seller_collateral, seller_position, sell_status] × N
|
|
1533
|
+
* [extraAccountMetaList, hookConfig, hookProgram]
|
|
1534
|
+
* [feeManagement, fee_config, mkt_override, company_ata, oracle_vault] (when fee > 0)
|
|
1535
|
+
*/
|
|
1536
|
+
buildMatchComplementaryIxs(takerSigned: SignedOrder, makersSigned: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, operator: PublicKey, opts?: {
|
|
1537
|
+
marketOracleVault?: PublicKey;
|
|
1538
|
+
fillAmount?: anchor.BN;
|
|
1539
|
+
}, useTakerPrice?: boolean, skipCrossingCheck?: boolean): Promise<TransactionInstruction[]>;
|
|
1540
|
+
/**
|
|
1541
|
+
* COMPLEMENTARY: 1 taker (BUY) + N makers (SELL), same tokenId.
|
|
1542
|
+
* Phase 1: register taker + all makers in parallel.
|
|
1543
|
+
* Phase 2: 1 atomic match tx.
|
|
1544
|
+
*/
|
|
1545
|
+
private matchComplementary;
|
|
1546
|
+
/**
|
|
1547
|
+
* 1 SELL taker vs N BUY makers.
|
|
1548
|
+
* Program now supports SELL-as-taker natively → 1 instruction with all BUY makers
|
|
1549
|
+
* in remaining_accounts (same structure as BUY taker case).
|
|
1550
|
+
*/
|
|
1551
|
+
private matchComplementarySellVsMultiBuy;
|
|
1552
|
+
/**
|
|
1553
|
+
* MINT: 1 YES buyer (taker) + N NO buyers (makers).
|
|
1554
|
+
* Phase 1: register taker + all NO makers in parallel.
|
|
1555
|
+
* Phase 2: 1 atomic match tx.
|
|
1556
|
+
*
|
|
1557
|
+
* remaining_accounts per NO maker (5):
|
|
1558
|
+
* [order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
|
|
1559
|
+
*/
|
|
1560
|
+
/** Build the match_mint_orders instruction (no signing, no sending). */
|
|
1561
|
+
private _buildMintIx;
|
|
1562
|
+
private matchMintOrders;
|
|
1563
|
+
/**
|
|
1564
|
+
* MERGE: 1 YES seller (taker) + N NO sellers (makers).
|
|
1565
|
+
* Phase 1: register taker + all NO makers in parallel.
|
|
1566
|
+
* Phase 2: 1 atomic match tx.
|
|
1567
|
+
*
|
|
1568
|
+
* remaining_accounts per NO maker (5):
|
|
1569
|
+
* [order_record, seller_no_token, seller_no_collateral, seller_no_position, no_order_status]
|
|
1570
|
+
* After all makers, optional 5 fee accounts.
|
|
1571
|
+
*/
|
|
1572
|
+
/** Build the match_merge_orders instruction (no signing, no sending). */
|
|
1573
|
+
private _buildMergeIx;
|
|
1574
|
+
private matchMergeOrders;
|
|
1575
|
+
/**
|
|
1576
|
+
* Auto-detect match type and execute 2-phase:
|
|
1577
|
+
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
|
1578
|
+
* Phase 2 — 1 atomic match transaction.
|
|
1579
|
+
*
|
|
1580
|
+
* Detection (pure, no RPC):
|
|
1581
|
+
* taker.tokenId === makers[0].tokenId:
|
|
1582
|
+
* taker BUY + all makers SELL → COMPLEMENTARY
|
|
1583
|
+
* taker.tokenId !== makers[0].tokenId + all BUY → MINT
|
|
1584
|
+
* taker.tokenId !== makers[0].tokenId + all SELL → MERGE
|
|
1585
|
+
*
|
|
1586
|
+
* @param opts.marketOracleVault Oracle vault ATA for presale markets.
|
|
1587
|
+
* Omit for admin markets (payer used as placeholder).
|
|
1588
|
+
*/
|
|
1589
|
+
matchOrders(taker: SignedOrder, makers: SignedOrder[], opts?: {
|
|
1590
|
+
marketOracleVault?: PublicKey;
|
|
1591
|
+
operatorWallet?: anchor.Wallet;
|
|
1592
|
+
}): Promise<TxResult>;
|
|
1593
|
+
/**
|
|
1594
|
+
* High-level match: caller passes price + quantity + keypair — SDK builds,
|
|
1595
|
+
* signs, and submits in one call. No manual amount calculation needed.
|
|
1596
|
+
*
|
|
1597
|
+
* Amounts are computed from each order's own limit `price` (percentage, e.g. 51 for 51%).
|
|
1598
|
+
* NEVER pass averageMatchedPrice — that is an engine output, not an order input.
|
|
1599
|
+
*
|
|
1600
|
+
* @param taker { keypair, condition, tokenId, side, price, quantity, nonce?, expiry? }
|
|
1601
|
+
* @param makers Array of same shape
|
|
1602
|
+
* @param decimals Collateral decimals (default 9 for USDS)
|
|
1603
|
+
*/
|
|
1604
|
+
matchOrdersFromPrice(taker: {
|
|
1605
|
+
keypair: {
|
|
1606
|
+
publicKey: PublicKey;
|
|
1607
|
+
secretKey: Uint8Array;
|
|
1608
|
+
};
|
|
1609
|
+
condition: PublicKey;
|
|
1610
|
+
tokenId: number;
|
|
1611
|
+
side: 0 | 1;
|
|
1612
|
+
price: number;
|
|
1613
|
+
quantity: number;
|
|
1614
|
+
nonce?: BN;
|
|
1615
|
+
expiry?: BN;
|
|
1616
|
+
fee?: BN;
|
|
1617
|
+
taker?: PublicKey;
|
|
1618
|
+
}, makers: Array<{
|
|
1619
|
+
keypair: {
|
|
1620
|
+
publicKey: PublicKey;
|
|
1621
|
+
secretKey: Uint8Array;
|
|
1622
|
+
};
|
|
1623
|
+
condition: PublicKey;
|
|
1624
|
+
tokenId: number;
|
|
1625
|
+
side: 0 | 1;
|
|
1626
|
+
price: number;
|
|
1627
|
+
quantity: number;
|
|
1628
|
+
nonce?: BN;
|
|
1629
|
+
expiry?: BN;
|
|
1630
|
+
fee?: BN;
|
|
1631
|
+
taker?: PublicKey;
|
|
1632
|
+
}>, decimals?: number, opts?: {
|
|
1633
|
+
marketOracleVault?: PublicKey;
|
|
1634
|
+
operatorWallet?: anchor.Wallet;
|
|
1635
|
+
}): Promise<TxResult>;
|
|
1636
|
+
/**
|
|
1637
|
+
* Build an unsigned VersionedTransaction for a set of match instructions.
|
|
1638
|
+
* Callers sign and send externally — mirrors createQuestionAdmin pattern.
|
|
1639
|
+
*/
|
|
1640
|
+
private _buildUnsignedVtx;
|
|
1641
|
+
/**
|
|
1642
|
+
* Build unsigned VersionedTransaction(s) for matching orders.
|
|
1643
|
+
*
|
|
1644
|
+
* Mirrors createQuestionAdmin pattern — SDK registers orders internally but
|
|
1645
|
+
* returns the match tx unsigned. BE signs with both keypairs and sends:
|
|
1646
|
+
*
|
|
1647
|
+
* const [vtx] = await sdk.clob.buildMatchOrdersTx(taker, makers, operatorPk, payerPk);
|
|
1648
|
+
* vtx.sign([feePayerKeypair, operatorKeypair]);
|
|
1649
|
+
* await connection.sendRawTransaction(vtx.serialize());
|
|
1650
|
+
*
|
|
1651
|
+
* All match types pack into a single VersionedTransaction — same as createQuestionAdmin pattern.
|
|
1652
|
+
* NO-taker MINT/MERGE decomposes into N instructions but all packed in 1 tx.
|
|
1653
|
+
*
|
|
1654
|
+
* @param operator - Whitelisted CLOB operator pubkey (must sign)
|
|
1655
|
+
* @param payer - Fee payer pubkey (must sign, pays tx fee + rent)
|
|
1656
|
+
*/
|
|
1657
|
+
buildMatchOrdersTx(taker: SignedOrder, makers: SignedOrder[], operator: PublicKey, payer: PublicKey, opts?: {
|
|
1658
|
+
marketOracleVault?: PublicKey;
|
|
1659
|
+
}): Promise<VersionedTransaction>;
|
|
1660
|
+
/**
|
|
1661
|
+
* Build VersionedTransaction for batchCollectRedeemEarly.
|
|
1662
|
+
*
|
|
1663
|
+
* Prerequisite: each user's CollectFeeOrder must be registered on-chain via
|
|
1664
|
+
* buildRegisterCollectFeeOrderTx (one tx per user).
|
|
1665
|
+
*
|
|
1666
|
+
* Flow: batchCollectRedeemEarly ix reads CollectFeeOrderRecord PDAs — no Ed25519 inline.
|
|
1667
|
+
* No tx-size limit from signatures, supports 10+ orders in one tx.
|
|
1668
|
+
*
|
|
1669
|
+
* @param signedOrders - Array of { order, signature } (used to derive record PDAs)
|
|
1670
|
+
* @param condition - Market condition PDA
|
|
1671
|
+
* @param outcomeIndex - 0 = NO wins, 1 = YES wins
|
|
1672
|
+
* @param operator - Whitelisted operator pubkey (must sign)
|
|
1673
|
+
* @param payer - Fee payer pubkey (must sign)
|
|
1674
|
+
* @param opts.marketOracleVault - MarketOracle vault for fee distribution
|
|
1675
|
+
*/
|
|
1676
|
+
buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1677
|
+
marketOracleVault?: PublicKey;
|
|
1678
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1679
|
+
}): Promise<VersionedTransaction>;
|
|
1680
|
+
/**
|
|
1681
|
+
* Build a Transaction to register a RedeemFeeOrder on-chain (Ed25519 verify + PDA).
|
|
1682
|
+
* Must be sent before calling buildBatchRedeemWithFeeTx / buildBatchMergeWithFeeTx.
|
|
1683
|
+
*
|
|
1684
|
+
* ix[0]: batched Ed25519 { pubkey=order.user, sig, msg=128 bytes }
|
|
1685
|
+
* ix[1]: register_redeem_fee_order(nonce)
|
|
1686
|
+
*/
|
|
1687
|
+
buildRegisterRedeemFeeOrderTx(signedOrder: SignedRedeemFeeOrder, payer: PublicKey): Promise<anchor.web3.Transaction>;
|
|
1688
|
+
/**
|
|
1689
|
+
* Build a VersionedTransaction for batchRedeemWithFee.
|
|
1690
|
+
* Each pair has a YES order + NO order for the same user (same signer or different).
|
|
1691
|
+
* After resolution: YES holder taker_amount > 0, NO holder taker_amount = 0 (or vice versa).
|
|
1692
|
+
*
|
|
1693
|
+
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
1694
|
+
*/
|
|
1695
|
+
buildBatchRedeemWithFeeTx(orderPairs: RedeemFeeOrderPair[], condition: PublicKey, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1696
|
+
marketOracleVault?: PublicKey;
|
|
1697
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1698
|
+
}): Promise<VersionedTransaction>;
|
|
1699
|
+
/**
|
|
1700
|
+
* Build a VersionedTransaction for batchMergeWithFee (pre-resolution merge with fee).
|
|
1701
|
+
* Each pair: YES order + NO order with equal amounts for the same user.
|
|
1702
|
+
* Only yes_signer receives net USDS (mirrors EVM _matchMergeOrder).
|
|
1703
|
+
*
|
|
1704
|
+
* Prerequisite: each order's RedeemFeeOrderRecord must be registered via buildRegisterRedeemFeeOrderTx.
|
|
1705
|
+
*/
|
|
1706
|
+
buildBatchMergeWithFeeTx(orderPairs: RedeemFeeOrderPair[], condition: PublicKey, operator: PublicKey, payer: PublicKey, opts?: {
|
|
1707
|
+
marketOracleVault?: PublicKey;
|
|
1708
|
+
lookupTable?: AddressLookupTableAccount;
|
|
1709
|
+
}): Promise<VersionedTransaction>;
|
|
1710
|
+
/**
|
|
1711
|
+
* Build ALT for batchCollectRedeemEarly — includes per-user accounts so all
|
|
1712
|
+
* remaining_accounts fit as 1-byte ALT indices instead of 32-byte inline addresses.
|
|
1713
|
+
*/
|
|
1714
|
+
buildAltForCollectBatch(condition: PublicKey, payer: PublicKey, collateralMint: PublicKey, signedOrders: SignedCollectFeeOrder[], outcomeIndex: 0 | 1): Promise<AddressLookupTableAccount>;
|
|
1715
|
+
/**
|
|
1716
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
1717
|
+
* Use before buildBatchCollectRedeemEarlyTx when no prior buildMatchOrdersTx ran in this session.
|
|
1718
|
+
*/
|
|
1719
|
+
buildAltForCondition(condition: PublicKey, _payer: PublicKey, collateralMint?: PublicKey): Promise<AddressLookupTableAccount>;
|
|
1720
|
+
fetchConfig(): Promise<ClobConfig | null>;
|
|
1721
|
+
fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
|
|
1722
|
+
fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
|
|
1723
|
+
maker: PublicKey;
|
|
1724
|
+
condition: PublicKey;
|
|
1725
|
+
tokenId: number;
|
|
1726
|
+
side: number;
|
|
1727
|
+
makerAmount: anchor.BN;
|
|
1728
|
+
takerAmount: anchor.BN;
|
|
1729
|
+
nonce: anchor.BN;
|
|
1730
|
+
expiry: anchor.BN;
|
|
1731
|
+
fee: anchor.BN;
|
|
1732
|
+
taker: PublicKey;
|
|
1733
|
+
signer: PublicKey;
|
|
1734
|
+
} | null>;
|
|
1735
|
+
}
|
|
1736
|
+
|
|
1737
|
+
declare const SEEDS: {
|
|
1738
|
+
readonly config: Buffer<ArrayBuffer>;
|
|
1739
|
+
readonly question: Buffer<ArrayBuffer>;
|
|
1740
|
+
readonly condition: Buffer<ArrayBuffer>;
|
|
1741
|
+
readonly collateralVault: Buffer<ArrayBuffer>;
|
|
1742
|
+
readonly vaultToken: Buffer<ArrayBuffer>;
|
|
1743
|
+
readonly position: Buffer<ArrayBuffer>;
|
|
1744
|
+
readonly yesMint: Buffer<ArrayBuffer>;
|
|
1745
|
+
readonly noMint: Buffer<ArrayBuffer>;
|
|
1746
|
+
readonly mintAuthority: Buffer<ArrayBuffer>;
|
|
1747
|
+
readonly reporter: Buffer<ArrayBuffer>;
|
|
1748
|
+
readonly result: Buffer<ArrayBuffer>;
|
|
1749
|
+
readonly ctfConfig: Buffer<ArrayBuffer>;
|
|
1750
|
+
readonly hookConfig: Buffer<ArrayBuffer>;
|
|
1751
|
+
readonly extraAccountMetas: Buffer<ArrayBuffer>;
|
|
1752
|
+
readonly clobConfig: Buffer<ArrayBuffer>;
|
|
1753
|
+
readonly order: Buffer<ArrayBuffer>;
|
|
1754
|
+
readonly feeConfig: Buffer<ArrayBuffer>;
|
|
1755
|
+
readonly referralConfig: Buffer<ArrayBuffer>;
|
|
1756
|
+
readonly questionFee: Buffer<ArrayBuffer>;
|
|
1757
|
+
readonly marketFee: Buffer<ArrayBuffer>;
|
|
1758
|
+
readonly presale: Buffer<ArrayBuffer>;
|
|
1759
|
+
readonly qtMint: Buffer<ArrayBuffer>;
|
|
1760
|
+
readonly qtAuthority: Buffer<ArrayBuffer>;
|
|
1761
|
+
readonly userBuy: Buffer<ArrayBuffer>;
|
|
1762
|
+
readonly marketOracle: Buffer<ArrayBuffer>;
|
|
1763
|
+
readonly userClaim: Buffer<ArrayBuffer>;
|
|
1764
|
+
readonly adminConfig: Buffer<ArrayBuffer>;
|
|
1765
|
+
readonly claimRecord: Buffer<ArrayBuffer>;
|
|
1766
|
+
readonly disputeConfig: Buffer<ArrayBuffer>;
|
|
1767
|
+
readonly disputeMarket: Buffer<ArrayBuffer>;
|
|
1768
|
+
readonly userDispute: Buffer<ArrayBuffer>;
|
|
1769
|
+
};
|
|
1770
|
+
declare class PDA {
|
|
1771
|
+
static questionMarketConfig(owner: PublicKey, programIds: Pick<ProgramIds, "questionMarket">): [PublicKey, number];
|
|
1772
|
+
static question(config: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "questionMarket">): [PublicKey, number];
|
|
1773
|
+
static ctfConfig(programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1774
|
+
static condition(oracle: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1775
|
+
static collateralVault(collateralMint: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1776
|
+
static vaultToken(collateralMint: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1777
|
+
static yesMint(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1778
|
+
static noMint(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1779
|
+
static mintAuthority(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1780
|
+
static position(condition: PublicKey, outcomeIndex: number, owner: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
1781
|
+
static oracleConfig(owner: PublicKey, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
1782
|
+
static reporter(oracleConfig: PublicKey, reporterAddress: PublicKey, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
1783
|
+
static questionResult(oracleConfig: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
1784
|
+
static hookConfig(programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
|
|
1785
|
+
static extraAccountMetaList(mint: PublicKey, programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
|
|
1786
|
+
static clobConfig(programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
1787
|
+
static orderStatus(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
1788
|
+
static orderRecord(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
1789
|
+
static collectFeeOrderRecord(user: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
1790
|
+
static redeemFeeOrderRecord(user: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
1791
|
+
static feeConfig(owner: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
|
|
1792
|
+
static questionFee(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
|
|
1793
|
+
static marketFeeOverride(conditionPda: PublicKey, programIds: Pick<ProgramIds, "feeManagement">): [PublicKey, number];
|
|
1794
|
+
static presale(questionMarketConfig: PublicKey, presaleIndex: BN, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
|
|
1795
|
+
static qtMint(presalePda: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
|
|
1796
|
+
static qtAuthority(presalePda: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
|
|
1797
|
+
static userBuyRecord(presalePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "presale">): [PublicKey, number];
|
|
1798
|
+
static marketOraclePda(questionPda: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
|
|
1799
|
+
static userClaimRecord(marketOraclePda: PublicKey, user: PublicKey, programIds: Pick<ProgramIds, "marketOracle">): [PublicKey, number];
|
|
1800
|
+
static referralConfig(owner: PublicKey, programIds: Pick<ProgramIds, "referral">): [PublicKey, number];
|
|
1801
|
+
static adminConfig(owner: PublicKey, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
|
|
1802
|
+
static claimRecord(conditionId: Uint8Array, programIds: Pick<ProgramIds, "adminContract">): [PublicKey, number];
|
|
1803
|
+
static disputeConfig(owner: PublicKey, programIds: Pick<ProgramIds, "dispute">): [PublicKey, number];
|
|
1804
|
+
static disputeMarket(conditionId: Uint8Array, programIds: Pick<ProgramIds, "dispute">): [PublicKey, number];
|
|
1805
|
+
static userDispute(user: PublicKey, conditionId: Uint8Array, programIds: Pick<ProgramIds, "dispute">): [PublicKey, number];
|
|
1265
1806
|
}
|
|
1266
1807
|
/** Unique 32-byte question ID: SHA-256(content + timestamp). Different each call. */
|
|
1267
1808
|
declare function generateQuestionId(content: string, salt?: number): Uint8Array;
|
|
@@ -1441,50 +1982,22 @@ type MatchType = "COMPLEMENTARY" | "MINT" | "MERGE";
|
|
|
1441
1982
|
declare function detectMatchType(a: Order | SignedOrder, b: Order | SignedOrder): MatchType;
|
|
1442
1983
|
|
|
1443
1984
|
/**
|
|
1444
|
-
* SPL Token
|
|
1445
|
-
*
|
|
1446
|
-
* Before a match instruction can transfer tokens on behalf of a user, the user
|
|
1447
|
-
* must approve the CLOB config PDA as a delegate. These helpers build the
|
|
1448
|
-
* approve transactions that need two signers:
|
|
1449
|
-
* - signer = the token owner (user wallet — must sign the approve instruction)
|
|
1450
|
-
* - payer = the BE wallet (pays transaction fees)
|
|
1451
|
-
*
|
|
1452
|
-
* Both must sign the resulting Transaction before sending.
|
|
1985
|
+
* SPL Token approve utilities for the CLOB matching flow.
|
|
1986
|
+
* V2: YES/NO mints are plain SPL tokens (TOKEN_PROGRAM_ID), no Token-2022.
|
|
1453
1987
|
*/
|
|
1454
1988
|
|
|
1455
|
-
/** Maximum u64 — approve "unlimited" amount. */
|
|
1456
1989
|
declare const MAX_APPROVE_AMOUNT: BN;
|
|
1457
1990
|
/**
|
|
1458
|
-
* Build a Transaction that creates YES and NO
|
|
1459
|
-
* (idempotent — safe to call even if they already exist).
|
|
1460
|
-
*
|
|
1461
|
-
* Required signer: payer (fee payer). No user signature needed.
|
|
1462
|
-
*
|
|
1463
|
-
* @param condition - condition PDA
|
|
1464
|
-
* @param user - wallet that will own the ATAs
|
|
1465
|
-
* @param payer - fee payer wallet pubkey
|
|
1466
|
-
* @param programIds - network program IDs
|
|
1991
|
+
* Build a Transaction that creates YES and NO SPL ATAs for a user (idempotent).
|
|
1467
1992
|
*/
|
|
1468
1993
|
declare function buildCreateUserAtasTx(condition: PublicKey, user: PublicKey, payer: PublicKey, programIds: ProgramIds): Transaction;
|
|
1469
1994
|
/**
|
|
1470
|
-
* Build a Transaction that approves the CLOB config PDA to transfer collateral
|
|
1471
|
-
* (USDC) from the signer's ATA.
|
|
1472
|
-
*
|
|
1473
|
-
* Required signers: signer (token owner), payer (fee payer).
|
|
1474
|
-
*
|
|
1475
|
-
* @param collateralMint - e.g. USDC mint
|
|
1476
|
-
* @param signer - token owner (must sign)
|
|
1477
|
-
* @param payer - fee payer wallet pubkey
|
|
1478
|
-
* @param delegate - clob config PDA (the spender)
|
|
1479
|
-
* @param amount - amount to approve (defaults to MAX_APPROVE_AMOUNT)
|
|
1995
|
+
* Build a Transaction that approves the CLOB config PDA to transfer collateral (USDS).
|
|
1480
1996
|
*/
|
|
1481
1997
|
declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, amount?: BN): Transaction;
|
|
1482
1998
|
/**
|
|
1483
|
-
* Build a Transaction that approves the CLOB config PDA to transfer
|
|
1484
|
-
* YES and NO outcome tokens from the signer's ATAs (two approve instructions).
|
|
1485
|
-
*
|
|
1486
|
-
* Required signers: signer (token owner), payer (fee payer).
|
|
1999
|
+
* Build a Transaction that approves the CLOB config PDA to transfer YES and NO tokens.
|
|
1487
2000
|
*/
|
|
1488
2001
|
declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
|
|
1489
2002
|
|
|
1490
|
-
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, 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 };
|
|
2003
|
+
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, XMarketSDKV2 as XMarketSDK, XMarketSDKV2, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|