@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.mjs
CHANGED
|
@@ -1912,8 +1912,8 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
|
|
|
1912
1912
|
import {
|
|
1913
1913
|
AddressLookupTableAccount,
|
|
1914
1914
|
AddressLookupTableProgram,
|
|
1915
|
-
PublicKey as
|
|
1916
|
-
TransactionInstruction
|
|
1915
|
+
PublicKey as PublicKey3,
|
|
1916
|
+
TransactionInstruction as TransactionInstruction2
|
|
1917
1917
|
} from "@solana/web3.js";
|
|
1918
1918
|
|
|
1919
1919
|
// src/constants.ts
|
|
@@ -2033,20 +2033,134 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
|
2033
2033
|
];
|
|
2034
2034
|
var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
|
|
2035
2035
|
var DEFAULT_JUPITER_API_VERSION = "v2" /* V2 */;
|
|
2036
|
-
|
|
2037
|
-
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2036
|
+
|
|
2037
|
+
// src/helpers/token.ts
|
|
2038
|
+
import {
|
|
2039
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
2040
|
+
createAssociatedTokenAccountIdempotentInstruction,
|
|
2041
|
+
createCloseAccountInstruction,
|
|
2042
|
+
getAssociatedTokenAddressSync,
|
|
2043
|
+
NATIVE_MINT,
|
|
2044
|
+
TOKEN_PROGRAM_ID
|
|
2045
|
+
} from "@solana/spl-token";
|
|
2046
|
+
import {
|
|
2047
|
+
SystemProgram,
|
|
2048
|
+
TransactionInstruction
|
|
2049
|
+
} from "@solana/web3.js";
|
|
2050
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2051
|
+
const toAccount = getAssociatedTokenAddressSync(
|
|
2052
|
+
tokenMint,
|
|
2053
|
+
owner,
|
|
2054
|
+
allowOwnerOffCurve,
|
|
2055
|
+
tokenProgram
|
|
2056
|
+
);
|
|
2057
|
+
const ix = createAssociatedTokenAccountIdempotentInstruction(
|
|
2058
|
+
payer,
|
|
2059
|
+
toAccount,
|
|
2060
|
+
owner,
|
|
2061
|
+
tokenMint,
|
|
2062
|
+
tokenProgram
|
|
2063
|
+
);
|
|
2064
|
+
return { ataPubkey: toAccount, ix };
|
|
2065
|
+
});
|
|
2066
|
+
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2067
|
+
const wSolATAAccount = getAssociatedTokenAddressSync(
|
|
2068
|
+
NATIVE_MINT,
|
|
2069
|
+
owner,
|
|
2070
|
+
allowOwnerOffCurve
|
|
2071
|
+
);
|
|
2072
|
+
if (wSolATAAccount) {
|
|
2073
|
+
const closedWrappedSolInstruction = createCloseAccountInstruction(
|
|
2074
|
+
wSolATAAccount,
|
|
2075
|
+
receiver,
|
|
2076
|
+
owner,
|
|
2077
|
+
[],
|
|
2078
|
+
TOKEN_PROGRAM_ID
|
|
2079
|
+
);
|
|
2080
|
+
return closedWrappedSolInstruction;
|
|
2081
|
+
}
|
|
2082
|
+
return null;
|
|
2083
|
+
}
|
|
2084
|
+
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2085
|
+
return __async(this, null, function* () {
|
|
2086
|
+
let balance;
|
|
2087
|
+
try {
|
|
2088
|
+
balance = (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
2089
|
+
} catch (e) {
|
|
2090
|
+
balance = "0";
|
|
2091
|
+
}
|
|
2092
|
+
return balance;
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID) {
|
|
2096
|
+
return [
|
|
2097
|
+
SystemProgram.transfer({
|
|
2098
|
+
fromPubkey: from,
|
|
2099
|
+
toPubkey: to,
|
|
2100
|
+
lamports: amount
|
|
2101
|
+
}),
|
|
2102
|
+
new TransactionInstruction({
|
|
2103
|
+
keys: [
|
|
2104
|
+
{
|
|
2105
|
+
pubkey: to,
|
|
2106
|
+
isSigner: false,
|
|
2107
|
+
isWritable: true
|
|
2108
|
+
}
|
|
2109
|
+
],
|
|
2110
|
+
data: Buffer.from(new Uint8Array([17])),
|
|
2111
|
+
programId: tokenProgram
|
|
2112
|
+
})
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
2115
|
+
var CLOSE_ACCOUNT_DISCRIMINATOR = 9;
|
|
2116
|
+
function filterOutCloseSplTokenAccountInstructions(instructions) {
|
|
2117
|
+
return instructions.filter((ix) => {
|
|
2118
|
+
if (ix.programId.equals(TOKEN_PROGRAM_ID)) {
|
|
2119
|
+
return ix.data[0] !== CLOSE_ACCOUNT_DISCRIMINATOR;
|
|
2120
|
+
}
|
|
2121
|
+
return true;
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
function getCreateAtaInstructions(user, tokens) {
|
|
2125
|
+
const tokenAccounts = tokens.map(
|
|
2126
|
+
({ mint, tokenProgram }) => getAssociatedTokenAddressSync(mint, user, true, tokenProgram)
|
|
2127
|
+
);
|
|
2128
|
+
const instructions = tokens.map(
|
|
2129
|
+
({ mint, tokenProgram }, i) => createAssociatedTokenAccountIdempotentInstruction(
|
|
2130
|
+
user,
|
|
2131
|
+
tokenAccounts[i],
|
|
2132
|
+
user,
|
|
2133
|
+
mint,
|
|
2134
|
+
tokenProgram
|
|
2135
|
+
)
|
|
2136
|
+
);
|
|
2137
|
+
return { tokenAccounts, instructions };
|
|
2138
|
+
}
|
|
2139
|
+
function isCreateAtaInstruction(ix) {
|
|
2140
|
+
return ix.programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID) && (ix.data.length === 0 || ix.data[0] === 0 || ix.data[0] === 1);
|
|
2141
|
+
}
|
|
2142
|
+
function dedupeCreateAtaInstructions(instructions) {
|
|
2143
|
+
const createdAccounts = /* @__PURE__ */ new Set();
|
|
2144
|
+
return instructions.filter((ix) => {
|
|
2145
|
+
if (!isCreateAtaInstruction(ix)) {
|
|
2146
|
+
return true;
|
|
2147
|
+
}
|
|
2148
|
+
const account = ix.keys[1].pubkey.toBase58();
|
|
2149
|
+
if (createdAccounts.has(account)) {
|
|
2150
|
+
return false;
|
|
2151
|
+
}
|
|
2152
|
+
createdAccounts.add(account);
|
|
2153
|
+
return true;
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
2042
2156
|
|
|
2043
2157
|
// src/helpers/jupiter.ts
|
|
2044
|
-
function resolveJupiterConfig(config
|
|
2158
|
+
function resolveJupiterConfig(config) {
|
|
2045
2159
|
var _a;
|
|
2046
2160
|
return {
|
|
2047
|
-
url: config.jupiterApiUrl || DEFAULT_JUPITER_API_URL,
|
|
2048
|
-
apiKey: config.jupiterApiKey || "",
|
|
2049
|
-
version: (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2161
|
+
url: (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL,
|
|
2162
|
+
apiKey: (config == null ? void 0 : config.jupiterApiKey) || "",
|
|
2163
|
+
version: (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2050
2164
|
};
|
|
2051
2165
|
}
|
|
2052
2166
|
function getJupiterInstructionLayout(data) {
|
|
@@ -2067,37 +2181,28 @@ function isJupiterSwapInstructionForUser(swapInstruction, user) {
|
|
|
2067
2181
|
Buffer.from(swapInstruction.data, "base64")
|
|
2068
2182
|
);
|
|
2069
2183
|
const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
|
|
2070
|
-
return authority !== void 0 && new
|
|
2184
|
+
return authority !== void 0 && new PublicKey3(authority.pubkey).equals(user);
|
|
2071
2185
|
}
|
|
2072
2186
|
function jupiterHeaders(apiKey, json) {
|
|
2073
2187
|
return __spreadValues(__spreadValues({
|
|
2074
2188
|
Accept: "application/json"
|
|
2075
2189
|
}, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
|
|
2076
2190
|
}
|
|
2077
|
-
function toSearchParams(
|
|
2191
|
+
function toSearchParams(params) {
|
|
2078
2192
|
var _a;
|
|
2079
|
-
const
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
amount: query.amount,
|
|
2083
|
-
slippageBps: query.slippageBps.toString()
|
|
2084
|
-
}, query.maxAccounts !== void 0 ? { maxAccounts: query.maxAccounts.toString() } : {}), {
|
|
2085
|
-
onlyDirectRoutes: query.onlyDirectRoutes.toString(),
|
|
2086
|
-
restrictIntermediateTokens: query.restrictIntermediateTokens.toString(),
|
|
2087
|
-
dynamicSlippage: query.dynamicSlippage.toString(),
|
|
2088
|
-
forJitoBundle: query.forJitoBundle.toString()
|
|
2089
|
-
}));
|
|
2090
|
-
for (const [name, value] of Object.entries(
|
|
2091
|
-
(_a = query.additionalQueryParams) != null ? _a : {}
|
|
2092
|
-
)) {
|
|
2093
|
-
params.set(name, value);
|
|
2193
|
+
const searchParams = new URLSearchParams();
|
|
2194
|
+
for (const [name, value] of Object.entries((_a = params.queryParams) != null ? _a : {})) {
|
|
2195
|
+
searchParams.set(name, value.toString());
|
|
2094
2196
|
}
|
|
2095
|
-
|
|
2197
|
+
searchParams.set("inputMint", params.inputMint.toString());
|
|
2198
|
+
searchParams.set("outputMint", params.outputMint.toString());
|
|
2199
|
+
searchParams.set("amount", params.amount.toString());
|
|
2200
|
+
return searchParams;
|
|
2096
2201
|
}
|
|
2097
|
-
function fetchJupiterQuoteV1(
|
|
2202
|
+
function fetchJupiterQuoteV1(params, config) {
|
|
2098
2203
|
return __async(this, null, function* () {
|
|
2099
2204
|
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2100
|
-
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(
|
|
2205
|
+
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(params).toString()}`;
|
|
2101
2206
|
try {
|
|
2102
2207
|
const response = yield fetch(url, {
|
|
2103
2208
|
method: "GET",
|
|
@@ -2112,12 +2217,12 @@ function fetchJupiterQuoteV1(query, config) {
|
|
|
2112
2217
|
}
|
|
2113
2218
|
});
|
|
2114
2219
|
}
|
|
2115
|
-
function fetchJupiterBuildV2(
|
|
2220
|
+
function fetchJupiterBuildV2(params, config) {
|
|
2116
2221
|
return __async(this, null, function* () {
|
|
2117
2222
|
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2120
|
-
const url = `${baseUrl}/swap/v2/build?${
|
|
2223
|
+
const searchParams = toSearchParams(params);
|
|
2224
|
+
searchParams.set("taker", params.user.toString());
|
|
2225
|
+
const url = `${baseUrl}/swap/v2/build?${searchParams.toString()}`;
|
|
2121
2226
|
try {
|
|
2122
2227
|
const response = yield fetch(url, {
|
|
2123
2228
|
method: "GET",
|
|
@@ -2132,26 +2237,13 @@ function fetchJupiterBuildV2(query, taker, config) {
|
|
|
2132
2237
|
}
|
|
2133
2238
|
});
|
|
2134
2239
|
}
|
|
2135
|
-
function getJupiterQuote(
|
|
2136
|
-
return __async(this,
|
|
2137
|
-
var _a, _b, _c, _d;
|
|
2138
|
-
const query = {
|
|
2139
|
-
inputMint: params.inputMint,
|
|
2140
|
-
outputMint: params.outputMint,
|
|
2141
|
-
amount: params.amount.toString(),
|
|
2142
|
-
slippageBps: params.slippageBps,
|
|
2143
|
-
maxAccounts: params.maxAccounts,
|
|
2144
|
-
dynamicSlippage: (_a = params.dynamicSlippage) != null ? _a : DEFAULT_JUPITER_QUOTE_OPTIONS.dynamicSlippage,
|
|
2145
|
-
onlyDirectRoutes: (_b = params.onlyDirectRoutes) != null ? _b : DEFAULT_JUPITER_QUOTE_OPTIONS.onlyDirectRoutes,
|
|
2146
|
-
restrictIntermediateTokens: (_c = params.restrictIntermediateTokens) != null ? _c : DEFAULT_JUPITER_QUOTE_OPTIONS.restrictIntermediateTokens,
|
|
2147
|
-
forJitoBundle: (_d = params.forJitoBundle) != null ? _d : DEFAULT_JUPITER_QUOTE_OPTIONS.forJitoBundle,
|
|
2148
|
-
additionalQueryParams: params.additionalQueryParams
|
|
2149
|
-
};
|
|
2240
|
+
function getJupiterQuote(params, config) {
|
|
2241
|
+
return __async(this, null, function* () {
|
|
2150
2242
|
const { version } = resolveJupiterConfig(config);
|
|
2151
2243
|
if (version === "v1" /* V1 */) {
|
|
2152
|
-
return fetchJupiterQuoteV1(
|
|
2244
|
+
return fetchJupiterQuoteV1(params, config);
|
|
2153
2245
|
}
|
|
2154
|
-
return fetchJupiterBuildV2(
|
|
2246
|
+
return fetchJupiterBuildV2(params, config);
|
|
2155
2247
|
});
|
|
2156
2248
|
}
|
|
2157
2249
|
function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
@@ -2181,8 +2273,8 @@ function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
|
2181
2273
|
return yield response.json();
|
|
2182
2274
|
});
|
|
2183
2275
|
}
|
|
2184
|
-
function getJupiterSwapInstruction(
|
|
2185
|
-
return __async(this,
|
|
2276
|
+
function getJupiterSwapInstruction(userPublicKey, quoteResponse, config) {
|
|
2277
|
+
return __async(this, null, function* () {
|
|
2186
2278
|
const { version } = resolveJupiterConfig(config);
|
|
2187
2279
|
if (version === "v1" /* V1 */) {
|
|
2188
2280
|
return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
|
|
@@ -2216,9 +2308,9 @@ var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
|
|
|
2216
2308
|
function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
|
|
2217
2309
|
return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
|
|
2218
2310
|
([key, addresses]) => new AddressLookupTableAccount({
|
|
2219
|
-
key: new
|
|
2311
|
+
key: new PublicKey3(key),
|
|
2220
2312
|
state: {
|
|
2221
|
-
addresses: addresses.map((address) => new
|
|
2313
|
+
addresses: addresses.map((address) => new PublicKey3(address)),
|
|
2222
2314
|
deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
|
|
2223
2315
|
lastExtendedSlot: 0,
|
|
2224
2316
|
lastExtendedSlotStartIndex: 0
|
|
@@ -2231,7 +2323,7 @@ function fetchAddressLookupTableAccounts(connection, addresses) {
|
|
|
2231
2323
|
if (addresses.length === 0) {
|
|
2232
2324
|
return [];
|
|
2233
2325
|
}
|
|
2234
|
-
const keys = addresses.map((address) => new
|
|
2326
|
+
const keys = addresses.map((address) => new PublicKey3(address));
|
|
2235
2327
|
const accounts = yield connection.getMultipleAccountsInfo(keys);
|
|
2236
2328
|
return keys.map((key, i) => {
|
|
2237
2329
|
const account = accounts[i];
|
|
@@ -2267,22 +2359,35 @@ function getJupiterAddressLookupTableAccounts(connection, response) {
|
|
|
2267
2359
|
);
|
|
2268
2360
|
});
|
|
2269
2361
|
}
|
|
2270
|
-
function
|
|
2271
|
-
return
|
|
2362
|
+
function toTransactionInstruction(instruction) {
|
|
2363
|
+
return new TransactionInstruction2({
|
|
2364
|
+
keys: instruction.accounts.map((item) => ({
|
|
2365
|
+
pubkey: new PublicKey3(item.pubkey),
|
|
2366
|
+
isSigner: item.isSigner,
|
|
2367
|
+
isWritable: item.isWritable
|
|
2368
|
+
})),
|
|
2369
|
+
programId: new PublicKey3(instruction.programId),
|
|
2370
|
+
data: Buffer.from(instruction.data, "base64")
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
function getJupiterCreateAtaInstructions(setupInstructions) {
|
|
2374
|
+
return setupInstructions.filter(isCreateAtaInstruction);
|
|
2375
|
+
}
|
|
2376
|
+
function buildJupiterSwapTransaction(connection, user, inputMint, outputMint, amount, slippageBps, jupiterQuoteResponse, config, jupiterQuoteOptions) {
|
|
2377
|
+
return __async(this, null, function* () {
|
|
2272
2378
|
if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
|
|
2273
2379
|
throw new Error(
|
|
2274
2380
|
`Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
|
|
2275
2381
|
);
|
|
2276
2382
|
}
|
|
2277
2383
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
2278
|
-
|
|
2384
|
+
{
|
|
2279
2385
|
inputMint,
|
|
2280
2386
|
outputMint,
|
|
2281
2387
|
amount,
|
|
2282
2388
|
user,
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
}, jupiterQuoteOptions),
|
|
2389
|
+
queryParams: __spreadValues({ slippageBps }, jupiterQuoteOptions)
|
|
2390
|
+
},
|
|
2286
2391
|
config
|
|
2287
2392
|
);
|
|
2288
2393
|
if (!quoteResponse) {
|
|
@@ -2295,27 +2400,27 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
|
2295
2400
|
quoteResponse,
|
|
2296
2401
|
config
|
|
2297
2402
|
);
|
|
2298
|
-
const instruction =
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
};
|
|
2305
|
-
}),
|
|
2306
|
-
programId: new PublicKey2(swapInstructionResponse.swapInstruction.programId),
|
|
2307
|
-
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
2308
|
-
});
|
|
2403
|
+
const instruction = toTransactionInstruction(
|
|
2404
|
+
swapInstructionResponse.swapInstruction
|
|
2405
|
+
);
|
|
2406
|
+
const setupInstructions = swapInstructionResponse.setupInstructions.map(
|
|
2407
|
+
toTransactionInstruction
|
|
2408
|
+
);
|
|
2309
2409
|
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2310
2410
|
connection,
|
|
2311
2411
|
swapInstructionResponse
|
|
2312
2412
|
);
|
|
2313
|
-
return {
|
|
2413
|
+
return {
|
|
2414
|
+
instruction,
|
|
2415
|
+
setupInstructions,
|
|
2416
|
+
addressLookupTableAccounts,
|
|
2417
|
+
quoteResponse
|
|
2418
|
+
};
|
|
2314
2419
|
});
|
|
2315
2420
|
}
|
|
2316
2421
|
|
|
2317
2422
|
// src/helpers/dammV2.ts
|
|
2318
|
-
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
2423
|
+
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
2319
2424
|
import {
|
|
2320
2425
|
CollectFeeMode,
|
|
2321
2426
|
CpAmm,
|
|
@@ -2323,27 +2428,27 @@ import {
|
|
|
2323
2428
|
} from "@meteora-ag/cp-amm-sdk";
|
|
2324
2429
|
|
|
2325
2430
|
// src/helpers/pda.ts
|
|
2326
|
-
import { PublicKey as
|
|
2431
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
2327
2432
|
function deriveDammV2EventAuthority() {
|
|
2328
|
-
return
|
|
2433
|
+
return PublicKey4.findProgramAddressSync(
|
|
2329
2434
|
[Buffer.from("__event_authority")],
|
|
2330
2435
|
DAMM_V2_PROGRAM_ID
|
|
2331
2436
|
)[0];
|
|
2332
2437
|
}
|
|
2333
2438
|
function deriveDammV2PoolAuthority() {
|
|
2334
|
-
return
|
|
2439
|
+
return PublicKey4.findProgramAddressSync(
|
|
2335
2440
|
[Buffer.from("pool_authority")],
|
|
2336
2441
|
DAMM_V2_PROGRAM_ID
|
|
2337
2442
|
)[0];
|
|
2338
2443
|
}
|
|
2339
2444
|
function deriveLedgerAccount(owner) {
|
|
2340
|
-
return
|
|
2445
|
+
return PublicKey4.findProgramAddressSync(
|
|
2341
2446
|
[Buffer.from("user_ledger"), owner.toBuffer()],
|
|
2342
2447
|
ZAP_PROGRAM_ID
|
|
2343
2448
|
)[0];
|
|
2344
2449
|
}
|
|
2345
2450
|
function deriveDlmmEventAuthority() {
|
|
2346
|
-
return
|
|
2451
|
+
return PublicKey4.findProgramAddressSync(
|
|
2347
2452
|
[Buffer.from("__event_authority")],
|
|
2348
2453
|
DLMM_PROGRAM_ID
|
|
2349
2454
|
)[0];
|
|
@@ -2357,7 +2462,7 @@ function getDammV2Pool(connection, poolAddress) {
|
|
|
2357
2462
|
});
|
|
2358
2463
|
}
|
|
2359
2464
|
function getDammV2RemainingAccounts(_0, _1, _2, _3) {
|
|
2360
|
-
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram =
|
|
2465
|
+
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram = TOKEN_PROGRAM_ID2, tokenBProgram = TOKEN_PROGRAM_ID2, poolState) {
|
|
2361
2466
|
const remainingAccounts = [
|
|
2362
2467
|
{
|
|
2363
2468
|
isSigner: false,
|
|
@@ -2448,16 +2553,16 @@ function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
|
2448
2553
|
}
|
|
2449
2554
|
|
|
2450
2555
|
// src/helpers/common.ts
|
|
2451
|
-
import { NATIVE_MINT, TOKEN_PROGRAM_ID as
|
|
2556
|
+
import { NATIVE_MINT as NATIVE_MINT2, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
|
|
2452
2557
|
import {
|
|
2453
2558
|
ComputeBudgetProgram,
|
|
2454
|
-
PublicKey as
|
|
2559
|
+
PublicKey as PublicKey5
|
|
2455
2560
|
} from "@solana/web3.js";
|
|
2456
2561
|
import Decimal from "decimal.js";
|
|
2457
2562
|
function getTokenProgramFromMint(connection, mint) {
|
|
2458
2563
|
return __async(this, null, function* () {
|
|
2459
|
-
if (mint.equals(
|
|
2460
|
-
return
|
|
2564
|
+
if (mint.equals(NATIVE_MINT2)) {
|
|
2565
|
+
return TOKEN_PROGRAM_ID3;
|
|
2461
2566
|
}
|
|
2462
2567
|
try {
|
|
2463
2568
|
const mintInfo = yield connection.getAccountInfo(mint);
|
|
@@ -2465,18 +2570,18 @@ function getTokenProgramFromMint(connection, mint) {
|
|
|
2465
2570
|
throw new Error(`Mint account not found: ${mint.toString()}`);
|
|
2466
2571
|
}
|
|
2467
2572
|
if (mintInfo.owner.equals(
|
|
2468
|
-
new
|
|
2573
|
+
new PublicKey5("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
2469
2574
|
)) {
|
|
2470
|
-
return new
|
|
2575
|
+
return new PublicKey5("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
2471
2576
|
} else {
|
|
2472
|
-
return
|
|
2577
|
+
return TOKEN_PROGRAM_ID3;
|
|
2473
2578
|
}
|
|
2474
2579
|
} catch (error) {
|
|
2475
2580
|
console.warn(
|
|
2476
2581
|
`Failed to determine token program for ${mint.toString()}, defaulting to TOKEN_PROGRAM_ID:`,
|
|
2477
2582
|
error
|
|
2478
2583
|
);
|
|
2479
|
-
return
|
|
2584
|
+
return TOKEN_PROGRAM_ID3;
|
|
2480
2585
|
}
|
|
2481
2586
|
});
|
|
2482
2587
|
}
|
|
@@ -2492,93 +2597,6 @@ function filterOutComputeBudgetInstructions(instructions) {
|
|
|
2492
2597
|
);
|
|
2493
2598
|
}
|
|
2494
2599
|
|
|
2495
|
-
// src/helpers/token.ts
|
|
2496
|
-
import {
|
|
2497
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
2498
|
-
createCloseAccountInstruction,
|
|
2499
|
-
getAssociatedTokenAddressSync,
|
|
2500
|
-
NATIVE_MINT as NATIVE_MINT2,
|
|
2501
|
-
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
|
|
2502
|
-
} from "@solana/spl-token";
|
|
2503
|
-
import {
|
|
2504
|
-
SystemProgram,
|
|
2505
|
-
TransactionInstruction as TransactionInstruction3
|
|
2506
|
-
} from "@solana/web3.js";
|
|
2507
|
-
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2508
|
-
const toAccount = getAssociatedTokenAddressSync(
|
|
2509
|
-
tokenMint,
|
|
2510
|
-
owner,
|
|
2511
|
-
allowOwnerOffCurve,
|
|
2512
|
-
tokenProgram
|
|
2513
|
-
);
|
|
2514
|
-
const ix = createAssociatedTokenAccountIdempotentInstruction(
|
|
2515
|
-
payer,
|
|
2516
|
-
toAccount,
|
|
2517
|
-
owner,
|
|
2518
|
-
tokenMint,
|
|
2519
|
-
tokenProgram
|
|
2520
|
-
);
|
|
2521
|
-
return { ataPubkey: toAccount, ix };
|
|
2522
|
-
});
|
|
2523
|
-
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2524
|
-
const wSolATAAccount = getAssociatedTokenAddressSync(
|
|
2525
|
-
NATIVE_MINT2,
|
|
2526
|
-
owner,
|
|
2527
|
-
allowOwnerOffCurve
|
|
2528
|
-
);
|
|
2529
|
-
if (wSolATAAccount) {
|
|
2530
|
-
const closedWrappedSolInstruction = createCloseAccountInstruction(
|
|
2531
|
-
wSolATAAccount,
|
|
2532
|
-
receiver,
|
|
2533
|
-
owner,
|
|
2534
|
-
[],
|
|
2535
|
-
TOKEN_PROGRAM_ID3
|
|
2536
|
-
);
|
|
2537
|
-
return closedWrappedSolInstruction;
|
|
2538
|
-
}
|
|
2539
|
-
return null;
|
|
2540
|
-
}
|
|
2541
|
-
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2542
|
-
return __async(this, null, function* () {
|
|
2543
|
-
let balance;
|
|
2544
|
-
try {
|
|
2545
|
-
balance = (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
2546
|
-
} catch (e) {
|
|
2547
|
-
balance = "0";
|
|
2548
|
-
}
|
|
2549
|
-
return balance;
|
|
2550
|
-
});
|
|
2551
|
-
}
|
|
2552
|
-
function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID3) {
|
|
2553
|
-
return [
|
|
2554
|
-
SystemProgram.transfer({
|
|
2555
|
-
fromPubkey: from,
|
|
2556
|
-
toPubkey: to,
|
|
2557
|
-
lamports: amount
|
|
2558
|
-
}),
|
|
2559
|
-
new TransactionInstruction3({
|
|
2560
|
-
keys: [
|
|
2561
|
-
{
|
|
2562
|
-
pubkey: to,
|
|
2563
|
-
isSigner: false,
|
|
2564
|
-
isWritable: true
|
|
2565
|
-
}
|
|
2566
|
-
],
|
|
2567
|
-
data: Buffer.from(new Uint8Array([17])),
|
|
2568
|
-
programId: tokenProgram
|
|
2569
|
-
})
|
|
2570
|
-
];
|
|
2571
|
-
}
|
|
2572
|
-
var CLOSE_ACCOUNT_DISCRIMINATOR = 9;
|
|
2573
|
-
function filterOutCloseSplTokenAccountInstructions(instructions) {
|
|
2574
|
-
return instructions.filter((ix) => {
|
|
2575
|
-
if (ix.programId.equals(TOKEN_PROGRAM_ID3)) {
|
|
2576
|
-
return ix.data[0] !== CLOSE_ACCOUNT_DISCRIMINATOR;
|
|
2577
|
-
}
|
|
2578
|
-
return true;
|
|
2579
|
-
});
|
|
2580
|
-
}
|
|
2581
|
-
|
|
2582
2600
|
// src/helpers/dlmm.ts
|
|
2583
2601
|
import { PublicKey as PublicKey7 } from "@solana/web3.js";
|
|
2584
2602
|
import BN2 from "bn.js";
|
|
@@ -2956,8 +2974,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2956
2974
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2957
2975
|
return new BN3(estimatedOutput.floor().toString());
|
|
2958
2976
|
}
|
|
2959
|
-
function getBestSwapQuoteJupiterDlmm(
|
|
2960
|
-
return __async(this,
|
|
2977
|
+
function getBestSwapQuoteJupiterDlmm(dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config, jupiterQuoteOptions) {
|
|
2978
|
+
return __async(this, null, function* () {
|
|
2961
2979
|
let dlmmQuoteResult = null;
|
|
2962
2980
|
try {
|
|
2963
2981
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2970,14 +2988,15 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
|
2970
2988
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
2971
2989
|
}
|
|
2972
2990
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
2973
|
-
|
|
2991
|
+
{
|
|
2974
2992
|
inputMint: inMint,
|
|
2975
2993
|
outputMint: outMint,
|
|
2976
2994
|
amount: inAmount,
|
|
2977
2995
|
user,
|
|
2978
|
-
|
|
2979
|
-
|
|
2980
|
-
|
|
2996
|
+
queryParams: __spreadValues({
|
|
2997
|
+
slippageBps: swapSlippageBps
|
|
2998
|
+
}, jupiterQuoteOptions)
|
|
2999
|
+
},
|
|
2981
3000
|
config
|
|
2982
3001
|
);
|
|
2983
3002
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -3104,7 +3123,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3104
3123
|
strategy,
|
|
3105
3124
|
singleSided,
|
|
3106
3125
|
jupiterQuoteOptions,
|
|
3107
|
-
config
|
|
3126
|
+
config
|
|
3108
3127
|
}) {
|
|
3109
3128
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3110
3129
|
const activeBin = yield dlmm.getActiveBin();
|
|
@@ -3128,14 +3147,15 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3128
3147
|
const singleSidedX = singleSided === 0 /* X */;
|
|
3129
3148
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
3130
3149
|
const quote = yield getJupiterQuote(
|
|
3131
|
-
|
|
3150
|
+
{
|
|
3132
3151
|
inputMint: inputTokenMint,
|
|
3133
3152
|
outputMint: outputTokenMint,
|
|
3134
3153
|
amount: amountIn,
|
|
3135
3154
|
user,
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3155
|
+
queryParams: __spreadValues({
|
|
3156
|
+
slippageBps: swapSlippageBps
|
|
3157
|
+
}, jupiterQuoteOptions)
|
|
3158
|
+
},
|
|
3139
3159
|
config
|
|
3140
3160
|
);
|
|
3141
3161
|
if (!quote) {
|
|
@@ -3158,25 +3178,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3158
3178
|
const halfAmount = amountIn.div(new BN3(2));
|
|
3159
3179
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
3160
3180
|
getJupiterQuote(
|
|
3161
|
-
|
|
3181
|
+
{
|
|
3162
3182
|
inputMint: inputTokenMint,
|
|
3163
3183
|
outputMint: tokenXMint,
|
|
3164
3184
|
amount: halfAmount,
|
|
3165
3185
|
user,
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3186
|
+
queryParams: __spreadValues({
|
|
3187
|
+
slippageBps: swapSlippageBps
|
|
3188
|
+
}, jupiterQuoteOptions)
|
|
3189
|
+
},
|
|
3169
3190
|
config
|
|
3170
3191
|
),
|
|
3171
3192
|
getJupiterQuote(
|
|
3172
|
-
|
|
3193
|
+
{
|
|
3173
3194
|
inputMint: inputTokenMint,
|
|
3174
3195
|
outputMint: tokenYMint,
|
|
3175
3196
|
amount: halfAmount,
|
|
3176
3197
|
user,
|
|
3177
|
-
|
|
3178
|
-
|
|
3179
|
-
|
|
3198
|
+
queryParams: __spreadValues({
|
|
3199
|
+
slippageBps: swapSlippageBps
|
|
3200
|
+
}, jupiterQuoteOptions)
|
|
3201
|
+
},
|
|
3180
3202
|
config
|
|
3181
3203
|
)
|
|
3182
3204
|
]);
|
|
@@ -3272,25 +3294,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
3272
3294
|
}
|
|
3273
3295
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
3274
3296
|
getJupiterQuote(
|
|
3275
|
-
|
|
3297
|
+
{
|
|
3276
3298
|
inputMint: inputTokenMint,
|
|
3277
3299
|
outputMint: tokenXMint,
|
|
3278
3300
|
amount: bestAmountToX,
|
|
3279
3301
|
user,
|
|
3280
|
-
|
|
3281
|
-
|
|
3282
|
-
|
|
3302
|
+
queryParams: __spreadValues({
|
|
3303
|
+
slippageBps: swapSlippageBps
|
|
3304
|
+
}, jupiterQuoteOptions)
|
|
3305
|
+
},
|
|
3283
3306
|
config
|
|
3284
3307
|
),
|
|
3285
3308
|
getJupiterQuote(
|
|
3286
|
-
|
|
3309
|
+
{
|
|
3287
3310
|
inputMint: inputTokenMint,
|
|
3288
3311
|
outputMint: tokenYMint,
|
|
3289
3312
|
amount: bestAmountToY,
|
|
3290
3313
|
user,
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3314
|
+
queryParams: __spreadValues({
|
|
3315
|
+
slippageBps: swapSlippageBps
|
|
3316
|
+
}, jupiterQuoteOptions)
|
|
3317
|
+
},
|
|
3294
3318
|
config
|
|
3295
3319
|
)
|
|
3296
3320
|
]);
|
|
@@ -3336,7 +3360,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3336
3360
|
strategy,
|
|
3337
3361
|
singleSided,
|
|
3338
3362
|
jupiterQuoteOptions,
|
|
3339
|
-
config
|
|
3363
|
+
config
|
|
3340
3364
|
}) {
|
|
3341
3365
|
if (singleSided !== void 0) {
|
|
3342
3366
|
const singleSidedX = singleSided === 0 /* X */;
|
|
@@ -3581,7 +3605,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3581
3605
|
strategy,
|
|
3582
3606
|
singleSided,
|
|
3583
3607
|
jupiterQuoteOptions,
|
|
3584
|
-
config
|
|
3608
|
+
config
|
|
3585
3609
|
}) {
|
|
3586
3610
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3587
3611
|
invariant(
|
|
@@ -3630,7 +3654,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3630
3654
|
maxDeltaId,
|
|
3631
3655
|
strategy,
|
|
3632
3656
|
jupiterQuoteOptions,
|
|
3633
|
-
config
|
|
3657
|
+
config
|
|
3634
3658
|
}) {
|
|
3635
3659
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3636
3660
|
const userPosition = yield dlmm.getPosition(position);
|
|
@@ -3736,13 +3760,13 @@ var Zap = class {
|
|
|
3736
3760
|
* @param connection - The connection to the Solana cluster
|
|
3737
3761
|
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
|
|
3738
3762
|
*/
|
|
3739
|
-
constructor(connection, config
|
|
3763
|
+
constructor(connection, config) {
|
|
3740
3764
|
var _a;
|
|
3741
3765
|
this.connection = connection;
|
|
3742
3766
|
this.zapProgram = new Program(idl_default, { connection });
|
|
3743
|
-
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3744
|
-
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3745
|
-
this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3767
|
+
this.jupiterApiUrl = (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL;
|
|
3768
|
+
this.jupiterApiKey = (config == null ? void 0 : config.jupiterApiKey) || "";
|
|
3769
|
+
this.jupiterApiVersion = (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3746
3770
|
}
|
|
3747
3771
|
/////// PRIVATE FUNDTIONS //////
|
|
3748
3772
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3976,13 +4000,12 @@ var Zap = class {
|
|
|
3976
4000
|
* @param params.amountIn - The amount of input token
|
|
3977
4001
|
* @param params.inputTokenMint - The input token mint
|
|
3978
4002
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
3979
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
3980
4003
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
3981
4004
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
3982
4005
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3983
4006
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3984
4007
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
3985
|
-
* @param params.jupiterQuoteOptions - Optional Jupiter
|
|
4008
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
3986
4009
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
3987
4010
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3988
4011
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -3996,7 +4019,6 @@ var Zap = class {
|
|
|
3996
4019
|
inputTokenMint,
|
|
3997
4020
|
amountIn,
|
|
3998
4021
|
positionNftMint,
|
|
3999
|
-
maxAccounts,
|
|
4000
4022
|
maxSqrtPriceChangeBps,
|
|
4001
4023
|
slippageBps,
|
|
4002
4024
|
dammV2Quote,
|
|
@@ -4094,7 +4116,6 @@ var Zap = class {
|
|
|
4094
4116
|
inputTokenMint,
|
|
4095
4117
|
outputTokenMint,
|
|
4096
4118
|
swapInAmount,
|
|
4097
|
-
maxAccounts,
|
|
4098
4119
|
slippageBps,
|
|
4099
4120
|
void 0,
|
|
4100
4121
|
{
|
|
@@ -4104,6 +4125,9 @@ var Zap = class {
|
|
|
4104
4125
|
},
|
|
4105
4126
|
jupiterQuoteOptions
|
|
4106
4127
|
);
|
|
4128
|
+
preInstructions.push(
|
|
4129
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4130
|
+
);
|
|
4107
4131
|
swapInstructions = [result.instruction];
|
|
4108
4132
|
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
4109
4133
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
@@ -4147,7 +4171,6 @@ var Zap = class {
|
|
|
4147
4171
|
inputTokenMint,
|
|
4148
4172
|
outputTokenMint,
|
|
4149
4173
|
swapInAmount,
|
|
4150
|
-
maxAccounts,
|
|
4151
4174
|
slippageBps,
|
|
4152
4175
|
void 0,
|
|
4153
4176
|
{
|
|
@@ -4157,6 +4180,9 @@ var Zap = class {
|
|
|
4157
4180
|
},
|
|
4158
4181
|
jupiterQuoteOptions
|
|
4159
4182
|
);
|
|
4183
|
+
preInstructions.push(
|
|
4184
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4185
|
+
);
|
|
4160
4186
|
swapInstructions = [result.instruction];
|
|
4161
4187
|
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
4162
4188
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
@@ -4236,13 +4262,12 @@ var Zap = class {
|
|
|
4236
4262
|
* @param params.amountIn - The amount of input token
|
|
4237
4263
|
* @param params.inputTokenMint - The input token mint
|
|
4238
4264
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
4239
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
4240
4265
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4241
4266
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
4242
4267
|
* @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)
|
|
4243
4268
|
* @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)
|
|
4244
4269
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4245
|
-
* @param params.jupiterQuoteOptions - Optional Jupiter
|
|
4270
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
4246
4271
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
4247
4272
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
4248
4273
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -4256,7 +4281,6 @@ var Zap = class {
|
|
|
4256
4281
|
pool,
|
|
4257
4282
|
positionNftMint,
|
|
4258
4283
|
amountIn,
|
|
4259
|
-
maxAccounts,
|
|
4260
4284
|
maxSqrtPriceChangeBps,
|
|
4261
4285
|
maxTransferAmountExtendPercentage,
|
|
4262
4286
|
slippageBps,
|
|
@@ -4352,7 +4376,6 @@ var Zap = class {
|
|
|
4352
4376
|
inputTokenMint,
|
|
4353
4377
|
tokenAMint,
|
|
4354
4378
|
amountIn,
|
|
4355
|
-
maxAccounts,
|
|
4356
4379
|
slippageBps,
|
|
4357
4380
|
void 0,
|
|
4358
4381
|
{
|
|
@@ -4362,6 +4385,9 @@ var Zap = class {
|
|
|
4362
4385
|
},
|
|
4363
4386
|
jupiterQuoteOptions
|
|
4364
4387
|
);
|
|
4388
|
+
preInstructions.push(
|
|
4389
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4390
|
+
);
|
|
4365
4391
|
return {
|
|
4366
4392
|
user,
|
|
4367
4393
|
pool,
|
|
@@ -4407,7 +4433,6 @@ var Zap = class {
|
|
|
4407
4433
|
inputTokenMint,
|
|
4408
4434
|
tokenBMint,
|
|
4409
4435
|
amountIn,
|
|
4410
|
-
maxAccounts,
|
|
4411
4436
|
slippageBps,
|
|
4412
4437
|
void 0,
|
|
4413
4438
|
{
|
|
@@ -4417,6 +4442,9 @@ var Zap = class {
|
|
|
4417
4442
|
},
|
|
4418
4443
|
jupiterQuoteOptions
|
|
4419
4444
|
);
|
|
4445
|
+
preInstructions.push(
|
|
4446
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4447
|
+
);
|
|
4420
4448
|
return {
|
|
4421
4449
|
user,
|
|
4422
4450
|
pool,
|
|
@@ -4457,7 +4485,6 @@ var Zap = class {
|
|
|
4457
4485
|
inputTokenMint,
|
|
4458
4486
|
tokenAMint,
|
|
4459
4487
|
amountIn,
|
|
4460
|
-
maxAccounts,
|
|
4461
4488
|
slippageBps,
|
|
4462
4489
|
void 0,
|
|
4463
4490
|
{
|
|
@@ -4467,6 +4494,9 @@ var Zap = class {
|
|
|
4467
4494
|
},
|
|
4468
4495
|
jupiterQuoteOptions
|
|
4469
4496
|
);
|
|
4497
|
+
preInstructions.push(
|
|
4498
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4499
|
+
);
|
|
4470
4500
|
return {
|
|
4471
4501
|
user,
|
|
4472
4502
|
pool,
|
|
@@ -4507,7 +4537,6 @@ var Zap = class {
|
|
|
4507
4537
|
inputTokenMint,
|
|
4508
4538
|
tokenBMint,
|
|
4509
4539
|
amountIn,
|
|
4510
|
-
maxAccounts,
|
|
4511
4540
|
slippageBps,
|
|
4512
4541
|
void 0,
|
|
4513
4542
|
{
|
|
@@ -4517,6 +4546,9 @@ var Zap = class {
|
|
|
4517
4546
|
},
|
|
4518
4547
|
jupiterQuoteOptions
|
|
4519
4548
|
);
|
|
4549
|
+
preInstructions.push(
|
|
4550
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4551
|
+
);
|
|
4520
4552
|
return {
|
|
4521
4553
|
user,
|
|
4522
4554
|
pool,
|
|
@@ -4598,7 +4630,6 @@ var Zap = class {
|
|
|
4598
4630
|
inputTokenMint,
|
|
4599
4631
|
tokenAMint,
|
|
4600
4632
|
swapAmountToA,
|
|
4601
|
-
maxAccounts,
|
|
4602
4633
|
slippageBps,
|
|
4603
4634
|
void 0,
|
|
4604
4635
|
{
|
|
@@ -4608,13 +4639,15 @@ var Zap = class {
|
|
|
4608
4639
|
},
|
|
4609
4640
|
jupiterQuoteOptions
|
|
4610
4641
|
);
|
|
4642
|
+
preInstructions.push(
|
|
4643
|
+
...getJupiterCreateAtaInstructions(swapToA.setupInstructions)
|
|
4644
|
+
);
|
|
4611
4645
|
const swapToB = yield buildJupiterSwapTransaction(
|
|
4612
4646
|
this.connection,
|
|
4613
4647
|
user,
|
|
4614
4648
|
inputTokenMint,
|
|
4615
4649
|
tokenBMint,
|
|
4616
4650
|
swapAmountToB,
|
|
4617
|
-
maxAccounts,
|
|
4618
4651
|
slippageBps,
|
|
4619
4652
|
void 0,
|
|
4620
4653
|
{
|
|
@@ -4624,6 +4657,9 @@ var Zap = class {
|
|
|
4624
4657
|
},
|
|
4625
4658
|
jupiterQuoteOptions
|
|
4626
4659
|
);
|
|
4660
|
+
preInstructions.push(
|
|
4661
|
+
...getJupiterCreateAtaInstructions(swapToB.setupInstructions)
|
|
4662
|
+
);
|
|
4627
4663
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4628
4664
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4629
4665
|
swapToA.quoteResponse.outAmount,
|
|
@@ -4674,7 +4710,7 @@ var Zap = class {
|
|
|
4674
4710
|
* @param params.amount - The amount to deposit
|
|
4675
4711
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4676
4712
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4677
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
4713
|
+
* @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
|
|
4678
4714
|
* @param params.swapInstructions - Swap instructions to execute
|
|
4679
4715
|
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4680
4716
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
@@ -4702,30 +4738,13 @@ var Zap = class {
|
|
|
4702
4738
|
addressLookupTableAccounts,
|
|
4703
4739
|
cleanUpInstructions
|
|
4704
4740
|
} = params;
|
|
4705
|
-
const
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
tokenAMint,
|
|
4712
|
-
user,
|
|
4713
|
-
user,
|
|
4714
|
-
false,
|
|
4715
|
-
tokenAProgram
|
|
4716
|
-
),
|
|
4717
|
-
getOrCreateATAInstruction(
|
|
4718
|
-
this.connection,
|
|
4719
|
-
tokenBMint,
|
|
4720
|
-
user,
|
|
4721
|
-
user,
|
|
4722
|
-
false,
|
|
4723
|
-
tokenBProgram
|
|
4724
|
-
)
|
|
4741
|
+
const {
|
|
4742
|
+
tokenAccounts: [tokenAAccount, tokenBAccount],
|
|
4743
|
+
instructions: setupInstructions
|
|
4744
|
+
} = getCreateAtaInstructions(user, [
|
|
4745
|
+
{ mint: tokenAMint, tokenProgram: tokenAProgram },
|
|
4746
|
+
{ mint: tokenBMint, tokenProgram: tokenBProgram }
|
|
4725
4747
|
]);
|
|
4726
|
-
const setupInstructions = [];
|
|
4727
|
-
initializeTokenAIx && setupInstructions.push(initializeTokenAIx);
|
|
4728
|
-
initializeTokenBIx && setupInstructions.push(initializeTokenBIx);
|
|
4729
4748
|
setupInstructions.push(...preInstructions);
|
|
4730
4749
|
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4731
4750
|
if (isDirectPool) {
|
|
@@ -4807,7 +4826,7 @@ var Zap = class {
|
|
|
4807
4826
|
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4808
4827
|
return {
|
|
4809
4828
|
instructions: [
|
|
4810
|
-
...setupInstructions,
|
|
4829
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
4811
4830
|
...swapInstructions,
|
|
4812
4831
|
...ledgerInstructions,
|
|
4813
4832
|
zapInInstruction,
|
|
@@ -4831,7 +4850,6 @@ var Zap = class {
|
|
|
4831
4850
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4832
4851
|
* @param params.strategy - The liquidity distribution strategy
|
|
4833
4852
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4834
|
-
* @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.
|
|
4835
4853
|
* @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
|
|
4836
4854
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4837
4855
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
@@ -4852,7 +4870,6 @@ var Zap = class {
|
|
|
4852
4870
|
maxDeltaId,
|
|
4853
4871
|
strategy,
|
|
4854
4872
|
favorXInActiveId,
|
|
4855
|
-
maxAccounts,
|
|
4856
4873
|
swapSlippageBps,
|
|
4857
4874
|
maxTransferAmountExtendPercentage,
|
|
4858
4875
|
maxActiveBinSlippage,
|
|
@@ -4897,7 +4914,6 @@ var Zap = class {
|
|
|
4897
4914
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4898
4915
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
4899
4916
|
directSwapEstimate.swapAmount,
|
|
4900
|
-
maxAccounts,
|
|
4901
4917
|
swapSlippageBps,
|
|
4902
4918
|
swapQuote.originalQuote,
|
|
4903
4919
|
{
|
|
@@ -4906,6 +4922,9 @@ var Zap = class {
|
|
|
4906
4922
|
jupiterApiVersion: this.jupiterApiVersion
|
|
4907
4923
|
}
|
|
4908
4924
|
);
|
|
4925
|
+
preInstructions.push(
|
|
4926
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
4927
|
+
);
|
|
4909
4928
|
swapInstructions.push(swap.instruction);
|
|
4910
4929
|
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4911
4930
|
} else {
|
|
@@ -5004,7 +5023,6 @@ var Zap = class {
|
|
|
5004
5023
|
* @param params.strategy - The liquidity distribution strategy
|
|
5005
5024
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5006
5025
|
* @param params.indirectSwapEstimate - The result from the indirect swap estimate
|
|
5007
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
5008
5026
|
* @param params.swapSlippageBps - The swap slippage tolerance in basis points
|
|
5009
5027
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
5010
5028
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
@@ -5025,7 +5043,6 @@ var Zap = class {
|
|
|
5025
5043
|
strategy,
|
|
5026
5044
|
favorXInActiveId,
|
|
5027
5045
|
indirectSwapEstimate,
|
|
5028
|
-
maxAccounts,
|
|
5029
5046
|
swapSlippageBps,
|
|
5030
5047
|
maxTransferAmountExtendPercentage,
|
|
5031
5048
|
maxActiveBinSlippage,
|
|
@@ -5074,7 +5091,6 @@ var Zap = class {
|
|
|
5074
5091
|
inputTokenMint,
|
|
5075
5092
|
tokenXMint,
|
|
5076
5093
|
swapAmountToXInLamports,
|
|
5077
|
-
maxAccounts,
|
|
5078
5094
|
swapSlippageBps,
|
|
5079
5095
|
indirectSwapEstimate.swapToX,
|
|
5080
5096
|
{
|
|
@@ -5083,6 +5099,9 @@ var Zap = class {
|
|
|
5083
5099
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5084
5100
|
}
|
|
5085
5101
|
);
|
|
5102
|
+
preInstructions.push(
|
|
5103
|
+
...getJupiterCreateAtaInstructions(swapToX.setupInstructions)
|
|
5104
|
+
);
|
|
5086
5105
|
swapInstructions.push(swapToX.instruction);
|
|
5087
5106
|
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
5088
5107
|
}
|
|
@@ -5093,7 +5112,6 @@ var Zap = class {
|
|
|
5093
5112
|
inputTokenMint,
|
|
5094
5113
|
tokenYMint,
|
|
5095
5114
|
swapAmountToYInLamports,
|
|
5096
|
-
maxAccounts,
|
|
5097
5115
|
swapSlippageBps,
|
|
5098
5116
|
indirectSwapEstimate.swapToY,
|
|
5099
5117
|
{
|
|
@@ -5102,6 +5120,9 @@ var Zap = class {
|
|
|
5102
5120
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5103
5121
|
}
|
|
5104
5122
|
);
|
|
5123
|
+
preInstructions.push(
|
|
5124
|
+
...getJupiterCreateAtaInstructions(swapToY.setupInstructions)
|
|
5125
|
+
);
|
|
5105
5126
|
swapInstructions.push(swapToY.instruction);
|
|
5106
5127
|
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
5107
5128
|
}
|
|
@@ -5180,7 +5201,7 @@ var Zap = class {
|
|
|
5180
5201
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
5181
5202
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5182
5203
|
* @param params.strategy - The liquidity distribution strategy
|
|
5183
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
5204
|
+
* @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
|
|
5184
5205
|
* @param params.swapInstructions - Swap instructions to execute
|
|
5185
5206
|
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
5186
5207
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
@@ -5215,30 +5236,13 @@ var Zap = class {
|
|
|
5215
5236
|
isDirectRoute,
|
|
5216
5237
|
singleSided
|
|
5217
5238
|
} = params;
|
|
5218
|
-
const
|
|
5219
|
-
|
|
5220
|
-
|
|
5221
|
-
|
|
5222
|
-
|
|
5223
|
-
|
|
5224
|
-
tokenXMint,
|
|
5225
|
-
user,
|
|
5226
|
-
user,
|
|
5227
|
-
false,
|
|
5228
|
-
tokenXProgram
|
|
5229
|
-
),
|
|
5230
|
-
getOrCreateATAInstruction(
|
|
5231
|
-
this.connection,
|
|
5232
|
-
tokenYMint,
|
|
5233
|
-
user,
|
|
5234
|
-
user,
|
|
5235
|
-
false,
|
|
5236
|
-
tokenYProgram
|
|
5237
|
-
)
|
|
5239
|
+
const {
|
|
5240
|
+
tokenAccounts: [tokenXAccount, tokenYAccount],
|
|
5241
|
+
instructions: setupInstructions
|
|
5242
|
+
} = getCreateAtaInstructions(user, [
|
|
5243
|
+
{ mint: tokenXMint, tokenProgram: tokenXProgram },
|
|
5244
|
+
{ mint: tokenYMint, tokenProgram: tokenYProgram }
|
|
5238
5245
|
]);
|
|
5239
|
-
const setupInstructions = [];
|
|
5240
|
-
initializeTokenXIx && setupInstructions.push(initializeTokenXIx);
|
|
5241
|
-
initializeTokenYIx && setupInstructions.push(initializeTokenYIx);
|
|
5242
5246
|
setupInstructions.push(...preInstructions);
|
|
5243
5247
|
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
5244
5248
|
if (isDirectRoute) {
|
|
@@ -5362,7 +5366,7 @@ var Zap = class {
|
|
|
5362
5366
|
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
5363
5367
|
return {
|
|
5364
5368
|
instructions: [
|
|
5365
|
-
...setupInstructions,
|
|
5369
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5366
5370
|
...swapInstructions,
|
|
5367
5371
|
...ledgerInstructions,
|
|
5368
5372
|
zapInInstruction,
|
|
@@ -5395,7 +5399,6 @@ var Zap = class {
|
|
|
5395
5399
|
* @param params.strategy - The strategy to use for the rebalance
|
|
5396
5400
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
5397
5401
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
5398
|
-
* @param params.maxAccounts - The maximum number of accounts to use for the swap operation
|
|
5399
5402
|
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
5400
5403
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
5401
5404
|
*/
|
|
@@ -5411,36 +5414,18 @@ var Zap = class {
|
|
|
5411
5414
|
swapSlippageBps,
|
|
5412
5415
|
strategy,
|
|
5413
5416
|
favorXInActiveId,
|
|
5414
|
-
directSwapEstimate
|
|
5415
|
-
maxAccounts = 50
|
|
5417
|
+
directSwapEstimate
|
|
5416
5418
|
} = params;
|
|
5417
5419
|
const dlmm = yield DLMM3.create(this.connection, lbPair);
|
|
5418
5420
|
const userPosition = yield dlmm.getPosition(position);
|
|
5419
5421
|
const { tokenXProgram, tokenYProgram } = getTokenProgramId(dlmm.lbPair);
|
|
5420
|
-
const
|
|
5421
|
-
|
|
5422
|
-
|
|
5423
|
-
|
|
5424
|
-
|
|
5425
|
-
|
|
5426
|
-
dlmm.lbPair.tokenXMint,
|
|
5427
|
-
user,
|
|
5428
|
-
user,
|
|
5429
|
-
true,
|
|
5430
|
-
tokenXProgram
|
|
5431
|
-
),
|
|
5432
|
-
getOrCreateATAInstruction(
|
|
5433
|
-
this.connection,
|
|
5434
|
-
dlmm.lbPair.tokenYMint,
|
|
5435
|
-
user,
|
|
5436
|
-
user,
|
|
5437
|
-
true,
|
|
5438
|
-
tokenYProgram
|
|
5439
|
-
)
|
|
5422
|
+
const {
|
|
5423
|
+
tokenAccounts: [userTokenX, userTokenY],
|
|
5424
|
+
instructions: setupInstructions
|
|
5425
|
+
} = getCreateAtaInstructions(user, [
|
|
5426
|
+
{ mint: dlmm.lbPair.tokenXMint, tokenProgram: tokenXProgram },
|
|
5427
|
+
{ mint: dlmm.lbPair.tokenYMint, tokenProgram: tokenYProgram }
|
|
5440
5428
|
]);
|
|
5441
|
-
const setupInstructions = [];
|
|
5442
|
-
userTokenXIx && setupInstructions.push(userTokenXIx);
|
|
5443
|
-
userTokenYIx && setupInstructions.push(userTokenYIx);
|
|
5444
5429
|
const strategyParamBuilder = getLiquidityStrategyParameterBuilder(strategy);
|
|
5445
5430
|
const { x0, y0, deltaX, deltaY } = buildLiquidityStrategyParameters(
|
|
5446
5431
|
new BN5(0),
|
|
@@ -5512,7 +5497,6 @@ var Zap = class {
|
|
|
5512
5497
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
5513
5498
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
5514
5499
|
directSwapEstimate.swapAmount,
|
|
5515
|
-
maxAccounts,
|
|
5516
5500
|
swapSlippageBps,
|
|
5517
5501
|
swapQuote.originalQuote,
|
|
5518
5502
|
{
|
|
@@ -5521,6 +5505,9 @@ var Zap = class {
|
|
|
5521
5505
|
jupiterApiVersion: this.jupiterApiVersion
|
|
5522
5506
|
}
|
|
5523
5507
|
);
|
|
5508
|
+
setupInstructions.push(
|
|
5509
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
5510
|
+
);
|
|
5524
5511
|
swapInstructions = [swap.instruction];
|
|
5525
5512
|
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
5526
5513
|
} else {
|
|
@@ -5623,7 +5610,7 @@ var Zap = class {
|
|
|
5623
5610
|
}
|
|
5624
5611
|
return {
|
|
5625
5612
|
instructions: [
|
|
5626
|
-
...setupInstructions,
|
|
5613
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5627
5614
|
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5628
5615
|
...rebalancePositionInstruction,
|
|
5629
5616
|
...swapInstructions,
|
|
@@ -5700,6 +5687,7 @@ var Zap = class {
|
|
|
5700
5687
|
*/
|
|
5701
5688
|
zapOutThroughJupiter(params) {
|
|
5702
5689
|
return __async(this, null, function* () {
|
|
5690
|
+
var _a;
|
|
5703
5691
|
const {
|
|
5704
5692
|
user,
|
|
5705
5693
|
inputMint,
|
|
@@ -5712,29 +5700,21 @@ var Zap = class {
|
|
|
5712
5700
|
} = params;
|
|
5713
5701
|
const preInstructions = [];
|
|
5714
5702
|
const postInstructions = [];
|
|
5715
|
-
const
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5719
|
-
|
|
5720
|
-
|
|
5721
|
-
inputMint,
|
|
5722
|
-
user,
|
|
5723
|
-
user,
|
|
5724
|
-
true,
|
|
5725
|
-
inputTokenProgram
|
|
5726
|
-
),
|
|
5727
|
-
getOrCreateATAInstruction(
|
|
5728
|
-
this.connection,
|
|
5729
|
-
outputMint,
|
|
5730
|
-
user,
|
|
5731
|
-
user,
|
|
5732
|
-
true,
|
|
5733
|
-
outputTokenProgram
|
|
5734
|
-
)
|
|
5703
|
+
const {
|
|
5704
|
+
tokenAccounts: [inputTokenAccount],
|
|
5705
|
+
instructions: createAtaInstructions
|
|
5706
|
+
} = getCreateAtaInstructions(user, [
|
|
5707
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5708
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5735
5709
|
]);
|
|
5736
|
-
|
|
5737
|
-
|
|
5710
|
+
preInstructions.push(...createAtaInstructions);
|
|
5711
|
+
preInstructions.push(
|
|
5712
|
+
...getJupiterCreateAtaInstructions(
|
|
5713
|
+
((_a = jupiterSwapResponse.setupInstructions) != null ? _a : []).map(
|
|
5714
|
+
toTransactionInstruction
|
|
5715
|
+
)
|
|
5716
|
+
)
|
|
5717
|
+
);
|
|
5738
5718
|
let preUserTokenBalance;
|
|
5739
5719
|
try {
|
|
5740
5720
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5779,7 +5759,7 @@ var Zap = class {
|
|
|
5779
5759
|
},
|
|
5780
5760
|
remainingAccounts,
|
|
5781
5761
|
ammProgram: JUP_V6_PROGRAM_ID,
|
|
5782
|
-
preInstructions,
|
|
5762
|
+
preInstructions: dedupeCreateAtaInstructions(preInstructions),
|
|
5783
5763
|
postInstructions
|
|
5784
5764
|
}),
|
|
5785
5765
|
getJupiterAddressLookupTableAccounts(
|
|
@@ -5822,29 +5802,14 @@ var Zap = class {
|
|
|
5822
5802
|
const poolState = yield getDammV2Pool(this.connection, poolAddress);
|
|
5823
5803
|
const preInstructions = [];
|
|
5824
5804
|
const postInstructions = [];
|
|
5825
|
-
const
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5830
|
-
|
|
5831
|
-
inputMint,
|
|
5832
|
-
user,
|
|
5833
|
-
user,
|
|
5834
|
-
true,
|
|
5835
|
-
inputTokenProgram
|
|
5836
|
-
),
|
|
5837
|
-
getOrCreateATAInstruction(
|
|
5838
|
-
this.connection,
|
|
5839
|
-
outputMint,
|
|
5840
|
-
user,
|
|
5841
|
-
user,
|
|
5842
|
-
true,
|
|
5843
|
-
outputTokenProgram
|
|
5844
|
-
)
|
|
5805
|
+
const {
|
|
5806
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5807
|
+
instructions: createAtaInstructions
|
|
5808
|
+
} = getCreateAtaInstructions(user, [
|
|
5809
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5810
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5845
5811
|
]);
|
|
5846
|
-
|
|
5847
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5812
|
+
preInstructions.push(...createAtaInstructions);
|
|
5848
5813
|
let preUserTokenBalance;
|
|
5849
5814
|
try {
|
|
5850
5815
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5919,29 +5884,14 @@ var Zap = class {
|
|
|
5919
5884
|
const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
|
|
5920
5885
|
const preInstructions = [];
|
|
5921
5886
|
const postInstructions = [];
|
|
5922
|
-
const
|
|
5923
|
-
|
|
5924
|
-
|
|
5925
|
-
|
|
5926
|
-
|
|
5927
|
-
|
|
5928
|
-
inputMint,
|
|
5929
|
-
user,
|
|
5930
|
-
user,
|
|
5931
|
-
true,
|
|
5932
|
-
inputTokenProgram
|
|
5933
|
-
),
|
|
5934
|
-
getOrCreateATAInstruction(
|
|
5935
|
-
this.connection,
|
|
5936
|
-
outputMint,
|
|
5937
|
-
user,
|
|
5938
|
-
user,
|
|
5939
|
-
true,
|
|
5940
|
-
outputTokenProgram
|
|
5941
|
-
)
|
|
5887
|
+
const {
|
|
5888
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5889
|
+
instructions: createAtaInstructions
|
|
5890
|
+
} = getCreateAtaInstructions(user, [
|
|
5891
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5892
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5942
5893
|
]);
|
|
5943
|
-
|
|
5944
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5894
|
+
preInstructions.push(...createAtaInstructions);
|
|
5945
5895
|
let preUserTokenBalance;
|
|
5946
5896
|
try {
|
|
5947
5897
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5999,18 +5949,12 @@ export {
|
|
|
5999
5949
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
6000
5950
|
DEFAULT_JUPITER_API_URL,
|
|
6001
5951
|
DEFAULT_JUPITER_API_VERSION,
|
|
6002
|
-
DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
6003
5952
|
DLMM_PROGRAM_ID,
|
|
6004
5953
|
DLMM_SWAP_DISCRIMINATOR,
|
|
6005
5954
|
DlmmDirectSwapQuoteRoute,
|
|
6006
5955
|
DlmmSingleSided,
|
|
6007
5956
|
DlmmSwapType,
|
|
6008
|
-
JUPITER_INSTRUCTION_LAYOUTS,
|
|
6009
5957
|
JUP_V6_PROGRAM_ID,
|
|
6010
|
-
JUP_V6_ROUTE_DISCRIMINATOR,
|
|
6011
|
-
JUP_V6_ROUTE_V2_DISCRIMINATOR,
|
|
6012
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR,
|
|
6013
|
-
JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR,
|
|
6014
5958
|
JupiterApiVersion,
|
|
6015
5959
|
MEMO_PROGRAM_ID,
|
|
6016
5960
|
SwapExternalType,
|
|
@@ -6031,17 +5975,13 @@ export {
|
|
|
6031
5975
|
estimateDlmmDirectSwap,
|
|
6032
5976
|
estimateDlmmIndirectSwap,
|
|
6033
5977
|
estimateDlmmRebalanceSwap,
|
|
6034
|
-
fetchAddressLookupTableAccounts,
|
|
6035
5978
|
filterOutCloseSplTokenAccountInstructions,
|
|
6036
|
-
filterOutComputeBudgetInstructions,
|
|
6037
5979
|
getBinArrayBitmapExtension,
|
|
6038
5980
|
getBitFromBinArrayIndexInBitmapExtension,
|
|
6039
5981
|
getDammV2Pool,
|
|
6040
5982
|
getDammV2RemainingAccounts,
|
|
6041
5983
|
getDlmmRemainingAccounts,
|
|
6042
5984
|
getExtraAccountMetasForTransferHook,
|
|
6043
|
-
getJupiterAddressLookupTableAccounts,
|
|
6044
|
-
getJupiterInstructionLayout,
|
|
6045
5985
|
getJupiterQuote,
|
|
6046
5986
|
getJupiterSwapInstruction,
|
|
6047
5987
|
getLbPairState,
|
|
@@ -6049,13 +5989,8 @@ export {
|
|
|
6049
5989
|
getOrCreateATAInstruction,
|
|
6050
5990
|
getTokenAccountBalance,
|
|
6051
5991
|
getTokenProgramFromMint,
|
|
6052
|
-
isJupiterBuildResponse,
|
|
6053
|
-
isJupiterSwapInstructionForUser,
|
|
6054
5992
|
isSingleSidedA,
|
|
6055
5993
|
isSingleSidedB,
|
|
6056
|
-
mergeAddressLookupTableAccounts,
|
|
6057
|
-
resolveJupiterConfig,
|
|
6058
|
-
toAddressLookupTableAccounts,
|
|
6059
5994
|
toProgramStrategyType,
|
|
6060
5995
|
unwrapSOLInstruction,
|
|
6061
5996
|
wrapSOLInstruction
|