@elmntl/jlpd-sdk 0.1.3 → 0.1.4

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
@@ -3135,10 +3135,17 @@ declare class JlpdClient {
3135
3135
  readonly program: Program<JlpDProgram>;
3136
3136
  readonly vaultPda: PublicKey;
3137
3137
  readonly vaultBump: number;
3138
+ readonly jupiterApiKey?: string;
3138
3139
  private readonly poolContextCache;
3139
- constructor(connection: Connection, programId?: PublicKey);
3140
- static mainnet(connection: Connection): JlpdClient;
3141
- static devnet(connection: Connection): JlpdClient;
3140
+ constructor(connection: Connection, programId?: PublicKey, options?: {
3141
+ jupiterApiKey?: string;
3142
+ });
3143
+ static mainnet(connection: Connection, options?: {
3144
+ jupiterApiKey?: string;
3145
+ }): JlpdClient;
3146
+ static devnet(connection: Connection, options?: {
3147
+ jupiterApiKey?: string;
3148
+ }): JlpdClient;
3142
3149
  fetchVault(): Promise<JLPVault | null>;
3143
3150
  fetchStv(baseMint: PublicKey): Promise<STV | null>;
3144
3151
  fetchExchangeRate(poolName: PoolName): Promise<ExchangeRateResult>;
@@ -3411,11 +3418,11 @@ declare function parseRewardsRateModel(data: Buffer): RewardsRateModelData;
3411
3418
  /**
3412
3419
  * Get a swap quote from Jupiter API
3413
3420
  */
3414
- declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, slippageBps?: number, maxAccounts?: number): Promise<JupiterQuoteResponse>;
3421
+ declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, slippageBps?: number, maxAccounts?: number, apiKey?: string): Promise<JupiterQuoteResponse>;
3415
3422
  /**
3416
3423
  * Get swap instructions from Jupiter API
3417
3424
  */
3418
- declare function getJupiterSwapInstructions(quote: JupiterQuoteResponse, userPubkey: PublicKey): Promise<JupiterSwapInstructionsResponse>;
3425
+ declare function getJupiterSwapInstructions(quote: JupiterQuoteResponse, userPubkey: PublicKey, apiKey?: string): Promise<JupiterSwapInstructionsResponse>;
3419
3426
  /**
3420
3427
  * Parse swap instruction to extract remaining accounts
3421
3428
  */
