@theliem/xmarket-sdk 1.0.12
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/README.md +1 -0
- package/dist/clob_exchange-ATSH42KC.json +1859 -0
- package/dist/conditional_tokens-3O5V46N5.json +2215 -0
- package/dist/hook-THBRGUM6.json +481 -0
- package/dist/index.d.mts +818 -0
- package/dist/index.d.ts +818 -0
- package/dist/index.js +1860 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1797 -0
- package/dist/index.mjs.map +1 -0
- package/dist/oracle-FZJJIJGI.json +694 -0
- package/dist/question_market-CB6ZUZ5E.json +1465 -0
- package/package.json +65 -0
- package/src/idls/clob_exchange.json +1859 -0
- package/src/idls/conditional_tokens.json +2215 -0
- package/src/idls/hook.json +481 -0
- package/src/idls/oracle.json +694 -0
- package/src/idls/question_market.json +1465 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,818 @@
|
|
|
1
|
+
import * as anchor from '@coral-xyz/anchor';
|
|
2
|
+
import * as _solana_web3_js from '@solana/web3.js';
|
|
3
|
+
import { PublicKey, Keypair, TransactionInstruction, Transaction, AddressLookupTableAccount } from '@solana/web3.js';
|
|
4
|
+
import BN from 'bn.js';
|
|
5
|
+
|
|
6
|
+
interface ProgramIds {
|
|
7
|
+
oracle: PublicKey;
|
|
8
|
+
conditionalTokens: PublicKey;
|
|
9
|
+
questionMarket: PublicKey;
|
|
10
|
+
hook: PublicKey;
|
|
11
|
+
clobExchange: PublicKey;
|
|
12
|
+
}
|
|
13
|
+
interface CollateralConfig {
|
|
14
|
+
mint: PublicKey;
|
|
15
|
+
/** Token decimals (USDC = 6) */
|
|
16
|
+
decimals: number;
|
|
17
|
+
}
|
|
18
|
+
interface NetworkConfig {
|
|
19
|
+
name: string;
|
|
20
|
+
rpcUrl: string;
|
|
21
|
+
programIds: ProgramIds;
|
|
22
|
+
defaultCollateral: CollateralConfig;
|
|
23
|
+
}
|
|
24
|
+
type NetworkName = "devnet" | "localnet" | "mainnet";
|
|
25
|
+
declare const DEVNET_CONFIG: NetworkConfig;
|
|
26
|
+
declare const LOCALNET_CONFIG: NetworkConfig;
|
|
27
|
+
declare const MAINNET_CONFIG: NetworkConfig;
|
|
28
|
+
declare const NETWORK_CONFIGS: Record<NetworkName, NetworkConfig>;
|
|
29
|
+
|
|
30
|
+
interface TxResult {
|
|
31
|
+
signature: string;
|
|
32
|
+
}
|
|
33
|
+
interface OracleConfig {
|
|
34
|
+
owner: PublicKey;
|
|
35
|
+
admin: PublicKey;
|
|
36
|
+
questionCount: number;
|
|
37
|
+
whitelist: PublicKey[];
|
|
38
|
+
whitelistLen: number;
|
|
39
|
+
isPaused: boolean;
|
|
40
|
+
bump: number;
|
|
41
|
+
}
|
|
42
|
+
interface QuestionResult {
|
|
43
|
+
oracleConfig: PublicKey;
|
|
44
|
+
questionId: Uint8Array;
|
|
45
|
+
outcomeIndex: number;
|
|
46
|
+
outcomeCount: number;
|
|
47
|
+
payoutNumerators: BN[];
|
|
48
|
+
isResolved: boolean;
|
|
49
|
+
resolvedAt: number;
|
|
50
|
+
reporter: PublicKey;
|
|
51
|
+
condition: PublicKey | null;
|
|
52
|
+
bump: number;
|
|
53
|
+
}
|
|
54
|
+
interface Condition {
|
|
55
|
+
oracle: PublicKey;
|
|
56
|
+
questionId: Uint8Array;
|
|
57
|
+
outcomeSlotCount: number;
|
|
58
|
+
payoutNumerators: BN[];
|
|
59
|
+
payoutDenominator: BN;
|
|
60
|
+
totalCollateral: BN;
|
|
61
|
+
collateralMint: PublicKey;
|
|
62
|
+
collateralVault: PublicKey;
|
|
63
|
+
yesMint: PublicKey;
|
|
64
|
+
noMint: PublicKey;
|
|
65
|
+
hookProgram: PublicKey;
|
|
66
|
+
authorizedClob: PublicKey;
|
|
67
|
+
isResolved: boolean;
|
|
68
|
+
resolvedAt: number;
|
|
69
|
+
bump: number;
|
|
70
|
+
}
|
|
71
|
+
interface CollateralVault {
|
|
72
|
+
collateralMint: PublicKey;
|
|
73
|
+
vaultTokenAccount: PublicKey;
|
|
74
|
+
totalLocked: BN;
|
|
75
|
+
conditionCount: BN;
|
|
76
|
+
bump: number;
|
|
77
|
+
vaultBump: number;
|
|
78
|
+
}
|
|
79
|
+
interface Position {
|
|
80
|
+
owner: PublicKey;
|
|
81
|
+
condition: PublicKey;
|
|
82
|
+
outcomeIndex: number;
|
|
83
|
+
balance: BN;
|
|
84
|
+
bump: number;
|
|
85
|
+
}
|
|
86
|
+
declare enum QuestionStatus {
|
|
87
|
+
Pending = "pending",
|
|
88
|
+
Approved = "approved",
|
|
89
|
+
Rejected = "rejected",
|
|
90
|
+
Resolved = "resolved"
|
|
91
|
+
}
|
|
92
|
+
interface QuestionMarketConfig {
|
|
93
|
+
owner: PublicKey;
|
|
94
|
+
admin: PublicKey;
|
|
95
|
+
oracle: PublicKey;
|
|
96
|
+
conditionalTokensProgram: PublicKey;
|
|
97
|
+
questionCount: number;
|
|
98
|
+
approvedCount: number;
|
|
99
|
+
rejectedCount: number;
|
|
100
|
+
whitelist: PublicKey[];
|
|
101
|
+
whitelistLen: number;
|
|
102
|
+
isPaused: boolean;
|
|
103
|
+
bump: number;
|
|
104
|
+
}
|
|
105
|
+
interface Question {
|
|
106
|
+
config: PublicKey;
|
|
107
|
+
questionId: Uint8Array;
|
|
108
|
+
contentHash: Uint8Array;
|
|
109
|
+
expirationTime: number;
|
|
110
|
+
currencyMint: PublicKey;
|
|
111
|
+
creator: PublicKey;
|
|
112
|
+
condition: PublicKey | null;
|
|
113
|
+
status: QuestionStatus;
|
|
114
|
+
createdAt: number;
|
|
115
|
+
approvedAt: number;
|
|
116
|
+
resolvedAt: number;
|
|
117
|
+
bump: number;
|
|
118
|
+
}
|
|
119
|
+
interface CreateQuestionParams {
|
|
120
|
+
/** Human-readable question text — used to derive questionId + contentHash */
|
|
121
|
+
content: string;
|
|
122
|
+
/** Expiration as Unix timestamp */
|
|
123
|
+
expirationTime: number;
|
|
124
|
+
/** Collateral mint (e.g. USDC) */
|
|
125
|
+
collateralMint: PublicKey;
|
|
126
|
+
/** Hook program ID for Token-2022 transfer enforcement */
|
|
127
|
+
hookProgram: PublicKey;
|
|
128
|
+
/** Authorized CLOB program ID */
|
|
129
|
+
authorizedClob: PublicKey;
|
|
130
|
+
/** Override auto-generated questionId */
|
|
131
|
+
questionId?: Uint8Array;
|
|
132
|
+
/** Override auto-generated contentHash */
|
|
133
|
+
contentHash?: Uint8Array;
|
|
134
|
+
}
|
|
135
|
+
interface CtfConfig {
|
|
136
|
+
owner: PublicKey;
|
|
137
|
+
bump: number;
|
|
138
|
+
}
|
|
139
|
+
interface HookConfig {
|
|
140
|
+
owner: PublicKey;
|
|
141
|
+
whitelist: PublicKey[];
|
|
142
|
+
whitelistLen: number;
|
|
143
|
+
isFrozen: boolean;
|
|
144
|
+
bump: number;
|
|
145
|
+
}
|
|
146
|
+
interface ClobConfig {
|
|
147
|
+
owner: PublicKey;
|
|
148
|
+
operators: PublicKey[];
|
|
149
|
+
operatorsLen: number;
|
|
150
|
+
feeRecipient: PublicKey;
|
|
151
|
+
feeRateBps: number;
|
|
152
|
+
conditionalTokensProgram: PublicKey;
|
|
153
|
+
isPaused: boolean;
|
|
154
|
+
bump: number;
|
|
155
|
+
}
|
|
156
|
+
interface ClobWhitelistEntry {
|
|
157
|
+
address: PublicKey;
|
|
158
|
+
bump: number;
|
|
159
|
+
}
|
|
160
|
+
interface OrderStatus {
|
|
161
|
+
maker: PublicKey;
|
|
162
|
+
nonce: BN;
|
|
163
|
+
filledAmount: BN;
|
|
164
|
+
isCancelled: boolean;
|
|
165
|
+
bump: number;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Off-chain order struct passed as instruction data.
|
|
169
|
+
* Operator validates + submits matched order pairs on-chain.
|
|
170
|
+
*
|
|
171
|
+
* Semantics (mirrors EVM makerAmount/takerAmount):
|
|
172
|
+
* BUY (side=1): makerAmount = USDC paid, takerAmount = CTF tokens received
|
|
173
|
+
* SELL (side=0): makerAmount = CTF tokens given, takerAmount = USDC received
|
|
174
|
+
*/
|
|
175
|
+
interface Order {
|
|
176
|
+
/** Maker's wallet public key */
|
|
177
|
+
maker: PublicKey;
|
|
178
|
+
/** Condition PDA this order belongs to */
|
|
179
|
+
condition: PublicKey;
|
|
180
|
+
/** Outcome token: 0 = NO, 1 = YES */
|
|
181
|
+
tokenId: number;
|
|
182
|
+
/** Side: 0 = SELL (give tokens, want USDC), 1 = BUY (give USDC, want tokens) */
|
|
183
|
+
side: number;
|
|
184
|
+
/** Amount the maker puts in: BUY → USDC, SELL → CTF tokens */
|
|
185
|
+
makerAmount: BN;
|
|
186
|
+
/** Amount the maker wants to receive: BUY → CTF tokens, SELL → USDC */
|
|
187
|
+
takerAmount: BN;
|
|
188
|
+
/** Unique nonce per maker — used for OrderStatus PDA + replay protection */
|
|
189
|
+
nonce: BN;
|
|
190
|
+
/** Unix timestamp expiry (0 = no expiry) */
|
|
191
|
+
expiry: BN;
|
|
192
|
+
/** Creation timestamp (Unix seconds) */
|
|
193
|
+
createdAt: BN;
|
|
194
|
+
/** Fee from taker order transferred to treasury. 0 = use global fee_rate_bps */
|
|
195
|
+
fee: BN;
|
|
196
|
+
/** Directed order: only this pubkey can be counterparty. PublicKey.default() = public */
|
|
197
|
+
taker: PublicKey;
|
|
198
|
+
/** Ed25519 signer key. Must equal maker for now (proxy not supported) */
|
|
199
|
+
signer: PublicKey;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Signed order — Order + 64-byte Ed25519 signature over serializeOrderToBytes().
|
|
203
|
+
* This is the on-chain instruction data type for all match_* instructions.
|
|
204
|
+
*/
|
|
205
|
+
interface SignedOrder {
|
|
206
|
+
order: Order;
|
|
207
|
+
/** Ed25519 signature (64 bytes) from order.maker over serializeOrderToBytes() */
|
|
208
|
+
signature: Uint8Array;
|
|
209
|
+
}
|
|
210
|
+
declare class XMarketError extends Error {
|
|
211
|
+
code?: string | undefined;
|
|
212
|
+
constructor(message: string, code?: string | undefined);
|
|
213
|
+
}
|
|
214
|
+
declare class UnauthorizedError extends XMarketError {
|
|
215
|
+
constructor(msg?: string);
|
|
216
|
+
}
|
|
217
|
+
declare class AccountNotFoundError extends XMarketError {
|
|
218
|
+
constructor(account: string, address?: string);
|
|
219
|
+
}
|
|
220
|
+
declare class InvalidParamError extends XMarketError {
|
|
221
|
+
constructor(msg?: string);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
declare class OracleClient {
|
|
225
|
+
private readonly program;
|
|
226
|
+
private readonly provider;
|
|
227
|
+
private readonly programIds;
|
|
228
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
229
|
+
get walletPubkey(): PublicKey;
|
|
230
|
+
configPda(owner?: PublicKey): PublicKey;
|
|
231
|
+
/** One-time setup. Caller becomes owner. */
|
|
232
|
+
initialize(admin: PublicKey): Promise<TxResult>;
|
|
233
|
+
/** Admin or owner adds an address to the oracle whitelist. */
|
|
234
|
+
addToWhitelist(address: PublicKey, ownerPubkey?: PublicKey): Promise<TxResult>;
|
|
235
|
+
/** Admin or owner removes an address from the oracle whitelist. */
|
|
236
|
+
removeFromWhitelist(address: PublicKey, ownerPubkey?: PublicKey): Promise<TxResult>;
|
|
237
|
+
/**
|
|
238
|
+
* Whitelisted reporter resolves a question.
|
|
239
|
+
* CPIs directly into CTF.set_payout — condition is resolved in one tx.
|
|
240
|
+
* @param conditionPda - CTF condition account (oracle_config = oraclePda, question_id must match)
|
|
241
|
+
* @param ownerPubkey - oracle config owner (defaults to wallet)
|
|
242
|
+
* @param payer - fee payer (defaults to wallet)
|
|
243
|
+
*/
|
|
244
|
+
resolveQuestion(questionId: Uint8Array, outcomeCount: number, payoutNumerators: number[], conditionPda: PublicKey, ownerPubkey?: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<TxResult>;
|
|
245
|
+
/** Owner updates the admin. */
|
|
246
|
+
updateAdmin(newAdmin: PublicKey, ownerPubkey?: PublicKey): Promise<TxResult>;
|
|
247
|
+
/** Owner transfers ownership to a new keypair. */
|
|
248
|
+
transferOwnership(newOwner: PublicKey, ownerPubkey?: PublicKey): Promise<TxResult>;
|
|
249
|
+
/** Admin or owner pause/unpause the oracle. */
|
|
250
|
+
pause(paused: boolean, ownerPubkey?: PublicKey): Promise<TxResult>;
|
|
251
|
+
fetchConfig(owner?: PublicKey): Promise<OracleConfig | null>;
|
|
252
|
+
fetchQuestionResult(questionId: Uint8Array, ownerPubkey?: PublicKey): Promise<QuestionResult | null>;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
declare class HookClient {
|
|
256
|
+
private readonly program;
|
|
257
|
+
private readonly provider;
|
|
258
|
+
private readonly programIds;
|
|
259
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
260
|
+
get walletPubkey(): PublicKey;
|
|
261
|
+
configPda(): PublicKey;
|
|
262
|
+
/** One-time setup. Caller becomes owner. */
|
|
263
|
+
initialize(initialWhitelist: PublicKey[]): Promise<TxResult>;
|
|
264
|
+
/**
|
|
265
|
+
* Register extra account metas for a Token-2022 YES/NO mint.
|
|
266
|
+
* Must be called once per mint after CTF creates it.
|
|
267
|
+
*/
|
|
268
|
+
initializeExtraAccountMetaList(mint: PublicKey): Promise<TxResult>;
|
|
269
|
+
/** Owner adds a program to the transfer whitelist. */
|
|
270
|
+
addToWhitelist(program: PublicKey): Promise<TxResult>;
|
|
271
|
+
/** Owner removes a program from the transfer whitelist. */
|
|
272
|
+
removeFromWhitelist(program: PublicKey): Promise<TxResult>;
|
|
273
|
+
/** Permanently freeze the whitelist — no further changes allowed. */
|
|
274
|
+
freezeWhitelist(): Promise<TxResult>;
|
|
275
|
+
/**
|
|
276
|
+
* SPL Transfer-Hook `execute` — invoked automatically by Token-2022 on every
|
|
277
|
+
* YES/NO token transfer. Validates the destination against the whitelist.
|
|
278
|
+
*
|
|
279
|
+
* Calling this directly is useful for:
|
|
280
|
+
* - Off-chain simulation ("would this transfer be allowed?")
|
|
281
|
+
* - Integration tests that verify whitelist enforcement
|
|
282
|
+
*
|
|
283
|
+
* Token-2022 calls this automatically; you normally don't call it manually.
|
|
284
|
+
*
|
|
285
|
+
* @param sourceToken - Source token account (tokens leaving)
|
|
286
|
+
* @param mint - The YES/NO Token-2022 mint
|
|
287
|
+
* @param destinationToken - Destination token account (tokens arriving)
|
|
288
|
+
* @param owner - Authority that authorized the transfer
|
|
289
|
+
* @param amount - Token amount being transferred
|
|
290
|
+
*/
|
|
291
|
+
execute(sourceToken: PublicKey, mint: PublicKey, destinationToken: PublicKey, owner: PublicKey, amount: anchor.BN): Promise<TxResult>;
|
|
292
|
+
fetchConfig(): Promise<HookConfig | null>;
|
|
293
|
+
isWhitelisted(program: PublicKey): Promise<boolean>;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
declare class CtfClient {
|
|
297
|
+
private readonly program;
|
|
298
|
+
private readonly provider;
|
|
299
|
+
private readonly programIds;
|
|
300
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
301
|
+
get walletPubkey(): PublicKey;
|
|
302
|
+
/**
|
|
303
|
+
* Create a Condition directly (bypasses QuestionMarket).
|
|
304
|
+
* oracle is UncheckedAccount — set it to any pubkey (e.g. user wallet)
|
|
305
|
+
* so that wallet can later sign reportPayouts.
|
|
306
|
+
* payer covers rent for condition + mints.
|
|
307
|
+
*/
|
|
308
|
+
prepareCondition(questionId: Uint8Array, oracle: PublicKey, collateralMint: PublicKey, hookProgram: PublicKey, authorizedClob: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<{
|
|
309
|
+
signature: string;
|
|
310
|
+
conditionPda: PublicKey;
|
|
311
|
+
yesMint: PublicKey;
|
|
312
|
+
noMint: PublicKey;
|
|
313
|
+
}>;
|
|
314
|
+
/** One-time setup. Caller becomes the CTF owner. Can only be called once. */
|
|
315
|
+
initializeCtfConfig(): Promise<TxResult>;
|
|
316
|
+
/**
|
|
317
|
+
* Create the shared collateral vault for a given collateral mint (e.g. USDC).
|
|
318
|
+
* Only callable by the CTF owner (as stored in ctf_config).
|
|
319
|
+
* authority defaults to the wallet — pass a different signer if needed.
|
|
320
|
+
*/
|
|
321
|
+
initializeVault(collateralMint: PublicKey): Promise<TxResult>;
|
|
322
|
+
/**
|
|
323
|
+
* Initialize an empty Position account (balance = 0) for a user.
|
|
324
|
+
* Needed before redeemPositions when the user only holds the opposite outcome
|
|
325
|
+
* (e.g. buyer received YES via CLOB match but never had a NO position).
|
|
326
|
+
*
|
|
327
|
+
* Idempotent — call `fetchPosition` first to skip if already initialized.
|
|
328
|
+
*/
|
|
329
|
+
initPosition(condition: PublicKey, outcomeIndex: number, user?: PublicKey): Promise<TxResult>;
|
|
330
|
+
/**
|
|
331
|
+
* Split `amount` collateral into equal YES + NO tokens.
|
|
332
|
+
* ATAs created automatically via `init_if_needed`.
|
|
333
|
+
*/
|
|
334
|
+
splitPosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<TxResult>;
|
|
335
|
+
/**
|
|
336
|
+
* Merge `amount` YES + NO tokens back into collateral.
|
|
337
|
+
* Both token balances must be ≥ amount.
|
|
338
|
+
*/
|
|
339
|
+
mergePosition(condition: PublicKey, collateralMint: PublicKey, amount: anchor.BN, user?: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<TxResult>;
|
|
340
|
+
/**
|
|
341
|
+
* After condition resolves: burn outcome tokens proportional to payout
|
|
342
|
+
* and receive USDC. Works for winning, losing, or both positions.
|
|
343
|
+
*/
|
|
344
|
+
redeemPositions(condition: PublicKey, collateralMint: PublicKey, user?: PublicKey, payer?: PublicKey, signers?: Keypair[]): Promise<TxResult>;
|
|
345
|
+
/**
|
|
346
|
+
* Oracle directly resolves a condition with payout numerators.
|
|
347
|
+
* Bypasses QuestionMarket — only for oracle-owned conditions.
|
|
348
|
+
*/
|
|
349
|
+
reportPayouts(condition: PublicKey, payoutNumerators: number[]): Promise<TxResult>;
|
|
350
|
+
/**
|
|
351
|
+
* Build the `transfer_position` instruction for use in a CLOB CPI.
|
|
352
|
+
*
|
|
353
|
+
* This instruction requires `clob_authority` (the CLOB's PDA) to sign.
|
|
354
|
+
* A PDA can only sign from within its own program via CPI — this method
|
|
355
|
+
* CANNOT be called directly from a wallet transaction.
|
|
356
|
+
*
|
|
357
|
+
* Use-cases:
|
|
358
|
+
* - Custom CLOB implementations that call CTF.transfer_position via CPI
|
|
359
|
+
* - Anchor CPI builders in other Rust programs
|
|
360
|
+
*
|
|
361
|
+
* @param condition - Condition PDA
|
|
362
|
+
* @param outcomeMint - YES or NO mint
|
|
363
|
+
* @param fromUser - Source wallet
|
|
364
|
+
* @param fromTokenAccount - Source ATA
|
|
365
|
+
* @param fromPosition - Source Position PDA
|
|
366
|
+
* @param toUser - Destination wallet
|
|
367
|
+
* @param toTokenAccount - Destination ATA (created if needed — payer covers rent)
|
|
368
|
+
* @param toPosition - Destination Position PDA
|
|
369
|
+
* @param payer - Pays rent for toPosition + toTokenAccount creation
|
|
370
|
+
* @param clobAuthority - CLOB config PDA (must sign via CPI)
|
|
371
|
+
* @param outcomeIndex - 0 = NO, 1 = YES
|
|
372
|
+
* @param amount - Token amount to transfer
|
|
373
|
+
*/
|
|
374
|
+
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>;
|
|
375
|
+
/**
|
|
376
|
+
* Update the authorized CLOB on a condition.
|
|
377
|
+
* Only callable by the condition's oracle (the wallet that signed createQuestion).
|
|
378
|
+
*/
|
|
379
|
+
updateAuthorizedClob(condition: PublicKey, newAuthorizedClob: PublicKey): Promise<TxResult>;
|
|
380
|
+
fetchCtfConfig(): Promise<CtfConfig | null>;
|
|
381
|
+
fetchCondition(conditionPda: PublicKey): Promise<Condition | null>;
|
|
382
|
+
fetchVault(collateralMint: PublicKey): Promise<CollateralVault | null>;
|
|
383
|
+
fetchPosition(condition: PublicKey, outcomeIndex: number, owner?: PublicKey): Promise<Position | null>;
|
|
384
|
+
/** YES = outcome index 1, NO = outcome index 0. */
|
|
385
|
+
fetchBothPositions(condition: PublicKey, owner?: PublicKey): Promise<{
|
|
386
|
+
yes: Position | null;
|
|
387
|
+
no: Position | null;
|
|
388
|
+
}>;
|
|
389
|
+
/** Thin wrapper: fetch position for a single outcome token (0=NO, 1=YES). */
|
|
390
|
+
fetchTokenBalance(condition: PublicKey, tokenId: number, owner?: PublicKey): Promise<Position | null>;
|
|
391
|
+
yesMintPda(condition: PublicKey): PublicKey;
|
|
392
|
+
noMintPda(condition: PublicKey): PublicKey;
|
|
393
|
+
mintAuthorityPda(condition: PublicKey): PublicKey;
|
|
394
|
+
collateralVaultPda(collateralMint: PublicKey): PublicKey;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
declare class MarketClient {
|
|
398
|
+
private readonly program;
|
|
399
|
+
private readonly provider;
|
|
400
|
+
private readonly programIds;
|
|
401
|
+
readonly configPda: PublicKey;
|
|
402
|
+
/** Injected by XMarketSDK after construction — enables fetchQuestionBalances. */
|
|
403
|
+
ctfClient?: CtfClient;
|
|
404
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds, ownerPubkey: PublicKey);
|
|
405
|
+
get walletPubkey(): PublicKey;
|
|
406
|
+
initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
407
|
+
/**
|
|
408
|
+
* Build createQuestion transaction.
|
|
409
|
+
* @param payer - Pays rent for all new accounts (can differ from creator)
|
|
410
|
+
* @param creator - Identity of the question creator (signs but does not pay)
|
|
411
|
+
*/
|
|
412
|
+
createQuestion(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
413
|
+
tx: Transaction;
|
|
414
|
+
questionPda: PublicKey;
|
|
415
|
+
conditionPda: PublicKey;
|
|
416
|
+
questionId: Uint8Array;
|
|
417
|
+
}>;
|
|
418
|
+
/**
|
|
419
|
+
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
420
|
+
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
421
|
+
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
422
|
+
*/
|
|
423
|
+
createQuestionAdmin(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
424
|
+
tx: Transaction;
|
|
425
|
+
questionPda: PublicKey;
|
|
426
|
+
conditionPda: PublicKey;
|
|
427
|
+
questionId: Uint8Array;
|
|
428
|
+
}>;
|
|
429
|
+
approveQuestion(questionPda: PublicKey, admin?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
430
|
+
updateConfig(params: {
|
|
431
|
+
newAdmin?: PublicKey;
|
|
432
|
+
newOracle?: PublicKey;
|
|
433
|
+
isPaused?: boolean;
|
|
434
|
+
newConditionalTokensProgram?: PublicKey;
|
|
435
|
+
}, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
436
|
+
/** Set the admin (owner only). Replaces any existing admin. */
|
|
437
|
+
addAdmin(newAdmin: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
438
|
+
/** Clear the admin (owner only). Sets admin to default pubkey. */
|
|
439
|
+
removeAdmin(owner?: PublicKey): Promise<Transaction>;
|
|
440
|
+
addToWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
441
|
+
removeFromWhitelist(address: PublicKey, authority?: PublicKey, payer?: PublicKey): Promise<Transaction>;
|
|
442
|
+
fetchConfig(): Promise<QuestionMarketConfig | null>;
|
|
443
|
+
fetchQuestion(questionPda: PublicKey): Promise<Question | null>;
|
|
444
|
+
questionPda(questionId: Uint8Array): PublicKey;
|
|
445
|
+
private _parseStatus;
|
|
446
|
+
/**
|
|
447
|
+
* Convenience: fetch YES and NO token balances for a question.
|
|
448
|
+
* Returns null for each if question not approved or position not initialized.
|
|
449
|
+
* Requires ctfClient to be injected (done automatically by XMarketSDK).
|
|
450
|
+
*/
|
|
451
|
+
fetchQuestionBalances(questionPda: PublicKey, owner: PublicKey): Promise<{
|
|
452
|
+
yes: Position | null;
|
|
453
|
+
no: Position | null;
|
|
454
|
+
}>;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
declare class ClobClient {
|
|
458
|
+
private readonly program;
|
|
459
|
+
private readonly provider;
|
|
460
|
+
private readonly programIds;
|
|
461
|
+
constructor(program: anchor.Program, provider: anchor.AnchorProvider, programIds: ProgramIds);
|
|
462
|
+
get walletPubkey(): PublicKey;
|
|
463
|
+
/**
|
|
464
|
+
* Send a match transaction as versioned (v0).
|
|
465
|
+
* Pass a pre-built AddressLookupTableAccount to compress account keys and
|
|
466
|
+
* stay under the 1232-byte limit — required for match_complementary which
|
|
467
|
+
* has ~25 accounts + 2 Ed25519 precompile instructions (~1697 bytes raw).
|
|
468
|
+
*
|
|
469
|
+
* If `whitelistedWallet` is provided and differs from `this.provider.wallet`,
|
|
470
|
+
* both wallets sign the transaction (whitelisted operator + payer).
|
|
471
|
+
*/
|
|
472
|
+
private _sendMatchTx;
|
|
473
|
+
/** PDA for a CLOB whitelist entry. */
|
|
474
|
+
whitelistEntryPda(address: PublicKey): PublicKey;
|
|
475
|
+
configPda(): PublicKey;
|
|
476
|
+
/** One-time setup. Caller becomes admin. */
|
|
477
|
+
initialize(operators: PublicKey[], feeRecipient: PublicKey, feeRateBps: number): Promise<TxResult>;
|
|
478
|
+
/** Admin adds an operator to the whitelist. */
|
|
479
|
+
addOperator(operator: PublicKey): Promise<TxResult>;
|
|
480
|
+
/** Admin removes an operator from the whitelist. */
|
|
481
|
+
removeOperator(operator: PublicKey): Promise<TxResult>;
|
|
482
|
+
/** Admin pause/unpause the CLOB. */
|
|
483
|
+
setPaused(paused: boolean): Promise<TxResult>;
|
|
484
|
+
/**
|
|
485
|
+
* Maker cancels their own order.
|
|
486
|
+
* OrderStatus PDA is marked cancelled — any future fill rejected.
|
|
487
|
+
*/
|
|
488
|
+
cancelOrder(nonce: anchor.BN): Promise<TxResult>;
|
|
489
|
+
/**
|
|
490
|
+
* Emergency reset of CLOB config (upgrade authority only).
|
|
491
|
+
*/
|
|
492
|
+
forceResetClob(programData: PublicKey, newAdmin: PublicKey, newOperators: PublicKey[], newFeeRecipient: PublicKey, newFeeRateBps: number): Promise<TxResult>;
|
|
493
|
+
/**
|
|
494
|
+
* COMPLEMENTARY match: 1 buyer (taker) + N sellers (makers), same tokenId.
|
|
495
|
+
*
|
|
496
|
+
* Transaction structure:
|
|
497
|
+
* ix[0] Ed25519(taker/buyer)
|
|
498
|
+
* ix[1+i] Ed25519(maker_i/seller_i)
|
|
499
|
+
* ix[N+1] match_complementary(buyNonce, makerNonces[])
|
|
500
|
+
*
|
|
501
|
+
* remaining_accounts: [hook×3] [seller×5 × N]
|
|
502
|
+
*/
|
|
503
|
+
private matchComplementary;
|
|
504
|
+
/**
|
|
505
|
+
* MINT match: 1 YES buyer (taker) + N NO buyers (makers).
|
|
506
|
+
*
|
|
507
|
+
* Transaction structure:
|
|
508
|
+
* ix[0] Ed25519(taker/YES buyer)
|
|
509
|
+
* ix[1+i] Ed25519(maker_i/NO buyer)
|
|
510
|
+
* ix[N+1] match_mint_orders(yesNonce, makerNonces[])
|
|
511
|
+
*
|
|
512
|
+
* remaining_accounts: [maker×5 × N] (no hook accounts — mint_to doesn't fire hook)
|
|
513
|
+
*/
|
|
514
|
+
private matchMintOrders;
|
|
515
|
+
/**
|
|
516
|
+
* MERGE match: 1 YES seller (taker) + N NO sellers (makers).
|
|
517
|
+
*
|
|
518
|
+
* Transaction structure:
|
|
519
|
+
* ix[0] Ed25519(taker/YES seller)
|
|
520
|
+
* ix[1+i] Ed25519(maker_i/NO seller)
|
|
521
|
+
* ix[N+1] match_merge_orders(yesNonce, makerNonces[])
|
|
522
|
+
*
|
|
523
|
+
* remaining_accounts: [maker×5 × N] (no hook accounts — burn doesn't fire hook)
|
|
524
|
+
*/
|
|
525
|
+
private matchMergeOrders;
|
|
526
|
+
/**
|
|
527
|
+
* Auto-detect match type and execute 1-taker + N-makers in a single transaction.
|
|
528
|
+
*
|
|
529
|
+
* Detection (pure, no RPC) based on taker.order vs makers[0].order:
|
|
530
|
+
* taker.tokenId === makers[0].tokenId: taker BUY + all makers SELL → COMPLEMENTARY
|
|
531
|
+
* taker.tokenId !== makers[0].tokenId + taker BUY + all makers BUY → MINT
|
|
532
|
+
* taker.tokenId !== makers[0].tokenId + taker SELL + all makers SELL → MERGE
|
|
533
|
+
* Otherwise → throws InvalidParamError
|
|
534
|
+
*
|
|
535
|
+
* All makers must have the same tokenId and side as makers[0].
|
|
536
|
+
*/
|
|
537
|
+
matchOrders(taker: SignedOrder, makers: SignedOrder[], collateralMint: PublicKey, feeRecipient: PublicKey, whitelistedWallet: anchor.Wallet, lookupTable?: AddressLookupTableAccount): Promise<TxResult>;
|
|
538
|
+
/** Add an address to the CLOB whitelist (owner only). */
|
|
539
|
+
addToWhitelist(address: PublicKey): Promise<TxResult>;
|
|
540
|
+
/** Batch-add addresses to the CLOB whitelist (owner only). All PDAs created in one tx. */
|
|
541
|
+
addToWhitelistBatch(addresses: PublicKey[]): Promise<TxResult>;
|
|
542
|
+
/** Remove an address from the CLOB whitelist (owner only). */
|
|
543
|
+
removeFromWhitelist(address: PublicKey, rentReceiver?: PublicKey): Promise<TxResult>;
|
|
544
|
+
/** Fetch a whitelist entry PDA (returns null if address is not whitelisted). */
|
|
545
|
+
fetchWhitelistEntry(address: PublicKey): Promise<ClobWhitelistEntry | null>;
|
|
546
|
+
/** Check if an address is on the CLOB whitelist. */
|
|
547
|
+
isWhitelisted(address: PublicKey): Promise<boolean>;
|
|
548
|
+
/** Fetch all whitelisted addresses (scans all ClobWhitelistEntry accounts). */
|
|
549
|
+
fetchWhitelist(): Promise<PublicKey[]>;
|
|
550
|
+
fetchConfig(): Promise<ClobConfig | null>;
|
|
551
|
+
fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
|
|
552
|
+
isOrderCancelled(maker: PublicKey, nonce: anchor.BN): Promise<boolean>;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
interface XMarketSDKConfig {
|
|
556
|
+
/**
|
|
557
|
+
* Network to connect to.
|
|
558
|
+
* - `"devnet"` — public devnet, programs deployed
|
|
559
|
+
* - `"localnet"` — local test validator (same program IDs as devnet)
|
|
560
|
+
* - `"mainnet"` — mainnet-beta (hook + clob IDs TBD)
|
|
561
|
+
* - `NetworkConfig` — fully custom config
|
|
562
|
+
*/
|
|
563
|
+
network: NetworkName | NetworkConfig;
|
|
564
|
+
wallet: anchor.Wallet;
|
|
565
|
+
/**
|
|
566
|
+
* Owner public key used to derive QuestionMarket + Oracle config PDAs.
|
|
567
|
+
* Defaults to wallet pubkey.
|
|
568
|
+
*/
|
|
569
|
+
marketOwner?: PublicKey;
|
|
570
|
+
}
|
|
571
|
+
/**
|
|
572
|
+
* Top-level SDK entry point.
|
|
573
|
+
*
|
|
574
|
+
* ```ts
|
|
575
|
+
* // Quickstart: devnet
|
|
576
|
+
* const sdk = XMarketSDK.devnet(wallet);
|
|
577
|
+
*
|
|
578
|
+
* // Create a question market
|
|
579
|
+
* await sdk.market.createQuestion({ content: "...", ... }, oraclePubkey);
|
|
580
|
+
*
|
|
581
|
+
* // Split collateral into YES + NO tokens
|
|
582
|
+
* await sdk.ctf.splitPosition(conditionPda, usdcMint, new BN(100_000));
|
|
583
|
+
*
|
|
584
|
+
* // Match orders on the CLOB
|
|
585
|
+
* await sdk.clob.matchMintOrders(yesOrder, noOrder, fillAmount, usdcMint);
|
|
586
|
+
*
|
|
587
|
+
* // Inspect active network config
|
|
588
|
+
* console.log(sdk.networkConfig.name, sdk.networkConfig.programIds);
|
|
589
|
+
* ```
|
|
590
|
+
*/
|
|
591
|
+
declare class XMarketSDK {
|
|
592
|
+
readonly provider: anchor.AnchorProvider;
|
|
593
|
+
/** Active network configuration (program IDs, RPC, collateral) */
|
|
594
|
+
readonly networkConfig: NetworkConfig;
|
|
595
|
+
private readonly _programIds;
|
|
596
|
+
private readonly _marketOwner;
|
|
597
|
+
private _oracle?;
|
|
598
|
+
private _hook?;
|
|
599
|
+
private _market?;
|
|
600
|
+
private _ctf?;
|
|
601
|
+
private _clob?;
|
|
602
|
+
constructor(config: XMarketSDKConfig);
|
|
603
|
+
private _withAddress;
|
|
604
|
+
/** Oracle program client */
|
|
605
|
+
get oracle(): OracleClient;
|
|
606
|
+
/** Transfer-hook program client */
|
|
607
|
+
get hook(): HookClient;
|
|
608
|
+
/** QuestionMarket program client */
|
|
609
|
+
get market(): MarketClient;
|
|
610
|
+
/** Conditional tokens (CTF) program client */
|
|
611
|
+
get ctf(): CtfClient;
|
|
612
|
+
/** CLOB exchange program client */
|
|
613
|
+
get clob(): ClobClient;
|
|
614
|
+
/**
|
|
615
|
+
* Connect to devnet.
|
|
616
|
+
* ```ts
|
|
617
|
+
* const sdk = XMarketSDK.devnet(wallet);
|
|
618
|
+
* ```
|
|
619
|
+
*/
|
|
620
|
+
static devnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
|
|
621
|
+
/**
|
|
622
|
+
* Connect to localhost test validator.
|
|
623
|
+
* ```ts
|
|
624
|
+
* const sdk = XMarketSDK.localnet(wallet);
|
|
625
|
+
* ```
|
|
626
|
+
*/
|
|
627
|
+
static localnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
|
|
628
|
+
/**
|
|
629
|
+
* Connect to mainnet-beta.
|
|
630
|
+
* ```ts
|
|
631
|
+
* const sdk = XMarketSDK.mainnet(wallet);
|
|
632
|
+
* ```
|
|
633
|
+
*/
|
|
634
|
+
static mainnet(wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
|
|
635
|
+
/**
|
|
636
|
+
* Custom network (e.g. custom RPC, custom program IDs for a fork).
|
|
637
|
+
* ```ts
|
|
638
|
+
* const sdk = XMarketSDK.custom({
|
|
639
|
+
* name: "staging",
|
|
640
|
+
* rpcUrl: "https://my-rpc.com",
|
|
641
|
+
* programIds: { ... },
|
|
642
|
+
* defaultCollateral: { mint: ..., decimals: 6 },
|
|
643
|
+
* }, wallet);
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
static custom(config: NetworkConfig, wallet: anchor.Wallet, marketOwner?: PublicKey): XMarketSDK;
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
declare const SEEDS: {
|
|
650
|
+
readonly config: Buffer<ArrayBuffer>;
|
|
651
|
+
readonly question: Buffer<ArrayBuffer>;
|
|
652
|
+
readonly condition: Buffer<ArrayBuffer>;
|
|
653
|
+
readonly collateralVault: Buffer<ArrayBuffer>;
|
|
654
|
+
readonly vaultToken: Buffer<ArrayBuffer>;
|
|
655
|
+
readonly position: Buffer<ArrayBuffer>;
|
|
656
|
+
readonly yesMint: Buffer<ArrayBuffer>;
|
|
657
|
+
readonly noMint: Buffer<ArrayBuffer>;
|
|
658
|
+
readonly mintAuthority: Buffer<ArrayBuffer>;
|
|
659
|
+
readonly reporter: Buffer<ArrayBuffer>;
|
|
660
|
+
readonly result: Buffer<ArrayBuffer>;
|
|
661
|
+
readonly ctfConfig: Buffer<ArrayBuffer>;
|
|
662
|
+
readonly hookConfig: Buffer<ArrayBuffer>;
|
|
663
|
+
readonly extraAccountMetas: Buffer<ArrayBuffer>;
|
|
664
|
+
readonly clobConfig: Buffer<ArrayBuffer>;
|
|
665
|
+
readonly order: Buffer<ArrayBuffer>;
|
|
666
|
+
};
|
|
667
|
+
declare class PDA {
|
|
668
|
+
static questionMarketConfig(owner: PublicKey, programIds: Pick<ProgramIds, "questionMarket">): [PublicKey, number];
|
|
669
|
+
static question(config: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "questionMarket">): [PublicKey, number];
|
|
670
|
+
static ctfConfig(programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
671
|
+
static condition(oracle: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
672
|
+
static collateralVault(collateralMint: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
673
|
+
static vaultToken(collateralMint: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
674
|
+
static yesMint(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
675
|
+
static noMint(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
676
|
+
static mintAuthority(condition: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
677
|
+
static position(condition: PublicKey, outcomeIndex: number, owner: PublicKey, programIds: Pick<ProgramIds, "conditionalTokens">): [PublicKey, number];
|
|
678
|
+
static oracleConfig(owner: PublicKey, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
679
|
+
static reporter(oracleConfig: PublicKey, reporterAddress: PublicKey, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
680
|
+
static questionResult(oracleConfig: PublicKey, questionId: Uint8Array, programIds: Pick<ProgramIds, "oracle">): [PublicKey, number];
|
|
681
|
+
static hookConfig(programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
|
|
682
|
+
static extraAccountMetaList(mint: PublicKey, programIds: Pick<ProgramIds, "hook">): [PublicKey, number];
|
|
683
|
+
static clobConfig(programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
684
|
+
static orderStatus(maker: PublicKey, nonce: BN, programIds: Pick<ProgramIds, "clobExchange">): [PublicKey, number];
|
|
685
|
+
}
|
|
686
|
+
/** Unique 32-byte question ID: SHA-256(content + timestamp). Different each call. */
|
|
687
|
+
declare function generateQuestionId(content: string, salt?: number): Uint8Array;
|
|
688
|
+
/** Deterministic 32-byte content hash: SHA-256(content). Same content = same hash. */
|
|
689
|
+
declare function generateContentHash(content: string): Uint8Array;
|
|
690
|
+
|
|
691
|
+
declare function serializeOrderToBytes(order: Order): Uint8Array;
|
|
692
|
+
/**
|
|
693
|
+
* Sign an order with a keypair's sign function.
|
|
694
|
+
* The `signFn` receives the 98-byte canonical message and returns a 64-byte signature.
|
|
695
|
+
*
|
|
696
|
+
* Usage with a Keypair:
|
|
697
|
+
* const signed = signOrder(order, (msg) => keypair.secretKey.slice(0,64) && nacl.sign.detached(msg, keypair.secretKey))
|
|
698
|
+
*
|
|
699
|
+
* Or use the convenience wrapper `signOrderWithKeypair` from this module.
|
|
700
|
+
*/
|
|
701
|
+
declare function signOrder(order: Order, signFn: (message: Uint8Array) => Uint8Array | Promise<Uint8Array>): Promise<SignedOrder>;
|
|
702
|
+
/**
|
|
703
|
+
* Build a single batched Ed25519 precompile instruction for N signed orders.
|
|
704
|
+
*
|
|
705
|
+
* All signatures are packed into one instruction (ix[0]).
|
|
706
|
+
* The on-chain program reads sig[i] via `extract_order_from_ed25519_ix(sysvar, i)`.
|
|
707
|
+
*
|
|
708
|
+
* Batched layout saves ~12 bytes vs N separate Ed25519 instructions — critical for
|
|
709
|
+
* fitting 1-taker + 2-maker transactions within Solana's 1232-byte raw tx limit.
|
|
710
|
+
*
|
|
711
|
+
* Data format:
|
|
712
|
+
* [0] num_sigs (N)
|
|
713
|
+
* [1] padding
|
|
714
|
+
* [2+i*14] per-sig offset entries (14 bytes each)
|
|
715
|
+
* Then: sigs (64B each), pubkeys (32B each), messages (178B each)
|
|
716
|
+
*/
|
|
717
|
+
declare function buildBatchedEd25519Instruction(orders: SignedOrder[]): TransactionInstruction;
|
|
718
|
+
/**
|
|
719
|
+
* The Solana instructions sysvar public key.
|
|
720
|
+
* Pass this as `ixSysvar` to all match_* instruction accounts.
|
|
721
|
+
*/
|
|
722
|
+
declare const IX_SYSVAR: _solana_web3_js.PublicKey;
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* High-level order utilities — build, sign, serialize, verify, detect match type.
|
|
726
|
+
*
|
|
727
|
+
* These helpers layer on top of the low-level `signing.ts` primitives and
|
|
728
|
+
* provide a convenient interface for both the browser (wallet adapters) and
|
|
729
|
+
* Node.js (Keypair-based) environments.
|
|
730
|
+
*/
|
|
731
|
+
|
|
732
|
+
/**
|
|
733
|
+
* Build a fully-populated Order.
|
|
734
|
+
* Sets `signer = maker` (proxy not yet supported).
|
|
735
|
+
* `taker` defaults to new PublicKey(new Uint8Array(32)) (public order).
|
|
736
|
+
* `createdAt` defaults to current Unix timestamp.
|
|
737
|
+
* `fee` defaults to 0 (use global fee_rate_bps).
|
|
738
|
+
*/
|
|
739
|
+
declare function buildOrder(params: {
|
|
740
|
+
maker: PublicKey;
|
|
741
|
+
condition: PublicKey;
|
|
742
|
+
tokenId: number;
|
|
743
|
+
side: number;
|
|
744
|
+
makerAmount: BN;
|
|
745
|
+
takerAmount: BN;
|
|
746
|
+
nonce?: BN;
|
|
747
|
+
expiry?: BN;
|
|
748
|
+
createdAt?: BN;
|
|
749
|
+
fee?: BN;
|
|
750
|
+
taker?: PublicKey;
|
|
751
|
+
}): Order;
|
|
752
|
+
/**
|
|
753
|
+
* Sign an order with a Keypair.
|
|
754
|
+
* Uses Ed25519 (nacl.sign.detached) over the 178-byte canonical message.
|
|
755
|
+
*/
|
|
756
|
+
declare function signOrderWithKeypair(order: Order, keypair: Keypair): SignedOrder;
|
|
757
|
+
/** Return the 178-byte canonical message that gets signed for an order. */
|
|
758
|
+
declare function getOrderSignBytes(order: Order): Uint8Array;
|
|
759
|
+
/** Serialize a SignedOrder to bytes: 178 (order) + 64 (sig) = 242 bytes. */
|
|
760
|
+
declare function serializeSignedOrder(signed: SignedOrder): Uint8Array;
|
|
761
|
+
/**
|
|
762
|
+
* Deserialize 242 bytes back to a SignedOrder.
|
|
763
|
+
* Field layout mirrors `serializeOrderToBytes()` + 64-byte signature.
|
|
764
|
+
*/
|
|
765
|
+
declare function deserializeSignedOrder(bytes: Uint8Array): SignedOrder;
|
|
766
|
+
/**
|
|
767
|
+
* Verify the Ed25519 signature on a signed order.
|
|
768
|
+
* Returns true only if the signature is valid for `order.maker` (or `order.signer`).
|
|
769
|
+
*/
|
|
770
|
+
declare function verifySignedOrder(signed: SignedOrder): boolean;
|
|
771
|
+
type MatchType = "COMPLEMENTARY" | "MINT" | "MERGE";
|
|
772
|
+
/**
|
|
773
|
+
* Detect the match type from two orders (pure, no RPC).
|
|
774
|
+
*
|
|
775
|
+
* | tokenId A === B | sides | type |
|
|
776
|
+
* |-----------------|--------------|---------------|
|
|
777
|
+
* | yes | one BUY+SELL | COMPLEMENTARY |
|
|
778
|
+
* | no | both BUY | MINT |
|
|
779
|
+
* | no | both SELL | MERGE |
|
|
780
|
+
*/
|
|
781
|
+
declare function detectMatchType(a: Order | SignedOrder, b: Order | SignedOrder): MatchType;
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* SPL Token / Token-2022 approve utilities for the CLOB matching flow.
|
|
785
|
+
*
|
|
786
|
+
* Before a match instruction can transfer tokens on behalf of a user, the user
|
|
787
|
+
* must approve the CLOB config PDA as a delegate. These helpers build the
|
|
788
|
+
* approve transactions that need two signers:
|
|
789
|
+
* - signer = the token owner (user wallet — must sign the approve instruction)
|
|
790
|
+
* - payer = the BE wallet (pays transaction fees)
|
|
791
|
+
*
|
|
792
|
+
* Both must sign the resulting Transaction before sending.
|
|
793
|
+
*/
|
|
794
|
+
|
|
795
|
+
/** Maximum u64 — approve "unlimited" amount. */
|
|
796
|
+
declare const MAX_APPROVE_AMOUNT: BN;
|
|
797
|
+
/**
|
|
798
|
+
* Build a Transaction that approves the CLOB config PDA to transfer collateral
|
|
799
|
+
* (USDC) from the signer's ATA.
|
|
800
|
+
*
|
|
801
|
+
* Required signers: signer (token owner), payer (fee payer).
|
|
802
|
+
*
|
|
803
|
+
* @param collateralMint - e.g. USDC mint
|
|
804
|
+
* @param signer - token owner (must sign)
|
|
805
|
+
* @param payer - fee payer wallet pubkey
|
|
806
|
+
* @param delegate - clob config PDA (the spender)
|
|
807
|
+
* @param amount - amount to approve (defaults to MAX_APPROVE_AMOUNT)
|
|
808
|
+
*/
|
|
809
|
+
declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, amount?: BN): Transaction;
|
|
810
|
+
/**
|
|
811
|
+
* Build a Transaction that approves the CLOB config PDA to transfer BOTH
|
|
812
|
+
* YES and NO outcome tokens from the signer's ATAs (two approve instructions).
|
|
813
|
+
*
|
|
814
|
+
* Required signers: signer (token owner), payer (fee payer).
|
|
815
|
+
*/
|
|
816
|
+
declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
|
|
817
|
+
|
|
818
|
+
export { AccountNotFoundError, ClobClient, type ClobConfig, type ClobWhitelistEntry, type CollateralConfig, type CollateralVault, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DEVNET_CONFIG, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, LOCALNET_CONFIG, MAINNET_CONFIG, MAX_APPROVE_AMOUNT, MarketClient, type MatchType, NETWORK_CONFIGS, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, type ProgramIds, type Question, type QuestionMarketConfig, type QuestionResult, QuestionStatus, SEEDS, type SignedOrder, type TxResult, UnauthorizedError, XMarketError, XMarketSDK, type XMarketSDKConfig, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedEd25519Instruction, buildOrder, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, serializeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
|