@theliem/xmarket-sdk 4.1.1 → 4.2.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.mjs CHANGED
@@ -185,6 +185,7 @@ var PDA = class {
185
185
  );
186
186
  }
187
187
  // ─── Presale ─────────────────────────────────────────────────────────────────
188
+ /** seeds: ["presale", questionMarketConfig, presale_index u64 LE] under presale program */
188
189
  static presale(questionMarketConfig, presaleIndex, programIds) {
189
190
  if (!programIds.presale) throw new Error("presale program ID not configured");
190
191
  const idxBuf = Buffer.alloc(8);
@@ -607,28 +608,52 @@ var MarketClient = class {
607
608
  return this.program.methods.bumpPresaleCount(new anchor6.BN(count)).accounts({ authority, config: this.configPda }).transaction();
608
609
  }
609
610
  // ─── Queries ─────────────────────────────────────────────────────────────────
611
+ configNotFoundMessage() {
612
+ return `Question market config not found at ${this.configPda.toBase58()}. Check NetworkConfig.programIds.questionMarket (v2 FkpHo3...) and marketOwner (config owner pubkey \u2014 not the user wallet). Devnet: use DEVNET_CONFIG or marketOwner DEVNET_MARKET_OWNER.`;
613
+ }
610
614
  async fetchConfig() {
615
+ const info = await this.provider.connection.getAccountInfo(this.configPda);
616
+ if (!info) return null;
611
617
  try {
612
618
  const acc = await this.program.account.questionMarketConfig.fetch(this.configPda);
613
- return {
614
- owner: acc.owner,
615
- admin: acc.admin,
616
- oracle: acc.oracle,
617
- oracleProgram: acc.oracleProgram,
618
- conditionalTokensProgram: acc.conditionalTokensProgram,
619
- questionCount: acc.questionCount.toNumber(),
620
- approvedCount: acc.approvedCount.toNumber(),
621
- rejectedCount: acc.rejectedCount.toNumber(),
622
- presaleCount: acc.presaleCount.toNumber(),
623
- whitelist: acc.whitelist.slice(0, acc.whitelistLen),
624
- whitelistLen: acc.whitelistLen,
625
- isPaused: acc.isPaused,
626
- bump: acc.bump
627
- };
619
+ return this.mapQuestionMarketConfig(acc);
628
620
  } catch {
629
621
  return null;
630
622
  }
631
623
  }
624
+ /** Like fetchConfig but throws with a hint when the config account is missing or invalid. */
625
+ async fetchConfigOrThrow() {
626
+ const info = await this.provider.connection.getAccountInfo(this.configPda);
627
+ if (!info) {
628
+ throw new Error(this.configNotFoundMessage());
629
+ }
630
+ try {
631
+ const acc = await this.program.account.questionMarketConfig.fetch(this.configPda);
632
+ return this.mapQuestionMarketConfig(acc);
633
+ } catch (e) {
634
+ throw new Error(
635
+ `${this.configNotFoundMessage()} Deserialize failed: ${e instanceof Error ? e.message : e}`
636
+ );
637
+ }
638
+ }
639
+ mapQuestionMarketConfig(acc) {
640
+ const accAny = acc;
641
+ return {
642
+ owner: accAny.owner,
643
+ admin: accAny.admin,
644
+ oracle: accAny.oracle,
645
+ oracleProgram: accAny.oracleProgram,
646
+ conditionalTokensProgram: accAny.conditionalTokensProgram,
647
+ questionCount: Number(accAny.questionCount.toString()),
648
+ approvedCount: Number(accAny.approvedCount.toString()),
649
+ rejectedCount: Number(accAny.rejectedCount.toString()),
650
+ presaleCount: Number(accAny.presaleCount.toString()),
651
+ whitelist: accAny.whitelist.slice(0, accAny.whitelistLen),
652
+ whitelistLen: accAny.whitelistLen,
653
+ isPaused: accAny.isPaused,
654
+ bump: accAny.bump
655
+ };
656
+ }
632
657
  /** Check if address is in question_market whitelist (can call createQuestion) */
633
658
  async isWhitelisted(address) {
634
659
  const cfg = await this.fetchConfig();
@@ -681,9 +706,10 @@ var MarketClient = class {
681
706
  * Any user creates a presale + initial buy (question-market::create_presale).
682
707
  * Reads agents_rev / company_rev from fee_config.
683
708
  *
684
- * @param feeConfig fee_management fee_config PDA (owner = feeConfigOwner)
685
- * @param currencyMint collateral token (e.g. USDC)
686
- * @param presaleIndex config.presale_count — fetch config first or pass 0 for first presale
709
+ * Presale PDA seeds (presale program): ["presale", config, presale_index]
710
+ * where presale_index must equal config.presale_count at execution time.
711
+ *
712
+ * @param presaleIndex config.presale_count — fetch config first via fetchConfig()
687
713
  */
688
714
  async createPresale(params, feeConfig, currencyMint, presaleIndex, creator = this.walletPubkey, payer = creator) {
689
715
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
@@ -2082,7 +2108,7 @@ ${logs.join("\n")}`);
2082
2108
  * remaining_accounts per NO maker (6):
2083
2109
  * [maker, order_record, buyer_no_token, buyer_no_collateral, buyer_no_position, no_order_status]
2084
2110
  */
2085
- async _buildMintIx(yesSigned, noMakers, collateralMint, operator, payer) {
2111
+ async _buildMintIx(yesSigned, noMakers, collateralMint, operator, payer, feeRecipient, opts) {
2086
2112
  const condition = yesSigned.order.condition;
2087
2113
  const taker = yesSigned.order.maker;
2088
2114
  const takerNonce = yesSigned.order.nonce;
@@ -2120,6 +2146,26 @@ ${logs.join("\n")}`);
2120
2146
  { pubkey: noStatus, isSigner: false, isWritable: true }
2121
2147
  );
2122
2148
  }
2149
+ if (yesSigned.order.fee.gtn(0) && this.programIds.feeManagement && this.feeConfigOwner) {
2150
+ const companyAddr = await this.companyAddress();
2151
+ const refVault = await this.referralVault();
2152
+ if (companyAddr && refVault) {
2153
+ const feeOverridePda = PDA.marketFeeOverride(condition, this.programIds)[0];
2154
+ const feeOverrideExists = await this.provider.connection.getAccountInfo(feeOverridePda);
2155
+ if (feeOverrideExists) {
2156
+ const oracleVault = opts?.marketOracleVault ?? await this.getMarketOracleVault(condition, collateralMint) ?? payer;
2157
+ remainingAccounts.push(
2158
+ { pubkey: this.programIds.feeManagement, isSigner: false, isWritable: false },
2159
+ { pubkey: PDA.feeConfig(this.feeConfigOwner, this.programIds)[0], isSigner: false, isWritable: false },
2160
+ { pubkey: feeOverridePda, isSigner: false, isWritable: false },
2161
+ { pubkey: getAssociatedTokenAddressSync(collateralMint, companyAddr), isSigner: false, isWritable: true },
2162
+ { pubkey: oracleVault, isSigner: false, isWritable: true },
2163
+ { pubkey: refVault, isSigner: false, isWritable: true }
2164
+ );
2165
+ }
2166
+ }
2167
+ }
2168
+ const resolvedFeeRecipient = feeRecipient ?? clobUsdcAta;
2123
2169
  return this.program.methods.matchMintOrders(takerNonce, fillAmount, true).accounts({
2124
2170
  operator,
2125
2171
  payer,
@@ -2131,6 +2177,7 @@ ${logs.join("\n")}`);
2131
2177
  takerYesToken,
2132
2178
  takerYesPosition,
2133
2179
  takerOrderStatus,
2180
+ feeRecipient: resolvedFeeRecipient,
2134
2181
  clobUsdcAta,
2135
2182
  clobYesAta,
2136
2183
  clobNoAta,
@@ -2160,7 +2207,7 @@ ${logs.join("\n")}`);
2160
2207
  const [noMint] = PDA.noMint(condition, this.programIds);
2161
2208
  const clobYesAta = getAssociatedTokenAddressSync(yesMint, clobConfig, true, TOKEN_PROGRAM_ID);
2162
2209
  const clobNoAta = getAssociatedTokenAddressSync(noMint, clobConfig, true, TOKEN_PROGRAM_ID);
2163
- const matchIx = await this._buildMintIx(yesSigned, noMakers, collateralMint, operatorWallet.publicKey, this.walletPubkey);
2210
+ const matchIx = await this._buildMintIx(yesSigned, noMakers, collateralMint, operatorWallet.publicKey, this.walletPubkey, _feeRecipient);
2164
2211
  await this._ensureClobOutcomeAtas(yesMint, noMint, clobConfig, clobYesAta, clobNoAta);
2165
2212
  const sig = await this.sendMatchTx([matchIx], lookupTable, operatorWallet);
2166
2213
  return { signature: sig };
@@ -7184,13 +7231,6 @@ var question_market_default = {
7184
7231
  ],
7185
7232
  type: "pubkey"
7186
7233
  },
7187
- {
7188
- name: "oracle_program",
7189
- docs: [
7190
- "Oracle program ID \u2014 pinned for CPI validation in resolve_question"
7191
- ],
7192
- type: "pubkey"
7193
- },
7194
7234
  {
7195
7235
  name: "question_count",
7196
7236
  docs: [
@@ -7252,6 +7292,14 @@ var question_market_default = {
7252
7292
  ],
7253
7293
  type: "u64"
7254
7294
  },
7295
+ {
7296
+ name: "oracle_program",
7297
+ docs: [
7298
+ "Oracle program ID \u2014 pinned for CPI validation in resolve_question",
7299
+ "Placed at end of meaningful fields to avoid layout shift on old accounts."
7300
+ ],
7301
+ type: "pubkey"
7302
+ },
7255
7303
  {
7256
7304
  name: "_reserved",
7257
7305
  docs: [
@@ -18042,7 +18090,11 @@ var XMarketSDK = class {
18042
18090
  );
18043
18091
  anchor6.setProvider(this.provider);
18044
18092
  this._programIds = config.programIds;
18045
- this._marketOwner = marketOwner ?? wallet.publicKey;
18093
+ this._marketOwner = marketOwner ?? config.marketOwner ?? wallet.publicKey;
18094
+ }
18095
+ /** Question market config PDA derived from marketOwner + questionMarket program. */
18096
+ get questionMarketConfigPda() {
18097
+ return this.market.configPda;
18046
18098
  }
18047
18099
  _withAddress(idl, address) {
18048
18100
  return { ...idl, address: address.toBase58() };
@@ -18132,6 +18184,44 @@ var XMarketSDK = class {
18132
18184
  return this._dispute;
18133
18185
  }
18134
18186
  };
18187
+ var V2_PROGRAM_IDS = {
18188
+ oracle: new PublicKey("8uNiLDZnarxyFyoCi1bE1qkBMsLs2Tpyohtdzdvjkg8j"),
18189
+ conditionalTokens: new PublicKey("xpn3htSptTZECudoRA8WJmAEtiijxDseTqtawYysVNT"),
18190
+ questionMarket: new PublicKey("FkpHo3zb5h2nNS5n6tWAvDwXPTXR2qqVLjDmEkMayott"),
18191
+ clobExchange: new PublicKey("AFT8SM1Vv8g8AQTf81LoE5oLteUTyhWzWTLj7SKZjkY1"),
18192
+ feeManagement: new PublicKey("8S6hxqbDc8kgHf4uUzq2t15PeY36QSCYEpBVvM4Fhrkm"),
18193
+ presale: new PublicKey("CKd94vPibAMAr8R5eLv21r8PYXkgLRithipBe8GV7J6C"),
18194
+ marketOracle: new PublicKey("Agt6beCbghi4jV9A8v9geRP5dnt2wDkJBVgy9oM33zit"),
18195
+ adminContract: new PublicKey("2HsyCdr59W5ndeboaE9JAmhEQ46m5Gm2ZWBfYEs1tC1i"),
18196
+ referral: new PublicKey("9kyNMtUEFR6hDeZHUTbRKH3t1EJisfSvWQKKUev7ujoC"),
18197
+ dispute: new PublicKey("8gqHPY1WtGFGmYNbrGrPVoct1kqPL6cCaUtJ17EHSsFp")
18198
+ };
18199
+ var DEVNET_MARKET_OWNER = new PublicKey(
18200
+ "7eGpbyRpcM7WpNKQtd6XkteNQWHbWXP7icZjKzNK2aTk"
18201
+ );
18202
+ var DEVNET_QUESTION_MARKET_CONFIG = new PublicKey(
18203
+ "7n8y2oQYmxTp9fn2Wf2dFE1pC7ZESXYJ4yXSbYSEuRn5"
18204
+ );
18205
+ var DEVNET_USDC_MINT = new PublicKey(
18206
+ "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
18207
+ );
18208
+ var MAINNET_USDC_MINT = new PublicKey(
18209
+ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
18210
+ );
18211
+ var DEVNET_CONFIG = {
18212
+ name: "devnet",
18213
+ rpcUrl: "https://api.devnet.solana.com",
18214
+ programIds: V2_PROGRAM_IDS,
18215
+ defaultCollateral: { mint: DEVNET_USDC_MINT, decimals: 6 },
18216
+ marketOwner: DEVNET_MARKET_OWNER,
18217
+ feeConfigOwner: DEVNET_MARKET_OWNER
18218
+ };
18219
+ var MAINNET_CONFIG = {
18220
+ name: "mainnet",
18221
+ rpcUrl: "https://api.mainnet-beta.solana.com",
18222
+ programIds: V2_PROGRAM_IDS,
18223
+ defaultCollateral: { mint: MAINNET_USDC_MINT, decimals: 6 }
18224
+ };
18135
18225
  var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
18136
18226
  function buildCreateUserAtasTx(condition, user, payer, programIds) {
18137
18227
  const [yesMint] = PDA.yesMint(condition, programIds);
@@ -18201,6 +18291,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
18201
18291
  return tx;
18202
18292
  }
18203
18293
 
18204
- export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, DisputeClient, FEE_DENOMINATOR, FeeManagementClient, IX_SYSVAR, InvalidParamError, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, ReferralClient, SEEDS, UnauthorizedError, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
18294
+ export { AccountNotFoundError, AdminClient, ClobClient, CtfClient, DEVNET_CONFIG, DEVNET_MARKET_OWNER, DEVNET_QUESTION_MARKET_CONFIG, DEVNET_USDC_MINT, DisputeClient, FEE_DENOMINATOR, FeeManagementClient, IX_SYSVAR, InvalidParamError, MAINNET_CONFIG, MAINNET_USDC_MINT, MAX_APPROVE_AMOUNT, MarketClient, MarketOracleClient, OracleClient, PDA, PresaleClient, QuestionStatus, ReferralClient, SEEDS, UnauthorizedError, V2_PROGRAM_IDS, XMarketError, XMarketSDK, buildApproveAllOutcomeTokensTx, buildApproveCollateralTx, buildBatchedCollectFeeEd25519Instruction, buildBatchedEd25519Instruction, buildBatchedRedeemFeeEd25519Instruction, buildCreateUserAtasTx, buildOrder, buildOrderFromPrice, deserializeSignedOrder, detectMatchType, generateContentHash, generateQuestionId, getOrderSignBytes, orderAmountsFromPrice, serializeCollectFeeOrderToBytes, serializeOrderToBytes, serializeRedeemFeeOrderToBytes, serializeSignedOrder, signOrder, signOrderWithKeypair, verifySignedOrder };
18205
18295
  //# sourceMappingURL=index.mjs.map
18206
18296
  //# sourceMappingURL=index.mjs.map