@meteora-ag/zap-sdk 2.0.0-rc.0 → 2.0.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 +2 -2
- package/dist/index.d.mts +60 -91
- package/dist/index.d.ts +60 -91
- package/dist/index.js +322 -403
- package/dist/index.mjs +328 -393
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -76,18 +76,12 @@ __export(index_exports, {
|
|
|
76
76
|
DAMM_V2_SWAP_DISCRIMINATOR: () => DAMM_V2_SWAP_DISCRIMINATOR,
|
|
77
77
|
DEFAULT_JUPITER_API_URL: () => DEFAULT_JUPITER_API_URL,
|
|
78
78
|
DEFAULT_JUPITER_API_VERSION: () => DEFAULT_JUPITER_API_VERSION,
|
|
79
|
-
DEFAULT_JUPITER_QUOTE_OPTIONS: () => DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
80
79
|
DLMM_PROGRAM_ID: () => DLMM_PROGRAM_ID,
|
|
81
80
|
DLMM_SWAP_DISCRIMINATOR: () => DLMM_SWAP_DISCRIMINATOR,
|
|
82
81
|
DlmmDirectSwapQuoteRoute: () => DlmmDirectSwapQuoteRoute,
|
|
83
82
|
DlmmSingleSided: () => DlmmSingleSided,
|
|
84
83
|
DlmmSwapType: () => DlmmSwapType,
|
|
85
|
-
JUPITER_INSTRUCTION_LAYOUTS: () => JUPITER_INSTRUCTION_LAYOUTS,
|
|
86
84
|
JUP_V6_PROGRAM_ID: () => JUP_V6_PROGRAM_ID,
|
|
87
|
-
JUP_V6_ROUTE_DISCRIMINATOR: () => JUP_V6_ROUTE_DISCRIMINATOR,
|
|
88
|
-
JUP_V6_ROUTE_V2_DISCRIMINATOR: () => JUP_V6_ROUTE_V2_DISCRIMINATOR,
|
|
89
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR: () => JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR,
|
|
90
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR: () => JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR,
|
|
91
85
|
JupiterApiVersion: () => JupiterApiVersion,
|
|
92
86
|
MEMO_PROGRAM_ID: () => MEMO_PROGRAM_ID,
|
|
93
87
|
SwapExternalType: () => SwapExternalType,
|
|
@@ -108,17 +102,13 @@ __export(index_exports, {
|
|
|
108
102
|
estimateDlmmDirectSwap: () => estimateDlmmDirectSwap,
|
|
109
103
|
estimateDlmmIndirectSwap: () => estimateDlmmIndirectSwap,
|
|
110
104
|
estimateDlmmRebalanceSwap: () => estimateDlmmRebalanceSwap,
|
|
111
|
-
fetchAddressLookupTableAccounts: () => fetchAddressLookupTableAccounts,
|
|
112
105
|
filterOutCloseSplTokenAccountInstructions: () => filterOutCloseSplTokenAccountInstructions,
|
|
113
|
-
filterOutComputeBudgetInstructions: () => filterOutComputeBudgetInstructions,
|
|
114
106
|
getBinArrayBitmapExtension: () => getBinArrayBitmapExtension,
|
|
115
107
|
getBitFromBinArrayIndexInBitmapExtension: () => getBitFromBinArrayIndexInBitmapExtension,
|
|
116
108
|
getDammV2Pool: () => getDammV2Pool,
|
|
117
109
|
getDammV2RemainingAccounts: () => getDammV2RemainingAccounts,
|
|
118
110
|
getDlmmRemainingAccounts: () => getDlmmRemainingAccounts,
|
|
119
111
|
getExtraAccountMetasForTransferHook: () => getExtraAccountMetasForTransferHook,
|
|
120
|
-
getJupiterAddressLookupTableAccounts: () => getJupiterAddressLookupTableAccounts,
|
|
121
|
-
getJupiterInstructionLayout: () => getJupiterInstructionLayout,
|
|
122
112
|
getJupiterQuote: () => getJupiterQuote,
|
|
123
113
|
getJupiterSwapInstruction: () => getJupiterSwapInstruction,
|
|
124
114
|
getLbPairState: () => getLbPairState,
|
|
@@ -126,13 +116,8 @@ __export(index_exports, {
|
|
|
126
116
|
getOrCreateATAInstruction: () => getOrCreateATAInstruction,
|
|
127
117
|
getTokenAccountBalance: () => getTokenAccountBalance,
|
|
128
118
|
getTokenProgramFromMint: () => getTokenProgramFromMint,
|
|
129
|
-
isJupiterBuildResponse: () => isJupiterBuildResponse,
|
|
130
|
-
isJupiterSwapInstructionForUser: () => isJupiterSwapInstructionForUser,
|
|
131
119
|
isSingleSidedA: () => isSingleSidedA,
|
|
132
120
|
isSingleSidedB: () => isSingleSidedB,
|
|
133
|
-
mergeAddressLookupTableAccounts: () => mergeAddressLookupTableAccounts,
|
|
134
|
-
resolveJupiterConfig: () => resolveJupiterConfig,
|
|
135
|
-
toAddressLookupTableAccounts: () => toAddressLookupTableAccounts,
|
|
136
121
|
toProgramStrategyType: () => toProgramStrategyType,
|
|
137
122
|
unwrapSOLInstruction: () => unwrapSOLInstruction,
|
|
138
123
|
wrapSOLInstruction: () => wrapSOLInstruction
|
|
@@ -2007,7 +1992,7 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
|
|
|
2007
1992
|
})(DlmmSingleSided || {});
|
|
2008
1993
|
|
|
2009
1994
|
// src/helpers/jupiter.ts
|
|
2010
|
-
var
|
|
1995
|
+
var import_web33 = require("@solana/web3.js");
|
|
2011
1996
|
|
|
2012
1997
|
// src/constants.ts
|
|
2013
1998
|
var import_web3 = require("@solana/web3.js");
|
|
@@ -2123,20 +2108,124 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
|
2123
2108
|
];
|
|
2124
2109
|
var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
|
|
2125
2110
|
var DEFAULT_JUPITER_API_VERSION = "v2" /* V2 */;
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2111
|
+
|
|
2112
|
+
// src/helpers/token.ts
|
|
2113
|
+
var import_spl_token = require("@solana/spl-token");
|
|
2114
|
+
var import_web32 = require("@solana/web3.js");
|
|
2115
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2116
|
+
const toAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
2117
|
+
tokenMint,
|
|
2118
|
+
owner,
|
|
2119
|
+
allowOwnerOffCurve,
|
|
2120
|
+
tokenProgram
|
|
2121
|
+
);
|
|
2122
|
+
const ix = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
2123
|
+
payer,
|
|
2124
|
+
toAccount,
|
|
2125
|
+
owner,
|
|
2126
|
+
tokenMint,
|
|
2127
|
+
tokenProgram
|
|
2128
|
+
);
|
|
2129
|
+
return { ataPubkey: toAccount, ix };
|
|
2130
|
+
});
|
|
2131
|
+
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2132
|
+
const wSolATAAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
2133
|
+
import_spl_token.NATIVE_MINT,
|
|
2134
|
+
owner,
|
|
2135
|
+
allowOwnerOffCurve
|
|
2136
|
+
);
|
|
2137
|
+
if (wSolATAAccount) {
|
|
2138
|
+
const closedWrappedSolInstruction = (0, import_spl_token.createCloseAccountInstruction)(
|
|
2139
|
+
wSolATAAccount,
|
|
2140
|
+
receiver,
|
|
2141
|
+
owner,
|
|
2142
|
+
[],
|
|
2143
|
+
import_spl_token.TOKEN_PROGRAM_ID
|
|
2144
|
+
);
|
|
2145
|
+
return closedWrappedSolInstruction;
|
|
2146
|
+
}
|
|
2147
|
+
return null;
|
|
2148
|
+
}
|
|
2149
|
+
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2150
|
+
return __async(this, null, function* () {
|
|
2151
|
+
let balance;
|
|
2152
|
+
try {
|
|
2153
|
+
balance = (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
2154
|
+
} catch (e) {
|
|
2155
|
+
balance = "0";
|
|
2156
|
+
}
|
|
2157
|
+
return balance;
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
function wrapSOLInstruction(from, to, amount, tokenProgram = import_spl_token.TOKEN_PROGRAM_ID) {
|
|
2161
|
+
return [
|
|
2162
|
+
import_web32.SystemProgram.transfer({
|
|
2163
|
+
fromPubkey: from,
|
|
2164
|
+
toPubkey: to,
|
|
2165
|
+
lamports: amount
|
|
2166
|
+
}),
|
|
2167
|
+
new import_web32.TransactionInstruction({
|
|
2168
|
+
keys: [
|
|
2169
|
+
{
|
|
2170
|
+
pubkey: to,
|
|
2171
|
+
isSigner: false,
|
|
2172
|
+
isWritable: true
|
|
2173
|
+
}
|
|
2174
|
+
],
|
|
2175
|
+
data: Buffer.from(new Uint8Array([17])),
|
|
2176
|
+
programId: tokenProgram
|
|
2177
|
+
})
|
|
2178
|
+
];
|
|
2179
|
+
}
|
|
2180
|
+
var CLOSE_ACCOUNT_DISCRIMINATOR = 9;
|
|
2181
|
+
function filterOutCloseSplTokenAccountInstructions(instructions) {
|
|
2182
|
+
return instructions.filter((ix) => {
|
|
2183
|
+
if (ix.programId.equals(import_spl_token.TOKEN_PROGRAM_ID)) {
|
|
2184
|
+
return ix.data[0] !== CLOSE_ACCOUNT_DISCRIMINATOR;
|
|
2185
|
+
}
|
|
2186
|
+
return true;
|
|
2187
|
+
});
|
|
2188
|
+
}
|
|
2189
|
+
function getCreateAtaInstructions(user, tokens) {
|
|
2190
|
+
const tokenAccounts = tokens.map(
|
|
2191
|
+
({ mint, tokenProgram }) => (0, import_spl_token.getAssociatedTokenAddressSync)(mint, user, true, tokenProgram)
|
|
2192
|
+
);
|
|
2193
|
+
const instructions = tokens.map(
|
|
2194
|
+
({ mint, tokenProgram }, i) => (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
2195
|
+
user,
|
|
2196
|
+
tokenAccounts[i],
|
|
2197
|
+
user,
|
|
2198
|
+
mint,
|
|
2199
|
+
tokenProgram
|
|
2200
|
+
)
|
|
2201
|
+
);
|
|
2202
|
+
return { tokenAccounts, instructions };
|
|
2203
|
+
}
|
|
2204
|
+
function isCreateAtaInstruction(ix) {
|
|
2205
|
+
return ix.programId.equals(import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID) && (ix.data.length === 0 || ix.data[0] === 0 || ix.data[0] === 1);
|
|
2206
|
+
}
|
|
2207
|
+
function dedupeCreateAtaInstructions(instructions) {
|
|
2208
|
+
const createdAccounts = /* @__PURE__ */ new Set();
|
|
2209
|
+
return instructions.filter((ix) => {
|
|
2210
|
+
if (!isCreateAtaInstruction(ix)) {
|
|
2211
|
+
return true;
|
|
2212
|
+
}
|
|
2213
|
+
const account = ix.keys[1].pubkey.toBase58();
|
|
2214
|
+
if (createdAccounts.has(account)) {
|
|
2215
|
+
return false;
|
|
2216
|
+
}
|
|
2217
|
+
createdAccounts.add(account);
|
|
2218
|
+
return true;
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2132
2221
|
|
|
2133
2222
|
// src/helpers/jupiter.ts
|
|
2134
|
-
function resolveJupiterConfig(config
|
|
2223
|
+
function resolveJupiterConfig(config) {
|
|
2135
2224
|
var _a;
|
|
2136
2225
|
return {
|
|
2137
|
-
url: config.jupiterApiUrl || DEFAULT_JUPITER_API_URL,
|
|
2138
|
-
apiKey: config.jupiterApiKey || "",
|
|
2139
|
-
version: (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2226
|
+
url: (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL,
|
|
2227
|
+
apiKey: (config == null ? void 0 : config.jupiterApiKey) || "",
|
|
2228
|
+
version: (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2140
2229
|
};
|
|
2141
2230
|
}
|
|
2142
2231
|
function getJupiterInstructionLayout(data) {
|
|
@@ -2157,37 +2246,28 @@ function isJupiterSwapInstructionForUser(swapInstruction, user) {
|
|
|
2157
2246
|
Buffer.from(swapInstruction.data, "base64")
|
|
2158
2247
|
);
|
|
2159
2248
|
const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
|
|
2160
|
-
return authority !== void 0 && new
|
|
2249
|
+
return authority !== void 0 && new import_web33.PublicKey(authority.pubkey).equals(user);
|
|
2161
2250
|
}
|
|
2162
2251
|
function jupiterHeaders(apiKey, json) {
|
|
2163
2252
|
return __spreadValues(__spreadValues({
|
|
2164
2253
|
Accept: "application/json"
|
|
2165
2254
|
}, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
|
|
2166
2255
|
}
|
|
2167
|
-
function toSearchParams(
|
|
2256
|
+
function toSearchParams(params) {
|
|
2168
2257
|
var _a;
|
|
2169
|
-
const
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
amount: query.amount,
|
|
2173
|
-
slippageBps: query.slippageBps.toString()
|
|
2174
|
-
}, query.maxAccounts !== void 0 ? { maxAccounts: query.maxAccounts.toString() } : {}), {
|
|
2175
|
-
onlyDirectRoutes: query.onlyDirectRoutes.toString(),
|
|
2176
|
-
restrictIntermediateTokens: query.restrictIntermediateTokens.toString(),
|
|
2177
|
-
dynamicSlippage: query.dynamicSlippage.toString(),
|
|
2178
|
-
forJitoBundle: query.forJitoBundle.toString()
|
|
2179
|
-
}));
|
|
2180
|
-
for (const [name, value] of Object.entries(
|
|
2181
|
-
(_a = query.additionalQueryParams) != null ? _a : {}
|
|
2182
|
-
)) {
|
|
2183
|
-
params.set(name, value);
|
|
2258
|
+
const searchParams = new URLSearchParams();
|
|
2259
|
+
for (const [name, value] of Object.entries((_a = params.queryParams) != null ? _a : {})) {
|
|
2260
|
+
searchParams.set(name, value.toString());
|
|
2184
2261
|
}
|
|
2185
|
-
|
|
2262
|
+
searchParams.set("inputMint", params.inputMint.toString());
|
|
2263
|
+
searchParams.set("outputMint", params.outputMint.toString());
|
|
2264
|
+
searchParams.set("amount", params.amount.toString());
|
|
2265
|
+
return searchParams;
|
|
2186
2266
|
}
|
|
2187
|
-
function fetchJupiterQuoteV1(
|
|
2267
|
+
function fetchJupiterQuoteV1(params, config) {
|
|
2188
2268
|
return __async(this, null, function* () {
|
|
2189
2269
|
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2190
|
-
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(
|
|
2270
|
+
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(params).toString()}`;
|
|
2191
2271
|
try {
|
|
2192
2272
|
const response = yield fetch(url, {
|
|
2193
2273
|
method: "GET",
|
|
@@ -2202,12 +2282,12 @@ function fetchJupiterQuoteV1(query, config) {
|
|
|
2202
2282
|
}
|
|
2203
2283
|
});
|
|
2204
2284
|
}
|
|
2205
|
-
function fetchJupiterBuildV2(
|
|
2285
|
+
function fetchJupiterBuildV2(params, config) {
|
|
2206
2286
|
return __async(this, null, function* () {
|
|
2207
2287
|
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2208
|
-
const
|
|
2209
|
-
|
|
2210
|
-
const url = `${baseUrl}/swap/v2/build?${
|
|
2288
|
+
const searchParams = toSearchParams(params);
|
|
2289
|
+
searchParams.set("taker", params.user.toString());
|
|
2290
|
+
const url = `${baseUrl}/swap/v2/build?${searchParams.toString()}`;
|
|
2211
2291
|
try {
|
|
2212
2292
|
const response = yield fetch(url, {
|
|
2213
2293
|
method: "GET",
|
|
@@ -2222,26 +2302,13 @@ function fetchJupiterBuildV2(query, taker, config) {
|
|
|
2222
2302
|
}
|
|
2223
2303
|
});
|
|
2224
2304
|
}
|
|
2225
|
-
function getJupiterQuote(
|
|
2226
|
-
return __async(this,
|
|
2227
|
-
var _a, _b, _c, _d;
|
|
2228
|
-
const query = {
|
|
2229
|
-
inputMint: params.inputMint,
|
|
2230
|
-
outputMint: params.outputMint,
|
|
2231
|
-
amount: params.amount.toString(),
|
|
2232
|
-
slippageBps: params.slippageBps,
|
|
2233
|
-
maxAccounts: params.maxAccounts,
|
|
2234
|
-
dynamicSlippage: (_a = params.dynamicSlippage) != null ? _a : DEFAULT_JUPITER_QUOTE_OPTIONS.dynamicSlippage,
|
|
2235
|
-
onlyDirectRoutes: (_b = params.onlyDirectRoutes) != null ? _b : DEFAULT_JUPITER_QUOTE_OPTIONS.onlyDirectRoutes,
|
|
2236
|
-
restrictIntermediateTokens: (_c = params.restrictIntermediateTokens) != null ? _c : DEFAULT_JUPITER_QUOTE_OPTIONS.restrictIntermediateTokens,
|
|
2237
|
-
forJitoBundle: (_d = params.forJitoBundle) != null ? _d : DEFAULT_JUPITER_QUOTE_OPTIONS.forJitoBundle,
|
|
2238
|
-
additionalQueryParams: params.additionalQueryParams
|
|
2239
|
-
};
|
|
2305
|
+
function getJupiterQuote(params, config) {
|
|
2306
|
+
return __async(this, null, function* () {
|
|
2240
2307
|
const { version } = resolveJupiterConfig(config);
|
|
2241
2308
|
if (version === "v1" /* V1 */) {
|
|
2242
|
-
return fetchJupiterQuoteV1(
|
|
2309
|
+
return fetchJupiterQuoteV1(params, config);
|
|
2243
2310
|
}
|
|
2244
|
-
return fetchJupiterBuildV2(
|
|
2311
|
+
return fetchJupiterBuildV2(params, config);
|
|
2245
2312
|
});
|
|
2246
2313
|
}
|
|
2247
2314
|
function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
@@ -2271,8 +2338,8 @@ function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
|
2271
2338
|
return yield response.json();
|
|
2272
2339
|
});
|
|
2273
2340
|
}
|
|
2274
|
-
function getJupiterSwapInstruction(
|
|
2275
|
-
return __async(this,
|
|
2341
|
+
function getJupiterSwapInstruction(userPublicKey, quoteResponse, config) {
|
|
2342
|
+
return __async(this, null, function* () {
|
|
2276
2343
|
const { version } = resolveJupiterConfig(config);
|
|
2277
2344
|
if (version === "v1" /* V1 */) {
|
|
2278
2345
|
return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
|
|
@@ -2305,10 +2372,10 @@ function isQuoteMatchesSwap(quoteResponse, user, amount) {
|
|
|
2305
2372
|
var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
|
|
2306
2373
|
function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
|
|
2307
2374
|
return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
|
|
2308
|
-
([key, addresses]) => new
|
|
2309
|
-
key: new
|
|
2375
|
+
([key, addresses]) => new import_web33.AddressLookupTableAccount({
|
|
2376
|
+
key: new import_web33.PublicKey(key),
|
|
2310
2377
|
state: {
|
|
2311
|
-
addresses: addresses.map((address) => new
|
|
2378
|
+
addresses: addresses.map((address) => new import_web33.PublicKey(address)),
|
|
2312
2379
|
deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
|
|
2313
2380
|
lastExtendedSlot: 0,
|
|
2314
2381
|
lastExtendedSlotStartIndex: 0
|
|
@@ -2321,16 +2388,16 @@ function fetchAddressLookupTableAccounts(connection, addresses) {
|
|
|
2321
2388
|
if (addresses.length === 0) {
|
|
2322
2389
|
return [];
|
|
2323
2390
|
}
|
|
2324
|
-
const keys = addresses.map((address) => new
|
|
2391
|
+
const keys = addresses.map((address) => new import_web33.PublicKey(address));
|
|
2325
2392
|
const accounts = yield connection.getMultipleAccountsInfo(keys);
|
|
2326
2393
|
return keys.map((key, i) => {
|
|
2327
2394
|
const account = accounts[i];
|
|
2328
|
-
if (!account || !account.owner.equals(
|
|
2395
|
+
if (!account || !account.owner.equals(import_web33.AddressLookupTableProgram.programId)) {
|
|
2329
2396
|
throw new Error(`Address lookup table not found: ${key.toBase58()}`);
|
|
2330
2397
|
}
|
|
2331
|
-
return new
|
|
2398
|
+
return new import_web33.AddressLookupTableAccount({
|
|
2332
2399
|
key,
|
|
2333
|
-
state:
|
|
2400
|
+
state: import_web33.AddressLookupTableAccount.deserialize(account.data)
|
|
2334
2401
|
});
|
|
2335
2402
|
});
|
|
2336
2403
|
});
|
|
@@ -2357,22 +2424,35 @@ function getJupiterAddressLookupTableAccounts(connection, response) {
|
|
|
2357
2424
|
);
|
|
2358
2425
|
});
|
|
2359
2426
|
}
|
|
2360
|
-
function
|
|
2361
|
-
return
|
|
2427
|
+
function toTransactionInstruction(instruction) {
|
|
2428
|
+
return new import_web33.TransactionInstruction({
|
|
2429
|
+
keys: instruction.accounts.map((item) => ({
|
|
2430
|
+
pubkey: new import_web33.PublicKey(item.pubkey),
|
|
2431
|
+
isSigner: item.isSigner,
|
|
2432
|
+
isWritable: item.isWritable
|
|
2433
|
+
})),
|
|
2434
|
+
programId: new import_web33.PublicKey(instruction.programId),
|
|
2435
|
+
data: Buffer.from(instruction.data, "base64")
|
|
2436
|
+
});
|
|
2437
|
+
}
|
|
2438
|
+
function getJupiterCreateAtaInstructions(setupInstructions) {
|
|
2439
|
+
return setupInstructions.filter(isCreateAtaInstruction);
|
|
2440
|
+
}
|
|
2441
|
+
function buildJupiterSwapTransaction(connection, user, inputMint, outputMint, amount, slippageBps, jupiterQuoteResponse, config, jupiterQuoteOptions) {
|
|
2442
|
+
return __async(this, null, function* () {
|
|
2362
2443
|
if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
|
|
2363
2444
|
throw new Error(
|
|
2364
2445
|
`Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
|
|
2365
2446
|
);
|
|
2366
2447
|
}
|
|
2367
2448
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
2368
|
-
|
|
2449
|
+
{
|
|
2369
2450
|
inputMint,
|
|
2370
2451
|
outputMint,
|
|
2371
2452
|
amount,
|
|
2372
2453
|
user,
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
}, jupiterQuoteOptions),
|
|
2454
|
+
queryParams: __spreadValues({ slippageBps }, jupiterQuoteOptions)
|
|
2455
|
+
},
|
|
2376
2456
|
config
|
|
2377
2457
|
);
|
|
2378
2458
|
if (!quoteResponse) {
|
|
@@ -2385,51 +2465,51 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
|
2385
2465
|
quoteResponse,
|
|
2386
2466
|
config
|
|
2387
2467
|
);
|
|
2388
|
-
const instruction =
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
};
|
|
2395
|
-
}),
|
|
2396
|
-
programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
|
|
2397
|
-
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
2398
|
-
});
|
|
2468
|
+
const instruction = toTransactionInstruction(
|
|
2469
|
+
swapInstructionResponse.swapInstruction
|
|
2470
|
+
);
|
|
2471
|
+
const setupInstructions = swapInstructionResponse.setupInstructions.map(
|
|
2472
|
+
toTransactionInstruction
|
|
2473
|
+
);
|
|
2399
2474
|
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2400
2475
|
connection,
|
|
2401
2476
|
swapInstructionResponse
|
|
2402
2477
|
);
|
|
2403
|
-
return {
|
|
2478
|
+
return {
|
|
2479
|
+
instruction,
|
|
2480
|
+
setupInstructions,
|
|
2481
|
+
addressLookupTableAccounts,
|
|
2482
|
+
quoteResponse
|
|
2483
|
+
};
|
|
2404
2484
|
});
|
|
2405
2485
|
}
|
|
2406
2486
|
|
|
2407
2487
|
// src/helpers/dammV2.ts
|
|
2408
|
-
var
|
|
2488
|
+
var import_spl_token2 = require("@solana/spl-token");
|
|
2409
2489
|
var import_cp_amm_sdk = require("@meteora-ag/cp-amm-sdk");
|
|
2410
2490
|
|
|
2411
2491
|
// src/helpers/pda.ts
|
|
2412
|
-
var
|
|
2492
|
+
var import_web34 = require("@solana/web3.js");
|
|
2413
2493
|
function deriveDammV2EventAuthority() {
|
|
2414
|
-
return
|
|
2494
|
+
return import_web34.PublicKey.findProgramAddressSync(
|
|
2415
2495
|
[Buffer.from("__event_authority")],
|
|
2416
2496
|
DAMM_V2_PROGRAM_ID
|
|
2417
2497
|
)[0];
|
|
2418
2498
|
}
|
|
2419
2499
|
function deriveDammV2PoolAuthority() {
|
|
2420
|
-
return
|
|
2500
|
+
return import_web34.PublicKey.findProgramAddressSync(
|
|
2421
2501
|
[Buffer.from("pool_authority")],
|
|
2422
2502
|
DAMM_V2_PROGRAM_ID
|
|
2423
2503
|
)[0];
|
|
2424
2504
|
}
|
|
2425
2505
|
function deriveLedgerAccount(owner) {
|
|
2426
|
-
return
|
|
2506
|
+
return import_web34.PublicKey.findProgramAddressSync(
|
|
2427
2507
|
[Buffer.from("user_ledger"), owner.toBuffer()],
|
|
2428
2508
|
ZAP_PROGRAM_ID
|
|
2429
2509
|
)[0];
|
|
2430
2510
|
}
|
|
2431
2511
|
function deriveDlmmEventAuthority() {
|
|
2432
|
-
return
|
|
2512
|
+
return import_web34.PublicKey.findProgramAddressSync(
|
|
2433
2513
|
[Buffer.from("__event_authority")],
|
|
2434
2514
|
DLMM_PROGRAM_ID
|
|
2435
2515
|
)[0];
|
|
@@ -2443,7 +2523,7 @@ function getDammV2Pool(connection, poolAddress) {
|
|
|
2443
2523
|
});
|
|
2444
2524
|
}
|
|
2445
2525
|
function getDammV2RemainingAccounts(_0, _1, _2, _3) {
|
|
2446
|
-
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram =
|
|
2526
|
+
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram = import_spl_token2.TOKEN_PROGRAM_ID, tokenBProgram = import_spl_token2.TOKEN_PROGRAM_ID, poolState) {
|
|
2447
2527
|
const remainingAccounts = [
|
|
2448
2528
|
{
|
|
2449
2529
|
isSigner: false,
|
|
@@ -2534,13 +2614,13 @@ function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
|
2534
2614
|
}
|
|
2535
2615
|
|
|
2536
2616
|
// src/helpers/common.ts
|
|
2537
|
-
var
|
|
2538
|
-
var
|
|
2617
|
+
var import_spl_token3 = require("@solana/spl-token");
|
|
2618
|
+
var import_web35 = require("@solana/web3.js");
|
|
2539
2619
|
var import_decimal = __toESM(require("decimal.js"));
|
|
2540
2620
|
function getTokenProgramFromMint(connection, mint) {
|
|
2541
2621
|
return __async(this, null, function* () {
|
|
2542
|
-
if (mint.equals(
|
|
2543
|
-
return
|
|
2622
|
+
if (mint.equals(import_spl_token3.NATIVE_MINT)) {
|
|
2623
|
+
return import_spl_token3.TOKEN_PROGRAM_ID;
|
|
2544
2624
|
}
|
|
2545
2625
|
try {
|
|
2546
2626
|
const mintInfo = yield connection.getAccountInfo(mint);
|
|
@@ -2548,18 +2628,18 @@ function getTokenProgramFromMint(connection, mint) {
|
|
|
2548
2628
|
throw new Error(`Mint account not found: ${mint.toString()}`);
|
|
2549
2629
|
}
|
|
2550
2630
|
if (mintInfo.owner.equals(
|
|
2551
|
-
new
|
|
2631
|
+
new import_web35.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
2552
2632
|
)) {
|
|
2553
|
-
return new
|
|
2633
|
+
return new import_web35.PublicKey("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
2554
2634
|
} else {
|
|
2555
|
-
return
|
|
2635
|
+
return import_spl_token3.TOKEN_PROGRAM_ID;
|
|
2556
2636
|
}
|
|
2557
2637
|
} catch (error) {
|
|
2558
2638
|
console.warn(
|
|
2559
2639
|
`Failed to determine token program for ${mint.toString()}, defaulting to TOKEN_PROGRAM_ID:`,
|
|
2560
2640
|
error
|
|
2561
2641
|
);
|
|
2562
|
-
return
|
|
2642
|
+
return import_spl_token3.TOKEN_PROGRAM_ID;
|
|
2563
2643
|
}
|
|
2564
2644
|
});
|
|
2565
2645
|
}
|
|
@@ -2571,86 +2651,8 @@ function convertUiAmountToLamports(amount, decimals) {
|
|
|
2571
2651
|
}
|
|
2572
2652
|
function filterOutComputeBudgetInstructions(instructions) {
|
|
2573
2653
|
return instructions.filter(
|
|
2574
|
-
(ix) => !ix.programId.equals(
|
|
2575
|
-
);
|
|
2576
|
-
}
|
|
2577
|
-
|
|
2578
|
-
// src/helpers/token.ts
|
|
2579
|
-
var import_spl_token3 = require("@solana/spl-token");
|
|
2580
|
-
var import_web35 = require("@solana/web3.js");
|
|
2581
|
-
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2582
|
-
const toAccount = (0, import_spl_token3.getAssociatedTokenAddressSync)(
|
|
2583
|
-
tokenMint,
|
|
2584
|
-
owner,
|
|
2585
|
-
allowOwnerOffCurve,
|
|
2586
|
-
tokenProgram
|
|
2654
|
+
(ix) => !ix.programId.equals(import_web35.ComputeBudgetProgram.programId)
|
|
2587
2655
|
);
|
|
2588
|
-
const ix = (0, import_spl_token3.createAssociatedTokenAccountIdempotentInstruction)(
|
|
2589
|
-
payer,
|
|
2590
|
-
toAccount,
|
|
2591
|
-
owner,
|
|
2592
|
-
tokenMint,
|
|
2593
|
-
tokenProgram
|
|
2594
|
-
);
|
|
2595
|
-
return { ataPubkey: toAccount, ix };
|
|
2596
|
-
});
|
|
2597
|
-
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2598
|
-
const wSolATAAccount = (0, import_spl_token3.getAssociatedTokenAddressSync)(
|
|
2599
|
-
import_spl_token3.NATIVE_MINT,
|
|
2600
|
-
owner,
|
|
2601
|
-
allowOwnerOffCurve
|
|
2602
|
-
);
|
|
2603
|
-
if (wSolATAAccount) {
|
|
2604
|
-
const closedWrappedSolInstruction = (0, import_spl_token3.createCloseAccountInstruction)(
|
|
2605
|
-
wSolATAAccount,
|
|
2606
|
-
receiver,
|
|
2607
|
-
owner,
|
|
2608
|
-
[],
|
|
2609
|
-
import_spl_token3.TOKEN_PROGRAM_ID
|
|
2610
|
-
);
|
|
2611
|
-
return closedWrappedSolInstruction;
|
|
2612
|
-
}
|
|
2613
|
-
return null;
|
|
2614
|
-
}
|
|
2615
|
-
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2616
|
-
return __async(this, null, function* () {
|
|
2617
|
-
let balance;
|
|
2618
|
-
try {
|
|
2619
|
-
balance = (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
2620
|
-
} catch (e) {
|
|
2621
|
-
balance = "0";
|
|
2622
|
-
}
|
|
2623
|
-
return balance;
|
|
2624
|
-
});
|
|
2625
|
-
}
|
|
2626
|
-
function wrapSOLInstruction(from, to, amount, tokenProgram = import_spl_token3.TOKEN_PROGRAM_ID) {
|
|
2627
|
-
return [
|
|
2628
|
-
import_web35.SystemProgram.transfer({
|
|
2629
|
-
fromPubkey: from,
|
|
2630
|
-
toPubkey: to,
|
|
2631
|
-
lamports: amount
|
|
2632
|
-
}),
|
|
2633
|
-
new import_web35.TransactionInstruction({
|
|
2634
|
-
keys: [
|
|
2635
|
-
{
|
|
2636
|
-
pubkey: to,
|
|
2637
|
-
isSigner: false,
|
|
2638
|
-
isWritable: true
|
|
2639
|
-
}
|
|
2640
|
-
],
|
|
2641
|
-
data: Buffer.from(new Uint8Array([17])),
|
|
2642
|
-
programId: tokenProgram
|
|
2643
|
-
})
|
|
2644
|
-
];
|
|
2645
|
-
}
|
|
2646
|
-
var CLOSE_ACCOUNT_DISCRIMINATOR = 9;
|
|
2647
|
-
function filterOutCloseSplTokenAccountInstructions(instructions) {
|
|
2648
|
-
return instructions.filter((ix) => {
|
|
2649
|
-
if (ix.programId.equals(import_spl_token3.TOKEN_PROGRAM_ID)) {
|
|
2650
|
-
return ix.data[0] !== CLOSE_ACCOUNT_DISCRIMINATOR;
|
|
2651
|
-
}
|
|
2652
|
-
return true;
|
|
2653
|
-
});
|
|
2654
2656
|
}
|
|
2655
2657
|
|
|
2656
2658
|
// src/helpers/dlmm.ts
|
|
@@ -3014,8 +3016,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
3014
3016
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
3015
3017
|
return new import_bn3.default(estimatedOutput.floor().toString());
|
|
3016
3018
|
}
|
|
3017
|
-
function getBestSwapQuoteJupiterDlmm(
|
|
3018
|
-
return __async(this,
|
|
3019
|
+
function getBestSwapQuoteJupiterDlmm(dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config, jupiterQuoteOptions) {
|
|
3020
|
+
return __async(this, null, function* () {
|
|
3019
3021
|
let dlmmQuoteResult = null;
|
|
3020
3022
|
try {
|
|
3021
3023
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -3028,14 +3030,15 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
|
3028
3030
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
3029
3031
|
}
|
|
3030
3032
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
3031
|
-
|
|
3033
|
+
{
|
|
3032
3034
|
inputMint: inMint,
|
|
3033
3035
|
outputMint: outMint,
|
|
3034
3036
|
amount: inAmount,
|
|
3035
3037
|
user,
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3038
|
+
queryParams: __spreadValues({
|
|
3039
|
+
slippageBps: swapSlippageBps
|
|
3040
|
+
}, jupiterQuoteOptions)
|
|
3041
|
+
},
|
|
3039
3042
|
config
|
|
3040
3043
|
);
|
|
3041
3044
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -3162,7 +3165,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3162
3165
|
strategy,
|
|
3163
3166
|
singleSided,
|
|
3164
3167
|
jupiterQuoteOptions,
|
|
3165
|
-
config
|
|
3168
|
+
config
|
|
3166
3169
|
}) {
|
|
3167
3170
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3168
3171
|
const activeBin = yield dlmm.getActiveBin();
|
|
@@ -3186,14 +3189,15 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3186
3189
|
const singleSidedX = singleSided === 0 /* X */;
|
|
3187
3190
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
3188
3191
|
const quote = yield getJupiterQuote(
|
|
3189
|
-
|
|
3192
|
+
{
|
|
3190
3193
|
inputMint: inputTokenMint,
|
|
3191
3194
|
outputMint: outputTokenMint,
|
|
3192
3195
|
amount: amountIn,
|
|
3193
3196
|
user,
|
|
3194
|
-
|
|
3195
|
-
|
|
3196
|
-
|
|
3197
|
+
queryParams: __spreadValues({
|
|
3198
|
+
slippageBps: swapSlippageBps
|
|
3199
|
+
}, jupiterQuoteOptions)
|
|
3200
|
+
},
|
|
3197
3201
|
config
|
|
3198
3202
|
);
|
|
3199
3203
|
if (!quote) {
|
|
@@ -3216,25 +3220,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3216
3220
|
const halfAmount = amountIn.div(new import_bn3.default(2));
|
|
3217
3221
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
3218
3222
|
getJupiterQuote(
|
|
3219
|
-
|
|
3223
|
+
{
|
|
3220
3224
|
inputMint: inputTokenMint,
|
|
3221
3225
|
outputMint: tokenXMint,
|
|
3222
3226
|
amount: halfAmount,
|
|
3223
3227
|
user,
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3228
|
+
queryParams: __spreadValues({
|
|
3229
|
+
slippageBps: swapSlippageBps
|
|
3230
|
+
}, jupiterQuoteOptions)
|
|
3231
|
+
},
|
|
3227
3232
|
config
|
|
3228
3233
|
),
|
|
3229
3234
|
getJupiterQuote(
|
|
3230
|
-
|
|
3235
|
+
{
|
|
3231
3236
|
inputMint: inputTokenMint,
|
|
3232
3237
|
outputMint: tokenYMint,
|
|
3233
3238
|
amount: halfAmount,
|
|
3234
3239
|
user,
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3240
|
+
queryParams: __spreadValues({
|
|
3241
|
+
slippageBps: swapSlippageBps
|
|
3242
|
+
}, jupiterQuoteOptions)
|
|
3243
|
+
},
|
|
3238
3244
|
config
|
|
3239
3245
|
)
|
|
3240
3246
|
]);
|
|
@@ -3330,25 +3336,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3330
3336
|
}
|
|
3331
3337
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
3332
3338
|
getJupiterQuote(
|
|
3333
|
-
|
|
3339
|
+
{
|
|
3334
3340
|
inputMint: inputTokenMint,
|
|
3335
3341
|
outputMint: tokenXMint,
|
|
3336
3342
|
amount: bestAmountToX,
|
|
3337
3343
|
user,
|
|
3338
|
-
|
|
3339
|
-
|
|
3340
|
-
|
|
3344
|
+
queryParams: __spreadValues({
|
|
3345
|
+
slippageBps: swapSlippageBps
|
|
3346
|
+
}, jupiterQuoteOptions)
|
|
3347
|
+
},
|
|
3341
3348
|
config
|
|
3342
3349
|
),
|
|
3343
3350
|
getJupiterQuote(
|
|
3344
|
-
|
|
3351
|
+
{
|
|
3345
3352
|
inputMint: inputTokenMint,
|
|
3346
3353
|
outputMint: tokenYMint,
|
|
3347
3354
|
amount: bestAmountToY,
|
|
3348
3355
|
user,
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3356
|
+
queryParams: __spreadValues({
|
|
3357
|
+
slippageBps: swapSlippageBps
|
|
3358
|
+
}, jupiterQuoteOptions)
|
|
3359
|
+
},
|
|
3352
3360
|
config
|
|
3353
3361
|
)
|
|
3354
3362
|
]);
|
|
@@ -3394,7 +3402,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3394
3402
|
strategy,
|
|
3395
3403
|
singleSided,
|
|
3396
3404
|
jupiterQuoteOptions,
|
|
3397
|
-
config
|
|
3405
|
+
config
|
|
3398
3406
|
}) {
|
|
3399
3407
|
if (singleSided !== void 0) {
|
|
3400
3408
|
const singleSidedX = singleSided === 0 /* X */;
|
|
@@ -3639,7 +3647,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3639
3647
|
strategy,
|
|
3640
3648
|
singleSided,
|
|
3641
3649
|
jupiterQuoteOptions,
|
|
3642
|
-
config
|
|
3650
|
+
config
|
|
3643
3651
|
}) {
|
|
3644
3652
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3645
3653
|
(0, import_invariant.default)(
|
|
@@ -3688,7 +3696,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3688
3696
|
maxDeltaId,
|
|
3689
3697
|
strategy,
|
|
3690
3698
|
jupiterQuoteOptions,
|
|
3691
|
-
config
|
|
3699
|
+
config
|
|
3692
3700
|
}) {
|
|
3693
3701
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3694
3702
|
const userPosition = yield dlmm.getPosition(position);
|
|
@@ -3773,13 +3781,13 @@ var Zap = class {
|
|
|
3773
3781
|
* @param connection - The connection to the Solana cluster
|
|
3774
3782
|
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
|
|
3775
3783
|
*/
|
|
3776
|
-
constructor(connection, config
|
|
3784
|
+
constructor(connection, config) {
|
|
3777
3785
|
var _a;
|
|
3778
3786
|
this.connection = connection;
|
|
3779
3787
|
this.zapProgram = new import_core.Program(idl_default, { connection });
|
|
3780
|
-
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3781
|
-
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3782
|
-
this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3788
|
+
this.jupiterApiUrl = (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL;
|
|
3789
|
+
this.jupiterApiKey = (config == null ? void 0 : config.jupiterApiKey) || "";
|
|
3790
|
+
this.jupiterApiVersion = (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3783
3791
|
}
|
|
3784
3792
|
/////// PRIVATE FUNDTIONS //////
|
|
3785
3793
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -4013,13 +4021,12 @@ var Zap = class {
|
|
|
4013
4021
|
* @param params.amountIn - The amount of input token
|
|
4014
4022
|
* @param params.inputTokenMint - The input token mint
|
|
4015
4023
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
4016
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
4017
4024
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4018
4025
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
4019
4026
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
4020
4027
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
4021
4028
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4022
|
-
* @param params.jupiterQuoteOptions - Optional Jupiter
|
|
4029
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
4023
4030
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
4024
4031
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
4025
4032
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -4033,7 +4040,6 @@ var Zap = class {
|
|
|
4033
4040
|
inputTokenMint,
|
|
4034
4041
|
amountIn,
|
|
4035
4042
|
positionNftMint,
|
|
4036
|
-
maxAccounts,
|
|
4037
4043
|
maxSqrtPriceChangeBps,
|
|
4038
4044
|
slippageBps,
|
|
4039
4045
|
dammV2Quote,
|
|
@@ -4131,7 +4137,6 @@ var Zap = class {
|
|
|
4131
4137
|
inputTokenMint,
|
|
4132
4138
|
outputTokenMint,
|
|
4133
4139
|
swapInAmount,
|
|
4134
|
-
maxAccounts,
|
|
4135
4140
|
slippageBps,
|
|
4136
4141
|
void 0,
|
|
4137
4142
|
{
|
|
@@ -4141,6 +4146,9 @@ var Zap = class {
|
|
|
4141
4146
|
},
|
|
4142
4147
|
jupiterQuoteOptions
|
|
4143
4148
|
);
|
|
4149
|
+
preInstructions.push(
|
|
4150
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4151
|
+
);
|
|
4144
4152
|
swapInstructions = [result.instruction];
|
|
4145
4153
|
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
4146
4154
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
@@ -4184,7 +4192,6 @@ var Zap = class {
|
|
|
4184
4192
|
inputTokenMint,
|
|
4185
4193
|
outputTokenMint,
|
|
4186
4194
|
swapInAmount,
|
|
4187
|
-
maxAccounts,
|
|
4188
4195
|
slippageBps,
|
|
4189
4196
|
void 0,
|
|
4190
4197
|
{
|
|
@@ -4194,6 +4201,9 @@ var Zap = class {
|
|
|
4194
4201
|
},
|
|
4195
4202
|
jupiterQuoteOptions
|
|
4196
4203
|
);
|
|
4204
|
+
preInstructions.push(
|
|
4205
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4206
|
+
);
|
|
4197
4207
|
swapInstructions = [result.instruction];
|
|
4198
4208
|
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
4199
4209
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
@@ -4273,13 +4283,12 @@ var Zap = class {
|
|
|
4273
4283
|
* @param params.amountIn - The amount of input token
|
|
4274
4284
|
* @param params.inputTokenMint - The input token mint
|
|
4275
4285
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
4276
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
4277
4286
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4278
4287
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
4279
4288
|
* @param params.jupiterQuoteToA - The Jupiter quote for swapping to tokenA for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
4280
4289
|
* @param params.jupiterQuoteToB - The Jupiter quote for swapping to tokenB for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
4281
4290
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4282
|
-
* @param params.jupiterQuoteOptions - Optional Jupiter
|
|
4291
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
4283
4292
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
4284
4293
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
4285
4294
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -4293,7 +4302,6 @@ var Zap = class {
|
|
|
4293
4302
|
pool,
|
|
4294
4303
|
positionNftMint,
|
|
4295
4304
|
amountIn,
|
|
4296
|
-
maxAccounts,
|
|
4297
4305
|
maxSqrtPriceChangeBps,
|
|
4298
4306
|
maxTransferAmountExtendPercentage,
|
|
4299
4307
|
slippageBps,
|
|
@@ -4389,7 +4397,6 @@ var Zap = class {
|
|
|
4389
4397
|
inputTokenMint,
|
|
4390
4398
|
tokenAMint,
|
|
4391
4399
|
amountIn,
|
|
4392
|
-
maxAccounts,
|
|
4393
4400
|
slippageBps,
|
|
4394
4401
|
void 0,
|
|
4395
4402
|
{
|
|
@@ -4399,6 +4406,9 @@ var Zap = class {
|
|
|
4399
4406
|
},
|
|
4400
4407
|
jupiterQuoteOptions
|
|
4401
4408
|
);
|
|
4409
|
+
preInstructions.push(
|
|
4410
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4411
|
+
);
|
|
4402
4412
|
return {
|
|
4403
4413
|
user,
|
|
4404
4414
|
pool,
|
|
@@ -4444,7 +4454,6 @@ var Zap = class {
|
|
|
4444
4454
|
inputTokenMint,
|
|
4445
4455
|
tokenBMint,
|
|
4446
4456
|
amountIn,
|
|
4447
|
-
maxAccounts,
|
|
4448
4457
|
slippageBps,
|
|
4449
4458
|
void 0,
|
|
4450
4459
|
{
|
|
@@ -4454,6 +4463,9 @@ var Zap = class {
|
|
|
4454
4463
|
},
|
|
4455
4464
|
jupiterQuoteOptions
|
|
4456
4465
|
);
|
|
4466
|
+
preInstructions.push(
|
|
4467
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4468
|
+
);
|
|
4457
4469
|
return {
|
|
4458
4470
|
user,
|
|
4459
4471
|
pool,
|
|
@@ -4494,7 +4506,6 @@ var Zap = class {
|
|
|
4494
4506
|
inputTokenMint,
|
|
4495
4507
|
tokenAMint,
|
|
4496
4508
|
amountIn,
|
|
4497
|
-
maxAccounts,
|
|
4498
4509
|
slippageBps,
|
|
4499
4510
|
void 0,
|
|
4500
4511
|
{
|
|
@@ -4504,6 +4515,9 @@ var Zap = class {
|
|
|
4504
4515
|
},
|
|
4505
4516
|
jupiterQuoteOptions
|
|
4506
4517
|
);
|
|
4518
|
+
preInstructions.push(
|
|
4519
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4520
|
+
);
|
|
4507
4521
|
return {
|
|
4508
4522
|
user,
|
|
4509
4523
|
pool,
|
|
@@ -4544,7 +4558,6 @@ var Zap = class {
|
|
|
4544
4558
|
inputTokenMint,
|
|
4545
4559
|
tokenBMint,
|
|
4546
4560
|
amountIn,
|
|
4547
|
-
maxAccounts,
|
|
4548
4561
|
slippageBps,
|
|
4549
4562
|
void 0,
|
|
4550
4563
|
{
|
|
@@ -4554,6 +4567,9 @@ var Zap = class {
|
|
|
4554
4567
|
},
|
|
4555
4568
|
jupiterQuoteOptions
|
|
4556
4569
|
);
|
|
4570
|
+
preInstructions.push(
|
|
4571
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4572
|
+
);
|
|
4557
4573
|
return {
|
|
4558
4574
|
user,
|
|
4559
4575
|
pool,
|
|
@@ -4635,7 +4651,6 @@ var Zap = class {
|
|
|
4635
4651
|
inputTokenMint,
|
|
4636
4652
|
tokenAMint,
|
|
4637
4653
|
swapAmountToA,
|
|
4638
|
-
maxAccounts,
|
|
4639
4654
|
slippageBps,
|
|
4640
4655
|
void 0,
|
|
4641
4656
|
{
|
|
@@ -4645,13 +4660,15 @@ var Zap = class {
|
|
|
4645
4660
|
},
|
|
4646
4661
|
jupiterQuoteOptions
|
|
4647
4662
|
);
|
|
4663
|
+
preInstructions.push(
|
|
4664
|
+
...getJupiterCreateAtaInstructions(swapToA.setupInstructions)
|
|
4665
|
+
);
|
|
4648
4666
|
const swapToB = yield buildJupiterSwapTransaction(
|
|
4649
4667
|
this.connection,
|
|
4650
4668
|
user,
|
|
4651
4669
|
inputTokenMint,
|
|
4652
4670
|
tokenBMint,
|
|
4653
4671
|
swapAmountToB,
|
|
4654
|
-
maxAccounts,
|
|
4655
4672
|
slippageBps,
|
|
4656
4673
|
void 0,
|
|
4657
4674
|
{
|
|
@@ -4661,6 +4678,9 @@ var Zap = class {
|
|
|
4661
4678
|
},
|
|
4662
4679
|
jupiterQuoteOptions
|
|
4663
4680
|
);
|
|
4681
|
+
preInstructions.push(
|
|
4682
|
+
...getJupiterCreateAtaInstructions(swapToB.setupInstructions)
|
|
4683
|
+
);
|
|
4664
4684
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4665
4685
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4666
4686
|
swapToA.quoteResponse.outAmount,
|
|
@@ -4711,7 +4731,7 @@ var Zap = class {
|
|
|
4711
4731
|
* @param params.amount - The amount to deposit
|
|
4712
4732
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4713
4733
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4714
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
4734
|
+
* @param params.preInstructions - Instructions to run before the zap in, including the token accounts the Jupiter swaps need. Token account creation repeated here is removed
|
|
4715
4735
|
* @param params.swapInstructions - Swap instructions to execute
|
|
4716
4736
|
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4717
4737
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
@@ -4739,30 +4759,13 @@ var Zap = class {
|
|
|
4739
4759
|
addressLookupTableAccounts,
|
|
4740
4760
|
cleanUpInstructions
|
|
4741
4761
|
} = params;
|
|
4742
|
-
const
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
tokenAMint,
|
|
4749
|
-
user,
|
|
4750
|
-
user,
|
|
4751
|
-
false,
|
|
4752
|
-
tokenAProgram
|
|
4753
|
-
),
|
|
4754
|
-
getOrCreateATAInstruction(
|
|
4755
|
-
this.connection,
|
|
4756
|
-
tokenBMint,
|
|
4757
|
-
user,
|
|
4758
|
-
user,
|
|
4759
|
-
false,
|
|
4760
|
-
tokenBProgram
|
|
4761
|
-
)
|
|
4762
|
+
const {
|
|
4763
|
+
tokenAccounts: [tokenAAccount, tokenBAccount],
|
|
4764
|
+
instructions: setupInstructions
|
|
4765
|
+
} = getCreateAtaInstructions(user, [
|
|
4766
|
+
{ mint: tokenAMint, tokenProgram: tokenAProgram },
|
|
4767
|
+
{ mint: tokenBMint, tokenProgram: tokenBProgram }
|
|
4762
4768
|
]);
|
|
4763
|
-
const setupInstructions = [];
|
|
4764
|
-
initializeTokenAIx && setupInstructions.push(initializeTokenAIx);
|
|
4765
|
-
initializeTokenBIx && setupInstructions.push(initializeTokenBIx);
|
|
4766
4769
|
setupInstructions.push(...preInstructions);
|
|
4767
4770
|
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4768
4771
|
if (isDirectPool) {
|
|
@@ -4844,7 +4847,7 @@ var Zap = class {
|
|
|
4844
4847
|
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4845
4848
|
return {
|
|
4846
4849
|
instructions: [
|
|
4847
|
-
...setupInstructions,
|
|
4850
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
4848
4851
|
...swapInstructions,
|
|
4849
4852
|
...ledgerInstructions,
|
|
4850
4853
|
zapInInstruction,
|
|
@@ -4868,7 +4871,6 @@ var Zap = class {
|
|
|
4868
4871
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4869
4872
|
* @param params.strategy - The liquidity distribution strategy
|
|
4870
4873
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4871
|
-
* @param params.maxAccounts - Max accounts for the Jupiter swap query. Example value is `50`; this is not safe for every pool/size. Combined with Direct estimators (`onlyDirectRoutes=true`) this can select a much thinner route than Jupiter UI.
|
|
4872
4874
|
* @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
|
|
4873
4875
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4874
4876
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
@@ -4889,7 +4891,6 @@ var Zap = class {
|
|
|
4889
4891
|
maxDeltaId,
|
|
4890
4892
|
strategy,
|
|
4891
4893
|
favorXInActiveId,
|
|
4892
|
-
maxAccounts,
|
|
4893
4894
|
swapSlippageBps,
|
|
4894
4895
|
maxTransferAmountExtendPercentage,
|
|
4895
4896
|
maxActiveBinSlippage,
|
|
@@ -4934,7 +4935,6 @@ var Zap = class {
|
|
|
4934
4935
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4935
4936
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
4936
4937
|
directSwapEstimate.swapAmount,
|
|
4937
|
-
maxAccounts,
|
|
4938
4938
|
swapSlippageBps,
|
|
4939
4939
|
swapQuote.originalQuote,
|
|
4940
4940
|
{
|
|
@@ -4943,6 +4943,9 @@ var Zap = class {
|
|
|
4943
4943
|
jupiterApiVersion: this.jupiterApiVersion
|
|
4944
4944
|
}
|
|
4945
4945
|
);
|
|
4946
|
+
preInstructions.push(
|
|
4947
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
4948
|
+
);
|
|
4946
4949
|
swapInstructions.push(swap.instruction);
|
|
4947
4950
|
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4948
4951
|
} else {
|
|
@@ -5041,7 +5044,6 @@ var Zap = class {
|
|
|
5041
5044
|
* @param params.strategy - The liquidity distribution strategy
|
|
5042
5045
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5043
5046
|
* @param params.indirectSwapEstimate - The result from the indirect swap estimate
|
|
5044
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
5045
5047
|
* @param params.swapSlippageBps - The swap slippage tolerance in basis points
|
|
5046
5048
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
5047
5049
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
@@ -5062,7 +5064,6 @@ var Zap = class {
|
|
|
5062
5064
|
strategy,
|
|
5063
5065
|
favorXInActiveId,
|
|
5064
5066
|
indirectSwapEstimate,
|
|
5065
|
-
maxAccounts,
|
|
5066
5067
|
swapSlippageBps,
|
|
5067
5068
|
maxTransferAmountExtendPercentage,
|
|
5068
5069
|
maxActiveBinSlippage,
|
|
@@ -5111,7 +5112,6 @@ var Zap = class {
|
|
|
5111
5112
|
inputTokenMint,
|
|
5112
5113
|
tokenXMint,
|
|
5113
5114
|
swapAmountToXInLamports,
|
|
5114
|
-
maxAccounts,
|
|
5115
5115
|
swapSlippageBps,
|
|
5116
5116
|
indirectSwapEstimate.swapToX,
|
|
5117
5117
|
{
|
|
@@ -5120,6 +5120,9 @@ var Zap = class {
|
|
|
5120
5120
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5121
5121
|
}
|
|
5122
5122
|
);
|
|
5123
|
+
preInstructions.push(
|
|
5124
|
+
...getJupiterCreateAtaInstructions(swapToX.setupInstructions)
|
|
5125
|
+
);
|
|
5123
5126
|
swapInstructions.push(swapToX.instruction);
|
|
5124
5127
|
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
5125
5128
|
}
|
|
@@ -5130,7 +5133,6 @@ var Zap = class {
|
|
|
5130
5133
|
inputTokenMint,
|
|
5131
5134
|
tokenYMint,
|
|
5132
5135
|
swapAmountToYInLamports,
|
|
5133
|
-
maxAccounts,
|
|
5134
5136
|
swapSlippageBps,
|
|
5135
5137
|
indirectSwapEstimate.swapToY,
|
|
5136
5138
|
{
|
|
@@ -5139,6 +5141,9 @@ var Zap = class {
|
|
|
5139
5141
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5140
5142
|
}
|
|
5141
5143
|
);
|
|
5144
|
+
preInstructions.push(
|
|
5145
|
+
...getJupiterCreateAtaInstructions(swapToY.setupInstructions)
|
|
5146
|
+
);
|
|
5142
5147
|
swapInstructions.push(swapToY.instruction);
|
|
5143
5148
|
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
5144
5149
|
}
|
|
@@ -5217,7 +5222,7 @@ var Zap = class {
|
|
|
5217
5222
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
5218
5223
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5219
5224
|
* @param params.strategy - The liquidity distribution strategy
|
|
5220
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
5225
|
+
* @param params.preInstructions - Instructions to run before the zap in, including the token accounts the Jupiter swaps need. Token account creation repeated here is removed
|
|
5221
5226
|
* @param params.swapInstructions - Swap instructions to execute
|
|
5222
5227
|
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
5223
5228
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
@@ -5252,30 +5257,13 @@ var Zap = class {
|
|
|
5252
5257
|
isDirectRoute,
|
|
5253
5258
|
singleSided
|
|
5254
5259
|
} = params;
|
|
5255
|
-
const
|
|
5256
|
-
|
|
5257
|
-
|
|
5258
|
-
|
|
5259
|
-
|
|
5260
|
-
|
|
5261
|
-
tokenXMint,
|
|
5262
|
-
user,
|
|
5263
|
-
user,
|
|
5264
|
-
false,
|
|
5265
|
-
tokenXProgram
|
|
5266
|
-
),
|
|
5267
|
-
getOrCreateATAInstruction(
|
|
5268
|
-
this.connection,
|
|
5269
|
-
tokenYMint,
|
|
5270
|
-
user,
|
|
5271
|
-
user,
|
|
5272
|
-
false,
|
|
5273
|
-
tokenYProgram
|
|
5274
|
-
)
|
|
5260
|
+
const {
|
|
5261
|
+
tokenAccounts: [tokenXAccount, tokenYAccount],
|
|
5262
|
+
instructions: setupInstructions
|
|
5263
|
+
} = getCreateAtaInstructions(user, [
|
|
5264
|
+
{ mint: tokenXMint, tokenProgram: tokenXProgram },
|
|
5265
|
+
{ mint: tokenYMint, tokenProgram: tokenYProgram }
|
|
5275
5266
|
]);
|
|
5276
|
-
const setupInstructions = [];
|
|
5277
|
-
initializeTokenXIx && setupInstructions.push(initializeTokenXIx);
|
|
5278
|
-
initializeTokenYIx && setupInstructions.push(initializeTokenYIx);
|
|
5279
5267
|
setupInstructions.push(...preInstructions);
|
|
5280
5268
|
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
5281
5269
|
if (isDirectRoute) {
|
|
@@ -5399,7 +5387,7 @@ var Zap = class {
|
|
|
5399
5387
|
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
5400
5388
|
return {
|
|
5401
5389
|
instructions: [
|
|
5402
|
-
...setupInstructions,
|
|
5390
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5403
5391
|
...swapInstructions,
|
|
5404
5392
|
...ledgerInstructions,
|
|
5405
5393
|
zapInInstruction,
|
|
@@ -5432,7 +5420,6 @@ var Zap = class {
|
|
|
5432
5420
|
* @param params.strategy - The strategy to use for the rebalance
|
|
5433
5421
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5434
5422
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
5435
|
-
* @param params.maxAccounts - The maximum number of accounts to use for the swap operation
|
|
5436
5423
|
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
5437
5424
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
5438
5425
|
*/
|
|
@@ -5448,36 +5435,18 @@ var Zap = class {
|
|
|
5448
5435
|
swapSlippageBps,
|
|
5449
5436
|
strategy,
|
|
5450
5437
|
favorXInActiveId,
|
|
5451
|
-
directSwapEstimate
|
|
5452
|
-
maxAccounts = 50
|
|
5438
|
+
directSwapEstimate
|
|
5453
5439
|
} = params;
|
|
5454
5440
|
const dlmm = yield import_dlmm4.default.create(this.connection, lbPair);
|
|
5455
5441
|
const userPosition = yield dlmm.getPosition(position);
|
|
5456
5442
|
const { tokenXProgram, tokenYProgram } = (0, import_dlmm4.getTokenProgramId)(dlmm.lbPair);
|
|
5457
|
-
const
|
|
5458
|
-
|
|
5459
|
-
|
|
5460
|
-
|
|
5461
|
-
|
|
5462
|
-
|
|
5463
|
-
dlmm.lbPair.tokenXMint,
|
|
5464
|
-
user,
|
|
5465
|
-
user,
|
|
5466
|
-
true,
|
|
5467
|
-
tokenXProgram
|
|
5468
|
-
),
|
|
5469
|
-
getOrCreateATAInstruction(
|
|
5470
|
-
this.connection,
|
|
5471
|
-
dlmm.lbPair.tokenYMint,
|
|
5472
|
-
user,
|
|
5473
|
-
user,
|
|
5474
|
-
true,
|
|
5475
|
-
tokenYProgram
|
|
5476
|
-
)
|
|
5443
|
+
const {
|
|
5444
|
+
tokenAccounts: [userTokenX, userTokenY],
|
|
5445
|
+
instructions: setupInstructions
|
|
5446
|
+
} = getCreateAtaInstructions(user, [
|
|
5447
|
+
{ mint: dlmm.lbPair.tokenXMint, tokenProgram: tokenXProgram },
|
|
5448
|
+
{ mint: dlmm.lbPair.tokenYMint, tokenProgram: tokenYProgram }
|
|
5477
5449
|
]);
|
|
5478
|
-
const setupInstructions = [];
|
|
5479
|
-
userTokenXIx && setupInstructions.push(userTokenXIx);
|
|
5480
|
-
userTokenYIx && setupInstructions.push(userTokenYIx);
|
|
5481
5450
|
const strategyParamBuilder = (0, import_dlmm4.getLiquidityStrategyParameterBuilder)(strategy);
|
|
5482
5451
|
const { x0, y0, deltaX, deltaY } = (0, import_dlmm4.buildLiquidityStrategyParameters)(
|
|
5483
5452
|
new import_core.BN(0),
|
|
@@ -5549,7 +5518,6 @@ var Zap = class {
|
|
|
5549
5518
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
5550
5519
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
5551
5520
|
directSwapEstimate.swapAmount,
|
|
5552
|
-
maxAccounts,
|
|
5553
5521
|
swapSlippageBps,
|
|
5554
5522
|
swapQuote.originalQuote,
|
|
5555
5523
|
{
|
|
@@ -5558,6 +5526,9 @@ var Zap = class {
|
|
|
5558
5526
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5559
5527
|
}
|
|
5560
5528
|
);
|
|
5529
|
+
setupInstructions.push(
|
|
5530
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
5531
|
+
);
|
|
5561
5532
|
swapInstructions = [swap.instruction];
|
|
5562
5533
|
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
5563
5534
|
} else {
|
|
@@ -5660,7 +5631,7 @@ var Zap = class {
|
|
|
5660
5631
|
}
|
|
5661
5632
|
return {
|
|
5662
5633
|
instructions: [
|
|
5663
|
-
...setupInstructions,
|
|
5634
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5664
5635
|
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5665
5636
|
...rebalancePositionInstruction,
|
|
5666
5637
|
...swapInstructions,
|
|
@@ -5737,6 +5708,7 @@ var Zap = class {
|
|
|
5737
5708
|
*/
|
|
5738
5709
|
zapOutThroughJupiter(params) {
|
|
5739
5710
|
return __async(this, null, function* () {
|
|
5711
|
+
var _a;
|
|
5740
5712
|
const {
|
|
5741
5713
|
user,
|
|
5742
5714
|
inputMint,
|
|
@@ -5749,29 +5721,21 @@ var Zap = class {
|
|
|
5749
5721
|
} = params;
|
|
5750
5722
|
const preInstructions = [];
|
|
5751
5723
|
const postInstructions = [];
|
|
5752
|
-
const
|
|
5753
|
-
|
|
5754
|
-
|
|
5755
|
-
|
|
5756
|
-
|
|
5757
|
-
|
|
5758
|
-
inputMint,
|
|
5759
|
-
user,
|
|
5760
|
-
user,
|
|
5761
|
-
true,
|
|
5762
|
-
inputTokenProgram
|
|
5763
|
-
),
|
|
5764
|
-
getOrCreateATAInstruction(
|
|
5765
|
-
this.connection,
|
|
5766
|
-
outputMint,
|
|
5767
|
-
user,
|
|
5768
|
-
user,
|
|
5769
|
-
true,
|
|
5770
|
-
outputTokenProgram
|
|
5771
|
-
)
|
|
5724
|
+
const {
|
|
5725
|
+
tokenAccounts: [inputTokenAccount],
|
|
5726
|
+
instructions: createAtaInstructions
|
|
5727
|
+
} = getCreateAtaInstructions(user, [
|
|
5728
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5729
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5772
5730
|
]);
|
|
5773
|
-
|
|
5774
|
-
|
|
5731
|
+
preInstructions.push(...createAtaInstructions);
|
|
5732
|
+
preInstructions.push(
|
|
5733
|
+
...getJupiterCreateAtaInstructions(
|
|
5734
|
+
((_a = jupiterSwapResponse.setupInstructions) != null ? _a : []).map(
|
|
5735
|
+
toTransactionInstruction
|
|
5736
|
+
)
|
|
5737
|
+
)
|
|
5738
|
+
);
|
|
5775
5739
|
let preUserTokenBalance;
|
|
5776
5740
|
try {
|
|
5777
5741
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5816,7 +5780,7 @@ var Zap = class {
|
|
|
5816
5780
|
},
|
|
5817
5781
|
remainingAccounts,
|
|
5818
5782
|
ammProgram: JUP_V6_PROGRAM_ID,
|
|
5819
|
-
preInstructions,
|
|
5783
|
+
preInstructions: dedupeCreateAtaInstructions(preInstructions),
|
|
5820
5784
|
postInstructions
|
|
5821
5785
|
}),
|
|
5822
5786
|
getJupiterAddressLookupTableAccounts(
|
|
@@ -5859,29 +5823,14 @@ var Zap = class {
|
|
|
5859
5823
|
const poolState = yield getDammV2Pool(this.connection, poolAddress);
|
|
5860
5824
|
const preInstructions = [];
|
|
5861
5825
|
const postInstructions = [];
|
|
5862
|
-
const
|
|
5863
|
-
|
|
5864
|
-
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
|
|
5868
|
-
inputMint,
|
|
5869
|
-
user,
|
|
5870
|
-
user,
|
|
5871
|
-
true,
|
|
5872
|
-
inputTokenProgram
|
|
5873
|
-
),
|
|
5874
|
-
getOrCreateATAInstruction(
|
|
5875
|
-
this.connection,
|
|
5876
|
-
outputMint,
|
|
5877
|
-
user,
|
|
5878
|
-
user,
|
|
5879
|
-
true,
|
|
5880
|
-
outputTokenProgram
|
|
5881
|
-
)
|
|
5826
|
+
const {
|
|
5827
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5828
|
+
instructions: createAtaInstructions
|
|
5829
|
+
} = getCreateAtaInstructions(user, [
|
|
5830
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5831
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5882
5832
|
]);
|
|
5883
|
-
|
|
5884
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5833
|
+
preInstructions.push(...createAtaInstructions);
|
|
5885
5834
|
let preUserTokenBalance;
|
|
5886
5835
|
try {
|
|
5887
5836
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5956,29 +5905,14 @@ var Zap = class {
|
|
|
5956
5905
|
const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
|
|
5957
5906
|
const preInstructions = [];
|
|
5958
5907
|
const postInstructions = [];
|
|
5959
|
-
const
|
|
5960
|
-
|
|
5961
|
-
|
|
5962
|
-
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
inputMint,
|
|
5966
|
-
user,
|
|
5967
|
-
user,
|
|
5968
|
-
true,
|
|
5969
|
-
inputTokenProgram
|
|
5970
|
-
),
|
|
5971
|
-
getOrCreateATAInstruction(
|
|
5972
|
-
this.connection,
|
|
5973
|
-
outputMint,
|
|
5974
|
-
user,
|
|
5975
|
-
user,
|
|
5976
|
-
true,
|
|
5977
|
-
outputTokenProgram
|
|
5978
|
-
)
|
|
5908
|
+
const {
|
|
5909
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5910
|
+
instructions: createAtaInstructions
|
|
5911
|
+
} = getCreateAtaInstructions(user, [
|
|
5912
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5913
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5979
5914
|
]);
|
|
5980
|
-
|
|
5981
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5915
|
+
preInstructions.push(...createAtaInstructions);
|
|
5982
5916
|
let preUserTokenBalance;
|
|
5983
5917
|
try {
|
|
5984
5918
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -6037,18 +5971,12 @@ var Zap = class {
|
|
|
6037
5971
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
6038
5972
|
DEFAULT_JUPITER_API_URL,
|
|
6039
5973
|
DEFAULT_JUPITER_API_VERSION,
|
|
6040
|
-
DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
6041
5974
|
DLMM_PROGRAM_ID,
|
|
6042
5975
|
DLMM_SWAP_DISCRIMINATOR,
|
|
6043
5976
|
DlmmDirectSwapQuoteRoute,
|
|
6044
5977
|
DlmmSingleSided,
|
|
6045
5978
|
DlmmSwapType,
|
|
6046
|
-
JUPITER_INSTRUCTION_LAYOUTS,
|
|
6047
5979
|
JUP_V6_PROGRAM_ID,
|
|
6048
|
-
JUP_V6_ROUTE_DISCRIMINATOR,
|
|
6049
|
-
JUP_V6_ROUTE_V2_DISCRIMINATOR,
|
|
6050
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR,
|
|
6051
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR,
|
|
6052
5980
|
JupiterApiVersion,
|
|
6053
5981
|
MEMO_PROGRAM_ID,
|
|
6054
5982
|
SwapExternalType,
|
|
@@ -6069,17 +5997,13 @@ var Zap = class {
|
|
|
6069
5997
|
estimateDlmmDirectSwap,
|
|
6070
5998
|
estimateDlmmIndirectSwap,
|
|
6071
5999
|
estimateDlmmRebalanceSwap,
|
|
6072
|
-
fetchAddressLookupTableAccounts,
|
|
6073
6000
|
filterOutCloseSplTokenAccountInstructions,
|
|
6074
|
-
filterOutComputeBudgetInstructions,
|
|
6075
6001
|
getBinArrayBitmapExtension,
|
|
6076
6002
|
getBitFromBinArrayIndexInBitmapExtension,
|
|
6077
6003
|
getDammV2Pool,
|
|
6078
6004
|
getDammV2RemainingAccounts,
|
|
6079
6005
|
getDlmmRemainingAccounts,
|
|
6080
6006
|
getExtraAccountMetasForTransferHook,
|
|
6081
|
-
getJupiterAddressLookupTableAccounts,
|
|
6082
|
-
getJupiterInstructionLayout,
|
|
6083
6007
|
getJupiterQuote,
|
|
6084
6008
|
getJupiterSwapInstruction,
|
|
6085
6009
|
getLbPairState,
|
|
@@ -6087,13 +6011,8 @@ var Zap = class {
|
|
|
6087
6011
|
getOrCreateATAInstruction,
|
|
6088
6012
|
getTokenAccountBalance,
|
|
6089
6013
|
getTokenProgramFromMint,
|
|
6090
|
-
isJupiterBuildResponse,
|
|
6091
|
-
isJupiterSwapInstructionForUser,
|
|
6092
6014
|
isSingleSidedA,
|
|
6093
6015
|
isSingleSidedB,
|
|
6094
|
-
mergeAddressLookupTableAccounts,
|
|
6095
|
-
resolveJupiterConfig,
|
|
6096
|
-
toAddressLookupTableAccounts,
|
|
6097
6016
|
toProgramStrategyType,
|
|
6098
6017
|
unwrapSOLInstruction,
|
|
6099
6018
|
wrapSOLInstruction
|