@theliem/xmarket-sdk 4.0.1 → 4.0.3
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 +12 -5
- package/dist/index.d.ts +12 -5
- package/dist/index.js +95 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -64,7 +64,6 @@ interface Condition {
|
|
|
64
64
|
collateralVault: PublicKey;
|
|
65
65
|
yesMint: PublicKey;
|
|
66
66
|
noMint: PublicKey;
|
|
67
|
-
hookProgram: PublicKey;
|
|
68
67
|
authorizedClob: PublicKey;
|
|
69
68
|
isResolved: boolean;
|
|
70
69
|
resolvedAt: number;
|
|
@@ -138,7 +137,7 @@ interface CtfConfig {
|
|
|
138
137
|
bump: number;
|
|
139
138
|
}
|
|
140
139
|
interface ClobConfig {
|
|
141
|
-
|
|
140
|
+
admin: PublicKey;
|
|
142
141
|
operators: PublicKey[];
|
|
143
142
|
operatorsLen: number;
|
|
144
143
|
feeRecipient: PublicKey;
|
|
@@ -391,11 +390,10 @@ declare class MarketClient {
|
|
|
391
390
|
initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
392
391
|
/**
|
|
393
392
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
394
|
-
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
395
393
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
396
394
|
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
397
395
|
*/
|
|
398
|
-
createQuestionAdmin(params:
|
|
396
|
+
createQuestionAdmin(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
399
397
|
tx: Transaction;
|
|
400
398
|
questionPda: PublicKey;
|
|
401
399
|
conditionPda: PublicKey;
|
|
@@ -452,7 +450,6 @@ declare class MarketClient {
|
|
|
452
450
|
}>;
|
|
453
451
|
/**
|
|
454
452
|
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
455
|
-
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
456
453
|
*
|
|
457
454
|
* @param presalePda the presale account
|
|
458
455
|
* @param contentHash 32-byte hash for question content
|
|
@@ -727,6 +724,16 @@ declare class ClobClient {
|
|
|
727
724
|
*/
|
|
728
725
|
private _buildMergeIx;
|
|
729
726
|
private matchMergeOrders;
|
|
727
|
+
/**
|
|
728
|
+
* Build ixs for a mixed batch: some makers COMPLEMENTARY (same tokenId as taker),
|
|
729
|
+
* others MINT/MERGE (opposite tokenId). Packs all into a single ix array so the
|
|
730
|
+
* caller can send them in one atomic tx.
|
|
731
|
+
*
|
|
732
|
+
* Supported taker configurations:
|
|
733
|
+
* YES BUY + YES SELL makers + NO BUY makers → COMP ixs + MINT ix
|
|
734
|
+
* YES SELL + YES BUY makers + NO SELL makers → COMP ixs + MERGE ix
|
|
735
|
+
*/
|
|
736
|
+
private _buildMixedMatchIxs;
|
|
730
737
|
/**
|
|
731
738
|
* Auto-detect match type and execute 2-phase:
|
|
732
739
|
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
package/dist/index.d.ts
CHANGED
|
@@ -64,7 +64,6 @@ interface Condition {
|
|
|
64
64
|
collateralVault: PublicKey;
|
|
65
65
|
yesMint: PublicKey;
|
|
66
66
|
noMint: PublicKey;
|
|
67
|
-
hookProgram: PublicKey;
|
|
68
67
|
authorizedClob: PublicKey;
|
|
69
68
|
isResolved: boolean;
|
|
70
69
|
resolvedAt: number;
|
|
@@ -138,7 +137,7 @@ interface CtfConfig {
|
|
|
138
137
|
bump: number;
|
|
139
138
|
}
|
|
140
139
|
interface ClobConfig {
|
|
141
|
-
|
|
140
|
+
admin: PublicKey;
|
|
142
141
|
operators: PublicKey[];
|
|
143
142
|
operatorsLen: number;
|
|
144
143
|
feeRecipient: PublicKey;
|
|
@@ -391,11 +390,10 @@ declare class MarketClient {
|
|
|
391
390
|
initialize(admin: PublicKey, oracle: PublicKey, owner?: PublicKey): Promise<Transaction>;
|
|
392
391
|
/**
|
|
393
392
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
394
|
-
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
395
393
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
396
394
|
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
397
395
|
*/
|
|
398
|
-
createQuestionAdmin(params:
|
|
396
|
+
createQuestionAdmin(params: CreateQuestionParams, oracle: PublicKey, creator?: PublicKey, payer?: PublicKey): Promise<{
|
|
399
397
|
tx: Transaction;
|
|
400
398
|
questionPda: PublicKey;
|
|
401
399
|
conditionPda: PublicKey;
|
|
@@ -452,7 +450,6 @@ declare class MarketClient {
|
|
|
452
450
|
}>;
|
|
453
451
|
/**
|
|
454
452
|
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
455
|
-
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
456
453
|
*
|
|
457
454
|
* @param presalePda the presale account
|
|
458
455
|
* @param contentHash 32-byte hash for question content
|
|
@@ -727,6 +724,16 @@ declare class ClobClient {
|
|
|
727
724
|
*/
|
|
728
725
|
private _buildMergeIx;
|
|
729
726
|
private matchMergeOrders;
|
|
727
|
+
/**
|
|
728
|
+
* Build ixs for a mixed batch: some makers COMPLEMENTARY (same tokenId as taker),
|
|
729
|
+
* others MINT/MERGE (opposite tokenId). Packs all into a single ix array so the
|
|
730
|
+
* caller can send them in one atomic tx.
|
|
731
|
+
*
|
|
732
|
+
* Supported taker configurations:
|
|
733
|
+
* YES BUY + YES SELL makers + NO BUY makers → COMP ixs + MINT ix
|
|
734
|
+
* YES SELL + YES BUY makers + NO SELL makers → COMP ixs + MERGE ix
|
|
735
|
+
*/
|
|
736
|
+
private _buildMixedMatchIxs;
|
|
730
737
|
/**
|
|
731
738
|
* Auto-detect match type and execute 2-phase:
|
|
732
739
|
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
package/dist/index.js
CHANGED
|
@@ -518,7 +518,6 @@ var MarketClient = class {
|
|
|
518
518
|
}
|
|
519
519
|
/**
|
|
520
520
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
521
|
-
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
522
521
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
523
522
|
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
524
523
|
*/
|
|
@@ -755,7 +754,6 @@ var MarketClient = class {
|
|
|
755
754
|
}
|
|
756
755
|
/**
|
|
757
756
|
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
758
|
-
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
759
757
|
*
|
|
760
758
|
* @param presalePda the presale account
|
|
761
759
|
* @param contentHash 32-byte hash for question content
|
|
@@ -1225,7 +1223,6 @@ var CtfClient = class {
|
|
|
1225
1223
|
collateralVault: acc.collateralVault,
|
|
1226
1224
|
yesMint: acc.yesMint,
|
|
1227
1225
|
noMint: acc.noMint,
|
|
1228
|
-
hookProgram: acc.hookProgram,
|
|
1229
1226
|
authorizedClob: acc.authorizedClob,
|
|
1230
1227
|
isResolved: acc.isResolved,
|
|
1231
1228
|
resolvedAt: acc.resolvedAt?.toNumber() ?? 0,
|
|
@@ -2297,6 +2294,54 @@ ${logs.join("\n")}`);
|
|
|
2297
2294
|
const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
|
|
2298
2295
|
return { signature: sig };
|
|
2299
2296
|
}
|
|
2297
|
+
/**
|
|
2298
|
+
* Build ixs for a mixed batch: some makers COMPLEMENTARY (same tokenId as taker),
|
|
2299
|
+
* others MINT/MERGE (opposite tokenId). Packs all into a single ix array so the
|
|
2300
|
+
* caller can send them in one atomic tx.
|
|
2301
|
+
*
|
|
2302
|
+
* Supported taker configurations:
|
|
2303
|
+
* YES BUY + YES SELL makers + NO BUY makers → COMP ixs + MINT ix
|
|
2304
|
+
* YES SELL + YES BUY makers + NO SELL makers → COMP ixs + MERGE ix
|
|
2305
|
+
*/
|
|
2306
|
+
async _buildMixedMatchIxs(taker, complementaryMakers, mintMergeMakers, collateralMint, feeRecipient, operator, opts) {
|
|
2307
|
+
const t = taker.order;
|
|
2308
|
+
const SIDE_BUY = 0;
|
|
2309
|
+
const SIDE_SELL = 1;
|
|
2310
|
+
const useTakerPrice = t.side === SIDE_BUY;
|
|
2311
|
+
const compIxs = await this.buildMatchComplementaryIxs(
|
|
2312
|
+
taker,
|
|
2313
|
+
complementaryMakers,
|
|
2314
|
+
collateralMint,
|
|
2315
|
+
feeRecipient,
|
|
2316
|
+
operator,
|
|
2317
|
+
opts,
|
|
2318
|
+
useTakerPrice
|
|
2319
|
+
);
|
|
2320
|
+
const allBuy = t.side === SIDE_BUY && mintMergeMakers.every((m) => m.order.side === SIDE_BUY);
|
|
2321
|
+
const allSell = t.side === SIDE_SELL && mintMergeMakers.every((m) => m.order.side === SIDE_SELL);
|
|
2322
|
+
if (!allBuy && !allSell) {
|
|
2323
|
+
throw new InvalidParamError("MINT/MERGE makers in mixed batch must all share taker side");
|
|
2324
|
+
}
|
|
2325
|
+
const condition = t.condition;
|
|
2326
|
+
const clobConfig = this.configPda();
|
|
2327
|
+
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2328
|
+
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
2329
|
+
const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfig, true, splToken.TOKEN_PROGRAM_ID);
|
|
2330
|
+
const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfig, true, splToken.TOKEN_PROGRAM_ID);
|
|
2331
|
+
await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
|
|
2332
|
+
let mmIxs;
|
|
2333
|
+
if (t.tokenId === 1) {
|
|
2334
|
+
const ix = allBuy ? await this._buildMintIx(taker, mintMergeMakers, collateralMint, operator, this.walletPubkey) : await this._buildMergeIx(taker, mintMergeMakers, collateralMint, operator, this.walletPubkey, opts);
|
|
2335
|
+
mmIxs = [ix];
|
|
2336
|
+
} else {
|
|
2337
|
+
mmIxs = [];
|
|
2338
|
+
for (const yesMaker of mintMergeMakers) {
|
|
2339
|
+
const ix = allBuy ? await this._buildMintIx(yesMaker, [taker], collateralMint, operator, this.walletPubkey) : await this._buildMergeIx(yesMaker, [taker], collateralMint, operator, this.walletPubkey, opts);
|
|
2340
|
+
mmIxs.push(ix);
|
|
2341
|
+
}
|
|
2342
|
+
}
|
|
2343
|
+
return [...compIxs, ...mmIxs];
|
|
2344
|
+
}
|
|
2300
2345
|
/**
|
|
2301
2346
|
* Auto-detect match type and execute 2-phase:
|
|
2302
2347
|
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
|
@@ -2325,9 +2370,28 @@ ${logs.join("\n")}`);
|
|
|
2325
2370
|
makers
|
|
2326
2371
|
);
|
|
2327
2372
|
const t = taker.order;
|
|
2328
|
-
const m0 = makers[0].order;
|
|
2329
2373
|
const SIDE_BUY = 0;
|
|
2330
2374
|
const SIDE_SELL = 1;
|
|
2375
|
+
const complementaryMakers = makers.filter((m) => m.order.tokenId === t.tokenId);
|
|
2376
|
+
const mintMergeMakers = makers.filter((m) => m.order.tokenId !== t.tokenId);
|
|
2377
|
+
if (complementaryMakers.length > 0 && mintMergeMakers.length > 0) {
|
|
2378
|
+
await Promise.all([
|
|
2379
|
+
this.registerOrderIfNeeded(taker),
|
|
2380
|
+
...makers.map((m) => this.registerOrderIfNeeded(m))
|
|
2381
|
+
]);
|
|
2382
|
+
const ixs = await this._buildMixedMatchIxs(
|
|
2383
|
+
taker,
|
|
2384
|
+
complementaryMakers,
|
|
2385
|
+
mintMergeMakers,
|
|
2386
|
+
collateralMint,
|
|
2387
|
+
feeRecipient,
|
|
2388
|
+
operatorWallet.publicKey,
|
|
2389
|
+
opts
|
|
2390
|
+
);
|
|
2391
|
+
const sig = await this.sendMatchTx(ixs, alt, operatorWallet);
|
|
2392
|
+
return { signature: sig };
|
|
2393
|
+
}
|
|
2394
|
+
const m0 = makers[0].order;
|
|
2331
2395
|
if (t.tokenId === m0.tokenId) {
|
|
2332
2396
|
let buySignedOrder, sellCandidates;
|
|
2333
2397
|
if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
|
|
@@ -2428,9 +2492,34 @@ ${logs.join("\n")}`);
|
|
|
2428
2492
|
const feeRecipient = cfg.feeRecipient;
|
|
2429
2493
|
const alt = await this.ensureAlt(taker.order.condition, collateralMint, taker, makers);
|
|
2430
2494
|
const t = taker.order;
|
|
2431
|
-
const m0 = makers[0].order;
|
|
2432
2495
|
const SIDE_BUY = 0;
|
|
2433
2496
|
const SIDE_SELL = 1;
|
|
2497
|
+
const complementaryMakers = makers.filter((m) => m.order.tokenId === t.tokenId);
|
|
2498
|
+
const mintMergeMakers = makers.filter((m) => m.order.tokenId !== t.tokenId);
|
|
2499
|
+
if (complementaryMakers.length > 0 && mintMergeMakers.length > 0) {
|
|
2500
|
+
await Promise.all([
|
|
2501
|
+
this.registerOrderIfNeeded(taker),
|
|
2502
|
+
...makers.map((m) => this.registerOrderIfNeeded(m))
|
|
2503
|
+
]);
|
|
2504
|
+
const oracleVaultInitIx2 = await this.buildInitOracleVaultIfNeeded(
|
|
2505
|
+
t.condition,
|
|
2506
|
+
collateralMint,
|
|
2507
|
+
t.fee,
|
|
2508
|
+
payer
|
|
2509
|
+
);
|
|
2510
|
+
const preIxs2 = oracleVaultInitIx2 ? [oracleVaultInitIx2] : [];
|
|
2511
|
+
const ixs2 = await this._buildMixedMatchIxs(
|
|
2512
|
+
taker,
|
|
2513
|
+
complementaryMakers,
|
|
2514
|
+
mintMergeMakers,
|
|
2515
|
+
collateralMint,
|
|
2516
|
+
feeRecipient,
|
|
2517
|
+
operator,
|
|
2518
|
+
opts
|
|
2519
|
+
);
|
|
2520
|
+
return this._buildUnsignedVtx([...preIxs2, ...ixs2], alt, payer);
|
|
2521
|
+
}
|
|
2522
|
+
const m0 = makers[0].order;
|
|
2434
2523
|
const oracleVaultInitIx = await this.buildInitOracleVaultIfNeeded(
|
|
2435
2524
|
t.condition,
|
|
2436
2525
|
collateralMint,
|
|
@@ -2936,7 +3025,7 @@ ${logs.join("\n")}`);
|
|
|
2936
3025
|
try {
|
|
2937
3026
|
const acc = await this.program.account.clobConfig.fetch(this.configPda());
|
|
2938
3027
|
return {
|
|
2939
|
-
|
|
3028
|
+
admin: acc.admin,
|
|
2940
3029
|
operators: acc.operators,
|
|
2941
3030
|
operatorsLen: acc.operatorsLen,
|
|
2942
3031
|
feeRecipient: acc.feeRecipient,
|