@theliem/xmarket-sdk 4.0.2 → 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 +11 -4
- package/dist/index.d.ts +11 -4
- package/dist/index.js +94 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -492,7 +492,6 @@ var MarketClient = class {
|
|
|
492
492
|
}
|
|
493
493
|
/**
|
|
494
494
|
* Build createQuestionAdmin transaction (whitelist/admin path — status = Approved immediately).
|
|
495
|
-
* V2: no hookProgram param, uses TOKEN_PROGRAM_ID for YES/NO mints.
|
|
496
495
|
* @param creator - Whitelisted creator (must be in whitelist or be admin/owner)
|
|
497
496
|
* @param payer - Fee payer (pays rent; can differ from creator)
|
|
498
497
|
*/
|
|
@@ -729,7 +728,6 @@ var MarketClient = class {
|
|
|
729
728
|
}
|
|
730
729
|
/**
|
|
731
730
|
* Whitelist-only: approve presale → creates question + CTF condition + market_oracle in one tx.
|
|
732
|
-
* V2: no hookProgram param — removes Token-2022 hook from CPI call.
|
|
733
731
|
*
|
|
734
732
|
* @param presalePda the presale account
|
|
735
733
|
* @param contentHash 32-byte hash for question content
|
|
@@ -1199,7 +1197,6 @@ var CtfClient = class {
|
|
|
1199
1197
|
collateralVault: acc.collateralVault,
|
|
1200
1198
|
yesMint: acc.yesMint,
|
|
1201
1199
|
noMint: acc.noMint,
|
|
1202
|
-
hookProgram: acc.hookProgram,
|
|
1203
1200
|
authorizedClob: acc.authorizedClob,
|
|
1204
1201
|
isResolved: acc.isResolved,
|
|
1205
1202
|
resolvedAt: acc.resolvedAt?.toNumber() ?? 0,
|
|
@@ -2271,6 +2268,54 @@ ${logs.join("\n")}`);
|
|
|
2271
2268
|
const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
|
|
2272
2269
|
return { signature: sig };
|
|
2273
2270
|
}
|
|
2271
|
+
/**
|
|
2272
|
+
* Build ixs for a mixed batch: some makers COMPLEMENTARY (same tokenId as taker),
|
|
2273
|
+
* others MINT/MERGE (opposite tokenId). Packs all into a single ix array so the
|
|
2274
|
+
* caller can send them in one atomic tx.
|
|
2275
|
+
*
|
|
2276
|
+
* Supported taker configurations:
|
|
2277
|
+
* YES BUY + YES SELL makers + NO BUY makers → COMP ixs + MINT ix
|
|
2278
|
+
* YES SELL + YES BUY makers + NO SELL makers → COMP ixs + MERGE ix
|
|
2279
|
+
*/
|
|
2280
|
+
async _buildMixedMatchIxs(taker, complementaryMakers, mintMergeMakers, collateralMint, feeRecipient, operator, opts) {
|
|
2281
|
+
const t = taker.order;
|
|
2282
|
+
const SIDE_BUY = 0;
|
|
2283
|
+
const SIDE_SELL = 1;
|
|
2284
|
+
const useTakerPrice = t.side === SIDE_BUY;
|
|
2285
|
+
const compIxs = await this.buildMatchComplementaryIxs(
|
|
2286
|
+
taker,
|
|
2287
|
+
complementaryMakers,
|
|
2288
|
+
collateralMint,
|
|
2289
|
+
feeRecipient,
|
|
2290
|
+
operator,
|
|
2291
|
+
opts,
|
|
2292
|
+
useTakerPrice
|
|
2293
|
+
);
|
|
2294
|
+
const allBuy = t.side === SIDE_BUY && mintMergeMakers.every((m) => m.order.side === SIDE_BUY);
|
|
2295
|
+
const allSell = t.side === SIDE_SELL && mintMergeMakers.every((m) => m.order.side === SIDE_SELL);
|
|
2296
|
+
if (!allBuy && !allSell) {
|
|
2297
|
+
throw new InvalidParamError("MINT/MERGE makers in mixed batch must all share taker side");
|
|
2298
|
+
}
|
|
2299
|
+
const condition = t.condition;
|
|
2300
|
+
const clobConfig = this.configPda();
|
|
2301
|
+
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2302
|
+
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
2303
|
+
const clobYesAta = getAssociatedTokenAddressSync(yesMint, clobConfig, true, TOKEN_PROGRAM_ID);
|
|
2304
|
+
const clobNoAta = getAssociatedTokenAddressSync(noMint, clobConfig, true, TOKEN_PROGRAM_ID);
|
|
2305
|
+
await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
|
|
2306
|
+
let mmIxs;
|
|
2307
|
+
if (t.tokenId === 1) {
|
|
2308
|
+
const ix = allBuy ? await this._buildMintIx(taker, mintMergeMakers, collateralMint, operator, this.walletPubkey) : await this._buildMergeIx(taker, mintMergeMakers, collateralMint, operator, this.walletPubkey, opts);
|
|
2309
|
+
mmIxs = [ix];
|
|
2310
|
+
} else {
|
|
2311
|
+
mmIxs = [];
|
|
2312
|
+
for (const yesMaker of mintMergeMakers) {
|
|
2313
|
+
const ix = allBuy ? await this._buildMintIx(yesMaker, [taker], collateralMint, operator, this.walletPubkey) : await this._buildMergeIx(yesMaker, [taker], collateralMint, operator, this.walletPubkey, opts);
|
|
2314
|
+
mmIxs.push(ix);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
return [...compIxs, ...mmIxs];
|
|
2318
|
+
}
|
|
2274
2319
|
/**
|
|
2275
2320
|
* Auto-detect match type and execute 2-phase:
|
|
2276
2321
|
* Phase 1 — register all orders (taker + makers) on-chain in parallel.
|
|
@@ -2299,9 +2344,28 @@ ${logs.join("\n")}`);
|
|
|
2299
2344
|
makers
|
|
2300
2345
|
);
|
|
2301
2346
|
const t = taker.order;
|
|
2302
|
-
const m0 = makers[0].order;
|
|
2303
2347
|
const SIDE_BUY = 0;
|
|
2304
2348
|
const SIDE_SELL = 1;
|
|
2349
|
+
const complementaryMakers = makers.filter((m) => m.order.tokenId === t.tokenId);
|
|
2350
|
+
const mintMergeMakers = makers.filter((m) => m.order.tokenId !== t.tokenId);
|
|
2351
|
+
if (complementaryMakers.length > 0 && mintMergeMakers.length > 0) {
|
|
2352
|
+
await Promise.all([
|
|
2353
|
+
this.registerOrderIfNeeded(taker),
|
|
2354
|
+
...makers.map((m) => this.registerOrderIfNeeded(m))
|
|
2355
|
+
]);
|
|
2356
|
+
const ixs = await this._buildMixedMatchIxs(
|
|
2357
|
+
taker,
|
|
2358
|
+
complementaryMakers,
|
|
2359
|
+
mintMergeMakers,
|
|
2360
|
+
collateralMint,
|
|
2361
|
+
feeRecipient,
|
|
2362
|
+
operatorWallet.publicKey,
|
|
2363
|
+
opts
|
|
2364
|
+
);
|
|
2365
|
+
const sig = await this.sendMatchTx(ixs, alt, operatorWallet);
|
|
2366
|
+
return { signature: sig };
|
|
2367
|
+
}
|
|
2368
|
+
const m0 = makers[0].order;
|
|
2305
2369
|
if (t.tokenId === m0.tokenId) {
|
|
2306
2370
|
let buySignedOrder, sellCandidates;
|
|
2307
2371
|
if (t.side === SIDE_BUY && makers.every((m) => m.order.side === SIDE_SELL)) {
|
|
@@ -2402,9 +2466,34 @@ ${logs.join("\n")}`);
|
|
|
2402
2466
|
const feeRecipient = cfg.feeRecipient;
|
|
2403
2467
|
const alt = await this.ensureAlt(taker.order.condition, collateralMint, taker, makers);
|
|
2404
2468
|
const t = taker.order;
|
|
2405
|
-
const m0 = makers[0].order;
|
|
2406
2469
|
const SIDE_BUY = 0;
|
|
2407
2470
|
const SIDE_SELL = 1;
|
|
2471
|
+
const complementaryMakers = makers.filter((m) => m.order.tokenId === t.tokenId);
|
|
2472
|
+
const mintMergeMakers = makers.filter((m) => m.order.tokenId !== t.tokenId);
|
|
2473
|
+
if (complementaryMakers.length > 0 && mintMergeMakers.length > 0) {
|
|
2474
|
+
await Promise.all([
|
|
2475
|
+
this.registerOrderIfNeeded(taker),
|
|
2476
|
+
...makers.map((m) => this.registerOrderIfNeeded(m))
|
|
2477
|
+
]);
|
|
2478
|
+
const oracleVaultInitIx2 = await this.buildInitOracleVaultIfNeeded(
|
|
2479
|
+
t.condition,
|
|
2480
|
+
collateralMint,
|
|
2481
|
+
t.fee,
|
|
2482
|
+
payer
|
|
2483
|
+
);
|
|
2484
|
+
const preIxs2 = oracleVaultInitIx2 ? [oracleVaultInitIx2] : [];
|
|
2485
|
+
const ixs2 = await this._buildMixedMatchIxs(
|
|
2486
|
+
taker,
|
|
2487
|
+
complementaryMakers,
|
|
2488
|
+
mintMergeMakers,
|
|
2489
|
+
collateralMint,
|
|
2490
|
+
feeRecipient,
|
|
2491
|
+
operator,
|
|
2492
|
+
opts
|
|
2493
|
+
);
|
|
2494
|
+
return this._buildUnsignedVtx([...preIxs2, ...ixs2], alt, payer);
|
|
2495
|
+
}
|
|
2496
|
+
const m0 = makers[0].order;
|
|
2408
2497
|
const oracleVaultInitIx = await this.buildInitOracleVaultIfNeeded(
|
|
2409
2498
|
t.condition,
|
|
2410
2499
|
collateralMint,
|