@theliem/xmarket-sdk 4.1.0 → 4.1.2

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);
@@ -479,11 +480,12 @@ var MarketClient = class {
479
480
  return this.provider.wallet.publicKey;
480
481
  }
481
482
  // ─── Instructions (return Transaction — caller signs + sends) ───────────────
482
- async initialize(admin, oracle, owner = this.walletPubkey) {
483
+ async initialize(admin, oracle, oracleProgram, owner = this.walletPubkey) {
483
484
  return this.program.methods.initialize({
484
485
  admin,
485
486
  conditionalTokensProgram: this.programIds.conditionalTokens,
486
- oracle
487
+ oracle,
488
+ oracleProgram
487
489
  }).accounts({
488
490
  owner,
489
491
  config: this.configPda,
@@ -550,7 +552,8 @@ var MarketClient = class {
550
552
  newAdmin: params.newAdmin ?? null,
551
553
  newOracle: params.newOracle ?? null,
552
554
  isPaused: params.isPaused ?? null,
553
- newConditionalTokensProgram: params.newConditionalTokensProgram ?? null
555
+ newConditionalTokensProgram: params.newConditionalTokensProgram ?? null,
556
+ newOracleProgram: params.newOracleProgram ?? null
554
557
  }).accounts({
555
558
  authority,
556
559
  payer,
@@ -605,27 +608,52 @@ var MarketClient = class {
605
608
  return this.program.methods.bumpPresaleCount(new anchor6.BN(count)).accounts({ authority, config: this.configPda }).transaction();
606
609
  }
607
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
+ }
608
614
  async fetchConfig() {
615
+ const info = await this.provider.connection.getAccountInfo(this.configPda);
616
+ if (!info) return null;
609
617
  try {
610
618
  const acc = await this.program.account.questionMarketConfig.fetch(this.configPda);
611
- return {
612
- owner: acc.owner,
613
- admin: acc.admin,
614
- oracle: acc.oracle,
615
- conditionalTokensProgram: acc.conditionalTokensProgram,
616
- questionCount: acc.questionCount.toNumber(),
617
- approvedCount: acc.approvedCount.toNumber(),
618
- rejectedCount: acc.rejectedCount.toNumber(),
619
- presaleCount: acc.presaleCount.toNumber(),
620
- whitelist: acc.whitelist.slice(0, acc.whitelistLen),
621
- whitelistLen: acc.whitelistLen,
622
- isPaused: acc.isPaused,
623
- bump: acc.bump
624
- };
619
+ return this.mapQuestionMarketConfig(acc);
625
620
  } catch {
626
621
  return null;
627
622
  }
628
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
+ }
629
657
  /** Check if address is in question_market whitelist (can call createQuestion) */
630
658
  async isWhitelisted(address) {
631
659
  const cfg = await this.fetchConfig();
@@ -678,9 +706,10 @@ var MarketClient = class {
678
706
  * Any user creates a presale + initial buy (question-market::create_presale).
679
707
  * Reads agents_rev / company_rev from fee_config.
680
708
  *
681
- * @param feeConfig fee_management fee_config PDA (owner = feeConfigOwner)
682
- * @param currencyMint collateral token (e.g. USDC)
683
- * @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()
684
713
  */
685
714
  async createPresale(params, feeConfig, currencyMint, presaleIndex, creator = this.walletPubkey, payer = creator) {
686
715
  if (!this.programIds.presale) throw new Error("presale program ID not configured");
@@ -6075,7 +6104,7 @@ var question_market_default = {
6075
6104
  {
6076
6105
  name: "oracle_program",
6077
6106
  docs: [
6078
- "Oracle program (for reading QuestionResult)"
6107
+ "Oracle program (for reading QuestionResult) \u2014 must match config.oracle_program"
6079
6108
  ]
6080
6109
  },
6081
6110
  {
@@ -6698,7 +6727,14 @@ var question_market_default = {
6698
6727
  {
6699
6728
  name: "oracle",
6700
6729
  docs: [
6701
- "Oracle pubkey that will resolve conditions"
6730
+ "Oracle config PDA that will resolve conditions"
6731
+ ],
6732
+ type: "pubkey"
6733
+ },
6734
+ {
6735
+ name: "oracle_program",
6736
+ docs: [
6737
+ "Oracle program ID \u2014 used to validate oracle proofs in resolve_question"
6702
6738
  ],
6703
6739
  type: "pubkey"
6704
6740
  }
@@ -7170,7 +7206,7 @@ var question_market_default = {
7170
7206
  {
7171
7207
  name: "oracle",
7172
7208
  docs: [
7173
- "Oracle pubkey that will resolve conditions"
7209
+ "Oracle config PDA that will resolve conditions"
7174
7210
  ],
7175
7211
  type: "pubkey"
7176
7212
  },
@@ -7235,6 +7271,14 @@ var question_market_default = {
7235
7271
  ],
7236
7272
  type: "u64"
7237
7273
  },
7274
+ {
7275
+ name: "oracle_program",
7276
+ docs: [
7277
+ "Oracle program ID \u2014 pinned for CPI validation in resolve_question",
7278
+ "Placed at end of meaningful fields to avoid layout shift on old accounts."
7279
+ ],
7280
+ type: "pubkey"
7281
+ },
7238
7282
  {
7239
7283
  name: "_reserved",
7240
7284
  docs: [
@@ -7243,7 +7287,7 @@ var question_market_default = {
7243
7287
  type: {
7244
7288
  array: [
7245
7289
  "u8",
7246
- 440
7290
+ 408
7247
7291
  ]
7248
7292
  }
7249
7293
  }
@@ -7441,6 +7485,15 @@ var question_market_default = {
7441
7485
  type: {
7442
7486
  option: "pubkey"
7443
7487
  }
7488
+ },
7489
+ {
7490
+ name: "new_oracle_program",
7491
+ docs: [
7492
+ "New oracle program ID (optional) \u2014 used to validate oracle proofs in resolve_question"
7493
+ ],
7494
+ type: {
7495
+ option: "pubkey"
7496
+ }
7444
7497
  }
7445
7498
  ]
7446
7499
  }
@@ -18016,7 +18069,11 @@ var XMarketSDK = class {
18016
18069
  );
18017
18070
  anchor6.setProvider(this.provider);
18018
18071
  this._programIds = config.programIds;
18019
- this._marketOwner = marketOwner ?? wallet.publicKey;
18072
+ this._marketOwner = marketOwner ?? config.marketOwner ?? wallet.publicKey;
18073
+ }
18074
+ /** Question market config PDA derived from marketOwner + questionMarket program. */
18075
+ get questionMarketConfigPda() {
18076
+ return this.market.configPda;
18020
18077
  }
18021
18078
  _withAddress(idl, address) {
18022
18079
  return { ...idl, address: address.toBase58() };
@@ -18106,6 +18163,44 @@ var XMarketSDK = class {
18106
18163
  return this._dispute;
18107
18164
  }
18108
18165
  };
18166
+ var V2_PROGRAM_IDS = {
18167
+ oracle: new PublicKey("8uNiLDZnarxyFyoCi1bE1qkBMsLs2Tpyohtdzdvjkg8j"),
18168
+ conditionalTokens: new PublicKey("xpn3htSptTZECudoRA8WJmAEtiijxDseTqtawYysVNT"),
18169
+ questionMarket: new PublicKey("FkpHo3zb5h2nNS5n6tWAvDwXPTXR2qqVLjDmEkMayott"),
18170
+ clobExchange: new PublicKey("AFT8SM1Vv8g8AQTf81LoE5oLteUTyhWzWTLj7SKZjkY1"),
18171
+ feeManagement: new PublicKey("8S6hxqbDc8kgHf4uUzq2t15PeY36QSCYEpBVvM4Fhrkm"),
18172
+ presale: new PublicKey("CKd94vPibAMAr8R5eLv21r8PYXkgLRithipBe8GV7J6C"),
18173
+ marketOracle: new PublicKey("Agt6beCbghi4jV9A8v9geRP5dnt2wDkJBVgy9oM33zit"),
18174
+ adminContract: new PublicKey("2HsyCdr59W5ndeboaE9JAmhEQ46m5Gm2ZWBfYEs1tC1i"),
18175
+ referral: new PublicKey("9kyNMtUEFR6hDeZHUTbRKH3t1EJisfSvWQKKUev7ujoC"),
18176
+ dispute: new PublicKey("8gqHPY1WtGFGmYNbrGrPVoct1kqPL6cCaUtJ17EHSsFp")
18177
+ };
18178
+ var DEVNET_MARKET_OWNER = new PublicKey(
18179
+ "7eGpbyRpcM7WpNKQtd6XkteNQWHbWXP7icZjKzNK2aTk"
18180
+ );
18181
+ var DEVNET_QUESTION_MARKET_CONFIG = new PublicKey(
18182
+ "7n8y2oQYmxTp9fn2Wf2dFE1pC7ZESXYJ4yXSbYSEuRn5"
18183
+ );
18184
+ var DEVNET_USDC_MINT = new PublicKey(
18185
+ "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU"
18186
+ );
18187
+ var MAINNET_USDC_MINT = new PublicKey(
18188
+ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
18189
+ );
18190
+ var DEVNET_CONFIG = {
18191
+ name: "devnet",
18192
+ rpcUrl: "https://api.devnet.solana.com",
18193
+ programIds: V2_PROGRAM_IDS,
18194
+ defaultCollateral: { mint: DEVNET_USDC_MINT, decimals: 6 },
18195
+ marketOwner: DEVNET_MARKET_OWNER,
18196
+ feeConfigOwner: DEVNET_MARKET_OWNER
18197
+ };
18198
+ var MAINNET_CONFIG = {
18199
+ name: "mainnet",
18200
+ rpcUrl: "https://api.mainnet-beta.solana.com",
18201
+ programIds: V2_PROGRAM_IDS,
18202
+ defaultCollateral: { mint: MAINNET_USDC_MINT, decimals: 6 }
18203
+ };
18109
18204
  var MAX_APPROVE_AMOUNT = new BN4("18446744073709551615");
18110
18205
  function buildCreateUserAtasTx(condition, user, payer, programIds) {
18111
18206
  const [yesMint] = PDA.yesMint(condition, programIds);
@@ -18175,6 +18270,6 @@ function buildApproveAllOutcomeTokensTx(condition, signer, payer, delegate, prog
18175
18270
  return tx;
18176
18271
  }
18177
18272
 
18178
- 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 };
18273
+ 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 };
18179
18274
  //# sourceMappingURL=index.mjs.map
18180
18275
  //# sourceMappingURL=index.mjs.map