pnp-sdk 0.2.0 → 0.2.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.
@@ -9828,6 +9828,7 @@ var pdas_exports = {};
9828
9828
  __export(pdas_exports, {
9829
9829
  deriveAta: () => deriveAta,
9830
9830
  deriveCreatorFeeTreasuryPda: () => deriveCreatorFeeTreasuryPda,
9831
+ deriveCreatorFeeTreasuryPdaLegacy: () => deriveCreatorFeeTreasuryPdaLegacy,
9831
9832
  deriveGlobalConfigPda: () => deriveGlobalConfigPda,
9832
9833
  deriveMarketPda: () => deriveMarketPda,
9833
9834
  deriveMarketPdaFromMints: () => deriveMarketPdaFromMints,
@@ -9855,8 +9856,17 @@ function derivePositionPda(market, owner, programId) {
9855
9856
  function deriveGlobalConfigPda(programId) {
9856
9857
  return PublicKey3.findProgramAddressSync([Buffer.from("global_config")], programId);
9857
9858
  }
9858
- function deriveCreatorFeeTreasuryPda(creator, programId) {
9859
- return PublicKey3.findProgramAddressSync([Buffer.from("creator_fee_treasury"), creator.toBuffer()], programId);
9859
+ function deriveCreatorFeeTreasuryPda(creator, programId, collateralMint) {
9860
+ return PublicKey3.findProgramAddressSync(
9861
+ [Buffer.from("creator_fee_treasury"), creator.toBuffer(), collateralMint.toBuffer()],
9862
+ programId
9863
+ );
9864
+ }
9865
+ function deriveCreatorFeeTreasuryPdaLegacy(creator, programId) {
9866
+ return PublicKey3.findProgramAddressSync(
9867
+ [Buffer.from("creator_fee_treasury"), creator.toBuffer()],
9868
+ programId
9869
+ );
9860
9870
  }
9861
9871
  function deriveAta(owner, mint, allowOwnerOffCurve = false, tokenProgramId = TOKEN_PROGRAM_ID, ataProgramId = ASSOCIATED_TOKEN_PROGRAM_ID) {
9862
9872
  return getAssociatedTokenAddressSync(mint, owner, allowOwnerOffCurve, tokenProgramId, ataProgramId);
@@ -10086,7 +10096,7 @@ var MarketModule = class {
10086
10096
  const creator = payer;
10087
10097
  const payerCollateralTokenAccount = deriveAta(payer, collateralMint);
10088
10098
  const marketReserveVault = deriveAta(market, collateralMint, true);
10089
- const [creatorFeeTreasury] = deriveCreatorFeeTreasuryPda(creator, this.client.programId);
10099
+ const [creatorFeeTreasury] = deriveCreatorFeeTreasuryPda(creator, this.client.programId, collateralMint);
10090
10100
  const accounts = {
10091
10101
  payer,
10092
10102
  creator,
@@ -10839,7 +10849,7 @@ var AnchorMarketModule = class {
10839
10849
  // allowOwnerOffCurve
10840
10850
  );
10841
10851
  const [creatorFeeTreasury] = PublicKey11.findProgramAddressSync(
10842
- [Buffer.from("creator_fee_treasury"), creatorOverride.toBuffer()],
10852
+ [Buffer.from("creator_fee_treasury"), creatorOverride.toBuffer(), collateralTokenMint.toBuffer()],
10843
10853
  this.anchorClient.program.programId
10844
10854
  );
10845
10855
  try {
@@ -10973,7 +10983,7 @@ var AnchorMarketV3Module = class {
10973
10983
  creatorOverride
10974
10984
  );
10975
10985
  const [creatorFeeTreasury] = PublicKey12.findProgramAddressSync(
10976
- [Buffer.from("creator_fee_treasury"), creatorOverride.toBuffer()],
10986
+ [Buffer.from("creator_fee_treasury"), creatorOverride.toBuffer(), collateralTokenMint.toBuffer()],
10977
10987
  this.anchorClient.program.programId
10978
10988
  );
10979
10989
  try {
@@ -11031,7 +11041,7 @@ import {
11031
11041
  TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID6,
11032
11042
  getAssociatedTokenAddressSync as getAssociatedTokenAddressSync3
11033
11043
  } from "@solana/spl-token";
11034
- import { BN as BN3 } from "@coral-xyz/anchor";
11044
+ import { BN as BN3 } from "bn.js";
11035
11045
  var PNPClient = class _PNPClient {
11036
11046
  client;
11037
11047
  signer;
@@ -11180,6 +11190,24 @@ var PNPClient = class _PNPClient {
11180
11190
  detectedYoutubeUrl: youtubeUrl || detected.youtubeUrl
11181
11191
  };
11182
11192
  }
11193
+ /**
11194
+ * Create a P2P market with DeFiLlama protocol/metric detection (high-level wrapper).
11195
+ * Automatically formats the question with DeFiLlama reference.
11196
+ * Serializes PublicKeys to base58 strings to match P2PMarketResponse.
11197
+ */
11198
+ async createP2PMarketDefiLlama(params) {
11199
+ const { question, protocolName, metric, ...rest } = params;
11200
+ const finalQuestion = `${question}${question.endsWith(" ") ? "" : " "}df ${protocolName} ${metric}`;
11201
+ const result = await this.createP2PMarketGeneral({
11202
+ ...rest,
11203
+ question: finalQuestion
11204
+ });
11205
+ return {
11206
+ ...result,
11207
+ detectedProtocol: protocolName,
11208
+ detectedMetric: metric
11209
+ };
11210
+ }
11183
11211
  /**
11184
11212
  * Simple helper to create a P2P market with a YouTube URL using UI-friendly parameters.
11185
11213
  * - Accepts amount in USDC (number) and converts to raw units internally (assumes 6 decimals).
@@ -11227,6 +11255,107 @@ var PNPClient = class _PNPClient {
11227
11255
  creator
11228
11256
  });
11229
11257
  }
11258
+ /**
11259
+ * Create a V2 (AMM) market with Twitter URL detection (high-level wrapper).
11260
+ * Automatically detects and extracts Twitter URLs from the question.
11261
+ * Serializes PublicKeys to base58 strings.
11262
+ */
11263
+ async createMarketTwitter(params) {
11264
+ const { question, tweetUrl, initialLiquidity, endTime, collateralTokenMint } = params;
11265
+ if (!this.market) {
11266
+ throw new Error("MarketModule not available. Initialize client with a signer.");
11267
+ }
11268
+ const patterns = [
11269
+ /https?:\/\/(?:www\.)?twitter\.com\/[^/]+\/status\/(\d+)/i,
11270
+ /https?:\/\/(?:www\.)?x\.com\/[^/]+\/status\/(\d+)/i,
11271
+ /https?:\/\/(?:mobile\.)?twitter\.com\/[^/]+\/status\/(\d+)/i
11272
+ ];
11273
+ let tweetId = null;
11274
+ for (const re of patterns) {
11275
+ const m = tweetUrl.match(re);
11276
+ if (m && m[1]) {
11277
+ tweetId = m[1];
11278
+ break;
11279
+ }
11280
+ }
11281
+ if (!tweetId) {
11282
+ const m = tweetUrl.match(/(\d{8,})/);
11283
+ if (m && m[1]) tweetId = m[1];
11284
+ }
11285
+ if (!tweetId) {
11286
+ throw new Error("Unable to extract tweet ID from tweetUrl");
11287
+ }
11288
+ const finalQuestion = `${question}${question.endsWith(" ") ? "" : " "}X {${tweetId}}`;
11289
+ const result = await this.market.createMarket({
11290
+ question: finalQuestion,
11291
+ initialLiquidity,
11292
+ endTime,
11293
+ baseMint: collateralTokenMint
11294
+ });
11295
+ if (!result.signature) {
11296
+ throw new Error("Transaction failed: No signature returned");
11297
+ }
11298
+ return {
11299
+ signature: result.signature,
11300
+ market: result.market.toBase58(),
11301
+ detectedTwitterUrl: tweetUrl,
11302
+ isTweetIdFormat: true
11303
+ };
11304
+ }
11305
+ /**
11306
+ * Create a V2 (AMM) market with YouTube URL detection (high-level wrapper).
11307
+ * Automatically detects and extracts YouTube URLs from the question.
11308
+ * Serializes PublicKeys to base58 strings.
11309
+ */
11310
+ async createMarketYoutube(params) {
11311
+ const { question, youtubeUrl, initialLiquidity, endTime, collateralTokenMint } = params;
11312
+ if (!this.market) {
11313
+ throw new Error("MarketModule not available. Initialize client with a signer.");
11314
+ }
11315
+ const questionWithUrl = youtubeUrl && youtubeUrl.length > 0 ? `${question}${question.endsWith(" ") ? "" : " "}${youtubeUrl}` : question;
11316
+ const detected = _PNPClient.detectYoutubeUrl(questionWithUrl);
11317
+ const result = await this.market.createMarket({
11318
+ question: questionWithUrl,
11319
+ initialLiquidity,
11320
+ endTime,
11321
+ baseMint: collateralTokenMint
11322
+ });
11323
+ if (!result.signature) {
11324
+ throw new Error("Transaction failed: No signature returned");
11325
+ }
11326
+ return {
11327
+ signature: result.signature,
11328
+ market: result.market.toBase58(),
11329
+ detectedYoutubeUrl: youtubeUrl || detected.youtubeUrl
11330
+ };
11331
+ }
11332
+ /**
11333
+ * Create a V2 (AMM) market with DeFiLlama protocol/metric detection (high-level wrapper).
11334
+ * Automatically formats the question with DeFiLlama reference.
11335
+ * Serializes PublicKeys to base58 strings.
11336
+ */
11337
+ async createMarketDefiLlama(params) {
11338
+ const { question, protocolName, metric, initialLiquidity, endTime, collateralTokenMint } = params;
11339
+ if (!this.market) {
11340
+ throw new Error("MarketModule not available. Initialize client with a signer.");
11341
+ }
11342
+ const finalQuestion = `${question}${question.endsWith(" ") ? "" : " "}df ${protocolName} ${metric}`;
11343
+ const result = await this.market.createMarket({
11344
+ question: finalQuestion,
11345
+ initialLiquidity,
11346
+ endTime,
11347
+ baseMint: collateralTokenMint
11348
+ });
11349
+ if (!result.signature) {
11350
+ throw new Error("Transaction failed: No signature returned");
11351
+ }
11352
+ return {
11353
+ signature: result.signature,
11354
+ market: result.market.toBase58(),
11355
+ detectedProtocol: protocolName,
11356
+ detectedMetric: metric
11357
+ };
11358
+ }
11230
11359
  /**
11231
11360
  * Create a P2P market with Twitter URL detection (high-level wrapper).
11232
11361
  * Automatically detects and extracts Twitter URLs from the question.
@@ -11312,6 +11441,55 @@ var PNPClient = class _PNPClient {
11312
11441
  creator
11313
11442
  });
11314
11443
  }
11444
+ /**
11445
+ * Simple helper to create a P2P market with DeFiLlama protocol/metric using UI-friendly parameters.
11446
+ * - Accepts amount in USDC (number) and converts to raw units internally (assumes 6 decimals).
11447
+ * - Defaults to mainnet USDC as collateral mint if not provided.
11448
+ * - Defaults creatorSideCap to 5x the initial amount if not provided.
11449
+ * - Defaults end time to `daysUntilEnd` days from now (30 days by default).
11450
+ */
11451
+ async createP2PMarketDefiLlamaSimple(params) {
11452
+ const {
11453
+ question,
11454
+ protocolName,
11455
+ metric,
11456
+ side,
11457
+ amountUsdc,
11458
+ daysUntilEnd = 30,
11459
+ creatorSideCapMultiplier = 5,
11460
+ collateralTokenMint,
11461
+ maxPotRatio,
11462
+ creator
11463
+ } = params;
11464
+ if (!Number.isFinite(amountUsdc) || amountUsdc <= 0) {
11465
+ throw new Error("amountUsdc must be a positive number");
11466
+ }
11467
+ if (!["yes", "no"].includes(side)) {
11468
+ throw new Error("side must be 'yes' or 'no'");
11469
+ }
11470
+ const defaultUsdcMint = new PublicKey13(
11471
+ "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
11472
+ );
11473
+ const collateralMintPk = collateralTokenMint ?? defaultUsdcMint;
11474
+ const initialAmount = this.uiToRaw(amountUsdc, 6);
11475
+ const creatorCapUsdc = amountUsdc * creatorSideCapMultiplier;
11476
+ const creatorSideCap = this.uiToRaw(creatorCapUsdc, 6);
11477
+ const nowSeconds = Math.floor(Date.now() / 1e3);
11478
+ const endTimeSeconds = nowSeconds + daysUntilEnd * 24 * 60 * 60;
11479
+ const endTime = BigInt(endTimeSeconds);
11480
+ return this.createP2PMarketDefiLlama({
11481
+ question,
11482
+ protocolName,
11483
+ metric,
11484
+ initialAmount,
11485
+ side,
11486
+ creatorSideCap,
11487
+ endTime,
11488
+ maxPotRatio,
11489
+ collateralTokenMint: collateralMintPk,
11490
+ creator
11491
+ });
11492
+ }
11315
11493
  /**
11316
11494
  * Detects if a question contains a Twitter URL or tweet ID format after the question mark
11317
11495
  * @param questionText The question text to analyze
@@ -11393,6 +11571,36 @@ var PNPClient = class _PNPClient {
11393
11571
  }
11394
11572
  return { question: questionText };
11395
11573
  }
11574
+ /**
11575
+ * Detects if a question contains a DeFiLlama format after the question mark
11576
+ * @param questionText The question text to analyze
11577
+ * @returns Object containing the cleaned question and DeFiLlama protocol/metric info if present
11578
+ * @example
11579
+ * detectDefiLlamaUrl("Will Uniswap TVL exceed $5B? df uniswap-v3 tvl");
11580
+ */
11581
+ static detectDefiLlamaUrl(questionText) {
11582
+ const questionMarkIndex = questionText.indexOf("?");
11583
+ if (questionMarkIndex === -1) {
11584
+ return { question: questionText };
11585
+ }
11586
+ const afterQuestionMark = questionText.substring(questionMarkIndex + 1).trim();
11587
+ if (!afterQuestionMark) {
11588
+ return { question: questionText };
11589
+ }
11590
+ const defillamaPattern = /^\s*df\s+(\S+(?:\s+\S+)*)\s+(\S+)\s*$/i;
11591
+ const match = afterQuestionMark.match(defillamaPattern);
11592
+ if (match && match[1] && match[2]) {
11593
+ const protocolParts = match[1].trim().split(/\s+/);
11594
+ const metric = match[2].trim();
11595
+ const protocol = protocolParts.join(" ");
11596
+ return {
11597
+ question: questionText.substring(0, questionMarkIndex + 1).trim(),
11598
+ protocol,
11599
+ metric
11600
+ };
11601
+ }
11602
+ return { question: questionText };
11603
+ }
11396
11604
  /**
11397
11605
  * Parse a private key from a string that could be a JSON array or base58 encoded
11398
11606
  * @param keyString Private key as JSON array or base58 string
@@ -11660,7 +11868,7 @@ Cause: ${err.message}`);
11660
11868
  TOKEN_PROGRAM_ID6
11661
11869
  );
11662
11870
  const [creatorFeeTreasury] = PublicKey13.findProgramAddressSync(
11663
- [Buffer.from("creator_fee_treasury"), creator.toBuffer()],
11871
+ [Buffer.from("creator_fee_treasury"), creator.toBuffer(), collateralTokenMint.toBuffer()],
11664
11872
  this.client.programId
11665
11873
  );
11666
11874
  try {
@@ -12251,4 +12459,4 @@ export {
12251
12459
  RedemptionModule,
12252
12460
  PNPClient
12253
12461
  };
12254
- //# sourceMappingURL=chunk-PODGM4UD.js.map
12462
+ //# sourceMappingURL=chunk-RJ2IJGCX.js.map