@theliem/xmarket-sdk 3.27.0 → 3.28.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 +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +93 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +92 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as anchor6 from '@coral-xyz/anchor';
|
|
2
2
|
import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, SYSVAR_RENT_PUBKEY, ComputeBudgetProgram, TransactionMessage, VersionedTransaction, Transaction, TransactionInstruction, Ed25519Program, AddressLookupTableProgram, Connection } from '@solana/web3.js';
|
|
3
3
|
import { createHash } from 'crypto';
|
|
4
4
|
import { TOKEN_2022_PROGRAM_ID, getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, createAssociatedTokenAccountIdempotentInstruction, createApproveInstruction } from '@solana/spl-token';
|
|
@@ -350,7 +350,7 @@ var OracleClient = class {
|
|
|
350
350
|
return this.program.methods.resolveQuestion(
|
|
351
351
|
Array.from(questionId),
|
|
352
352
|
outcomeCount,
|
|
353
|
-
payoutNumerators.map((n) => new
|
|
353
|
+
payoutNumerators.map((n) => new anchor6.BN(n))
|
|
354
354
|
).accounts({
|
|
355
355
|
reporter,
|
|
356
356
|
oracleConfig,
|
|
@@ -639,7 +639,7 @@ var MarketClient = class {
|
|
|
639
639
|
contentHash: Array.from(contentHash),
|
|
640
640
|
hookProgram: params.hookProgram,
|
|
641
641
|
authorizedClob: params.authorizedClob,
|
|
642
|
-
expirationTime: new
|
|
642
|
+
expirationTime: new anchor6.BN(params.expirationTime)
|
|
643
643
|
}).accounts({
|
|
644
644
|
creator,
|
|
645
645
|
payer,
|
|
@@ -728,7 +728,7 @@ var MarketClient = class {
|
|
|
728
728
|
}).transaction();
|
|
729
729
|
}
|
|
730
730
|
async bumpPresaleCount(count, authority) {
|
|
731
|
-
return this.program.methods.bumpPresaleCount(new
|
|
731
|
+
return this.program.methods.bumpPresaleCount(new anchor6.BN(count)).accounts({ authority, config: this.configPda }).transaction();
|
|
732
732
|
}
|
|
733
733
|
// ─── Queries ─────────────────────────────────────────────────────────────────
|
|
734
734
|
async fetchConfig() {
|
|
@@ -1236,7 +1236,7 @@ var CtfClient = class {
|
|
|
1236
1236
|
* Bypasses QuestionMarket — only for oracle-owned conditions.
|
|
1237
1237
|
*/
|
|
1238
1238
|
async reportPayouts(condition, payoutNumerators) {
|
|
1239
|
-
const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new
|
|
1239
|
+
const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor6.BN(n))).accounts({
|
|
1240
1240
|
oracle: this.walletPubkey,
|
|
1241
1241
|
condition
|
|
1242
1242
|
}).rpc();
|
|
@@ -2081,7 +2081,7 @@ ${logs.join("\n")}`);
|
|
|
2081
2081
|
const tokenId = takerSigned.order.tokenId;
|
|
2082
2082
|
const taker = takerSigned.order.maker;
|
|
2083
2083
|
const takerNonce = takerSigned.order.nonce;
|
|
2084
|
-
const fillAmount = opts?.fillAmount ?? new
|
|
2084
|
+
const fillAmount = opts?.fillAmount ?? new anchor6.BN("18446744073709551615");
|
|
2085
2085
|
const [outcomeMint] = tokenId === 1 ? PDA.yesMint(condition, this.programIds) : PDA.noMint(condition, this.programIds);
|
|
2086
2086
|
const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
|
|
2087
2087
|
const takerCollateral = getAssociatedTokenAddressSync(collateralMint, taker);
|
|
@@ -2222,7 +2222,7 @@ ${logs.join("\n")}`);
|
|
|
2222
2222
|
const condition = yesSigned.order.condition;
|
|
2223
2223
|
const taker = yesSigned.order.maker;
|
|
2224
2224
|
const takerNonce = yesSigned.order.nonce;
|
|
2225
|
-
const fillAmount = new
|
|
2225
|
+
const fillAmount = new anchor6.BN("18446744073709551615");
|
|
2226
2226
|
const clobConfig = this.configPda();
|
|
2227
2227
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2228
2228
|
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
@@ -2326,7 +2326,7 @@ ${logs.join("\n")}`);
|
|
|
2326
2326
|
const condition = yesSigned.order.condition;
|
|
2327
2327
|
const sellerYes = yesSigned.order.maker;
|
|
2328
2328
|
const takerNonce = yesSigned.order.nonce;
|
|
2329
|
-
const fillAmount = new
|
|
2329
|
+
const fillAmount = new anchor6.BN("18446744073709551615");
|
|
2330
2330
|
const clobConfig = this.configPda();
|
|
2331
2331
|
const [yesMint] = PDA.yesMint(condition, this.programIds);
|
|
2332
2332
|
const [noMint] = PDA.noMint(condition, this.programIds);
|
|
@@ -2793,9 +2793,9 @@ ${logs.join("\n")}`);
|
|
|
2793
2793
|
ixSysvar: IX_SYSVAR,
|
|
2794
2794
|
orderSigner: order.user,
|
|
2795
2795
|
redeemFeeOrderRecord,
|
|
2796
|
-
systemProgram:
|
|
2796
|
+
systemProgram: anchor6.web3.SystemProgram.programId
|
|
2797
2797
|
}).instruction();
|
|
2798
|
-
const tx = new
|
|
2798
|
+
const tx = new anchor6.web3.Transaction();
|
|
2799
2799
|
tx.add(ed25519Ix, registerIx);
|
|
2800
2800
|
return tx;
|
|
2801
2801
|
}
|
|
@@ -2898,7 +2898,7 @@ ${logs.join("\n")}`);
|
|
|
2898
2898
|
conditionalTokensProgram: this.programIds.conditionalTokens,
|
|
2899
2899
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
2900
2900
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
2901
|
-
systemProgram:
|
|
2901
|
+
systemProgram: anchor6.web3.SystemProgram.programId
|
|
2902
2902
|
}).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
|
|
2903
2903
|
const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
|
|
2904
2904
|
return this._buildUnsignedVtx([...hookInitIxs, redeemIx], alt, payer);
|
|
@@ -3000,7 +3000,7 @@ ${logs.join("\n")}`);
|
|
|
3000
3000
|
conditionalTokensProgram: this.programIds.conditionalTokens,
|
|
3001
3001
|
tokenProgram: TOKEN_PROGRAM_ID,
|
|
3002
3002
|
token2022Program: TOKEN_2022_PROGRAM_ID,
|
|
3003
|
-
systemProgram:
|
|
3003
|
+
systemProgram: anchor6.web3.SystemProgram.programId
|
|
3004
3004
|
}).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
|
|
3005
3005
|
const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
|
|
3006
3006
|
return this._buildUnsignedVtx([...hookInitIxs, mergeIx], alt, payer);
|
|
@@ -3571,6 +3571,73 @@ var MarketOracleClient = class {
|
|
|
3571
3571
|
const bal = await this.program.provider.connection.getTokenAccountBalance(vault);
|
|
3572
3572
|
return bal.value.uiAmount ?? 0;
|
|
3573
3573
|
}
|
|
3574
|
+
/**
|
|
3575
|
+
* Estimate the USDS share a user would receive if they called claimFeesShare now.
|
|
3576
|
+
* Works both before and after fees_distributed — no extra params needed.
|
|
3577
|
+
*
|
|
3578
|
+
* When fees not yet distributed, auto-resolves qtMint via:
|
|
3579
|
+
* oracle.question (questionPda) → raw account bytes[8..40] = presalePda
|
|
3580
|
+
* → PDA.qtMint(presalePda) → qtMint
|
|
3581
|
+
*
|
|
3582
|
+
* Formula mirrors on-chain claim_fees_share_handler:
|
|
3583
|
+
* effective_total = vault_balance + oracle.total_claimed
|
|
3584
|
+
* share = user_qt_balance * effective_total / oracle.qt_total_supply
|
|
3585
|
+
*/
|
|
3586
|
+
async estimateFeesShare(marketOraclePda, user) {
|
|
3587
|
+
const { connection } = this.provider;
|
|
3588
|
+
const [oracle, claimRecord] = await Promise.all([
|
|
3589
|
+
this.fetchMarketOracle(marketOraclePda),
|
|
3590
|
+
this.fetchUserClaimRecord(marketOraclePda, user)
|
|
3591
|
+
]);
|
|
3592
|
+
if (!oracle) return null;
|
|
3593
|
+
const hasClaimed = claimRecord?.hasClaimed ?? false;
|
|
3594
|
+
const vaultAta = getAssociatedTokenAddressSync(oracle.currencyMint, marketOraclePda, true);
|
|
3595
|
+
const needsQtMintResolve = !oracle.feesDistributed || oracle.qtMint.equals(PublicKey.default);
|
|
3596
|
+
const [vaultResult, questionAccount] = await Promise.all([
|
|
3597
|
+
connection.getTokenAccountBalance(vaultAta).catch(() => null),
|
|
3598
|
+
needsQtMintResolve ? connection.getAccountInfo(oracle.question).catch(() => null) : Promise.resolve(null)
|
|
3599
|
+
]);
|
|
3600
|
+
const vaultBalance = vaultResult ? new anchor6.BN(vaultResult.value.amount) : new anchor6.BN(0);
|
|
3601
|
+
let qtMint = oracle.qtMint;
|
|
3602
|
+
if (needsQtMintResolve && questionAccount) {
|
|
3603
|
+
try {
|
|
3604
|
+
const presalePda = new PublicKey(questionAccount.data.slice(41, 73));
|
|
3605
|
+
qtMint = PDA.qtMint(presalePda, this.programIds)[0];
|
|
3606
|
+
} catch {
|
|
3607
|
+
}
|
|
3608
|
+
}
|
|
3609
|
+
const isDefaultMint = qtMint.equals(PublicKey.default);
|
|
3610
|
+
const needsSupply = (!oracle.feesDistributed || oracle.qtTotalSupply.isZero()) && !isDefaultMint;
|
|
3611
|
+
const userQtAta = isDefaultMint ? null : getAssociatedTokenAddressSync(qtMint, user);
|
|
3612
|
+
const [qtBalResult, supplyResult] = await Promise.all([
|
|
3613
|
+
userQtAta ? connection.getTokenAccountBalance(userQtAta).catch(() => null) : Promise.resolve(null),
|
|
3614
|
+
needsSupply ? connection.getTokenSupply(qtMint).catch(() => null) : Promise.resolve(null)
|
|
3615
|
+
]);
|
|
3616
|
+
const userQtBalance = qtBalResult ? new anchor6.BN(qtBalResult.value.amount) : new anchor6.BN(0);
|
|
3617
|
+
const qtTotalSupply = needsSupply && supplyResult ? new anchor6.BN(supplyResult.value.amount) : oracle.qtTotalSupply;
|
|
3618
|
+
const effectiveTotal = vaultBalance.add(oracle.totalClaimed);
|
|
3619
|
+
if (qtTotalSupply.isZero() || userQtBalance.isZero()) {
|
|
3620
|
+
return {
|
|
3621
|
+
share: new anchor6.BN(0),
|
|
3622
|
+
effectiveTotal,
|
|
3623
|
+
vaultBalance,
|
|
3624
|
+
userQtBalance,
|
|
3625
|
+
qtTotalSupply,
|
|
3626
|
+
feesDistributed: oracle.feesDistributed,
|
|
3627
|
+
hasClaimed
|
|
3628
|
+
};
|
|
3629
|
+
}
|
|
3630
|
+
const share = userQtBalance.mul(effectiveTotal).div(qtTotalSupply);
|
|
3631
|
+
return {
|
|
3632
|
+
share,
|
|
3633
|
+
effectiveTotal,
|
|
3634
|
+
vaultBalance,
|
|
3635
|
+
userQtBalance,
|
|
3636
|
+
qtTotalSupply,
|
|
3637
|
+
feesDistributed: oracle.feesDistributed,
|
|
3638
|
+
hasClaimed
|
|
3639
|
+
};
|
|
3640
|
+
}
|
|
3574
3641
|
async fetchUserClaimRecord(marketOraclePda, user) {
|
|
3575
3642
|
try {
|
|
3576
3643
|
const pda = this.userClaimRecordPda(marketOraclePda, user);
|
|
@@ -18708,12 +18775,12 @@ var dispute_default = {
|
|
|
18708
18775
|
var XMarketSDK = class {
|
|
18709
18776
|
constructor(config, wallet, marketOwner) {
|
|
18710
18777
|
this.networkConfig = config;
|
|
18711
|
-
this.provider = new
|
|
18778
|
+
this.provider = new anchor6.AnchorProvider(
|
|
18712
18779
|
new Connection(config.rpcUrl, "confirmed"),
|
|
18713
18780
|
wallet,
|
|
18714
18781
|
{ commitment: "confirmed", preflightCommitment: "confirmed" }
|
|
18715
18782
|
);
|
|
18716
|
-
|
|
18783
|
+
anchor6.setProvider(this.provider);
|
|
18717
18784
|
this._programIds = config.programIds;
|
|
18718
18785
|
this._marketOwner = marketOwner ?? wallet.publicKey;
|
|
18719
18786
|
}
|
|
@@ -18722,21 +18789,21 @@ var XMarketSDK = class {
|
|
|
18722
18789
|
}
|
|
18723
18790
|
get oracle() {
|
|
18724
18791
|
if (!this._oracle) {
|
|
18725
|
-
const program = new
|
|
18792
|
+
const program = new anchor6.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
|
|
18726
18793
|
this._oracle = new OracleClient(program, this.provider, this._programIds);
|
|
18727
18794
|
}
|
|
18728
18795
|
return this._oracle;
|
|
18729
18796
|
}
|
|
18730
18797
|
get hook() {
|
|
18731
18798
|
if (!this._hook) {
|
|
18732
|
-
const program = new
|
|
18799
|
+
const program = new anchor6.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
|
|
18733
18800
|
this._hook = new HookClient(program, this.provider, this._programIds);
|
|
18734
18801
|
}
|
|
18735
18802
|
return this._hook;
|
|
18736
18803
|
}
|
|
18737
18804
|
get market() {
|
|
18738
18805
|
if (!this._market) {
|
|
18739
|
-
const program = new
|
|
18806
|
+
const program = new anchor6.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
|
|
18740
18807
|
this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
|
|
18741
18808
|
this._market.ctfClient = this.ctf;
|
|
18742
18809
|
this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
|
|
@@ -18745,14 +18812,14 @@ var XMarketSDK = class {
|
|
|
18745
18812
|
}
|
|
18746
18813
|
get ctf() {
|
|
18747
18814
|
if (!this._ctf) {
|
|
18748
|
-
const program = new
|
|
18815
|
+
const program = new anchor6.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
|
|
18749
18816
|
this._ctf = new CtfClient(program, this.provider, this._programIds);
|
|
18750
18817
|
}
|
|
18751
18818
|
return this._ctf;
|
|
18752
18819
|
}
|
|
18753
18820
|
get clob() {
|
|
18754
18821
|
if (!this._clob) {
|
|
18755
|
-
const program = new
|
|
18822
|
+
const program = new anchor6.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
|
|
18756
18823
|
this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
|
|
18757
18824
|
if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
|
|
18758
18825
|
this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
|
|
@@ -18767,7 +18834,7 @@ var XMarketSDK = class {
|
|
|
18767
18834
|
get fee() {
|
|
18768
18835
|
if (!this._fee) {
|
|
18769
18836
|
if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
|
|
18770
|
-
const program = new
|
|
18837
|
+
const program = new anchor6.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
|
|
18771
18838
|
this._fee = new FeeManagementClient(program, this.provider, this._programIds);
|
|
18772
18839
|
}
|
|
18773
18840
|
return this._fee;
|
|
@@ -18775,7 +18842,7 @@ var XMarketSDK = class {
|
|
|
18775
18842
|
get presale() {
|
|
18776
18843
|
if (!this._presale) {
|
|
18777
18844
|
if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
|
|
18778
|
-
const program = new
|
|
18845
|
+
const program = new anchor6.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
|
|
18779
18846
|
this._presale = new PresaleClient(program, this.provider, this._programIds);
|
|
18780
18847
|
}
|
|
18781
18848
|
return this._presale;
|
|
@@ -18783,7 +18850,7 @@ var XMarketSDK = class {
|
|
|
18783
18850
|
get marketOracle() {
|
|
18784
18851
|
if (!this._marketOracle) {
|
|
18785
18852
|
if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
|
|
18786
|
-
const program = new
|
|
18853
|
+
const program = new anchor6.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
|
|
18787
18854
|
this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
|
|
18788
18855
|
}
|
|
18789
18856
|
return this._marketOracle;
|
|
@@ -18791,7 +18858,7 @@ var XMarketSDK = class {
|
|
|
18791
18858
|
get admin() {
|
|
18792
18859
|
if (!this._admin) {
|
|
18793
18860
|
if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
|
|
18794
|
-
const program = new
|
|
18861
|
+
const program = new anchor6.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
|
|
18795
18862
|
this._admin = new AdminClient(program, this.provider, this._programIds);
|
|
18796
18863
|
}
|
|
18797
18864
|
return this._admin;
|
|
@@ -18799,7 +18866,7 @@ var XMarketSDK = class {
|
|
|
18799
18866
|
get referral() {
|
|
18800
18867
|
if (!this._referral) {
|
|
18801
18868
|
if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
|
|
18802
|
-
const program = new
|
|
18869
|
+
const program = new anchor6.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
|
|
18803
18870
|
this._referral = new ReferralClient(program, this.provider, this._programIds);
|
|
18804
18871
|
}
|
|
18805
18872
|
return this._referral;
|
|
@@ -18807,7 +18874,7 @@ var XMarketSDK = class {
|
|
|
18807
18874
|
get dispute() {
|
|
18808
18875
|
if (!this._dispute) {
|
|
18809
18876
|
if (!this._programIds.dispute) throw new Error("dispute program ID not configured in NetworkConfig");
|
|
18810
|
-
const program = new
|
|
18877
|
+
const program = new anchor6.Program(this._withAddress(dispute_default, this._programIds.dispute), this.provider);
|
|
18811
18878
|
this._dispute = new DisputeClient(program, this.provider, this._programIds);
|
|
18812
18879
|
}
|
|
18813
18880
|
return this._dispute;
|