@meteora-ag/zap-sdk 1.1.0 → 1.1.1

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
@@ -1769,12 +1769,17 @@ declare enum DlmmDirectSwapQuoteRoute {
1769
1769
  Jupiter = 0,
1770
1770
  Dlmm = 1
1771
1771
  }
1772
- interface SwapQuoteResult {
1772
+ type SwapQuoteResult = {
1773
1773
  inAmount: BN;
1774
1774
  outAmount: BN;
1775
- route: DlmmDirectSwapQuoteRoute;
1776
- originalQuote: JupiterQuoteResponse | SwapQuote;
1777
- }
1775
+ route: DlmmDirectSwapQuoteRoute.Jupiter;
1776
+ originalQuote: JupiterQuoteResponse;
1777
+ } | {
1778
+ inAmount: BN;
1779
+ outAmount: BN;
1780
+ route: DlmmDirectSwapQuoteRoute.Dlmm;
1781
+ originalQuote: SwapQuote;
1782
+ };
1778
1783
  declare enum DlmmSwapType {
1779
1784
  XToY = 0,
1780
1785
  YToX = 1,
@@ -2229,7 +2234,7 @@ declare class Zap {
2229
2234
 
2230
2235
  declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, dynamicSlippage: boolean | undefined, onlyDirectRoutes: boolean, restrictIntermediateTokens: boolean, apiUrl?: string, apiKey?: string): Promise<JupiterQuoteResponse | null>;
2231
2236
  declare function getJupiterSwapInstruction(userPublicKey: PublicKey, quoteResponse: any, apiUrl?: string, apiKey?: string): Promise<JupiterSwapInstructionResponse>;
2232
- declare function buildJupiterSwapTransaction(user: PublicKey, inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number): Promise<{
2237
+ declare function buildJupiterSwapTransaction(user: PublicKey, inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, jupiterQuoteResponse?: JupiterQuoteResponse): Promise<{
2233
2238
  transaction: Transaction;
2234
2239
  quoteResponse: JupiterQuoteResponse;
2235
2240
  }>;
package/dist/index.d.ts CHANGED
@@ -1769,12 +1769,17 @@ declare enum DlmmDirectSwapQuoteRoute {
1769
1769
  Jupiter = 0,
1770
1770
  Dlmm = 1
1771
1771
  }
1772
- interface SwapQuoteResult {
1772
+ type SwapQuoteResult = {
1773
1773
  inAmount: BN;
1774
1774
  outAmount: BN;
1775
- route: DlmmDirectSwapQuoteRoute;
1776
- originalQuote: JupiterQuoteResponse | SwapQuote;
1777
- }
1775
+ route: DlmmDirectSwapQuoteRoute.Jupiter;
1776
+ originalQuote: JupiterQuoteResponse;
1777
+ } | {
1778
+ inAmount: BN;
1779
+ outAmount: BN;
1780
+ route: DlmmDirectSwapQuoteRoute.Dlmm;
1781
+ originalQuote: SwapQuote;
1782
+ };
1778
1783
  declare enum DlmmSwapType {
1779
1784
  XToY = 0,
1780
1785
  YToX = 1,
@@ -2229,7 +2234,7 @@ declare class Zap {
2229
2234
 
2230
2235
  declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, dynamicSlippage: boolean | undefined, onlyDirectRoutes: boolean, restrictIntermediateTokens: boolean, apiUrl?: string, apiKey?: string): Promise<JupiterQuoteResponse | null>;
2231
2236
  declare function getJupiterSwapInstruction(userPublicKey: PublicKey, quoteResponse: any, apiUrl?: string, apiKey?: string): Promise<JupiterSwapInstructionResponse>;
2232
- declare function buildJupiterSwapTransaction(user: PublicKey, inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number): Promise<{
2237
+ declare function buildJupiterSwapTransaction(user: PublicKey, inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, jupiterQuoteResponse?: JupiterQuoteResponse): Promise<{
2233
2238
  transaction: Transaction;
2234
2239
  quoteResponse: JupiterQuoteResponse;
2235
2240
  }>;
package/dist/index.js CHANGED
@@ -1737,14 +1737,18 @@ function getJupiterQuote(inputMint, outputMint, amount, maxAccounts, slippageBps
1737
1737
  dynamicSlippage: dynamicSlippage.toString()
1738
1738
  });
1739
1739
  const url = `${apiUrl}/swap/v1/quote?${params.toString()}`;
1740
- console.log(url);
1741
- const response = yield fetch(url, {
1742
- method: "GET",
1743
- headers: __spreadValues({
1744
- Accept: "application/json"
1745
- }, apiKey ? { "x-api-key": apiKey } : {})
1746
- });
1747
- if (!response.ok) {
1740
+ let response = null;
1741
+ try {
1742
+ response = yield fetch(url, {
1743
+ method: "GET",
1744
+ headers: __spreadValues({
1745
+ Accept: "application/json"
1746
+ }, apiKey ? { "x-api-key": apiKey } : {})
1747
+ });
1748
+ if (!response.ok) {
1749
+ return null;
1750
+ }
1751
+ } catch (error) {
1748
1752
  return null;
1749
1753
  }
1750
1754
  const result = yield response.json();
@@ -1758,27 +1762,32 @@ function getJupiterSwapInstruction(userPublicKey, quoteResponse, apiUrl = "https
1758
1762
  userPublicKey: userPublicKey.toString(),
1759
1763
  quoteResponse
1760
1764
  };
1761
- const response = yield fetch(url, {
1762
- method: "POST",
1763
- headers: __spreadValues({
1764
- "Content-Type": "application/json",
1765
- Accept: "application/json"
1766
- }, apiKey ? { "x-api-key": apiKey } : {}),
1767
- body: JSON.stringify(requestBody)
1768
- });
1769
- if (!response.ok) {
1770
- const errorText = yield response.text();
1771
- throw new Error(
1772
- `Jupiter swap instruction failed (${response.status}): ${errorText}`
1773
- );
1765
+ let response = null;
1766
+ try {
1767
+ response = yield fetch(url, {
1768
+ method: "POST",
1769
+ headers: __spreadValues({
1770
+ "Content-Type": "application/json",
1771
+ Accept: "application/json"
1772
+ }, apiKey ? { "x-api-key": apiKey } : {}),
1773
+ body: JSON.stringify(requestBody)
1774
+ });
1775
+ if (!response.ok) {
1776
+ const errorText = yield response.text();
1777
+ throw new Error(
1778
+ `Jupiter swap instruction failed (${response.status}): ${errorText}`
1779
+ );
1780
+ }
1781
+ } catch (error) {
1782
+ throw new Error(`Jupiter swap instruction failed to fetch`);
1774
1783
  }
1775
1784
  const result = yield response.json();
1776
1785
  return result;
1777
1786
  });
1778
1787
  }
1779
- function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAccounts, slippageBps) {
1788
+ function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse) {
1780
1789
  return __async(this, null, function* () {
1781
- const quoteResponse = yield getJupiterQuote(
1790
+ const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
1782
1791
  inputMint,
1783
1792
  outputMint,
1784
1793
  amount,
@@ -4117,7 +4126,8 @@ var Zap = class {
4117
4126
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
4118
4127
  directSwapEstimate.swapAmount,
4119
4128
  maxAccounts,
4120
- swapSlippageBps
4129
+ swapSlippageBps,
4130
+ swapQuote.originalQuote
4121
4131
  );
4122
4132
  swapTransactions.push(swapTx);
4123
4133
  } else {
@@ -4281,7 +4291,8 @@ var Zap = class {
4281
4291
  tokenXMint,
4282
4292
  swapAmountToXInLamports,
4283
4293
  maxAccounts,
4284
- swapSlippageBps
4294
+ swapSlippageBps,
4295
+ indirectSwapEstimate.swapToX
4285
4296
  );
4286
4297
  swapTransactions.push(swapToXTransaction);
4287
4298
  }
@@ -4292,7 +4303,8 @@ var Zap = class {
4292
4303
  tokenYMint,
4293
4304
  swapAmountToYInLamports,
4294
4305
  maxAccounts,
4295
- swapSlippageBps
4306
+ swapSlippageBps,
4307
+ indirectSwapEstimate.swapToY
4296
4308
  );
4297
4309
  swapTransactions.push(swapToYTransaction);
4298
4310
  }
@@ -4689,7 +4701,8 @@ var Zap = class {
4689
4701
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
4690
4702
  directSwapEstimate.swapAmount,
4691
4703
  maxAccounts,
4692
- swapSlippageBps
4704
+ swapSlippageBps,
4705
+ swapQuote.originalQuote
4693
4706
  );
4694
4707
  swapTransaction = swapTx;
4695
4708
  } else {
package/dist/index.mjs CHANGED
@@ -1665,14 +1665,18 @@ function getJupiterQuote(inputMint, outputMint, amount, maxAccounts, slippageBps
1665
1665
  dynamicSlippage: dynamicSlippage.toString()
1666
1666
  });
1667
1667
  const url = `${apiUrl}/swap/v1/quote?${params.toString()}`;
1668
- console.log(url);
1669
- const response = yield fetch(url, {
1670
- method: "GET",
1671
- headers: __spreadValues({
1672
- Accept: "application/json"
1673
- }, apiKey ? { "x-api-key": apiKey } : {})
1674
- });
1675
- if (!response.ok) {
1668
+ let response = null;
1669
+ try {
1670
+ response = yield fetch(url, {
1671
+ method: "GET",
1672
+ headers: __spreadValues({
1673
+ Accept: "application/json"
1674
+ }, apiKey ? { "x-api-key": apiKey } : {})
1675
+ });
1676
+ if (!response.ok) {
1677
+ return null;
1678
+ }
1679
+ } catch (error) {
1676
1680
  return null;
1677
1681
  }
1678
1682
  const result = yield response.json();
@@ -1686,27 +1690,32 @@ function getJupiterSwapInstruction(userPublicKey, quoteResponse, apiUrl = "https
1686
1690
  userPublicKey: userPublicKey.toString(),
1687
1691
  quoteResponse
1688
1692
  };
1689
- const response = yield fetch(url, {
1690
- method: "POST",
1691
- headers: __spreadValues({
1692
- "Content-Type": "application/json",
1693
- Accept: "application/json"
1694
- }, apiKey ? { "x-api-key": apiKey } : {}),
1695
- body: JSON.stringify(requestBody)
1696
- });
1697
- if (!response.ok) {
1698
- const errorText = yield response.text();
1699
- throw new Error(
1700
- `Jupiter swap instruction failed (${response.status}): ${errorText}`
1701
- );
1693
+ let response = null;
1694
+ try {
1695
+ response = yield fetch(url, {
1696
+ method: "POST",
1697
+ headers: __spreadValues({
1698
+ "Content-Type": "application/json",
1699
+ Accept: "application/json"
1700
+ }, apiKey ? { "x-api-key": apiKey } : {}),
1701
+ body: JSON.stringify(requestBody)
1702
+ });
1703
+ if (!response.ok) {
1704
+ const errorText = yield response.text();
1705
+ throw new Error(
1706
+ `Jupiter swap instruction failed (${response.status}): ${errorText}`
1707
+ );
1708
+ }
1709
+ } catch (error) {
1710
+ throw new Error(`Jupiter swap instruction failed to fetch`);
1702
1711
  }
1703
1712
  const result = yield response.json();
1704
1713
  return result;
1705
1714
  });
1706
1715
  }
1707
- function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAccounts, slippageBps) {
1716
+ function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse) {
1708
1717
  return __async(this, null, function* () {
1709
- const quoteResponse = yield getJupiterQuote(
1718
+ const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
1710
1719
  inputMint,
1711
1720
  outputMint,
1712
1721
  amount,
@@ -4097,7 +4106,8 @@ var Zap = class {
4097
4106
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
4098
4107
  directSwapEstimate.swapAmount,
4099
4108
  maxAccounts,
4100
- swapSlippageBps
4109
+ swapSlippageBps,
4110
+ swapQuote.originalQuote
4101
4111
  );
4102
4112
  swapTransactions.push(swapTx);
4103
4113
  } else {
@@ -4261,7 +4271,8 @@ var Zap = class {
4261
4271
  tokenXMint,
4262
4272
  swapAmountToXInLamports,
4263
4273
  maxAccounts,
4264
- swapSlippageBps
4274
+ swapSlippageBps,
4275
+ indirectSwapEstimate.swapToX
4265
4276
  );
4266
4277
  swapTransactions.push(swapToXTransaction);
4267
4278
  }
@@ -4272,7 +4283,8 @@ var Zap = class {
4272
4283
  tokenYMint,
4273
4284
  swapAmountToYInLamports,
4274
4285
  maxAccounts,
4275
- swapSlippageBps
4286
+ swapSlippageBps,
4287
+ indirectSwapEstimate.swapToY
4276
4288
  );
4277
4289
  swapTransactions.push(swapToYTransaction);
4278
4290
  }
@@ -4669,7 +4681,8 @@ var Zap = class {
4669
4681
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
4670
4682
  directSwapEstimate.swapAmount,
4671
4683
  maxAccounts,
4672
- swapSlippageBps
4684
+ swapSlippageBps,
4685
+ swapQuote.originalQuote
4673
4686
  );
4674
4687
  swapTransaction = swapTx;
4675
4688
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meteora-ag/zap-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A Typescript SDK for interacting with the Zap program on Meteora.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",