@@ -3427,7 +3434,7 @@ declare function fetchAddressLookupTables(connection: Connection, addresses: str
3427
3434
  /**
3428
3435
  * Build complete swap data for CPI including quote, instructions, and ALTs
3429
3436
  */
3430
- declare function buildSwapData(connection: Connection, inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, userPubkey: PublicKey, slippageBps?: number, maxAccounts?: number): Promise<{
3437
+ declare function buildSwapData(connection: Connection, inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, userPubkey: PublicKey, slippageBps?: number, maxAccounts?: number, apiKey?: string): Promise<{
3431
3438
  quote: JupiterQuoteResponse;
3432
3439
  instructions: JupiterSwapInstructionsResponse;
3433
3440
  remainingAccounts: AccountMeta[];
@@ -3462,10 +3469,10 @@ type JupiterPriceResponse = {
3462
3469
  * Fetch token price from Jupiter Price API V3
3463
3470
  *
3464
3471
  * @param mint Token mint address
3465
- * @param apiKey Jupiter API key (uses default if not provided)
3472
+ * @param apiKey Jupiter API key
3466
3473
  * @returns Price in USD as a number, or null if unavailable
3467
3474
  */
3468
- declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<number | null>;
3475
+ declare function fetchJupiterPriceUsd(mint: string, apiKey: string): Promise<number | null>;
3469
3476
  /**
3470
3477
  * Fetch JLP price and convert to 8 decimals for on-chain use
3471
3478
  *
@@ -3474,7 +3481,7 @@ declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<nu
3474
3481
  *
3475
3482
  * @param jlpMint JLP token mint address
3476
3483
  * @param fallbackPrice Fallback price in USD if API fails (default: $4.60)
3477
- * @param apiKey Jupiter API key (uses default if not provided)
3484
+ * @param apiKey Jupiter API key
3478
3485
  * @returns Price as BN with 8 decimals (e.g., $4.60 -> 460_000_000)
3479
3486
  *
3480
3487
  * @example
@@ -3487,7 +3494,7 @@ declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<nu
3487
3494
  * });
3488
3495
  * ```
3489
3496
  */
3490
- declare function fetchJlpRate(jlpMint: string, fallbackPrice?: number, apiKey?: string): Promise<BN>;
3497
+ declare function fetchJlpRate(jlpMint: string, fallbackPrice: number | undefined, apiKey: string): Promise<BN>;
3491
3498
 
3492
3499
  interface InitOrUpdateJlpVaultParams {
3493
3500
  jlpMint: PublicKey | null;
package/dist/index.d.ts CHANGED
@@ -3135,10 +3135,17 @@ declare class JlpdClient {
3135
3135
  readonly program: Program<JlpDProgram>;
3136
3136
  readonly vaultPda: PublicKey;
3137
3137
  readonly vaultBump: number;
3138
+ readonly jupiterApiKey?: string;
3138
3139
  private readonly poolContextCache;
3139
- constructor(connection: Connection, programId?: PublicKey);
3140
- static mainnet(connection: Connection): JlpdClient;
3141
- static devnet(connection: Connection): JlpdClient;
3140
+ constructor(connection: Connection, programId?: PublicKey, options?: {
3141
+ jupiterApiKey?: string;
3142
+ });
3143
+ static mainnet(connection: Connection, options?: {
3144
+ jupiterApiKey?: string;
3145
+ }): JlpdClient;
3146
+ static devnet(connection: Connection, options?: {
3147
+ jupiterApiKey?: string;
3148
+ }): JlpdClient;
3142
3149
  fetchVault(): Promise<JLPVault | null>;
3143
3150
  fetchStv(baseMint: PublicKey): Promise<STV | null>;
3144
3151
  fetchExchangeRate(poolName: PoolName): Promise<ExchangeRateResult>;
@@ -3411,11 +3418,11 @@ declare function parseRewardsRateModel(data: Buffer): RewardsRateModelData;
3411
3418
  /**
3412
3419
  * Get a swap quote from Jupiter API
3413
3420
  */
3414
- declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, slippageBps?: number, maxAccounts?: number): Promise<JupiterQuoteResponse>;
3421
+ declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, slippageBps?: number, maxAccounts?: number, apiKey?: string): Promise<JupiterQuoteResponse>;
3415
3422
  /**
3416
3423
  * Get swap instructions from Jupiter API
3417
3424
  */
3418
- declare function getJupiterSwapInstructions(quote: JupiterQuoteResponse, userPubkey: PublicKey): Promise<JupiterSwapInstructionsResponse>;
3425
+ declare function getJupiterSwapInstructions(quote: JupiterQuoteResponse, userPubkey: PublicKey, apiKey?: string): Promise<JupiterSwapInstructionsResponse>;
3419
3426
  /**
3420
3427
  * Parse swap instruction to extract remaining accounts
3421
3428
  */
@@ -3427,7 +3434,7 @@ declare function fetchAddressLookupTables(connection: Connection, addresses: str
3427
3434
  /**
3428
3435
  * Build complete swap data for CPI including quote, instructions, and ALTs
3429
3436
  */
3430
- declare function buildSwapData(connection: Connection, inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, userPubkey: PublicKey, slippageBps?: number, maxAccounts?: number): Promise<{
3437
+ declare function buildSwapData(connection: Connection, inputMint: PublicKey, outputMint: PublicKey, amount: bigint | number, userPubkey: PublicKey, slippageBps?: number, maxAccounts?: number, apiKey?: string): Promise<{
3431
3438
  quote: JupiterQuoteResponse;
3432
3439
  instructions: JupiterSwapInstructionsResponse;
3433
3440
  remainingAccounts: AccountMeta[];
@@ -3462,10 +3469,10 @@ type JupiterPriceResponse = {
3462
3469
  * Fetch token price from Jupiter Price API V3
3463
3470
  *
3464
3471
  * @param mint Token mint address
3465
- * @param apiKey Jupiter API key (uses default if not provided)
3472
+ * @param apiKey Jupiter API key
3466
3473
  * @returns Price in USD as a number, or null if unavailable
3467
3474
  */
3468
- declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<number | null>;
3475
+ declare function fetchJupiterPriceUsd(mint: string, apiKey: string): Promise<number | null>;
3469
3476
  /**
3470
3477
  * Fetch JLP price and convert to 8 decimals for on-chain use
3471
3478
  *
@@ -3474,7 +3481,7 @@ declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<nu
3474
3481
  *
3475
3482
  * @param jlpMint JLP token mint address
3476
3483
  * @param fallbackPrice Fallback price in USD if API fails (default: $4.60)
3477
- * @param apiKey Jupiter API key (uses default if not provided)
3484
+ * @param apiKey Jupiter API key
3478
3485
  * @returns Price as BN with 8 decimals (e.g., $4.60 -> 460_000_000)
3479
3486
  *
3480
3487
  * @example
@@ -3487,7 +3494,7 @@ declare function fetchJupiterPriceUsd(mint: string, apiKey?: string): Promise<nu
3487
3494
  * });
3488
3495
  * ```
3489
3496
  */
3490
- declare function fetchJlpRate(jlpMint: string, fallbackPrice?: number, apiKey?: string): Promise<BN>;
3497
+ declare function fetchJlpRate(jlpMint: string, fallbackPrice: number | undefined, apiKey: string): Promise<BN>;
3491
3498
 
3492
3499
  interface InitOrUpdateJlpVaultParams {
3493
3500
  jlpMint: PublicKey | null;
package/dist/index.js CHANGED
@@ -3644,7 +3644,7 @@ function parseRewardsRateModel(data) {
3644
3644
 
3645
3645
  // src/jupiter/swap.ts
3646
3646
  var import_web38 = require("@solana/web3.js");
3647
- var JUPITER_API_BASE = "https://lite-api.jup.ag/swap/v1";
3647
+ var JUPITER_API_BASE = "https://api.jup.ag/swap/v1";
3648
3648
  var DEFAULT_TIMEOUT_MS = 3e4;
3649
3649
  var MAX_RETRIES = 3;
3650
3650
  var RETRY_DELAY_MS = 1e3;
@@ -3685,7 +3685,7 @@ async function fetchWithRetry(url, options = {}, timeoutMs = DEFAULT_TIMEOUT_MS,
3685
3685
  }
3686
3686
  throw lastError ?? new Error("Unknown error during fetch");
3687
3687
  }
3688
- async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40) {
3688
+ async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40, apiKey) {
3689
3689
  const params = new URLSearchParams({
3690
3690
  inputMint: inputMint.toBase58(),
3691
3691
  outputMint: outputMint.toBase58(),
@@ -3694,26 +3694,35 @@ async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50,
3694
3694
  maxAccounts: maxAccounts.toString()
3695
3695
  });
3696
3696
  const url = `${JUPITER_API_BASE}/quote?${params.toString()}`;
3697
- const response = await fetchWithRetry(url);
3697
+ const headers = {};
3698
+ if (apiKey) {
3699
+ headers["x-api-key"] = apiKey;
3700
+ }
3701
+ const response = await fetchWithRetry(url, { headers });
3698
3702
  const data = await response.json();
3699
3703
  if (data.error) {
3700
3704
  throw new Error(`Jupiter quote error: ${data.error}`);
3701
3705
  }
3702
3706
  return data;
3703
3707
  }
3704
- async function getJupiterSwapInstructions(quote, userPubkey) {
3708
+ async function getJupiterSwapInstructions(quote, userPubkey, apiKey) {
3705
3709
  const url = `${JUPITER_API_BASE}/swap-instructions`;
3706
3710
  const body = {
3707
3711
  quoteResponse: quote,
3708
3712
  userPublicKey: userPubkey.toBase58(),
3709
- wrapAndUnwrapSol: true,
3710
- useSharedAccounts: true,
3713
+ wrapAndUnwrapSol: false,
3711
3714
  dynamicComputeUnitLimit: true,
3712
- skipUserAccountsRpcCalls: false
3715
+ skipUserAccountsRpcCalls: true
3716
+ };
3717
+ const headers = {
3718
+ "Content-Type": "application/json"
3713
3719
  };
3720
+ if (apiKey) {
3721
+ headers["x-api-key"] = apiKey;
3722
+ }
3714
3723
  const response = await fetchWithRetry(url, {
3715
3724
  method: "POST",
3716
- headers: { "Content-Type": "application/json" },
3725
+ headers,
3717
3726
  body: JSON.stringify(body)
3718
3727
  });
3719
3728
  const data = await response.json();
@@ -3725,7 +3734,8 @@ async function getJupiterSwapInstructions(quote, userPubkey) {
3725
3734
  function parseSwapRemainingAccounts(swapInstruction) {
3726
3735
  return swapInstruction.accounts.map((acc) => ({
3727
3736
  pubkey: new import_web38.PublicKey(acc.pubkey),
3728
- isSigner: acc.isSigner,
3737
+ isSigner: false,
3738
+ // Always false for CPI — vault PDA signs via seeds
3729
3739
  isWritable: acc.isWritable
3730
3740
  }));
3731
3741
  }
@@ -3750,15 +3760,16 @@ async function fetchAddressLookupTables(connection, addresses) {
3750
3760
  }
3751
3761
  return tables;
3752
3762
  }
3753
- async function buildSwapData(connection, inputMint, outputMint, amount, userPubkey, slippageBps = 50, maxAccounts = 40) {
3763
+ async function buildSwapData(connection, inputMint, outputMint, amount, userPubkey, slippageBps = 50, maxAccounts = 40, apiKey) {
3754
3764
  const quote = await getJupiterQuote(
3755
3765
  inputMint,
3756
3766
  outputMint,
3757
3767
  amount,
3758
3768
  slippageBps,
3759
- maxAccounts
3769
+ maxAccounts,
3770
+ apiKey
3760
3771
  );
3761
- const instructions = await getJupiterSwapInstructions(quote, userPubkey);
3772
+ const instructions = await getJupiterSwapInstructions(quote, userPubkey, apiKey);
3762
3773
  const remainingAccounts = parseSwapRemainingAccounts(instructions.swapInstruction);
3763
3774
  const addressLookupTables = await fetchAddressLookupTables(
3764
3775
  connection,
@@ -3774,8 +3785,7 @@ async function buildSwapData(connection, inputMint, outputMint, amount, userPubk
3774
3785
 
3775
3786
  // src/jupiter/price.ts
3776
3787
  var import_anchor5 = require("@coral-xyz/anchor");
3777
- var DEFAULT_API_KEY = "REDACTED_JUPITER_API_KEY";
3778
- async function fetchJupiterPriceUsd(mint, apiKey = DEFAULT_API_KEY) {
3788
+ async function fetchJupiterPriceUsd(mint, apiKey) {
3779
3789
  const url = `https://api.jup.ag/price/v3?ids=${mint}`;
3780
3790
  try {
3781
3791
  const response = await fetch(url, {
@@ -3799,7 +3809,7 @@ async function fetchJupiterPriceUsd(mint, apiKey = DEFAULT_API_KEY) {
3799
3809
  return null;
3800
3810
  }
3801
3811
  }
3802
- async function fetchJlpRate(jlpMint, fallbackPrice = 4.6, apiKey = DEFAULT_API_KEY) {
3812
+ async function fetchJlpRate(jlpMint, fallbackPrice = 4.6, apiKey) {
3803
3813
  const priceUsd = await fetchJupiterPriceUsd(jlpMint, apiKey);
3804
3814
  if (priceUsd === null) {
3805
3815
  console.warn(`Using fallback JLP price: $${fallbackPrice}`);
@@ -3931,7 +3941,7 @@ async function createSwapJlxJlxInstruction(program, params, accounts, remainingA
3931
3941
  toIndex: params.toIndex,
3932
3942
  amountIn: params.amountIn,
3933
3943
  minOut: params.minOut,
3934
- jupiterData: Array.from(params.jupiterData)
3944
+ jupiterData: params.jupiterData
3935
3945
  }).accounts({
3936
3946
  manager: accounts.manager,
3937
3947
  jlpVault: accounts.jlpVault,
@@ -3949,7 +3959,7 @@ async function createSwapJlxJlpInstruction(program, params, accounts, remainingA
3949
3959
  direction: toAnchorSwapDirection(params.direction),
3950
3960
  amountIn: params.amountIn,
3951
3961
  expectedAmountOut: params.expectedAmountOut,
3952
- jupiterData: Array.from(params.jupiterData)
3962
+ jupiterData: params.jupiterData
3953
3963
  }).accounts({
3954
3964
  manager: accounts.manager,
3955
3965
  jlpVault: accounts.jlpVault,
@@ -4008,7 +4018,7 @@ var JlpdClientError = class extends Error {
4008
4018
  }
4009
4019
  };
4010
4020
  var JlpdClient = class _JlpdClient {
4011
- constructor(connection, programId = JLPD_PROGRAM_ID) {
4021
+ constructor(connection, programId = JLPD_PROGRAM_ID, options) {
4012
4022
  // Cache for PoolContext instances (avoids re-deriving PDAs/ATAs)
4013
4023
  this.poolContextCache = /* @__PURE__ */ new Map();
4014
4024
  this.connection = connection;
@@ -4017,15 +4027,16 @@ var JlpdClient = class _JlpdClient {
4017
4027
  this.vaultPda = vaultPda;
4018
4028
  this.vaultBump = vaultBump;
4019
4029
  this.program = createProgram(connection);
4030
+ this.jupiterApiKey = options?.jupiterApiKey;
4020
4031
  }
4021
- static mainnet(connection) {
4022
- return new _JlpdClient(connection, JLPD_PROGRAM_ID);
4032
+ static mainnet(connection, options) {
4033
+ return new _JlpdClient(connection, JLPD_PROGRAM_ID, options);
4023
4034
  }
4024
- static devnet(connection) {
4035
+ static devnet(connection, options) {
4025
4036
  const devnetProgramId = new import_web39.PublicKey(
4026
4037
  "AcVcAihjB9Z3Lg3ZiboWxni2sTzXUrrsF3unGX4ntn6p"
4027
4038
  );
4028
- return new _JlpdClient(connection, devnetProgramId);
4039
+ return new _JlpdClient(connection, devnetProgramId, options);
4029
4040
  }
4030
4041
  // Fetch vault account
4031
4042
  async fetchVault() {
@@ -4404,9 +4415,11 @@ var SwapContext = class {
4404
4415
  inputMint,
4405
4416
  outputMint,
4406
4417
  BigInt(params.amountIn.toString()),
4407
- params.slippageBps ?? 30
4418
+ params.slippageBps ?? 30,
4419
+ 40,
4420
+ this.client.jupiterApiKey
4408
4421
  );
4409
- const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda);
4422
+ const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda, this.client.jupiterApiKey);
4410
4423
  const remainingAccounts = parseSwapRemainingAccounts(swapIxs.swapInstruction);
4411
4424
  const alts = await fetchAddressLookupTables(
4412
4425
  this.client.connection,
@@ -4434,7 +4447,7 @@ var SwapContext = class {
4434
4447
  const computeIx = import_web39.ComputeBudgetProgram.setComputeUnitLimit({
4435
4448
  units: params.quote.computeUnitLimit
4436
4449
  });
4437
- const jupiterProgram = params.quote.remainingAccounts[0]?.pubkey ?? import_web39.PublicKey.default;
4450
+ const jupiterProgram = JUPITER_SWAP_PROGRAM_ID;
4438
4451
  const swapIx = await createSwapJlxJlpInstruction(
4439
4452
  this.client.program,
4440
4453
  {
@@ -4475,9 +4488,11 @@ var SwapContext = class {
4475
4488
  inputMint,
4476
4489
  outputMint,
4477
4490
  BigInt(params.amountIn.toString()),
4478
- params.slippageBps ?? 30
4491
+ params.slippageBps ?? 30,
4492
+ 40,
4493
+ this.client.jupiterApiKey
4479
4494
  );
4480
- const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda);
4495
+ const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda, this.client.jupiterApiKey);
4481
4496
  const remainingAccounts = parseSwapRemainingAccounts(swapIxs.swapInstruction);
4482
4497
  const alts = await fetchAddressLookupTables(
4483
4498
  this.client.connection,
@@ -4508,7 +4523,7 @@ var SwapContext = class {
4508
4523
  const computeIx = import_web39.ComputeBudgetProgram.setComputeUnitLimit({
4509
4524
  units: params.quote.computeUnitLimit
4510
4525
  });
4511
- const jupiterProgram = params.quote.remainingAccounts[0]?.pubkey ?? import_web39.PublicKey.default;
4526
+ const jupiterProgram = JUPITER_SWAP_PROGRAM_ID;
4512
4527
  const swapIx = await createSwapJlxJlxInstruction(
4513
4528
  this.client.program,
4514
4529
  {
package/dist/index.mjs CHANGED
@@ -3551,7 +3551,7 @@ import {
3551
3551
  PublicKey as PublicKey7,
3552
3552
  AddressLookupTableAccount
3553
3553
  } from "@solana/web3.js";
3554
- var JUPITER_API_BASE = "https://lite-api.jup.ag/swap/v1";
3554
+ var JUPITER_API_BASE = "https://api.jup.ag/swap/v1";
3555
3555
  var DEFAULT_TIMEOUT_MS = 3e4;
3556
3556
  var MAX_RETRIES = 3;
3557
3557
  var RETRY_DELAY_MS = 1e3;
@@ -3592,7 +3592,7 @@ async function fetchWithRetry(url, options = {}, timeoutMs = DEFAULT_TIMEOUT_MS,
3592
3592
  }
3593
3593
  throw lastError ?? new Error("Unknown error during fetch");
3594
3594
  }
3595
- async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40) {
3595
+ async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50, maxAccounts = 40, apiKey) {
3596
3596
  const params = new URLSearchParams({
3597
3597
  inputMint: inputMint.toBase58(),
3598
3598
  outputMint: outputMint.toBase58(),
@@ -3601,26 +3601,35 @@ async function getJupiterQuote(inputMint, outputMint, amount, slippageBps = 50,
3601
3601
  maxAccounts: maxAccounts.toString()
3602
3602
  });
3603
3603
  const url = `${JUPITER_API_BASE}/quote?${params.toString()}`;
3604
- const response = await fetchWithRetry(url);
3604
+ const headers = {};
3605
+ if (apiKey) {
3606
+ headers["x-api-key"] = apiKey;
3607
+ }
3608
+ const response = await fetchWithRetry(url, { headers });
3605
3609
  const data = await response.json();
3606
3610
  if (data.error) {
3607
3611
  throw new Error(`Jupiter quote error: ${data.error}`);
3608
3612
  }
3609
3613
  return data;
3610
3614
  }
3611
- async function getJupiterSwapInstructions(quote, userPubkey) {
3615
+ async function getJupiterSwapInstructions(quote, userPubkey, apiKey) {
3612
3616
  const url = `${JUPITER_API_BASE}/swap-instructions`;
3613
3617
  const body = {
3614
3618
  quoteResponse: quote,
3615
3619
  userPublicKey: userPubkey.toBase58(),
3616
- wrapAndUnwrapSol: true,
3617
- useSharedAccounts: true,
3620
+ wrapAndUnwrapSol: false,
3618
3621
  dynamicComputeUnitLimit: true,
3619
- skipUserAccountsRpcCalls: false
3622
+ skipUserAccountsRpcCalls: true
3623
+ };
3624
+ const headers = {
3625
+ "Content-Type": "application/json"
3620
3626
  };
3627
+ if (apiKey) {
3628
+ headers["x-api-key"] = apiKey;
3629
+ }
3621
3630
  const response = await fetchWithRetry(url, {
3622
3631
  method: "POST",
3623
- headers: { "Content-Type": "application/json" },
3632
+ headers,
3624
3633
  body: JSON.stringify(body)
3625
3634
  });
3626
3635
  const data = await response.json();
@@ -3632,7 +3641,8 @@ async function getJupiterSwapInstructions(quote, userPubkey) {
3632
3641
  function parseSwapRemainingAccounts(swapInstruction) {
3633
3642
  return swapInstruction.accounts.map((acc) => ({
3634
3643
  pubkey: new PublicKey7(acc.pubkey),
3635
- isSigner: acc.isSigner,
3644
+ isSigner: false,
3645
+ // Always false for CPI — vault PDA signs via seeds
3636
3646
  isWritable: acc.isWritable
3637
3647
  }));
3638
3648
  }
@@ -3657,15 +3667,16 @@ async function fetchAddressLookupTables(connection, addresses) {
3657
3667
  }
3658
3668
  return tables;
3659
3669
  }
3660
- async function buildSwapData(connection, inputMint, outputMint, amount, userPubkey, slippageBps = 50, maxAccounts = 40) {
3670
+ async function buildSwapData(connection, inputMint, outputMint, amount, userPubkey, slippageBps = 50, maxAccounts = 40, apiKey) {
3661
3671
  const quote = await getJupiterQuote(
3662
3672
  inputMint,
3663
3673
  outputMint,
3664
3674
  amount,
3665
3675
  slippageBps,
3666
- maxAccounts
3676
+ maxAccounts,
3677
+ apiKey
3667
3678
  );
3668
- const instructions = await getJupiterSwapInstructions(quote, userPubkey);
3679
+ const instructions = await getJupiterSwapInstructions(quote, userPubkey, apiKey);
3669
3680
  const remainingAccounts = parseSwapRemainingAccounts(instructions.swapInstruction);
3670
3681
  const addressLookupTables = await fetchAddressLookupTables(
3671
3682
  connection,
@@ -3681,8 +3692,7 @@ async function buildSwapData(connection, inputMint, outputMint, amount, userPubk
3681
3692
 
3682
3693
  // src/jupiter/price.ts
3683
3694
  import { BN as BN4 } from "@coral-xyz/anchor";
3684
- var DEFAULT_API_KEY = "REDACTED_JUPITER_API_KEY";
3685
- async function fetchJupiterPriceUsd(mint, apiKey = DEFAULT_API_KEY) {
3695
+ async function fetchJupiterPriceUsd(mint, apiKey) {
3686
3696
  const url = `https://api.jup.ag/price/v3?ids=${mint}`;
3687
3697
  try {
3688
3698
  const response = await fetch(url, {
@@ -3706,7 +3716,7 @@ async function fetchJupiterPriceUsd(mint, apiKey = DEFAULT_API_KEY) {
3706
3716
  return null;
3707
3717
  }
3708
3718
  }
3709
- async function fetchJlpRate(jlpMint, fallbackPrice = 4.6, apiKey = DEFAULT_API_KEY) {
3719
+ async function fetchJlpRate(jlpMint, fallbackPrice = 4.6, apiKey) {
3710
3720
  const priceUsd = await fetchJupiterPriceUsd(jlpMint, apiKey);
3711
3721
  if (priceUsd === null) {
3712
3722
  console.warn(`Using fallback JLP price: $${fallbackPrice}`);
@@ -3838,7 +3848,7 @@ async function createSwapJlxJlxInstruction(program, params, accounts, remainingA
3838
3848
  toIndex: params.toIndex,
3839
3849
  amountIn: params.amountIn,
3840
3850
  minOut: params.minOut,
3841
- jupiterData: Array.from(params.jupiterData)
3851
+ jupiterData: params.jupiterData
3842
3852
  }).accounts({
3843
3853
  manager: accounts.manager,
3844
3854
  jlpVault: accounts.jlpVault,
@@ -3856,7 +3866,7 @@ async function createSwapJlxJlpInstruction(program, params, accounts, remainingA
3856
3866
  direction: toAnchorSwapDirection(params.direction),
3857
3867
  amountIn: params.amountIn,
3858
3868
  expectedAmountOut: params.expectedAmountOut,
3859
- jupiterData: Array.from(params.jupiterData)
3869
+ jupiterData: params.jupiterData
3860
3870
  }).accounts({
3861
3871
  manager: accounts.manager,
3862
3872
  jlpVault: accounts.jlpVault,
@@ -3915,7 +3925,7 @@ var JlpdClientError = class extends Error {
3915
3925
  }
3916
3926
  };
3917
3927
  var JlpdClient = class _JlpdClient {
3918
- constructor(connection, programId = JLPD_PROGRAM_ID) {
3928
+ constructor(connection, programId = JLPD_PROGRAM_ID, options) {
3919
3929
  // Cache for PoolContext instances (avoids re-deriving PDAs/ATAs)
3920
3930
  this.poolContextCache = /* @__PURE__ */ new Map();
3921
3931
  this.connection = connection;
@@ -3924,15 +3934,16 @@ var JlpdClient = class _JlpdClient {
3924
3934
  this.vaultPda = vaultPda;
3925
3935
  this.vaultBump = vaultBump;
3926
3936
  this.program = createProgram(connection);
3937
+ this.jupiterApiKey = options?.jupiterApiKey;
3927
3938
  }
3928
- static mainnet(connection) {
3929
- return new _JlpdClient(connection, JLPD_PROGRAM_ID);
3939
+ static mainnet(connection, options) {
3940
+ return new _JlpdClient(connection, JLPD_PROGRAM_ID, options);
3930
3941
  }
3931
- static devnet(connection) {
3942
+ static devnet(connection, options) {
3932
3943
  const devnetProgramId = new PublicKey8(
3933
3944
  "AcVcAihjB9Z3Lg3ZiboWxni2sTzXUrrsF3unGX4ntn6p"
3934
3945
  );
3935
- return new _JlpdClient(connection, devnetProgramId);
3946
+ return new _JlpdClient(connection, devnetProgramId, options);
3936
3947
  }
3937
3948
  // Fetch vault account
3938
3949
  async fetchVault() {
@@ -4311,9 +4322,11 @@ var SwapContext = class {
4311
4322
  inputMint,
4312
4323
  outputMint,
4313
4324
  BigInt(params.amountIn.toString()),
4314
- params.slippageBps ?? 30
4325
+ params.slippageBps ?? 30,
4326
+ 40,
4327
+ this.client.jupiterApiKey
4315
4328
  );
4316
- const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda);
4329
+ const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda, this.client.jupiterApiKey);
4317
4330
  const remainingAccounts = parseSwapRemainingAccounts(swapIxs.swapInstruction);
4318
4331
  const alts = await fetchAddressLookupTables(
4319
4332
  this.client.connection,
@@ -4341,7 +4354,7 @@ var SwapContext = class {
4341
4354
  const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
4342
4355
  units: params.quote.computeUnitLimit
4343
4356
  });
4344
- const jupiterProgram = params.quote.remainingAccounts[0]?.pubkey ?? PublicKey8.default;
4357
+ const jupiterProgram = JUPITER_SWAP_PROGRAM_ID;
4345
4358
  const swapIx = await createSwapJlxJlpInstruction(
4346
4359
  this.client.program,
4347
4360
  {
@@ -4382,9 +4395,11 @@ var SwapContext = class {
4382
4395
  inputMint,
4383
4396
  outputMint,
4384
4397
  BigInt(params.amountIn.toString()),
4385
- params.slippageBps ?? 30
4398
+ params.slippageBps ?? 30,
4399
+ 40,
4400
+ this.client.jupiterApiKey
4386
4401
  );
4387
- const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda);
4402
+ const swapIxs = await getJupiterSwapInstructions(quote, this.client.vaultPda, this.client.jupiterApiKey);
4388
4403
  const remainingAccounts = parseSwapRemainingAccounts(swapIxs.swapInstruction);
4389
4404
  const alts = await fetchAddressLookupTables(
4390
4405
  this.client.connection,
@@ -4415,7 +4430,7 @@ var SwapContext = class {
4415
4430
  const computeIx = ComputeBudgetProgram.setComputeUnitLimit({
4416
4431
  units: params.quote.computeUnitLimit
4417
4432
  });
4418
- const jupiterProgram = params.quote.remainingAccounts[0]?.pubkey ?? PublicKey8.default;
4433
+ const jupiterProgram = JUPITER_SWAP_PROGRAM_ID;
4419
4434
  const swapIx = await createSwapJlxJlxInstruction(
4420
4435
  this.client.program,
4421
4436
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elmntl/jlpd-sdk",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "SDK for JLP.D (JLP Deconstructed) by Elemental",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",