@meteora-ag/zap-sdk 1.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.
@@ -0,0 +1,381 @@
1
+ import * as _solana_web3_js from '@solana/web3.js';
2
+ import { PublicKey, AccountMeta, TransactionInstruction, Connection, Transaction } from '@solana/web3.js';
3
+ import { IdlTypes, Program } from '@coral-xyz/anchor';
4
+ import BN from 'bn.js';
5
+ import { PoolState } from '@meteora-ag/cp-amm-sdk';
6
+ import { LbPair, BinArrayBitmapExtension, RemainingAccountInfo } from '@meteora-ag/dlmm';
7
+
8
+ /**
9
+ * Program IDL in camelCase format in order to be used in JS/TS.
10
+ *
11
+ * Note that this is only a type helper and is not the actual IDL. The original
12
+ * IDL can be found at `target/idl/zap.json`.
13
+ */
14
+ type Zap$1 = {
15
+ address: "zapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz";
16
+ metadata: {
17
+ name: "zap";
18
+ version: "0.1.0";
19
+ spec: "0.1.0";
20
+ description: "Created with Anchor";
21
+ };
22
+ instructions: [
23
+ {
24
+ name: "zapOut";
25
+ discriminator: [155, 108, 185, 112, 104, 210, 161, 64];
26
+ accounts: [
27
+ {
28
+ name: "userTokenInAccount";
29
+ writable: true;
30
+ },
31
+ {
32
+ name: "ammProgram";
33
+ }
34
+ ];
35
+ args: [
36
+ {
37
+ name: "params";
38
+ type: {
39
+ defined: {
40
+ name: "zapOutParameters";
41
+ };
42
+ };
43
+ }
44
+ ];
45
+ }
46
+ ];
47
+ errors: [
48
+ {
49
+ code: 6000;
50
+ name: "mathOverflow";
51
+ msg: "Math operation overflow";
52
+ },
53
+ {
54
+ code: 6001;
55
+ name: "invalidOffset";
56
+ msg: "Invalid offset";
57
+ },
58
+ {
59
+ code: 6002;
60
+ name: "invalidZapOutParameters";
61
+ msg: "Math operation overflow";
62
+ },
63
+ {
64
+ code: 6003;
65
+ name: "typeCastFailed";
66
+ msg: "Type cast error";
67
+ },
68
+ {
69
+ code: 6004;
70
+ name: "ammIsNotSupported";
71
+ msg: "Amm program is not supported";
72
+ }
73
+ ];
74
+ types: [
75
+ {
76
+ name: "zapOutParameters";
77
+ type: {
78
+ kind: "struct";
79
+ fields: [
80
+ {
81
+ name: "percentage";
82
+ type: "u8";
83
+ },
84
+ {
85
+ name: "offsetAmountIn";
86
+ type: "u16";
87
+ },
88
+ {
89
+ name: "preUserTokenBalance";
90
+ type: "u64";
91
+ },
92
+ {
93
+ name: "maxSwapAmount";
94
+ type: "u64";
95
+ },
96
+ {
97
+ name: "payloadData";
98
+ type: "bytes";
99
+ }
100
+ ];
101
+ };
102
+ }
103
+ ];
104
+ };
105
+
106
+ type ZapProgram = Program<Zap$1>;
107
+ type ZapOutParameters = IdlTypes<Zap$1>["zapOutParameters"];
108
+ type ZapOutParams = {
109
+ userTokenInAccount: PublicKey;
110
+ zapOutParams: ZapOutParameters;
111
+ remainingAccounts: AccountMeta[];
112
+ ammProgram: PublicKey;
113
+ preInstructions: TransactionInstruction[];
114
+ postInstructions: TransactionInstruction[];
115
+ };
116
+ type ZapOutThroughDammV2Params = {
117
+ user: PublicKey;
118
+ poolAddress: PublicKey;
119
+ inputTokenAccount: PublicKey;
120
+ outputTokenAccount: PublicKey;
121
+ amountIn: BN;
122
+ minimumSwapAmountOut: BN;
123
+ maxSwapAmount: BN;
124
+ percentageToZapOut: number;
125
+ preInstructions?: TransactionInstruction[];
126
+ postInstructions?: TransactionInstruction[];
127
+ };
128
+ type ZapOutThroughDlmmParams = {
129
+ user: PublicKey;
130
+ lbPairAddress: PublicKey;
131
+ inputTokenAccount: PublicKey;
132
+ outputTokenAccount: PublicKey;
133
+ amountIn: BN;
134
+ minimumSwapAmountOut: BN;
135
+ maxSwapAmount: BN;
136
+ percentageToZapOut: number;
137
+ preInstructions?: TransactionInstruction[];
138
+ postInstructions?: TransactionInstruction[];
139
+ };
140
+ interface ZapOutThroughJupiterParams {
141
+ inputTokenAccount: PublicKey;
142
+ jupiterSwapResponse: JupiterSwapInstructionResponse;
143
+ maxSwapAmount: BN;
144
+ percentageToZapOut: number;
145
+ preInstructions?: TransactionInstruction[];
146
+ postInstructions?: TransactionInstruction[];
147
+ }
148
+ interface JupiterQuoteResponse {
149
+ inputMint: string;
150
+ inAmount: string;
151
+ outputMint: string;
152
+ outAmount: string;
153
+ otherAmountThreshold: string;
154
+ swapMode: string;
155
+ slippageBps: number;
156
+ platformFee: any;
157
+ priceImpactPct: string;
158
+ routePlan: JupiterRoutePlan[];
159
+ contextSlot: number;
160
+ timeTaken: number;
161
+ swapUsdValue: string;
162
+ simplerRouteUsed: boolean;
163
+ mostReliableAmmsQuoteReport: {
164
+ info: Record<string, string>;
165
+ };
166
+ useIncurredSlippageForQuoting: any;
167
+ otherRoutePlans: any;
168
+ aggregatorVersion: any;
169
+ }
170
+ interface JupiterRoutePlan {
171
+ swapInfo: any;
172
+ percent: number;
173
+ bps: number;
174
+ }
175
+ interface JupiterInstruction {
176
+ programId: string;
177
+ accounts: any[];
178
+ data: string;
179
+ }
180
+ interface JupiterSwapInstructionResponse {
181
+ tokenLedgerInstruction: JupiterInstruction | null;
182
+ computeBudgetInstructions: JupiterInstruction[];
183
+ setupInstructions: JupiterInstruction[];
184
+ swapInstruction: JupiterInstruction;
185
+ cleanupInstruction: JupiterInstruction;
186
+ otherInstructions: JupiterInstruction[];
187
+ addressLookupTableAddresses: string[];
188
+ prioritizationFeeLamports: number;
189
+ computeUnitLimit: number;
190
+ prioritizationType: {
191
+ computeBudget: {
192
+ microLamports: number;
193
+ estimatedMicroLamports: number;
194
+ };
195
+ };
196
+ simulationSlot: any;
197
+ dynamicSlippageReport: any;
198
+ simulationError: any;
199
+ addressesByLookupTableAddress: any;
200
+ blockhashWithMetadata: {
201
+ blockhash: number[];
202
+ lastValidBlockHeight: number;
203
+ fetchedAt: {
204
+ secs_since_epoch: number;
205
+ nanos_since_epoch: number;
206
+ };
207
+ };
208
+ }
209
+
210
+ declare class Zap {
211
+ private connection;
212
+ private zapProgram;
213
+ constructor(connection: Connection);
214
+ /**
215
+ * Executes a generic zap out operation with custom parameters.
216
+ *
217
+ * @param params - Zap out operation parameters
218
+ * @param params.userTokenInAccount - Token ledger account to zap out from
219
+ * @param params.zapOutParams - Zap out parameters
220
+ * @param params.remainingAccounts - Additional accounts needed for the operation
221
+ * @param params.ammProgram - AMM program ID to interact with
222
+ * @param params.preInstructions - Instructions to run before the zap out
223
+ * @param params.postInstructions - Instructions to run after the zap out
224
+ * @returns builder transaction
225
+ */
226
+ zapOut(params: ZapOutParams): Promise<Transaction>;
227
+ /**
228
+ * Performs a token swap using Jupiter V6 protocol as part of a zap out operation.
229
+ * Swaps tokens from the input token ledger to the user's output token account.
230
+ *
231
+ * @param params - Jupiter V6 swap parameters from Jupiter API
232
+ * @param params.user - Public key of the user performing the swap
233
+ * @param params.inputMint - Token mint being swapped from
234
+ * @param params.outputMint - Token mint being swapped to
235
+ * @param params.jupiterSwapResponse - Jupiter swap instruction response
236
+ * @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
237
+ * @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
238
+ * @param params.maxSwapAmount - Maximum amount of input token to swap
239
+ * @param params.percentageToZapOut - Percentage of input token to zap out
240
+ * @returns built transaction
241
+ */
242
+ zapOutThroughJupiter(params: ZapOutThroughJupiterParams): Promise<Transaction>;
243
+ /**
244
+ * Performs a token swap using Damms V2 protocol as part of a zap out operation.
245
+ * Swaps tokens from the input token ledger to the user's output token account.
246
+ *
247
+ * @param params - Damms V2 swap parameters
248
+ * @param params.user - Public key of the user performing the swap
249
+ * @param params.poolAddress - Address of the pool to swap through
250
+ * @param params.inputMint - Token mint being swapped from
251
+ * @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
252
+ * @param params.amountIn - Amount of input token to swap
253
+ * @param params.minimumSwapAmountOut - Minimum amount of output token to receive
254
+ * @param params.maxSwapAmount - Maximum amount of input token to swap
255
+ * @param params.percentageToZapOut - Percentage of input token to zap out
256
+ */
257
+ zapOutThroughDammV2(params: ZapOutThroughDammV2Params): Promise<Transaction>;
258
+ /**
259
+ * Performs a token swap using Dlmm protocol as part of a zap out operation.
260
+ * Swaps tokens from the input token ledger to the user's output token account.
261
+ *
262
+ * @param params - Dlmm swap parameters
263
+ * @param params.user - Public key of the user performing the swap
264
+ * @param params.lbPairAddress - Address of the lbPair to swap through
265
+ * @param params.inputMint - Token mint being swapped from
266
+ * @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
267
+ * @param params.amountIn - Amount of input token to swap
268
+ * @param params.minimumSwapAmountOut - Minimum amount of output token to receive
269
+ * @param params.maxSwapAmount - Maximum amount of input token to swap
270
+ * @param params.percentageToZapOut - Percentage of input token to zap out
271
+ */
272
+ zapOutThroughDlmm(params: ZapOutThroughDlmmParams): Promise<Transaction>;
273
+ }
274
+
275
+ declare function getJupiterQuote(inputMint: PublicKey, outputMint: PublicKey, amount: BN, maxAccounts: number, slippageBps: number, onlyDirectRoutes: boolean, restrictIntermediateTokens: boolean, apiUrl?: string, apiKey?: string): Promise<JupiterQuoteResponse>;
276
+ declare function getJupiterSwapInstruction(userPublicKey: PublicKey, quoteResponse: any, apiUrl?: string, apiKey?: string): Promise<JupiterSwapInstructionResponse>;
277
+
278
+ declare function getDammV2Pool(connection: Connection, poolAddress: PublicKey): Promise<PoolState>;
279
+ declare function getDammV2RemainingAccounts(poolAddress: PublicKey, user: PublicKey, userInputTokenAccount: PublicKey, userTokenOutAccount: PublicKey, tokenAProgram: PublicKey | undefined, tokenBProgram: PublicKey | undefined, poolState: PoolState): Promise<Array<{
280
+ isSigner: boolean;
281
+ isWritable: boolean;
282
+ pubkey: PublicKey;
283
+ }>>;
284
+ /**
285
+ * Creates payload data for DAMM V2 swap instruction
286
+ * @param amountIn - The input amount for the swap
287
+ * @param minimumSwapAmountOut - The minimum amount out for the swap
288
+ * @returns Buffer containing the payload data
289
+ * Discriminator (8 bytes): [248, 198, 158, 145, 225, 117, 135, 200] - identifies this as a DAMM V2 swap instruction.
290
+ * Amount In (8 bytes): u64 little-endian - the swap amount (modified by zap program at runtime).
291
+ * Minimum Amount Out (8 bytes): u64 little-endian - slippage protection (static value).
292
+ */
293
+ declare function createDammV2SwapPayload(amountIn: BN, minimumSwapAmountOut: BN): Buffer;
294
+
295
+ declare function deriveDammV2EventAuthority(): PublicKey;
296
+
297
+ declare function getTokenProgramFromMint(connection: Connection, mint: PublicKey): Promise<PublicKey>;
298
+
299
+ /**
300
+ * Get or create a token account
301
+ * @param connection - Solana connection
302
+ * @param tokenMint - The mint of the token
303
+ * @param owner - The owner of the token
304
+ * @param payer - The payer of the token
305
+ * @param allowOwnerOffCurve - Whether to allow the owner to be off curve
306
+ * @param tokenProgram - The token program to use (defaults to TOKEN_PROGRAM_ID)
307
+ * @returns The token account and the instruction to create it if it doesn't exist
308
+ */
309
+ declare const getOrCreateATAInstruction: (connection: Connection, tokenMint: PublicKey, owner: PublicKey, payer: PublicKey, allowOwnerOffCurve: boolean | undefined, tokenProgram: PublicKey) => Promise<{
310
+ ataPubkey: PublicKey;
311
+ ix?: TransactionInstruction;
312
+ }>;
313
+ /**
314
+ * Unwrap SOL instruction
315
+ * @param owner - The owner of the SOL
316
+ * @param receiver - The receiver of the SOL
317
+ * @param allowOwnerOffCurve - Whether to allow the owner to be off curve
318
+ * @returns The unwrap SOL instruction
319
+ */
320
+ declare function unwrapSOLInstruction(owner: PublicKey, receiver: PublicKey, allowOwnerOffCurve?: boolean): TransactionInstruction | null;
321
+ /**
322
+ * Wrap SOL instruction
323
+ * @param from - The from address
324
+ * @param to - The to address
325
+ * @param amount - The amount to wrap
326
+ * @param tokenProgram - The token program to use (defaults to TOKEN_PROGRAM_ID)
327
+ * @returns The wrap SOL instruction
328
+ */
329
+ declare function wrapSOLInstruction(from: PublicKey, to: PublicKey, amount: bigint, tokenProgram?: PublicKey): TransactionInstruction[];
330
+
331
+ declare function getLbPairState(connection: Connection, lbPair: PublicKey): Promise<LbPair>;
332
+ declare function getBinArrayBitmapExtension(connection: Connection, binArray: PublicKey): Promise<BinArrayBitmapExtension | null>;
333
+ declare function getBitFromBinArrayIndexInBitmapExtension(binArrayIndex: BN, state: BinArrayBitmapExtension): boolean;
334
+ declare function getNextBinArrayIndexWithLiquidity(binArrayIndex: BN, pairState: LbPair, swapForY: boolean, state: BinArrayBitmapExtension | null): BN | null;
335
+ declare function getDlmmRemainingAccounts(connection: Connection, lbPair: PublicKey, user: PublicKey, userInputTokenAccount: PublicKey, userTokenOutAccount: PublicKey, tokenXProgram: PublicKey, tokenYProgram: PublicKey, lbPairState: LbPair): Promise<{
336
+ remainingAccounts: AccountMeta[];
337
+ remainingAccountsInfo: RemainingAccountInfo;
338
+ }>;
339
+ declare function convertAccountTypeToNumber(accountType: object): number;
340
+ /**
341
+ * Creates payload data for DLMM swap instruction
342
+ * @param amountIn - The input amount for the swap
343
+ * @param minimumSwapAmountOut - The minimum amount out for the swap
344
+ * @param remainingAccountsInfo - Information about remaining accounts including slices
345
+ * @returns Buffer containing the payload data
346
+ * Discriminator (8 bytes): [65, 75, 63, 76, 235, 91, 91, 136] - identifies this as a DLMM swap2 instruction.
347
+ * Amount In (8 bytes): u64 little-endian - the swap amount (modified by zap program at runtime).
348
+ * Minimum Amount Out (8 bytes): u64 little-endian - slippage protection (static value).
349
+ * Slice Count (4 bytes): u32 little-endian - number of account type slices.
350
+ * Slices Data (2 bytes per slice): Each slice contains:
351
+ * -> Account Type (1 byte): enum value (0=TransferHookX, 1=TransferHookY, 2=TransferHookReward).
352
+ * -> Length (1 byte): number of accounts in this slice.
353
+ */
354
+ declare function createDlmmSwapPayload(amountIn: BN, minimumSwapAmountOut: BN, remainingAccountsInfo: RemainingAccountInfo): Buffer;
355
+
356
+ declare function getExtraAccountMetasForTransferHook(connection: Connection, mint: PublicKey): Promise<_solana_web3_js.AccountMeta[]>;
357
+
358
+ declare const ZAP_PROGRAM_ID: PublicKey;
359
+ declare const JUP_V6_PROGRAM_ID: PublicKey;
360
+ declare const DAMM_V2_PROGRAM_ID: PublicKey;
361
+ declare const DLMM_PROGRAM_ID: PublicKey;
362
+ declare const MEMO_PROGRAM_ID: PublicKey;
363
+ declare const BIN_ARRAY_INDEX_BOUND: BN[];
364
+ declare const AccountsType: {
365
+ TransferHookX: {
366
+ transferHookX: {};
367
+ };
368
+ TransferHookY: {
369
+ transferHookY: {};
370
+ };
371
+ TransferHookReward: {
372
+ transferHookReward: {};
373
+ };
374
+ };
375
+ declare const DLMM_SWAP_DISCRIMINATOR: number[];
376
+ declare const AMOUNT_IN_DLMM_OFFSET = 8;
377
+ declare const AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
378
+ declare const AMOUNT_IN_DAMM_V2_OFFSET = 8;
379
+ declare const DAMM_V2_SWAP_DISCRIMINATOR: number[];
380
+
381
+ export { AMOUNT_IN_DAMM_V2_OFFSET, AMOUNT_IN_DLMM_OFFSET, AMOUNT_IN_JUP_V6_REVERSE_OFFSET, AccountsType, BIN_ARRAY_INDEX_BOUND, DAMM_V2_PROGRAM_ID, DAMM_V2_SWAP_DISCRIMINATOR, DLMM_PROGRAM_ID, DLMM_SWAP_DISCRIMINATOR, JUP_V6_PROGRAM_ID, type JupiterInstruction, type JupiterQuoteResponse, type JupiterRoutePlan, type JupiterSwapInstructionResponse, MEMO_PROGRAM_ID, ZAP_PROGRAM_ID, Zap, type ZapOutParameters, type ZapOutParams, type ZapOutThroughDammV2Params, type ZapOutThroughDlmmParams, type ZapOutThroughJupiterParams, type ZapProgram, convertAccountTypeToNumber, createDammV2SwapPayload, createDlmmSwapPayload, deriveDammV2EventAuthority, getBinArrayBitmapExtension, getBitFromBinArrayIndexInBitmapExtension, getDammV2Pool, getDammV2RemainingAccounts, getDlmmRemainingAccounts, getExtraAccountMetasForTransferHook, getJupiterQuote, getJupiterSwapInstruction, getLbPairState, getNextBinArrayIndexWithLiquidity, getOrCreateATAInstruction, getTokenProgramFromMint, unwrapSOLInstruction, wrapSOLInstruction };