@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 CHANGED
@@ -1015,6 +1015,22 @@ interface UserClaimRecord {
1015
1015
  hasClaimed: boolean;
1016
1016
  bump: number;
1017
1017
  }
1018
+ interface FeesShareEstimate {
1019
+ /** Net USDS user will receive if they claim now */
1020
+ share: anchor.BN;
1021
+ /** Total accumulated fees (vault + already claimed) */
1022
+ effectiveTotal: anchor.BN;
1023
+ /** Current vault balance */
1024
+ vaultBalance: anchor.BN;
1025
+ /** User's current MST balance */
1026
+ userQtBalance: anchor.BN;
1027
+ /** Snapshotted total MST supply (0 if not yet distributed) */
1028
+ qtTotalSupply: anchor.BN;
1029
+ /** True if fees_distributed — claim is on-chain executable */
1030
+ feesDistributed: boolean;
1031
+ /** True if user already claimed */
1032
+ hasClaimed: boolean;
1033
+ }
1018
1034
  declare class MarketOracleClient {
1019
1035
  private readonly program;
1020
1036
  private readonly provider;
@@ -1029,6 +1045,24 @@ declare class MarketOracleClient {
1029
1045
  */
1030
1046
  claimFeesShare(marketOraclePda: PublicKey, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
1031
1047
  fetchMarketOracle(marketOraclePda: PublicKey): Promise<MarketOracleInfo | null>;
1048
+ /**
1049
+ * Derive marketOracleVault from presaleAddress and return its USDS balance.
1050
+ * presaleAddress is used as the questionId seed in the question PDA.
1051
+ */
1052
+ getOracleVaultBalance(presaleAddress: PublicKey, qmConfigPda: PublicKey, collateralMint: PublicKey): Promise<number>;
1053
+ /**
1054
+ * Estimate the USDS share a user would receive if they called claimFeesShare now.
1055
+ * Works both before and after fees_distributed — no extra params needed.
1056
+ *
1057
+ * When fees not yet distributed, auto-resolves qtMint via:
1058
+ * oracle.question (questionPda) → raw account bytes[8..40] = presalePda
1059
+ * → PDA.qtMint(presalePda) → qtMint
1060
+ *
1061
+ * Formula mirrors on-chain claim_fees_share_handler:
1062
+ * effective_total = vault_balance + oracle.total_claimed
1063
+ * share = user_qt_balance * effective_total / oracle.qt_total_supply
1064
+ */
1065
+ estimateFeesShare(marketOraclePda: PublicKey, user: PublicKey): Promise<FeesShareEstimate | null>;
1032
1066
  fetchUserClaimRecord(marketOraclePda: PublicKey, user: PublicKey): Promise<UserClaimRecord | null>;
1033
1067
  }
1034
1068
 
@@ -1482,4 +1516,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1482
1516
  */
1483
1517
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1484
1518
 
1485
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1519
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, type FeesShareEstimate, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.d.ts CHANGED
@@ -1015,6 +1015,22 @@ interface UserClaimRecord {
1015
1015
  hasClaimed: boolean;
1016
1016
  bump: number;
1017
1017
  }
1018
+ interface FeesShareEstimate {
1019
+ /** Net USDS user will receive if they claim now */
1020
+ share: anchor.BN;
1021
+ /** Total accumulated fees (vault + already claimed) */
1022
+ effectiveTotal: anchor.BN;
1023
+ /** Current vault balance */
1024
+ vaultBalance: anchor.BN;
1025
+ /** User's current MST balance */
1026
+ userQtBalance: anchor.BN;
1027
+ /** Snapshotted total MST supply (0 if not yet distributed) */
1028
+ qtTotalSupply: anchor.BN;
1029
+ /** True if fees_distributed — claim is on-chain executable */
1030
+ feesDistributed: boolean;
1031
+ /** True if user already claimed */
1032
+ hasClaimed: boolean;
1033
+ }
1018
1034
  declare class MarketOracleClient {
1019
1035
  private readonly program;
1020
1036
  private readonly provider;
@@ -1029,6 +1045,24 @@ declare class MarketOracleClient {
1029
1045
  */
1030
1046
  claimFeesShare(marketOraclePda: PublicKey, user?: PublicKey, payer?: PublicKey): Promise<Transaction>;
1031
1047
  fetchMarketOracle(marketOraclePda: PublicKey): Promise<MarketOracleInfo | null>;
1048
+ /**
1049
+ * Derive marketOracleVault from presaleAddress and return its USDS balance.
1050
+ * presaleAddress is used as the questionId seed in the question PDA.
1051
+ */
1052
+ getOracleVaultBalance(presaleAddress: PublicKey, qmConfigPda: PublicKey, collateralMint: PublicKey): Promise<number>;
1053
+ /**
1054
+ * Estimate the USDS share a user would receive if they called claimFeesShare now.
1055
+ * Works both before and after fees_distributed — no extra params needed.
1056
+ *
1057
+ * When fees not yet distributed, auto-resolves qtMint via:
1058
+ * oracle.question (questionPda) → raw account bytes[8..40] = presalePda
1059
+ * → PDA.qtMint(presalePda) → qtMint
1060
+ *
1061
+ * Formula mirrors on-chain claim_fees_share_handler:
1062
+ * effective_total = vault_balance + oracle.total_claimed
1063
+ * share = user_qt_balance * effective_total / oracle.qt_total_supply
1064
+ */
1065
+ estimateFeesShare(marketOraclePda: PublicKey, user: PublicKey): Promise<FeesShareEstimate | null>;
1032
1066
  fetchUserClaimRecord(marketOraclePda: PublicKey, user: PublicKey): Promise<UserClaimRecord | null>;
1033
1067
  }
1034
1068
 
@@ -1482,4 +1516,4 @@ declare function buildApproveCollateralTx(collateralMint: PublicKey, signer: Pub
1482
1516
  */
1483
1517
  declare function buildApproveAllOutcomeTokensTx(condition: PublicKey, signer: PublicKey, payer: PublicKey, delegate: PublicKey, programIds: ProgramIds, amount?: BN): Transaction;
1484
1518
 
1485
- export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
1519
+ export { AccountNotFoundError, AdminClient, type AdminConfigInfo, type ClaimRecordInfo, ClobClient, type ClobConfig, type CollateralConfig, type CollateralVault, type CollectFeeOrder, type Condition, type CreateQuestionParams, CtfClient, type CtfConfig, DisputeClient, type DisputeConfigInfo, type DisputeMarketInfo, FEE_DENOMINATOR, FeeManagementClient, type FeesShareEstimate, HookClient, type HookConfig, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, type MarketOracleInfo, type MatchType, type NetworkConfig, type NetworkName, OracleClient, type OracleConfig, type Order, type OrderStatus, PDA, type Position, PresaleClient, type PresaleInfo, type ProgramIds, type Question, type QuestionFee, type QuestionMarketConfig, type QuestionResult, QuestionStatus, type RedeemFeeOrder, type RedeemFeeOrderPair, ReferralClient, type ReferralConfigInfo, SEEDS, type SignedCollectFeeOrder, type SignedOrder, type SignedRedeemFeeOrder, type TxResult, UnauthorizedError, type UserBuyRecord, type UserClaimRecord, type UserDisputeInfo, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var anchor5 = require('@coral-xyz/anchor');
3
+ var anchor6 = require('@coral-xyz/anchor');
4
4
  var web3_js = require('@solana/web3.js');
5
5
  var crypto = require('crypto');
6
6
  var splToken = require('@solana/spl-token');
@@ -27,7 +27,7 @@ function _interopNamespace(e) {
27
27
  return Object.freeze(n);
28
28
  }
29
29
 
30
- var anchor5__namespace = /*#__PURE__*/_interopNamespace(anchor5);
30
+ var anchor6__namespace = /*#__PURE__*/_interopNamespace(anchor6);
31
31
  var BN4__default = /*#__PURE__*/_interopDefault(BN4);
32
32
  var nacl__namespace = /*#__PURE__*/_interopNamespace(nacl);
33
33
 
@@ -376,7 +376,7 @@ var OracleClient = class {
376
376
  return this.program.methods.resolveQuestion(
377
377
  Array.from(questionId),
378
378
  outcomeCount,
379
- payoutNumerators.map((n) => new anchor5__namespace.BN(n))
379
+ payoutNumerators.map((n) => new anchor6__namespace.BN(n))
380
380
  ).accounts({
381
381
  reporter,
382
382
  oracleConfig,
@@ -665,7 +665,7 @@ var MarketClient = class {
665
665
  contentHash: Array.from(contentHash),
666
666
  hookProgram: params.hookProgram,
667
667
  authorizedClob: params.authorizedClob,
668
- expirationTime: new anchor5__namespace.BN(params.expirationTime)
668
+ expirationTime: new anchor6__namespace.BN(params.expirationTime)
669
669
  }).accounts({
670
670
  creator,
671
671
  payer,
@@ -754,7 +754,7 @@ var MarketClient = class {
754
754
  }).transaction();
755
755
  }
756
756
  async bumpPresaleCount(count, authority) {
757
- return this.program.methods.bumpPresaleCount(new anchor5__namespace.BN(count)).accounts({ authority, config: this.configPda }).transaction();
757
+ return this.program.methods.bumpPresaleCount(new anchor6__namespace.BN(count)).accounts({ authority, config: this.configPda }).transaction();
758
758
  }
759
759
  // ─── Queries ─────────────────────────────────────────────────────────────────
760
760
  async fetchConfig() {
@@ -1262,7 +1262,7 @@ var CtfClient = class {
1262
1262
  * Bypasses QuestionMarket — only for oracle-owned conditions.
1263
1263
  */
1264
1264
  async reportPayouts(condition, payoutNumerators) {
1265
- const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor5__namespace.BN(n))).accounts({
1265
+ const sig = await this.program.methods.reportPayouts(payoutNumerators.map((n) => new anchor6__namespace.BN(n))).accounts({
1266
1266
  oracle: this.walletPubkey,
1267
1267
  condition
1268
1268
  }).rpc();
@@ -2107,7 +2107,7 @@ ${logs.join("\n")}`);
2107
2107
  const tokenId = takerSigned.order.tokenId;
2108
2108
  const taker = takerSigned.order.maker;
2109
2109
  const takerNonce = takerSigned.order.nonce;
2110
- const fillAmount = opts?.fillAmount ?? new anchor5__namespace.BN("18446744073709551615");
2110
+ const fillAmount = opts?.fillAmount ?? new anchor6__namespace.BN("18446744073709551615");
2111
2111
  const [outcomeMint] = tokenId === 1 ? PDA.yesMint(condition, this.programIds) : PDA.noMint(condition, this.programIds);
2112
2112
  const [takerOrderRecord] = PDA.orderRecord(taker, takerNonce, this.programIds);
2113
2113
  const takerCollateral = splToken.getAssociatedTokenAddressSync(collateralMint, taker);
@@ -2248,7 +2248,7 @@ ${logs.join("\n")}`);
2248
2248
  const condition = yesSigned.order.condition;
2249
2249
  const taker = yesSigned.order.maker;
2250
2250
  const takerNonce = yesSigned.order.nonce;
2251
- const fillAmount = new anchor5__namespace.BN("18446744073709551615");
2251
+ const fillAmount = new anchor6__namespace.BN("18446744073709551615");
2252
2252
  const clobConfig = this.configPda();
2253
2253
  const [yesMint] = PDA.yesMint(condition, this.programIds);
2254
2254
  const [noMint] = PDA.noMint(condition, this.programIds);
@@ -2352,7 +2352,7 @@ ${logs.join("\n")}`);
2352
2352
  const condition = yesSigned.order.condition;
2353
2353
  const sellerYes = yesSigned.order.maker;
2354
2354
  const takerNonce = yesSigned.order.nonce;
2355
- const fillAmount = new anchor5__namespace.BN("18446744073709551615");
2355
+ const fillAmount = new anchor6__namespace.BN("18446744073709551615");
2356
2356
  const clobConfig = this.configPda();
2357
2357
  const [yesMint] = PDA.yesMint(condition, this.programIds);
2358
2358
  const [noMint] = PDA.noMint(condition, this.programIds);
@@ -2819,9 +2819,9 @@ ${logs.join("\n")}`);
2819
2819
  ixSysvar: IX_SYSVAR,
2820
2820
  orderSigner: order.user,
2821
2821
  redeemFeeOrderRecord,
2822
- systemProgram: anchor5__namespace.web3.SystemProgram.programId
2822
+ systemProgram: anchor6__namespace.web3.SystemProgram.programId
2823
2823
  }).instruction();
2824
- const tx = new anchor5__namespace.web3.Transaction();
2824
+ const tx = new anchor6__namespace.web3.Transaction();
2825
2825
  tx.add(ed25519Ix, registerIx);
2826
2826
  return tx;
2827
2827
  }
@@ -2924,7 +2924,7 @@ ${logs.join("\n")}`);
2924
2924
  conditionalTokensProgram: this.programIds.conditionalTokens,
2925
2925
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
2926
2926
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
2927
- systemProgram: anchor5__namespace.web3.SystemProgram.programId
2927
+ systemProgram: anchor6__namespace.web3.SystemProgram.programId
2928
2928
  }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
2929
2929
  const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
2930
2930
  return this._buildUnsignedVtx([...hookInitIxs, redeemIx], alt, payer);
@@ -3026,7 +3026,7 @@ ${logs.join("\n")}`);
3026
3026
  conditionalTokensProgram: this.programIds.conditionalTokens,
3027
3027
  tokenProgram: splToken.TOKEN_PROGRAM_ID,
3028
3028
  token2022Program: splToken.TOKEN_2022_PROGRAM_ID,
3029
- systemProgram: anchor5__namespace.web3.SystemProgram.programId
3029
+ systemProgram: anchor6__namespace.web3.SystemProgram.programId
3030
3030
  }).remainingAccounts([...userAccounts, ...hookAccounts, ...feeAccounts]).instruction();
3031
3031
  const alt = opts?.lookupTable ?? await this.buildAltForCondition(condition, payer, collateralMint);
3032
3032
  return this._buildUnsignedVtx([...hookInitIxs, mergeIx], alt, payer);
@@ -3586,6 +3586,84 @@ var MarketOracleClient = class {
3586
3586
  return null;
3587
3587
  }
3588
3588
  }
3589
+ /**
3590
+ * Derive marketOracleVault from presaleAddress and return its USDS balance.
3591
+ * presaleAddress is used as the questionId seed in the question PDA.
3592
+ */
3593
+ async getOracleVaultBalance(presaleAddress, qmConfigPda, collateralMint) {
3594
+ const [questionPda] = PDA.question(qmConfigPda, presaleAddress.toBytes(), this.programIds);
3595
+ const [marketOraclePda] = PDA.marketOraclePda(questionPda, this.programIds);
3596
+ const vault = splToken.getAssociatedTokenAddressSync(collateralMint, marketOraclePda, true);
3597
+ const bal = await this.program.provider.connection.getTokenAccountBalance(vault);
3598
+ return bal.value.uiAmount ?? 0;
3599
+ }
3600
+ /**
3601
+ * Estimate the USDS share a user would receive if they called claimFeesShare now.
3602
+ * Works both before and after fees_distributed — no extra params needed.
3603
+ *
3604
+ * When fees not yet distributed, auto-resolves qtMint via:
3605
+ * oracle.question (questionPda) → raw account bytes[8..40] = presalePda
3606
+ * → PDA.qtMint(presalePda) → qtMint
3607
+ *
3608
+ * Formula mirrors on-chain claim_fees_share_handler:
3609
+ * effective_total = vault_balance + oracle.total_claimed
3610
+ * share = user_qt_balance * effective_total / oracle.qt_total_supply
3611
+ */
3612
+ async estimateFeesShare(marketOraclePda, user) {
3613
+ const { connection } = this.provider;
3614
+ const [oracle, claimRecord] = await Promise.all([
3615
+ this.fetchMarketOracle(marketOraclePda),
3616
+ this.fetchUserClaimRecord(marketOraclePda, user)
3617
+ ]);
3618
+ if (!oracle) return null;
3619
+ const hasClaimed = claimRecord?.hasClaimed ?? false;
3620
+ const vaultAta = splToken.getAssociatedTokenAddressSync(oracle.currencyMint, marketOraclePda, true);
3621
+ const needsQtMintResolve = !oracle.feesDistributed || oracle.qtMint.equals(web3_js.PublicKey.default);
3622
+ const [vaultResult, questionAccount] = await Promise.all([
3623
+ connection.getTokenAccountBalance(vaultAta).catch(() => null),
3624
+ needsQtMintResolve ? connection.getAccountInfo(oracle.question).catch(() => null) : Promise.resolve(null)
3625
+ ]);
3626
+ const vaultBalance = vaultResult ? new anchor6__namespace.BN(vaultResult.value.amount) : new anchor6__namespace.BN(0);
3627
+ let qtMint = oracle.qtMint;
3628
+ if (needsQtMintResolve && questionAccount) {
3629
+ try {
3630
+ const presalePda = new web3_js.PublicKey(questionAccount.data.slice(41, 73));
3631
+ qtMint = PDA.qtMint(presalePda, this.programIds)[0];
3632
+ } catch {
3633
+ }
3634
+ }
3635
+ const isDefaultMint = qtMint.equals(web3_js.PublicKey.default);
3636
+ const needsSupply = (!oracle.feesDistributed || oracle.qtTotalSupply.isZero()) && !isDefaultMint;
3637
+ const userQtAta = isDefaultMint ? null : splToken.getAssociatedTokenAddressSync(qtMint, user);
3638
+ const [qtBalResult, supplyResult] = await Promise.all([
3639
+ userQtAta ? connection.getTokenAccountBalance(userQtAta).catch(() => null) : Promise.resolve(null),
3640
+ needsSupply ? connection.getTokenSupply(qtMint).catch(() => null) : Promise.resolve(null)
3641
+ ]);
3642
+ const userQtBalance = qtBalResult ? new anchor6__namespace.BN(qtBalResult.value.amount) : new anchor6__namespace.BN(0);
3643
+ const qtTotalSupply = needsSupply && supplyResult ? new anchor6__namespace.BN(supplyResult.value.amount) : oracle.qtTotalSupply;
3644
+ const effectiveTotal = vaultBalance.add(oracle.totalClaimed);
3645
+ if (qtTotalSupply.isZero() || userQtBalance.isZero()) {
3646
+ return {
3647
+ share: new anchor6__namespace.BN(0),
3648
+ effectiveTotal,
3649
+ vaultBalance,
3650
+ userQtBalance,
3651
+ qtTotalSupply,
3652
+ feesDistributed: oracle.feesDistributed,
3653
+ hasClaimed
3654
+ };
3655
+ }
3656
+ const share = userQtBalance.mul(effectiveTotal).div(qtTotalSupply);
3657
+ return {
3658
+ share,
3659
+ effectiveTotal,
3660
+ vaultBalance,
3661
+ userQtBalance,
3662
+ qtTotalSupply,
3663
+ feesDistributed: oracle.feesDistributed,
3664
+ hasClaimed
3665
+ };
3666
+ }
3589
3667
  async fetchUserClaimRecord(marketOraclePda, user) {
3590
3668
  try {
3591
3669
  const pda = this.userClaimRecordPda(marketOraclePda, user);
@@ -18723,12 +18801,12 @@ var dispute_default = {
18723
18801
  var XMarketSDK = class {
18724
18802
  constructor(config, wallet, marketOwner) {
18725
18803
  this.networkConfig = config;
18726
- this.provider = new anchor5__namespace.AnchorProvider(
18804
+ this.provider = new anchor6__namespace.AnchorProvider(
18727
18805
  new web3_js.Connection(config.rpcUrl, "confirmed"),
18728
18806
  wallet,
18729
18807
  { commitment: "confirmed", preflightCommitment: "confirmed" }
18730
18808
  );
18731
- anchor5__namespace.setProvider(this.provider);
18809
+ anchor6__namespace.setProvider(this.provider);
18732
18810
  this._programIds = config.programIds;
18733
18811
  this._marketOwner = marketOwner ?? wallet.publicKey;
18734
18812
  }
@@ -18737,21 +18815,21 @@ var XMarketSDK = class {
18737
18815
  }
18738
18816
  get oracle() {
18739
18817
  if (!this._oracle) {
18740
- const program = new anchor5__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
18818
+ const program = new anchor6__namespace.Program(this._withAddress(oracle_default, this._programIds.oracle), this.provider);
18741
18819
  this._oracle = new OracleClient(program, this.provider, this._programIds);
18742
18820
  }
18743
18821
  return this._oracle;
18744
18822
  }
18745
18823
  get hook() {
18746
18824
  if (!this._hook) {
18747
- const program = new anchor5__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
18825
+ const program = new anchor6__namespace.Program(this._withAddress(hook_default, this._programIds.hook), this.provider);
18748
18826
  this._hook = new HookClient(program, this.provider, this._programIds);
18749
18827
  }
18750
18828
  return this._hook;
18751
18829
  }
18752
18830
  get market() {
18753
18831
  if (!this._market) {
18754
- const program = new anchor5__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
18832
+ const program = new anchor6__namespace.Program(this._withAddress(question_market_default, this._programIds.questionMarket), this.provider);
18755
18833
  this._market = new MarketClient(program, this.provider, this._programIds, this._marketOwner);
18756
18834
  this._market.ctfClient = this.ctf;
18757
18835
  this._market.feeConfigOwner = this.networkConfig.feeConfigOwner ?? this._marketOwner;
@@ -18760,14 +18838,14 @@ var XMarketSDK = class {
18760
18838
  }
18761
18839
  get ctf() {
18762
18840
  if (!this._ctf) {
18763
- const program = new anchor5__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
18841
+ const program = new anchor6__namespace.Program(this._withAddress(conditional_tokens_default, this._programIds.conditionalTokens), this.provider);
18764
18842
  this._ctf = new CtfClient(program, this.provider, this._programIds);
18765
18843
  }
18766
18844
  return this._ctf;
18767
18845
  }
18768
18846
  get clob() {
18769
18847
  if (!this._clob) {
18770
- const program = new anchor5__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
18848
+ const program = new anchor6__namespace.Program(this._withAddress(clob_exchange_default, this._programIds.clobExchange), this.provider);
18771
18849
  this._clob = new ClobClient(program, this.provider, this._programIds, this.networkConfig);
18772
18850
  if (this.networkConfig.feeConfigOwner && this._programIds.feeManagement) {
18773
18851
  this._clob.feeConfigOwner = this.networkConfig.feeConfigOwner;
@@ -18782,7 +18860,7 @@ var XMarketSDK = class {
18782
18860
  get fee() {
18783
18861
  if (!this._fee) {
18784
18862
  if (!this._programIds.feeManagement) throw new Error("feeManagement program ID not configured in NetworkConfig");
18785
- const program = new anchor5__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
18863
+ const program = new anchor6__namespace.Program(this._withAddress(fee_management_default, this._programIds.feeManagement), this.provider);
18786
18864
  this._fee = new FeeManagementClient(program, this.provider, this._programIds);
18787
18865
  }
18788
18866
  return this._fee;
@@ -18790,7 +18868,7 @@ var XMarketSDK = class {
18790
18868
  get presale() {
18791
18869
  if (!this._presale) {
18792
18870
  if (!this._programIds.presale) throw new Error("presale program ID not configured in NetworkConfig");
18793
- const program = new anchor5__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
18871
+ const program = new anchor6__namespace.Program(this._withAddress(presale_default, this._programIds.presale), this.provider);
18794
18872
  this._presale = new PresaleClient(program, this.provider, this._programIds);
18795
18873
  }
18796
18874
  return this._presale;
@@ -18798,7 +18876,7 @@ var XMarketSDK = class {
18798
18876
  get marketOracle() {
18799
18877
  if (!this._marketOracle) {
18800
18878
  if (!this._programIds.marketOracle) throw new Error("marketOracle program ID not configured in NetworkConfig");
18801
- const program = new anchor5__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
18879
+ const program = new anchor6__namespace.Program(this._withAddress(market_oracle_default, this._programIds.marketOracle), this.provider);
18802
18880
  this._marketOracle = new MarketOracleClient(program, this.provider, this._programIds);
18803
18881
  }
18804
18882
  return this._marketOracle;
@@ -18806,7 +18884,7 @@ var XMarketSDK = class {
18806
18884
  get admin() {
18807
18885
  if (!this._admin) {
18808
18886
  if (!this._programIds.adminContract) throw new Error("adminContract program ID not configured in NetworkConfig");
18809
- const program = new anchor5__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
18887
+ const program = new anchor6__namespace.Program(this._withAddress(admin_contract_default, this._programIds.adminContract), this.provider);
18810
18888
  this._admin = new AdminClient(program, this.provider, this._programIds);
18811
18889
  }
18812
18890
  return this._admin;
@@ -18814,7 +18892,7 @@ var XMarketSDK = class {
18814
18892
  get referral() {
18815
18893
  if (!this._referral) {
18816
18894
  if (!this._programIds.referral) throw new Error("referral program ID not configured in NetworkConfig");
18817
- const program = new anchor5__namespace.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
18895
+ const program = new anchor6__namespace.Program(this._withAddress(referral_default, this._programIds.referral), this.provider);
18818
18896
  this._referral = new ReferralClient(program, this.provider, this._programIds);
18819
18897
  }
18820
18898
  return this._referral;
@@ -18822,7 +18900,7 @@ var XMarketSDK = class {
18822
18900
  get dispute() {
18823
18901
  if (!this._dispute) {
18824
18902
  if (!this._programIds.dispute) throw new Error("dispute program ID not configured in NetworkConfig");
18825
- const program = new anchor5__namespace.Program(this._withAddress(dispute_default, this._programIds.dispute), this.provider);
18903
+ const program = new anchor6__namespace.Program(this._withAddress(dispute_default, this._programIds.dispute), this.provider);
18826
18904
  this._dispute = new DisputeClient(program, this.provider, this._programIds);
18827
18905
  }
18828
18906
  return this._dispute;