@meteora-ag/zap-sdk 1.1.2 → 1.2.0-rc.0
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/README.md +23 -1
- package/dist/index.d.mts +25 -8
- package/dist/index.d.ts +25 -8
- package/dist/index.js +257 -97
- package/dist/index.mjs +258 -99
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -74,6 +74,7 @@ __export(index_exports, {
|
|
|
74
74
|
BIN_ARRAY_INDEX_BOUND: () => BIN_ARRAY_INDEX_BOUND,
|
|
75
75
|
DAMM_V2_PROGRAM_ID: () => DAMM_V2_PROGRAM_ID,
|
|
76
76
|
DAMM_V2_SWAP_DISCRIMINATOR: () => DAMM_V2_SWAP_DISCRIMINATOR,
|
|
77
|
+
DEFAULT_JUPITER_API_URL: () => DEFAULT_JUPITER_API_URL,
|
|
77
78
|
DLMM_PROGRAM_ID: () => DLMM_PROGRAM_ID,
|
|
78
79
|
DLMM_SWAP_DISCRIMINATOR: () => DLMM_SWAP_DISCRIMINATOR,
|
|
79
80
|
DlmmDirectSwapQuoteRoute: () => DlmmDirectSwapQuoteRoute,
|
|
@@ -1723,9 +1724,63 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
|
|
|
1723
1724
|
})(DlmmSingleSided || {});
|
|
1724
1725
|
|
|
1725
1726
|
// src/helpers/jupiter.ts
|
|
1727
|
+
var import_web32 = require("@solana/web3.js");
|
|
1728
|
+
|
|
1729
|
+
// src/constants.ts
|
|
1726
1730
|
var import_web3 = require("@solana/web3.js");
|
|
1727
|
-
|
|
1728
|
-
|
|
1731
|
+
var import_bn = __toESM(require("bn.js"));
|
|
1732
|
+
var import_dlmm = require("@meteora-ag/dlmm");
|
|
1733
|
+
var ZAP_PROGRAM_ID = new import_web3.PublicKey(idl_default.address);
|
|
1734
|
+
var JUP_V6_PROGRAM_ID = new import_web3.PublicKey(
|
|
1735
|
+
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
|
|
1736
|
+
);
|
|
1737
|
+
var DAMM_V2_PROGRAM_ID = new import_web3.PublicKey(
|
|
1738
|
+
"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
|
|
1739
|
+
);
|
|
1740
|
+
var DLMM_PROGRAM_ID = new import_web3.PublicKey(
|
|
1741
|
+
"LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
|
|
1742
|
+
);
|
|
1743
|
+
var MEMO_PROGRAM_ID = new import_web3.PublicKey(
|
|
1744
|
+
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
|
|
1745
|
+
);
|
|
1746
|
+
var BIN_ARRAY_INDEX_BOUND = [
|
|
1747
|
+
import_dlmm.BIN_ARRAY_BITMAP_SIZE.mul(
|
|
1748
|
+
import_dlmm.EXTENSION_BINARRAY_BITMAP_SIZE.add(new import_bn.default(1))
|
|
1749
|
+
).neg(),
|
|
1750
|
+
import_dlmm.BIN_ARRAY_BITMAP_SIZE.mul(import_dlmm.EXTENSION_BINARRAY_BITMAP_SIZE.add(new import_bn.default(1))).sub(
|
|
1751
|
+
new import_bn.default(1)
|
|
1752
|
+
)
|
|
1753
|
+
];
|
|
1754
|
+
var AccountsType = {
|
|
1755
|
+
TransferHookX: {
|
|
1756
|
+
transferHookX: {}
|
|
1757
|
+
},
|
|
1758
|
+
TransferHookY: {
|
|
1759
|
+
transferHookY: {}
|
|
1760
|
+
},
|
|
1761
|
+
TransferHookReward: {
|
|
1762
|
+
transferHookReward: {}
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
var DLMM_SWAP_DISCRIMINATOR = [65, 75, 63, 76, 235, 91, 91, 136];
|
|
1766
|
+
var AMOUNT_IN_DLMM_OFFSET = 8;
|
|
1767
|
+
var AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
1768
|
+
var AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
1769
|
+
var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
1770
|
+
248,
|
|
1771
|
+
198,
|
|
1772
|
+
158,
|
|
1773
|
+
145,
|
|
1774
|
+
225,
|
|
1775
|
+
117,
|
|
1776
|
+
135,
|
|
1777
|
+
200
|
|
1778
|
+
];
|
|
1779
|
+
var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
|
|
1780
|
+
|
|
1781
|
+
// src/helpers/jupiter.ts
|
|
1782
|
+
function getJupiterQuote(_0, _1, _2, _3, _4) {
|
|
1783
|
+
return __async(this, arguments, function* (inputMint, outputMint, amount, maxAccounts, slippageBps, dynamicSlippage = false, onlyDirectRoutes, restrictIntermediateTokens, config = {}) {
|
|
1729
1784
|
const params = new URLSearchParams({
|
|
1730
1785
|
inputMint: inputMint.toString(),
|
|
1731
1786
|
outputMint: outputMint.toString(),
|
|
@@ -1736,14 +1791,14 @@ function getJupiterQuote(inputMint, outputMint, amount, maxAccounts, slippageBps
|
|
|
1736
1791
|
restrictIntermediateTokens: restrictIntermediateTokens.toString(),
|
|
1737
1792
|
dynamicSlippage: dynamicSlippage.toString()
|
|
1738
1793
|
});
|
|
1739
|
-
const url = `${
|
|
1794
|
+
const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
|
|
1740
1795
|
let response = null;
|
|
1741
1796
|
try {
|
|
1742
1797
|
response = yield fetch(url, {
|
|
1743
1798
|
method: "GET",
|
|
1744
1799
|
headers: __spreadValues({
|
|
1745
1800
|
Accept: "application/json"
|
|
1746
|
-
},
|
|
1801
|
+
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
|
|
1747
1802
|
});
|
|
1748
1803
|
if (!response.ok) {
|
|
1749
1804
|
return null;
|
|
@@ -1755,9 +1810,9 @@ function getJupiterQuote(inputMint, outputMint, amount, maxAccounts, slippageBps
|
|
|
1755
1810
|
return result;
|
|
1756
1811
|
});
|
|
1757
1812
|
}
|
|
1758
|
-
function getJupiterSwapInstruction(
|
|
1759
|
-
return __async(this,
|
|
1760
|
-
const url = `${
|
|
1813
|
+
function getJupiterSwapInstruction(_0, _1) {
|
|
1814
|
+
return __async(this, arguments, function* (userPublicKey, quoteResponse, config = {}) {
|
|
1815
|
+
const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/swap-instructions`;
|
|
1761
1816
|
const requestBody = {
|
|
1762
1817
|
userPublicKey: userPublicKey.toString(),
|
|
1763
1818
|
quoteResponse
|
|
@@ -1769,7 +1824,7 @@ function getJupiterSwapInstruction(userPublicKey, quoteResponse, apiUrl = "https
|
|
|
1769
1824
|
headers: __spreadValues({
|
|
1770
1825
|
"Content-Type": "application/json",
|
|
1771
1826
|
Accept: "application/json"
|
|
1772
|
-
},
|
|
1827
|
+
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
|
|
1773
1828
|
body: JSON.stringify(requestBody)
|
|
1774
1829
|
});
|
|
1775
1830
|
if (!response.ok) {
|
|
@@ -1785,8 +1840,8 @@ function getJupiterSwapInstruction(userPublicKey, quoteResponse, apiUrl = "https
|
|
|
1785
1840
|
return result;
|
|
1786
1841
|
});
|
|
1787
1842
|
}
|
|
1788
|
-
function buildJupiterSwapTransaction(
|
|
1789
|
-
return __async(this,
|
|
1843
|
+
function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
1844
|
+
return __async(this, arguments, function* (user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
|
|
1790
1845
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
1791
1846
|
inputMint,
|
|
1792
1847
|
outputMint,
|
|
@@ -1796,7 +1851,7 @@ function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAcc
|
|
|
1796
1851
|
false,
|
|
1797
1852
|
true,
|
|
1798
1853
|
true,
|
|
1799
|
-
|
|
1854
|
+
config
|
|
1800
1855
|
);
|
|
1801
1856
|
if (!quoteResponse) {
|
|
1802
1857
|
throw new Error(
|
|
@@ -1805,78 +1860,26 @@ function buildJupiterSwapTransaction(user, inputMint, outputMint, amount, maxAcc
|
|
|
1805
1860
|
}
|
|
1806
1861
|
const swapInstructionResponse = yield getJupiterSwapInstruction(
|
|
1807
1862
|
user,
|
|
1808
|
-
quoteResponse
|
|
1863
|
+
quoteResponse,
|
|
1864
|
+
config
|
|
1809
1865
|
);
|
|
1810
|
-
const instruction = new
|
|
1866
|
+
const instruction = new import_web32.TransactionInstruction({
|
|
1811
1867
|
keys: swapInstructionResponse.swapInstruction.accounts.map((item) => {
|
|
1812
1868
|
return {
|
|
1813
|
-
pubkey: new
|
|
1869
|
+
pubkey: new import_web32.PublicKey(item.pubkey),
|
|
1814
1870
|
isSigner: item.isSigner,
|
|
1815
1871
|
isWritable: item.isWritable
|
|
1816
1872
|
};
|
|
1817
1873
|
}),
|
|
1818
|
-
programId: new
|
|
1874
|
+
programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
|
|
1819
1875
|
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1820
1876
|
});
|
|
1821
|
-
return { transaction: new
|
|
1877
|
+
return { transaction: new import_web32.Transaction().add(instruction), quoteResponse };
|
|
1822
1878
|
});
|
|
1823
1879
|
}
|
|
1824
1880
|
|
|
1825
1881
|
// src/helpers/dammV2.ts
|
|
1826
1882
|
var import_spl_token = require("@solana/spl-token");
|
|
1827
|
-
|
|
1828
|
-
// src/constants.ts
|
|
1829
|
-
var import_web32 = require("@solana/web3.js");
|
|
1830
|
-
var import_bn = __toESM(require("bn.js"));
|
|
1831
|
-
var import_dlmm = require("@meteora-ag/dlmm");
|
|
1832
|
-
var ZAP_PROGRAM_ID = new import_web32.PublicKey(idl_default.address);
|
|
1833
|
-
var JUP_V6_PROGRAM_ID = new import_web32.PublicKey(
|
|
1834
|
-
"JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
|
|
1835
|
-
);
|
|
1836
|
-
var DAMM_V2_PROGRAM_ID = new import_web32.PublicKey(
|
|
1837
|
-
"cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
|
|
1838
|
-
);
|
|
1839
|
-
var DLMM_PROGRAM_ID = new import_web32.PublicKey(
|
|
1840
|
-
"LBUZKhRxPF3XUpBCjp4YzTKgLccjZhTSDM9YuVaPwxo"
|
|
1841
|
-
);
|
|
1842
|
-
var MEMO_PROGRAM_ID = new import_web32.PublicKey(
|
|
1843
|
-
"MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"
|
|
1844
|
-
);
|
|
1845
|
-
var BIN_ARRAY_INDEX_BOUND = [
|
|
1846
|
-
import_dlmm.BIN_ARRAY_BITMAP_SIZE.mul(
|
|
1847
|
-
import_dlmm.EXTENSION_BINARRAY_BITMAP_SIZE.add(new import_bn.default(1))
|
|
1848
|
-
).neg(),
|
|
1849
|
-
import_dlmm.BIN_ARRAY_BITMAP_SIZE.mul(import_dlmm.EXTENSION_BINARRAY_BITMAP_SIZE.add(new import_bn.default(1))).sub(
|
|
1850
|
-
new import_bn.default(1)
|
|
1851
|
-
)
|
|
1852
|
-
];
|
|
1853
|
-
var AccountsType = {
|
|
1854
|
-
TransferHookX: {
|
|
1855
|
-
transferHookX: {}
|
|
1856
|
-
},
|
|
1857
|
-
TransferHookY: {
|
|
1858
|
-
transferHookY: {}
|
|
1859
|
-
},
|
|
1860
|
-
TransferHookReward: {
|
|
1861
|
-
transferHookReward: {}
|
|
1862
|
-
}
|
|
1863
|
-
};
|
|
1864
|
-
var DLMM_SWAP_DISCRIMINATOR = [65, 75, 63, 76, 235, 91, 91, 136];
|
|
1865
|
-
var AMOUNT_IN_DLMM_OFFSET = 8;
|
|
1866
|
-
var AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
1867
|
-
var AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
1868
|
-
var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
1869
|
-
248,
|
|
1870
|
-
198,
|
|
1871
|
-
158,
|
|
1872
|
-
145,
|
|
1873
|
-
225,
|
|
1874
|
-
117,
|
|
1875
|
-
135,
|
|
1876
|
-
200
|
|
1877
|
-
];
|
|
1878
|
-
|
|
1879
|
-
// src/helpers/dammV2.ts
|
|
1880
1883
|
var import_cp_amm_sdk = require("@meteora-ag/cp-amm-sdk");
|
|
1881
1884
|
|
|
1882
1885
|
// src/helpers/pda.ts
|
|
@@ -2474,8 +2477,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2474
2477
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2475
2478
|
return new import_bn3.default(estimatedOutput.floor().toString());
|
|
2476
2479
|
}
|
|
2477
|
-
function getBestSwapQuoteJupiterDlmm(
|
|
2478
|
-
return __async(this,
|
|
2480
|
+
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
2481
|
+
return __async(this, arguments, function* (dlmm, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}) {
|
|
2479
2482
|
let dlmmQuoteResult = null;
|
|
2480
2483
|
try {
|
|
2481
2484
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2496,7 +2499,7 @@ function getBestSwapQuoteJupiterDlmm(dlmm, inMint, outMint, inAmount, swapSlippa
|
|
|
2496
2499
|
false,
|
|
2497
2500
|
true,
|
|
2498
2501
|
true,
|
|
2499
|
-
|
|
2502
|
+
config
|
|
2500
2503
|
);
|
|
2501
2504
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
2502
2505
|
inAmount: new import_bn3.default(jupiterQuoteResult.inAmount),
|
|
@@ -2619,7 +2622,8 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2619
2622
|
minDeltaId,
|
|
2620
2623
|
maxDeltaId,
|
|
2621
2624
|
strategy,
|
|
2622
|
-
singleSided
|
|
2625
|
+
singleSided,
|
|
2626
|
+
config = {}
|
|
2623
2627
|
}) {
|
|
2624
2628
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
2625
2629
|
const activeBin = yield dlmm.getActiveBin();
|
|
@@ -2651,7 +2655,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2651
2655
|
false,
|
|
2652
2656
|
true,
|
|
2653
2657
|
true,
|
|
2654
|
-
|
|
2658
|
+
config
|
|
2655
2659
|
);
|
|
2656
2660
|
if (!quote) {
|
|
2657
2661
|
throw new Error(
|
|
@@ -2681,7 +2685,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2681
2685
|
false,
|
|
2682
2686
|
true,
|
|
2683
2687
|
true,
|
|
2684
|
-
|
|
2688
|
+
config
|
|
2685
2689
|
),
|
|
2686
2690
|
getJupiterQuote(
|
|
2687
2691
|
inputTokenMint,
|
|
@@ -2692,7 +2696,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2692
2696
|
false,
|
|
2693
2697
|
true,
|
|
2694
2698
|
true,
|
|
2695
|
-
|
|
2699
|
+
config
|
|
2696
2700
|
)
|
|
2697
2701
|
]);
|
|
2698
2702
|
const quoteToX = quoteToXResult.status === "fulfilled" ? quoteToXResult.value : null;
|
|
@@ -2795,7 +2799,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2795
2799
|
false,
|
|
2796
2800
|
true,
|
|
2797
2801
|
true,
|
|
2798
|
-
|
|
2802
|
+
config
|
|
2799
2803
|
),
|
|
2800
2804
|
getJupiterQuote(
|
|
2801
2805
|
inputTokenMint,
|
|
@@ -2806,7 +2810,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2806
2810
|
false,
|
|
2807
2811
|
true,
|
|
2808
2812
|
true,
|
|
2809
|
-
|
|
2813
|
+
config
|
|
2810
2814
|
)
|
|
2811
2815
|
]);
|
|
2812
2816
|
const finalQuoteToX = finalQuoteToXResult.status === "fulfilled" ? finalQuoteToXResult.value : null;
|
|
@@ -2848,7 +2852,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2848
2852
|
minDeltaId,
|
|
2849
2853
|
maxDeltaId,
|
|
2850
2854
|
strategy,
|
|
2851
|
-
singleSided
|
|
2855
|
+
singleSided,
|
|
2856
|
+
config = {}
|
|
2852
2857
|
}) {
|
|
2853
2858
|
if (singleSided !== void 0) {
|
|
2854
2859
|
const singleSidedX = singleSided === 0 /* X */;
|
|
@@ -2865,7 +2870,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2865
2870
|
tokenYAmount,
|
|
2866
2871
|
swapSlippageBps,
|
|
2867
2872
|
swapForY2,
|
|
2868
|
-
binArrayForSwap2
|
|
2873
|
+
binArrayForSwap2,
|
|
2874
|
+
config
|
|
2869
2875
|
);
|
|
2870
2876
|
if (!quote) {
|
|
2871
2877
|
throw new Error(
|
|
@@ -2893,7 +2899,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2893
2899
|
tokenXAmount,
|
|
2894
2900
|
swapSlippageBps,
|
|
2895
2901
|
swapForY2,
|
|
2896
|
-
binArrayForSwap2
|
|
2902
|
+
binArrayForSwap2,
|
|
2903
|
+
config
|
|
2897
2904
|
);
|
|
2898
2905
|
if (!quote) {
|
|
2899
2906
|
throw new Error(
|
|
@@ -2987,7 +2994,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2987
2994
|
initialSwapAmount,
|
|
2988
2995
|
swapSlippageBps,
|
|
2989
2996
|
swapForY,
|
|
2990
|
-
binArrayForSwap
|
|
2997
|
+
binArrayForSwap,
|
|
2998
|
+
config
|
|
2991
2999
|
);
|
|
2992
3000
|
if (!initialQuote) {
|
|
2993
3001
|
throw new Error(
|
|
@@ -3044,7 +3052,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3044
3052
|
refinedAmount,
|
|
3045
3053
|
swapSlippageBps,
|
|
3046
3054
|
swapForY,
|
|
3047
|
-
binArrayForSwap
|
|
3055
|
+
binArrayForSwap,
|
|
3056
|
+
config
|
|
3048
3057
|
);
|
|
3049
3058
|
if (!finalQuote) {
|
|
3050
3059
|
return {
|
|
@@ -3078,7 +3087,8 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3078
3087
|
minDeltaId,
|
|
3079
3088
|
maxDeltaId,
|
|
3080
3089
|
strategy,
|
|
3081
|
-
singleSided
|
|
3090
|
+
singleSided,
|
|
3091
|
+
config = {}
|
|
3082
3092
|
}) {
|
|
3083
3093
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3084
3094
|
(0, import_invariant.default)(
|
|
@@ -3096,7 +3106,8 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3096
3106
|
minDeltaId,
|
|
3097
3107
|
maxDeltaId,
|
|
3098
3108
|
strategy,
|
|
3099
|
-
singleSided
|
|
3109
|
+
singleSided,
|
|
3110
|
+
config
|
|
3100
3111
|
});
|
|
3101
3112
|
return {
|
|
3102
3113
|
result,
|
|
@@ -3121,7 +3132,8 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3121
3132
|
swapSlippageBps,
|
|
3122
3133
|
minDeltaId,
|
|
3123
3134
|
maxDeltaId,
|
|
3124
|
-
strategy
|
|
3135
|
+
strategy,
|
|
3136
|
+
config = {}
|
|
3125
3137
|
}) {
|
|
3126
3138
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3127
3139
|
const userPosition = yield dlmm.getPosition(position);
|
|
@@ -3133,8 +3145,9 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3133
3145
|
minDeltaId,
|
|
3134
3146
|
maxDeltaId,
|
|
3135
3147
|
strategy,
|
|
3136
|
-
singleSided: void 0
|
|
3148
|
+
singleSided: void 0,
|
|
3137
3149
|
// rebalance does not use single-sided deposits
|
|
3150
|
+
config
|
|
3138
3151
|
});
|
|
3139
3152
|
return {
|
|
3140
3153
|
result,
|
|
@@ -3199,9 +3212,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
|
|
|
3199
3212
|
|
|
3200
3213
|
// src/zap.ts
|
|
3201
3214
|
var Zap = class {
|
|
3202
|
-
|
|
3215
|
+
/**
|
|
3216
|
+
* @param connection - The connection to the Solana cluster
|
|
3217
|
+
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag) and API key (default: empty string)
|
|
3218
|
+
*/
|
|
3219
|
+
constructor(connection, config = {}) {
|
|
3203
3220
|
this.connection = connection;
|
|
3204
3221
|
this.zapProgram = new import_anchor.Program(idl_default, { connection });
|
|
3222
|
+
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3223
|
+
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3205
3224
|
}
|
|
3206
3225
|
/////// PRIVATE FUNDTIONS //////
|
|
3207
3226
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3553,7 +3572,12 @@ var Zap = class {
|
|
|
3553
3572
|
tokenAMint.equals(inputTokenMint) ? tokenBMint : tokenAMint,
|
|
3554
3573
|
swapInAmount,
|
|
3555
3574
|
maxAccounts,
|
|
3556
|
-
slippageBps
|
|
3575
|
+
slippageBps,
|
|
3576
|
+
void 0,
|
|
3577
|
+
{
|
|
3578
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3579
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3580
|
+
}
|
|
3557
3581
|
);
|
|
3558
3582
|
swapTransactions = [result.transaction];
|
|
3559
3583
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
@@ -3730,7 +3754,12 @@ var Zap = class {
|
|
|
3730
3754
|
tokenAMint,
|
|
3731
3755
|
amountIn,
|
|
3732
3756
|
maxAccounts,
|
|
3733
|
-
slippageBps
|
|
3757
|
+
slippageBps,
|
|
3758
|
+
void 0,
|
|
3759
|
+
{
|
|
3760
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3761
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3762
|
+
}
|
|
3734
3763
|
);
|
|
3735
3764
|
return {
|
|
3736
3765
|
user,
|
|
@@ -3771,7 +3800,12 @@ var Zap = class {
|
|
|
3771
3800
|
tokenBMint,
|
|
3772
3801
|
amountIn,
|
|
3773
3802
|
maxAccounts,
|
|
3774
|
-
slippageBps
|
|
3803
|
+
slippageBps,
|
|
3804
|
+
void 0,
|
|
3805
|
+
{
|
|
3806
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3807
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3808
|
+
}
|
|
3775
3809
|
);
|
|
3776
3810
|
return {
|
|
3777
3811
|
user,
|
|
@@ -3829,13 +3863,117 @@ var Zap = class {
|
|
|
3829
3863
|
)
|
|
3830
3864
|
);
|
|
3831
3865
|
const swapAmountToB = amountIn.sub(swapAmountToA);
|
|
3866
|
+
const MIN_SWAP_AMOUNT = new import_anchor.BN(1e3);
|
|
3867
|
+
if (swapAmountToB.lt(MIN_SWAP_AMOUNT)) {
|
|
3868
|
+
const {
|
|
3869
|
+
transaction: swapTransaction,
|
|
3870
|
+
quoteResponse: swapToAQuote2
|
|
3871
|
+
} = yield buildJupiterSwapTransaction(
|
|
3872
|
+
user,
|
|
3873
|
+
inputTokenMint,
|
|
3874
|
+
tokenAMint,
|
|
3875
|
+
amountIn,
|
|
3876
|
+
maxAccounts,
|
|
3877
|
+
slippageBps,
|
|
3878
|
+
void 0,
|
|
3879
|
+
{
|
|
3880
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3881
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3882
|
+
}
|
|
3883
|
+
);
|
|
3884
|
+
return {
|
|
3885
|
+
user,
|
|
3886
|
+
pool,
|
|
3887
|
+
position,
|
|
3888
|
+
positionNftAccount,
|
|
3889
|
+
maxSqrtPriceChangeBps,
|
|
3890
|
+
amount: new import_anchor.BN(0),
|
|
3891
|
+
isDirectPool: false,
|
|
3892
|
+
tokenAMint,
|
|
3893
|
+
tokenBMint,
|
|
3894
|
+
tokenAVault,
|
|
3895
|
+
tokenBVault,
|
|
3896
|
+
tokenAProgram,
|
|
3897
|
+
tokenBProgram,
|
|
3898
|
+
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
3899
|
+
swapToAQuote2.outAmount,
|
|
3900
|
+
maxTransferAmountExtendPercentage
|
|
3901
|
+
),
|
|
3902
|
+
swapType: 0 /* swapToA */,
|
|
3903
|
+
maxTransferAmountB: new import_anchor.BN(0),
|
|
3904
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3905
|
+
preInstructions,
|
|
3906
|
+
swapTransactions: [swapTransaction],
|
|
3907
|
+
cleanUpInstructions,
|
|
3908
|
+
swapInEstimate: {
|
|
3909
|
+
inAmountA: amountIn,
|
|
3910
|
+
inAmountB: new import_anchor.BN(0),
|
|
3911
|
+
routeA: "jupiter" /* Jupiter */,
|
|
3912
|
+
routeB: "dammV2" /* DammV2 */
|
|
3913
|
+
}
|
|
3914
|
+
};
|
|
3915
|
+
}
|
|
3916
|
+
if (swapAmountToA.lt(MIN_SWAP_AMOUNT)) {
|
|
3917
|
+
const {
|
|
3918
|
+
transaction: swapTransaction,
|
|
3919
|
+
quoteResponse: swapToBQuote2
|
|
3920
|
+
} = yield buildJupiterSwapTransaction(
|
|
3921
|
+
user,
|
|
3922
|
+
inputTokenMint,
|
|
3923
|
+
tokenBMint,
|
|
3924
|
+
amountIn,
|
|
3925
|
+
maxAccounts,
|
|
3926
|
+
slippageBps,
|
|
3927
|
+
void 0,
|
|
3928
|
+
{
|
|
3929
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3930
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3931
|
+
}
|
|
3932
|
+
);
|
|
3933
|
+
return {
|
|
3934
|
+
user,
|
|
3935
|
+
pool,
|
|
3936
|
+
position,
|
|
3937
|
+
positionNftAccount,
|
|
3938
|
+
maxSqrtPriceChangeBps,
|
|
3939
|
+
amount: new import_anchor.BN(0),
|
|
3940
|
+
isDirectPool: false,
|
|
3941
|
+
tokenAMint,
|
|
3942
|
+
tokenBMint,
|
|
3943
|
+
tokenAVault,
|
|
3944
|
+
tokenBVault,
|
|
3945
|
+
tokenAProgram,
|
|
3946
|
+
tokenBProgram,
|
|
3947
|
+
maxTransferAmountA: new import_anchor.BN(0),
|
|
3948
|
+
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3949
|
+
swapToBQuote2.outAmount,
|
|
3950
|
+
maxTransferAmountExtendPercentage
|
|
3951
|
+
),
|
|
3952
|
+
swapType: 1 /* swapToB */,
|
|
3953
|
+
preSqrtPrice: poolState.sqrtPrice,
|
|
3954
|
+
preInstructions,
|
|
3955
|
+
swapTransactions: [swapTransaction],
|
|
3956
|
+
cleanUpInstructions,
|
|
3957
|
+
swapInEstimate: {
|
|
3958
|
+
inAmountA: new import_anchor.BN(0),
|
|
3959
|
+
inAmountB: amountIn,
|
|
3960
|
+
routeA: "dammV2" /* DammV2 */,
|
|
3961
|
+
routeB: "jupiter" /* Jupiter */
|
|
3962
|
+
}
|
|
3963
|
+
};
|
|
3964
|
+
}
|
|
3832
3965
|
const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
|
|
3833
3966
|
user,
|
|
3834
3967
|
inputTokenMint,
|
|
3835
3968
|
tokenAMint,
|
|
3836
3969
|
swapAmountToA,
|
|
3837
3970
|
maxAccounts,
|
|
3838
|
-
slippageBps
|
|
3971
|
+
slippageBps,
|
|
3972
|
+
void 0,
|
|
3973
|
+
{
|
|
3974
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3975
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3976
|
+
}
|
|
3839
3977
|
);
|
|
3840
3978
|
const { transaction: swapToBTransaction, quoteResponse: swapToBQuote } = yield buildJupiterSwapTransaction(
|
|
3841
3979
|
user,
|
|
@@ -3843,7 +3981,12 @@ var Zap = class {
|
|
|
3843
3981
|
tokenBMint,
|
|
3844
3982
|
swapAmountToB,
|
|
3845
3983
|
maxAccounts,
|
|
3846
|
-
slippageBps
|
|
3984
|
+
slippageBps,
|
|
3985
|
+
void 0,
|
|
3986
|
+
{
|
|
3987
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
3988
|
+
jupiterApiKey: this.jupiterApiKey
|
|
3989
|
+
}
|
|
3847
3990
|
);
|
|
3848
3991
|
return {
|
|
3849
3992
|
user,
|
|
@@ -4127,7 +4270,11 @@ var Zap = class {
|
|
|
4127
4270
|
directSwapEstimate.swapAmount,
|
|
4128
4271
|
maxAccounts,
|
|
4129
4272
|
swapSlippageBps,
|
|
4130
|
-
swapQuote.originalQuote
|
|
4273
|
+
swapQuote.originalQuote,
|
|
4274
|
+
{
|
|
4275
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
4276
|
+
jupiterApiKey: this.jupiterApiKey
|
|
4277
|
+
}
|
|
4131
4278
|
);
|
|
4132
4279
|
swapTransactions.push(swapTx);
|
|
4133
4280
|
} else {
|
|
@@ -4292,7 +4439,11 @@ var Zap = class {
|
|
|
4292
4439
|
swapAmountToXInLamports,
|
|
4293
4440
|
maxAccounts,
|
|
4294
4441
|
swapSlippageBps,
|
|
4295
|
-
indirectSwapEstimate.swapToX
|
|
4442
|
+
indirectSwapEstimate.swapToX,
|
|
4443
|
+
{
|
|
4444
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
4445
|
+
jupiterApiKey: this.jupiterApiKey
|
|
4446
|
+
}
|
|
4296
4447
|
);
|
|
4297
4448
|
swapTransactions.push(swapToXTransaction);
|
|
4298
4449
|
}
|
|
@@ -4304,7 +4455,11 @@ var Zap = class {
|
|
|
4304
4455
|
swapAmountToYInLamports,
|
|
4305
4456
|
maxAccounts,
|
|
4306
4457
|
swapSlippageBps,
|
|
4307
|
-
indirectSwapEstimate.swapToY
|
|
4458
|
+
indirectSwapEstimate.swapToY,
|
|
4459
|
+
{
|
|
4460
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
4461
|
+
jupiterApiKey: this.jupiterApiKey
|
|
4462
|
+
}
|
|
4308
4463
|
);
|
|
4309
4464
|
swapTransactions.push(swapToYTransaction);
|
|
4310
4465
|
}
|
|
@@ -4702,7 +4857,11 @@ var Zap = class {
|
|
|
4702
4857
|
directSwapEstimate.swapAmount,
|
|
4703
4858
|
maxAccounts,
|
|
4704
4859
|
swapSlippageBps,
|
|
4705
|
-
swapQuote.originalQuote
|
|
4860
|
+
swapQuote.originalQuote,
|
|
4861
|
+
{
|
|
4862
|
+
jupiterApiUrl: this.jupiterApiUrl,
|
|
4863
|
+
jupiterApiKey: this.jupiterApiKey
|
|
4864
|
+
}
|
|
4706
4865
|
);
|
|
4707
4866
|
swapTransaction = swapTx;
|
|
4708
4867
|
} else {
|
|
@@ -5162,6 +5321,7 @@ var Zap = class {
|
|
|
5162
5321
|
BIN_ARRAY_INDEX_BOUND,
|
|
5163
5322
|
DAMM_V2_PROGRAM_ID,
|
|
5164
5323
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
5324
|
+
DEFAULT_JUPITER_API_URL,
|
|
5165
5325
|
DLMM_PROGRAM_ID,
|
|
5166
5326
|
DLMM_SWAP_DISCRIMINATOR,
|
|
5167
5327
|
DlmmDirectSwapQuoteRoute,
|