@meteora-ag/zap-sdk 1.3.2 → 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 -533
- package/dist/index.mjs +1131 -492
- 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,42 +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
|
-
|
|
1800
|
-
|
|
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()}`;
|
|
1801
2191
|
try {
|
|
1802
2192
|
const response = yield fetch(url, {
|
|
1803
2193
|
method: "GET",
|
|
1804
|
-
headers:
|
|
1805
|
-
Accept: "application/json"
|
|
1806
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
|
|
2194
|
+
headers: jupiterHeaders(apiKey, false)
|
|
1807
2195
|
});
|
|
1808
2196
|
if (!response.ok) {
|
|
1809
2197
|
return null;
|
|
1810
2198
|
}
|
|
1811
|
-
|
|
1812
|
-
return result;
|
|
2199
|
+
return yield response.json();
|
|
1813
2200
|
} catch (error) {
|
|
1814
2201
|
return null;
|
|
1815
2202
|
}
|
|
1816
2203
|
});
|
|
1817
2204
|
}
|
|
1818
|
-
function
|
|
1819
|
-
return __async(this,
|
|
1820
|
-
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`;
|
|
1821
2251
|
const requestBody = {
|
|
1822
2252
|
userPublicKey: userPublicKey.toString(),
|
|
1823
2253
|
quoteResponse
|
|
@@ -1826,10 +2256,7 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1826
2256
|
try {
|
|
1827
2257
|
response = yield fetch(url, {
|
|
1828
2258
|
method: "POST",
|
|
1829
|
-
headers:
|
|
1830
|
-
"Content-Type": "application/json",
|
|
1831
|
-
Accept: "application/json"
|
|
1832
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
|
|
2259
|
+
headers: jupiterHeaders(apiKey, true),
|
|
1833
2260
|
body: JSON.stringify(requestBody)
|
|
1834
2261
|
});
|
|
1835
2262
|
if (!response.ok) {
|
|
@@ -1841,22 +2268,111 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1841
2268
|
} catch (error) {
|
|
1842
2269
|
throw new Error(`Jupiter swap instruction failed to fetch`);
|
|
1843
2270
|
}
|
|
1844
|
-
|
|
1845
|
-
return result;
|
|
2271
|
+
return yield response.json();
|
|
1846
2272
|
});
|
|
1847
2273
|
}
|
|
1848
|
-
function
|
|
1849
|
-
return __async(this, arguments, function* (
|
|
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
|
+
);
|
|
2358
|
+
});
|
|
2359
|
+
}
|
|
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
|
+
}
|
|
1850
2367
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
true,
|
|
2368
|
+
__spreadValues({
|
|
2369
|
+
inputMint,
|
|
2370
|
+
outputMint,
|
|
2371
|
+
amount,
|
|
2372
|
+
user,
|
|
2373
|
+
maxAccounts,
|
|
2374
|
+
slippageBps
|
|
2375
|
+
}, jupiterQuoteOptions),
|
|
1860
2376
|
config
|
|
1861
2377
|
);
|
|
1862
2378
|
if (!quoteResponse) {
|
|
@@ -1880,7 +2396,11 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1880
2396
|
programId: new import_web32.PublicKey(swapInstructionResponse.swapInstruction.programId),
|
|
1881
2397
|
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1882
2398
|
});
|
|
1883
|
-
|
|
2399
|
+
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2400
|
+
connection,
|
|
2401
|
+
swapInstructionResponse
|
|
2402
|
+
);
|
|
2403
|
+
return { instruction, addressLookupTableAccounts, quoteResponse };
|
|
1884
2404
|
});
|
|
1885
2405
|
}
|
|
1886
2406
|
|
|
@@ -2049,11 +2569,16 @@ function convertLamportsToUiAmount(amount, decimals) {
|
|
|
2049
2569
|
function convertUiAmountToLamports(amount, decimals) {
|
|
2050
2570
|
return amount.mul(import_decimal.default.pow(10, decimals));
|
|
2051
2571
|
}
|
|
2572
|
+
function filterOutComputeBudgetInstructions(instructions) {
|
|
2573
|
+
return instructions.filter(
|
|
2574
|
+
(ix) => !ix.programId.equals(import_web34.ComputeBudgetProgram.programId)
|
|
2575
|
+
);
|
|
2576
|
+
}
|
|
2052
2577
|
|
|
2053
2578
|
// src/helpers/token.ts
|
|
2054
2579
|
var import_spl_token3 = require("@solana/spl-token");
|
|
2055
2580
|
var import_web35 = require("@solana/web3.js");
|
|
2056
|
-
var getOrCreateATAInstruction = (
|
|
2581
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2057
2582
|
const toAccount = (0, import_spl_token3.getAssociatedTokenAddressSync)(
|
|
2058
2583
|
tokenMint,
|
|
2059
2584
|
owner,
|
|
@@ -2489,8 +3014,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2489
3014
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2490
3015
|
return new import_bn3.default(estimatedOutput.floor().toString());
|
|
2491
3016
|
}
|
|
2492
|
-
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
2493
|
-
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 = {}) {
|
|
2494
3019
|
let dlmmQuoteResult = null;
|
|
2495
3020
|
try {
|
|
2496
3021
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2503,15 +3028,14 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
2503
3028
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
2504
3029
|
}
|
|
2505
3030
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
2506
|
-
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
|
|
2510
|
-
|
|
2511
|
-
|
|
2512
|
-
|
|
2513
|
-
|
|
2514
|
-
true,
|
|
3031
|
+
__spreadValues({
|
|
3032
|
+
inputMint: inMint,
|
|
3033
|
+
outputMint: outMint,
|
|
3034
|
+
amount: inAmount,
|
|
3035
|
+
user,
|
|
3036
|
+
maxAccounts: 50,
|
|
3037
|
+
slippageBps: swapSlippageBps
|
|
3038
|
+
}, jupiterQuoteOptions),
|
|
2515
3039
|
config
|
|
2516
3040
|
);
|
|
2517
3041
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -2627,6 +3151,7 @@ function binarySearchRefineDirectSwapAmount(dlmm, initialActiveBin, initialMinBi
|
|
|
2627
3151
|
}
|
|
2628
3152
|
function estimateDlmmIndirectSwap(_0) {
|
|
2629
3153
|
return __async(this, arguments, function* ({
|
|
3154
|
+
user,
|
|
2630
3155
|
amountIn,
|
|
2631
3156
|
inputTokenMint,
|
|
2632
3157
|
lbPair,
|
|
@@ -2636,6 +3161,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2636
3161
|
maxDeltaId,
|
|
2637
3162
|
strategy,
|
|
2638
3163
|
singleSided,
|
|
3164
|
+
jupiterQuoteOptions,
|
|
2639
3165
|
config = {}
|
|
2640
3166
|
}) {
|
|
2641
3167
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
@@ -2660,15 +3186,14 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2660
3186
|
const singleSidedX = singleSided === 0 /* X */;
|
|
2661
3187
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
2662
3188
|
const quote = yield getJupiterQuote(
|
|
2663
|
-
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
true,
|
|
3189
|
+
__spreadValues({
|
|
3190
|
+
inputMint: inputTokenMint,
|
|
3191
|
+
outputMint: outputTokenMint,
|
|
3192
|
+
amount: amountIn,
|
|
3193
|
+
user,
|
|
3194
|
+
maxAccounts: 50,
|
|
3195
|
+
slippageBps: swapSlippageBps
|
|
3196
|
+
}, jupiterQuoteOptions),
|
|
2672
3197
|
config
|
|
2673
3198
|
);
|
|
2674
3199
|
if (!quote) {
|
|
@@ -2691,27 +3216,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2691
3216
|
const halfAmount = amountIn.div(new import_bn3.default(2));
|
|
2692
3217
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
2693
3218
|
getJupiterQuote(
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
true,
|
|
3219
|
+
__spreadValues({
|
|
3220
|
+
inputMint: inputTokenMint,
|
|
3221
|
+
outputMint: tokenXMint,
|
|
3222
|
+
amount: halfAmount,
|
|
3223
|
+
user,
|
|
3224
|
+
maxAccounts: 50,
|
|
3225
|
+
slippageBps: swapSlippageBps
|
|
3226
|
+
}, jupiterQuoteOptions),
|
|
2703
3227
|
config
|
|
2704
3228
|
),
|
|
2705
3229
|
getJupiterQuote(
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
true,
|
|
3230
|
+
__spreadValues({
|
|
3231
|
+
inputMint: inputTokenMint,
|
|
3232
|
+
outputMint: tokenYMint,
|
|
3233
|
+
amount: halfAmount,
|
|
3234
|
+
user,
|
|
3235
|
+
maxAccounts: 50,
|
|
3236
|
+
slippageBps: swapSlippageBps
|
|
3237
|
+
}, jupiterQuoteOptions),
|
|
2715
3238
|
config
|
|
2716
3239
|
)
|
|
2717
3240
|
]);
|
|
@@ -2807,27 +3330,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2807
3330
|
}
|
|
2808
3331
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
2809
3332
|
getJupiterQuote(
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
true,
|
|
3333
|
+
__spreadValues({
|
|
3334
|
+
inputMint: inputTokenMint,
|
|
3335
|
+
outputMint: tokenXMint,
|
|
3336
|
+
amount: bestAmountToX,
|
|
3337
|
+
user,
|
|
3338
|
+
maxAccounts: 50,
|
|
3339
|
+
slippageBps: swapSlippageBps
|
|
3340
|
+
}, jupiterQuoteOptions),
|
|
2819
3341
|
config
|
|
2820
3342
|
),
|
|
2821
3343
|
getJupiterQuote(
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
true,
|
|
3344
|
+
__spreadValues({
|
|
3345
|
+
inputMint: inputTokenMint,
|
|
3346
|
+
outputMint: tokenYMint,
|
|
3347
|
+
amount: bestAmountToY,
|
|
3348
|
+
user,
|
|
3349
|
+
maxAccounts: 50,
|
|
3350
|
+
slippageBps: swapSlippageBps
|
|
3351
|
+
}, jupiterQuoteOptions),
|
|
2831
3352
|
config
|
|
2832
3353
|
)
|
|
2833
3354
|
]);
|
|
@@ -2863,6 +3384,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2863
3384
|
}
|
|
2864
3385
|
function estimateDlmmDirectSwapCore(_0) {
|
|
2865
3386
|
return __async(this, arguments, function* ({
|
|
3387
|
+
user,
|
|
2866
3388
|
tokenXAmount,
|
|
2867
3389
|
tokenYAmount,
|
|
2868
3390
|
dlmm,
|
|
@@ -2871,6 +3393,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2871
3393
|
maxDeltaId,
|
|
2872
3394
|
strategy,
|
|
2873
3395
|
singleSided,
|
|
3396
|
+
jupiterQuoteOptions,
|
|
2874
3397
|
config = {}
|
|
2875
3398
|
}) {
|
|
2876
3399
|
if (singleSided !== void 0) {
|
|
@@ -2883,13 +3406,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2883
3406
|
);
|
|
2884
3407
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2885
3408
|
dlmm,
|
|
3409
|
+
user,
|
|
2886
3410
|
dlmm.lbPair.tokenYMint,
|
|
2887
3411
|
dlmm.lbPair.tokenXMint,
|
|
2888
3412
|
tokenYAmount,
|
|
2889
3413
|
swapSlippageBps,
|
|
2890
3414
|
swapForY2,
|
|
2891
3415
|
binArrayForSwap2,
|
|
2892
|
-
config
|
|
3416
|
+
config,
|
|
3417
|
+
jupiterQuoteOptions
|
|
2893
3418
|
);
|
|
2894
3419
|
if (!quote) {
|
|
2895
3420
|
throw new Error(
|
|
@@ -2912,13 +3437,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2912
3437
|
);
|
|
2913
3438
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2914
3439
|
dlmm,
|
|
3440
|
+
user,
|
|
2915
3441
|
dlmm.lbPair.tokenXMint,
|
|
2916
3442
|
dlmm.lbPair.tokenYMint,
|
|
2917
3443
|
tokenXAmount,
|
|
2918
3444
|
swapSlippageBps,
|
|
2919
3445
|
swapForY2,
|
|
2920
3446
|
binArrayForSwap2,
|
|
2921
|
-
config
|
|
3447
|
+
config,
|
|
3448
|
+
jupiterQuoteOptions
|
|
2922
3449
|
);
|
|
2923
3450
|
if (!quote) {
|
|
2924
3451
|
throw new Error(
|
|
@@ -3007,13 +3534,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3007
3534
|
);
|
|
3008
3535
|
const initialQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3009
3536
|
dlmm,
|
|
3537
|
+
user,
|
|
3010
3538
|
inMint,
|
|
3011
3539
|
outMint,
|
|
3012
3540
|
initialSwapAmount,
|
|
3013
3541
|
swapSlippageBps,
|
|
3014
3542
|
swapForY,
|
|
3015
3543
|
binArrayForSwap,
|
|
3016
|
-
config
|
|
3544
|
+
config,
|
|
3545
|
+
jupiterQuoteOptions
|
|
3017
3546
|
);
|
|
3018
3547
|
if (!initialQuote) {
|
|
3019
3548
|
throw new Error(
|
|
@@ -3065,13 +3594,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3065
3594
|
);
|
|
3066
3595
|
const finalQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3067
3596
|
dlmm,
|
|
3597
|
+
user,
|
|
3068
3598
|
inMint,
|
|
3069
3599
|
outMint,
|
|
3070
3600
|
refinedAmount,
|
|
3071
3601
|
swapSlippageBps,
|
|
3072
3602
|
swapForY,
|
|
3073
3603
|
binArrayForSwap,
|
|
3074
|
-
config
|
|
3604
|
+
config,
|
|
3605
|
+
jupiterQuoteOptions
|
|
3075
3606
|
);
|
|
3076
3607
|
if (!finalQuote) {
|
|
3077
3608
|
return {
|
|
@@ -3097,6 +3628,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3097
3628
|
}
|
|
3098
3629
|
function estimateDlmmDirectSwap(_0) {
|
|
3099
3630
|
return __async(this, arguments, function* ({
|
|
3631
|
+
user,
|
|
3100
3632
|
amountIn,
|
|
3101
3633
|
inputTokenMint,
|
|
3102
3634
|
lbPair,
|
|
@@ -3106,6 +3638,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3106
3638
|
maxDeltaId,
|
|
3107
3639
|
strategy,
|
|
3108
3640
|
singleSided,
|
|
3641
|
+
jupiterQuoteOptions,
|
|
3109
3642
|
config = {}
|
|
3110
3643
|
}) {
|
|
3111
3644
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
@@ -3117,6 +3650,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3117
3650
|
const tokenXAmount = isInputTokenX ? amountIn : new import_bn3.default(0);
|
|
3118
3651
|
const tokenYAmount = isInputTokenX ? new import_bn3.default(0) : amountIn;
|
|
3119
3652
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3653
|
+
user,
|
|
3120
3654
|
tokenXAmount,
|
|
3121
3655
|
tokenYAmount,
|
|
3122
3656
|
dlmm,
|
|
@@ -3125,6 +3659,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3125
3659
|
maxDeltaId,
|
|
3126
3660
|
strategy,
|
|
3127
3661
|
singleSided,
|
|
3662
|
+
jupiterQuoteOptions,
|
|
3128
3663
|
config
|
|
3129
3664
|
});
|
|
3130
3665
|
return {
|
|
@@ -3144,6 +3679,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3144
3679
|
}
|
|
3145
3680
|
function estimateDlmmRebalanceSwap(_0) {
|
|
3146
3681
|
return __async(this, arguments, function* ({
|
|
3682
|
+
user,
|
|
3147
3683
|
lbPair,
|
|
3148
3684
|
position,
|
|
3149
3685
|
connection,
|
|
@@ -3151,11 +3687,13 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3151
3687
|
minDeltaId,
|
|
3152
3688
|
maxDeltaId,
|
|
3153
3689
|
strategy,
|
|
3690
|
+
jupiterQuoteOptions,
|
|
3154
3691
|
config = {}
|
|
3155
3692
|
}) {
|
|
3156
3693
|
const dlmm = yield import_dlmm3.default.create(connection, lbPair);
|
|
3157
3694
|
const userPosition = yield dlmm.getPosition(position);
|
|
3158
3695
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3696
|
+
user,
|
|
3159
3697
|
tokenXAmount: new import_bn3.default(userPosition.positionData.totalXAmount),
|
|
3160
3698
|
tokenYAmount: new import_bn3.default(userPosition.positionData.totalYAmount),
|
|
3161
3699
|
dlmm,
|
|
@@ -3165,6 +3703,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3165
3703
|
strategy,
|
|
3166
3704
|
singleSided: void 0,
|
|
3167
3705
|
// rebalance does not use single-sided deposits
|
|
3706
|
+
jupiterQuoteOptions,
|
|
3168
3707
|
config
|
|
3169
3708
|
});
|
|
3170
3709
|
return {
|
|
@@ -3232,13 +3771,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
|
|
|
3232
3771
|
var Zap = class {
|
|
3233
3772
|
/**
|
|
3234
3773
|
* @param connection - The connection to the Solana cluster
|
|
3235
|
-
* @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)
|
|
3236
3775
|
*/
|
|
3237
3776
|
constructor(connection, config = {}) {
|
|
3777
|
+
var _a;
|
|
3238
3778
|
this.connection = connection;
|
|
3239
|
-
this.zapProgram = new
|
|
3779
|
+
this.zapProgram = new import_core.Program(idl_default, { connection });
|
|
3240
3780
|
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3241
3781
|
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3782
|
+
this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3242
3783
|
}
|
|
3243
3784
|
/////// PRIVATE FUNDTIONS //////
|
|
3244
3785
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3247,7 +3788,7 @@ var Zap = class {
|
|
|
3247
3788
|
ledger: deriveLedgerAccount(owner),
|
|
3248
3789
|
owner,
|
|
3249
3790
|
payer
|
|
3250
|
-
}).
|
|
3791
|
+
}).instruction();
|
|
3251
3792
|
});
|
|
3252
3793
|
}
|
|
3253
3794
|
closeLedgerAccount(owner, rentReceiver) {
|
|
@@ -3256,7 +3797,7 @@ var Zap = class {
|
|
|
3256
3797
|
ledger: deriveLedgerAccount(owner),
|
|
3257
3798
|
owner,
|
|
3258
3799
|
rentReceiver
|
|
3259
|
-
}).
|
|
3800
|
+
}).instruction();
|
|
3260
3801
|
});
|
|
3261
3802
|
}
|
|
3262
3803
|
setLedgerBalance(owner, amount, isTokenA) {
|
|
@@ -3264,7 +3805,7 @@ var Zap = class {
|
|
|
3264
3805
|
return yield this.zapProgram.methods.setLedgerBalance(amount, isTokenA).accountsPartial({
|
|
3265
3806
|
ledger: deriveLedgerAccount(owner),
|
|
3266
3807
|
owner
|
|
3267
|
-
}).
|
|
3808
|
+
}).instruction();
|
|
3268
3809
|
});
|
|
3269
3810
|
}
|
|
3270
3811
|
updateLedgerBalanceAfterSwap(owner, tokenAccount, preSourceTokenAccount, maxTransferAmount, isTokenA) {
|
|
@@ -3277,7 +3818,7 @@ var Zap = class {
|
|
|
3277
3818
|
ledger: deriveLedgerAccount(owner),
|
|
3278
3819
|
tokenAccount,
|
|
3279
3820
|
owner
|
|
3280
|
-
}).
|
|
3821
|
+
}).instruction();
|
|
3281
3822
|
});
|
|
3282
3823
|
}
|
|
3283
3824
|
zapInDammV2(params) {
|
|
@@ -3315,7 +3856,7 @@ var Zap = class {
|
|
|
3315
3856
|
tokenBProgram,
|
|
3316
3857
|
dammProgram: DAMM_V2_PROGRAM_ID,
|
|
3317
3858
|
dammEventAuthority: deriveDammV2EventAuthority()
|
|
3318
|
-
}).
|
|
3859
|
+
}).instruction();
|
|
3319
3860
|
});
|
|
3320
3861
|
}
|
|
3321
3862
|
resetOrInitializeLedgerAccount(user) {
|
|
@@ -3325,9 +3866,9 @@ var Zap = class {
|
|
|
3325
3866
|
if (accountInfo) {
|
|
3326
3867
|
const closeLedger = yield this.closeLedgerAccount(user, user);
|
|
3327
3868
|
const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
|
|
3328
|
-
return
|
|
3869
|
+
return [closeLedger, reInitializeLedger];
|
|
3329
3870
|
}
|
|
3330
|
-
return yield this.initializeLedgerAccount(user, user);
|
|
3871
|
+
return [yield this.initializeLedgerAccount(user, user)];
|
|
3331
3872
|
});
|
|
3332
3873
|
}
|
|
3333
3874
|
zapInDlmmForInitializedPosition(params) {
|
|
@@ -3394,7 +3935,7 @@ var Zap = class {
|
|
|
3394
3935
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3395
3936
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3396
3937
|
systemProgram: import_web38.SystemProgram.programId
|
|
3397
|
-
}).remainingAccounts(binArrays).
|
|
3938
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3398
3939
|
});
|
|
3399
3940
|
}
|
|
3400
3941
|
zapInDlmmForUninitializedPosition(params) {
|
|
@@ -3458,7 +3999,7 @@ var Zap = class {
|
|
|
3458
3999
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3459
4000
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3460
4001
|
systemProgram: import_web38.SystemProgram.programId
|
|
3461
|
-
}).remainingAccounts(binArrays).
|
|
4002
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3462
4003
|
});
|
|
3463
4004
|
}
|
|
3464
4005
|
//#region Zap In
|
|
@@ -3478,6 +4019,7 @@ var Zap = class {
|
|
|
3478
4019
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3479
4020
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3480
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`
|
|
3481
4023
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
3482
4024
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3483
4025
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -3496,7 +4038,8 @@ var Zap = class {
|
|
|
3496
4038
|
slippageBps,
|
|
3497
4039
|
dammV2Quote,
|
|
3498
4040
|
jupiterQuote,
|
|
3499
|
-
maxTransferAmountExtendPercentage
|
|
4041
|
+
maxTransferAmountExtendPercentage,
|
|
4042
|
+
jupiterQuoteOptions
|
|
3500
4043
|
} = params;
|
|
3501
4044
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3502
4045
|
const {
|
|
@@ -3516,7 +4059,7 @@ var Zap = class {
|
|
|
3516
4059
|
const tokenAProgram = (0, import_cp_amm_sdk3.getTokenProgram)(tokenAFlag);
|
|
3517
4060
|
const tokenBProgram = (0, import_cp_amm_sdk3.getTokenProgram)(tokenBFlag);
|
|
3518
4061
|
const preInstructions = [];
|
|
3519
|
-
if (
|
|
4062
|
+
if (inputTokenMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
3520
4063
|
const { ataPubkey: userWrapSolAcc, ix: initializeUserWrapSOLAta } = yield getOrCreateATAInstruction(
|
|
3521
4064
|
this.connection,
|
|
3522
4065
|
import_spl_token6.NATIVE_MINT,
|
|
@@ -3568,20 +4111,22 @@ var Zap = class {
|
|
|
3568
4111
|
const singleSidedA = isSingleSidedA(poolState);
|
|
3569
4112
|
const singleSidedB = isSingleSidedB(poolState);
|
|
3570
4113
|
let amount;
|
|
3571
|
-
let
|
|
4114
|
+
let swapInstructions = [];
|
|
4115
|
+
let addressLookupTableAccounts = [];
|
|
3572
4116
|
let maxTransferAmount;
|
|
3573
4117
|
let swapInAmount;
|
|
3574
4118
|
let swapRoute;
|
|
3575
4119
|
if (singleSidedA && isInputTokenA || singleSidedB && !isInputTokenA) {
|
|
3576
4120
|
amount = amountIn;
|
|
3577
|
-
swapInAmount = new
|
|
3578
|
-
maxTransferAmount = new
|
|
4121
|
+
swapInAmount = new import_core.BN(0);
|
|
4122
|
+
maxTransferAmount = new import_core.BN(0);
|
|
3579
4123
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3580
4124
|
} else if (singleSidedA && !isInputTokenA || singleSidedB && isInputTokenA) {
|
|
3581
|
-
if (jupiterQuote !== null && (dammV2Quote === null || new
|
|
4125
|
+
if (jupiterQuote !== null && (dammV2Quote === null || new import_core.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3582
4126
|
swapInAmount = amountIn;
|
|
3583
|
-
amount = new
|
|
4127
|
+
amount = new import_core.BN(0);
|
|
3584
4128
|
const result = yield buildJupiterSwapTransaction(
|
|
4129
|
+
this.connection,
|
|
3585
4130
|
user,
|
|
3586
4131
|
inputTokenMint,
|
|
3587
4132
|
outputTokenMint,
|
|
@@ -3591,26 +4136,29 @@ var Zap = class {
|
|
|
3591
4136
|
void 0,
|
|
3592
4137
|
{
|
|
3593
4138
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3594
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3595
|
-
|
|
4139
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4140
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4141
|
+
},
|
|
4142
|
+
jupiterQuoteOptions
|
|
3596
4143
|
);
|
|
3597
|
-
|
|
4144
|
+
swapInstructions = [result.instruction];
|
|
4145
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3598
4146
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3599
4147
|
result.quoteResponse.outAmount,
|
|
3600
4148
|
maxTransferAmountExtendPercentage
|
|
3601
4149
|
);
|
|
3602
4150
|
swapRoute = "jupiter" /* Jupiter */;
|
|
3603
4151
|
} else if (dammV2Quote !== null) {
|
|
3604
|
-
swapInAmount = new
|
|
4152
|
+
swapInAmount = new import_core.BN(0);
|
|
3605
4153
|
amount = amountIn;
|
|
3606
|
-
maxTransferAmount = new
|
|
4154
|
+
maxTransferAmount = new import_core.BN(0);
|
|
3607
4155
|
swapRoute = "dammV2" /* DammV2 */;
|
|
3608
4156
|
} else {
|
|
3609
4157
|
throw new Error(
|
|
3610
4158
|
"No Jupiter or DAMM v2 quote found for single-sided swap, unable to proceed"
|
|
3611
4159
|
);
|
|
3612
4160
|
}
|
|
3613
|
-
} else if (jupiterQuote !== null && (dammV2Quote === null || new
|
|
4161
|
+
} else if (jupiterQuote !== null && (dammV2Quote === null || new import_core.BN(jupiterQuote.outAmount).gte(dammV2Quote.swapOutAmount))) {
|
|
3614
4162
|
const price = convertLamportsToUiAmount(
|
|
3615
4163
|
new import_decimal4.default(jupiterQuote.outAmount),
|
|
3616
4164
|
isInputTokenA ? tokenBDecimal : tokenADecimal
|
|
@@ -3631,6 +4179,7 @@ var Zap = class {
|
|
|
3631
4179
|
);
|
|
3632
4180
|
amount = amountIn.sub(swapInAmount);
|
|
3633
4181
|
const result = yield buildJupiterSwapTransaction(
|
|
4182
|
+
this.connection,
|
|
3634
4183
|
user,
|
|
3635
4184
|
inputTokenMint,
|
|
3636
4185
|
outputTokenMint,
|
|
@@ -3640,10 +4189,13 @@ var Zap = class {
|
|
|
3640
4189
|
void 0,
|
|
3641
4190
|
{
|
|
3642
4191
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3643
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3644
|
-
|
|
4192
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4193
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4194
|
+
},
|
|
4195
|
+
jupiterQuoteOptions
|
|
3645
4196
|
);
|
|
3646
|
-
|
|
4197
|
+
swapInstructions = [result.instruction];
|
|
4198
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3647
4199
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3648
4200
|
result.quoteResponse.outAmount,
|
|
3649
4201
|
maxTransferAmountExtendPercentage
|
|
@@ -3701,7 +4253,8 @@ var Zap = class {
|
|
|
3701
4253
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3702
4254
|
maxSqrtPriceChangeBps,
|
|
3703
4255
|
preInstructions,
|
|
3704
|
-
|
|
4256
|
+
swapInstructions,
|
|
4257
|
+
addressLookupTableAccounts,
|
|
3705
4258
|
cleanUpInstructions,
|
|
3706
4259
|
swapInEstimate: {
|
|
3707
4260
|
inAmount: swapInAmount,
|
|
@@ -3726,6 +4279,7 @@ var Zap = class {
|
|
|
3726
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)
|
|
3727
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)
|
|
3728
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`
|
|
3729
4283
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
3730
4284
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3731
4285
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -3744,7 +4298,8 @@ var Zap = class {
|
|
|
3744
4298
|
maxTransferAmountExtendPercentage,
|
|
3745
4299
|
slippageBps,
|
|
3746
4300
|
jupiterQuoteToA,
|
|
3747
|
-
jupiterQuoteToB
|
|
4301
|
+
jupiterQuoteToB,
|
|
4302
|
+
jupiterQuoteOptions
|
|
3748
4303
|
} = params;
|
|
3749
4304
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3750
4305
|
const {
|
|
@@ -3829,6 +4384,7 @@ var Zap = class {
|
|
|
3829
4384
|
);
|
|
3830
4385
|
}
|
|
3831
4386
|
const result = yield buildJupiterSwapTransaction(
|
|
4387
|
+
this.connection,
|
|
3832
4388
|
user,
|
|
3833
4389
|
inputTokenMint,
|
|
3834
4390
|
tokenAMint,
|
|
@@ -3838,8 +4394,10 @@ var Zap = class {
|
|
|
3838
4394
|
void 0,
|
|
3839
4395
|
{
|
|
3840
4396
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3841
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3842
|
-
|
|
4397
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4398
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4399
|
+
},
|
|
4400
|
+
jupiterQuoteOptions
|
|
3843
4401
|
);
|
|
3844
4402
|
return {
|
|
3845
4403
|
user,
|
|
@@ -3847,7 +4405,7 @@ var Zap = class {
|
|
|
3847
4405
|
position,
|
|
3848
4406
|
positionNftAccount,
|
|
3849
4407
|
maxSqrtPriceChangeBps,
|
|
3850
|
-
amount: new
|
|
4408
|
+
amount: new import_core.BN(0),
|
|
3851
4409
|
isDirectPool: false,
|
|
3852
4410
|
tokenAMint,
|
|
3853
4411
|
tokenBMint,
|
|
@@ -3860,14 +4418,15 @@ var Zap = class {
|
|
|
3860
4418
|
maxTransferAmountExtendPercentage
|
|
3861
4419
|
),
|
|
3862
4420
|
swapType: 0 /* swapToA */,
|
|
3863
|
-
maxTransferAmountB: new
|
|
4421
|
+
maxTransferAmountB: new import_core.BN(0),
|
|
3864
4422
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3865
4423
|
preInstructions,
|
|
3866
|
-
|
|
4424
|
+
swapInstructions: [result.instruction],
|
|
4425
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3867
4426
|
cleanUpInstructions,
|
|
3868
4427
|
swapInEstimate: {
|
|
3869
4428
|
inAmountA: amountIn,
|
|
3870
|
-
inAmountB: new
|
|
4429
|
+
inAmountB: new import_core.BN(0),
|
|
3871
4430
|
routeA: "jupiter" /* Jupiter */,
|
|
3872
4431
|
routeB: "dammV2" /* DammV2 */
|
|
3873
4432
|
}
|
|
@@ -3880,6 +4439,7 @@ var Zap = class {
|
|
|
3880
4439
|
);
|
|
3881
4440
|
}
|
|
3882
4441
|
const result = yield buildJupiterSwapTransaction(
|
|
4442
|
+
this.connection,
|
|
3883
4443
|
user,
|
|
3884
4444
|
inputTokenMint,
|
|
3885
4445
|
tokenBMint,
|
|
@@ -3889,8 +4449,10 @@ var Zap = class {
|
|
|
3889
4449
|
void 0,
|
|
3890
4450
|
{
|
|
3891
4451
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3892
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3893
|
-
|
|
4452
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4453
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4454
|
+
},
|
|
4455
|
+
jupiterQuoteOptions
|
|
3894
4456
|
);
|
|
3895
4457
|
return {
|
|
3896
4458
|
user,
|
|
@@ -3898,7 +4460,7 @@ var Zap = class {
|
|
|
3898
4460
|
position,
|
|
3899
4461
|
positionNftAccount,
|
|
3900
4462
|
maxSqrtPriceChangeBps,
|
|
3901
|
-
amount: new
|
|
4463
|
+
amount: new import_core.BN(0),
|
|
3902
4464
|
isDirectPool: false,
|
|
3903
4465
|
tokenAMint,
|
|
3904
4466
|
tokenBMint,
|
|
@@ -3906,7 +4468,7 @@ var Zap = class {
|
|
|
3906
4468
|
tokenBVault,
|
|
3907
4469
|
tokenAProgram,
|
|
3908
4470
|
tokenBProgram,
|
|
3909
|
-
maxTransferAmountA: new
|
|
4471
|
+
maxTransferAmountA: new import_core.BN(0),
|
|
3910
4472
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
3911
4473
|
result.quoteResponse.outAmount,
|
|
3912
4474
|
maxTransferAmountExtendPercentage
|
|
@@ -3914,10 +4476,11 @@ var Zap = class {
|
|
|
3914
4476
|
swapType: 1 /* swapToB */,
|
|
3915
4477
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3916
4478
|
preInstructions,
|
|
3917
|
-
|
|
4479
|
+
swapInstructions: [result.instruction],
|
|
4480
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3918
4481
|
cleanUpInstructions,
|
|
3919
4482
|
swapInEstimate: {
|
|
3920
|
-
inAmountA: new
|
|
4483
|
+
inAmountA: new import_core.BN(0),
|
|
3921
4484
|
inAmountB: amountIn,
|
|
3922
4485
|
routeA: "dammV2" /* DammV2 */,
|
|
3923
4486
|
routeB: "jupiter" /* Jupiter */
|
|
@@ -3926,6 +4489,7 @@ var Zap = class {
|
|
|
3926
4489
|
}
|
|
3927
4490
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3928
4491
|
const result = yield buildJupiterSwapTransaction(
|
|
4492
|
+
this.connection,
|
|
3929
4493
|
user,
|
|
3930
4494
|
inputTokenMint,
|
|
3931
4495
|
tokenAMint,
|
|
@@ -3935,8 +4499,10 @@ var Zap = class {
|
|
|
3935
4499
|
void 0,
|
|
3936
4500
|
{
|
|
3937
4501
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3938
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3939
|
-
|
|
4502
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4503
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4504
|
+
},
|
|
4505
|
+
jupiterQuoteOptions
|
|
3940
4506
|
);
|
|
3941
4507
|
return {
|
|
3942
4508
|
user,
|
|
@@ -3944,7 +4510,7 @@ var Zap = class {
|
|
|
3944
4510
|
position,
|
|
3945
4511
|
positionNftAccount,
|
|
3946
4512
|
maxSqrtPriceChangeBps,
|
|
3947
|
-
amount: new
|
|
4513
|
+
amount: new import_core.BN(0),
|
|
3948
4514
|
isDirectPool: false,
|
|
3949
4515
|
tokenAMint,
|
|
3950
4516
|
tokenBMint,
|
|
@@ -3957,14 +4523,15 @@ var Zap = class {
|
|
|
3957
4523
|
maxTransferAmountExtendPercentage
|
|
3958
4524
|
),
|
|
3959
4525
|
swapType: 0 /* swapToA */,
|
|
3960
|
-
maxTransferAmountB: new
|
|
4526
|
+
maxTransferAmountB: new import_core.BN(0),
|
|
3961
4527
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3962
4528
|
preInstructions,
|
|
3963
|
-
|
|
4529
|
+
swapInstructions: [result.instruction],
|
|
4530
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3964
4531
|
cleanUpInstructions,
|
|
3965
4532
|
swapInEstimate: {
|
|
3966
4533
|
inAmountA: amountIn,
|
|
3967
|
-
inAmountB: new
|
|
4534
|
+
inAmountB: new import_core.BN(0),
|
|
3968
4535
|
routeA: "jupiter" /* Jupiter */,
|
|
3969
4536
|
routeB: "dammV2" /* DammV2 */
|
|
3970
4537
|
}
|
|
@@ -3972,6 +4539,7 @@ var Zap = class {
|
|
|
3972
4539
|
}
|
|
3973
4540
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3974
4541
|
const result = yield buildJupiterSwapTransaction(
|
|
4542
|
+
this.connection,
|
|
3975
4543
|
user,
|
|
3976
4544
|
inputTokenMint,
|
|
3977
4545
|
tokenBMint,
|
|
@@ -3981,8 +4549,10 @@ var Zap = class {
|
|
|
3981
4549
|
void 0,
|
|
3982
4550
|
{
|
|
3983
4551
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3984
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3985
|
-
|
|
4552
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4553
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4554
|
+
},
|
|
4555
|
+
jupiterQuoteOptions
|
|
3986
4556
|
);
|
|
3987
4557
|
return {
|
|
3988
4558
|
user,
|
|
@@ -3990,7 +4560,7 @@ var Zap = class {
|
|
|
3990
4560
|
position,
|
|
3991
4561
|
positionNftAccount,
|
|
3992
4562
|
maxSqrtPriceChangeBps,
|
|
3993
|
-
amount: new
|
|
4563
|
+
amount: new import_core.BN(0),
|
|
3994
4564
|
isDirectPool: false,
|
|
3995
4565
|
tokenAMint,
|
|
3996
4566
|
tokenBMint,
|
|
@@ -3998,7 +4568,7 @@ var Zap = class {
|
|
|
3998
4568
|
tokenBVault,
|
|
3999
4569
|
tokenAProgram,
|
|
4000
4570
|
tokenBProgram,
|
|
4001
|
-
maxTransferAmountA: new
|
|
4571
|
+
maxTransferAmountA: new import_core.BN(0),
|
|
4002
4572
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
4003
4573
|
result.quoteResponse.outAmount,
|
|
4004
4574
|
maxTransferAmountExtendPercentage
|
|
@@ -4006,10 +4576,11 @@ var Zap = class {
|
|
|
4006
4576
|
swapType: 1 /* swapToB */,
|
|
4007
4577
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4008
4578
|
preInstructions,
|
|
4009
|
-
|
|
4579
|
+
swapInstructions: [result.instruction],
|
|
4580
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
4010
4581
|
cleanUpInstructions,
|
|
4011
4582
|
swapInEstimate: {
|
|
4012
|
-
inAmountA: new
|
|
4583
|
+
inAmountA: new import_core.BN(0),
|
|
4013
4584
|
inAmountB: amountIn,
|
|
4014
4585
|
routeA: "dammV2" /* DammV2 */,
|
|
4015
4586
|
routeB: "jupiter" /* Jupiter */
|
|
@@ -4046,7 +4617,7 @@ var Zap = class {
|
|
|
4046
4617
|
position,
|
|
4047
4618
|
positionNftAccount,
|
|
4048
4619
|
maxSqrtPriceChangeBps,
|
|
4049
|
-
amount: new
|
|
4620
|
+
amount: new import_core.BN(0),
|
|
4050
4621
|
isDirectPool: false,
|
|
4051
4622
|
tokenAMint,
|
|
4052
4623
|
tokenBMint,
|
|
@@ -4058,7 +4629,8 @@ var Zap = class {
|
|
|
4058
4629
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4059
4630
|
cleanUpInstructions
|
|
4060
4631
|
};
|
|
4061
|
-
const
|
|
4632
|
+
const swapToA = yield buildJupiterSwapTransaction(
|
|
4633
|
+
this.connection,
|
|
4062
4634
|
user,
|
|
4063
4635
|
inputTokenMint,
|
|
4064
4636
|
tokenAMint,
|
|
@@ -4068,10 +4640,13 @@ var Zap = class {
|
|
|
4068
4640
|
void 0,
|
|
4069
4641
|
{
|
|
4070
4642
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4071
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4072
|
-
|
|
4643
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4644
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4645
|
+
},
|
|
4646
|
+
jupiterQuoteOptions
|
|
4073
4647
|
);
|
|
4074
|
-
const
|
|
4648
|
+
const swapToB = yield buildJupiterSwapTransaction(
|
|
4649
|
+
this.connection,
|
|
4075
4650
|
user,
|
|
4076
4651
|
inputTokenMint,
|
|
4077
4652
|
tokenBMint,
|
|
@@ -4081,20 +4656,26 @@ var Zap = class {
|
|
|
4081
4656
|
void 0,
|
|
4082
4657
|
{
|
|
4083
4658
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4084
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4085
|
-
|
|
4659
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4660
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4661
|
+
},
|
|
4662
|
+
jupiterQuoteOptions
|
|
4086
4663
|
);
|
|
4087
4664
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4088
4665
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4089
|
-
|
|
4666
|
+
swapToA.quoteResponse.outAmount,
|
|
4090
4667
|
maxTransferAmountExtendPercentage
|
|
4091
4668
|
),
|
|
4092
4669
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
4093
|
-
|
|
4670
|
+
swapToB.quoteResponse.outAmount,
|
|
4094
4671
|
maxTransferAmountExtendPercentage
|
|
4095
4672
|
),
|
|
4096
4673
|
swapType: 2 /* swapToBoth */,
|
|
4097
|
-
|
|
4674
|
+
swapInstructions: [swapToA.instruction, swapToB.instruction],
|
|
4675
|
+
addressLookupTableAccounts: mergeAddressLookupTableAccounts(
|
|
4676
|
+
swapToA.addressLookupTableAccounts,
|
|
4677
|
+
swapToB.addressLookupTableAccounts
|
|
4678
|
+
),
|
|
4098
4679
|
swapInEstimate: {
|
|
4099
4680
|
inAmountA: swapAmountToA,
|
|
4100
4681
|
inAmountB: swapAmountToB,
|
|
@@ -4109,7 +4690,12 @@ var Zap = class {
|
|
|
4109
4690
|
});
|
|
4110
4691
|
}
|
|
4111
4692
|
/**
|
|
4112
|
-
* 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.
|
|
4113
4699
|
*
|
|
4114
4700
|
* @param params.user - The user's public key
|
|
4115
4701
|
* @param params.pool - The pool's public key
|
|
@@ -4126,9 +4712,10 @@ var Zap = class {
|
|
|
4126
4712
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4127
4713
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4128
4714
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4129
|
-
* @param params.
|
|
4715
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
4716
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4130
4717
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4131
|
-
* @returns
|
|
4718
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4132
4719
|
*/
|
|
4133
4720
|
buildZapInDammV2Transaction(params) {
|
|
4134
4721
|
return __async(this, null, function* () {
|
|
@@ -4148,7 +4735,8 @@ var Zap = class {
|
|
|
4148
4735
|
preSqrtPrice,
|
|
4149
4736
|
maxSqrtPriceChangeBps,
|
|
4150
4737
|
preInstructions,
|
|
4151
|
-
|
|
4738
|
+
swapInstructions,
|
|
4739
|
+
addressLookupTableAccounts,
|
|
4152
4740
|
cleanUpInstructions
|
|
4153
4741
|
} = params;
|
|
4154
4742
|
const [
|
|
@@ -4172,37 +4760,33 @@ var Zap = class {
|
|
|
4172
4760
|
tokenBProgram
|
|
4173
4761
|
)
|
|
4174
4762
|
]);
|
|
4175
|
-
const
|
|
4176
|
-
initializeTokenAIx &&
|
|
4177
|
-
initializeTokenBIx &&
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
}
|
|
4181
|
-
const ledgerTransaction = new import_web38.Transaction();
|
|
4182
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4183
|
-
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);
|
|
4184
4768
|
if (isDirectPool) {
|
|
4185
4769
|
const isTokenA = params.isTokenA;
|
|
4186
|
-
const
|
|
4770
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4187
4771
|
user,
|
|
4188
4772
|
amount,
|
|
4189
4773
|
isTokenA
|
|
4190
4774
|
);
|
|
4191
|
-
|
|
4192
|
-
if (
|
|
4775
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4776
|
+
if (swapInstructions.length > 0) {
|
|
4193
4777
|
const tokenAccount = isTokenA ? tokenBAccount : tokenAAccount;
|
|
4194
4778
|
const preTokenBalance = yield getTokenAccountBalance(
|
|
4195
4779
|
this.connection,
|
|
4196
4780
|
tokenAccount
|
|
4197
4781
|
);
|
|
4198
|
-
const
|
|
4782
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4199
4783
|
user,
|
|
4200
4784
|
tokenAccount,
|
|
4201
|
-
new
|
|
4785
|
+
new import_core.BN(preTokenBalance),
|
|
4202
4786
|
params.maxTransferAmount,
|
|
4203
4787
|
!isTokenA
|
|
4204
4788
|
);
|
|
4205
|
-
|
|
4789
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4206
4790
|
}
|
|
4207
4791
|
} else {
|
|
4208
4792
|
const preTokenABalance = yield getTokenAccountBalance(
|
|
@@ -4213,32 +4797,35 @@ var Zap = class {
|
|
|
4213
4797
|
this.connection,
|
|
4214
4798
|
tokenBAccount
|
|
4215
4799
|
);
|
|
4216
|
-
const
|
|
4800
|
+
const updateLedgerBalanceTokenAAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4217
4801
|
user,
|
|
4218
4802
|
tokenAAccount,
|
|
4219
|
-
new
|
|
4803
|
+
new import_core.BN(preTokenABalance),
|
|
4220
4804
|
params.maxTransferAmountA,
|
|
4221
4805
|
true
|
|
4222
4806
|
// is token A
|
|
4223
4807
|
);
|
|
4224
|
-
const
|
|
4808
|
+
const updateLedgerBalanceTokenBAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4225
4809
|
user,
|
|
4226
4810
|
tokenBAccount,
|
|
4227
|
-
new
|
|
4811
|
+
new import_core.BN(preTokenBBalance),
|
|
4228
4812
|
params.maxTransferAmountB,
|
|
4229
4813
|
false
|
|
4230
4814
|
// isn't token A
|
|
4231
4815
|
);
|
|
4232
4816
|
const swapType = params.swapType;
|
|
4233
4817
|
if (swapType == 0 /* swapToA */) {
|
|
4234
|
-
|
|
4818
|
+
ledgerInstructions.push(updateLedgerBalanceTokenAAfterSwapIx);
|
|
4235
4819
|
} else if (swapType == 1 /* swapToB */) {
|
|
4236
|
-
|
|
4820
|
+
ledgerInstructions.push(updateLedgerBalanceTokenBAfterSwapIx);
|
|
4237
4821
|
} else {
|
|
4238
|
-
|
|
4822
|
+
ledgerInstructions.push(
|
|
4823
|
+
updateLedgerBalanceTokenAAfterSwapIx,
|
|
4824
|
+
updateLedgerBalanceTokenBAfterSwapIx
|
|
4825
|
+
);
|
|
4239
4826
|
}
|
|
4240
4827
|
}
|
|
4241
|
-
const
|
|
4828
|
+
const zapInInstruction = yield this.zapInDammV2({
|
|
4242
4829
|
user,
|
|
4243
4830
|
pool,
|
|
4244
4831
|
position,
|
|
@@ -4254,18 +4841,17 @@ var Zap = class {
|
|
|
4254
4841
|
tokenAAccount,
|
|
4255
4842
|
tokenBAccount
|
|
4256
4843
|
});
|
|
4257
|
-
const
|
|
4258
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4259
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4260
|
-
if (cleanUpInstructions.length > 0) {
|
|
4261
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4262
|
-
}
|
|
4844
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4263
4845
|
return {
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4268
|
-
|
|
4846
|
+
instructions: [
|
|
4847
|
+
...setupInstructions,
|
|
4848
|
+
...swapInstructions,
|
|
4849
|
+
...ledgerInstructions,
|
|
4850
|
+
zapInInstruction,
|
|
4851
|
+
closeLedgerInstruction,
|
|
4852
|
+
...cleanUpInstructions
|
|
4853
|
+
],
|
|
4854
|
+
addressLookupTableAccounts
|
|
4269
4855
|
};
|
|
4270
4856
|
});
|
|
4271
4857
|
}
|
|
@@ -4282,8 +4868,8 @@ var Zap = class {
|
|
|
4282
4868
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4283
4869
|
* @param params.strategy - The liquidity distribution strategy
|
|
4284
4870
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4285
|
-
* @param params.maxAccounts -
|
|
4286
|
-
* @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.
|
|
4287
4873
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4288
4874
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
4289
4875
|
* @param params.directSwapEstimate - The result from the direct swap estimate
|
|
@@ -4336,12 +4922,14 @@ var Zap = class {
|
|
|
4336
4922
|
initializeWrapSolIx && preInstructions.push(initializeWrapSolIx);
|
|
4337
4923
|
preInstructions.push(...wrapSOL);
|
|
4338
4924
|
}
|
|
4339
|
-
const
|
|
4925
|
+
const swapInstructions = [];
|
|
4926
|
+
let addressLookupTableAccounts = [];
|
|
4340
4927
|
let maxTransferAmount;
|
|
4341
4928
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4342
4929
|
const swapQuote = directSwapEstimate.quote;
|
|
4343
4930
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4344
|
-
const
|
|
4931
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
4932
|
+
this.connection,
|
|
4345
4933
|
user,
|
|
4346
4934
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4347
4935
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
@@ -4351,10 +4939,12 @@ var Zap = class {
|
|
|
4351
4939
|
swapQuote.originalQuote,
|
|
4352
4940
|
{
|
|
4353
4941
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4354
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4942
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4943
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4355
4944
|
}
|
|
4356
4945
|
);
|
|
4357
|
-
|
|
4946
|
+
swapInstructions.push(swap.instruction);
|
|
4947
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4358
4948
|
} else {
|
|
4359
4949
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4360
4950
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4367,6 +4957,9 @@ var Zap = class {
|
|
|
4367
4957
|
user,
|
|
4368
4958
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4369
4959
|
});
|
|
4960
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
4961
|
+
swapTx.instructions
|
|
4962
|
+
);
|
|
4370
4963
|
if (tokenXMint.equals(import_spl_token6.NATIVE_MINT) || tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4371
4964
|
swapTx.instructions = swapTx.instructions.filter((ix) => {
|
|
4372
4965
|
if (ix.programId.equals(import_spl_token6.TOKEN_PROGRAM_ID)) {
|
|
@@ -4375,14 +4968,14 @@ var Zap = class {
|
|
|
4375
4968
|
return true;
|
|
4376
4969
|
});
|
|
4377
4970
|
}
|
|
4378
|
-
|
|
4971
|
+
swapInstructions.push(...swapTx.instructions);
|
|
4379
4972
|
}
|
|
4380
4973
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
4381
4974
|
directSwapEstimate.expectedOutput.toString(),
|
|
4382
4975
|
maxTransferAmountExtendPercentage
|
|
4383
4976
|
);
|
|
4384
4977
|
} else {
|
|
4385
|
-
maxTransferAmount = new
|
|
4978
|
+
maxTransferAmount = new import_core.BN(0);
|
|
4386
4979
|
}
|
|
4387
4980
|
const amount = isTokenX ? directSwapEstimate.postSwapX : directSwapEstimate.postSwapY;
|
|
4388
4981
|
const cleanUpInstructions = [];
|
|
@@ -4392,8 +4985,8 @@ var Zap = class {
|
|
|
4392
4985
|
}
|
|
4393
4986
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4394
4987
|
lbPair,
|
|
4395
|
-
new
|
|
4396
|
-
new
|
|
4988
|
+
new import_core.BN(activeId + minDeltaId),
|
|
4989
|
+
new import_core.BN(activeId + maxDeltaId),
|
|
4397
4990
|
DLMM_PROGRAM_ID
|
|
4398
4991
|
).map((item) => ({
|
|
4399
4992
|
pubkey: item.key,
|
|
@@ -4425,7 +5018,8 @@ var Zap = class {
|
|
|
4425
5018
|
amount,
|
|
4426
5019
|
maxTransferAmount,
|
|
4427
5020
|
preInstructions,
|
|
4428
|
-
|
|
5021
|
+
swapInstructions,
|
|
5022
|
+
addressLookupTableAccounts,
|
|
4429
5023
|
cleanUpInstructions,
|
|
4430
5024
|
binArrays,
|
|
4431
5025
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4506,11 +5100,13 @@ var Zap = class {
|
|
|
4506
5100
|
}
|
|
4507
5101
|
let maxTransferAmountX;
|
|
4508
5102
|
let maxTransferAmountY;
|
|
4509
|
-
const
|
|
5103
|
+
const swapInstructions = [];
|
|
5104
|
+
const swapLookupTables = [];
|
|
4510
5105
|
const swapAmountToXInLamports = indirectSwapEstimate.swapAmountToX;
|
|
4511
5106
|
const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
|
|
4512
5107
|
if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
|
|
4513
|
-
const
|
|
5108
|
+
const swapToX = yield buildJupiterSwapTransaction(
|
|
5109
|
+
this.connection,
|
|
4514
5110
|
user,
|
|
4515
5111
|
inputTokenMint,
|
|
4516
5112
|
tokenXMint,
|
|
@@ -4520,13 +5116,16 @@ var Zap = class {
|
|
|
4520
5116
|
indirectSwapEstimate.swapToX,
|
|
4521
5117
|
{
|
|
4522
5118
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4523
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5119
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5120
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4524
5121
|
}
|
|
4525
5122
|
);
|
|
4526
|
-
|
|
5123
|
+
swapInstructions.push(swapToX.instruction);
|
|
5124
|
+
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
4527
5125
|
}
|
|
4528
5126
|
if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
|
|
4529
|
-
const
|
|
5127
|
+
const swapToY = yield buildJupiterSwapTransaction(
|
|
5128
|
+
this.connection,
|
|
4530
5129
|
user,
|
|
4531
5130
|
inputTokenMint,
|
|
4532
5131
|
tokenYMint,
|
|
@@ -4536,11 +5135,16 @@ var Zap = class {
|
|
|
4536
5135
|
indirectSwapEstimate.swapToY,
|
|
4537
5136
|
{
|
|
4538
5137
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4539
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5138
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5139
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4540
5140
|
}
|
|
4541
5141
|
);
|
|
4542
|
-
|
|
5142
|
+
swapInstructions.push(swapToY.instruction);
|
|
5143
|
+
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
4543
5144
|
}
|
|
5145
|
+
const addressLookupTableAccounts = mergeAddressLookupTableAccounts(
|
|
5146
|
+
...swapLookupTables
|
|
5147
|
+
);
|
|
4544
5148
|
maxTransferAmountX = getExtendMaxAmountTransfer(
|
|
4545
5149
|
indirectSwapEstimate.postSwapX.toString(),
|
|
4546
5150
|
maxTransferAmountExtendPercentage
|
|
@@ -4551,8 +5155,8 @@ var Zap = class {
|
|
|
4551
5155
|
);
|
|
4552
5156
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4553
5157
|
lbPair,
|
|
4554
|
-
new
|
|
4555
|
-
new
|
|
5158
|
+
new import_core.BN(activeId + minDeltaId),
|
|
5159
|
+
new import_core.BN(activeId + maxDeltaId),
|
|
4556
5160
|
DLMM_PROGRAM_ID
|
|
4557
5161
|
).map((item) => ({
|
|
4558
5162
|
pubkey: item.key,
|
|
@@ -4582,7 +5186,8 @@ var Zap = class {
|
|
|
4582
5186
|
maxTransferAmountX,
|
|
4583
5187
|
maxTransferAmountY,
|
|
4584
5188
|
preInstructions,
|
|
4585
|
-
|
|
5189
|
+
swapInstructions,
|
|
5190
|
+
addressLookupTableAccounts,
|
|
4586
5191
|
cleanUpInstructions,
|
|
4587
5192
|
binArrays,
|
|
4588
5193
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4592,7 +5197,12 @@ var Zap = class {
|
|
|
4592
5197
|
});
|
|
4593
5198
|
}
|
|
4594
5199
|
/**
|
|
4595
|
-
*
|
|
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.
|
|
4596
5206
|
*
|
|
4597
5207
|
* @param params.user - The user's public key
|
|
4598
5208
|
* @param params.lbPair - The DLMM pool's public key
|
|
@@ -4608,13 +5218,14 @@ var Zap = class {
|
|
|
4608
5218
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4609
5219
|
* @param params.strategy - The liquidity distribution strategy
|
|
4610
5220
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4611
|
-
* @param params.
|
|
5221
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
5222
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4612
5223
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4613
5224
|
* @param params.binArrays - The bin arrays required for the position
|
|
4614
5225
|
* @param params.binArrayBitmapExtension - The bin array bitmap extension account if it exists
|
|
4615
5226
|
* @param params.isDirectRoute - Whether this is a direct route
|
|
4616
5227
|
* @param params.singleSided - Optional single-sided deposit mode (X or Y only) - default is non-single-sided
|
|
4617
|
-
* @returns
|
|
5228
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4618
5229
|
*/
|
|
4619
5230
|
buildZapInDlmmTransaction(params) {
|
|
4620
5231
|
return __async(this, null, function* () {
|
|
@@ -4633,7 +5244,8 @@ var Zap = class {
|
|
|
4633
5244
|
favorXInActiveId,
|
|
4634
5245
|
strategy,
|
|
4635
5246
|
preInstructions,
|
|
4636
|
-
|
|
5247
|
+
swapInstructions,
|
|
5248
|
+
addressLookupTableAccounts,
|
|
4637
5249
|
cleanUpInstructions,
|
|
4638
5250
|
binArrays,
|
|
4639
5251
|
binArrayBitmapExtension,
|
|
@@ -4661,62 +5273,58 @@ var Zap = class {
|
|
|
4661
5273
|
tokenYProgram
|
|
4662
5274
|
)
|
|
4663
5275
|
]);
|
|
4664
|
-
const
|
|
4665
|
-
initializeTokenXIx &&
|
|
4666
|
-
initializeTokenYIx &&
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
}
|
|
4670
|
-
const ledgerTransaction = new import_web38.Transaction();
|
|
4671
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4672
|
-
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);
|
|
4673
5281
|
if (isDirectRoute) {
|
|
4674
5282
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
4675
5283
|
if (singleSided !== void 0) {
|
|
4676
5284
|
const singleSidedX = singleSided === 0 /* X */;
|
|
4677
|
-
if (
|
|
5285
|
+
if (swapInstructions.length > 0) {
|
|
4678
5286
|
const swappedTokenAccount = singleSidedX ? tokenXAccount : tokenYAccount;
|
|
4679
5287
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4680
5288
|
this.connection,
|
|
4681
5289
|
swappedTokenAccount
|
|
4682
5290
|
);
|
|
4683
|
-
const
|
|
5291
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4684
5292
|
user,
|
|
4685
5293
|
swappedTokenAccount,
|
|
4686
|
-
new
|
|
5294
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4687
5295
|
maxTransferAmount,
|
|
4688
5296
|
singleSidedX
|
|
4689
5297
|
);
|
|
4690
|
-
|
|
5298
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4691
5299
|
} else {
|
|
4692
|
-
const
|
|
5300
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4693
5301
|
user,
|
|
4694
5302
|
amount,
|
|
4695
5303
|
singleSidedX
|
|
4696
5304
|
);
|
|
4697
|
-
|
|
5305
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4698
5306
|
}
|
|
4699
5307
|
} else {
|
|
4700
|
-
const
|
|
5308
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4701
5309
|
user,
|
|
4702
5310
|
amount,
|
|
4703
5311
|
isTokenX
|
|
4704
5312
|
);
|
|
4705
|
-
|
|
4706
|
-
if (
|
|
5313
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
5314
|
+
if (swapInstructions.length > 0) {
|
|
4707
5315
|
const swappedTokenAccount = isTokenX ? tokenYAccount : tokenXAccount;
|
|
4708
5316
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4709
5317
|
this.connection,
|
|
4710
5318
|
swappedTokenAccount
|
|
4711
5319
|
);
|
|
4712
|
-
const
|
|
5320
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4713
5321
|
user,
|
|
4714
5322
|
swappedTokenAccount,
|
|
4715
|
-
new
|
|
5323
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4716
5324
|
maxTransferAmount,
|
|
4717
5325
|
!isTokenX
|
|
4718
5326
|
);
|
|
4719
|
-
|
|
5327
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4720
5328
|
}
|
|
4721
5329
|
}
|
|
4722
5330
|
} else {
|
|
@@ -4728,14 +5336,14 @@ var Zap = class {
|
|
|
4728
5336
|
this.connection,
|
|
4729
5337
|
swappedTokenAccount
|
|
4730
5338
|
);
|
|
4731
|
-
const
|
|
5339
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4732
5340
|
user,
|
|
4733
5341
|
swappedTokenAccount,
|
|
4734
|
-
new
|
|
5342
|
+
new import_core.BN(preSwappedTokenBalance),
|
|
4735
5343
|
singleSidedX ? maxTransferAmountX : maxTransferAmountY,
|
|
4736
5344
|
singleSidedX
|
|
4737
5345
|
);
|
|
4738
|
-
|
|
5346
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4739
5347
|
} else {
|
|
4740
5348
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
4741
5349
|
this.connection,
|
|
@@ -4745,22 +5353,22 @@ var Zap = class {
|
|
|
4745
5353
|
this.connection,
|
|
4746
5354
|
tokenYAccount
|
|
4747
5355
|
);
|
|
4748
|
-
const
|
|
5356
|
+
const updateLedgerBalanceTokenXAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4749
5357
|
user,
|
|
4750
5358
|
tokenXAccount,
|
|
4751
|
-
new
|
|
5359
|
+
new import_core.BN(preTokenXBalance),
|
|
4752
5360
|
maxTransferAmountX,
|
|
4753
5361
|
true
|
|
4754
5362
|
);
|
|
4755
|
-
const
|
|
5363
|
+
const updateLedgerBalanceTokenYAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4756
5364
|
user,
|
|
4757
5365
|
tokenYAccount,
|
|
4758
|
-
new
|
|
5366
|
+
new import_core.BN(preTokenYBalance),
|
|
4759
5367
|
maxTransferAmountY,
|
|
4760
5368
|
false
|
|
4761
5369
|
);
|
|
4762
|
-
|
|
4763
|
-
|
|
5370
|
+
ledgerInstructions.push(updateLedgerBalanceTokenXAfterSwapIx);
|
|
5371
|
+
ledgerInstructions.push(updateLedgerBalanceTokenYAfterSwapIx);
|
|
4764
5372
|
}
|
|
4765
5373
|
}
|
|
4766
5374
|
const dlmm = yield import_dlmm4.default.create(this.connection, lbPair);
|
|
@@ -4774,7 +5382,7 @@ var Zap = class {
|
|
|
4774
5382
|
tokenYProgram,
|
|
4775
5383
|
dlmm.lbPair
|
|
4776
5384
|
);
|
|
4777
|
-
const
|
|
5385
|
+
const zapInInstruction = yield this.zapInDlmmForUninitializedPosition({
|
|
4778
5386
|
user,
|
|
4779
5387
|
lbPair,
|
|
4780
5388
|
position,
|
|
@@ -4788,18 +5396,17 @@ var Zap = class {
|
|
|
4788
5396
|
strategy,
|
|
4789
5397
|
remainingAccountInfo
|
|
4790
5398
|
});
|
|
4791
|
-
const
|
|
4792
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4793
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4794
|
-
if (cleanUpInstructions.length > 0) {
|
|
4795
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4796
|
-
}
|
|
5399
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4797
5400
|
return {
|
|
4798
|
-
|
|
4799
|
-
|
|
4800
|
-
|
|
4801
|
-
|
|
4802
|
-
|
|
5401
|
+
instructions: [
|
|
5402
|
+
...setupInstructions,
|
|
5403
|
+
...swapInstructions,
|
|
5404
|
+
...ledgerInstructions,
|
|
5405
|
+
zapInInstruction,
|
|
5406
|
+
closeLedgerInstruction,
|
|
5407
|
+
...cleanUpInstructions
|
|
5408
|
+
],
|
|
5409
|
+
addressLookupTableAccounts
|
|
4803
5410
|
};
|
|
4804
5411
|
});
|
|
4805
5412
|
}
|
|
@@ -4807,6 +5414,13 @@ var Zap = class {
|
|
|
4807
5414
|
* High level method for DLMM position rebalancing
|
|
4808
5415
|
* Consist of remove liquidity, zap out through Jupiter or DLMM, and zap back in to rebalance the position
|
|
4809
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
|
+
*
|
|
4810
5424
|
* @param params - Rebalancing DLMM position parameters
|
|
4811
5425
|
* @param params.lbPairAddress - The DLMM pool address
|
|
4812
5426
|
* @param params.positionAddress - The position address
|
|
@@ -4819,7 +5433,7 @@ var Zap = class {
|
|
|
4819
5433
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4820
5434
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
4821
5435
|
* @param params.maxAccounts - The maximum number of accounts to use for the swap operation
|
|
4822
|
-
* @returns
|
|
5436
|
+
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
4823
5437
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
4824
5438
|
*/
|
|
4825
5439
|
rebalanceDlmmPosition(params) {
|
|
@@ -4861,18 +5475,18 @@ var Zap = class {
|
|
|
4861
5475
|
tokenYProgram
|
|
4862
5476
|
)
|
|
4863
5477
|
]);
|
|
4864
|
-
const
|
|
4865
|
-
userTokenXIx &&
|
|
4866
|
-
userTokenYIx &&
|
|
5478
|
+
const setupInstructions = [];
|
|
5479
|
+
userTokenXIx && setupInstructions.push(userTokenXIx);
|
|
5480
|
+
userTokenYIx && setupInstructions.push(userTokenYIx);
|
|
4867
5481
|
const strategyParamBuilder = (0, import_dlmm4.getLiquidityStrategyParameterBuilder)(strategy);
|
|
4868
5482
|
const { x0, y0, deltaX, deltaY } = (0, import_dlmm4.buildLiquidityStrategyParameters)(
|
|
4869
|
-
new
|
|
4870
|
-
new
|
|
4871
|
-
new
|
|
4872
|
-
new
|
|
4873
|
-
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),
|
|
4874
5488
|
favorXInActiveId,
|
|
4875
|
-
new
|
|
5489
|
+
new import_core.BN(dlmm.lbPair.activeId),
|
|
4876
5490
|
strategyParamBuilder
|
|
4877
5491
|
);
|
|
4878
5492
|
const { rebalancePosition, simulationResult } = yield dlmm.simulateRebalancePosition(
|
|
@@ -4888,16 +5502,16 @@ var Zap = class {
|
|
|
4888
5502
|
y0,
|
|
4889
5503
|
deltaX,
|
|
4890
5504
|
deltaY,
|
|
4891
|
-
minDeltaId: new
|
|
4892
|
-
maxDeltaId: new
|
|
5505
|
+
minDeltaId: new import_core.BN(minDeltaId),
|
|
5506
|
+
maxDeltaId: new import_core.BN(maxDeltaId),
|
|
4893
5507
|
favorXInActiveBin: favorXInActiveId
|
|
4894
5508
|
}
|
|
4895
5509
|
],
|
|
4896
5510
|
[
|
|
4897
5511
|
{
|
|
4898
|
-
minBinId: new
|
|
4899
|
-
maxBinId: new
|
|
4900
|
-
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)
|
|
4901
5515
|
// remove all liquidity
|
|
4902
5516
|
}
|
|
4903
5517
|
]
|
|
@@ -4912,21 +5526,25 @@ var Zap = class {
|
|
|
4912
5526
|
rebalancePositionInstruction: _rebalancePositionInstruction
|
|
4913
5527
|
} = yield dlmm.rebalancePosition(
|
|
4914
5528
|
{ simulationResult, rebalancePosition },
|
|
4915
|
-
new
|
|
5529
|
+
new import_core.BN(maxActiveBinSlippage)
|
|
5530
|
+
);
|
|
5531
|
+
let rebalancePositionInstruction = filterOutComputeBudgetInstructions(
|
|
5532
|
+
_rebalancePositionInstruction
|
|
4916
5533
|
);
|
|
4917
|
-
let rebalancePositionInstruction = _rebalancePositionInstruction;
|
|
4918
5534
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4919
5535
|
rebalancePositionInstruction = filterOutCloseSplTokenAccountInstructions(
|
|
4920
|
-
|
|
5536
|
+
rebalancePositionInstruction
|
|
4921
5537
|
);
|
|
4922
5538
|
}
|
|
4923
|
-
const tokenXAmount = new
|
|
4924
|
-
const tokenYAmount = new
|
|
4925
|
-
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 = [];
|
|
4926
5543
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4927
5544
|
const swapQuote = directSwapEstimate.quote;
|
|
4928
5545
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4929
|
-
const
|
|
5546
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
5547
|
+
this.connection,
|
|
4930
5548
|
user,
|
|
4931
5549
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
4932
5550
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
@@ -4936,10 +5554,12 @@ var Zap = class {
|
|
|
4936
5554
|
swapQuote.originalQuote,
|
|
4937
5555
|
{
|
|
4938
5556
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4939
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5557
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5558
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4940
5559
|
}
|
|
4941
5560
|
);
|
|
4942
|
-
|
|
5561
|
+
swapInstructions = [swap.instruction];
|
|
5562
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4943
5563
|
} else {
|
|
4944
5564
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4945
5565
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4952,12 +5572,15 @@ var Zap = class {
|
|
|
4952
5572
|
user,
|
|
4953
5573
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4954
5574
|
});
|
|
5575
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
5576
|
+
swapTx.instructions
|
|
5577
|
+
);
|
|
4955
5578
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
4956
5579
|
swapTx.instructions = filterOutCloseSplTokenAccountInstructions(
|
|
4957
5580
|
swapTx.instructions
|
|
4958
5581
|
);
|
|
4959
5582
|
}
|
|
4960
|
-
|
|
5583
|
+
swapInstructions = swapTx.instructions;
|
|
4961
5584
|
}
|
|
4962
5585
|
}
|
|
4963
5586
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
@@ -4972,31 +5595,31 @@ var Zap = class {
|
|
|
4972
5595
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4973
5596
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4974
5597
|
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4975
|
-
const
|
|
5598
|
+
const ledgerInstructions = [];
|
|
4976
5599
|
if (!ledgerAccountInfo) {
|
|
4977
|
-
const
|
|
4978
|
-
|
|
5600
|
+
const initLedgerIx = yield this.initializeLedgerAccount(user, user);
|
|
5601
|
+
ledgerInstructions.push(initLedgerIx);
|
|
4979
5602
|
}
|
|
4980
|
-
const
|
|
5603
|
+
const updateLedgerXIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4981
5604
|
user,
|
|
4982
5605
|
userTokenX,
|
|
4983
|
-
new
|
|
5606
|
+
new import_core.BN(preTokenXBalance),
|
|
4984
5607
|
tokenXAmountAfterSwap,
|
|
4985
5608
|
true
|
|
4986
5609
|
);
|
|
4987
|
-
|
|
4988
|
-
const
|
|
5610
|
+
ledgerInstructions.push(updateLedgerXIx);
|
|
5611
|
+
const updateLedgerYIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4989
5612
|
user,
|
|
4990
5613
|
userTokenY,
|
|
4991
|
-
new
|
|
5614
|
+
new import_core.BN(preTokenYBalance),
|
|
4992
5615
|
tokenYAmountAfterSwap,
|
|
4993
5616
|
false
|
|
4994
5617
|
);
|
|
4995
|
-
|
|
5618
|
+
ledgerInstructions.push(updateLedgerYIx);
|
|
4996
5619
|
const binArrays = (0, import_dlmm4.getBinArraysRequiredByPositionRange)(
|
|
4997
5620
|
lbPair,
|
|
4998
|
-
new
|
|
4999
|
-
new
|
|
5621
|
+
new import_core.BN(dlmm.lbPair.activeId + minDeltaId),
|
|
5622
|
+
new import_core.BN(dlmm.lbPair.activeId + maxDeltaId),
|
|
5000
5623
|
DLMM_PROGRAM_ID
|
|
5001
5624
|
).map((item) => ({
|
|
5002
5625
|
pubkey: item.key,
|
|
@@ -5013,7 +5636,7 @@ var Zap = class {
|
|
|
5013
5636
|
tokenYProgram,
|
|
5014
5637
|
dlmm.lbPair
|
|
5015
5638
|
);
|
|
5016
|
-
const
|
|
5639
|
+
const zapInInstruction = yield this.zapInDlmmForInitializedPosition({
|
|
5017
5640
|
user,
|
|
5018
5641
|
lbPair,
|
|
5019
5642
|
position,
|
|
@@ -5026,28 +5649,26 @@ var Zap = class {
|
|
|
5026
5649
|
strategy,
|
|
5027
5650
|
remainingAccountInfo
|
|
5028
5651
|
});
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
import_web38.ComputeBudgetProgram.setComputeUnitLimit({ units: 6e5 })
|
|
5033
|
-
);
|
|
5034
|
-
const cleanUpTransaction = new import_web38.Transaction();
|
|
5035
|
-
const closeLedgerTx = yield this.closeLedgerAccount(user, user);
|
|
5036
|
-
cleanUpTransaction.add(closeLedgerTx);
|
|
5652
|
+
const cleanUpInstructions = [
|
|
5653
|
+
yield this.closeLedgerAccount(user, user)
|
|
5654
|
+
];
|
|
5037
5655
|
if (dlmm.lbPair.tokenXMint.equals(import_spl_token6.NATIVE_MINT) || dlmm.lbPair.tokenYMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
5038
5656
|
const unwrapIx = unwrapSOLInstruction(user, user);
|
|
5039
5657
|
if (unwrapIx) {
|
|
5040
|
-
|
|
5658
|
+
cleanUpInstructions.push(unwrapIx);
|
|
5041
5659
|
}
|
|
5042
5660
|
}
|
|
5043
5661
|
return {
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5662
|
+
instructions: [
|
|
5663
|
+
...setupInstructions,
|
|
5664
|
+
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5665
|
+
...rebalancePositionInstruction,
|
|
5666
|
+
...swapInstructions,
|
|
5667
|
+
...ledgerInstructions,
|
|
5668
|
+
zapInInstruction,
|
|
5669
|
+
...cleanUpInstructions
|
|
5670
|
+
],
|
|
5671
|
+
addressLookupTableAccounts,
|
|
5051
5672
|
estimation: {
|
|
5052
5673
|
currentBalances: {
|
|
5053
5674
|
tokenX: tokenXAmount,
|
|
@@ -5073,7 +5694,7 @@ var Zap = class {
|
|
|
5073
5694
|
* @param params.ammProgram - AMM program ID to interact with
|
|
5074
5695
|
* @param params.preInstructions - Instructions to run before the zap out
|
|
5075
5696
|
* @param params.postInstructions - Instructions to run after the zap out
|
|
5076
|
-
* @returns
|
|
5697
|
+
* @returns The pre-instructions, the zap out instruction and the post-instructions in order, with no lookup tables
|
|
5077
5698
|
*/
|
|
5078
5699
|
zapOut(params) {
|
|
5079
5700
|
return __async(this, null, function* () {
|
|
@@ -5085,10 +5706,18 @@ var Zap = class {
|
|
|
5085
5706
|
preInstructions,
|
|
5086
5707
|
postInstructions
|
|
5087
5708
|
} = params;
|
|
5088
|
-
|
|
5709
|
+
const zapOutInstruction = yield this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
|
|
5089
5710
|
userTokenInAccount,
|
|
5090
5711
|
ammProgram
|
|
5091
|
-
}).remainingAccounts(remainingAccounts).
|
|
5712
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
5713
|
+
return {
|
|
5714
|
+
instructions: [
|
|
5715
|
+
...preInstructions,
|
|
5716
|
+
zapOutInstruction,
|
|
5717
|
+
...postInstructions
|
|
5718
|
+
],
|
|
5719
|
+
addressLookupTableAccounts: []
|
|
5720
|
+
};
|
|
5092
5721
|
});
|
|
5093
5722
|
}
|
|
5094
5723
|
/**
|
|
@@ -5099,12 +5728,12 @@ var Zap = class {
|
|
|
5099
5728
|
* @param params.user - Public key of the user performing the swap
|
|
5100
5729
|
* @param params.inputMint - Token mint being swapped from
|
|
5101
5730
|
* @param params.outputMint - Token mint being swapped to
|
|
5102
|
-
* @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)
|
|
5103
5732
|
* @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
|
|
5104
5733
|
* @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
|
|
5105
5734
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5106
5735
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5107
|
-
* @returns
|
|
5736
|
+
* @returns The ordered instructions and the lookup tables of the Jupiter swap
|
|
5108
5737
|
*/
|
|
5109
5738
|
zapOutThroughJupiter(params) {
|
|
5110
5739
|
return __async(this, null, function* () {
|
|
@@ -5122,7 +5751,7 @@ var Zap = class {
|
|
|
5122
5751
|
const postInstructions = [];
|
|
5123
5752
|
const [
|
|
5124
5753
|
{ ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
|
|
5125
|
-
{
|
|
5754
|
+
{ ix: outputTokenAccountIx }
|
|
5126
5755
|
] = yield Promise.all([
|
|
5127
5756
|
getOrCreateATAInstruction(
|
|
5128
5757
|
this.connection,
|
|
@@ -5166,27 +5795,36 @@ var Zap = class {
|
|
|
5166
5795
|
jupiterSwapResponse.swapInstruction.data,
|
|
5167
5796
|
"base64"
|
|
5168
5797
|
);
|
|
5169
|
-
const offsetAmountIn =
|
|
5798
|
+
const offsetAmountIn = getJupiterInstructionLayout(
|
|
5799
|
+
payloadData
|
|
5800
|
+
).amountInOffset(payloadData.length);
|
|
5170
5801
|
if (inputMint.equals(import_spl_token6.NATIVE_MINT) || outputMint.equals(import_spl_token6.NATIVE_MINT)) {
|
|
5171
5802
|
const unwrapInstructions = unwrapSOLInstruction(user, user);
|
|
5172
5803
|
if (unwrapInstructions) {
|
|
5173
5804
|
postInstructions.push(unwrapInstructions);
|
|
5174
5805
|
}
|
|
5175
5806
|
}
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5185
|
-
|
|
5186
|
-
|
|
5187
|
-
|
|
5188
|
-
|
|
5189
|
-
|
|
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 };
|
|
5190
5828
|
});
|
|
5191
5829
|
}
|
|
5192
5830
|
/**
|
|
@@ -5202,6 +5840,7 @@ var Zap = class {
|
|
|
5202
5840
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5203
5841
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5204
5842
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5843
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5205
5844
|
*/
|
|
5206
5845
|
zapOutThroughDammV2(params) {
|
|
5207
5846
|
return __async(this, null, function* () {
|
|
@@ -5274,7 +5913,7 @@ var Zap = class {
|
|
|
5274
5913
|
zapOutParams: {
|
|
5275
5914
|
percentage: percentageToZapOut,
|
|
5276
5915
|
offsetAmountIn,
|
|
5277
|
-
preUserTokenBalance: new
|
|
5916
|
+
preUserTokenBalance: new import_core.BN(preUserTokenBalance),
|
|
5278
5917
|
maxSwapAmount,
|
|
5279
5918
|
payloadData
|
|
5280
5919
|
},
|
|
@@ -5298,6 +5937,7 @@ var Zap = class {
|
|
|
5298
5937
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5299
5938
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5300
5939
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5940
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5301
5941
|
*/
|
|
5302
5942
|
zapOutThroughDlmm(params) {
|
|
5303
5943
|
return __async(this, null, function* () {
|
|
@@ -5374,7 +6014,7 @@ var Zap = class {
|
|
|
5374
6014
|
zapOutParams: {
|
|
5375
6015
|
percentage: percentageToZapOut,
|
|
5376
6016
|
offsetAmountIn: AMOUNT_IN_DLMM_OFFSET,
|
|
5377
|
-
preUserTokenBalance: new
|
|
6017
|
+
preUserTokenBalance: new import_core.BN(preUserTokenBalance),
|
|
5378
6018
|
maxSwapAmount,
|
|
5379
6019
|
payloadData
|
|
5380
6020
|
},
|
|
@@ -5396,12 +6036,20 @@ var Zap = class {
|
|
|
5396
6036
|
DAMM_V2_PROGRAM_ID,
|
|
5397
6037
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
5398
6038
|
DEFAULT_JUPITER_API_URL,
|
|
6039
|
+
DEFAULT_JUPITER_API_VERSION,
|
|
6040
|
+
DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
5399
6041
|
DLMM_PROGRAM_ID,
|
|
5400
6042
|
DLMM_SWAP_DISCRIMINATOR,
|
|
5401
6043
|
DlmmDirectSwapQuoteRoute,
|
|
5402
6044
|
DlmmSingleSided,
|
|
5403
6045
|
DlmmSwapType,
|
|
6046
|
+
JUPITER_INSTRUCTION_LAYOUTS,
|
|
5404
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,
|
|
5405
6053
|
MEMO_PROGRAM_ID,
|
|
5406
6054
|
SwapExternalType,
|
|
5407
6055
|
ZAP_PROGRAM_ID,
|
|
@@ -5421,13 +6069,17 @@ var Zap = class {
|
|
|
5421
6069
|
estimateDlmmDirectSwap,
|
|
5422
6070
|
estimateDlmmIndirectSwap,
|
|
5423
6071
|
estimateDlmmRebalanceSwap,
|
|
6072
|
+
fetchAddressLookupTableAccounts,
|
|
5424
6073
|
filterOutCloseSplTokenAccountInstructions,
|
|
6074
|
+
filterOutComputeBudgetInstructions,
|
|
5425
6075
|
getBinArrayBitmapExtension,
|
|
5426
6076
|
getBitFromBinArrayIndexInBitmapExtension,
|
|
5427
6077
|
getDammV2Pool,
|
|
5428
6078
|
getDammV2RemainingAccounts,
|
|
5429
6079
|
getDlmmRemainingAccounts,
|
|
5430
6080
|
getExtraAccountMetasForTransferHook,
|
|
6081
|
+
getJupiterAddressLookupTableAccounts,
|
|
6082
|
+
getJupiterInstructionLayout,
|
|
5431
6083
|
getJupiterQuote,
|
|
5432
6084
|
getJupiterSwapInstruction,
|
|
5433
6085
|
getLbPairState,
|
|
@@ -5435,8 +6087,13 @@ var Zap = class {
|
|
|
5435
6087
|
getOrCreateATAInstruction,
|
|
5436
6088
|
getTokenAccountBalance,
|
|
5437
6089
|
getTokenProgramFromMint,
|
|
6090
|
+
isJupiterBuildResponse,
|
|
6091
|
+
isJupiterSwapInstructionForUser,
|
|
5438
6092
|
isSingleSidedA,
|
|
5439
6093
|
isSingleSidedB,
|
|
6094
|
+
mergeAddressLookupTableAccounts,
|
|
6095
|
+
resolveJupiterConfig,
|
|
6096
|
+
toAddressLookupTableAccounts,
|
|
5440
6097
|
toProgramStrategyType,
|
|
5441
6098
|
unwrapSOLInstruction,
|
|
5442
6099
|
wrapSOLInstruction
|