@theliem/xmarket-sdk 3.26.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 +35 -1
- package/dist/index.d.ts +35 -1
- package/dist/index.js +104 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +103 -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);
|
|
@@ -3560,6 +3560,84 @@ var MarketOracleClient = class {
|
|
|
3560
3560
|
return null;
|
|
3561
3561
|
}
|
|
3562
3562
|
}
|
|
3563
|
+
/**
|
|
3564
|
+
* Derive marketOracleVault from presaleAddress and return its USDS balance.
|
|
3565
|
+
* presaleAddress is used as the questionId seed in the question PDA.
|
|
3566
|
+
*/
|
|
3567
|
+
async getOracleVaultBalance(presaleAddress, qmConfigPda, collateralMint) {
|
|
3568
|
+
const [questionPda] = PDA.question(qmConfigPda, presaleAddress.toBytes(), this.programIds);
|
|
3569
|
+
const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
|
|
3570
|
+
const vault = getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
|
|
3571
|
+
const bal = await this.program.provider.connection.getTokenAccountBalance(vault);
|
|
3572
|
+
return bal.value.uiAmount ?? 0;
|
|
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
|
+
}
|
|
3563
3641
|
async fetchUserClaimRecord(marketOraclePda, user) {
|
|
3564
3642
|
try {
|
|
3565
3643
|
const pda = this.userClaimRecordPda(marketOraclePda, user);
|
|
@@ -18697,12 +18775,12 @@ var dispute_default = {
|
|
|
18697
18775
|
var XMarketSDK = class {
|
|
18698
18776
|
constructor(config, wallet, marketOwner) {
|
|
18699
18777
|
this.networkConfig = config;
|
|
18700
|
-
this.provider = new
|
|
18778
|
+
this.provider = new anchor6.AnchorProvider(
|
|
18701
18779
|
new Connection(config.rpcUrl, "confirmed"),
|
|
18702
18780
|
wallet,
|
|
18703
18781
|
{ commitment: "confirmed", preflightCommitment: "confirmed" }
|
|
18704
18782
|
);
|
|
18705
|
-
|
|
18783
|
+
anchor6.setProvider(this.provider);
|
|
18706
18784
|
this._programIds = config.programIds;
|
|
18707
18785
|
this._marketOwner = marketOwner ?? wallet.publicKey;
|
|
18708
18786
|
}
|
|
@@ -18711,21 +18789,21 @@ var XMarketSDK = class {
|
|
|
18711
18789
|
}
|
|
18712
18790
|
get oracle() {
|
|
18713
18791
|
if (!this._oracle) {
|
|
18714
|
-
const program = new
|
|
18792
|
+
const program = new anchor6.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
|
|
18715
18793
|
this._oracle = new OracleClient(program, this.provider, this._programIds);
|
|
18716
18794
|
}
|
|
18717
18795
|
return this._oracle;
|
|
18718
18796
|
}
|
|
18719
18797
|
get hook() {
|
|
18720
18798
|
if (!this._hook) {
|
|
18721
|
-
const program = new
|
|
18799
|
+
const program = new anchor6.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
|
|
18722
18800
|
this._hook = new HookClient(program, this.provider, this._programIds);
|
|
18723
18801
|
}
|
|
18724
18802
|
return this._hook;
|
|
18725
18803
|
}
|
|
18726
18804
|
get market() {
|
|
18727
18805
|
if (!this._market) {
|
|
18728
|
-
const program = new
|
|
18806
|
+
const program = new anchor6.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
|
|
18729
18807
|
this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
|
|
18730
18808
|
this._market.ctfClient = this.ctf;
|
|
18731
18809
|
this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
|
|
@@ -18734,14 +18812,14 @@ var XMarketSDK = class {
|
|
|
18734
18812
|
}
|
|
18735
18813
|
get ctf() {
|
|
18736
18814
|
if (!this._ctf) {
|
|
18737
|
-
const program = new
|
|
18815
|
+
const program = new anchor6.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
|
|
18738
18816
|
this._ctf = new CtfClient(program, this.provider, this._programIds);
|
|
18739
18817
|
}
|
|
18740
18818
|
return this._ctf;
|
|
18741
18819
|
}
|
|
18742
18820
|
get clob() {
|
|
18743
18821
|
if (!this._clob) {
|
|
18744
|
-
const program = new
|
|
18822
|
+
const program = new anchor6.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
|
|
18745
18823
|
this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
|
|
18746
18824
|
if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
|
|
18747
18825
|
this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
|
|
@@ -18756,7 +18834,7 @@ var XMarketSDK = class {
|
|
|
18756
18834
|
get fee() {
|
|
18757
18835
|
if (!this._fee) {
|
|
18758
18836
|
if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
|
|
18759
|
-
const program = new
|
|
18837
|
+
const program = new anchor6.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
|
|
18760
18838
|
this._fee = new FeeManagementClient(program, this.provider, this._programIds);
|
|
18761
18839
|
}
|
|
18762
18840
|
return this._fee;
|
|
@@ -18764,7 +18842,7 @@ var XMarketSDK = class {
|
|
|
18764
18842
|
get presale() {
|
|
18765
18843
|
if (!this._presale) {
|
|
18766
18844
|
if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
|
|
18767
|
-
const program = new
|
|
18845
|
+
const program = new anchor6.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
|
|
18768
18846
|
this._presale = new PresaleClient(program, this.provider, this._programIds);
|
|
18769
18847
|
}
|
|
18770
18848
|
return this._presale;
|
|
@@ -18772,7 +18850,7 @@ var XMarketSDK = class {
|
|
|
18772
18850
|
get marketOracle() {
|
|
18773
18851
|
if (!this._marketOracle) {
|
|
18774
18852
|
if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
|
|
18775
|
-
const program = new
|
|
18853
|
+
const program = new anchor6.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
|
|
18776
18854
|
this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
|
|
18777
18855
|
}
|
|
18778
18856
|
return this._marketOracle;
|
|
@@ -18780,7 +18858,7 @@ var XMarketSDK = class {
|
|
|
18780
18858
|
get admin() {
|
|
18781
18859
|
if (!this._admin) {
|
|
18782
18860
|
if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
|
|
18783
|
-
const program = new
|
|
18861
|
+
const program = new anchor6.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
|
|
18784
18862
|
this._admin = new AdminClient(program, this.provider, this._programIds);
|
|
18785
18863
|
}
|
|
18786
18864
|
return this._admin;
|
|
@@ -18788,7 +18866,7 @@ var XMarketSDK = class {
|
|
|
18788
18866
|
get referral() {
|
|
18789
18867
|
if (!this._referral) {
|
|
18790
18868
|
if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
|
|
18791
|
-
const program = new
|
|
18869
|
+
const program = new anchor6.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
|
|
18792
18870
|
this._referral = new ReferralClient(program, this.provider, this._programIds);
|
|
18793
18871
|
}
|
|
18794
18872
|
return this._referral;
|
|
@@ -18796,7 +18874,7 @@ var XMarketSDK = class {
|
|
|
18796
18874
|
get dispute() {
|
|
18797
18875
|
if (!this._dispute) {
|
|
18798
18876
|
if (!this._programIds.dispute) throw new Error("dispute program ID not configured in NetworkConfig");
|
|
18799
|
-
const program = new
|
|
18877
|
+
const program = new anchor6.Program(this._withAddress(dispute_default, this._programIds.dispute), this.provider);
|
|
18800
18878
|
this._dispute = new DisputeClient(program, this.provider, this._programIds);
|
|
18801
18879
|
}
|
|
18802
18880
|
return this._dispute;
|