pnp-sdk 0.2.6 → 0.2.8

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.
@@ -8801,7 +8801,7 @@ var MarketModule = class {
8801
8801
  this.client.programId
8802
8802
  );
8803
8803
  const [marketExtension] = PublicKey5.findProgramAddressSync(
8804
- [Buffer.from("market_v2_ext"), gidLe],
8804
+ [Buffer.from("market_ext"), gidLe],
8805
8805
  this.client.programId
8806
8806
  );
8807
8807
  const payer = this.signer.publicKey;
@@ -8828,8 +8828,10 @@ var MarketModule = class {
8828
8828
  question,
8829
8829
  initial_liquidity: initialLiquidity,
8830
8830
  end_time: endTime,
8831
- creator
8831
+ creator,
8832
8832
  // Pass the creator explicitly
8833
+ yes_odds_bps: 5e3
8834
+ // Default 50/50 odds - REQUIRED to initialize market_extension
8833
8835
  }, this.client.programId);
8834
8836
  const res = await buildAndSendV0(this.client, this.signer, [ix], {
8835
8837
  computeUnitLimit: 4e5
@@ -8909,10 +8911,18 @@ var MarketModule = class {
8909
8911
  const collateralMintInfo = await this.client.connection.getAccountInfo(collateralTokenMint, this.client.commitment);
8910
8912
  if (!collateralMintInfo) throw new Error("collateral_token_mint not found");
8911
8913
  const tokenProgram = collateralMintInfo.owner.equals(TOKEN_2022_PROGRAM_ID) ? TOKEN_2022_PROGRAM_ID : TOKEN_PROGRAM_ID2;
8914
+ const marketIdBuffer = Buffer.alloc(8);
8915
+ marketIdBuffer.writeBigUInt64LE(marketId);
8916
+ const [marketExtension] = PublicKey5.findProgramAddressSync(
8917
+ [Buffer.from("market_ext"), marketIdBuffer],
8918
+ this.client.programId
8919
+ );
8912
8920
  const accounts = {
8913
8921
  authority: this.signer.publicKey,
8914
8922
  global_config: globalConfig,
8915
8923
  market,
8924
+ market_extension: marketExtension,
8925
+ // Always include (optional in IDL but position depends on it)
8916
8926
  collateral_token_mint: collateralTokenMint,
8917
8927
  yes_token_mint: yesTokenMint,
8918
8928
  no_token_mint: noTokenMint,
@@ -8927,11 +8937,6 @@ var MarketModule = class {
8927
8937
  system_program: SystemProgram2.programId,
8928
8938
  rent: new PublicKey5("SysvarRent111111111111111111111111111111111")
8929
8939
  };
8930
- if (params.market_extension) {
8931
- accounts.market_extension = params.market_extension;
8932
- } else if (params.marketExtension) {
8933
- accounts.market_extension = params.marketExtension;
8934
- }
8935
8940
  const ix = buildSetMarketResolvableV2Ix(accounts, {
8936
8941
  market_id: marketId,
8937
8942
  resolvable,
@@ -10408,6 +10413,75 @@ var PNPClient = class _PNPClient {
10408
10413
  creator
10409
10414
  });
10410
10415
  }
10416
+ /**
10417
+ * Create a V2 (AMM) market with custom initial odds and/or a custom oracle.
10418
+ *
10419
+ * @param params - Market creation parameters
10420
+ * @param params.yesOddsBps - Initial YES odds in basis points (100-9900).
10421
+ * Example: 7000 = 70% YES / 30% NO
10422
+ * @param params.oracle - Optional custom oracle for settlement (default: global oracle)
10423
+ * @returns Object with transaction signature and market PDA
10424
+ */
10425
+ async createMarketV2WithCustomOdds(params) {
10426
+ if (!this.anchorMarket) {
10427
+ throw new Error("AnchorMarketModule not available. Initialize client with a signer.");
10428
+ }
10429
+ if (params.yesOddsBps < 100 || params.yesOddsBps > 9900) {
10430
+ throw new Error("yesOddsBps must be between 100 and 9900 (1% to 99%)");
10431
+ }
10432
+ const res = await this.anchorMarket.createMarket({
10433
+ question: params.question,
10434
+ initialLiquidity: params.initialLiquidity,
10435
+ endTime: params.endTime,
10436
+ collateralTokenMint: params.collateralTokenMint,
10437
+ yesOddsBps: params.yesOddsBps,
10438
+ oracle: params.oracle,
10439
+ creator: params.creator
10440
+ });
10441
+ return {
10442
+ signature: res.signature,
10443
+ market: res.market.toBase58()
10444
+ };
10445
+ }
10446
+ /**
10447
+ * Create a P2P (V3) market with custom initial odds (high-level wrapper).
10448
+ * Custom odds allow splitting the initial liquidity between YES and NO sides
10449
+ * instead of the default 100% to creator side.
10450
+ *
10451
+ * @param params - Market creation parameters
10452
+ * @param params.oddsBps - Initial odds in basis points (100-9900).
10453
+ * Example: 7000 = 70% YES / 30% NO for a YES-side creator
10454
+ * @param params.oracle - Optional custom oracle for settlement (default: global oracle)
10455
+ * @returns P2PMarketResponse with market address and token mints
10456
+ */
10457
+ async createMarketP2PWithCustomOdds(params) {
10458
+ if (!this.anchorMarketV3) {
10459
+ throw new Error(
10460
+ "AnchorMarketV3Module not available. Initialize client with a signer."
10461
+ );
10462
+ }
10463
+ if (params.oddsBps < 100 || params.oddsBps > 9900) {
10464
+ throw new Error("oddsBps must be between 100 and 9900 (1% to 99%)");
10465
+ }
10466
+ const res = await this.anchorMarketV3.createMarketV3({
10467
+ question: params.question,
10468
+ initialAmount: params.initialAmount,
10469
+ side: params.side,
10470
+ creatorSideCap: params.creatorSideCap,
10471
+ endTime: params.endTime,
10472
+ maxPotRatio: params.maxPotRatio,
10473
+ collateralTokenMint: params.collateralTokenMint,
10474
+ creator: params.creator,
10475
+ oddsBps: params.oddsBps,
10476
+ oracle: params.oracle
10477
+ });
10478
+ return {
10479
+ signature: res.signature,
10480
+ market: res.market.toBase58(),
10481
+ yesTokenMint: res.yesTokenMint.toBase58(),
10482
+ noTokenMint: res.noTokenMint.toBase58()
10483
+ };
10484
+ }
10411
10485
  /**
10412
10486
  * Detects if a question contains a Twitter URL or tweet ID format after the question mark
10413
10487
  * @param questionText The question text to analyze
@@ -10857,24 +10931,16 @@ Cause: ${err.message}`);
10857
10931
  * @returns Transaction signature
10858
10932
  */
10859
10933
  async setMarketResolvable(market, resolvable, forceResolve) {
10860
- if (!this.market || !this.anchorClient) {
10934
+ if (!this.market) {
10861
10935
  throw new Error(
10862
- "MarketModule and AnchorClient required. Initialize client with a signer."
10936
+ "MarketModule required. Initialize client with a signer."
10863
10937
  );
10864
10938
  }
10865
10939
  const marketPk = typeof market === "string" ? new PublicKey14(market) : market;
10866
- const marketData = await this.anchorClient.program.account.market.fetch(marketPk);
10867
- const marketId = marketData.id;
10868
- const [marketExtension] = PublicKey14.findProgramAddressSync(
10869
- [Buffer.from("market_ext"), marketId.toArrayLike(Buffer, "le", 8)],
10870
- this.anchorClient.program.programId
10871
- );
10872
- const extensionAccountInfo = await this.connection.getAccountInfo(marketExtension);
10873
10940
  return this.market.setMarketResolvable({
10874
10941
  market: marketPk,
10875
10942
  resolvable,
10876
- forceResolve,
10877
- ...extensionAccountInfo ? { marketExtension } : {}
10943
+ forceResolve
10878
10944
  });
10879
10945
  }
10880
10946
  /**
@@ -11595,4 +11661,4 @@ export {
11595
11661
  RedemptionModule,
11596
11662
  PNPClient
11597
11663
  };
11598
- //# sourceMappingURL=chunk-OWSCUVZJ.js.map
11664
+ //# sourceMappingURL=chunk-HN2SKUTC.js.map