@meteora-ag/zap-sdk 1.3.1 → 2.0.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +31 -5
- package/dist/index.d.mts +1456 -1029
- package/dist/index.d.ts +1456 -1029
- package/dist/index.js +1190 -525
- package/dist/index.mjs +1131 -484
- package/package.json +12 -11
package/dist/index.js
CHANGED
|
@@ -75,12 +75,20 @@ __export(index_exports, {
|
|
|
75
75
|
DAMM_V2_PROGRAM_ID: () => DAMM_V2_PROGRAM_ID,
|
|
76
76
|
DAMM_V2_SWAP_DISCRIMINATOR: () => DAMM_V2_SWAP_DISCRIMINATOR,
|
|
77
77
|
DEFAULT_JUPITER_API_URL: () => DEFAULT_JUPITER_API_URL,
|
|
78
|
+
DEFAULT_JUPITER_API_VERSION: () => DEFAULT_JUPITER_API_VERSION,
|
|
79
|
+
DEFAULT_JUPITER_QUOTE_OPTIONS: () => DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
78
80
|
DLMM_PROGRAM_ID: () => DLMM_PROGRAM_ID,
|
|
79
81
|
DLMM_SWAP_DISCRIMINATOR: () => DLMM_SWAP_DISCRIMINATOR,
|
|
80
82
|
DlmmDirectSwapQuoteRoute: () => DlmmDirectSwapQuoteRoute,
|
|
81
83
|
DlmmSingleSided: () => DlmmSingleSided,
|
|
82
84
|
DlmmSwapType: () => DlmmSwapType,
|
|
85
|
+
JUPITER_INSTRUCTION_LAYOUTS: () => JUPITER_INSTRUCTION_LAYOUTS,
|
|
83
86
|
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
|
+
JupiterApiVersion: () => JupiterApiVersion,
|
|
84
92
|
MEMO_PROGRAM_ID: () => MEMO_PROGRAM_ID,
|
|
85
93
|
SwapExternalType: () => SwapExternalType,
|
|
86
94
|
ZAP_PROGRAM_ID: () => ZAP_PROGRAM_ID,
|
|
@@ -100,13 +108,17 @@ __export(index_exports, {
|
|
|
100
108
|
estimateDlmmDirectSwap: () => estimateDlmmDirectSwap,
|
|
101
109
|
estimateDlmmIndirectSwap: () => estimateDlmmIndirectSwap,
|
|
102
110
|
estimateDlmmRebalanceSwap: () => estimateDlmmRebalanceSwap,
|
|
111
|
+
fetchAddressLookupTableAccounts: () => fetchAddressLookupTableAccounts,
|
|
103
112
|
filterOutCloseSplTokenAccountInstructions: () => filterOutCloseSplTokenAccountInstructions,
|
|
113
|
+
filterOutComputeBudgetInstructions: () => filterOutComputeBudgetInstructions,
|
|
104
114
|
getBinArrayBitmapExtension: () => getBinArrayBitmapExtension,
|
|
105
115
|
getBitFromBinArrayIndexInBitmapExtension: () => getBitFromBinArrayIndexInBitmapExtension,
|
|
106
116
|
getDammV2Pool: () => getDammV2Pool,
|
|
107
117
|
getDammV2RemainingAccounts: () => getDammV2RemainingAccounts,
|
|
108
118
|
getDlmmRemainingAccounts: () => getDlmmRemainingAccounts,
|
|
109
119
|
getExtraAccountMetasForTransferHook: () => getExtraAccountMetasForTransferHook,
|
|
120
|
+
getJupiterAddressLookupTableAccounts: () => getJupiterAddressLookupTableAccounts,
|
|
121
|
+
getJupiterInstructionLayout: () => getJupiterInstructionLayout,
|
|
110
122
|
getJupiterQuote: () => getJupiterQuote,
|
|
111
123
|
getJupiterSwapInstruction: () => getJupiterSwapInstruction,
|
|
112
124
|
getLbPairState: () => getLbPairState,
|
|
@@ -114,8 +126,13 @@ __export(index_exports, {
|
|
|
114
126
|
getOrCreateATAInstruction: () => getOrCreateATAInstruction,
|
|
115
127
|
getTokenAccountBalance: () => getTokenAccountBalance,
|
|
116
128
|
getTokenProgramFromMint: () => getTokenProgramFromMint,
|
|
129
|
+
isJupiterBuildResponse: () => isJupiterBuildResponse,
|
|
130
|
+
isJupiterSwapInstructionForUser: () => isJupiterSwapInstructionForUser,
|
|
117
131
|
isSingleSidedA: () => isSingleSidedA,
|
|
118
132
|
isSingleSidedB: () => isSingleSidedB,
|
|
133
|
+
mergeAddressLookupTableAccounts: () => mergeAddressLookupTableAccounts,
|
|
134
|
+
resolveJupiterConfig: () => resolveJupiterConfig,
|
|
135
|
+
toAddressLookupTableAccounts: () => toAddressLookupTableAccounts,
|
|
119
136
|
toProgramStrategyType: () => toProgramStrategyType,
|
|
120
137
|
unwrapSOLInstruction: () => unwrapSOLInstruction,
|
|
121
138
|
wrapSOLInstruction: () => wrapSOLInstruction
|
|
@@ -125,21 +142,30 @@ module.exports = __toCommonJS(index_exports);
|
|
|
125
142
|
// src/zap.ts
|
|
126
143
|
var import_web38 = require("@solana/web3.js");
|
|
127
144
|
var import_invariant2 = __toESM(require("invariant"));
|
|
128
|
-
var
|
|
145
|
+
var import_core = require("@anchor-lang/core");
|
|
129
146
|
|
|
130
147
|
// src/idl/zap/idl.json
|
|
131
148
|
var idl_default = {
|
|
132
149
|
address: "zapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz",
|
|
133
150
|
metadata: {
|
|
134
151
|
name: "zap",
|
|
135
|
-
version: "0.2.
|
|
152
|
+
version: "0.2.3",
|
|
136
153
|
spec: "0.1.0",
|
|
137
154
|
description: "Created with Anchor"
|
|
138
155
|
},
|
|
139
156
|
instructions: [
|
|
140
157
|
{
|
|
141
158
|
name: "close_ledger_account",
|
|
142
|
-
discriminator: [
|
|
159
|
+
discriminator: [
|
|
160
|
+
189,
|
|
161
|
+
122,
|
|
162
|
+
172,
|
|
163
|
+
13,
|
|
164
|
+
122,
|
|
165
|
+
54,
|
|
166
|
+
54,
|
|
167
|
+
51
|
|
168
|
+
],
|
|
143
169
|
accounts: [
|
|
144
170
|
{
|
|
145
171
|
name: "ledger",
|
|
@@ -148,7 +174,9 @@ var idl_default = {
|
|
|
148
174
|
{
|
|
149
175
|
name: "owner",
|
|
150
176
|
signer: true,
|
|
151
|
-
relations: [
|
|
177
|
+
relations: [
|
|
178
|
+
"ledger"
|
|
179
|
+
]
|
|
152
180
|
},
|
|
153
181
|
{
|
|
154
182
|
name: "rent_receiver",
|
|
@@ -160,7 +188,16 @@ var idl_default = {
|
|
|
160
188
|
},
|
|
161
189
|
{
|
|
162
190
|
name: "initialize_ledger_account",
|
|
163
|
-
discriminator: [
|
|
191
|
+
discriminator: [
|
|
192
|
+
120,
|
|
193
|
+
69,
|
|
194
|
+
30,
|
|
195
|
+
74,
|
|
196
|
+
76,
|
|
197
|
+
242,
|
|
198
|
+
153,
|
|
199
|
+
162
|
|
200
|
+
],
|
|
164
201
|
accounts: [
|
|
165
202
|
{
|
|
166
203
|
name: "ledger",
|
|
@@ -169,7 +206,19 @@ var idl_default = {
|
|
|
169
206
|
seeds: [
|
|
170
207
|
{
|
|
171
208
|
kind: "const",
|
|
172
|
-
value: [
|
|
209
|
+
value: [
|
|
210
|
+
117,
|
|
211
|
+
115,
|
|
212
|
+
101,
|
|
213
|
+
114,
|
|
214
|
+
95,
|
|
215
|
+
108,
|
|
216
|
+
101,
|
|
217
|
+
100,
|
|
218
|
+
103,
|
|
219
|
+
101,
|
|
220
|
+
114
|
|
221
|
+
]
|
|
173
222
|
},
|
|
174
223
|
{
|
|
175
224
|
kind: "account",
|
|
@@ -196,7 +245,16 @@ var idl_default = {
|
|
|
196
245
|
},
|
|
197
246
|
{
|
|
198
247
|
name: "set_ledger_balance",
|
|
199
|
-
discriminator: [
|
|
248
|
+
discriminator: [
|
|
249
|
+
131,
|
|
250
|
+
49,
|
|
251
|
+
240,
|
|
252
|
+
17,
|
|
253
|
+
228,
|
|
254
|
+
248,
|
|
255
|
+
156,
|
|
256
|
+
54
|
|
257
|
+
],
|
|
200
258
|
accounts: [
|
|
201
259
|
{
|
|
202
260
|
name: "ledger",
|
|
@@ -205,7 +263,9 @@ var idl_default = {
|
|
|
205
263
|
{
|
|
206
264
|
name: "owner",
|
|
207
265
|
signer: true,
|
|
208
|
-
relations: [
|
|
266
|
+
relations: [
|
|
267
|
+
"ledger"
|
|
268
|
+
]
|
|
209
269
|
}
|
|
210
270
|
],
|
|
211
271
|
args: [
|
|
@@ -221,7 +281,16 @@ var idl_default = {
|
|
|
221
281
|
},
|
|
222
282
|
{
|
|
223
283
|
name: "update_ledger_balance_after_swap",
|
|
224
|
-
discriminator: [
|
|
284
|
+
discriminator: [
|
|
285
|
+
59,
|
|
286
|
+
206,
|
|
287
|
+
173,
|
|
288
|
+
232,
|
|
289
|
+
94,
|
|
290
|
+
57,
|
|
291
|
+
174,
|
|
292
|
+
202
|
|
293
|
+
],
|
|
225
294
|
accounts: [
|
|
226
295
|
{
|
|
227
296
|
name: "ledger",
|
|
@@ -233,7 +302,9 @@ var idl_default = {
|
|
|
233
302
|
{
|
|
234
303
|
name: "owner",
|
|
235
304
|
signer: true,
|
|
236
|
-
relations: [
|
|
305
|
+
relations: [
|
|
306
|
+
"ledger"
|
|
307
|
+
]
|
|
237
308
|
}
|
|
238
309
|
],
|
|
239
310
|
args: [
|
|
@@ -253,7 +324,16 @@ var idl_default = {
|
|
|
253
324
|
},
|
|
254
325
|
{
|
|
255
326
|
name: "zap_in_damm_v2",
|
|
256
|
-
discriminator: [
|
|
327
|
+
discriminator: [
|
|
328
|
+
243,
|
|
329
|
+
243,
|
|
330
|
+
119,
|
|
331
|
+
52,
|
|
332
|
+
199,
|
|
333
|
+
44,
|
|
334
|
+
154,
|
|
335
|
+
186
|
|
336
|
+
],
|
|
257
337
|
accounts: [
|
|
258
338
|
{
|
|
259
339
|
name: "ledger",
|
|
@@ -297,9 +377,13 @@ var idl_default = {
|
|
|
297
377
|
},
|
|
298
378
|
{
|
|
299
379
|
name: "owner",
|
|
300
|
-
docs: [
|
|
380
|
+
docs: [
|
|
381
|
+
"owner of position"
|
|
382
|
+
],
|
|
301
383
|
signer: true,
|
|
302
|
-
relations: [
|
|
384
|
+
relations: [
|
|
385
|
+
"ledger"
|
|
386
|
+
]
|
|
303
387
|
},
|
|
304
388
|
{
|
|
305
389
|
name: "token_a_program"
|
|
@@ -328,7 +412,16 @@ var idl_default = {
|
|
|
328
412
|
},
|
|
329
413
|
{
|
|
330
414
|
name: "zap_in_dlmm_for_initialized_position",
|
|
331
|
-
discriminator: [
|
|
415
|
+
discriminator: [
|
|
416
|
+
184,
|
|
417
|
+
71,
|
|
418
|
+
198,
|
|
419
|
+
231,
|
|
420
|
+
129,
|
|
421
|
+
110,
|
|
422
|
+
193,
|
|
423
|
+
67
|
|
424
|
+
],
|
|
332
425
|
accounts: [
|
|
333
426
|
{
|
|
334
427
|
name: "ledger",
|
|
@@ -336,7 +429,9 @@ var idl_default = {
|
|
|
336
429
|
},
|
|
337
430
|
{
|
|
338
431
|
name: "lb_pair",
|
|
339
|
-
docs: [
|
|
432
|
+
docs: [
|
|
433
|
+
"lb pair"
|
|
434
|
+
],
|
|
340
435
|
writable: true
|
|
341
436
|
},
|
|
342
437
|
{
|
|
@@ -376,9 +471,13 @@ var idl_default = {
|
|
|
376
471
|
},
|
|
377
472
|
{
|
|
378
473
|
name: "owner",
|
|
379
|
-
docs: [
|
|
474
|
+
docs: [
|
|
475
|
+
"owner of position"
|
|
476
|
+
],
|
|
380
477
|
signer: true,
|
|
381
|
-
relations: [
|
|
478
|
+
relations: [
|
|
479
|
+
"ledger"
|
|
480
|
+
]
|
|
382
481
|
},
|
|
383
482
|
{
|
|
384
483
|
name: "rent_payer",
|
|
@@ -442,7 +541,16 @@ var idl_default = {
|
|
|
442
541
|
},
|
|
443
542
|
{
|
|
444
543
|
name: "zap_in_dlmm_for_uninitialized_position",
|
|
445
|
-
discriminator: [
|
|
544
|
+
discriminator: [
|
|
545
|
+
59,
|
|
546
|
+
220,
|
|
547
|
+
182,
|
|
548
|
+
27,
|
|
549
|
+
254,
|
|
550
|
+
253,
|
|
551
|
+
2,
|
|
552
|
+
232
|
|
553
|
+
],
|
|
446
554
|
accounts: [
|
|
447
555
|
{
|
|
448
556
|
name: "ledger",
|
|
@@ -450,7 +558,9 @@ var idl_default = {
|
|
|
450
558
|
},
|
|
451
559
|
{
|
|
452
560
|
name: "lb_pair",
|
|
453
|
-
docs: [
|
|
561
|
+
docs: [
|
|
562
|
+
"lb pair"
|
|
563
|
+
],
|
|
454
564
|
writable: true
|
|
455
565
|
},
|
|
456
566
|
{
|
|
@@ -495,9 +605,13 @@ var idl_default = {
|
|
|
495
605
|
},
|
|
496
606
|
{
|
|
497
607
|
name: "owner",
|
|
498
|
-
docs: [
|
|
608
|
+
docs: [
|
|
609
|
+
"owner of position"
|
|
610
|
+
],
|
|
499
611
|
signer: true,
|
|
500
|
-
relations: [
|
|
612
|
+
relations: [
|
|
613
|
+
"ledger"
|
|
614
|
+
]
|
|
501
615
|
},
|
|
502
616
|
{
|
|
503
617
|
name: "rent_payer",
|
|
@@ -561,7 +675,16 @@ var idl_default = {
|
|
|
561
675
|
},
|
|
562
676
|
{
|
|
563
677
|
name: "zap_out",
|
|
564
|
-
discriminator: [
|
|
678
|
+
discriminator: [
|
|
679
|
+
155,
|
|
680
|
+
108,
|
|
681
|
+
185,
|
|
682
|
+
112,
|
|
683
|
+
104,
|
|
684
|
+
210,
|
|
685
|
+
161,
|
|
686
|
+
64
|
|
687
|
+
],
|
|
565
688
|
accounts: [
|
|
566
689
|
{
|
|
567
690
|
name: "user_token_in_account",
|
|
@@ -584,17 +707,18 @@ var idl_default = {
|
|
|
584
707
|
}
|
|
585
708
|
],
|
|
586
709
|
accounts: [
|
|
587
|
-
{
|
|
588
|
-
name: "LbPair",
|
|
589
|
-
discriminator: [33, 11, 49, 98, 181, 101, 177, 13]
|
|
590
|
-
},
|
|
591
|
-
{
|
|
592
|
-
name: "Pool",
|
|
593
|
-
discriminator: [241, 154, 109, 4, 17, 177, 109, 188]
|
|
594
|
-
},
|
|
595
710
|
{
|
|
596
711
|
name: "UserLedger",
|
|
597
|
-
discriminator: [
|
|
712
|
+
discriminator: [
|
|
713
|
+
185,
|
|
714
|
+
84,
|
|
715
|
+
101,
|
|
716
|
+
128,
|
|
717
|
+
8,
|
|
718
|
+
6,
|
|
719
|
+
160,
|
|
720
|
+
83
|
|
721
|
+
]
|
|
598
722
|
}
|
|
599
723
|
],
|
|
600
724
|
errors: [
|
|
@@ -661,7 +785,9 @@ var idl_default = {
|
|
|
661
785
|
},
|
|
662
786
|
{
|
|
663
787
|
name: "TransferHookMultiReward",
|
|
664
|
-
fields: [
|
|
788
|
+
fields: [
|
|
789
|
+
"u8"
|
|
790
|
+
]
|
|
665
791
|
},
|
|
666
792
|
{
|
|
667
793
|
name: "TransferHookReferral"
|
|
@@ -670,7 +796,7 @@ var idl_default = {
|
|
|
670
796
|
}
|
|
671
797
|
},
|
|
672
798
|
{
|
|
673
|
-
name: "
|
|
799
|
+
name: "BaseFeeInfo",
|
|
674
800
|
serialization: "bytemuck",
|
|
675
801
|
repr: {
|
|
676
802
|
kind: "c"
|
|
@@ -679,33 +805,34 @@ var idl_default = {
|
|
|
679
805
|
kind: "struct",
|
|
680
806
|
fields: [
|
|
681
807
|
{
|
|
682
|
-
name: "
|
|
683
|
-
type: "u64"
|
|
684
|
-
},
|
|
685
|
-
{
|
|
686
|
-
name: "base_fee_mode",
|
|
687
|
-
type: "u8"
|
|
688
|
-
},
|
|
689
|
-
{
|
|
690
|
-
name: "padding_0",
|
|
808
|
+
name: "data",
|
|
691
809
|
type: {
|
|
692
|
-
array: [
|
|
810
|
+
array: [
|
|
811
|
+
"u8",
|
|
812
|
+
32
|
|
813
|
+
]
|
|
693
814
|
}
|
|
694
|
-
}
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
815
|
+
}
|
|
816
|
+
]
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
{
|
|
820
|
+
name: "BaseFeeStruct",
|
|
821
|
+
serialization: "bytemuck",
|
|
822
|
+
repr: {
|
|
823
|
+
kind: "c"
|
|
824
|
+
},
|
|
825
|
+
type: {
|
|
826
|
+
kind: "struct",
|
|
827
|
+
fields: [
|
|
699
828
|
{
|
|
700
|
-
name: "
|
|
829
|
+
name: "base_fee_info",
|
|
701
830
|
type: {
|
|
702
|
-
|
|
831
|
+
defined: {
|
|
832
|
+
name: "BaseFeeInfo"
|
|
833
|
+
}
|
|
703
834
|
}
|
|
704
835
|
},
|
|
705
|
-
{
|
|
706
|
-
name: "third_factor",
|
|
707
|
-
type: "u64"
|
|
708
|
-
},
|
|
709
836
|
{
|
|
710
837
|
name: "padding_1",
|
|
711
838
|
type: "u64"
|
|
@@ -729,7 +856,10 @@ var idl_default = {
|
|
|
729
856
|
{
|
|
730
857
|
name: "padding",
|
|
731
858
|
type: {
|
|
732
|
-
array: [
|
|
859
|
+
array: [
|
|
860
|
+
"u8",
|
|
861
|
+
7
|
|
862
|
+
]
|
|
733
863
|
}
|
|
734
864
|
},
|
|
735
865
|
{
|
|
@@ -807,13 +937,19 @@ var idl_default = {
|
|
|
807
937
|
{
|
|
808
938
|
name: "bump_seed",
|
|
809
939
|
type: {
|
|
810
|
-
array: [
|
|
940
|
+
array: [
|
|
941
|
+
"u8",
|
|
942
|
+
1
|
|
943
|
+
]
|
|
811
944
|
}
|
|
812
945
|
},
|
|
813
946
|
{
|
|
814
947
|
name: "bin_step_seed",
|
|
815
948
|
type: {
|
|
816
|
-
array: [
|
|
949
|
+
array: [
|
|
950
|
+
"u8",
|
|
951
|
+
2
|
|
952
|
+
]
|
|
817
953
|
}
|
|
818
954
|
},
|
|
819
955
|
{
|
|
@@ -839,7 +975,10 @@ var idl_default = {
|
|
|
839
975
|
{
|
|
840
976
|
name: "base_factor_seed",
|
|
841
977
|
type: {
|
|
842
|
-
array: [
|
|
978
|
+
array: [
|
|
979
|
+
"u8",
|
|
980
|
+
2
|
|
981
|
+
]
|
|
843
982
|
}
|
|
844
983
|
},
|
|
845
984
|
{
|
|
@@ -877,7 +1016,10 @@ var idl_default = {
|
|
|
877
1016
|
{
|
|
878
1017
|
name: "_padding_1",
|
|
879
1018
|
type: {
|
|
880
|
-
array: [
|
|
1019
|
+
array: [
|
|
1020
|
+
"u8",
|
|
1021
|
+
32
|
|
1022
|
+
]
|
|
881
1023
|
}
|
|
882
1024
|
},
|
|
883
1025
|
{
|
|
@@ -900,7 +1042,10 @@ var idl_default = {
|
|
|
900
1042
|
{
|
|
901
1043
|
name: "bin_array_bitmap",
|
|
902
1044
|
type: {
|
|
903
|
-
array: [
|
|
1045
|
+
array: [
|
|
1046
|
+
"u64",
|
|
1047
|
+
16
|
|
1048
|
+
]
|
|
904
1049
|
}
|
|
905
1050
|
},
|
|
906
1051
|
{
|
|
@@ -910,7 +1055,10 @@ var idl_default = {
|
|
|
910
1055
|
{
|
|
911
1056
|
name: "_padding_2",
|
|
912
1057
|
type: {
|
|
913
|
-
array: [
|
|
1058
|
+
array: [
|
|
1059
|
+
"u8",
|
|
1060
|
+
32
|
|
1061
|
+
]
|
|
914
1062
|
}
|
|
915
1063
|
},
|
|
916
1064
|
{
|
|
@@ -932,7 +1080,10 @@ var idl_default = {
|
|
|
932
1080
|
{
|
|
933
1081
|
name: "_padding_3",
|
|
934
1082
|
type: {
|
|
935
|
-
array: [
|
|
1083
|
+
array: [
|
|
1084
|
+
"u8",
|
|
1085
|
+
8
|
|
1086
|
+
]
|
|
936
1087
|
}
|
|
937
1088
|
},
|
|
938
1089
|
{
|
|
@@ -951,10 +1102,17 @@ var idl_default = {
|
|
|
951
1102
|
name: "token_mint_y_program_flag",
|
|
952
1103
|
type: "u8"
|
|
953
1104
|
},
|
|
1105
|
+
{
|
|
1106
|
+
name: "version",
|
|
1107
|
+
type: "u8"
|
|
1108
|
+
},
|
|
954
1109
|
{
|
|
955
1110
|
name: "_reserved",
|
|
956
1111
|
type: {
|
|
957
|
-
array: [
|
|
1112
|
+
array: [
|
|
1113
|
+
"u8",
|
|
1114
|
+
21
|
|
1115
|
+
]
|
|
958
1116
|
}
|
|
959
1117
|
}
|
|
960
1118
|
]
|
|
@@ -971,7 +1129,9 @@ var idl_default = {
|
|
|
971
1129
|
fields: [
|
|
972
1130
|
{
|
|
973
1131
|
name: "pool_fees",
|
|
974
|
-
docs: [
|
|
1132
|
+
docs: [
|
|
1133
|
+
"Pool fee"
|
|
1134
|
+
],
|
|
975
1135
|
type: {
|
|
976
1136
|
defined: {
|
|
977
1137
|
name: "PoolFeesStruct"
|
|
@@ -980,22 +1140,30 @@ var idl_default = {
|
|
|
980
1140
|
},
|
|
981
1141
|
{
|
|
982
1142
|
name: "token_a_mint",
|
|
983
|
-
docs: [
|
|
1143
|
+
docs: [
|
|
1144
|
+
"token a mint"
|
|
1145
|
+
],
|
|
984
1146
|
type: "pubkey"
|
|
985
1147
|
},
|
|
986
1148
|
{
|
|
987
1149
|
name: "token_b_mint",
|
|
988
|
-
docs: [
|
|
1150
|
+
docs: [
|
|
1151
|
+
"token b mint"
|
|
1152
|
+
],
|
|
989
1153
|
type: "pubkey"
|
|
990
1154
|
},
|
|
991
1155
|
{
|
|
992
1156
|
name: "token_a_vault",
|
|
993
|
-
docs: [
|
|
1157
|
+
docs: [
|
|
1158
|
+
"token a vault"
|
|
1159
|
+
],
|
|
994
1160
|
type: "pubkey"
|
|
995
1161
|
},
|
|
996
1162
|
{
|
|
997
1163
|
name: "token_b_vault",
|
|
998
|
-
docs: [
|
|
1164
|
+
docs: [
|
|
1165
|
+
"token b vault"
|
|
1166
|
+
],
|
|
999
1167
|
type: "pubkey"
|
|
1000
1168
|
},
|
|
1001
1169
|
{
|
|
@@ -1006,17 +1174,26 @@ var idl_default = {
|
|
|
1006
1174
|
type: "pubkey"
|
|
1007
1175
|
},
|
|
1008
1176
|
{
|
|
1009
|
-
name: "
|
|
1010
|
-
docs: [
|
|
1011
|
-
|
|
1177
|
+
name: "padding_0",
|
|
1178
|
+
docs: [
|
|
1179
|
+
"padding, previously partner pubkey, be careful when using this field"
|
|
1180
|
+
],
|
|
1181
|
+
type: {
|
|
1182
|
+
array: [
|
|
1183
|
+
"u8",
|
|
1184
|
+
32
|
|
1185
|
+
]
|
|
1186
|
+
}
|
|
1012
1187
|
},
|
|
1013
1188
|
{
|
|
1014
1189
|
name: "liquidity",
|
|
1015
|
-
docs: [
|
|
1190
|
+
docs: [
|
|
1191
|
+
"liquidity share"
|
|
1192
|
+
],
|
|
1016
1193
|
type: "u128"
|
|
1017
1194
|
},
|
|
1018
1195
|
{
|
|
1019
|
-
name: "
|
|
1196
|
+
name: "padding_1",
|
|
1020
1197
|
docs: [
|
|
1021
1198
|
"padding, previous reserve amount, be careful to use that field"
|
|
1022
1199
|
],
|
|
@@ -1024,100 +1201,128 @@ var idl_default = {
|
|
|
1024
1201
|
},
|
|
1025
1202
|
{
|
|
1026
1203
|
name: "protocol_a_fee",
|
|
1027
|
-
docs: [
|
|
1204
|
+
docs: [
|
|
1205
|
+
"protocol a fee"
|
|
1206
|
+
],
|
|
1028
1207
|
type: "u64"
|
|
1029
1208
|
},
|
|
1030
1209
|
{
|
|
1031
1210
|
name: "protocol_b_fee",
|
|
1032
|
-
docs: [
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
{
|
|
1036
|
-
name: "partner_a_fee",
|
|
1037
|
-
docs: ["partner a fee"],
|
|
1211
|
+
docs: [
|
|
1212
|
+
"protocol b fee"
|
|
1213
|
+
],
|
|
1038
1214
|
type: "u64"
|
|
1039
1215
|
},
|
|
1040
1216
|
{
|
|
1041
|
-
name: "
|
|
1042
|
-
|
|
1043
|
-
type: "u64"
|
|
1217
|
+
name: "padding_2",
|
|
1218
|
+
type: "u128"
|
|
1044
1219
|
},
|
|
1045
1220
|
{
|
|
1046
1221
|
name: "sqrt_min_price",
|
|
1047
|
-
docs: [
|
|
1222
|
+
docs: [
|
|
1223
|
+
"min price"
|
|
1224
|
+
],
|
|
1048
1225
|
type: "u128"
|
|
1049
1226
|
},
|
|
1050
1227
|
{
|
|
1051
1228
|
name: "sqrt_max_price",
|
|
1052
|
-
docs: [
|
|
1229
|
+
docs: [
|
|
1230
|
+
"max price"
|
|
1231
|
+
],
|
|
1053
1232
|
type: "u128"
|
|
1054
1233
|
},
|
|
1055
1234
|
{
|
|
1056
1235
|
name: "sqrt_price",
|
|
1057
|
-
docs: [
|
|
1236
|
+
docs: [
|
|
1237
|
+
"current price"
|
|
1238
|
+
],
|
|
1058
1239
|
type: "u128"
|
|
1059
1240
|
},
|
|
1060
1241
|
{
|
|
1061
1242
|
name: "activation_point",
|
|
1062
|
-
docs: [
|
|
1243
|
+
docs: [
|
|
1244
|
+
"Activation point, can be slot or timestamp"
|
|
1245
|
+
],
|
|
1063
1246
|
type: "u64"
|
|
1064
1247
|
},
|
|
1065
1248
|
{
|
|
1066
1249
|
name: "activation_type",
|
|
1067
|
-
docs: [
|
|
1250
|
+
docs: [
|
|
1251
|
+
"Activation type, 0 means by slot, 1 means by timestamp"
|
|
1252
|
+
],
|
|
1068
1253
|
type: "u8"
|
|
1069
1254
|
},
|
|
1070
1255
|
{
|
|
1071
1256
|
name: "pool_status",
|
|
1072
|
-
docs: [
|
|
1257
|
+
docs: [
|
|
1258
|
+
"pool status, 0: enable, 1 disable"
|
|
1259
|
+
],
|
|
1073
1260
|
type: "u8"
|
|
1074
1261
|
},
|
|
1075
1262
|
{
|
|
1076
1263
|
name: "token_a_flag",
|
|
1077
|
-
docs: [
|
|
1264
|
+
docs: [
|
|
1265
|
+
"token a flag"
|
|
1266
|
+
],
|
|
1078
1267
|
type: "u8"
|
|
1079
1268
|
},
|
|
1080
1269
|
{
|
|
1081
1270
|
name: "token_b_flag",
|
|
1082
|
-
docs: [
|
|
1271
|
+
docs: [
|
|
1272
|
+
"token b flag"
|
|
1273
|
+
],
|
|
1083
1274
|
type: "u8"
|
|
1084
1275
|
},
|
|
1085
1276
|
{
|
|
1086
1277
|
name: "collect_fee_mode",
|
|
1087
1278
|
docs: [
|
|
1088
|
-
"0 is collect fee in both token, 1 only collect fee
|
|
1279
|
+
"0 is collect fee in both token, 1 only collect fee only in token b"
|
|
1089
1280
|
],
|
|
1090
1281
|
type: "u8"
|
|
1091
1282
|
},
|
|
1092
1283
|
{
|
|
1093
1284
|
name: "pool_type",
|
|
1094
|
-
docs: [
|
|
1285
|
+
docs: [
|
|
1286
|
+
"pool type"
|
|
1287
|
+
],
|
|
1095
1288
|
type: "u8"
|
|
1096
1289
|
},
|
|
1097
1290
|
{
|
|
1098
|
-
name: "
|
|
1291
|
+
name: "fee_version",
|
|
1099
1292
|
docs: [
|
|
1100
|
-
"pool version, 0: max_fee is still capped at 50%, 1: max_fee is capped at 99%"
|
|
1293
|
+
"pool fee version, 0: max_fee is still capped at 50%, 1: max_fee is capped at 99%"
|
|
1101
1294
|
],
|
|
1102
1295
|
type: "u8"
|
|
1103
1296
|
},
|
|
1104
1297
|
{
|
|
1105
|
-
name: "
|
|
1106
|
-
docs: [
|
|
1298
|
+
name: "padding_3",
|
|
1299
|
+
docs: [
|
|
1300
|
+
"padding"
|
|
1301
|
+
],
|
|
1107
1302
|
type: "u8"
|
|
1108
1303
|
},
|
|
1109
1304
|
{
|
|
1110
1305
|
name: "fee_a_per_liquidity",
|
|
1111
|
-
docs: [
|
|
1306
|
+
docs: [
|
|
1307
|
+
"cumulative"
|
|
1308
|
+
],
|
|
1112
1309
|
type: {
|
|
1113
|
-
array: [
|
|
1310
|
+
array: [
|
|
1311
|
+
"u8",
|
|
1312
|
+
32
|
|
1313
|
+
]
|
|
1114
1314
|
}
|
|
1115
1315
|
},
|
|
1116
1316
|
{
|
|
1117
1317
|
name: "fee_b_per_liquidity",
|
|
1118
|
-
docs: [
|
|
1318
|
+
docs: [
|
|
1319
|
+
"cumulative"
|
|
1320
|
+
],
|
|
1119
1321
|
type: {
|
|
1120
|
-
array: [
|
|
1322
|
+
array: [
|
|
1323
|
+
"u8",
|
|
1324
|
+
32
|
|
1325
|
+
]
|
|
1121
1326
|
}
|
|
1122
1327
|
},
|
|
1123
1328
|
{
|
|
@@ -1126,7 +1331,9 @@ var idl_default = {
|
|
|
1126
1331
|
},
|
|
1127
1332
|
{
|
|
1128
1333
|
name: "metrics",
|
|
1129
|
-
docs: [
|
|
1334
|
+
docs: [
|
|
1335
|
+
"metrics"
|
|
1336
|
+
],
|
|
1130
1337
|
type: {
|
|
1131
1338
|
defined: {
|
|
1132
1339
|
name: "PoolMetrics"
|
|
@@ -1135,19 +1342,61 @@ var idl_default = {
|
|
|
1135
1342
|
},
|
|
1136
1343
|
{
|
|
1137
1344
|
name: "creator",
|
|
1138
|
-
docs: [
|
|
1345
|
+
docs: [
|
|
1346
|
+
"pool creator"
|
|
1347
|
+
],
|
|
1139
1348
|
type: "pubkey"
|
|
1140
1349
|
},
|
|
1141
1350
|
{
|
|
1142
|
-
name: "
|
|
1143
|
-
docs: [
|
|
1351
|
+
name: "token_a_amount",
|
|
1352
|
+
docs: [
|
|
1353
|
+
"token a amount"
|
|
1354
|
+
],
|
|
1355
|
+
type: "u64"
|
|
1356
|
+
},
|
|
1357
|
+
{
|
|
1358
|
+
name: "token_b_amount",
|
|
1359
|
+
docs: [
|
|
1360
|
+
"token b amount"
|
|
1361
|
+
],
|
|
1362
|
+
type: "u64"
|
|
1363
|
+
},
|
|
1364
|
+
{
|
|
1365
|
+
name: "layout_version",
|
|
1366
|
+
docs: [
|
|
1367
|
+
"layout version: version 0: haven't track token_a_amount and token_b_amount, version 1: track token_a_amount and token_b_amount"
|
|
1368
|
+
],
|
|
1369
|
+
type: "u8"
|
|
1370
|
+
},
|
|
1371
|
+
{
|
|
1372
|
+
name: "padding_4",
|
|
1373
|
+
docs: [
|
|
1374
|
+
"Padding for further use"
|
|
1375
|
+
],
|
|
1376
|
+
type: {
|
|
1377
|
+
array: [
|
|
1378
|
+
"u8",
|
|
1379
|
+
7
|
|
1380
|
+
]
|
|
1381
|
+
}
|
|
1382
|
+
},
|
|
1383
|
+
{
|
|
1384
|
+
name: "padding_5",
|
|
1385
|
+
docs: [
|
|
1386
|
+
"Padding for further use"
|
|
1387
|
+
],
|
|
1144
1388
|
type: {
|
|
1145
|
-
array: [
|
|
1389
|
+
array: [
|
|
1390
|
+
"u64",
|
|
1391
|
+
3
|
|
1392
|
+
]
|
|
1146
1393
|
}
|
|
1147
1394
|
},
|
|
1148
1395
|
{
|
|
1149
1396
|
name: "reward_infos",
|
|
1150
|
-
docs: [
|
|
1397
|
+
docs: [
|
|
1398
|
+
"Farming reward information"
|
|
1399
|
+
],
|
|
1151
1400
|
type: {
|
|
1152
1401
|
array: [
|
|
1153
1402
|
{
|
|
@@ -1168,8 +1417,7 @@ var idl_default = {
|
|
|
1168
1417
|
"Information regarding fee charges",
|
|
1169
1418
|
"trading_fee = amount * trade_fee_numerator / denominator",
|
|
1170
1419
|
"protocol_fee = trading_fee * protocol_fee_percentage / 100",
|
|
1171
|
-
"referral_fee = protocol_fee * referral_percentage / 100"
|
|
1172
|
-
"partner_fee = (protocol_fee - referral_fee) * partner_fee_percentage / denominator"
|
|
1420
|
+
"referral_fee = protocol_fee * referral_percentage / 100"
|
|
1173
1421
|
],
|
|
1174
1422
|
serialization: "bytemuck",
|
|
1175
1423
|
repr: {
|
|
@@ -1202,25 +1450,43 @@ var idl_default = {
|
|
|
1202
1450
|
type: "u8"
|
|
1203
1451
|
},
|
|
1204
1452
|
{
|
|
1205
|
-
name: "
|
|
1206
|
-
docs: [
|
|
1453
|
+
name: "padding_0",
|
|
1454
|
+
docs: [
|
|
1455
|
+
"padding for future use"
|
|
1456
|
+
],
|
|
1207
1457
|
type: "u8"
|
|
1208
1458
|
},
|
|
1209
1459
|
{
|
|
1210
1460
|
name: "referral_fee_percent",
|
|
1211
|
-
docs: [
|
|
1461
|
+
docs: [
|
|
1462
|
+
"referral fee"
|
|
1463
|
+
],
|
|
1212
1464
|
type: "u8"
|
|
1213
1465
|
},
|
|
1214
1466
|
{
|
|
1215
|
-
name: "
|
|
1216
|
-
docs: [
|
|
1467
|
+
name: "padding_1",
|
|
1468
|
+
docs: [
|
|
1469
|
+
"padding"
|
|
1470
|
+
],
|
|
1217
1471
|
type: {
|
|
1218
|
-
array: [
|
|
1472
|
+
array: [
|
|
1473
|
+
"u8",
|
|
1474
|
+
3
|
|
1475
|
+
]
|
|
1219
1476
|
}
|
|
1220
1477
|
},
|
|
1478
|
+
{
|
|
1479
|
+
name: "compounding_fee_bps",
|
|
1480
|
+
docs: [
|
|
1481
|
+
"compounding fee bps, only non-zero in CollectFeeMode::Compounding"
|
|
1482
|
+
],
|
|
1483
|
+
type: "u16"
|
|
1484
|
+
},
|
|
1221
1485
|
{
|
|
1222
1486
|
name: "dynamic_fee",
|
|
1223
|
-
docs: [
|
|
1487
|
+
docs: [
|
|
1488
|
+
"dynamic fee"
|
|
1489
|
+
],
|
|
1224
1490
|
type: {
|
|
1225
1491
|
defined: {
|
|
1226
1492
|
name: "DynamicFeeStruct"
|
|
@@ -1228,11 +1494,8 @@ var idl_default = {
|
|
|
1228
1494
|
}
|
|
1229
1495
|
},
|
|
1230
1496
|
{
|
|
1231
|
-
name: "
|
|
1232
|
-
|
|
1233
|
-
type: {
|
|
1234
|
-
array: ["u64", 2]
|
|
1235
|
-
}
|
|
1497
|
+
name: "init_sqrt_price",
|
|
1498
|
+
type: "u128"
|
|
1236
1499
|
}
|
|
1237
1500
|
]
|
|
1238
1501
|
}
|
|
@@ -1263,12 +1526,13 @@ var idl_default = {
|
|
|
1263
1526
|
type: "u64"
|
|
1264
1527
|
},
|
|
1265
1528
|
{
|
|
1266
|
-
name: "
|
|
1267
|
-
type:
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1529
|
+
name: "padding_0",
|
|
1530
|
+
type: {
|
|
1531
|
+
array: [
|
|
1532
|
+
"u64",
|
|
1533
|
+
2
|
|
1534
|
+
]
|
|
1535
|
+
}
|
|
1272
1536
|
},
|
|
1273
1537
|
{
|
|
1274
1538
|
name: "total_position",
|
|
@@ -1341,7 +1605,9 @@ var idl_default = {
|
|
|
1341
1605
|
},
|
|
1342
1606
|
{
|
|
1343
1607
|
name: "StaticParameters",
|
|
1344
|
-
docs: [
|
|
1608
|
+
docs: [
|
|
1609
|
+
"Parameter that set by the protocol"
|
|
1610
|
+
],
|
|
1345
1611
|
serialization: "bytemuck",
|
|
1346
1612
|
repr: {
|
|
1347
1613
|
kind: "c"
|
|
@@ -1389,10 +1655,21 @@ var idl_default = {
|
|
|
1389
1655
|
name: "base_fee_power_factor",
|
|
1390
1656
|
type: "u8"
|
|
1391
1657
|
},
|
|
1658
|
+
{
|
|
1659
|
+
name: "function_type",
|
|
1660
|
+
type: "u8"
|
|
1661
|
+
},
|
|
1662
|
+
{
|
|
1663
|
+
name: "collect_fee_mode",
|
|
1664
|
+
type: "u8"
|
|
1665
|
+
},
|
|
1392
1666
|
{
|
|
1393
1667
|
name: "_padding",
|
|
1394
1668
|
type: {
|
|
1395
|
-
array: [
|
|
1669
|
+
array: [
|
|
1670
|
+
"u8",
|
|
1671
|
+
3
|
|
1672
|
+
]
|
|
1396
1673
|
}
|
|
1397
1674
|
}
|
|
1398
1675
|
]
|
|
@@ -1441,7 +1718,9 @@ var idl_default = {
|
|
|
1441
1718
|
},
|
|
1442
1719
|
{
|
|
1443
1720
|
name: "VariableParameters",
|
|
1444
|
-
docs: [
|
|
1721
|
+
docs: [
|
|
1722
|
+
"Parameters that changes based on dynamic of the market"
|
|
1723
|
+
],
|
|
1445
1724
|
serialization: "bytemuck",
|
|
1446
1725
|
repr: {
|
|
1447
1726
|
kind: "c"
|
|
@@ -1464,7 +1743,10 @@ var idl_default = {
|
|
|
1464
1743
|
{
|
|
1465
1744
|
name: "_padding",
|
|
1466
1745
|
type: {
|
|
1467
|
-
array: [
|
|
1746
|
+
array: [
|
|
1747
|
+
"u8",
|
|
1748
|
+
4
|
|
1749
|
+
]
|
|
1468
1750
|
}
|
|
1469
1751
|
},
|
|
1470
1752
|
{
|
|
@@ -1474,7 +1756,10 @@ var idl_default = {
|
|
|
1474
1756
|
{
|
|
1475
1757
|
name: "_padding_1",
|
|
1476
1758
|
type: {
|
|
1477
|
-
array: [
|
|
1759
|
+
array: [
|
|
1760
|
+
"u8",
|
|
1761
|
+
8
|
|
1762
|
+
]
|
|
1478
1763
|
}
|
|
1479
1764
|
}
|
|
1480
1765
|
]
|
|
@@ -1522,70 +1807,96 @@ var idl_default = {
|
|
|
1522
1807
|
fields: [
|
|
1523
1808
|
{
|
|
1524
1809
|
name: "initialized",
|
|
1525
|
-
docs: [
|
|
1810
|
+
docs: [
|
|
1811
|
+
"Indicates if the reward has been initialized"
|
|
1812
|
+
],
|
|
1526
1813
|
type: "u8"
|
|
1527
1814
|
},
|
|
1528
1815
|
{
|
|
1529
1816
|
name: "reward_token_flag",
|
|
1530
|
-
docs: [
|
|
1817
|
+
docs: [
|
|
1818
|
+
"reward token flag"
|
|
1819
|
+
],
|
|
1531
1820
|
type: "u8"
|
|
1532
1821
|
},
|
|
1533
1822
|
{
|
|
1534
1823
|
name: "_padding_0",
|
|
1535
|
-
docs: [
|
|
1824
|
+
docs: [
|
|
1825
|
+
"padding"
|
|
1826
|
+
],
|
|
1536
1827
|
type: {
|
|
1537
|
-
array: [
|
|
1828
|
+
array: [
|
|
1829
|
+
"u8",
|
|
1830
|
+
6
|
|
1831
|
+
]
|
|
1538
1832
|
}
|
|
1539
1833
|
},
|
|
1540
1834
|
{
|
|
1541
|
-
name: "
|
|
1835
|
+
name: "dead_liquidity_reward_checkpoint",
|
|
1542
1836
|
docs: [
|
|
1543
|
-
"
|
|
1837
|
+
"Cumulative dead-liquidity reward (Compounding Pool only)"
|
|
1544
1838
|
],
|
|
1545
|
-
type:
|
|
1546
|
-
array: ["u8", 8]
|
|
1547
|
-
}
|
|
1839
|
+
type: "u64"
|
|
1548
1840
|
},
|
|
1549
1841
|
{
|
|
1550
1842
|
name: "mint",
|
|
1551
|
-
docs: [
|
|
1843
|
+
docs: [
|
|
1844
|
+
"Reward token mint."
|
|
1845
|
+
],
|
|
1552
1846
|
type: "pubkey"
|
|
1553
1847
|
},
|
|
1554
1848
|
{
|
|
1555
1849
|
name: "vault",
|
|
1556
|
-
docs: [
|
|
1850
|
+
docs: [
|
|
1851
|
+
"Reward vault token account."
|
|
1852
|
+
],
|
|
1557
1853
|
type: "pubkey"
|
|
1558
1854
|
},
|
|
1559
1855
|
{
|
|
1560
1856
|
name: "funder",
|
|
1561
|
-
docs: [
|
|
1857
|
+
docs: [
|
|
1858
|
+
"Authority account that allows to fund rewards"
|
|
1859
|
+
],
|
|
1562
1860
|
type: "pubkey"
|
|
1563
1861
|
},
|
|
1564
1862
|
{
|
|
1565
1863
|
name: "reward_duration",
|
|
1566
|
-
docs: [
|
|
1864
|
+
docs: [
|
|
1865
|
+
"reward duration"
|
|
1866
|
+
],
|
|
1567
1867
|
type: "u64"
|
|
1568
1868
|
},
|
|
1569
1869
|
{
|
|
1570
1870
|
name: "reward_duration_end",
|
|
1571
|
-
docs: [
|
|
1871
|
+
docs: [
|
|
1872
|
+
"reward duration end"
|
|
1873
|
+
],
|
|
1572
1874
|
type: "u64"
|
|
1573
1875
|
},
|
|
1574
1876
|
{
|
|
1575
1877
|
name: "reward_rate",
|
|
1576
|
-
docs: [
|
|
1878
|
+
docs: [
|
|
1879
|
+
"reward rate"
|
|
1880
|
+
],
|
|
1577
1881
|
type: "u128"
|
|
1578
1882
|
},
|
|
1579
1883
|
{
|
|
1580
1884
|
name: "reward_per_token_stored",
|
|
1581
|
-
docs: [
|
|
1885
|
+
docs: [
|
|
1886
|
+
"Reward per token stored"
|
|
1887
|
+
],
|
|
1582
1888
|
type: {
|
|
1583
|
-
array: [
|
|
1889
|
+
array: [
|
|
1890
|
+
"u8",
|
|
1891
|
+
32
|
|
1892
|
+
]
|
|
1584
1893
|
}
|
|
1585
1894
|
},
|
|
1586
1895
|
{
|
|
1587
1896
|
name: "last_update_time",
|
|
1588
|
-
docs: [
|
|
1897
|
+
docs: [
|
|
1898
|
+
"The last time reward states were updated."
|
|
1899
|
+
],
|
|
1589
1900
|
type: "u64"
|
|
1590
1901
|
},
|
|
1591
1902
|
{
|
|
@@ -1648,44 +1959,6 @@ var idl_default = {
|
|
|
1648
1959
|
}
|
|
1649
1960
|
],
|
|
1650
1961
|
constants: [
|
|
1651
|
-
{
|
|
1652
|
-
name: "DAMM_V2",
|
|
1653
|
-
type: "pubkey",
|
|
1654
|
-
value: "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
|
|
1655
|
-
},
|
|
1656
|
-
{
|
|
1657
|
-
name: "DAMM_V2_SWAP_DISC",
|
|
1658
|
-
type: {
|
|
1659
|
-
array: ["u8", 8]
|
|
1660
|
-
},
|
|
1661
|
-
value: "[248, 198, 158, 145, 225, 117, 135, 200]"
|
|
1662
|
-
},
|
|
1663
|
-
{
|
|
1664
|
-
name: "DLMM_SWAP2_DISC",
|
|
1665
|
-
type: {
|
|
1666
|
-
array: ["u8", 8]
|
|
1667
|
-
},
|
|
1668
|
-
value: "[65, 75, 63, 76, 235, 91, 91, 136]"
|
|
1669
|
-
},
|
|
1670
|
-
{
|
|
1671
|
-
name: "JUP_V6",
|
|
1672
|
-
type: "pubkey",
|
|
1673
|
-
value: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
|
|
1674
|
-
},
|
|
1675
|
-
{
|
|
1676
|
-
name: "JUP_V6_ROUTE_DISC",
|
|
1677
|
-
type: {
|
|
1678
|
-
array: ["u8", 8]
|
|
1679
|
-
},
|
|
1680
|
-
value: "[229, 23, 203, 151, 122, 227, 173, 42]"
|
|
1681
|
-
},
|
|
1682
|
-
{
|
|
1683
|
-
name: "JUP_V6_SHARED_ACCOUNT_ROUTE_DISC",
|
|
1684
|
-
type: {
|
|
1685
|
-
array: ["u8", 8]
|
|
1686
|
-
},
|
|
1687
|
-
value: "[193, 32, 155, 51, 65, 214, 156, 129]"
|
|
1688
|
-
},
|
|
1689
1962
|
{
|
|
1690
1963
|
name: "MAX_BASIS_POINT",
|
|
1691
1964
|
type: "u16",
|
|
@@ -1700,6 +1973,11 @@ var idl_default = {
|
|
|
1700
1973
|
};
|
|
1701
1974
|
|
|
1702
1975
|
// src/types.ts
|
|
1976
|
+
var JupiterApiVersion = /* @__PURE__ */ ((JupiterApiVersion3) => {
|
|
1977
|
+
JupiterApiVersion3["V1"] = "v1";
|
|
1978
|
+
JupiterApiVersion3["V2"] = "v2";
|
|
1979
|
+
return JupiterApiVersion3;
|
|
1980
|
+
})(JupiterApiVersion || {});
|
|
1703
1981
|
var ZapInDammV2PoolSwapRoute = /* @__PURE__ */ ((ZapInDammV2PoolSwapRoute2) => {
|
|
1704
1982
|
ZapInDammV2PoolSwapRoute2["Jupiter"] = "jupiter";
|
|
1705
1983
|
ZapInDammV2PoolSwapRoute2["DammV2"] = "dammV2";
|
|
@@ -1770,6 +2048,68 @@ var AccountsType = {
|
|
|
1770
2048
|
var DLMM_SWAP_DISCRIMINATOR = [65, 75, 63, 76, 235, 91, 91, 136];
|
|
1771
2049
|
var AMOUNT_IN_DLMM_OFFSET = 8;
|
|
1772
2050
|
var AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
2051
|
+
var JUP_V6_ROUTE_DISCRIMINATOR = [
|
|
2052
|
+
229,
|
|
2053
|
+
23,
|
|
2054
|
+
203,
|
|
2055
|
+
151,
|
|
2056
|
+
122,
|
|
2057
|
+
227,
|
|
2058
|
+
173,
|
|
2059
|
+
42
|
|
2060
|
+
];
|
|
2061
|
+
var JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR = [
|
|
2062
|
+
193,
|
|
2063
|
+
32,
|
|
2064
|
+
155,
|
|
2065
|
+
51,
|
|
2066
|
+
65,
|
|
2067
|
+
214,
|
|
2068
|
+
156,
|
|
2069
|
+
129
|
|
2070
|
+
];
|
|
2071
|
+
var JUP_V6_ROUTE_V2_DISCRIMINATOR = [
|
|
2072
|
+
187,
|
|
2073
|
+
100,
|
|
2074
|
+
250,
|
|
2075
|
+
204,
|
|
2076
|
+
49,
|
|
2077
|
+
196,
|
|
2078
|
+
175,
|
|
2079
|
+
20
|
|
2080
|
+
];
|
|
2081
|
+
var JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR = [
|
|
2082
|
+
209,
|
|
2083
|
+
152,
|
|
2084
|
+
83,
|
|
2085
|
+
147,
|
|
2086
|
+
124,
|
|
2087
|
+
254,
|
|
2088
|
+
216,
|
|
2089
|
+
233
|
|
2090
|
+
];
|
|
2091
|
+
var JUPITER_INSTRUCTION_LAYOUTS = {
|
|
2092
|
+
// route
|
|
2093
|
+
[Buffer.from(JUP_V6_ROUTE_DISCRIMINATOR).toString("hex")]: {
|
|
2094
|
+
amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
|
|
2095
|
+
userTransferAuthorityIndex: 1
|
|
2096
|
+
},
|
|
2097
|
+
// shared_accounts_route
|
|
2098
|
+
[Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR).toString("hex")]: {
|
|
2099
|
+
amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
|
|
2100
|
+
userTransferAuthorityIndex: 2
|
|
2101
|
+
},
|
|
2102
|
+
// route_v2
|
|
2103
|
+
[Buffer.from(JUP_V6_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
|
|
2104
|
+
amountInOffset: () => 8,
|
|
2105
|
+
userTransferAuthorityIndex: 0
|
|
2106
|
+
},
|
|
2107
|
+
// shared_accounts_route_v2
|
|
2108
|
+
[Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
|
|
2109
|
+
amountInOffset: () => 9,
|
|
2110
|
+
userTransferAuthorityIndex: 1
|
|
2111
|
+
}
|
|
2112
|
+
};
|
|
1773
2113
|
var AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
1774
2114
|
var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
1775
2115
|
248,
|
|
@@ -1782,41 +2122,132 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
|
1782
2122
|
200
|
|
1783
2123
|
];
|
|
1784
2124
|
var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
|
|
2125
|
+
var DEFAULT_JUPITER_API_VERSION = "v2" /* V2 */;
|
|
2126
|
+
var DEFAULT_JUPITER_QUOTE_OPTIONS = {
|
|
2127
|
+
dynamicSlippage: false,
|
|
2128
|
+
onlyDirectRoutes: true,
|
|
2129
|
+
restrictIntermediateTokens: true,
|
|
2130
|
+
forJitoBundle: true
|
|
2131
|
+
};
|
|
1785
2132
|
|
|
1786
2133
|
// src/helpers/jupiter.ts
|
|
1787
|
-
function
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1798
|
-
|
|
1799
|
-
|
|
2134
|
+
function resolveJupiterConfig(config = {}) {
|
|
2135
|
+
var _a;
|
|
2136
|
+
return {
|
|
2137
|
+
url: config.jupiterApiUrl || DEFAULT_JUPITER_API_URL,
|
|
2138
|
+
apiKey: config.jupiterApiKey || "",
|
|
2139
|
+
version: (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
function getJupiterInstructionLayout(data) {
|
|
2143
|
+
const discriminator = data.subarray(0, 8).toString("hex");
|
|
2144
|
+
const layout = JUPITER_INSTRUCTION_LAYOUTS[discriminator];
|
|
2145
|
+
if (!layout) {
|
|
2146
|
+
throw new Error(
|
|
2147
|
+
`Unsupported Jupiter instruction discriminator ${discriminator}`
|
|
2148
|
+
);
|
|
2149
|
+
}
|
|
2150
|
+
return layout;
|
|
2151
|
+
}
|
|
2152
|
+
function isJupiterBuildResponse(quoteResponse) {
|
|
2153
|
+
return quoteResponse.swapInstruction !== void 0;
|
|
2154
|
+
}
|
|
2155
|
+
function isJupiterSwapInstructionForUser(swapInstruction, user) {
|
|
2156
|
+
const layout = getJupiterInstructionLayout(
|
|
2157
|
+
Buffer.from(swapInstruction.data, "base64")
|
|
2158
|
+
);
|
|
2159
|
+
const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
|
|
2160
|
+
return authority !== void 0 && new import_web32.PublicKey(authority.pubkey).equals(user);
|
|
2161
|
+
}
|
|
2162
|
+
function jupiterHeaders(apiKey, json) {
|
|
2163
|
+
return __spreadValues(__spreadValues({
|
|
2164
|
+
Accept: "application/json"
|
|
2165
|
+
}, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
|
|
2166
|
+
}
|
|
2167
|
+
function toSearchParams(query) {
|
|
2168
|
+
var _a;
|
|
2169
|
+
const params = new URLSearchParams(__spreadProps(__spreadValues({
|
|
2170
|
+
inputMint: query.inputMint.toString(),
|
|
2171
|
+
outputMint: query.outputMint.toString(),
|
|
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);
|
|
2184
|
+
}
|
|
2185
|
+
return params;
|
|
2186
|
+
}
|
|
2187
|
+
function fetchJupiterQuoteV1(query, config) {
|
|
2188
|
+
return __async(this, null, function* () {
|
|
2189
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2190
|
+
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(query).toString()}`;
|
|
1800
2191
|
try {
|
|
1801
2192
|
const response = yield fetch(url, {
|
|
1802
2193
|
method: "GET",
|
|
1803
|
-
headers:
|
|
1804
|
-
Accept: "application/json"
|
|
1805
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
|
|
2194
|
+
headers: jupiterHeaders(apiKey, false)
|
|
1806
2195
|
});
|
|
1807
2196
|
if (!response.ok) {
|
|
1808
2197
|
return null;
|
|
1809
2198
|
}
|
|
1810
|
-
|
|
1811
|
-
return result;
|
|
2199
|
+
return yield response.json();
|
|
1812
2200
|
} catch (error) {
|
|
1813
2201
|
return null;
|
|
1814
2202
|
}
|
|
1815
2203
|
});
|
|
1816
2204
|
}
|
|
1817
|
-
function
|
|
1818
|
-
return __async(this,
|
|
1819
|
-
const url =
|
|
2205
|
+
function fetchJupiterBuildV2(query, taker, config) {
|
|
2206
|
+
return __async(this, null, function* () {
|
|
2207
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2208
|
+
const params = toSearchParams(query);
|
|
2209
|
+
params.set("taker", taker.toString());
|
|
2210
|
+
const url = `${baseUrl}/swap/v2/build?${params.toString()}`;
|
|
2211
|
+
try {
|
|
2212
|
+
const response = yield fetch(url, {
|
|
2213
|
+
method: "GET",
|
|
2214
|
+
headers: jupiterHeaders(apiKey, false)
|
|
2215
|
+
});
|
|
2216
|
+
if (!response.ok) {
|
|
2217
|
+
return null;
|
|
2218
|
+
}
|
|
2219
|
+
return yield response.json();
|
|
2220
|
+
} catch (error) {
|
|
2221
|
+
return null;
|
|
2222
|
+
}
|
|
2223
|
+
});
|
|
2224
|
+
}
|
|
2225
|
+
function getJupiterQuote(_0) {
|
|
2226
|
+
return __async(this, arguments, function* (params, config = {}) {
|
|
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
|
+
};
|
|
2240
|
+
const { version } = resolveJupiterConfig(config);
|
|
2241
|
+
if (version === "v1" /* V1 */) {
|
|
2242
|
+
return fetchJupiterQuoteV1(query, config);
|
|
2243
|
+
}
|
|
2244
|
+
return fetchJupiterBuildV2(query, params.user, config);
|
|
2245
|
+
});
|
|
2246
|
+
}
|
|
2247
|
+
function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
2248
|
+
return __async(this, null, function* () {
|
|
2249
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2250
|
+
const url = `${baseUrl}/swap/v1/swap-instructions`;
|
|
1820
2251
|
const requestBody = {
|
|
1821
2252
|
userPublicKey: userPublicKey.toString(),
|
|
1822
2253
|
quoteResponse
|
|
@@ -1825,10 +2256,7 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1825
2256
|
try {
|
|
1826
2257
|
response = yield fetch(url, {
|
|
1827
2258
|
method: "POST",
|
|
1828
|
-
headers:
|
|
1829
|
-
"Content-Type": "application/json",
|
|
1830
|
-
Accept: "application/json"
|
|
1831
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
|
|
2259
|
+
headers: jupiterHeaders(apiKey, true),
|
|
1832
2260
|
body: JSON.stringify(requestBody)
|
|
1833
2261
|
});
|
|
1834
2262
|
if (!response.ok) {
|
|
@@ -1840,21 +2268,111 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1840
2268
|
} catch (error) {
|
|
1841
2269
|
throw new Error(`Jupiter swap instruction failed to fetch`);
|
|
1842
2270
|
}
|
|
1843
|
-
|
|
1844
|
-
|
|
2271
|
+
return yield response.json();
|
|
2272
|
+
});
|
|
2273
|
+
}
|
|
2274
|
+
function getJupiterSwapInstruction(_0, _1) {
|
|
2275
|
+
return __async(this, arguments, function* (userPublicKey, quoteResponse, config = {}) {
|
|
2276
|
+
const { version } = resolveJupiterConfig(config);
|
|
2277
|
+
if (version === "v1" /* V1 */) {
|
|
2278
|
+
return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
|
|
2279
|
+
}
|
|
2280
|
+
if (!isJupiterBuildResponse(quoteResponse)) {
|
|
2281
|
+
throw new Error(
|
|
2282
|
+
"Jupiter quote has no swap instructions, get the quote with getJupiterQuote under Jupiter API v2"
|
|
2283
|
+
);
|
|
2284
|
+
}
|
|
2285
|
+
if (!isJupiterSwapInstructionForUser(
|
|
2286
|
+
quoteResponse.swapInstruction,
|
|
2287
|
+
userPublicKey
|
|
2288
|
+
)) {
|
|
2289
|
+
throw new Error(
|
|
2290
|
+
`Jupiter quote swap instructions are not built for ${userPublicKey.toBase58()}`
|
|
2291
|
+
);
|
|
2292
|
+
}
|
|
2293
|
+
return quoteResponse;
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
function isQuoteMatchesSwap(quoteResponse, user, amount) {
|
|
2297
|
+
if (quoteResponse.inAmount !== amount.toString()) {
|
|
2298
|
+
return false;
|
|
2299
|
+
}
|
|
2300
|
+
if (isJupiterBuildResponse(quoteResponse)) {
|
|
2301
|
+
return isJupiterSwapInstructionForUser(quoteResponse.swapInstruction, user);
|
|
2302
|
+
}
|
|
2303
|
+
return true;
|
|
2304
|
+
}
|
|
2305
|
+
var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
|
|
2306
|
+
function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
|
|
2307
|
+
return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
|
|
2308
|
+
([key, addresses]) => new import_web32.AddressLookupTableAccount({
|
|
2309
|
+
key: new import_web32.PublicKey(key),
|
|
2310
|
+
state: {
|
|
2311
|
+
addresses: addresses.map((address) => new import_web32.PublicKey(address)),
|
|
2312
|
+
deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
|
|
2313
|
+
lastExtendedSlot: 0,
|
|
2314
|
+
lastExtendedSlotStartIndex: 0
|
|
2315
|
+
}
|
|
2316
|
+
})
|
|
2317
|
+
);
|
|
2318
|
+
}
|
|
2319
|
+
function fetchAddressLookupTableAccounts(connection, addresses) {
|
|
2320
|
+
return __async(this, null, function* () {
|
|
2321
|
+
if (addresses.length === 0) {
|
|
2322
|
+
return [];
|
|
2323
|
+
}
|
|
2324
|
+
const keys = addresses.map((address) => new import_web32.PublicKey(address));
|
|
2325
|
+
const accounts = yield connection.getMultipleAccountsInfo(keys);
|
|
2326
|
+
return keys.map((key, i) => {
|
|
2327
|
+
const account = accounts[i];
|
|
2328
|
+
if (!account || !account.owner.equals(import_web32.AddressLookupTableProgram.programId)) {
|
|
2329
|
+
throw new Error(`Address lookup table not found: ${key.toBase58()}`);
|
|
2330
|
+
}
|
|
2331
|
+
return new import_web32.AddressLookupTableAccount({
|
|
2332
|
+
key,
|
|
2333
|
+
state: import_web32.AddressLookupTableAccount.deserialize(account.data)
|
|
2334
|
+
});
|
|
2335
|
+
});
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
function mergeAddressLookupTableAccounts(...lists) {
|
|
2339
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2340
|
+
for (const table of lists.flat()) {
|
|
2341
|
+
const key = table.key.toBase58();
|
|
2342
|
+
if (!merged.has(key)) {
|
|
2343
|
+
merged.set(key, table);
|
|
2344
|
+
}
|
|
2345
|
+
}
|
|
2346
|
+
return [...merged.values()];
|
|
2347
|
+
}
|
|
2348
|
+
function getJupiterAddressLookupTableAccounts(connection, response) {
|
|
2349
|
+
return __async(this, null, function* () {
|
|
2350
|
+
var _a;
|
|
2351
|
+
if (response.addressesByLookupTableAddress) {
|
|
2352
|
+
return toAddressLookupTableAccounts(response.addressesByLookupTableAddress);
|
|
2353
|
+
}
|
|
2354
|
+
return fetchAddressLookupTableAccounts(
|
|
2355
|
+
connection,
|
|
2356
|
+
(_a = response.addressLookupTableAddresses) != null ? _a : []
|
|
2357
|
+
);
|
|
1845
2358
|
});
|
|
1846
2359
|
}
|
|
1847
|
-
function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
1848
|
-
return __async(this, arguments, function* (user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
|
|
2360
|
+
function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
2361
|
+
return __async(this, arguments, function* (connection, user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}, jupiterQuoteOptions = {}) {
|
|
2362
|
+
if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
|
|
2363
|
+
throw new Error(
|
|
2364
|
+
`Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
|
|
2365
|
+
);
|
|
2366
|
+
}
|
|
1849
2367
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
2368
|
+
__spreadValues({
|
|
2369
|
+
inputMint,
|
|
2370
|
+
outputMint,
|
|
2371
|
+
amount,
|
|
2372
|
+
user,
|
|
2373
|
+
maxAccounts,
|
|
2374
|
+
slippageBps
|
|
2375
|
+
}, jupiterQuoteOptions),
|
|
1858
2376
|
config
|
|
1859
2377
|
);
|
|
1860
2378
|
if (!quoteResponse) {
|
|
@@ -1878,7 +2396,11 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1878
2396
|
programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
|
|
1879
2397
|
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1880
2398
|
});
|
|
1881
|
-
|
|
2399
|
+
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2400
|
+
connection,
|
|
2401
|
+
swapInstructionResponse
|
|
2402
|
+
);
|
|
2403
|
+
return { instruction, addressLookupTableAccounts, quoteResponse };
|
|
1882
2404
|
});
|
|
1883
2405
|
}
|
|
1884
2406
|
|
|
@@ -2047,11 +2569,16 @@ function convertLamportsToUiAmount(amount, decimals) {
|
|
|
2047
2569
|
function convertUiAmountToLamports(amount, decimals) {
|
|
2048
2570
|
return amount.mul(import_decimal.default.pow(10, decimals));
|
|
2049
2571
|
}
|
|
2572
|
+
function filterOutComputeBudgetInstructions(instructions) {
|
|
2573
|
+
return instructions.filter(
|
|
2574
|
+
(ix) => !ix.programId.equals(import_web34.ComputeBudgetProgram.programId)
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2050
2577
|
|
|
2051
2578
|
// src/helpers/token.ts
|
|
2052
2579
|
var import_spl_token3 = require("@solana/spl-token");
|
|
2053
2580
|
var import_web35 = require("@solana/web3.js");
|
|
2054
|
-
var getOrCreateATAInstruction = (
|
|
2581
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2055
2582
|
const toAccount = (0, import_spl_token3.getAssociatedTokenAddressSync)(
|
|
2056
2583
|
tokenMint,
|
|
2057
2584
|
owner,
|
|
@@ -2487,8 +3014,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2487
3014
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2488
3015
|
return new import_bn3.default(estimatedOutput.floor().toString());
|
|
2489
3016
|
}
|
|
2490
|
-
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
2491
|
-
return __async(this, arguments, function* (dlmm, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}) {
|
|
3017
|
+
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
3018
|
+
return __async(this, arguments, function* (dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}, jupiterQuoteOptions = {}) {
|
|
2492
3019
|
let dlmmQuoteResult = null;
|
|
2493
3020
|
try {
|
|
2494
3021
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2501,14 +3028,14 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
2501
3028
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
2502
3029
|
}
|
|
2503
3030
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
2504
|
-
|
|
2505
|
-
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
3031
|
+
__spreadValues({
|
|
3032
|
+
inputMint: inMint,
|
|
3033
|
+
outputMint: outMint,
|
|
3034
|
+
amount: inAmount,
|
|
3035
|
+
user,
|
|
3036
|
+
maxAccounts: 50,
|
|
3037
|
+
slippageBps: swapSlippageBps
|
|
3038
|
+
}, jupiterQuoteOptions),
|
|
2512
3039
|
config
|
|
2513
3040
|
);
|
|
2514
3041
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -2624,6 +3151,7 @@ function binarySearchRefineDirectSwapAmount(dlmm, initialActiveBin, initialMinBi
|
|
|
2624
3151
|
}
|
|
2625
3152
|
function estimateDlmmIndirectSwap(_0) {
|
|
2626
3153
|
return __async(this, arguments, function* ({
|
|
3154
|
+
user,
|
|
2627
3155
|
amountIn,
|
|
2628
3156
|
inputTokenMint,
|
|
2629
3157
|
lbPair,
|
|
@@ -2633,6 +3161,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2633
3161
|
maxDeltaId,
|
|
2634
3162
|
strategy,
|
|
2635
3163
|
singleSided,
|
|
3164
|
+
jupiterQuoteOptions,
|
|
2636
3165
|
config = {}
|
|
2637
3166
|
}) {
|
|
2638
3167
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
@@ -2657,14 +3186,14 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2657
3186
|
const singleSidedX = singleSided === 0 /* X */;
|
|
2658
3187
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
2659
3188
|
const quote = yield getJupiterQuote(
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
3189
|
+
__spreadValues({
|
|
3190
|
+
inputMint: inputTokenMint,
|
|
3191
|
+
outputMint: outputTokenMint,
|
|
3192
|
+
amount: amountIn,
|
|
3193
|
+
user,
|
|
3194
|
+
maxAccounts: 50,
|
|
3195
|
+
slippageBps: swapSlippageBps
|
|
3196
|
+
}, jupiterQuoteOptions),
|
|
2668
3197
|
config
|
|
2669
3198
|
);
|
|
2670
3199
|
if (!quote) {
|
|
@@ -2687,25 +3216,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2687
3216
|
const halfAmount = amountIn.div(new import_bn3.default(2));
|
|
2688
3217
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
2689
3218
|
getJupiterQuote(
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
3219
|
+
__spreadValues({
|
|
3220
|
+
inputMint: inputTokenMint,
|
|
3221
|
+
outputMint: tokenXMint,
|
|
3222
|
+
amount: halfAmount,
|
|
3223
|
+
user,
|
|
3224
|
+
maxAccounts: 50,
|
|
3225
|
+
slippageBps: swapSlippageBps
|
|
3226
|
+
}, jupiterQuoteOptions),
|
|
2698
3227
|
config
|
|
2699
3228
|
),
|
|
2700
3229
|
getJupiterQuote(
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
3230
|
+
__spreadValues({
|
|
3231
|
+
inputMint: inputTokenMint,
|
|
3232
|
+
outputMint: tokenYMint,
|
|
3233
|
+
amount: halfAmount,
|
|
3234
|
+
user,
|
|
3235
|
+
maxAccounts: 50,
|
|
3236
|
+
slippageBps: swapSlippageBps
|
|
3237
|
+
}, jupiterQuoteOptions),
|
|
2709
3238
|
config
|
|
2710
3239
|
)
|
|
2711
3240
|
]);
|
|
@@ -2801,25 +3330,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2801
3330
|
}
|
|
2802
3331
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
2803
3332
|
getJupiterQuote(
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
3333
|
+
__spreadValues({
|
|
3334
|
+
inputMint: inputTokenMint,
|
|
3335
|
+
outputMint: tokenXMint,
|
|
3336
|
+
amount: bestAmountToX,
|
|
3337
|
+
user,
|
|
3338
|
+
maxAccounts: 50,
|
|
3339
|
+
slippageBps: swapSlippageBps
|
|
3340
|
+
}, jupiterQuoteOptions),
|
|
2812
3341
|
config
|
|
2813
3342
|
),
|
|
2814
3343
|
getJupiterQuote(
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
3344
|
+
__spreadValues({
|
|
3345
|
+
inputMint: inputTokenMint,
|
|
3346
|
+
outputMint: tokenYMint,
|
|
3347
|
+
amount: bestAmountToY,
|
|
3348
|
+
user,
|
|
3349
|
+
maxAccounts: 50,
|
|
3350
|
+
slippageBps: swapSlippageBps
|
|
3351
|
+
}, jupiterQuoteOptions),
|
|
2823
3352
|
config
|
|
2824
3353
|
)
|
|
2825
3354
|
]);
|
|
@@ -2855,6 +3384,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2855
3384
|
}
|
|
2856
3385
|
function estimateDlmmDirectSwapCore(_0) {
|
|
2857
3386
|
return __async(this, arguments, function* ({
|
|
3387
|
+
user,
|
|
2858
3388
|
tokenXAmount,
|
|
2859
3389
|
tokenYAmount,
|
|
2860
3390
|
dlmm,
|
|
@@ -2863,6 +3393,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2863
3393
|
maxDeltaId,
|
|
2864
3394
|
strategy,
|
|
2865
3395
|
singleSided,
|
|
3396
|
+
jupiterQuoteOptions,
|
|
2866
3397
|
config = {}
|
|
2867
3398
|
}) {
|
|
2868
3399
|
if (singleSided !== void 0) {
|
|
@@ -2875,13 +3406,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2875
3406
|
);
|
|
2876
3407
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2877
3408
|
dlmm,
|
|
3409
|
+
user,
|
|
2878
3410
|
dlmm.lbPair.tokenYMint,
|
|
2879
3411
|
dlmm.lbPair.tokenXMint,
|
|
2880
3412
|
tokenYAmount,
|
|
2881
3413
|
swapSlippageBps,
|
|
2882
3414
|
swapForY2,
|
|
2883
3415
|
binArrayForSwap2,
|
|
2884
|
-
config
|
|
3416
|
+
config,
|
|
3417
|
+
jupiterQuoteOptions
|
|
2885
3418
|
);
|
|
2886
3419
|
if (!quote) {
|
|
2887
3420
|
throw new Error(
|
|
@@ -2904,13 +3437,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2904
3437
|
);
|
|
2905
3438
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2906
3439
|
dlmm,
|
|
3440
|
+
user,
|
|
2907
3441
|
dlmm.lbPair.tokenXMint,
|
|
2908
3442
|
dlmm.lbPair.tokenYMint,
|
|
2909
3443
|
tokenXAmount,
|
|
2910
3444
|
swapSlippageBps,
|
|
2911
3445
|
swapForY2,
|
|
2912
3446
|
binArrayForSwap2,
|
|
2913
|
-
config
|
|
3447
|
+
config,
|
|
3448
|
+
jupiterQuoteOptions
|
|
2914
3449
|
);
|
|
2915
3450
|
if (!quote) {
|
|
2916
3451
|
throw new Error(
|
|
@@ -2999,13 +3534,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2999
3534
|
);
|
|
3000
3535
|
const initialQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3001
3536
|
dlmm,
|
|
3537
|
+
user,
|
|
3002
3538
|
inMint,
|
|
3003
3539
|
outMint,
|
|
3004
3540
|
initialSwapAmount,
|
|
3005
3541
|
swapSlippageBps,
|
|
3006
3542
|
swapForY,
|
|
3007
3543
|
binArrayForSwap,
|
|
3008
|
-
config
|
|
3544
|
+
config,
|
|
3545
|
+
jupiterQuoteOptions
|
|
3009
3546
|
);
|
|
3010
3547
|
if (!initialQuote) {
|
|
3011
3548
|
throw new Error(
|
|
@@ -3057,13 +3594,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3057
3594
|
);
|
|
3058
3595
|
const finalQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3059
3596
|
dlmm,
|
|
3597
|
+
user,
|
|
3060
3598
|
inMint,
|
|
3061
3599
|
outMint,
|
|
3062
3600
|
refinedAmount,
|
|
3063
3601
|
swapSlippageBps,
|
|
3064
3602
|
swapForY,
|
|
3065
3603
|
binArrayForSwap,
|
|
3066
|
-
config
|
|
3604
|
+
config,
|
|
3605
|
+
jupiterQuoteOptions
|
|
3067
3606
|
);
|
|
3068
3607
|
if (!finalQuote) {
|
|
3069
3608
|
return {
|
|
@@ -3089,6 +3628,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3089
3628
|
}
|
|
3090
3629
|
function estimateDlmmDirectSwap(_0) {
|
|
3091
3630
|
return __async(this, arguments, function* ({
|
|
3631
|
+
user,
|
|
3092
3632
|
amountIn,
|
|
3093
3633
|
inputTokenMint,
|
|
3094
3634
|
lbPair,
|
|
@@ -3098,6 +3638,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3098
3638
|
maxDeltaId,
|
|
3099
3639
|
strategy,
|
|
3100
3640
|
singleSided,
|
|
3641
|
+
jupiterQuoteOptions,
|
|
3101
3642
|
config = {}
|
|
3102
3643
|
}) {
|
|
3103
3644
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
@@ -3109,6 +3650,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3109
3650
|
const tokenXAmount = isInputTokenX ? amountIn : new import_bn3.default(0);
|
|
3110
3651
|
const tokenYAmount = isInputTokenX ? new import_bn3.default(0) : amountIn;
|
|
3111
3652
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3653
|
+
user,
|
|
3112
3654
|
tokenXAmount,
|
|
3113
3655
|
tokenYAmount,
|
|
3114
3656
|
dlmm,
|
|
@@ -3117,6 +3659,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3117
3659
|
maxDeltaId,
|
|
3118
3660
|
strategy,
|
|
3119
3661
|
singleSided,
|
|
3662
|
+
jupiterQuoteOptions,
|
|
3120
3663
|
config
|
|
3121
3664
|
});
|
|
3122
3665
|
return {
|
|
@@ -3136,6 +3679,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3136
3679
|
}
|
|
3137
3680
|
function estimateDlmmRebalanceSwap(_0) {
|
|
3138
3681
|
return __async(this, arguments, function* ({
|
|
3682
|
+
user,
|
|
3139
3683
|
lbPair,
|
|
3140
3684
|
position,
|
|
3141
3685
|
connection,
|
|
@@ -3143,11 +3687,13 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3143
3687
|
minDeltaId,
|
|
3144
3688
|
maxDeltaId,
|
|
3145
3689
|
strategy,
|
|
3690
|
+
jupiterQuoteOptions,
|
|
3146
3691
|
config = {}
|
|
3147
3692
|
}) {
|
|
3148
3693
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3149
3694
|
const userPosition = yield dlmm.getPosition(position);
|
|
3150
3695
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3696
|
+
user,
|
|
3151
3697
|
tokenXAmount: new import_bn3.default(userPosition.positionData.totalXAmount),
|
|
3152
3698
|
tokenYAmount: new import_bn3.default(userPosition.positionData.totalYAmount),
|
|
3153
3699
|
dlmm,
|
|
@@ -3157,6 +3703,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3157
3703
|
strategy,
|
|
3158
3704
|
singleSided: void 0,
|
|
3159
3705
|
// rebalance does not use single-sided deposits
|
|
3706
|
+
jupiterQuoteOptions,
|
|
3160
3707
|
config
|
|
3161
3708
|
});
|
|
3162
3709
|
return {
|
|
@@ -3224,13 +3771,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
|
|
|
3224
3771
|
var Zap = class {
|
|
3225
3772
|
/**
|
|
3226
3773
|
* @param connection - The connection to the Solana cluster
|
|
3227
|
-
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag)
|
|
3774
|
+
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
|
|
3228
3775
|
*/
|
|
3229
3776
|
constructor(connection, config = {}) {
|
|
3777
|
+
var _a;
|
|
3230
3778
|
this.connection = connection;
|
|
3231
|
-
this.zapProgram = new
|
|
3779
|
+
this.zapProgram = new import_core.Program(idl_default, { connection });
|
|
3232
3780
|
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3233
3781
|
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3782
|
+
this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3234
3783
|
}
|
|
3235
3784
|
/////// PRIVATE FUNDTIONS //////
|
|
3236
3785
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3239,7 +3788,7 @@ var Zap = class {
|
|
|
3239
3788
|
ledger: deriveLedgerAccount(owner),
|
|
3240
3789
|
owner,
|
|
3241
3790
|
payer
|
|
3242
|
-
}).
|
|
3791
|
+
}).instruction();
|
|
3243
3792
|
});
|
|
3244
3793
|
}
|
|
3245
3794
|
closeLedgerAccount(owner, rentReceiver) {
|
|
@@ -3248,7 +3797,7 @@ var Zap = class {
|
|
|
3248
3797
|
ledger: deriveLedgerAccount(owner),
|
|
3249
3798
|
owner,
|
|
3250
3799
|
rentReceiver
|
|
3251
|
-
}).
|
|
3800
|
+
}).instruction();
|
|
3252
3801
|
});
|
|
3253
3802
|
}
|
|
3254
3803
|
setLedgerBalance(owner, amount, isTokenA) {
|
|
@@ -3256,7 +3805,7 @@ var Zap = class {
|
|
|
3256
3805
|
return yield this.zapProgram.methods.setLedgerBalance(amount, isTokenA).accountsPartial({
|
|
3257
3806
|
ledger: deriveLedgerAccount(owner),
|
|
3258
3807
|
owner
|
|
3259
|
-
}).
|
|
3808
|
+
}).instruction();
|
|
3260
3809
|
});
|
|
3261
3810
|
}
|
|
3262
3811
|
updateLedgerBalanceAfterSwap(owner, tokenAccount, preSourceTokenAccount, maxTransferAmount, isTokenA) {
|
|
@@ -3269,7 +3818,7 @@ var Zap = class {
|
|
|
3269
3818
|
ledger: deriveLedgerAccount(owner),
|
|
3270
3819
|
tokenAccount,
|
|
3271
3820
|
owner
|
|
3272
|
-
}).
|
|
3821
|
+
}).instruction();
|
|
3273
3822
|
});
|
|
3274
3823
|
}
|
|
3275
3824
|
zapInDammV2(params) {
|
|
@@ -3307,7 +3856,7 @@ var Zap = class {
|
|
|
3307
3856
|
tokenBProgram,
|
|
3308
3857
|
dammProgram: DAMM_V2_PROGRAM_ID,
|
|
3309
3858
|
dammEventAuthority: deriveDammV2EventAuthority()
|
|
3310
|
-
}).
|
|
3859
|
+
}).instruction();
|
|
3311
3860
|
});
|
|
3312
3861
|
}
|
|
3313
3862
|
resetOrInitializeLedgerAccount(user) {
|
|
@@ -3317,9 +3866,9 @@ var Zap = class {
|
|
|
3317
3866
|
if (accountInfo) {
|
|
3318
3867
|
const closeLedger = yield this.closeLedgerAccount(user, user);
|
|
3319
3868
|
const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
|
|
3320
|
-
return
|
|
3869
|
+
return [closeLedger, reInitializeLedger];
|
|
3321
3870
|
}
|
|
3322
|
-
return yield this.initializeLedgerAccount(user, user);
|
|
3871
|
+
return [yield this.initializeLedgerAccount(user, user)];
|
|
3323
3872
|
});
|
|
3324
3873
|
}
|
|
3325
3874
|
zapInDlmmForInitializedPosition(params) {
|
|
@@ -3386,7 +3935,7 @@ var Zap = class {
|
|
|
3386
3935
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3387
3936
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3388
3937
|
systemProgram: import_web38.SystemProgram.programId
|
|
3389
|
-
}).remainingAccounts(binArrays).
|
|
3938
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3390
3939
|
});
|
|
3391
3940
|
}
|
|
3392
3941
|
zapInDlmmForUninitializedPosition(params) {
|
|
@@ -3450,7 +3999,7 @@ var Zap = class {
|
|
|
3450
3999
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3451
4000
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3452
4001
|
systemProgram: import_web38.SystemProgram.programId
|
|
3453
|
-
}).remainingAccounts(binArrays).
|
|
4002
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3454
4003
|
});
|
|
3455
4004
|
}
|
|
3456
4005
|
//#region Zap In
|
|
@@ -3470,6 +4019,7 @@ var Zap = class {
|
|
|
3470
4019
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3471
4020
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3472
4021
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4022
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
|
|
3473
4023
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
3474
4024
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3475
4025
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -3488,7 +4038,8 @@ var Zap = class {
|
|
|
3488
4038
|
slippageBps,
|
|
3489
4039
|
dammV2Quote,
|
|
3490
4040
|
jupiterQuote,
|
|
3491
|
-
maxTransferAmountExtendPercentage
|
|
4041
|
+
maxTransferAmountExtendPercentage,
|
|
4042
|
+
jupiterQuoteOptions
|
|
3492
4043
|
} = params;
|
|
3493
4044
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3494
4045
|
const {
|
|
@@ -3508,7 +4059,7 @@ var Zap = class {
|
|
|
3508
4059
|
const tokenAProgram = (0, import_cp_amm_sdk3.getTokenProgram)(tokenAFlag);
|
|
3509
4060
|
const tokenBProgram = (0, import_cp_amm_sdk3.getTokenProgram)(tokenBFlag);
|
|
3510
4061
|
const preInstructions = [];
|
|
3511
|
-
if (
|
|
4062
|
+
if (inputTokenMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
3512
4063
|
const { ataPubkey: userWrapSolAcc, ix: initializeUserWrapSOLAta } = yield getOrCreateATAInstruction(
|
|
3513
4064
|
this.connection,
|
|
3514
4065
|
import_spl_token6.NATIVE_MINT,
|
|
@@ -3560,20 +4111,22 @@ var Zap = class {
|
|
|
3560
4111
|
const singleSidedA = isSingleSidedA(poolState);
|
|
3561
4112
|
const singleSidedB = isSingleSidedB(poolState);
|
|
3562
4113
|
let amount;
|
|
3563
|
-
let
|
|
4114
|
+
let swapInstructions = [];
|
|
4115
|
+
let addressLookupTableAccounts = [];
|
|
3564
4116
|
let maxTransferAmount;
|
|
3565
4117
|
let swapInAmount;
|
|
3566
4118
|
let swapRoute;
|
|
3567
4119
|
if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
|
|
3568
4120
|
amount = amountIn;
|
|
3569
|
-
swapInAmount = new
|
|
3570
|
-
maxTransferAmount = new
|
|
4121
|
+
swapInAmount = new import_core.BN(0);
|
|
4122
|
+
maxTransferAmount = new import_core.BN(0);
|
|
3571
4123
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3572
4124
|
} else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
|
|
3573
|
-
if (jupiterQuote !== null && (dammV2Quote === null || new
|
|
4125
|
+
if (jupiterQuote !== null && (dammV2Quote === null || new import_core.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3574
4126
|
swapInAmount = amountIn;
|
|
3575
|
-
amount = new
|
|
4127
|
+
amount = new import_core.BN(0);
|
|
3576
4128
|
const result = yield buildJupiterSwapTransaction(
|
|
4129
|
+
this.connection,
|
|
3577
4130
|
user,
|
|
3578
4131
|
inputTokenMint,
|
|
3579
4132
|
outputTokenMint,
|
|
@@ -3583,26 +4136,29 @@ var Zap = class {
|
|
|
3583
4136
|
void 0,
|
|
3584
4137
|
{
|
|
3585
4138
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3586
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3587
|
-
|
|
4139
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4140
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4141
|
+
},
|
|
4142
|
+
jupiterQuoteOptions
|
|
3588
4143
|
);
|
|
3589
|
-
|
|
4144
|
+
swapInstructions = [result.instruction];
|
|
4145
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3590
4146
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3591
4147
|
result.quoteResponse.outAmount,
|
|
3592
4148
|
maxTransferAmountExtendPercentage
|
|
3593
4149
|
);
|
|
3594
4150
|
swapRoute = "jupiter" /* Jupiter */;
|
|
3595
4151
|
} else if (dammV2Quote !== null) {
|
|
3596
|
-
swapInAmount = new
|
|
4152
|
+
swapInAmount = new import_core.BN(0);
|
|
3597
4153
|
amount = amountIn;
|
|
3598
|
-
maxTransferAmount = new
|
|
4154
|
+
maxTransferAmount = new import_core.BN(0);
|
|
3599
4155
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3600
4156
|
} else {
|
|
3601
4157
|
throw new Error(
|
|
3602
4158
|
"No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
|
|
3603
4159
|
);
|
|
3604
4160
|
}
|
|
3605
|
-
} else if (jupiterQuote !== null && (dammV2Quote === null || new
|
|
4161
|
+
} else if (jupiterQuote !== null && (dammV2Quote === null || new import_core.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3606
4162
|
const price = convertLamportsToUiAmount(
|
|
3607
4163
|
new import_decimal4.default(jupiterQuote.outAmount),
|
|
3608
4164
|
isInputTokenA ? tokenBDecimal : tokenADecimal
|
|
@@ -3623,6 +4179,7 @@ var Zap = class {
|
|
|
3623
4179
|
);
|
|
3624
4180
|
amount = amountIn.sub(swapInAmount);
|
|
3625
4181
|
const result = yield buildJupiterSwapTransaction(
|
|
4182
|
+
this.connection,
|
|
3626
4183
|
user,
|
|
3627
4184
|
inputTokenMint,
|
|
3628
4185
|
outputTokenMint,
|
|
@@ -3632,10 +4189,13 @@ var Zap = class {
|
|
|
3632
4189
|
void 0,
|
|
3633
4190
|
{
|
|
3634
4191
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3635
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3636
|
-
|
|
4192
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4193
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4194
|
+
},
|
|
4195
|
+
jupiterQuoteOptions
|
|
3637
4196
|
);
|
|
3638
|
-
|
|
4197
|
+
swapInstructions = [result.instruction];
|
|
4198
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3639
4199
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3640
4200
|
result.quoteResponse.outAmount,
|
|
3641
4201
|
maxTransferAmountExtendPercentage
|
|
@@ -3693,7 +4253,8 @@ var Zap = class {
|
|
|
3693
4253
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3694
4254
|
maxSqrtPriceChangeBps,
|
|
3695
4255
|
preInstructions,
|
|
3696
|
-
|
|
4256
|
+
swapInstructions,
|
|
4257
|
+
addressLookupTableAccounts,
|
|
3697
4258
|
cleanUpInstructions,
|
|
3698
4259
|
swapInEstimate: {
|
|
3699
4260
|
inAmount: swapInAmount,
|
|
@@ -3718,6 +4279,7 @@ var Zap = class {
|
|
|
3718
4279
|
* @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)
|
|
3719
4280
|
* @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)
|
|
3720
4281
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4282
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
|
|
3721
4283
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
3722
4284
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3723
4285
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -3736,7 +4298,8 @@ var Zap = class {
|
|
|
3736
4298
|
maxTransferAmountExtendPercentage,
|
|
3737
4299
|
slippageBps,
|
|
3738
4300
|
jupiterQuoteToA,
|
|
3739
|
-
jupiterQuoteToB
|
|
4301
|
+
jupiterQuoteToB,
|
|
4302
|
+
jupiterQuoteOptions
|
|
3740
4303
|
} = params;
|
|
3741
4304
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3742
4305
|
const {
|
|
@@ -3821,6 +4384,7 @@ var Zap = class {
|
|
|
3821
4384
|
);
|
|
3822
4385
|
}
|
|
3823
4386
|
const result = yield buildJupiterSwapTransaction(
|
|
4387
|
+
this.connection,
|
|
3824
4388
|
user,
|
|
3825
4389
|
inputTokenMint,
|
|
3826
4390
|
tokenAMint,
|
|
@@ -3830,8 +4394,10 @@ var Zap = class {
|
|
|
3830
4394
|
void 0,
|
|
3831
4395
|
{
|
|
3832
4396
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3833
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3834
|
-
|
|
4397
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4398
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4399
|
+
},
|
|
4400
|
+
jupiterQuoteOptions
|
|
3835
4401
|
);
|
|
3836
4402
|
return {
|
|
3837
4403
|
user,
|
|
@@ -3839,7 +4405,7 @@ var Zap = class {
|
|
|
3839
4405
|
position,
|
|
3840
4406
|
positionNftAccount,
|
|
3841
4407
|
maxSqrtPriceChangeBps,
|
|
3842
|
-
amount: new
|
|
4408
|
+
amount: new import_core.BN(0),
|
|
3843
4409
|
isDirectPool: false,
|
|
3844
4410
|
tokenAMint,
|
|
3845
4411
|
tokenBMint,
|
|
@@ -3852,14 +4418,15 @@ var Zap = class {
|
|
|
3852
4418
|
maxTransferAmountExtendPercentage
|
|
3853
4419
|
),
|
|
3854
4420
|
swapType: 0 /* swapToA */,
|
|
3855
|
-
maxTransferAmountB: new
|
|
4421
|
+
maxTransferAmountB: new import_core.BN(0),
|
|
3856
4422
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3857
4423
|
preInstructions,
|
|
3858
|
-
|
|
4424
|
+
swapInstructions: [result.instruction],
|
|
4425
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3859
4426
|
cleanUpInstructions,
|
|
3860
4427
|
swapInEstimate: {
|
|
3861
4428
|
inAmountA: amountIn,
|
|
3862
|
-
inAmountB: new
|
|
4429
|
+
inAmountB: new import_core.BN(0),
|
|
3863
4430
|
routeA: "jupiter" /* Jupiter */,
|
|
3864
4431
|
routeB: "dammV2" /* DammV2 */
|
|
3865
4432
|
}
|
|
@@ -3872,6 +4439,7 @@ var Zap = class {
|
|
|
3872
4439
|
);
|
|
3873
4440
|
}
|
|
3874
4441
|
const result = yield buildJupiterSwapTransaction(
|
|
4442
|
+
this.connection,
|
|
3875
4443
|
user,
|
|
3876
4444
|
inputTokenMint,
|
|
3877
4445
|
tokenBMint,
|
|
@@ -3881,8 +4449,10 @@ var Zap = class {
|
|
|
3881
4449
|
void 0,
|
|
3882
4450
|
{
|
|
3883
4451
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3884
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3885
|
-
|
|
4452
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4453
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4454
|
+
},
|
|
4455
|
+
jupiterQuoteOptions
|
|
3886
4456
|
);
|
|
3887
4457
|
return {
|
|
3888
4458
|
user,
|
|
@@ -3890,7 +4460,7 @@ var Zap = class {
|
|
|
3890
4460
|
position,
|
|
3891
4461
|
positionNftAccount,
|
|
3892
4462
|
maxSqrtPriceChangeBps,
|
|
3893
|
-
amount: new
|
|
4463
|
+
amount: new import_core.BN(0),
|
|
3894
4464
|
isDirectPool: false,
|
|
3895
4465
|
tokenAMint,
|
|
3896
4466
|
tokenBMint,
|
|
@@ -3898,7 +4468,7 @@ var Zap = class {
|
|
|
3898
4468
|
tokenBVault,
|
|
3899
4469
|
tokenAProgram,
|
|
3900
4470
|
tokenBProgram,
|
|
3901
|
-
maxTransferAmountA: new
|
|
4471
|
+
maxTransferAmountA: new import_core.BN(0),
|
|
3902
4472
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3903
4473
|
result.quoteResponse.outAmount,
|
|
3904
4474
|
maxTransferAmountExtendPercentage
|
|
@@ -3906,10 +4476,11 @@ var Zap = class {
|
|
|
3906
4476
|
swapType: 1 /* swapToB */,
|
|
3907
4477
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3908
4478
|
preInstructions,
|
|
3909
|
-
|
|
4479
|
+
swapInstructions: [result.instruction],
|
|
4480
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3910
4481
|
cleanUpInstructions,
|
|
3911
4482
|
swapInEstimate: {
|
|
3912
|
-
inAmountA: new
|
|
4483
|
+
inAmountA: new import_core.BN(0),
|
|
3913
4484
|
inAmountB: amountIn,
|
|
3914
4485
|
routeA: "dammV2" /* DammV2 */,
|
|
3915
4486
|
routeB: "jupiter" /* Jupiter */
|
|
@@ -3918,6 +4489,7 @@ var Zap = class {
|
|
|
3918
4489
|
}
|
|
3919
4490
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3920
4491
|
const result = yield buildJupiterSwapTransaction(
|
|
4492
|
+
this.connection,
|
|
3921
4493
|
user,
|
|
3922
4494
|
inputTokenMint,
|
|
3923
4495
|
tokenAMint,
|
|
@@ -3927,8 +4499,10 @@ var Zap = class {
|
|
|
3927
4499
|
void 0,
|
|
3928
4500
|
{
|
|
3929
4501
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3930
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3931
|
-
|
|
4502
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4503
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4504
|
+
},
|
|
4505
|
+
jupiterQuoteOptions
|
|
3932
4506
|
);
|
|
3933
4507
|
return {
|
|
3934
4508
|
user,
|
|
@@ -3936,7 +4510,7 @@ var Zap = class {
|
|
|
3936
4510
|
position,
|
|
3937
4511
|
positionNftAccount,
|
|
3938
4512
|
maxSqrtPriceChangeBps,
|
|
3939
|
-
amount: new
|
|
4513
|
+
amount: new import_core.BN(0),
|
|
3940
4514
|
isDirectPool: false,
|
|
3941
4515
|
tokenAMint,
|
|
3942
4516
|
tokenBMint,
|
|
@@ -3949,14 +4523,15 @@ var Zap = class {
|
|
|
3949
4523
|
maxTransferAmountExtendPercentage
|
|
3950
4524
|
),
|
|
3951
4525
|
swapType: 0 /* swapToA */,
|
|
3952
|
-
maxTransferAmountB: new
|
|
4526
|
+
maxTransferAmountB: new import_core.BN(0),
|
|
3953
4527
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3954
4528
|
preInstructions,
|
|
3955
|
-
|
|
4529
|
+
swapInstructions: [result.instruction],
|
|
4530
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3956
4531
|
cleanUpInstructions,
|
|
3957
4532
|
swapInEstimate: {
|
|
3958
4533
|
inAmountA: amountIn,
|
|
3959
|
-
inAmountB: new
|
|
4534
|
+
inAmountB: new import_core.BN(0),
|
|
3960
4535
|
routeA: "jupiter" /* Jupiter */,
|
|
3961
4536
|
routeB: "dammV2" /* DammV2 */
|
|
3962
4537
|
}
|
|
@@ -3964,6 +4539,7 @@ var Zap = class {
|
|
|
3964
4539
|
}
|
|
3965
4540
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3966
4541
|
const result = yield buildJupiterSwapTransaction(
|
|
4542
|
+
this.connection,
|
|
3967
4543
|
user,
|
|
3968
4544
|
inputTokenMint,
|
|
3969
4545
|
tokenBMint,
|
|
@@ -3973,8 +4549,10 @@ var Zap = class {
|
|
|
3973
4549
|
void 0,
|
|
3974
4550
|
{
|
|
3975
4551
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3976
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3977
|
-
|
|
4552
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4553
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4554
|
+
},
|
|
4555
|
+
jupiterQuoteOptions
|
|
3978
4556
|
);
|
|
3979
4557
|
return {
|
|
3980
4558
|
user,
|
|
@@ -3982,7 +4560,7 @@ var Zap = class {
|
|
|
3982
4560
|
position,
|
|
3983
4561
|
positionNftAccount,
|
|
3984
4562
|
maxSqrtPriceChangeBps,
|
|
3985
|
-
amount: new
|
|
4563
|
+
amount: new import_core.BN(0),
|
|
3986
4564
|
isDirectPool: false,
|
|
3987
4565
|
tokenAMint,
|
|
3988
4566
|
tokenBMint,
|
|
@@ -3990,7 +4568,7 @@ var Zap = class {
|
|
|
3990
4568
|
tokenBVault,
|
|
3991
4569
|
tokenAProgram,
|
|
3992
4570
|
tokenBProgram,
|
|
3993
|
-
maxTransferAmountA: new
|
|
4571
|
+
maxTransferAmountA: new import_core.BN(0),
|
|
3994
4572
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3995
4573
|
result.quoteResponse.outAmount,
|
|
3996
4574
|
maxTransferAmountExtendPercentage
|
|
@@ -3998,10 +4576,11 @@ var Zap = class {
|
|
|
3998
4576
|
swapType: 1 /* swapToB */,
|
|
3999
4577
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4000
4578
|
preInstructions,
|
|
4001
|
-
|
|
4579
|
+
swapInstructions: [result.instruction],
|
|
4580
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
4002
4581
|
cleanUpInstructions,
|
|
4003
4582
|
swapInEstimate: {
|
|
4004
|
-
inAmountA: new
|
|
4583
|
+
inAmountA: new import_core.BN(0),
|
|
4005
4584
|
inAmountB: amountIn,
|
|
4006
4585
|
routeA: "dammV2" /* DammV2 */,
|
|
4007
4586
|
routeB: "jupiter" /* Jupiter */
|
|
@@ -4038,7 +4617,7 @@ var Zap = class {
|
|
|
4038
4617
|
position,
|
|
4039
4618
|
positionNftAccount,
|
|
4040
4619
|
maxSqrtPriceChangeBps,
|
|
4041
|
-
amount: new
|
|
4620
|
+
amount: new import_core.BN(0),
|
|
4042
4621
|
isDirectPool: false,
|
|
4043
4622
|
tokenAMint,
|
|
4044
4623
|
tokenBMint,
|
|
@@ -4050,7 +4629,8 @@ var Zap = class {
|
|
|
4050
4629
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4051
4630
|
cleanUpInstructions
|
|
4052
4631
|
};
|
|
4053
|
-
const
|
|
4632
|
+
const swapToA = yield buildJupiterSwapTransaction(
|
|
4633
|
+
this.connection,
|
|
4054
4634
|
user,
|
|
4055
4635
|
inputTokenMint,
|
|
4056
4636
|
tokenAMint,
|
|
@@ -4060,10 +4640,13 @@ var Zap = class {
|
|
|
4060
4640
|
void 0,
|
|
4061
4641
|
{
|
|
4062
4642
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4063
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4064
|
-
|
|
4643
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4644
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4645
|
+
},
|
|
4646
|
+
jupiterQuoteOptions
|
|
4065
4647
|
);
|
|
4066
|
-
const
|
|
4648
|
+
const swapToB = yield buildJupiterSwapTransaction(
|
|
4649
|
+
this.connection,
|
|
4067
4650
|
user,
|
|
4068
4651
|
inputTokenMint,
|
|
4069
4652
|
tokenBMint,
|
|
@@ -4073,20 +4656,26 @@ var Zap = class {
|
|
|
4073
4656
|
void 0,
|
|
4074
4657
|
{
|
|
4075
4658
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4076
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4077
|
-
|
|
4659
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4660
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4661
|
+
},
|
|
4662
|
+
jupiterQuoteOptions
|
|
4078
4663
|
);
|
|
4079
4664
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4080
4665
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4081
|
-
|
|
4666
|
+
swapToA.quoteResponse.outAmount,
|
|
4082
4667
|
maxTransferAmountExtendPercentage
|
|
4083
4668
|
),
|
|
4084
4669
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
4085
|
-
|
|
4670
|
+
swapToB.quoteResponse.outAmount,
|
|
4086
4671
|
maxTransferAmountExtendPercentage
|
|
4087
4672
|
),
|
|
4088
4673
|
swapType: 2 /* swapToBoth */,
|
|
4089
|
-
|
|
4674
|
+
swapInstructions: [swapToA.instruction, swapToB.instruction],
|
|
4675
|
+
addressLookupTableAccounts: mergeAddressLookupTableAccounts(
|
|
4676
|
+
swapToA.addressLookupTableAccounts,
|
|
4677
|
+
swapToB.addressLookupTableAccounts
|
|
4678
|
+
),
|
|
4090
4679
|
swapInEstimate: {
|
|
4091
4680
|
inAmountA: swapAmountToA,
|
|
4092
4681
|
inAmountB: swapAmountToB,
|
|
@@ -4101,7 +4690,12 @@ var Zap = class {
|
|
|
4101
4690
|
});
|
|
4102
4691
|
}
|
|
4103
4692
|
/**
|
|
4104
|
-
* Build DAMM v2 zap-in
|
|
4693
|
+
* Build the DAMM v2 zap-in instructions
|
|
4694
|
+
*
|
|
4695
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
4696
|
+
* They must run in that order but can be split across several transactions, because state
|
|
4697
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
4698
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4105
4699
|
*
|
|
4106
4700
|
* @param params.user - The user's public key
|
|
4107
4701
|
* @param params.pool - The pool's public key
|
|
@@ -4118,9 +4712,10 @@ var Zap = class {
|
|
|
4118
4712
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4119
4713
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4120
4714
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4121
|
-
* @param params.
|
|
4715
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
4716
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4122
4717
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4123
|
-
* @returns
|
|
4718
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4124
4719
|
*/
|
|
4125
4720
|
buildZapInDammV2Transaction(params) {
|
|
4126
4721
|
return __async(this, null, function* () {
|
|
@@ -4140,7 +4735,8 @@ var Zap = class {
|
|
|
4140
4735
|
preSqrtPrice,
|
|
4141
4736
|
maxSqrtPriceChangeBps,
|
|
4142
4737
|
preInstructions,
|
|
4143
|
-
|
|
4738
|
+
swapInstructions,
|
|
4739
|
+
addressLookupTableAccounts,
|
|
4144
4740
|
cleanUpInstructions
|
|
4145
4741
|
} = params;
|
|
4146
4742
|
const [
|
|
@@ -4164,37 +4760,33 @@ var Zap = class {
|
|
|
4164
4760
|
tokenBProgram
|
|
4165
4761
|
)
|
|
4166
4762
|
]);
|
|
4167
|
-
const
|
|
4168
|
-
initializeTokenAIx &&
|
|
4169
|
-
initializeTokenBIx &&
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
}
|
|
4173
|
-
const ledgerTransaction = new import_web38.Transaction();
|
|
4174
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4175
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4763
|
+
const setupInstructions = [];
|
|
4764
|
+
initializeTokenAIx && setupInstructions.push(initializeTokenAIx);
|
|
4765
|
+
initializeTokenBIx && setupInstructions.push(initializeTokenBIx);
|
|
4766
|
+
setupInstructions.push(...preInstructions);
|
|
4767
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4176
4768
|
if (isDirectPool) {
|
|
4177
4769
|
const isTokenA = params.isTokenA;
|
|
4178
|
-
const
|
|
4770
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4179
4771
|
user,
|
|
4180
4772
|
amount,
|
|
4181
4773
|
isTokenA
|
|
4182
4774
|
);
|
|
4183
|
-
|
|
4184
|
-
if (
|
|
4775
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4776
|
+
if (swapInstructions.length > 0) {
|
|
4185
4777
|
const tokenAccount = isTokenA ? tokenBAccount : tokenAAccount;
|
|
4186
4778
|
const preTokenBalance = yield getTokenAccountBalance(
|
|
4187
4779
|
this.connection,
|
|
4188
4780
|
tokenAccount
|
|
4189
4781
|
);
|
|
4190
|
-
const
|
|
4782
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4191
4783
|
user,
|
|
4192
4784
|
tokenAccount,
|
|
4193
|
-
new
|
|
4785
|
+
new import_core.BN(preTokenBalance),
|
|
4194
4786
|
params.maxTransferAmount,
|
|
4195
4787
|
!isTokenA
|
|
4196
4788
|
);
|
|
4197
|
-
|
|
4789
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4198
4790
|
}
|
|
4199
4791
|
} else {
|
|
4200
4792
|
const preTokenABalance = yield getTokenAccountBalance(
|
|
@@ -4205,32 +4797,35 @@ var Zap = class {
|
|
|
4205
4797
|
this.connection,
|
|
4206
4798
|
tokenBAccount
|
|
4207
4799
|
);
|
|
4208
|
-
const
|
|
4800
|
+
const updateLedgerBalanceTokenAAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4209
4801
|
user,
|
|
4210
4802
|
tokenAAccount,
|
|
4211
|
-
new
|
|
4803
|
+
new import_core.BN(preTokenABalance),
|
|
4212
4804
|
params.maxTransferAmountA,
|
|
4213
4805
|
true
|
|
4214
4806
|
// is token A
|
|
4215
4807
|
);
|
|
4216
|
-
const
|
|
4808
|
+
const updateLedgerBalanceTokenBAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4217
4809
|
user,
|
|
4218
4810
|
tokenBAccount,
|
|
4219
|
-
new
|
|
4811
|
+
new import_core.BN(preTokenBBalance),
|
|
4220
4812
|
params.maxTransferAmountB,
|
|
4221
4813
|
false
|
|
4222
4814
|
// isn't token A
|
|
4223
4815
|
);
|
|
4224
4816
|
const swapType = params.swapType;
|
|
4225
4817
|
if (swapType == 0 /* swapToA */) {
|
|
4226
|
-
|
|
4818
|
+
ledgerInstructions.push(updateLedgerBalanceTokenAAfterSwapIx);
|
|
4227
4819
|
} else if (swapType == 1 /* swapToB */) {
|
|
4228
|
-
|
|
4820
|
+
ledgerInstructions.push(updateLedgerBalanceTokenBAfterSwapIx);
|
|
4229
4821
|
} else {
|
|
4230
|
-
|
|
4822
|
+
ledgerInstructions.push(
|
|
4823
|
+
updateLedgerBalanceTokenAAfterSwapIx,
|
|
4824
|
+
updateLedgerBalanceTokenBAfterSwapIx
|
|
4825
|
+
);
|
|
4231
4826
|
}
|
|
4232
4827
|
}
|
|
4233
|
-
const
|
|
4828
|
+
const zapInInstruction = yield this.zapInDammV2({
|
|
4234
4829
|
user,
|
|
4235
4830
|
pool,
|
|
4236
4831
|
position,
|
|
@@ -4246,18 +4841,17 @@ var Zap = class {
|
|
|
4246
4841
|
tokenAAccount,
|
|
4247
4842
|
tokenBAccount
|
|
4248
4843
|
});
|
|
4249
|
-
const
|
|
4250
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4251
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4252
|
-
if (cleanUpInstructions.length > 0) {
|
|
4253
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4254
|
-
}
|
|
4844
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4255
4845
|
return {
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4846
|
+
instructions: [
|
|
4847
|
+
...setupInstructions,
|
|
4848
|
+
...swapInstructions,
|
|
4849
|
+
...ledgerInstructions,
|
|
4850
|
+
zapInInstruction,
|
|
4851
|
+
closeLedgerInstruction,
|
|
4852
|
+
...cleanUpInstructions
|
|
4853
|
+
],
|
|
4854
|
+
addressLookupTableAccounts
|
|
4261
4855
|
};
|
|
4262
4856
|
});
|
|
4263
4857
|
}
|
|
@@ -4274,8 +4868,8 @@ var Zap = class {
|
|
|
4274
4868
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4275
4869
|
* @param params.strategy - The liquidity distribution strategy
|
|
4276
4870
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4277
|
-
* @param params.maxAccounts -
|
|
4278
|
-
* @param params.swapSlippageBps -
|
|
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
|
+
* @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
|
|
4279
4873
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4280
4874
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
4281
4875
|
* @param params.directSwapEstimate - The result from the direct swap estimate
|
|
@@ -4328,12 +4922,14 @@ var Zap = class {
|
|
|
4328
4922
|
initializeWrapSolIx && preInstructions.push(initializeWrapSolIx);
|
|
4329
4923
|
preInstructions.push(...wrapSOL);
|
|
4330
4924
|
}
|
|
4331
|
-
const
|
|
4925
|
+
const swapInstructions = [];
|
|
4926
|
+
let addressLookupTableAccounts = [];
|
|
4332
4927
|
let maxTransferAmount;
|
|
4333
4928
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4334
4929
|
const swapQuote = directSwapEstimate.quote;
|
|
4335
4930
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4336
|
-
const
|
|
4931
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
4932
|
+
this.connection,
|
|
4337
4933
|
user,
|
|
4338
4934
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4339
4935
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
@@ -4343,10 +4939,12 @@ var Zap = class {
|
|
|
4343
4939
|
swapQuote.originalQuote,
|
|
4344
4940
|
{
|
|
4345
4941
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4346
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4942
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4943
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4347
4944
|
}
|
|
4348
4945
|
);
|
|
4349
|
-
|
|
4946
|
+
swapInstructions.push(swap.instruction);
|
|
4947
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4350
4948
|
} else {
|
|
4351
4949
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4352
4950
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4359,6 +4957,9 @@ var Zap = class {
|
|
|
4359
4957
|
user,
|
|
4360
4958
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4361
4959
|
});
|
|
4960
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
4961
|
+
swapTx.instructions
|
|
4962
|
+
);
|
|
4362
4963
|
if (tokenXMint.equals(import_spl_token6.NATIVE_MINT) || tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4363
4964
|
swapTx.instructions = swapTx.instructions.filter((ix) => {
|
|
4364
4965
|
if (ix.programId.equals(import_spl_token6.TOKEN_PROGRAM_ID)) {
|
|
@@ -4367,14 +4968,14 @@ var Zap = class {
|
|
|
4367
4968
|
return true;
|
|
4368
4969
|
});
|
|
4369
4970
|
}
|
|
4370
|
-
|
|
4971
|
+
swapInstructions.push(...swapTx.instructions);
|
|
4371
4972
|
}
|
|
4372
4973
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
4373
4974
|
directSwapEstimate.expectedOutput.toString(),
|
|
4374
4975
|
maxTransferAmountExtendPercentage
|
|
4375
4976
|
);
|
|
4376
4977
|
} else {
|
|
4377
|
-
maxTransferAmount = new
|
|
4978
|
+
maxTransferAmount = new import_core.BN(0);
|
|
4378
4979
|
}
|
|
4379
4980
|
const amount = isTokenX ? directSwapEstimate.postSwapX : directSwapEstimate.postSwapY;
|
|
4380
4981
|
const cleanUpInstructions = [];
|
|
@@ -4384,8 +4985,8 @@ var Zap = class {
|
|
|
4384
4985
|
}
|
|
4385
4986
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4386
4987
|
lbPair,
|
|
4387
|
-
new
|
|
4388
|
-
new
|
|
4988
|
+
new import_core.BN(activeId + minDeltaId),
|
|
4989
|
+
new import_core.BN(activeId + maxDeltaId),
|
|
4389
4990
|
DLMM_PROGRAM_ID
|
|
4390
4991
|
).map((item) => ({
|
|
4391
4992
|
pubkey: item.key,
|
|
@@ -4417,7 +5018,8 @@ var Zap = class {
|
|
|
4417
5018
|
amount,
|
|
4418
5019
|
maxTransferAmount,
|
|
4419
5020
|
preInstructions,
|
|
4420
|
-
|
|
5021
|
+
swapInstructions,
|
|
5022
|
+
addressLookupTableAccounts,
|
|
4421
5023
|
cleanUpInstructions,
|
|
4422
5024
|
binArrays,
|
|
4423
5025
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4498,11 +5100,13 @@ var Zap = class {
|
|
|
4498
5100
|
}
|
|
4499
5101
|
let maxTransferAmountX;
|
|
4500
5102
|
let maxTransferAmountY;
|
|
4501
|
-
const
|
|
5103
|
+
const swapInstructions = [];
|
|
5104
|
+
const swapLookupTables = [];
|
|
4502
5105
|
const swapAmountToXInLamports = indirectSwapEstimate.swapAmountToX;
|
|
4503
5106
|
const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
|
|
4504
5107
|
if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
|
|
4505
|
-
const
|
|
5108
|
+
const swapToX = yield buildJupiterSwapTransaction(
|
|
5109
|
+
this.connection,
|
|
4506
5110
|
user,
|
|
4507
5111
|
inputTokenMint,
|
|
4508
5112
|
tokenXMint,
|
|
@@ -4512,13 +5116,16 @@ var Zap = class {
|
|
|
4512
5116
|
indirectSwapEstimate.swapToX,
|
|
4513
5117
|
{
|
|
4514
5118
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4515
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5119
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5120
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4516
5121
|
}
|
|
4517
5122
|
);
|
|
4518
|
-
|
|
5123
|
+
swapInstructions.push(swapToX.instruction);
|
|
5124
|
+
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
4519
5125
|
}
|
|
4520
5126
|
if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
|
|
4521
|
-
const
|
|
5127
|
+
const swapToY = yield buildJupiterSwapTransaction(
|
|
5128
|
+
this.connection,
|
|
4522
5129
|
user,
|
|
4523
5130
|
inputTokenMint,
|
|
4524
5131
|
tokenYMint,
|
|
@@ -4528,11 +5135,16 @@ var Zap = class {
|
|
|
4528
5135
|
indirectSwapEstimate.swapToY,
|
|
4529
5136
|
{
|
|
4530
5137
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4531
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5138
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5139
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4532
5140
|
}
|
|
4533
5141
|
);
|
|
4534
|
-
|
|
5142
|
+
swapInstructions.push(swapToY.instruction);
|
|
5143
|
+
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
4535
5144
|
}
|
|
5145
|
+
const addressLookupTableAccounts = mergeAddressLookupTableAccounts(
|
|
5146
|
+
...swapLookupTables
|
|
5147
|
+
);
|
|
4536
5148
|
maxTransferAmountX = getExtendMaxAmountTransfer(
|
|
4537
5149
|
indirectSwapEstimate.postSwapX.toString(),
|
|
4538
5150
|
maxTransferAmountExtendPercentage
|
|
@@ -4543,8 +5155,8 @@ var Zap = class {
|
|
|
4543
5155
|
);
|
|
4544
5156
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4545
5157
|
lbPair,
|
|
4546
|
-
new
|
|
4547
|
-
new
|
|
5158
|
+
new import_core.BN(activeId + minDeltaId),
|
|
5159
|
+
new import_core.BN(activeId + maxDeltaId),
|
|
4548
5160
|
DLMM_PROGRAM_ID
|
|
4549
5161
|
).map((item) => ({
|
|
4550
5162
|
pubkey: item.key,
|
|
@@ -4574,7 +5186,8 @@ var Zap = class {
|
|
|
4574
5186
|
maxTransferAmountX,
|
|
4575
5187
|
maxTransferAmountY,
|
|
4576
5188
|
preInstructions,
|
|
4577
|
-
|
|
5189
|
+
swapInstructions,
|
|
5190
|
+
addressLookupTableAccounts,
|
|
4578
5191
|
cleanUpInstructions,
|
|
4579
5192
|
binArrays,
|
|
4580
5193
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4584,7 +5197,12 @@ var Zap = class {
|
|
|
4584
5197
|
});
|
|
4585
5198
|
}
|
|
4586
5199
|
/**
|
|
4587
|
-
*
|
|
5200
|
+
* Build the DLMM zap-in instructions
|
|
5201
|
+
*
|
|
5202
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
5203
|
+
* They must run in that order but can be split across several transactions, because state
|
|
5204
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
5205
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4588
5206
|
*
|
|
4589
5207
|
* @param params.user - The user's public key
|
|
4590
5208
|
* @param params.lbPair - The DLMM pool's public key
|
|
@@ -4600,13 +5218,14 @@ var Zap = class {
|
|
|
4600
5218
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4601
5219
|
* @param params.strategy - The liquidity distribution strategy
|
|
4602
5220
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4603
|
-
* @param params.
|
|
5221
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
5222
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4604
5223
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4605
5224
|
* @param params.binArrays - The bin arrays required for the position
|
|
4606
5225
|
* @param params.binArrayBitmapExtension - The bin array bitmap extension account if it exists
|
|
4607
5226
|
* @param params.isDirectRoute - Whether this is a direct route
|
|
4608
5227
|
* @param params.singleSided - Optional single-sided deposit mode (X or Y only) - default is non-single-sided
|
|
4609
|
-
* @returns
|
|
5228
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4610
5229
|
*/
|
|
4611
5230
|
buildZapInDlmmTransaction(params) {
|
|
4612
5231
|
return __async(this, null, function* () {
|
|
@@ -4625,7 +5244,8 @@ var Zap = class {
|
|
|
4625
5244
|
favorXInActiveId,
|
|
4626
5245
|
strategy,
|
|
4627
5246
|
preInstructions,
|
|
4628
|
-
|
|
5247
|
+
swapInstructions,
|
|
5248
|
+
addressLookupTableAccounts,
|
|
4629
5249
|
cleanUpInstructions,
|
|
4630
5250
|
binArrays,
|
|
4631
5251
|
binArrayBitmapExtension,
|
|
@@ -4653,62 +5273,58 @@ var Zap = class {
|
|
|
4653
5273
|
tokenYProgram
|
|
4654
5274
|
)
|
|
4655
5275
|
]);
|
|
4656
|
-
const
|
|
4657
|
-
initializeTokenXIx &&
|
|
4658
|
-
initializeTokenYIx &&
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
}
|
|
4662
|
-
const ledgerTransaction = new import_web38.Transaction();
|
|
4663
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4664
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
5276
|
+
const setupInstructions = [];
|
|
5277
|
+
initializeTokenXIx && setupInstructions.push(initializeTokenXIx);
|
|
5278
|
+
initializeTokenYIx && setupInstructions.push(initializeTokenYIx);
|
|
5279
|
+
setupInstructions.push(...preInstructions);
|
|
5280
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4665
5281
|
if (isDirectRoute) {
|
|
4666
5282
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
4667
5283
|
if (singleSided !== void 0) {
|
|
4668
5284
|
const singleSidedX = singleSided === 0 /* X */;
|
|
4669
|
-
if (
|
|
5285
|
+
if (swapInstructions.length > 0) {
|
|
4670
5286
|
const swappedTokenAccount = singleSidedX ? tokenXAccount : tokenYAccount;
|
|
4671
5287
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4672
5288
|
this.connection,
|
|
4673
5289
|
swappedTokenAccount
|
|
4674
5290
|
);
|
|
4675
|
-
const
|
|
5291
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4676
5292
|
user,
|
|
4677
5293
|
swappedTokenAccount,
|
|
4678
|
-
new
|
|
5294
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4679
5295
|
maxTransferAmount,
|
|
4680
5296
|
singleSidedX
|
|
4681
5297
|
);
|
|
4682
|
-
|
|
5298
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4683
5299
|
} else {
|
|
4684
|
-
const
|
|
5300
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4685
5301
|
user,
|
|
4686
5302
|
amount,
|
|
4687
5303
|
singleSidedX
|
|
4688
5304
|
);
|
|
4689
|
-
|
|
5305
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4690
5306
|
}
|
|
4691
5307
|
} else {
|
|
4692
|
-
const
|
|
5308
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4693
5309
|
user,
|
|
4694
5310
|
amount,
|
|
4695
5311
|
isTokenX
|
|
4696
5312
|
);
|
|
4697
|
-
|
|
4698
|
-
if (
|
|
5313
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
5314
|
+
if (swapInstructions.length > 0) {
|
|
4699
5315
|
const swappedTokenAccount = isTokenX ? tokenYAccount : tokenXAccount;
|
|
4700
5316
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4701
5317
|
this.connection,
|
|
4702
5318
|
swappedTokenAccount
|
|
4703
5319
|
);
|
|
4704
|
-
const
|
|
5320
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4705
5321
|
user,
|
|
4706
5322
|
swappedTokenAccount,
|
|
4707
|
-
new
|
|
5323
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4708
5324
|
maxTransferAmount,
|
|
4709
5325
|
!isTokenX
|
|
4710
5326
|
);
|
|
4711
|
-
|
|
5327
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4712
5328
|
}
|
|
4713
5329
|
}
|
|
4714
5330
|
} else {
|
|
@@ -4720,14 +5336,14 @@ var Zap = class {
|
|
|
4720
5336
|
this.connection,
|
|
4721
5337
|
swappedTokenAccount
|
|
4722
5338
|
);
|
|
4723
|
-
const
|
|
5339
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4724
5340
|
user,
|
|
4725
5341
|
swappedTokenAccount,
|
|
4726
|
-
new
|
|
5342
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4727
5343
|
singleSidedX ? maxTransferAmountX : maxTransferAmountY,
|
|
4728
5344
|
singleSidedX
|
|
4729
5345
|
);
|
|
4730
|
-
|
|
5346
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4731
5347
|
} else {
|
|
4732
5348
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
4733
5349
|
this.connection,
|
|
@@ -4737,22 +5353,22 @@ var Zap = class {
|
|
|
4737
5353
|
this.connection,
|
|
4738
5354
|
tokenYAccount
|
|
4739
5355
|
);
|
|
4740
|
-
const
|
|
5356
|
+
const updateLedgerBalanceTokenXAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4741
5357
|
user,
|
|
4742
5358
|
tokenXAccount,
|
|
4743
|
-
new
|
|
5359
|
+
new import_core.BN(preTokenXBalance),
|
|
4744
5360
|
maxTransferAmountX,
|
|
4745
5361
|
true
|
|
4746
5362
|
);
|
|
4747
|
-
const
|
|
5363
|
+
const updateLedgerBalanceTokenYAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4748
5364
|
user,
|
|
4749
5365
|
tokenYAccount,
|
|
4750
|
-
new
|
|
5366
|
+
new import_core.BN(preTokenYBalance),
|
|
4751
5367
|
maxTransferAmountY,
|
|
4752
5368
|
false
|
|
4753
5369
|
);
|
|
4754
|
-
|
|
4755
|
-
|
|
5370
|
+
ledgerInstructions.push(updateLedgerBalanceTokenXAfterSwapIx);
|
|
5371
|
+
ledgerInstructions.push(updateLedgerBalanceTokenYAfterSwapIx);
|
|
4756
5372
|
}
|
|
4757
5373
|
}
|
|
4758
5374
|
const dlmm = yield import_dlmm4.default.create(this.connection, lbPair);
|
|
@@ -4766,7 +5382,7 @@ var Zap = class {
|
|
|
4766
5382
|
tokenYProgram,
|
|
4767
5383
|
dlmm.lbPair
|
|
4768
5384
|
);
|
|
4769
|
-
const
|
|
5385
|
+
const zapInInstruction = yield this.zapInDlmmForUninitializedPosition({
|
|
4770
5386
|
user,
|
|
4771
5387
|
lbPair,
|
|
4772
5388
|
position,
|
|
@@ -4780,18 +5396,17 @@ var Zap = class {
|
|
|
4780
5396
|
strategy,
|
|
4781
5397
|
remainingAccountInfo
|
|
4782
5398
|
});
|
|
4783
|
-
const
|
|
4784
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4785
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4786
|
-
if (cleanUpInstructions.length > 0) {
|
|
4787
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4788
|
-
}
|
|
5399
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4789
5400
|
return {
|
|
4790
|
-
|
|
4791
|
-
|
|
4792
|
-
|
|
4793
|
-
|
|
4794
|
-
|
|
5401
|
+
instructions: [
|
|
5402
|
+
...setupInstructions,
|
|
5403
|
+
...swapInstructions,
|
|
5404
|
+
...ledgerInstructions,
|
|
5405
|
+
zapInInstruction,
|
|
5406
|
+
closeLedgerInstruction,
|
|
5407
|
+
...cleanUpInstructions
|
|
5408
|
+
],
|
|
5409
|
+
addressLookupTableAccounts
|
|
4795
5410
|
};
|
|
4796
5411
|
});
|
|
4797
5412
|
}
|
|
@@ -4799,6 +5414,13 @@ var Zap = class {
|
|
|
4799
5414
|
* High level method for DLMM position rebalancing
|
|
4800
5415
|
* Consist of remove liquidity, zap out through Jupiter or DLMM, and zap back in to rebalance the position
|
|
4801
5416
|
*
|
|
5417
|
+
* Instructions are ordered: setup (token accounts), init bin arrays, rebalance position, swap, ledger,
|
|
5418
|
+
* zap in, clean up. They must run in that order but can be split across several transactions.
|
|
5419
|
+
* Splitting loses atomicity, so send split transactions as a bundle.
|
|
5420
|
+
* No compute budget instructions are included. The zap-in instruction was measured at about 462k
|
|
5421
|
+
* compute units. Without a compute unit limit, a transaction gets 200k units per instruction (up to
|
|
5422
|
+
* 1.4M), which may not cover it, so set a compute unit limit on the transaction that holds it.
|
|
5423
|
+
*
|
|
4802
5424
|
* @param params - Rebalancing DLMM position parameters
|
|
4803
5425
|
* @param params.lbPairAddress - The DLMM pool address
|
|
4804
5426
|
* @param params.positionAddress - The position address
|
|
@@ -4811,7 +5433,7 @@ var Zap = class {
|
|
|
4811
5433
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4812
5434
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
4813
5435
|
* @param params.maxAccounts - The maximum number of accounts to use for the swap operation
|
|
4814
|
-
* @returns
|
|
5436
|
+
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
4815
5437
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
4816
5438
|
*/
|
|
4817
5439
|
rebalanceDlmmPosition(params) {
|
|
@@ -4853,18 +5475,18 @@ var Zap = class {
|
|
|
4853
5475
|
tokenYProgram
|
|
4854
5476
|
)
|
|
4855
5477
|
]);
|
|
4856
|
-
const
|
|
4857
|
-
userTokenXIx &&
|
|
4858
|
-
userTokenYIx &&
|
|
5478
|
+
const setupInstructions = [];
|
|
5479
|
+
userTokenXIx && setupInstructions.push(userTokenXIx);
|
|
5480
|
+
userTokenYIx && setupInstructions.push(userTokenYIx);
|
|
4859
5481
|
const strategyParamBuilder = (0, import_dlmm4.getLiquidityStrategyParameterBuilder)(strategy);
|
|
4860
5482
|
const { x0, y0, deltaX, deltaY } = (0, import_dlmm4.buildLiquidityStrategyParameters)(
|
|
4861
|
-
new
|
|
4862
|
-
new
|
|
4863
|
-
new
|
|
4864
|
-
new
|
|
4865
|
-
new
|
|
5483
|
+
new import_core.BN(0),
|
|
5484
|
+
new import_core.BN(0),
|
|
5485
|
+
new import_core.BN(minDeltaId),
|
|
5486
|
+
new import_core.BN(maxDeltaId),
|
|
5487
|
+
new import_core.BN(dlmm.lbPair.binStep),
|
|
4866
5488
|
favorXInActiveId,
|
|
4867
|
-
new
|
|
5489
|
+
new import_core.BN(dlmm.lbPair.activeId),
|
|
4868
5490
|
strategyParamBuilder
|
|
4869
5491
|
);
|
|
4870
5492
|
const { rebalancePosition, simulationResult } = yield dlmm.simulateRebalancePosition(
|
|
@@ -4880,16 +5502,16 @@ var Zap = class {
|
|
|
4880
5502
|
y0,
|
|
4881
5503
|
deltaX,
|
|
4882
5504
|
deltaY,
|
|
4883
|
-
minDeltaId: new
|
|
4884
|
-
maxDeltaId: new
|
|
5505
|
+
minDeltaId: new import_core.BN(minDeltaId),
|
|
5506
|
+
maxDeltaId: new import_core.BN(maxDeltaId),
|
|
4885
5507
|
favorXInActiveBin: favorXInActiveId
|
|
4886
5508
|
}
|
|
4887
5509
|
],
|
|
4888
5510
|
[
|
|
4889
5511
|
{
|
|
4890
|
-
minBinId: new
|
|
4891
|
-
maxBinId: new
|
|
4892
|
-
bps: new
|
|
5512
|
+
minBinId: new import_core.BN(userPosition.positionData.lowerBinId),
|
|
5513
|
+
maxBinId: new import_core.BN(userPosition.positionData.upperBinId),
|
|
5514
|
+
bps: new import_core.BN(import_dlmm4.BASIS_POINT_MAX)
|
|
4893
5515
|
// remove all liquidity
|
|
4894
5516
|
}
|
|
4895
5517
|
]
|
|
@@ -4904,21 +5526,25 @@ var Zap = class {
|
|
|
4904
5526
|
rebalancePositionInstruction: _rebalancePositionInstruction
|
|
4905
5527
|
} = yield dlmm.rebalancePosition(
|
|
4906
5528
|
{ simulationResult, rebalancePosition },
|
|
4907
|
-
new
|
|
5529
|
+
new import_core.BN(maxActiveBinSlippage)
|
|
5530
|
+
);
|
|
5531
|
+
let rebalancePositionInstruction = filterOutComputeBudgetInstructions(
|
|
5532
|
+
_rebalancePositionInstruction
|
|
4908
5533
|
);
|
|
4909
|
-
let rebalancePositionInstruction = _rebalancePositionInstruction;
|
|
4910
5534
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4911
5535
|
rebalancePositionInstruction = filterOutCloseSplTokenAccountInstructions(
|
|
4912
|
-
|
|
5536
|
+
rebalancePositionInstruction
|
|
4913
5537
|
);
|
|
4914
5538
|
}
|
|
4915
|
-
const tokenXAmount = new
|
|
4916
|
-
const tokenYAmount = new
|
|
4917
|
-
let
|
|
5539
|
+
const tokenXAmount = new import_core.BN(userPosition.positionData.totalXAmount);
|
|
5540
|
+
const tokenYAmount = new import_core.BN(userPosition.positionData.totalYAmount);
|
|
5541
|
+
let swapInstructions = [];
|
|
5542
|
+
let addressLookupTableAccounts = [];
|
|
4918
5543
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4919
5544
|
const swapQuote = directSwapEstimate.quote;
|
|
4920
5545
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4921
|
-
const
|
|
5546
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
5547
|
+
this.connection,
|
|
4922
5548
|
user,
|
|
4923
5549
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
4924
5550
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
@@ -4928,10 +5554,12 @@ var Zap = class {
|
|
|
4928
5554
|
swapQuote.originalQuote,
|
|
4929
5555
|
{
|
|
4930
5556
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4931
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5557
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5558
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4932
5559
|
}
|
|
4933
5560
|
);
|
|
4934
|
-
|
|
5561
|
+
swapInstructions = [swap.instruction];
|
|
5562
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4935
5563
|
} else {
|
|
4936
5564
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4937
5565
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4944,12 +5572,15 @@ var Zap = class {
|
|
|
4944
5572
|
user,
|
|
4945
5573
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4946
5574
|
});
|
|
5575
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
5576
|
+
swapTx.instructions
|
|
5577
|
+
);
|
|
4947
5578
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4948
5579
|
swapTx.instructions = filterOutCloseSplTokenAccountInstructions(
|
|
4949
5580
|
swapTx.instructions
|
|
4950
5581
|
);
|
|
4951
5582
|
}
|
|
4952
|
-
|
|
5583
|
+
swapInstructions = swapTx.instructions;
|
|
4953
5584
|
}
|
|
4954
5585
|
}
|
|
4955
5586
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
@@ -4964,31 +5595,31 @@ var Zap = class {
|
|
|
4964
5595
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4965
5596
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4966
5597
|
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4967
|
-
const
|
|
5598
|
+
const ledgerInstructions = [];
|
|
4968
5599
|
if (!ledgerAccountInfo) {
|
|
4969
|
-
const
|
|
4970
|
-
|
|
5600
|
+
const initLedgerIx = yield this.initializeLedgerAccount(user, user);
|
|
5601
|
+
ledgerInstructions.push(initLedgerIx);
|
|
4971
5602
|
}
|
|
4972
|
-
const
|
|
5603
|
+
const updateLedgerXIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4973
5604
|
user,
|
|
4974
5605
|
userTokenX,
|
|
4975
|
-
new
|
|
5606
|
+
new import_core.BN(preTokenXBalance),
|
|
4976
5607
|
tokenXAmountAfterSwap,
|
|
4977
5608
|
true
|
|
4978
5609
|
);
|
|
4979
|
-
|
|
4980
|
-
const
|
|
5610
|
+
ledgerInstructions.push(updateLedgerXIx);
|
|
5611
|
+
const updateLedgerYIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4981
5612
|
user,
|
|
4982
5613
|
userTokenY,
|
|
4983
|
-
new
|
|
5614
|
+
new import_core.BN(preTokenYBalance),
|
|
4984
5615
|
tokenYAmountAfterSwap,
|
|
4985
5616
|
false
|
|
4986
5617
|
);
|
|
4987
|
-
|
|
5618
|
+
ledgerInstructions.push(updateLedgerYIx);
|
|
4988
5619
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4989
5620
|
lbPair,
|
|
4990
|
-
new
|
|
4991
|
-
new
|
|
5621
|
+
new import_core.BN(dlmm.lbPair.activeId + minDeltaId),
|
|
5622
|
+
new import_core.BN(dlmm.lbPair.activeId + maxDeltaId),
|
|
4992
5623
|
DLMM_PROGRAM_ID
|
|
4993
5624
|
).map((item) => ({
|
|
4994
5625
|
pubkey: item.key,
|
|
@@ -5005,7 +5636,7 @@ var Zap = class {
|
|
|
5005
5636
|
tokenYProgram,
|
|
5006
5637
|
dlmm.lbPair
|
|
5007
5638
|
);
|
|
5008
|
-
const
|
|
5639
|
+
const zapInInstruction = yield this.zapInDlmmForInitializedPosition({
|
|
5009
5640
|
user,
|
|
5010
5641
|
lbPair,
|
|
5011
5642
|
position,
|
|
@@ -5018,28 +5649,26 @@ var Zap = class {
|
|
|
5018
5649
|
strategy,
|
|
5019
5650
|
remainingAccountInfo
|
|
5020
5651
|
});
|
|
5021
|
-
|
|
5022
|
-
|
|
5023
|
-
|
|
5024
|
-
import_web38.ComputeBudgetProgram.setComputeUnitLimit({ units: 6e5 })
|
|
5025
|
-
);
|
|
5026
|
-
const cleanUpTransaction = new import_web38.Transaction();
|
|
5027
|
-
const closeLedgerTx = yield this.closeLedgerAccount(user, user);
|
|
5028
|
-
cleanUpTransaction.add(closeLedgerTx);
|
|
5652
|
+
const cleanUpInstructions = [
|
|
5653
|
+
yield this.closeLedgerAccount(user, user)
|
|
5654
|
+
];
|
|
5029
5655
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
5030
5656
|
const unwrapIx = unwrapSOLInstruction(user, user);
|
|
5031
5657
|
if (unwrapIx) {
|
|
5032
|
-
|
|
5658
|
+
cleanUpInstructions.push(unwrapIx);
|
|
5033
5659
|
}
|
|
5034
5660
|
}
|
|
5035
5661
|
return {
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5662
|
+
instructions: [
|
|
5663
|
+
...setupInstructions,
|
|
5664
|
+
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5665
|
+
...rebalancePositionInstruction,
|
|
5666
|
+
...swapInstructions,
|
|
5667
|
+
...ledgerInstructions,
|
|
5668
|
+
zapInInstruction,
|
|
5669
|
+
...cleanUpInstructions
|
|
5670
|
+
],
|
|
5671
|
+
addressLookupTableAccounts,
|
|
5043
5672
|
estimation: {
|
|
5044
5673
|
currentBalances: {
|
|
5045
5674
|
tokenX: tokenXAmount,
|
|
@@ -5065,7 +5694,7 @@ var Zap = class {
|
|
|
5065
5694
|
* @param params.ammProgram - AMM program ID to interact with
|
|
5066
5695
|
* @param params.preInstructions - Instructions to run before the zap out
|
|
5067
5696
|
* @param params.postInstructions - Instructions to run after the zap out
|
|
5068
|
-
* @returns
|
|
5697
|
+
* @returns The pre-instructions, the zap out instruction and the post-instructions in order, with no lookup tables
|
|
5069
5698
|
*/
|
|
5070
5699
|
zapOut(params) {
|
|
5071
5700
|
return __async(this, null, function* () {
|
|
@@ -5077,10 +5706,18 @@ var Zap = class {
|
|
|
5077
5706
|
preInstructions,
|
|
5078
5707
|
postInstructions
|
|
5079
5708
|
} = params;
|
|
5080
|
-
|
|
5709
|
+
const zapOutInstruction = yield this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
|
|
5081
5710
|
userTokenInAccount,
|
|
5082
5711
|
ammProgram
|
|
5083
|
-
}).remainingAccounts(remainingAccounts).
|
|
5712
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
5713
|
+
return {
|
|
5714
|
+
instructions: [
|
|
5715
|
+
...preInstructions,
|
|
5716
|
+
zapOutInstruction,
|
|
5717
|
+
...postInstructions
|
|
5718
|
+
],
|
|
5719
|
+
addressLookupTableAccounts: []
|
|
5720
|
+
};
|
|
5084
5721
|
});
|
|
5085
5722
|
}
|
|
5086
5723
|
/**
|
|
@@ -5091,12 +5728,12 @@ var Zap = class {
|
|
|
5091
5728
|
* @param params.user - Public key of the user performing the swap
|
|
5092
5729
|
* @param params.inputMint - Token mint being swapped from
|
|
5093
5730
|
* @param params.outputMint - Token mint being swapped to
|
|
5094
|
-
* @param params.jupiterSwapResponse - Jupiter swap instruction response
|
|
5731
|
+
* @param params.jupiterSwapResponse - Jupiter swap instruction response. Its lookup table fields, when present, are returned as `addressLookupTableAccounts` (v1 tables are fetched with one RPC call)
|
|
5095
5732
|
* @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
|
|
5096
5733
|
* @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
|
|
5097
5734
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5098
5735
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5099
|
-
* @returns
|
|
5736
|
+
* @returns The ordered instructions and the lookup tables of the Jupiter swap
|
|
5100
5737
|
*/
|
|
5101
5738
|
zapOutThroughJupiter(params) {
|
|
5102
5739
|
return __async(this, null, function* () {
|
|
@@ -5114,7 +5751,7 @@ var Zap = class {
|
|
|
5114
5751
|
const postInstructions = [];
|
|
5115
5752
|
const [
|
|
5116
5753
|
{ ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
|
|
5117
|
-
{
|
|
5754
|
+
{ ix: outputTokenAccountIx }
|
|
5118
5755
|
] = yield Promise.all([
|
|
5119
5756
|
getOrCreateATAInstruction(
|
|
5120
5757
|
this.connection,
|
|
@@ -5158,27 +5795,36 @@ var Zap = class {
|
|
|
5158
5795
|
jupiterSwapResponse.swapInstruction.data,
|
|
5159
5796
|
"base64"
|
|
5160
5797
|
);
|
|
5161
|
-
const offsetAmountIn =
|
|
5798
|
+
const offsetAmountIn = getJupiterInstructionLayout(
|
|
5799
|
+
payloadData
|
|
5800
|
+
).amountInOffset(payloadData.length);
|
|
5162
5801
|
if (inputMint.equals(import_spl_token6.NATIVE_MINT) || outputMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
5163
5802
|
const unwrapInstructions = unwrapSOLInstruction(user, user);
|
|
5164
5803
|
if (unwrapInstructions) {
|
|
5165
5804
|
postInstructions.push(unwrapInstructions);
|
|
5166
5805
|
}
|
|
5167
5806
|
}
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5171
|
-
|
|
5172
|
-
|
|
5173
|
-
|
|
5174
|
-
|
|
5175
|
-
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5807
|
+
const [{ instructions }, addressLookupTableAccounts] = yield Promise.all([
|
|
5808
|
+
this.zapOut({
|
|
5809
|
+
userTokenInAccount: inputTokenAccount,
|
|
5810
|
+
zapOutParams: {
|
|
5811
|
+
percentage: percentageToZapOut,
|
|
5812
|
+
offsetAmountIn,
|
|
5813
|
+
preUserTokenBalance: new import_core.BN(preUserTokenBalance),
|
|
5814
|
+
maxSwapAmount,
|
|
5815
|
+
payloadData
|
|
5816
|
+
},
|
|
5817
|
+
remainingAccounts,
|
|
5818
|
+
ammProgram: JUP_V6_PROGRAM_ID,
|
|
5819
|
+
preInstructions,
|
|
5820
|
+
postInstructions
|
|
5821
|
+
}),
|
|
5822
|
+
getJupiterAddressLookupTableAccounts(
|
|
5823
|
+
this.connection,
|
|
5824
|
+
jupiterSwapResponse
|
|
5825
|
+
)
|
|
5826
|
+
]);
|
|
5827
|
+
return { instructions, addressLookupTableAccounts };
|
|
5182
5828
|
});
|
|
5183
5829
|
}
|
|
5184
5830
|
/**
|
|
@@ -5194,6 +5840,7 @@ var Zap = class {
|
|
|
5194
5840
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5195
5841
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5196
5842
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5843
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5197
5844
|
*/
|
|
5198
5845
|
zapOutThroughDammV2(params) {
|
|
5199
5846
|
return __async(this, null, function* () {
|
|
@@ -5266,7 +5913,7 @@ var Zap = class {
|
|
|
5266
5913
|
zapOutParams: {
|
|
5267
5914
|
percentage: percentageToZapOut,
|
|
5268
5915
|
offsetAmountIn,
|
|
5269
|
-
preUserTokenBalance: new
|
|
5916
|
+
preUserTokenBalance: new import_core.BN(preUserTokenBalance),
|
|
5270
5917
|
maxSwapAmount,
|
|
5271
5918
|
payloadData
|
|
5272
5919
|
},
|
|
@@ -5290,6 +5937,7 @@ var Zap = class {
|
|
|
5290
5937
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5291
5938
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5292
5939
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5940
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5293
5941
|
*/
|
|
5294
5942
|
zapOutThroughDlmm(params) {
|
|
5295
5943
|
return __async(this, null, function* () {
|
|
@@ -5366,7 +6014,7 @@ var Zap = class {
|
|
|
5366
6014
|
zapOutParams: {
|
|
5367
6015
|
percentage: percentageToZapOut,
|
|
5368
6016
|
offsetAmountIn: AMOUNT_IN_DLMM_OFFSET,
|
|
5369
|
-
preUserTokenBalance: new
|
|
6017
|
+
preUserTokenBalance: new import_core.BN(preUserTokenBalance),
|
|
5370
6018
|
maxSwapAmount,
|
|
5371
6019
|
payloadData
|
|
5372
6020
|
},
|
|
@@ -5388,12 +6036,20 @@ var Zap = class {
|
|
|
5388
6036
|
DAMM_V2_PROGRAM_ID,
|
|
5389
6037
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
5390
6038
|
DEFAULT_JUPITER_API_URL,
|
|
6039
|
+
DEFAULT_JUPITER_API_VERSION,
|
|
6040
|
+
DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
5391
6041
|
DLMM_PROGRAM_ID,
|
|
5392
6042
|
DLMM_SWAP_DISCRIMINATOR,
|
|
5393
6043
|
DlmmDirectSwapQuoteRoute,
|
|
5394
6044
|
DlmmSingleSided,
|
|
5395
6045
|
DlmmSwapType,
|
|
6046
|
+
JUPITER_INSTRUCTION_LAYOUTS,
|
|
5396
6047
|
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
|
+
JupiterApiVersion,
|
|
5397
6053
|
MEMO_PROGRAM_ID,
|
|
5398
6054
|
SwapExternalType,
|
|
5399
6055
|
ZAP_PROGRAM_ID,
|
|
@@ -5413,13 +6069,17 @@ var Zap = class {
|
|
|
5413
6069
|
estimateDlmmDirectSwap,
|
|
5414
6070
|
estimateDlmmIndirectSwap,
|
|
5415
6071
|
estimateDlmmRebalanceSwap,
|
|
6072
|
+
fetchAddressLookupTableAccounts,
|
|
5416
6073
|
filterOutCloseSplTokenAccountInstructions,
|
|
6074
|
+
filterOutComputeBudgetInstructions,
|
|
5417
6075
|
getBinArrayBitmapExtension,
|
|
5418
6076
|
getBitFromBinArrayIndexInBitmapExtension,
|
|
5419
6077
|
getDammV2Pool,
|
|
5420
6078
|
getDammV2RemainingAccounts,
|
|
5421
6079
|
getDlmmRemainingAccounts,
|
|
5422
6080
|
getExtraAccountMetasForTransferHook,
|
|
6081
|
+
getJupiterAddressLookupTableAccounts,
|
|
6082
|
+
getJupiterInstructionLayout,
|
|
5423
6083
|
getJupiterQuote,
|
|
5424
6084
|
getJupiterSwapInstruction,
|
|
5425
6085
|
getLbPairState,
|
|
@@ -5427,8 +6087,13 @@ var Zap = class {
|
|
|
5427
6087
|
getOrCreateATAInstruction,
|
|
5428
6088
|
getTokenAccountBalance,
|
|
5429
6089
|
getTokenProgramFromMint,
|
|
6090
|
+
isJupiterBuildResponse,
|
|
6091
|
+
isJupiterSwapInstructionForUser,
|
|
5430
6092
|
isSingleSidedA,
|
|
5431
6093
|
isSingleSidedB,
|
|
6094
|
+
mergeAddressLookupTableAccounts,
|
|
6095
|
+
resolveJupiterConfig,
|
|
6096
|
+
toAddressLookupTableAccounts,
|
|
5432
6097
|
toProgramStrategyType,
|
|
5433
6098
|
unwrapSOLInstruction,
|
|
5434
6099
|
wrapSOLInstruction
|