@theliem/xmarket-sdk 3.21.0 → 3.22.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 +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +77 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +77 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -838,7 +838,13 @@ declare class ClobClient {
|
|
|
838
838
|
*/
|
|
839
839
|
buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
|
|
840
840
|
marketOracleVault?: PublicKey;
|
|
841
|
+
lookupTable?: AddressLookupTableAccount;
|
|
841
842
|
}): Promise<VersionedTransaction>;
|
|
843
|
+
/**
|
|
844
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
845
|
+
* Use before buildBatchCollectRedeemEarlyTx when no prior buildMatchOrdersTx ran in this session.
|
|
846
|
+
*/
|
|
847
|
+
buildAltForCondition(condition: PublicKey, _payer: PublicKey, collateralMint?: PublicKey): Promise<AddressLookupTableAccount>;
|
|
842
848
|
fetchConfig(): Promise<ClobConfig | null>;
|
|
843
849
|
fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
|
|
844
850
|
fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
|
package/dist/index.d.ts
CHANGED
|
@@ -838,7 +838,13 @@ declare class ClobClient {
|
|
|
838
838
|
*/
|
|
839
839
|
buildBatchCollectRedeemEarlyTx(signedOrders: SignedCollectFeeOrder[], condition: PublicKey, outcomeIndex: 0 | 1, operator: PublicKey, payer: PublicKey, opts?: {
|
|
840
840
|
marketOracleVault?: PublicKey;
|
|
841
|
+
lookupTable?: AddressLookupTableAccount;
|
|
841
842
|
}): Promise<VersionedTransaction>;
|
|
843
|
+
/**
|
|
844
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
845
|
+
* Use before buildBatchCollectRedeemEarlyTx when no prior buildMatchOrdersTx ran in this session.
|
|
846
|
+
*/
|
|
847
|
+
buildAltForCondition(condition: PublicKey, _payer: PublicKey, collateralMint?: PublicKey): Promise<AddressLookupTableAccount>;
|
|
842
848
|
fetchConfig(): Promise<ClobConfig | null>;
|
|
843
849
|
fetchOrderStatus(maker: PublicKey, nonce: anchor.BN): Promise<OrderStatus | null>;
|
|
844
850
|
fetchOrderRecord(maker: PublicKey, nonce: anchor.BN): Promise<{
|
package/dist/index.js
CHANGED
|
@@ -2630,8 +2630,83 @@ ${logs.join("\n")}`);
|
|
|
2630
2630
|
token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
|
|
2631
2631
|
systemProgram: web3_js.SystemProgram.programId
|
|
2632
2632
|
}).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
|
|
2633
|
-
const
|
|
2634
|
-
return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx],
|
|
2633
|
+
const alt = opts?.lookupTable ?? this._altCache.get(condition.toBase58()) ?? await this.buildAltForCondition(condition, payer, collateralMint);
|
|
2634
|
+
return this._buildUnsignedVtx([...hookInitIxs, ed25519Ix, collectIx], alt, payer);
|
|
2635
|
+
}
|
|
2636
|
+
/**
|
|
2637
|
+
* Build ALT with static accounts for a condition — no order-specific PDAs needed.
|
|
2638
|
+
* Use before buildBatchCollectRedeemEarlyTx when no prior buildMatchOrdersTx ran in this session.
|
|
2639
|
+
*/
|
|
2640
|
+
async buildAltForCondition(condition, _payer, collateralMint) {
|
|
2641
|
+
const cacheKey = condition.toBase58();
|
|
2642
|
+
if (this._altCache.has(cacheKey)) return this._altCache.get(cacheKey);
|
|
2643
|
+
const mint = collateralMint ?? this.networkConfig.defaultCollateral.mint;
|
|
2644
|
+
const payer = this.walletPubkey;
|
|
2645
|
+
const { connection } = this.provider;
|
|
2646
|
+
const clobConfigPda = this.configPda();
|
|
2647
|
+
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2648
|
+
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
2649
|
+
const [extraAccountMeta] = PDA.extraAccountMetaList(yesMint, this.programIds);
|
|
2650
|
+
const [hookConfig] = PDA.hookConfig(this.programIds);
|
|
2651
|
+
const [collateralVault] = PDA.collateralVault(mint, this.programIds);
|
|
2652
|
+
const [vaultTokenAccount] = PDA.vaultToken(mint, this.programIds);
|
|
2653
|
+
const clobYesAta = splToken.getAssociatedTokenAddressSync(yesMint, clobConfigPda, true, splToken.TOKEN_2022_PROGRAM_ID);
|
|
2654
|
+
const clobNoAta = splToken.getAssociatedTokenAddressSync(noMint, clobConfigPda, true, splToken.TOKEN_2022_PROGRAM_ID);
|
|
2655
|
+
const feeRecipientAddr = (await this.fetchConfig())?.feeRecipient;
|
|
2656
|
+
const addresses = [
|
|
2657
|
+
web3_js.Ed25519Program.programId,
|
|
2658
|
+
this.programIds.clobExchange,
|
|
2659
|
+
this.programIds.conditionalTokens,
|
|
2660
|
+
this.programIds.hook,
|
|
2661
|
+
splToken.TOKEN_PROGRAM_ID,
|
|
2662
|
+
splToken.TOKEN_2022_PROGRAM_ID,
|
|
2663
|
+
web3_js.SystemProgram.programId,
|
|
2664
|
+
web3_js.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2665
|
+
clobConfigPda,
|
|
2666
|
+
hookConfig,
|
|
2667
|
+
condition,
|
|
2668
|
+
yesMint,
|
|
2669
|
+
noMint,
|
|
2670
|
+
extraAccountMeta,
|
|
2671
|
+
collateralVault,
|
|
2672
|
+
vaultTokenAccount,
|
|
2673
|
+
clobYesAta,
|
|
2674
|
+
clobNoAta
|
|
2675
|
+
];
|
|
2676
|
+
if (feeRecipientAddr) addresses.push(feeRecipientAddr);
|
|
2677
|
+
if (this.feeConfigOwner && this.programIds.feeManagement) {
|
|
2678
|
+
const companyAddr = await this.companyAddress();
|
|
2679
|
+
const refVault = await this.referralVault();
|
|
2680
|
+
addresses.push(this.programIds.feeManagement);
|
|
2681
|
+
addresses.push(PDA.feeConfig(this.feeConfigOwner, this.programIds)[0]);
|
|
2682
|
+
addresses.push(PDA.marketFeeOverride(condition, this.programIds)[0]);
|
|
2683
|
+
if (companyAddr) addresses.push(splToken.getAssociatedTokenAddressSync(mint, companyAddr));
|
|
2684
|
+
if (refVault) addresses.push(refVault);
|
|
2685
|
+
const oracleVault = await this.getMarketOracleVault(condition, mint) ?? payer;
|
|
2686
|
+
addresses.push(oracleVault);
|
|
2687
|
+
}
|
|
2688
|
+
const slot = await connection.getSlot("finalized");
|
|
2689
|
+
const [createIx, altAddress] = web3_js.AddressLookupTableProgram.createLookupTable(
|
|
2690
|
+
{ authority: payer, payer, recentSlot: slot }
|
|
2691
|
+
);
|
|
2692
|
+
const BATCH = 30;
|
|
2693
|
+
const extendIxs = [];
|
|
2694
|
+
for (let i = 0; i < addresses.length; i += BATCH) {
|
|
2695
|
+
extendIxs.push(web3_js.AddressLookupTableProgram.extendLookupTable(
|
|
2696
|
+
{ payer, authority: payer, lookupTable: altAddress, addresses: addresses.slice(i, i + BATCH) }
|
|
2697
|
+
));
|
|
2698
|
+
}
|
|
2699
|
+
await this._sendLegacyTx([createIx, extendIxs[0]]);
|
|
2700
|
+
for (let i = 1; i < extendIxs.length; i++) await this._sendLegacyTx([extendIxs[i]]);
|
|
2701
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
2702
|
+
await new Promise((r) => setTimeout(r, 1e3));
|
|
2703
|
+
const res = await connection.getAddressLookupTable(altAddress);
|
|
2704
|
+
if (res.value && res.value.state.addresses.length === addresses.length) {
|
|
2705
|
+
this._altCache.set(cacheKey, res.value);
|
|
2706
|
+
return res.value;
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
throw new Error(`ALT ${altAddress.toBase58()} not active after 30s`);
|
|
2635
2710
|
}
|
|
2636
2711
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
2637
2712
|
async fetchConfig() {
|