@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.mjs
CHANGED
|
@@ -40,27 +40,34 @@ var __async = (__this, __arguments, generator) => {
|
|
|
40
40
|
|
|
41
41
|
// src/zap.ts
|
|
42
42
|
import {
|
|
43
|
-
ComputeBudgetProgram,
|
|
44
43
|
PublicKey as PublicKey8,
|
|
45
|
-
SystemProgram as SystemProgram2
|
|
46
|
-
Transaction as Transaction2
|
|
44
|
+
SystemProgram as SystemProgram2
|
|
47
45
|
} from "@solana/web3.js";
|
|
48
46
|
import invariant2 from "invariant";
|
|
49
|
-
import { BN as BN5, Program } from "@
|
|
47
|
+
import { BN as BN5, Program } from "@anchor-lang/core";
|
|
50
48
|
|
|
51
49
|
// src/idl/zap/idl.json
|
|
52
50
|
var idl_default = {
|
|
53
51
|
address: "zapvX9M3uf5pvy4wRPAbQgdQsM1xmuiFnkfHKPvwMiz",
|
|
54
52
|
metadata: {
|
|
55
53
|
name: "zap",
|
|
56
|
-
version: "0.2.
|
|
54
|
+
version: "0.2.3",
|
|
57
55
|
spec: "0.1.0",
|
|
58
56
|
description: "Created with Anchor"
|
|
59
57
|
},
|
|
60
58
|
instructions: [
|
|
61
59
|
{
|
|
62
60
|
name: "close_ledger_account",
|
|
63
|
-
discriminator: [
|
|
61
|
+
discriminator: [
|
|
62
|
+
189,
|
|
63
|
+
122,
|
|
64
|
+
172,
|
|
65
|
+
13,
|
|
66
|
+
122,
|
|
67
|
+
54,
|
|
68
|
+
54,
|
|
69
|
+
51
|
|
70
|
+
],
|
|
64
71
|
accounts: [
|
|
65
72
|
{
|
|
66
73
|
name: "ledger",
|
|
@@ -69,7 +76,9 @@ var idl_default = {
|
|
|
69
76
|
{
|
|
70
77
|
name: "owner",
|
|
71
78
|
signer: true,
|
|
72
|
-
relations: [
|
|
79
|
+
relations: [
|
|
80
|
+
"ledger"
|
|
81
|
+
]
|
|
73
82
|
},
|
|
74
83
|
{
|
|
75
84
|
name: "rent_receiver",
|
|
@@ -81,7 +90,16 @@ var idl_default = {
|
|
|
81
90
|
},
|
|
82
91
|
{
|
|
83
92
|
name: "initialize_ledger_account",
|
|
84
|
-
discriminator: [
|
|
93
|
+
discriminator: [
|
|
94
|
+
120,
|
|
95
|
+
69,
|
|
96
|
+
30,
|
|
97
|
+
74,
|
|
98
|
+
76,
|
|
99
|
+
242,
|
|
100
|
+
153,
|
|
101
|
+
162
|
|
102
|
+
],
|
|
85
103
|
accounts: [
|
|
86
104
|
{
|
|
87
105
|
name: "ledger",
|
|
@@ -90,7 +108,19 @@ var idl_default = {
|
|
|
90
108
|
seeds: [
|
|
91
109
|
{
|
|
92
110
|
kind: "const",
|
|
93
|
-
value: [
|
|
111
|
+
value: [
|
|
112
|
+
117,
|
|
113
|
+
115,
|
|
114
|
+
101,
|
|
115
|
+
114,
|
|
116
|
+
95,
|
|
117
|
+
108,
|
|
118
|
+
101,
|
|
119
|
+
100,
|
|
120
|
+
103,
|
|
121
|
+
101,
|
|
122
|
+
114
|
|
123
|
+
]
|
|
94
124
|
},
|
|
95
125
|
{
|
|
96
126
|
kind: "account",
|
|
@@ -117,7 +147,16 @@ var idl_default = {
|
|
|
117
147
|
},
|
|
118
148
|
{
|
|
119
149
|
name: "set_ledger_balance",
|
|
120
|
-
discriminator: [
|
|
150
|
+
discriminator: [
|
|
151
|
+
131,
|
|
152
|
+
49,
|
|
153
|
+
240,
|
|
154
|
+
17,
|
|
155
|
+
228,
|
|
156
|
+
248,
|
|
157
|
+
156,
|
|
158
|
+
54
|
|
159
|
+
],
|
|
121
160
|
accounts: [
|
|
122
161
|
{
|
|
123
162
|
name: "ledger",
|
|
@@ -126,7 +165,9 @@ var idl_default = {
|
|
|
126
165
|
{
|
|
127
166
|
name: "owner",
|
|
128
167
|
signer: true,
|
|
129
|
-
relations: [
|
|
168
|
+
relations: [
|
|
169
|
+
"ledger"
|
|
170
|
+
]
|
|
130
171
|
}
|
|
131
172
|
],
|
|
132
173
|
args: [
|
|
@@ -142,7 +183,16 @@ var idl_default = {
|
|
|
142
183
|
},
|
|
143
184
|
{
|
|
144
185
|
name: "update_ledger_balance_after_swap",
|
|
145
|
-
discriminator: [
|
|
186
|
+
discriminator: [
|
|
187
|
+
59,
|
|
188
|
+
206,
|
|
189
|
+
173,
|
|
190
|
+
232,
|
|
191
|
+
94,
|
|
192
|
+
57,
|
|
193
|
+
174,
|
|
194
|
+
202
|
|
195
|
+
],
|
|
146
196
|
accounts: [
|
|
147
197
|
{
|
|
148
198
|
name: "ledger",
|
|
@@ -154,7 +204,9 @@ var idl_default = {
|
|
|
154
204
|
{
|
|
155
205
|
name: "owner",
|
|
156
206
|
signer: true,
|
|
157
|
-
relations: [
|
|
207
|
+
relations: [
|
|
208
|
+
"ledger"
|
|
209
|
+
]
|
|
158
210
|
}
|
|
159
211
|
],
|
|
160
212
|
args: [
|
|
@@ -174,7 +226,16 @@ var idl_default = {
|
|
|
174
226
|
},
|
|
175
227
|
{
|
|
176
228
|
name: "zap_in_damm_v2",
|
|
177
|
-
discriminator: [
|
|
229
|
+
discriminator: [
|
|
230
|
+
243,
|
|
231
|
+
243,
|
|
232
|
+
119,
|
|
233
|
+
52,
|
|
234
|
+
199,
|
|
235
|
+
44,
|
|
236
|
+
154,
|
|
237
|
+
186
|
|
238
|
+
],
|
|
178
239
|
accounts: [
|
|
179
240
|
{
|
|
180
241
|
name: "ledger",
|
|
@@ -218,9 +279,13 @@ var idl_default = {
|
|
|
218
279
|
},
|
|
219
280
|
{
|
|
220
281
|
name: "owner",
|
|
221
|
-
docs: [
|
|
282
|
+
docs: [
|
|
283
|
+
"owner of position"
|
|
284
|
+
],
|
|
222
285
|
signer: true,
|
|
223
|
-
relations: [
|
|
286
|
+
relations: [
|
|
287
|
+
"ledger"
|
|
288
|
+
]
|
|
224
289
|
},
|
|
225
290
|
{
|
|
226
291
|
name: "token_a_program"
|
|
@@ -249,7 +314,16 @@ var idl_default = {
|
|
|
249
314
|
},
|
|
250
315
|
{
|
|
251
316
|
name: "zap_in_dlmm_for_initialized_position",
|
|
252
|
-
discriminator: [
|
|
317
|
+
discriminator: [
|
|
318
|
+
184,
|
|
319
|
+
71,
|
|
320
|
+
198,
|
|
321
|
+
231,
|
|
322
|
+
129,
|
|
323
|
+
110,
|
|
324
|
+
193,
|
|
325
|
+
67
|
|
326
|
+
],
|
|
253
327
|
accounts: [
|
|
254
328
|
{
|
|
255
329
|
name: "ledger",
|
|
@@ -257,7 +331,9 @@ var idl_default = {
|
|
|
257
331
|
},
|
|
258
332
|
{
|
|
259
333
|
name: "lb_pair",
|
|
260
|
-
docs: [
|
|
334
|
+
docs: [
|
|
335
|
+
"lb pair"
|
|
336
|
+
],
|
|
261
337
|
writable: true
|
|
262
338
|
},
|
|
263
339
|
{
|
|
@@ -297,9 +373,13 @@ var idl_default = {
|
|
|
297
373
|
},
|
|
298
374
|
{
|
|
299
375
|
name: "owner",
|
|
300
|
-
docs: [
|
|
376
|
+
docs: [
|
|
377
|
+
"owner of position"
|
|
378
|
+
],
|
|
301
379
|
signer: true,
|
|
302
|
-
relations: [
|
|
380
|
+
relations: [
|
|
381
|
+
"ledger"
|
|
382
|
+
]
|
|
303
383
|
},
|
|
304
384
|
{
|
|
305
385
|
name: "rent_payer",
|
|
@@ -363,7 +443,16 @@ var idl_default = {
|
|
|
363
443
|
},
|
|
364
444
|
{
|
|
365
445
|
name: "zap_in_dlmm_for_uninitialized_position",
|
|
366
|
-
discriminator: [
|
|
446
|
+
discriminator: [
|
|
447
|
+
59,
|
|
448
|
+
220,
|
|
449
|
+
182,
|
|
450
|
+
27,
|
|
451
|
+
254,
|
|
452
|
+
253,
|
|
453
|
+
2,
|
|
454
|
+
232
|
|
455
|
+
],
|
|
367
456
|
accounts: [
|
|
368
457
|
{
|
|
369
458
|
name: "ledger",
|
|
@@ -371,7 +460,9 @@ var idl_default = {
|
|
|
371
460
|
},
|
|
372
461
|
{
|
|
373
462
|
name: "lb_pair",
|
|
374
|
-
docs: [
|
|
463
|
+
docs: [
|
|
464
|
+
"lb pair"
|
|
465
|
+
],
|
|
375
466
|
writable: true
|
|
376
467
|
},
|
|
377
468
|
{
|
|
@@ -416,9 +507,13 @@ var idl_default = {
|
|
|
416
507
|
},
|
|
417
508
|
{
|
|
418
509
|
name: "owner",
|
|
419
|
-
docs: [
|
|
510
|
+
docs: [
|
|
511
|
+
"owner of position"
|
|
512
|
+
],
|
|
420
513
|
signer: true,
|
|
421
|
-
relations: [
|
|
514
|
+
relations: [
|
|
515
|
+
"ledger"
|
|
516
|
+
]
|
|
422
517
|
},
|
|
423
518
|
{
|
|
424
519
|
name: "rent_payer",
|
|
@@ -482,7 +577,16 @@ var idl_default = {
|
|
|
482
577
|
},
|
|
483
578
|
{
|
|
484
579
|
name: "zap_out",
|
|
485
|
-
discriminator: [
|
|
580
|
+
discriminator: [
|
|
581
|
+
155,
|
|
582
|
+
108,
|
|
583
|
+
185,
|
|
584
|
+
112,
|
|
585
|
+
104,
|
|
586
|
+
210,
|
|
587
|
+
161,
|
|
588
|
+
64
|
|
589
|
+
],
|
|
486
590
|
accounts: [
|
|
487
591
|
{
|
|
488
592
|
name: "user_token_in_account",
|
|
@@ -505,17 +609,18 @@ var idl_default = {
|
|
|
505
609
|
}
|
|
506
610
|
],
|
|
507
611
|
accounts: [
|
|
508
|
-
{
|
|
509
|
-
name: "LbPair",
|
|
510
|
-
discriminator: [33, 11, 49, 98, 181, 101, 177, 13]
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
name: "Pool",
|
|
514
|
-
discriminator: [241, 154, 109, 4, 17, 177, 109, 188]
|
|
515
|
-
},
|
|
516
612
|
{
|
|
517
613
|
name: "UserLedger",
|
|
518
|
-
discriminator: [
|
|
614
|
+
discriminator: [
|
|
615
|
+
185,
|
|
616
|
+
84,
|
|
617
|
+
101,
|
|
618
|
+
128,
|
|
619
|
+
8,
|
|
620
|
+
6,
|
|
621
|
+
160,
|
|
622
|
+
83
|
|
623
|
+
]
|
|
519
624
|
}
|
|
520
625
|
],
|
|
521
626
|
errors: [
|
|
@@ -582,7 +687,9 @@ var idl_default = {
|
|
|
582
687
|
},
|
|
583
688
|
{
|
|
584
689
|
name: "TransferHookMultiReward",
|
|
585
|
-
fields: [
|
|
690
|
+
fields: [
|
|
691
|
+
"u8"
|
|
692
|
+
]
|
|
586
693
|
},
|
|
587
694
|
{
|
|
588
695
|
name: "TransferHookReferral"
|
|
@@ -591,7 +698,7 @@ var idl_default = {
|
|
|
591
698
|
}
|
|
592
699
|
},
|
|
593
700
|
{
|
|
594
|
-
name: "
|
|
701
|
+
name: "BaseFeeInfo",
|
|
595
702
|
serialization: "bytemuck",
|
|
596
703
|
repr: {
|
|
597
704
|
kind: "c"
|
|
@@ -600,33 +707,34 @@ var idl_default = {
|
|
|
600
707
|
kind: "struct",
|
|
601
708
|
fields: [
|
|
602
709
|
{
|
|
603
|
-
name: "
|
|
604
|
-
type: "u64"
|
|
605
|
-
},
|
|
606
|
-
{
|
|
607
|
-
name: "base_fee_mode",
|
|
608
|
-
type: "u8"
|
|
609
|
-
},
|
|
610
|
-
{
|
|
611
|
-
name: "padding_0",
|
|
710
|
+
name: "data",
|
|
612
711
|
type: {
|
|
613
|
-
array: [
|
|
712
|
+
array: [
|
|
713
|
+
"u8",
|
|
714
|
+
32
|
|
715
|
+
]
|
|
614
716
|
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
717
|
+
}
|
|
718
|
+
]
|
|
719
|
+
}
|
|
720
|
+
},
|
|
721
|
+
{
|
|
722
|
+
name: "BaseFeeStruct",
|
|
723
|
+
serialization: "bytemuck",
|
|
724
|
+
repr: {
|
|
725
|
+
kind: "c"
|
|
726
|
+
},
|
|
727
|
+
type: {
|
|
728
|
+
kind: "struct",
|
|
729
|
+
fields: [
|
|
620
730
|
{
|
|
621
|
-
name: "
|
|
731
|
+
name: "base_fee_info",
|
|
622
732
|
type: {
|
|
623
|
-
|
|
733
|
+
defined: {
|
|
734
|
+
name: "BaseFeeInfo"
|
|
735
|
+
}
|
|
624
736
|
}
|
|
625
737
|
},
|
|
626
|
-
{
|
|
627
|
-
name: "third_factor",
|
|
628
|
-
type: "u64"
|
|
629
|
-
},
|
|
630
738
|
{
|
|
631
739
|
name: "padding_1",
|
|
632
740
|
type: "u64"
|
|
@@ -650,7 +758,10 @@ var idl_default = {
|
|
|
650
758
|
{
|
|
651
759
|
name: "padding",
|
|
652
760
|
type: {
|
|
653
|
-
array: [
|
|
761
|
+
array: [
|
|
762
|
+
"u8",
|
|
763
|
+
7
|
|
764
|
+
]
|
|
654
765
|
}
|
|
655
766
|
},
|
|
656
767
|
{
|
|
@@ -728,13 +839,19 @@ var idl_default = {
|
|
|
728
839
|
{
|
|
729
840
|
name: "bump_seed",
|
|
730
841
|
type: {
|
|
731
|
-
array: [
|
|
842
|
+
array: [
|
|
843
|
+
"u8",
|
|
844
|
+
1
|
|
845
|
+
]
|
|
732
846
|
}
|
|
733
847
|
},
|
|
734
848
|
{
|
|
735
849
|
name: "bin_step_seed",
|
|
736
850
|
type: {
|
|
737
|
-
array: [
|
|
851
|
+
array: [
|
|
852
|
+
"u8",
|
|
853
|
+
2
|
|
854
|
+
]
|
|
738
855
|
}
|
|
739
856
|
},
|
|
740
857
|
{
|
|
@@ -760,7 +877,10 @@ var idl_default = {
|
|
|
760
877
|
{
|
|
761
878
|
name: "base_factor_seed",
|
|
762
879
|
type: {
|
|
763
|
-
array: [
|
|
880
|
+
array: [
|
|
881
|
+
"u8",
|
|
882
|
+
2
|
|
883
|
+
]
|
|
764
884
|
}
|
|
765
885
|
},
|
|
766
886
|
{
|
|
@@ -798,7 +918,10 @@ var idl_default = {
|
|
|
798
918
|
{
|
|
799
919
|
name: "_padding_1",
|
|
800
920
|
type: {
|
|
801
|
-
array: [
|
|
921
|
+
array: [
|
|
922
|
+
"u8",
|
|
923
|
+
32
|
|
924
|
+
]
|
|
802
925
|
}
|
|
803
926
|
},
|
|
804
927
|
{
|
|
@@ -821,7 +944,10 @@ var idl_default = {
|
|
|
821
944
|
{
|
|
822
945
|
name: "bin_array_bitmap",
|
|
823
946
|
type: {
|
|
824
|
-
array: [
|
|
947
|
+
array: [
|
|
948
|
+
"u64",
|
|
949
|
+
16
|
|
950
|
+
]
|
|
825
951
|
}
|
|
826
952
|
},
|
|
827
953
|
{
|
|
@@ -831,7 +957,10 @@ var idl_default = {
|
|
|
831
957
|
{
|
|
832
958
|
name: "_padding_2",
|
|
833
959
|
type: {
|
|
834
|
-
array: [
|
|
960
|
+
array: [
|
|
961
|
+
"u8",
|
|
962
|
+
32
|
|
963
|
+
]
|
|
835
964
|
}
|
|
836
965
|
},
|
|
837
966
|
{
|
|
@@ -853,7 +982,10 @@ var idl_default = {
|
|
|
853
982
|
{
|
|
854
983
|
name: "_padding_3",
|
|
855
984
|
type: {
|
|
856
|
-
array: [
|
|
985
|
+
array: [
|
|
986
|
+
"u8",
|
|
987
|
+
8
|
|
988
|
+
]
|
|
857
989
|
}
|
|
858
990
|
},
|
|
859
991
|
{
|
|
@@ -872,10 +1004,17 @@ var idl_default = {
|
|
|
872
1004
|
name: "token_mint_y_program_flag",
|
|
873
1005
|
type: "u8"
|
|
874
1006
|
},
|
|
1007
|
+
{
|
|
1008
|
+
name: "version",
|
|
1009
|
+
type: "u8"
|
|
1010
|
+
},
|
|
875
1011
|
{
|
|
876
1012
|
name: "_reserved",
|
|
877
1013
|
type: {
|
|
878
|
-
array: [
|
|
1014
|
+
array: [
|
|
1015
|
+
"u8",
|
|
1016
|
+
21
|
|
1017
|
+
]
|
|
879
1018
|
}
|
|
880
1019
|
}
|
|
881
1020
|
]
|
|
@@ -892,7 +1031,9 @@ var idl_default = {
|
|
|
892
1031
|
fields: [
|
|
893
1032
|
{
|
|
894
1033
|
name: "pool_fees",
|
|
895
|
-
docs: [
|
|
1034
|
+
docs: [
|
|
1035
|
+
"Pool fee"
|
|
1036
|
+
],
|
|
896
1037
|
type: {
|
|
897
1038
|
defined: {
|
|
898
1039
|
name: "PoolFeesStruct"
|
|
@@ -901,22 +1042,30 @@ var idl_default = {
|
|
|
901
1042
|
},
|
|
902
1043
|
{
|
|
903
1044
|
name: "token_a_mint",
|
|
904
|
-
docs: [
|
|
1045
|
+
docs: [
|
|
1046
|
+
"token a mint"
|
|
1047
|
+
],
|
|
905
1048
|
type: "pubkey"
|
|
906
1049
|
},
|
|
907
1050
|
{
|
|
908
1051
|
name: "token_b_mint",
|
|
909
|
-
docs: [
|
|
1052
|
+
docs: [
|
|
1053
|
+
"token b mint"
|
|
1054
|
+
],
|
|
910
1055
|
type: "pubkey"
|
|
911
1056
|
},
|
|
912
1057
|
{
|
|
913
1058
|
name: "token_a_vault",
|
|
914
|
-
docs: [
|
|
1059
|
+
docs: [
|
|
1060
|
+
"token a vault"
|
|
1061
|
+
],
|
|
915
1062
|
type: "pubkey"
|
|
916
1063
|
},
|
|
917
1064
|
{
|
|
918
1065
|
name: "token_b_vault",
|
|
919
|
-
docs: [
|
|
1066
|
+
docs: [
|
|
1067
|
+
"token b vault"
|
|
1068
|
+
],
|
|
920
1069
|
type: "pubkey"
|
|
921
1070
|
},
|
|
922
1071
|
{
|
|
@@ -927,17 +1076,26 @@ var idl_default = {
|
|
|
927
1076
|
type: "pubkey"
|
|
928
1077
|
},
|
|
929
1078
|
{
|
|
930
|
-
name: "
|
|
931
|
-
docs: [
|
|
932
|
-
|
|
1079
|
+
name: "padding_0",
|
|
1080
|
+
docs: [
|
|
1081
|
+
"padding, previously partner pubkey, be careful when using this field"
|
|
1082
|
+
],
|
|
1083
|
+
type: {
|
|
1084
|
+
array: [
|
|
1085
|
+
"u8",
|
|
1086
|
+
32
|
|
1087
|
+
]
|
|
1088
|
+
}
|
|
933
1089
|
},
|
|
934
1090
|
{
|
|
935
1091
|
name: "liquidity",
|
|
936
|
-
docs: [
|
|
1092
|
+
docs: [
|
|
1093
|
+
"liquidity share"
|
|
1094
|
+
],
|
|
937
1095
|
type: "u128"
|
|
938
1096
|
},
|
|
939
1097
|
{
|
|
940
|
-
name: "
|
|
1098
|
+
name: "padding_1",
|
|
941
1099
|
docs: [
|
|
942
1100
|
"padding, previous reserve amount, be careful to use that field"
|
|
943
1101
|
],
|
|
@@ -945,100 +1103,128 @@ var idl_default = {
|
|
|
945
1103
|
},
|
|
946
1104
|
{
|
|
947
1105
|
name: "protocol_a_fee",
|
|
948
|
-
docs: [
|
|
1106
|
+
docs: [
|
|
1107
|
+
"protocol a fee"
|
|
1108
|
+
],
|
|
949
1109
|
type: "u64"
|
|
950
1110
|
},
|
|
951
1111
|
{
|
|
952
1112
|
name: "protocol_b_fee",
|
|
953
|
-
docs: [
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
{
|
|
957
|
-
name: "partner_a_fee",
|
|
958
|
-
docs: ["partner a fee"],
|
|
1113
|
+
docs: [
|
|
1114
|
+
"protocol b fee"
|
|
1115
|
+
],
|
|
959
1116
|
type: "u64"
|
|
960
1117
|
},
|
|
961
1118
|
{
|
|
962
|
-
name: "
|
|
963
|
-
|
|
964
|
-
type: "u64"
|
|
1119
|
+
name: "padding_2",
|
|
1120
|
+
type: "u128"
|
|
965
1121
|
},
|
|
966
1122
|
{
|
|
967
1123
|
name: "sqrt_min_price",
|
|
968
|
-
docs: [
|
|
1124
|
+
docs: [
|
|
1125
|
+
"min price"
|
|
1126
|
+
],
|
|
969
1127
|
type: "u128"
|
|
970
1128
|
},
|
|
971
1129
|
{
|
|
972
1130
|
name: "sqrt_max_price",
|
|
973
|
-
docs: [
|
|
1131
|
+
docs: [
|
|
1132
|
+
"max price"
|
|
1133
|
+
],
|
|
974
1134
|
type: "u128"
|
|
975
1135
|
},
|
|
976
1136
|
{
|
|
977
1137
|
name: "sqrt_price",
|
|
978
|
-
docs: [
|
|
1138
|
+
docs: [
|
|
1139
|
+
"current price"
|
|
1140
|
+
],
|
|
979
1141
|
type: "u128"
|
|
980
1142
|
},
|
|
981
1143
|
{
|
|
982
1144
|
name: "activation_point",
|
|
983
|
-
docs: [
|
|
1145
|
+
docs: [
|
|
1146
|
+
"Activation point, can be slot or timestamp"
|
|
1147
|
+
],
|
|
984
1148
|
type: "u64"
|
|
985
1149
|
},
|
|
986
1150
|
{
|
|
987
1151
|
name: "activation_type",
|
|
988
|
-
docs: [
|
|
1152
|
+
docs: [
|
|
1153
|
+
"Activation type, 0 means by slot, 1 means by timestamp"
|
|
1154
|
+
],
|
|
989
1155
|
type: "u8"
|
|
990
1156
|
},
|
|
991
1157
|
{
|
|
992
1158
|
name: "pool_status",
|
|
993
|
-
docs: [
|
|
1159
|
+
docs: [
|
|
1160
|
+
"pool status, 0: enable, 1 disable"
|
|
1161
|
+
],
|
|
994
1162
|
type: "u8"
|
|
995
1163
|
},
|
|
996
1164
|
{
|
|
997
1165
|
name: "token_a_flag",
|
|
998
|
-
docs: [
|
|
1166
|
+
docs: [
|
|
1167
|
+
"token a flag"
|
|
1168
|
+
],
|
|
999
1169
|
type: "u8"
|
|
1000
1170
|
},
|
|
1001
1171
|
{
|
|
1002
1172
|
name: "token_b_flag",
|
|
1003
|
-
docs: [
|
|
1173
|
+
docs: [
|
|
1174
|
+
"token b flag"
|
|
1175
|
+
],
|
|
1004
1176
|
type: "u8"
|
|
1005
1177
|
},
|
|
1006
1178
|
{
|
|
1007
1179
|
name: "collect_fee_mode",
|
|
1008
1180
|
docs: [
|
|
1009
|
-
"0 is collect fee in both token, 1 only collect fee
|
|
1181
|
+
"0 is collect fee in both token, 1 only collect fee only in token b"
|
|
1010
1182
|
],
|
|
1011
1183
|
type: "u8"
|
|
1012
1184
|
},
|
|
1013
1185
|
{
|
|
1014
1186
|
name: "pool_type",
|
|
1015
|
-
docs: [
|
|
1187
|
+
docs: [
|
|
1188
|
+
"pool type"
|
|
1189
|
+
],
|
|
1016
1190
|
type: "u8"
|
|
1017
1191
|
},
|
|
1018
1192
|
{
|
|
1019
|
-
name: "
|
|
1193
|
+
name: "fee_version",
|
|
1020
1194
|
docs: [
|
|
1021
|
-
"pool version, 0: max_fee is still capped at 50%, 1: max_fee is capped at 99%"
|
|
1195
|
+
"pool fee version, 0: max_fee is still capped at 50%, 1: max_fee is capped at 99%"
|
|
1022
1196
|
],
|
|
1023
1197
|
type: "u8"
|
|
1024
1198
|
},
|
|
1025
1199
|
{
|
|
1026
|
-
name: "
|
|
1027
|
-
docs: [
|
|
1200
|
+
name: "padding_3",
|
|
1201
|
+
docs: [
|
|
1202
|
+
"padding"
|
|
1203
|
+
],
|
|
1028
1204
|
type: "u8"
|
|
1029
1205
|
},
|
|
1030
1206
|
{
|
|
1031
1207
|
name: "fee_a_per_liquidity",
|
|
1032
|
-
docs: [
|
|
1208
|
+
docs: [
|
|
1209
|
+
"cumulative"
|
|
1210
|
+
],
|
|
1033
1211
|
type: {
|
|
1034
|
-
array: [
|
|
1212
|
+
array: [
|
|
1213
|
+
"u8",
|
|
1214
|
+
32
|
|
1215
|
+
]
|
|
1035
1216
|
}
|
|
1036
1217
|
},
|
|
1037
1218
|
{
|
|
1038
1219
|
name: "fee_b_per_liquidity",
|
|
1039
|
-
docs: [
|
|
1220
|
+
docs: [
|
|
1221
|
+
"cumulative"
|
|
1222
|
+
],
|
|
1040
1223
|
type: {
|
|
1041
|
-
array: [
|
|
1224
|
+
array: [
|
|
1225
|
+
"u8",
|
|
1226
|
+
32
|
|
1227
|
+
]
|
|
1042
1228
|
}
|
|
1043
1229
|
},
|
|
1044
1230
|
{
|
|
@@ -1047,7 +1233,9 @@ var idl_default = {
|
|
|
1047
1233
|
},
|
|
1048
1234
|
{
|
|
1049
1235
|
name: "metrics",
|
|
1050
|
-
docs: [
|
|
1236
|
+
docs: [
|
|
1237
|
+
"metrics"
|
|
1238
|
+
],
|
|
1051
1239
|
type: {
|
|
1052
1240
|
defined: {
|
|
1053
1241
|
name: "PoolMetrics"
|
|
@@ -1056,19 +1244,61 @@ var idl_default = {
|
|
|
1056
1244
|
},
|
|
1057
1245
|
{
|
|
1058
1246
|
name: "creator",
|
|
1059
|
-
docs: [
|
|
1247
|
+
docs: [
|
|
1248
|
+
"pool creator"
|
|
1249
|
+
],
|
|
1060
1250
|
type: "pubkey"
|
|
1061
1251
|
},
|
|
1062
1252
|
{
|
|
1063
|
-
name: "
|
|
1064
|
-
docs: [
|
|
1253
|
+
name: "token_a_amount",
|
|
1254
|
+
docs: [
|
|
1255
|
+
"token a amount"
|
|
1256
|
+
],
|
|
1257
|
+
type: "u64"
|
|
1258
|
+
},
|
|
1259
|
+
{
|
|
1260
|
+
name: "token_b_amount",
|
|
1261
|
+
docs: [
|
|
1262
|
+
"token b amount"
|
|
1263
|
+
],
|
|
1264
|
+
type: "u64"
|
|
1265
|
+
},
|
|
1266
|
+
{
|
|
1267
|
+
name: "layout_version",
|
|
1268
|
+
docs: [
|
|
1269
|
+
"layout version: version 0: haven't track token_a_amount and token_b_amount, version 1: track token_a_amount and token_b_amount"
|
|
1270
|
+
],
|
|
1271
|
+
type: "u8"
|
|
1272
|
+
},
|
|
1273
|
+
{
|
|
1274
|
+
name: "padding_4",
|
|
1275
|
+
docs: [
|
|
1276
|
+
"Padding for further use"
|
|
1277
|
+
],
|
|
1065
1278
|
type: {
|
|
1066
|
-
array: [
|
|
1279
|
+
array: [
|
|
1280
|
+
"u8",
|
|
1281
|
+
7
|
|
1282
|
+
]
|
|
1283
|
+
}
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
name: "padding_5",
|
|
1287
|
+
docs: [
|
|
1288
|
+
"Padding for further use"
|
|
1289
|
+
],
|
|
1290
|
+
type: {
|
|
1291
|
+
array: [
|
|
1292
|
+
"u64",
|
|
1293
|
+
3
|
|
1294
|
+
]
|
|
1067
1295
|
}
|
|
1068
1296
|
},
|
|
1069
1297
|
{
|
|
1070
1298
|
name: "reward_infos",
|
|
1071
|
-
docs: [
|
|
1299
|
+
docs: [
|
|
1300
|
+
"Farming reward information"
|
|
1301
|
+
],
|
|
1072
1302
|
type: {
|
|
1073
1303
|
array: [
|
|
1074
1304
|
{
|
|
@@ -1089,8 +1319,7 @@ var idl_default = {
|
|
|
1089
1319
|
"Information regarding fee charges",
|
|
1090
1320
|
"trading_fee = amount * trade_fee_numerator / denominator",
|
|
1091
1321
|
"protocol_fee = trading_fee * protocol_fee_percentage / 100",
|
|
1092
|
-
"referral_fee = protocol_fee * referral_percentage / 100"
|
|
1093
|
-
"partner_fee = (protocol_fee - referral_fee) * partner_fee_percentage / denominator"
|
|
1322
|
+
"referral_fee = protocol_fee * referral_percentage / 100"
|
|
1094
1323
|
],
|
|
1095
1324
|
serialization: "bytemuck",
|
|
1096
1325
|
repr: {
|
|
@@ -1123,25 +1352,43 @@ var idl_default = {
|
|
|
1123
1352
|
type: "u8"
|
|
1124
1353
|
},
|
|
1125
1354
|
{
|
|
1126
|
-
name: "
|
|
1127
|
-
docs: [
|
|
1355
|
+
name: "padding_0",
|
|
1356
|
+
docs: [
|
|
1357
|
+
"padding for future use"
|
|
1358
|
+
],
|
|
1128
1359
|
type: "u8"
|
|
1129
1360
|
},
|
|
1130
1361
|
{
|
|
1131
1362
|
name: "referral_fee_percent",
|
|
1132
|
-
docs: [
|
|
1363
|
+
docs: [
|
|
1364
|
+
"referral fee"
|
|
1365
|
+
],
|
|
1133
1366
|
type: "u8"
|
|
1134
1367
|
},
|
|
1135
1368
|
{
|
|
1136
|
-
name: "
|
|
1137
|
-
docs: [
|
|
1369
|
+
name: "padding_1",
|
|
1370
|
+
docs: [
|
|
1371
|
+
"padding"
|
|
1372
|
+
],
|
|
1138
1373
|
type: {
|
|
1139
|
-
array: [
|
|
1374
|
+
array: [
|
|
1375
|
+
"u8",
|
|
1376
|
+
3
|
|
1377
|
+
]
|
|
1140
1378
|
}
|
|
1141
1379
|
},
|
|
1380
|
+
{
|
|
1381
|
+
name: "compounding_fee_bps",
|
|
1382
|
+
docs: [
|
|
1383
|
+
"compounding fee bps, only non-zero in CollectFeeMode::Compounding"
|
|
1384
|
+
],
|
|
1385
|
+
type: "u16"
|
|
1386
|
+
},
|
|
1142
1387
|
{
|
|
1143
1388
|
name: "dynamic_fee",
|
|
1144
|
-
docs: [
|
|
1389
|
+
docs: [
|
|
1390
|
+
"dynamic fee"
|
|
1391
|
+
],
|
|
1145
1392
|
type: {
|
|
1146
1393
|
defined: {
|
|
1147
1394
|
name: "DynamicFeeStruct"
|
|
@@ -1149,11 +1396,8 @@ var idl_default = {
|
|
|
1149
1396
|
}
|
|
1150
1397
|
},
|
|
1151
1398
|
{
|
|
1152
|
-
name: "
|
|
1153
|
-
|
|
1154
|
-
type: {
|
|
1155
|
-
array: ["u64", 2]
|
|
1156
|
-
}
|
|
1399
|
+
name: "init_sqrt_price",
|
|
1400
|
+
type: "u128"
|
|
1157
1401
|
}
|
|
1158
1402
|
]
|
|
1159
1403
|
}
|
|
@@ -1184,12 +1428,13 @@ var idl_default = {
|
|
|
1184
1428
|
type: "u64"
|
|
1185
1429
|
},
|
|
1186
1430
|
{
|
|
1187
|
-
name: "
|
|
1188
|
-
type:
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1431
|
+
name: "padding_0",
|
|
1432
|
+
type: {
|
|
1433
|
+
array: [
|
|
1434
|
+
"u64",
|
|
1435
|
+
2
|
|
1436
|
+
]
|
|
1437
|
+
}
|
|
1193
1438
|
},
|
|
1194
1439
|
{
|
|
1195
1440
|
name: "total_position",
|
|
@@ -1262,7 +1507,9 @@ var idl_default = {
|
|
|
1262
1507
|
},
|
|
1263
1508
|
{
|
|
1264
1509
|
name: "StaticParameters",
|
|
1265
|
-
docs: [
|
|
1510
|
+
docs: [
|
|
1511
|
+
"Parameter that set by the protocol"
|
|
1512
|
+
],
|
|
1266
1513
|
serialization: "bytemuck",
|
|
1267
1514
|
repr: {
|
|
1268
1515
|
kind: "c"
|
|
@@ -1310,10 +1557,21 @@ var idl_default = {
|
|
|
1310
1557
|
name: "base_fee_power_factor",
|
|
1311
1558
|
type: "u8"
|
|
1312
1559
|
},
|
|
1560
|
+
{
|
|
1561
|
+
name: "function_type",
|
|
1562
|
+
type: "u8"
|
|
1563
|
+
},
|
|
1564
|
+
{
|
|
1565
|
+
name: "collect_fee_mode",
|
|
1566
|
+
type: "u8"
|
|
1567
|
+
},
|
|
1313
1568
|
{
|
|
1314
1569
|
name: "_padding",
|
|
1315
1570
|
type: {
|
|
1316
|
-
array: [
|
|
1571
|
+
array: [
|
|
1572
|
+
"u8",
|
|
1573
|
+
3
|
|
1574
|
+
]
|
|
1317
1575
|
}
|
|
1318
1576
|
}
|
|
1319
1577
|
]
|
|
@@ -1362,7 +1620,9 @@ var idl_default = {
|
|
|
1362
1620
|
},
|
|
1363
1621
|
{
|
|
1364
1622
|
name: "VariableParameters",
|
|
1365
|
-
docs: [
|
|
1623
|
+
docs: [
|
|
1624
|
+
"Parameters that changes based on dynamic of the market"
|
|
1625
|
+
],
|
|
1366
1626
|
serialization: "bytemuck",
|
|
1367
1627
|
repr: {
|
|
1368
1628
|
kind: "c"
|
|
@@ -1385,7 +1645,10 @@ var idl_default = {
|
|
|
1385
1645
|
{
|
|
1386
1646
|
name: "_padding",
|
|
1387
1647
|
type: {
|
|
1388
|
-
array: [
|
|
1648
|
+
array: [
|
|
1649
|
+
"u8",
|
|
1650
|
+
4
|
|
1651
|
+
]
|
|
1389
1652
|
}
|
|
1390
1653
|
},
|
|
1391
1654
|
{
|
|
@@ -1395,7 +1658,10 @@ var idl_default = {
|
|
|
1395
1658
|
{
|
|
1396
1659
|
name: "_padding_1",
|
|
1397
1660
|
type: {
|
|
1398
|
-
array: [
|
|
1661
|
+
array: [
|
|
1662
|
+
"u8",
|
|
1663
|
+
8
|
|
1664
|
+
]
|
|
1399
1665
|
}
|
|
1400
1666
|
}
|
|
1401
1667
|
]
|
|
@@ -1443,70 +1709,96 @@ var idl_default = {
|
|
|
1443
1709
|
fields: [
|
|
1444
1710
|
{
|
|
1445
1711
|
name: "initialized",
|
|
1446
|
-
docs: [
|
|
1712
|
+
docs: [
|
|
1713
|
+
"Indicates if the reward has been initialized"
|
|
1714
|
+
],
|
|
1447
1715
|
type: "u8"
|
|
1448
1716
|
},
|
|
1449
1717
|
{
|
|
1450
1718
|
name: "reward_token_flag",
|
|
1451
|
-
docs: [
|
|
1719
|
+
docs: [
|
|
1720
|
+
"reward token flag"
|
|
1721
|
+
],
|
|
1452
1722
|
type: "u8"
|
|
1453
1723
|
},
|
|
1454
1724
|
{
|
|
1455
1725
|
name: "_padding_0",
|
|
1456
|
-
docs: [
|
|
1726
|
+
docs: [
|
|
1727
|
+
"padding"
|
|
1728
|
+
],
|
|
1457
1729
|
type: {
|
|
1458
|
-
array: [
|
|
1730
|
+
array: [
|
|
1731
|
+
"u8",
|
|
1732
|
+
6
|
|
1733
|
+
]
|
|
1459
1734
|
}
|
|
1460
1735
|
},
|
|
1461
1736
|
{
|
|
1462
|
-
name: "
|
|
1737
|
+
name: "dead_liquidity_reward_checkpoint",
|
|
1463
1738
|
docs: [
|
|
1464
|
-
"
|
|
1739
|
+
"Cumulative dead-liquidity reward (Compounding Pool only)"
|
|
1465
1740
|
],
|
|
1466
|
-
type:
|
|
1467
|
-
array: ["u8", 8]
|
|
1468
|
-
}
|
|
1741
|
+
type: "u64"
|
|
1469
1742
|
},
|
|
1470
1743
|
{
|
|
1471
1744
|
name: "mint",
|
|
1472
|
-
docs: [
|
|
1745
|
+
docs: [
|
|
1746
|
+
"Reward token mint."
|
|
1747
|
+
],
|
|
1473
1748
|
type: "pubkey"
|
|
1474
1749
|
},
|
|
1475
1750
|
{
|
|
1476
1751
|
name: "vault",
|
|
1477
|
-
docs: [
|
|
1752
|
+
docs: [
|
|
1753
|
+
"Reward vault token account."
|
|
1754
|
+
],
|
|
1478
1755
|
type: "pubkey"
|
|
1479
1756
|
},
|
|
1480
1757
|
{
|
|
1481
1758
|
name: "funder",
|
|
1482
|
-
docs: [
|
|
1759
|
+
docs: [
|
|
1760
|
+
"Authority account that allows to fund rewards"
|
|
1761
|
+
],
|
|
1483
1762
|
type: "pubkey"
|
|
1484
1763
|
},
|
|
1485
1764
|
{
|
|
1486
1765
|
name: "reward_duration",
|
|
1487
|
-
docs: [
|
|
1766
|
+
docs: [
|
|
1767
|
+
"reward duration"
|
|
1768
|
+
],
|
|
1488
1769
|
type: "u64"
|
|
1489
1770
|
},
|
|
1490
1771
|
{
|
|
1491
1772
|
name: "reward_duration_end",
|
|
1492
|
-
docs: [
|
|
1773
|
+
docs: [
|
|
1774
|
+
"reward duration end"
|
|
1775
|
+
],
|
|
1493
1776
|
type: "u64"
|
|
1494
1777
|
},
|
|
1495
1778
|
{
|
|
1496
1779
|
name: "reward_rate",
|
|
1497
|
-
docs: [
|
|
1780
|
+
docs: [
|
|
1781
|
+
"reward rate"
|
|
1782
|
+
],
|
|
1498
1783
|
type: "u128"
|
|
1499
1784
|
},
|
|
1500
1785
|
{
|
|
1501
1786
|
name: "reward_per_token_stored",
|
|
1502
|
-
docs: [
|
|
1787
|
+
docs: [
|
|
1788
|
+
"Reward per token stored"
|
|
1789
|
+
],
|
|
1503
1790
|
type: {
|
|
1504
|
-
array: [
|
|
1791
|
+
array: [
|
|
1792
|
+
"u8",
|
|
1793
|
+
32
|
|
1794
|
+
]
|
|
1505
1795
|
}
|
|
1506
1796
|
},
|
|
1507
1797
|
{
|
|
1508
1798
|
name: "last_update_time",
|
|
1509
|
-
docs: [
|
|
1799
|
+
docs: [
|
|
1800
|
+
"The last time reward states were updated."
|
|
1801
|
+
],
|
|
1510
1802
|
type: "u64"
|
|
1511
1803
|
},
|
|
1512
1804
|
{
|
|
@@ -1569,44 +1861,6 @@ var idl_default = {
|
|
|
1569
1861
|
}
|
|
1570
1862
|
],
|
|
1571
1863
|
constants: [
|
|
1572
|
-
{
|
|
1573
|
-
name: "DAMM_V2",
|
|
1574
|
-
type: "pubkey",
|
|
1575
|
-
value: "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
|
|
1576
|
-
},
|
|
1577
|
-
{
|
|
1578
|
-
name: "DAMM_V2_SWAP_DISC",
|
|
1579
|
-
type: {
|
|
1580
|
-
array: ["u8", 8]
|
|
1581
|
-
},
|
|
1582
|
-
value: "[248, 198, 158, 145, 225, 117, 135, 200]"
|
|
1583
|
-
},
|
|
1584
|
-
{
|
|
1585
|
-
name: "DLMM_SWAP2_DISC",
|
|
1586
|
-
type: {
|
|
1587
|
-
array: ["u8", 8]
|
|
1588
|
-
},
|
|
1589
|
-
value: "[65, 75, 63, 76, 235, 91, 91, 136]"
|
|
1590
|
-
},
|
|
1591
|
-
{
|
|
1592
|
-
name: "JUP_V6",
|
|
1593
|
-
type: "pubkey",
|
|
1594
|
-
value: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
|
|
1595
|
-
},
|
|
1596
|
-
{
|
|
1597
|
-
name: "JUP_V6_ROUTE_DISC",
|
|
1598
|
-
type: {
|
|
1599
|
-
array: ["u8", 8]
|
|
1600
|
-
},
|
|
1601
|
-
value: "[229, 23, 203, 151, 122, 227, 173, 42]"
|
|
1602
|
-
},
|
|
1603
|
-
{
|
|
1604
|
-
name: "JUP_V6_SHARED_ACCOUNT_ROUTE_DISC",
|
|
1605
|
-
type: {
|
|
1606
|
-
array: ["u8", 8]
|
|
1607
|
-
},
|
|
1608
|
-
value: "[193, 32, 155, 51, 65, 214, 156, 129]"
|
|
1609
|
-
},
|
|
1610
1864
|
{
|
|
1611
1865
|
name: "MAX_BASIS_POINT",
|
|
1612
1866
|
type: "u16",
|
|
@@ -1621,6 +1875,11 @@ var idl_default = {
|
|
|
1621
1875
|
};
|
|
1622
1876
|
|
|
1623
1877
|
// src/types.ts
|
|
1878
|
+
var JupiterApiVersion = /* @__PURE__ */ ((JupiterApiVersion3) => {
|
|
1879
|
+
JupiterApiVersion3["V1"] = "v1";
|
|
1880
|
+
JupiterApiVersion3["V2"] = "v2";
|
|
1881
|
+
return JupiterApiVersion3;
|
|
1882
|
+
})(JupiterApiVersion || {});
|
|
1624
1883
|
var ZapInDammV2PoolSwapRoute = /* @__PURE__ */ ((ZapInDammV2PoolSwapRoute2) => {
|
|
1625
1884
|
ZapInDammV2PoolSwapRoute2["Jupiter"] = "jupiter";
|
|
1626
1885
|
ZapInDammV2PoolSwapRoute2["DammV2"] = "dammV2";
|
|
@@ -1651,8 +1910,9 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
|
|
|
1651
1910
|
|
|
1652
1911
|
// src/helpers/jupiter.ts
|
|
1653
1912
|
import {
|
|
1913
|
+
AddressLookupTableAccount,
|
|
1914
|
+
AddressLookupTableProgram,
|
|
1654
1915
|
PublicKey as PublicKey2,
|
|
1655
|
-
Transaction,
|
|
1656
1916
|
TransactionInstruction
|
|
1657
1917
|
} from "@solana/web3.js";
|
|
1658
1918
|
|
|
@@ -1698,6 +1958,68 @@ var AccountsType = {
|
|
|
1698
1958
|
var DLMM_SWAP_DISCRIMINATOR = [65, 75, 63, 76, 235, 91, 91, 136];
|
|
1699
1959
|
var AMOUNT_IN_DLMM_OFFSET = 8;
|
|
1700
1960
|
var AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
|
|
1961
|
+
var JUP_V6_ROUTE_DISCRIMINATOR = [
|
|
1962
|
+
229,
|
|
1963
|
+
23,
|
|
1964
|
+
203,
|
|
1965
|
+
151,
|
|
1966
|
+
122,
|
|
1967
|
+
227,
|
|
1968
|
+
173,
|
|
1969
|
+
42
|
|
1970
|
+
];
|
|
1971
|
+
var JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR = [
|
|
1972
|
+
193,
|
|
1973
|
+
32,
|
|
1974
|
+
155,
|
|
1975
|
+
51,
|
|
1976
|
+
65,
|
|
1977
|
+
214,
|
|
1978
|
+
156,
|
|
1979
|
+
129
|
|
1980
|
+
];
|
|
1981
|
+
var JUP_V6_ROUTE_V2_DISCRIMINATOR = [
|
|
1982
|
+
187,
|
|
1983
|
+
100,
|
|
1984
|
+
250,
|
|
1985
|
+
204,
|
|
1986
|
+
49,
|
|
1987
|
+
196,
|
|
1988
|
+
175,
|
|
1989
|
+
20
|
|
1990
|
+
];
|
|
1991
|
+
var JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR = [
|
|
1992
|
+
209,
|
|
1993
|
+
152,
|
|
1994
|
+
83,
|
|
1995
|
+
147,
|
|
1996
|
+
124,
|
|
1997
|
+
254,
|
|
1998
|
+
216,
|
|
1999
|
+
233
|
|
2000
|
+
];
|
|
2001
|
+
var JUPITER_INSTRUCTION_LAYOUTS = {
|
|
2002
|
+
// route
|
|
2003
|
+
[Buffer.from(JUP_V6_ROUTE_DISCRIMINATOR).toString("hex")]: {
|
|
2004
|
+
amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
|
|
2005
|
+
userTransferAuthorityIndex: 1
|
|
2006
|
+
},
|
|
2007
|
+
// shared_accounts_route
|
|
2008
|
+
[Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR).toString("hex")]: {
|
|
2009
|
+
amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
|
|
2010
|
+
userTransferAuthorityIndex: 2
|
|
2011
|
+
},
|
|
2012
|
+
// route_v2
|
|
2013
|
+
[Buffer.from(JUP_V6_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
|
|
2014
|
+
amountInOffset: () => 8,
|
|
2015
|
+
userTransferAuthorityIndex: 0
|
|
2016
|
+
},
|
|
2017
|
+
// shared_accounts_route_v2
|
|
2018
|
+
[Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
|
|
2019
|
+
amountInOffset: () => 9,
|
|
2020
|
+
userTransferAuthorityIndex: 1
|
|
2021
|
+
}
|
|
2022
|
+
};
|
|
1701
2023
|
var AMOUNT_IN_DAMM_V2_OFFSET = 8;
|
|
1702
2024
|
var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
1703
2025
|
248,
|
|
@@ -1710,42 +2032,132 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
|
|
|
1710
2032
|
200
|
|
1711
2033
|
];
|
|
1712
2034
|
var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
|
|
2035
|
+
var DEFAULT_JUPITER_API_VERSION = "v2" /* V2 */;
|
|
2036
|
+
var DEFAULT_JUPITER_QUOTE_OPTIONS = {
|
|
2037
|
+
dynamicSlippage: false,
|
|
2038
|
+
onlyDirectRoutes: true,
|
|
2039
|
+
restrictIntermediateTokens: true,
|
|
2040
|
+
forJitoBundle: true
|
|
2041
|
+
};
|
|
1713
2042
|
|
|
1714
2043
|
// src/helpers/jupiter.ts
|
|
1715
|
-
function
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
2044
|
+
function resolveJupiterConfig(config = {}) {
|
|
2045
|
+
var _a;
|
|
2046
|
+
return {
|
|
2047
|
+
url: config.jupiterApiUrl || DEFAULT_JUPITER_API_URL,
|
|
2048
|
+
apiKey: config.jupiterApiKey || "",
|
|
2049
|
+
version: (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2050
|
+
};
|
|
2051
|
+
}
|
|
2052
|
+
function getJupiterInstructionLayout(data) {
|
|
2053
|
+
const discriminator = data.subarray(0, 8).toString("hex");
|
|
2054
|
+
const layout = JUPITER_INSTRUCTION_LAYOUTS[discriminator];
|
|
2055
|
+
if (!layout) {
|
|
2056
|
+
throw new Error(
|
|
2057
|
+
`Unsupported Jupiter instruction discriminator ${discriminator}`
|
|
2058
|
+
);
|
|
2059
|
+
}
|
|
2060
|
+
return layout;
|
|
2061
|
+
}
|
|
2062
|
+
function isJupiterBuildResponse(quoteResponse) {
|
|
2063
|
+
return quoteResponse.swapInstruction !== void 0;
|
|
2064
|
+
}
|
|
2065
|
+
function isJupiterSwapInstructionForUser(swapInstruction, user) {
|
|
2066
|
+
const layout = getJupiterInstructionLayout(
|
|
2067
|
+
Buffer.from(swapInstruction.data, "base64")
|
|
2068
|
+
);
|
|
2069
|
+
const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
|
|
2070
|
+
return authority !== void 0 && new PublicKey2(authority.pubkey).equals(user);
|
|
2071
|
+
}
|
|
2072
|
+
function jupiterHeaders(apiKey, json) {
|
|
2073
|
+
return __spreadValues(__spreadValues({
|
|
2074
|
+
Accept: "application/json"
|
|
2075
|
+
}, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
|
|
2076
|
+
}
|
|
2077
|
+
function toSearchParams(query) {
|
|
2078
|
+
var _a;
|
|
2079
|
+
const params = new URLSearchParams(__spreadProps(__spreadValues({
|
|
2080
|
+
inputMint: query.inputMint.toString(),
|
|
2081
|
+
outputMint: query.outputMint.toString(),
|
|
2082
|
+
amount: query.amount,
|
|
2083
|
+
slippageBps: query.slippageBps.toString()
|
|
2084
|
+
}, query.maxAccounts !== void 0 ? { maxAccounts: query.maxAccounts.toString() } : {}), {
|
|
2085
|
+
onlyDirectRoutes: query.onlyDirectRoutes.toString(),
|
|
2086
|
+
restrictIntermediateTokens: query.restrictIntermediateTokens.toString(),
|
|
2087
|
+
dynamicSlippage: query.dynamicSlippage.toString(),
|
|
2088
|
+
forJitoBundle: query.forJitoBundle.toString()
|
|
2089
|
+
}));
|
|
2090
|
+
for (const [name, value] of Object.entries(
|
|
2091
|
+
(_a = query.additionalQueryParams) != null ? _a : {}
|
|
2092
|
+
)) {
|
|
2093
|
+
params.set(name, value);
|
|
2094
|
+
}
|
|
2095
|
+
return params;
|
|
2096
|
+
}
|
|
2097
|
+
function fetchJupiterQuoteV1(query, config) {
|
|
2098
|
+
return __async(this, null, function* () {
|
|
2099
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2100
|
+
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(query).toString()}`;
|
|
1729
2101
|
try {
|
|
1730
2102
|
const response = yield fetch(url, {
|
|
1731
2103
|
method: "GET",
|
|
1732
|
-
headers:
|
|
1733
|
-
Accept: "application/json"
|
|
1734
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
|
|
2104
|
+
headers: jupiterHeaders(apiKey, false)
|
|
1735
2105
|
});
|
|
1736
2106
|
if (!response.ok) {
|
|
1737
2107
|
return null;
|
|
1738
2108
|
}
|
|
1739
|
-
|
|
1740
|
-
return result;
|
|
2109
|
+
return yield response.json();
|
|
1741
2110
|
} catch (error) {
|
|
1742
2111
|
return null;
|
|
1743
2112
|
}
|
|
1744
2113
|
});
|
|
1745
2114
|
}
|
|
1746
|
-
function
|
|
1747
|
-
return __async(this,
|
|
1748
|
-
const url =
|
|
2115
|
+
function fetchJupiterBuildV2(query, taker, config) {
|
|
2116
|
+
return __async(this, null, function* () {
|
|
2117
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2118
|
+
const params = toSearchParams(query);
|
|
2119
|
+
params.set("taker", taker.toString());
|
|
2120
|
+
const url = `${baseUrl}/swap/v2/build?${params.toString()}`;
|
|
2121
|
+
try {
|
|
2122
|
+
const response = yield fetch(url, {
|
|
2123
|
+
method: "GET",
|
|
2124
|
+
headers: jupiterHeaders(apiKey, false)
|
|
2125
|
+
});
|
|
2126
|
+
if (!response.ok) {
|
|
2127
|
+
return null;
|
|
2128
|
+
}
|
|
2129
|
+
return yield response.json();
|
|
2130
|
+
} catch (error) {
|
|
2131
|
+
return null;
|
|
2132
|
+
}
|
|
2133
|
+
});
|
|
2134
|
+
}
|
|
2135
|
+
function getJupiterQuote(_0) {
|
|
2136
|
+
return __async(this, arguments, function* (params, config = {}) {
|
|
2137
|
+
var _a, _b, _c, _d;
|
|
2138
|
+
const query = {
|
|
2139
|
+
inputMint: params.inputMint,
|
|
2140
|
+
outputMint: params.outputMint,
|
|
2141
|
+
amount: params.amount.toString(),
|
|
2142
|
+
slippageBps: params.slippageBps,
|
|
2143
|
+
maxAccounts: params.maxAccounts,
|
|
2144
|
+
dynamicSlippage: (_a = params.dynamicSlippage) != null ? _a : DEFAULT_JUPITER_QUOTE_OPTIONS.dynamicSlippage,
|
|
2145
|
+
onlyDirectRoutes: (_b = params.onlyDirectRoutes) != null ? _b : DEFAULT_JUPITER_QUOTE_OPTIONS.onlyDirectRoutes,
|
|
2146
|
+
restrictIntermediateTokens: (_c = params.restrictIntermediateTokens) != null ? _c : DEFAULT_JUPITER_QUOTE_OPTIONS.restrictIntermediateTokens,
|
|
2147
|
+
forJitoBundle: (_d = params.forJitoBundle) != null ? _d : DEFAULT_JUPITER_QUOTE_OPTIONS.forJitoBundle,
|
|
2148
|
+
additionalQueryParams: params.additionalQueryParams
|
|
2149
|
+
};
|
|
2150
|
+
const { version } = resolveJupiterConfig(config);
|
|
2151
|
+
if (version === "v1" /* V1 */) {
|
|
2152
|
+
return fetchJupiterQuoteV1(query, config);
|
|
2153
|
+
}
|
|
2154
|
+
return fetchJupiterBuildV2(query, params.user, config);
|
|
2155
|
+
});
|
|
2156
|
+
}
|
|
2157
|
+
function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
2158
|
+
return __async(this, null, function* () {
|
|
2159
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2160
|
+
const url = `${baseUrl}/swap/v1/swap-instructions`;
|
|
1749
2161
|
const requestBody = {
|
|
1750
2162
|
userPublicKey: userPublicKey.toString(),
|
|
1751
2163
|
quoteResponse
|
|
@@ -1754,10 +2166,7 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1754
2166
|
try {
|
|
1755
2167
|
response = yield fetch(url, {
|
|
1756
2168
|
method: "POST",
|
|
1757
|
-
headers:
|
|
1758
|
-
"Content-Type": "application/json",
|
|
1759
|
-
Accept: "application/json"
|
|
1760
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
|
|
2169
|
+
headers: jupiterHeaders(apiKey, true),
|
|
1761
2170
|
body: JSON.stringify(requestBody)
|
|
1762
2171
|
});
|
|
1763
2172
|
if (!response.ok) {
|
|
@@ -1769,22 +2178,111 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1769
2178
|
} catch (error) {
|
|
1770
2179
|
throw new Error(`Jupiter swap instruction failed to fetch`);
|
|
1771
2180
|
}
|
|
1772
|
-
|
|
1773
|
-
return result;
|
|
2181
|
+
return yield response.json();
|
|
1774
2182
|
});
|
|
1775
2183
|
}
|
|
1776
|
-
function
|
|
1777
|
-
return __async(this, arguments, function* (
|
|
2184
|
+
function getJupiterSwapInstruction(_0, _1) {
|
|
2185
|
+
return __async(this, arguments, function* (userPublicKey, quoteResponse, config = {}) {
|
|
2186
|
+
const { version } = resolveJupiterConfig(config);
|
|
2187
|
+
if (version === "v1" /* V1 */) {
|
|
2188
|
+
return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
|
|
2189
|
+
}
|
|
2190
|
+
if (!isJupiterBuildResponse(quoteResponse)) {
|
|
2191
|
+
throw new Error(
|
|
2192
|
+
"Jupiter quote has no swap instructions, get the quote with getJupiterQuote under Jupiter API v2"
|
|
2193
|
+
);
|
|
2194
|
+
}
|
|
2195
|
+
if (!isJupiterSwapInstructionForUser(
|
|
2196
|
+
quoteResponse.swapInstruction,
|
|
2197
|
+
userPublicKey
|
|
2198
|
+
)) {
|
|
2199
|
+
throw new Error(
|
|
2200
|
+
`Jupiter quote swap instructions are not built for ${userPublicKey.toBase58()}`
|
|
2201
|
+
);
|
|
2202
|
+
}
|
|
2203
|
+
return quoteResponse;
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
function isQuoteMatchesSwap(quoteResponse, user, amount) {
|
|
2207
|
+
if (quoteResponse.inAmount !== amount.toString()) {
|
|
2208
|
+
return false;
|
|
2209
|
+
}
|
|
2210
|
+
if (isJupiterBuildResponse(quoteResponse)) {
|
|
2211
|
+
return isJupiterSwapInstructionForUser(quoteResponse.swapInstruction, user);
|
|
2212
|
+
}
|
|
2213
|
+
return true;
|
|
2214
|
+
}
|
|
2215
|
+
var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
|
|
2216
|
+
function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
|
|
2217
|
+
return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
|
|
2218
|
+
([key, addresses]) => new AddressLookupTableAccount({
|
|
2219
|
+
key: new PublicKey2(key),
|
|
2220
|
+
state: {
|
|
2221
|
+
addresses: addresses.map((address) => new PublicKey2(address)),
|
|
2222
|
+
deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
|
|
2223
|
+
lastExtendedSlot: 0,
|
|
2224
|
+
lastExtendedSlotStartIndex: 0
|
|
2225
|
+
}
|
|
2226
|
+
})
|
|
2227
|
+
);
|
|
2228
|
+
}
|
|
2229
|
+
function fetchAddressLookupTableAccounts(connection, addresses) {
|
|
2230
|
+
return __async(this, null, function* () {
|
|
2231
|
+
if (addresses.length === 0) {
|
|
2232
|
+
return [];
|
|
2233
|
+
}
|
|
2234
|
+
const keys = addresses.map((address) => new PublicKey2(address));
|
|
2235
|
+
const accounts = yield connection.getMultipleAccountsInfo(keys);
|
|
2236
|
+
return keys.map((key, i) => {
|
|
2237
|
+
const account = accounts[i];
|
|
2238
|
+
if (!account || !account.owner.equals(AddressLookupTableProgram.programId)) {
|
|
2239
|
+
throw new Error(`Address lookup table not found: ${key.toBase58()}`);
|
|
2240
|
+
}
|
|
2241
|
+
return new AddressLookupTableAccount({
|
|
2242
|
+
key,
|
|
2243
|
+
state: AddressLookupTableAccount.deserialize(account.data)
|
|
2244
|
+
});
|
|
2245
|
+
});
|
|
2246
|
+
});
|
|
2247
|
+
}
|
|
2248
|
+
function mergeAddressLookupTableAccounts(...lists) {
|
|
2249
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2250
|
+
for (const table of lists.flat()) {
|
|
2251
|
+
const key = table.key.toBase58();
|
|
2252
|
+
if (!merged.has(key)) {
|
|
2253
|
+
merged.set(key, table);
|
|
2254
|
+
}
|
|
2255
|
+
}
|
|
2256
|
+
return [...merged.values()];
|
|
2257
|
+
}
|
|
2258
|
+
function getJupiterAddressLookupTableAccounts(connection, response) {
|
|
2259
|
+
return __async(this, null, function* () {
|
|
2260
|
+
var _a;
|
|
2261
|
+
if (response.addressesByLookupTableAddress) {
|
|
2262
|
+
return toAddressLookupTableAccounts(response.addressesByLookupTableAddress);
|
|
2263
|
+
}
|
|
2264
|
+
return fetchAddressLookupTableAccounts(
|
|
2265
|
+
connection,
|
|
2266
|
+
(_a = response.addressLookupTableAddresses) != null ? _a : []
|
|
2267
|
+
);
|
|
2268
|
+
});
|
|
2269
|
+
}
|
|
2270
|
+
function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
2271
|
+
return __async(this, arguments, function* (connection, user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}, jupiterQuoteOptions = {}) {
|
|
2272
|
+
if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
|
|
2273
|
+
throw new Error(
|
|
2274
|
+
`Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
|
|
2275
|
+
);
|
|
2276
|
+
}
|
|
1778
2277
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
true,
|
|
2278
|
+
__spreadValues({
|
|
2279
|
+
inputMint,
|
|
2280
|
+
outputMint,
|
|
2281
|
+
amount,
|
|
2282
|
+
user,
|
|
2283
|
+
maxAccounts,
|
|
2284
|
+
slippageBps
|
|
2285
|
+
}, jupiterQuoteOptions),
|
|
1788
2286
|
config
|
|
1789
2287
|
);
|
|
1790
2288
|
if (!quoteResponse) {
|
|
@@ -1808,7 +2306,11 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1808
2306
|
programId: new PublicKey2(swapInstructionResponse.swapInstruction.programId),
|
|
1809
2307
|
data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
|
|
1810
2308
|
});
|
|
1811
|
-
|
|
2309
|
+
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2310
|
+
connection,
|
|
2311
|
+
swapInstructionResponse
|
|
2312
|
+
);
|
|
2313
|
+
return { instruction, addressLookupTableAccounts, quoteResponse };
|
|
1812
2314
|
});
|
|
1813
2315
|
}
|
|
1814
2316
|
|
|
@@ -1946,11 +2448,11 @@ function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
|
1946
2448
|
}
|
|
1947
2449
|
|
|
1948
2450
|
// src/helpers/common.ts
|
|
2451
|
+
import { NATIVE_MINT, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
1949
2452
|
import {
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
} from "@solana/
|
|
1953
|
-
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
2453
|
+
ComputeBudgetProgram,
|
|
2454
|
+
PublicKey as PublicKey4
|
|
2455
|
+
} from "@solana/web3.js";
|
|
1954
2456
|
import Decimal from "decimal.js";
|
|
1955
2457
|
function getTokenProgramFromMint(connection, mint) {
|
|
1956
2458
|
return __async(this, null, function* () {
|
|
@@ -1984,6 +2486,11 @@ function convertLamportsToUiAmount(amount, decimals) {
|
|
|
1984
2486
|
function convertUiAmountToLamports(amount, decimals) {
|
|
1985
2487
|
return amount.mul(Decimal.pow(10, decimals));
|
|
1986
2488
|
}
|
|
2489
|
+
function filterOutComputeBudgetInstructions(instructions) {
|
|
2490
|
+
return instructions.filter(
|
|
2491
|
+
(ix) => !ix.programId.equals(ComputeBudgetProgram.programId)
|
|
2492
|
+
);
|
|
2493
|
+
}
|
|
1987
2494
|
|
|
1988
2495
|
// src/helpers/token.ts
|
|
1989
2496
|
import {
|
|
@@ -1995,9 +2502,9 @@ import {
|
|
|
1995
2502
|
} from "@solana/spl-token";
|
|
1996
2503
|
import {
|
|
1997
2504
|
SystemProgram,
|
|
1998
|
-
TransactionInstruction as
|
|
2505
|
+
TransactionInstruction as TransactionInstruction3
|
|
1999
2506
|
} from "@solana/web3.js";
|
|
2000
|
-
var getOrCreateATAInstruction = (
|
|
2507
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2001
2508
|
const toAccount = getAssociatedTokenAddressSync(
|
|
2002
2509
|
tokenMint,
|
|
2003
2510
|
owner,
|
|
@@ -2049,7 +2556,7 @@ function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID3)
|
|
|
2049
2556
|
toPubkey: to,
|
|
2050
2557
|
lamports: amount
|
|
2051
2558
|
}),
|
|
2052
|
-
new
|
|
2559
|
+
new TransactionInstruction3({
|
|
2053
2560
|
keys: [
|
|
2054
2561
|
{
|
|
2055
2562
|
pubkey: to,
|
|
@@ -2089,7 +2596,7 @@ import DLMM, {
|
|
|
2089
2596
|
import {
|
|
2090
2597
|
createTransferCheckedWithTransferHookInstruction,
|
|
2091
2598
|
getTransferHook,
|
|
2092
|
-
TOKEN_2022_PROGRAM_ID
|
|
2599
|
+
TOKEN_2022_PROGRAM_ID,
|
|
2093
2600
|
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4,
|
|
2094
2601
|
unpackMint
|
|
2095
2602
|
} from "@solana/spl-token";
|
|
@@ -2109,7 +2616,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
|
|
|
2109
2616
|
const mintInfo = unpackMint(
|
|
2110
2617
|
mint,
|
|
2111
2618
|
accountInfoWithBuffer,
|
|
2112
|
-
|
|
2619
|
+
TOKEN_2022_PROGRAM_ID
|
|
2113
2620
|
);
|
|
2114
2621
|
const transferHook = getTransferHook(mintInfo);
|
|
2115
2622
|
if (!transferHook) {
|
|
@@ -2125,7 +2632,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
|
|
|
2125
2632
|
mintInfo.decimals,
|
|
2126
2633
|
[],
|
|
2127
2634
|
"confirmed",
|
|
2128
|
-
|
|
2635
|
+
TOKEN_2022_PROGRAM_ID
|
|
2129
2636
|
);
|
|
2130
2637
|
return (yield transferWithHookIx).keys.slice(4);
|
|
2131
2638
|
}
|
|
@@ -2449,8 +2956,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2449
2956
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2450
2957
|
return new BN3(estimatedOutput.floor().toString());
|
|
2451
2958
|
}
|
|
2452
|
-
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
2453
|
-
return __async(this, arguments, function* (dlmm, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}) {
|
|
2959
|
+
function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6, _7) {
|
|
2960
|
+
return __async(this, arguments, function* (dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}, jupiterQuoteOptions = {}) {
|
|
2454
2961
|
let dlmmQuoteResult = null;
|
|
2455
2962
|
try {
|
|
2456
2963
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2463,15 +2970,14 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
2463
2970
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
2464
2971
|
}
|
|
2465
2972
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
true,
|
|
2973
|
+
__spreadValues({
|
|
2974
|
+
inputMint: inMint,
|
|
2975
|
+
outputMint: outMint,
|
|
2976
|
+
amount: inAmount,
|
|
2977
|
+
user,
|
|
2978
|
+
maxAccounts: 50,
|
|
2979
|
+
slippageBps: swapSlippageBps
|
|
2980
|
+
}, jupiterQuoteOptions),
|
|
2475
2981
|
config
|
|
2476
2982
|
);
|
|
2477
2983
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -2587,6 +3093,7 @@ function binarySearchRefineDirectSwapAmount(dlmm, initialActiveBin, initialMinBi
|
|
|
2587
3093
|
}
|
|
2588
3094
|
function estimateDlmmIndirectSwap(_0) {
|
|
2589
3095
|
return __async(this, arguments, function* ({
|
|
3096
|
+
user,
|
|
2590
3097
|
amountIn,
|
|
2591
3098
|
inputTokenMint,
|
|
2592
3099
|
lbPair,
|
|
@@ -2596,6 +3103,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2596
3103
|
maxDeltaId,
|
|
2597
3104
|
strategy,
|
|
2598
3105
|
singleSided,
|
|
3106
|
+
jupiterQuoteOptions,
|
|
2599
3107
|
config = {}
|
|
2600
3108
|
}) {
|
|
2601
3109
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
@@ -2620,15 +3128,14 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2620
3128
|
const singleSidedX = singleSided === 0 /* X */;
|
|
2621
3129
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
2622
3130
|
const quote = yield getJupiterQuote(
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
true,
|
|
3131
|
+
__spreadValues({
|
|
3132
|
+
inputMint: inputTokenMint,
|
|
3133
|
+
outputMint: outputTokenMint,
|
|
3134
|
+
amount: amountIn,
|
|
3135
|
+
user,
|
|
3136
|
+
maxAccounts: 50,
|
|
3137
|
+
slippageBps: swapSlippageBps
|
|
3138
|
+
}, jupiterQuoteOptions),
|
|
2632
3139
|
config
|
|
2633
3140
|
);
|
|
2634
3141
|
if (!quote) {
|
|
@@ -2651,27 +3158,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2651
3158
|
const halfAmount = amountIn.div(new BN3(2));
|
|
2652
3159
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
2653
3160
|
getJupiterQuote(
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
true,
|
|
3161
|
+
__spreadValues({
|
|
3162
|
+
inputMint: inputTokenMint,
|
|
3163
|
+
outputMint: tokenXMint,
|
|
3164
|
+
amount: halfAmount,
|
|
3165
|
+
user,
|
|
3166
|
+
maxAccounts: 50,
|
|
3167
|
+
slippageBps: swapSlippageBps
|
|
3168
|
+
}, jupiterQuoteOptions),
|
|
2663
3169
|
config
|
|
2664
3170
|
),
|
|
2665
3171
|
getJupiterQuote(
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
true,
|
|
3172
|
+
__spreadValues({
|
|
3173
|
+
inputMint: inputTokenMint,
|
|
3174
|
+
outputMint: tokenYMint,
|
|
3175
|
+
amount: halfAmount,
|
|
3176
|
+
user,
|
|
3177
|
+
maxAccounts: 50,
|
|
3178
|
+
slippageBps: swapSlippageBps
|
|
3179
|
+
}, jupiterQuoteOptions),
|
|
2675
3180
|
config
|
|
2676
3181
|
)
|
|
2677
3182
|
]);
|
|
@@ -2767,27 +3272,25 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2767
3272
|
}
|
|
2768
3273
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
2769
3274
|
getJupiterQuote(
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
true,
|
|
3275
|
+
__spreadValues({
|
|
3276
|
+
inputMint: inputTokenMint,
|
|
3277
|
+
outputMint: tokenXMint,
|
|
3278
|
+
amount: bestAmountToX,
|
|
3279
|
+
user,
|
|
3280
|
+
maxAccounts: 50,
|
|
3281
|
+
slippageBps: swapSlippageBps
|
|
3282
|
+
}, jupiterQuoteOptions),
|
|
2779
3283
|
config
|
|
2780
3284
|
),
|
|
2781
3285
|
getJupiterQuote(
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
true,
|
|
3286
|
+
__spreadValues({
|
|
3287
|
+
inputMint: inputTokenMint,
|
|
3288
|
+
outputMint: tokenYMint,
|
|
3289
|
+
amount: bestAmountToY,
|
|
3290
|
+
user,
|
|
3291
|
+
maxAccounts: 50,
|
|
3292
|
+
slippageBps: swapSlippageBps
|
|
3293
|
+
}, jupiterQuoteOptions),
|
|
2791
3294
|
config
|
|
2792
3295
|
)
|
|
2793
3296
|
]);
|
|
@@ -2823,6 +3326,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2823
3326
|
}
|
|
2824
3327
|
function estimateDlmmDirectSwapCore(_0) {
|
|
2825
3328
|
return __async(this, arguments, function* ({
|
|
3329
|
+
user,
|
|
2826
3330
|
tokenXAmount,
|
|
2827
3331
|
tokenYAmount,
|
|
2828
3332
|
dlmm,
|
|
@@ -2831,6 +3335,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2831
3335
|
maxDeltaId,
|
|
2832
3336
|
strategy,
|
|
2833
3337
|
singleSided,
|
|
3338
|
+
jupiterQuoteOptions,
|
|
2834
3339
|
config = {}
|
|
2835
3340
|
}) {
|
|
2836
3341
|
if (singleSided !== void 0) {
|
|
@@ -2843,13 +3348,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2843
3348
|
);
|
|
2844
3349
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2845
3350
|
dlmm,
|
|
3351
|
+
user,
|
|
2846
3352
|
dlmm.lbPair.tokenYMint,
|
|
2847
3353
|
dlmm.lbPair.tokenXMint,
|
|
2848
3354
|
tokenYAmount,
|
|
2849
3355
|
swapSlippageBps,
|
|
2850
3356
|
swapForY2,
|
|
2851
3357
|
binArrayForSwap2,
|
|
2852
|
-
config
|
|
3358
|
+
config,
|
|
3359
|
+
jupiterQuoteOptions
|
|
2853
3360
|
);
|
|
2854
3361
|
if (!quote) {
|
|
2855
3362
|
throw new Error(
|
|
@@ -2872,13 +3379,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2872
3379
|
);
|
|
2873
3380
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2874
3381
|
dlmm,
|
|
3382
|
+
user,
|
|
2875
3383
|
dlmm.lbPair.tokenXMint,
|
|
2876
3384
|
dlmm.lbPair.tokenYMint,
|
|
2877
3385
|
tokenXAmount,
|
|
2878
3386
|
swapSlippageBps,
|
|
2879
3387
|
swapForY2,
|
|
2880
3388
|
binArrayForSwap2,
|
|
2881
|
-
config
|
|
3389
|
+
config,
|
|
3390
|
+
jupiterQuoteOptions
|
|
2882
3391
|
);
|
|
2883
3392
|
if (!quote) {
|
|
2884
3393
|
throw new Error(
|
|
@@ -2967,13 +3476,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2967
3476
|
);
|
|
2968
3477
|
const initialQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
2969
3478
|
dlmm,
|
|
3479
|
+
user,
|
|
2970
3480
|
inMint,
|
|
2971
3481
|
outMint,
|
|
2972
3482
|
initialSwapAmount,
|
|
2973
3483
|
swapSlippageBps,
|
|
2974
3484
|
swapForY,
|
|
2975
3485
|
binArrayForSwap,
|
|
2976
|
-
config
|
|
3486
|
+
config,
|
|
3487
|
+
jupiterQuoteOptions
|
|
2977
3488
|
);
|
|
2978
3489
|
if (!initialQuote) {
|
|
2979
3490
|
throw new Error(
|
|
@@ -3025,13 +3536,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3025
3536
|
);
|
|
3026
3537
|
const finalQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3027
3538
|
dlmm,
|
|
3539
|
+
user,
|
|
3028
3540
|
inMint,
|
|
3029
3541
|
outMint,
|
|
3030
3542
|
refinedAmount,
|
|
3031
3543
|
swapSlippageBps,
|
|
3032
3544
|
swapForY,
|
|
3033
3545
|
binArrayForSwap,
|
|
3034
|
-
config
|
|
3546
|
+
config,
|
|
3547
|
+
jupiterQuoteOptions
|
|
3035
3548
|
);
|
|
3036
3549
|
if (!finalQuote) {
|
|
3037
3550
|
return {
|
|
@@ -3057,6 +3570,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3057
3570
|
}
|
|
3058
3571
|
function estimateDlmmDirectSwap(_0) {
|
|
3059
3572
|
return __async(this, arguments, function* ({
|
|
3573
|
+
user,
|
|
3060
3574
|
amountIn,
|
|
3061
3575
|
inputTokenMint,
|
|
3062
3576
|
lbPair,
|
|
@@ -3066,6 +3580,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3066
3580
|
maxDeltaId,
|
|
3067
3581
|
strategy,
|
|
3068
3582
|
singleSided,
|
|
3583
|
+
jupiterQuoteOptions,
|
|
3069
3584
|
config = {}
|
|
3070
3585
|
}) {
|
|
3071
3586
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
@@ -3077,6 +3592,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3077
3592
|
const tokenXAmount = isInputTokenX ? amountIn : new BN3(0);
|
|
3078
3593
|
const tokenYAmount = isInputTokenX ? new BN3(0) : amountIn;
|
|
3079
3594
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3595
|
+
user,
|
|
3080
3596
|
tokenXAmount,
|
|
3081
3597
|
tokenYAmount,
|
|
3082
3598
|
dlmm,
|
|
@@ -3085,6 +3601,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3085
3601
|
maxDeltaId,
|
|
3086
3602
|
strategy,
|
|
3087
3603
|
singleSided,
|
|
3604
|
+
jupiterQuoteOptions,
|
|
3088
3605
|
config
|
|
3089
3606
|
});
|
|
3090
3607
|
return {
|
|
@@ -3104,6 +3621,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3104
3621
|
}
|
|
3105
3622
|
function estimateDlmmRebalanceSwap(_0) {
|
|
3106
3623
|
return __async(this, arguments, function* ({
|
|
3624
|
+
user,
|
|
3107
3625
|
lbPair,
|
|
3108
3626
|
position,
|
|
3109
3627
|
connection,
|
|
@@ -3111,11 +3629,13 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3111
3629
|
minDeltaId,
|
|
3112
3630
|
maxDeltaId,
|
|
3113
3631
|
strategy,
|
|
3632
|
+
jupiterQuoteOptions,
|
|
3114
3633
|
config = {}
|
|
3115
3634
|
}) {
|
|
3116
3635
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3117
3636
|
const userPosition = yield dlmm.getPosition(position);
|
|
3118
3637
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3638
|
+
user,
|
|
3119
3639
|
tokenXAmount: new BN3(userPosition.positionData.totalXAmount),
|
|
3120
3640
|
tokenYAmount: new BN3(userPosition.positionData.totalYAmount),
|
|
3121
3641
|
dlmm,
|
|
@@ -3125,6 +3645,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3125
3645
|
strategy,
|
|
3126
3646
|
singleSided: void 0,
|
|
3127
3647
|
// rebalance does not use single-sided deposits
|
|
3648
|
+
jupiterQuoteOptions,
|
|
3128
3649
|
config
|
|
3129
3650
|
});
|
|
3130
3651
|
return {
|
|
@@ -3213,13 +3734,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
|
|
|
3213
3734
|
var Zap = class {
|
|
3214
3735
|
/**
|
|
3215
3736
|
* @param connection - The connection to the Solana cluster
|
|
3216
|
-
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag)
|
|
3737
|
+
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
|
|
3217
3738
|
*/
|
|
3218
3739
|
constructor(connection, config = {}) {
|
|
3740
|
+
var _a;
|
|
3219
3741
|
this.connection = connection;
|
|
3220
3742
|
this.zapProgram = new Program(idl_default, { connection });
|
|
3221
3743
|
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3222
3744
|
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3745
|
+
this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3223
3746
|
}
|
|
3224
3747
|
/////// PRIVATE FUNDTIONS //////
|
|
3225
3748
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3228,7 +3751,7 @@ var Zap = class {
|
|
|
3228
3751
|
ledger: deriveLedgerAccount(owner),
|
|
3229
3752
|
owner,
|
|
3230
3753
|
payer
|
|
3231
|
-
}).
|
|
3754
|
+
}).instruction();
|
|
3232
3755
|
});
|
|
3233
3756
|
}
|
|
3234
3757
|
closeLedgerAccount(owner, rentReceiver) {
|
|
@@ -3237,7 +3760,7 @@ var Zap = class {
|
|
|
3237
3760
|
ledger: deriveLedgerAccount(owner),
|
|
3238
3761
|
owner,
|
|
3239
3762
|
rentReceiver
|
|
3240
|
-
}).
|
|
3763
|
+
}).instruction();
|
|
3241
3764
|
});
|
|
3242
3765
|
}
|
|
3243
3766
|
setLedgerBalance(owner, amount, isTokenA) {
|
|
@@ -3245,7 +3768,7 @@ var Zap = class {
|
|
|
3245
3768
|
return yield this.zapProgram.methods.setLedgerBalance(amount, isTokenA).accountsPartial({
|
|
3246
3769
|
ledger: deriveLedgerAccount(owner),
|
|
3247
3770
|
owner
|
|
3248
|
-
}).
|
|
3771
|
+
}).instruction();
|
|
3249
3772
|
});
|
|
3250
3773
|
}
|
|
3251
3774
|
updateLedgerBalanceAfterSwap(owner, tokenAccount, preSourceTokenAccount, maxTransferAmount, isTokenA) {
|
|
@@ -3258,7 +3781,7 @@ var Zap = class {
|
|
|
3258
3781
|
ledger: deriveLedgerAccount(owner),
|
|
3259
3782
|
tokenAccount,
|
|
3260
3783
|
owner
|
|
3261
|
-
}).
|
|
3784
|
+
}).instruction();
|
|
3262
3785
|
});
|
|
3263
3786
|
}
|
|
3264
3787
|
zapInDammV2(params) {
|
|
@@ -3296,7 +3819,7 @@ var Zap = class {
|
|
|
3296
3819
|
tokenBProgram,
|
|
3297
3820
|
dammProgram: DAMM_V2_PROGRAM_ID,
|
|
3298
3821
|
dammEventAuthority: deriveDammV2EventAuthority()
|
|
3299
|
-
}).
|
|
3822
|
+
}).instruction();
|
|
3300
3823
|
});
|
|
3301
3824
|
}
|
|
3302
3825
|
resetOrInitializeLedgerAccount(user) {
|
|
@@ -3306,9 +3829,9 @@ var Zap = class {
|
|
|
3306
3829
|
if (accountInfo) {
|
|
3307
3830
|
const closeLedger = yield this.closeLedgerAccount(user, user);
|
|
3308
3831
|
const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
|
|
3309
|
-
return
|
|
3832
|
+
return [closeLedger, reInitializeLedger];
|
|
3310
3833
|
}
|
|
3311
|
-
return yield this.initializeLedgerAccount(user, user);
|
|
3834
|
+
return [yield this.initializeLedgerAccount(user, user)];
|
|
3312
3835
|
});
|
|
3313
3836
|
}
|
|
3314
3837
|
zapInDlmmForInitializedPosition(params) {
|
|
@@ -3375,7 +3898,7 @@ var Zap = class {
|
|
|
3375
3898
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3376
3899
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3377
3900
|
systemProgram: SystemProgram2.programId
|
|
3378
|
-
}).remainingAccounts(binArrays).
|
|
3901
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3379
3902
|
});
|
|
3380
3903
|
}
|
|
3381
3904
|
zapInDlmmForUninitializedPosition(params) {
|
|
@@ -3439,7 +3962,7 @@ var Zap = class {
|
|
|
3439
3962
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3440
3963
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3441
3964
|
systemProgram: SystemProgram2.programId
|
|
3442
|
-
}).remainingAccounts(binArrays).
|
|
3965
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3443
3966
|
});
|
|
3444
3967
|
}
|
|
3445
3968
|
//#region Zap In
|
|
@@ -3459,6 +3982,7 @@ var Zap = class {
|
|
|
3459
3982
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3460
3983
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3461
3984
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
3985
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
|
|
3462
3986
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
3463
3987
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3464
3988
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -3477,7 +4001,8 @@ var Zap = class {
|
|
|
3477
4001
|
slippageBps,
|
|
3478
4002
|
dammV2Quote,
|
|
3479
4003
|
jupiterQuote,
|
|
3480
|
-
maxTransferAmountExtendPercentage
|
|
4004
|
+
maxTransferAmountExtendPercentage,
|
|
4005
|
+
jupiterQuoteOptions
|
|
3481
4006
|
} = params;
|
|
3482
4007
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3483
4008
|
const {
|
|
@@ -3497,7 +4022,7 @@ var Zap = class {
|
|
|
3497
4022
|
const tokenAProgram = getTokenProgram(tokenAFlag);
|
|
3498
4023
|
const tokenBProgram = getTokenProgram(tokenBFlag);
|
|
3499
4024
|
const preInstructions = [];
|
|
3500
|
-
if (
|
|
4025
|
+
if (inputTokenMint.equals(NATIVE_MINT3)) {
|
|
3501
4026
|
const { ataPubkey: userWrapSolAcc, ix: initializeUserWrapSOLAta } = yield getOrCreateATAInstruction(
|
|
3502
4027
|
this.connection,
|
|
3503
4028
|
NATIVE_MINT3,
|
|
@@ -3549,7 +4074,8 @@ var Zap = class {
|
|
|
3549
4074
|
const singleSidedA = isSingleSidedA(poolState);
|
|
3550
4075
|
const singleSidedB = isSingleSidedB(poolState);
|
|
3551
4076
|
let amount;
|
|
3552
|
-
let
|
|
4077
|
+
let swapInstructions = [];
|
|
4078
|
+
let addressLookupTableAccounts = [];
|
|
3553
4079
|
let maxTransferAmount;
|
|
3554
4080
|
let swapInAmount;
|
|
3555
4081
|
let swapRoute;
|
|
@@ -3563,6 +4089,7 @@ var Zap = class {
|
|
|
3563
4089
|
swapInAmount = amountIn;
|
|
3564
4090
|
amount = new BN5(0);
|
|
3565
4091
|
const result = yield buildJupiterSwapTransaction(
|
|
4092
|
+
this.connection,
|
|
3566
4093
|
user,
|
|
3567
4094
|
inputTokenMint,
|
|
3568
4095
|
outputTokenMint,
|
|
@@ -3572,10 +4099,13 @@ var Zap = class {
|
|
|
3572
4099
|
void 0,
|
|
3573
4100
|
{
|
|
3574
4101
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3575
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3576
|
-
|
|
4102
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4103
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4104
|
+
},
|
|
4105
|
+
jupiterQuoteOptions
|
|
3577
4106
|
);
|
|
3578
|
-
|
|
4107
|
+
swapInstructions = [result.instruction];
|
|
4108
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3579
4109
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3580
4110
|
result.quoteResponse.outAmount,
|
|
3581
4111
|
maxTransferAmountExtendPercentage
|
|
@@ -3612,6 +4142,7 @@ var Zap = class {
|
|
|
3612
4142
|
);
|
|
3613
4143
|
amount = amountIn.sub(swapInAmount);
|
|
3614
4144
|
const result = yield buildJupiterSwapTransaction(
|
|
4145
|
+
this.connection,
|
|
3615
4146
|
user,
|
|
3616
4147
|
inputTokenMint,
|
|
3617
4148
|
outputTokenMint,
|
|
@@ -3621,10 +4152,13 @@ var Zap = class {
|
|
|
3621
4152
|
void 0,
|
|
3622
4153
|
{
|
|
3623
4154
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3624
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3625
|
-
|
|
4155
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4156
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4157
|
+
},
|
|
4158
|
+
jupiterQuoteOptions
|
|
3626
4159
|
);
|
|
3627
|
-
|
|
4160
|
+
swapInstructions = [result.instruction];
|
|
4161
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3628
4162
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3629
4163
|
result.quoteResponse.outAmount,
|
|
3630
4164
|
maxTransferAmountExtendPercentage
|
|
@@ -3682,7 +4216,8 @@ var Zap = class {
|
|
|
3682
4216
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3683
4217
|
maxSqrtPriceChangeBps,
|
|
3684
4218
|
preInstructions,
|
|
3685
|
-
|
|
4219
|
+
swapInstructions,
|
|
4220
|
+
addressLookupTableAccounts,
|
|
3686
4221
|
cleanUpInstructions,
|
|
3687
4222
|
swapInEstimate: {
|
|
3688
4223
|
inAmount: swapInAmount,
|
|
@@ -3707,6 +4242,7 @@ var Zap = class {
|
|
|
3707
4242
|
* @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)
|
|
3708
4243
|
* @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)
|
|
3709
4244
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4245
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
|
|
3710
4246
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
3711
4247
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3712
4248
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -3725,7 +4261,8 @@ var Zap = class {
|
|
|
3725
4261
|
maxTransferAmountExtendPercentage,
|
|
3726
4262
|
slippageBps,
|
|
3727
4263
|
jupiterQuoteToA,
|
|
3728
|
-
jupiterQuoteToB
|
|
4264
|
+
jupiterQuoteToB,
|
|
4265
|
+
jupiterQuoteOptions
|
|
3729
4266
|
} = params;
|
|
3730
4267
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3731
4268
|
const {
|
|
@@ -3810,6 +4347,7 @@ var Zap = class {
|
|
|
3810
4347
|
);
|
|
3811
4348
|
}
|
|
3812
4349
|
const result = yield buildJupiterSwapTransaction(
|
|
4350
|
+
this.connection,
|
|
3813
4351
|
user,
|
|
3814
4352
|
inputTokenMint,
|
|
3815
4353
|
tokenAMint,
|
|
@@ -3819,8 +4357,10 @@ var Zap = class {
|
|
|
3819
4357
|
void 0,
|
|
3820
4358
|
{
|
|
3821
4359
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3822
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3823
|
-
|
|
4360
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4361
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4362
|
+
},
|
|
4363
|
+
jupiterQuoteOptions
|
|
3824
4364
|
);
|
|
3825
4365
|
return {
|
|
3826
4366
|
user,
|
|
@@ -3844,7 +4384,8 @@ var Zap = class {
|
|
|
3844
4384
|
maxTransferAmountB: new BN5(0),
|
|
3845
4385
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3846
4386
|
preInstructions,
|
|
3847
|
-
|
|
4387
|
+
swapInstructions: [result.instruction],
|
|
4388
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3848
4389
|
cleanUpInstructions,
|
|
3849
4390
|
swapInEstimate: {
|
|
3850
4391
|
inAmountA: amountIn,
|
|
@@ -3861,6 +4402,7 @@ var Zap = class {
|
|
|
3861
4402
|
);
|
|
3862
4403
|
}
|
|
3863
4404
|
const result = yield buildJupiterSwapTransaction(
|
|
4405
|
+
this.connection,
|
|
3864
4406
|
user,
|
|
3865
4407
|
inputTokenMint,
|
|
3866
4408
|
tokenBMint,
|
|
@@ -3870,8 +4412,10 @@ var Zap = class {
|
|
|
3870
4412
|
void 0,
|
|
3871
4413
|
{
|
|
3872
4414
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3873
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3874
|
-
|
|
4415
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4416
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4417
|
+
},
|
|
4418
|
+
jupiterQuoteOptions
|
|
3875
4419
|
);
|
|
3876
4420
|
return {
|
|
3877
4421
|
user,
|
|
@@ -3895,7 +4439,8 @@ var Zap = class {
|
|
|
3895
4439
|
swapType: 1 /* swapToB */,
|
|
3896
4440
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3897
4441
|
preInstructions,
|
|
3898
|
-
|
|
4442
|
+
swapInstructions: [result.instruction],
|
|
4443
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3899
4444
|
cleanUpInstructions,
|
|
3900
4445
|
swapInEstimate: {
|
|
3901
4446
|
inAmountA: new BN5(0),
|
|
@@ -3907,6 +4452,7 @@ var Zap = class {
|
|
|
3907
4452
|
}
|
|
3908
4453
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3909
4454
|
const result = yield buildJupiterSwapTransaction(
|
|
4455
|
+
this.connection,
|
|
3910
4456
|
user,
|
|
3911
4457
|
inputTokenMint,
|
|
3912
4458
|
tokenAMint,
|
|
@@ -3916,8 +4462,10 @@ var Zap = class {
|
|
|
3916
4462
|
void 0,
|
|
3917
4463
|
{
|
|
3918
4464
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3919
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3920
|
-
|
|
4465
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4466
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4467
|
+
},
|
|
4468
|
+
jupiterQuoteOptions
|
|
3921
4469
|
);
|
|
3922
4470
|
return {
|
|
3923
4471
|
user,
|
|
@@ -3941,7 +4489,8 @@ var Zap = class {
|
|
|
3941
4489
|
maxTransferAmountB: new BN5(0),
|
|
3942
4490
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3943
4491
|
preInstructions,
|
|
3944
|
-
|
|
4492
|
+
swapInstructions: [result.instruction],
|
|
4493
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3945
4494
|
cleanUpInstructions,
|
|
3946
4495
|
swapInEstimate: {
|
|
3947
4496
|
inAmountA: amountIn,
|
|
@@ -3953,6 +4502,7 @@ var Zap = class {
|
|
|
3953
4502
|
}
|
|
3954
4503
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3955
4504
|
const result = yield buildJupiterSwapTransaction(
|
|
4505
|
+
this.connection,
|
|
3956
4506
|
user,
|
|
3957
4507
|
inputTokenMint,
|
|
3958
4508
|
tokenBMint,
|
|
@@ -3962,8 +4512,10 @@ var Zap = class {
|
|
|
3962
4512
|
void 0,
|
|
3963
4513
|
{
|
|
3964
4514
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3965
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3966
|
-
|
|
4515
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4516
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4517
|
+
},
|
|
4518
|
+
jupiterQuoteOptions
|
|
3967
4519
|
);
|
|
3968
4520
|
return {
|
|
3969
4521
|
user,
|
|
@@ -3987,7 +4539,8 @@ var Zap = class {
|
|
|
3987
4539
|
swapType: 1 /* swapToB */,
|
|
3988
4540
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3989
4541
|
preInstructions,
|
|
3990
|
-
|
|
4542
|
+
swapInstructions: [result.instruction],
|
|
4543
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3991
4544
|
cleanUpInstructions,
|
|
3992
4545
|
swapInEstimate: {
|
|
3993
4546
|
inAmountA: new BN5(0),
|
|
@@ -4039,7 +4592,8 @@ var Zap = class {
|
|
|
4039
4592
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4040
4593
|
cleanUpInstructions
|
|
4041
4594
|
};
|
|
4042
|
-
const
|
|
4595
|
+
const swapToA = yield buildJupiterSwapTransaction(
|
|
4596
|
+
this.connection,
|
|
4043
4597
|
user,
|
|
4044
4598
|
inputTokenMint,
|
|
4045
4599
|
tokenAMint,
|
|
@@ -4049,10 +4603,13 @@ var Zap = class {
|
|
|
4049
4603
|
void 0,
|
|
4050
4604
|
{
|
|
4051
4605
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4052
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4053
|
-
|
|
4606
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4607
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4608
|
+
},
|
|
4609
|
+
jupiterQuoteOptions
|
|
4054
4610
|
);
|
|
4055
|
-
const
|
|
4611
|
+
const swapToB = yield buildJupiterSwapTransaction(
|
|
4612
|
+
this.connection,
|
|
4056
4613
|
user,
|
|
4057
4614
|
inputTokenMint,
|
|
4058
4615
|
tokenBMint,
|
|
@@ -4062,20 +4619,26 @@ var Zap = class {
|
|
|
4062
4619
|
void 0,
|
|
4063
4620
|
{
|
|
4064
4621
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4065
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4066
|
-
|
|
4622
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4623
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4624
|
+
},
|
|
4625
|
+
jupiterQuoteOptions
|
|
4067
4626
|
);
|
|
4068
4627
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4069
4628
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4070
|
-
|
|
4629
|
+
swapToA.quoteResponse.outAmount,
|
|
4071
4630
|
maxTransferAmountExtendPercentage
|
|
4072
4631
|
),
|
|
4073
4632
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
4074
|
-
|
|
4633
|
+
swapToB.quoteResponse.outAmount,
|
|
4075
4634
|
maxTransferAmountExtendPercentage
|
|
4076
4635
|
),
|
|
4077
4636
|
swapType: 2 /* swapToBoth */,
|
|
4078
|
-
|
|
4637
|
+
swapInstructions: [swapToA.instruction, swapToB.instruction],
|
|
4638
|
+
addressLookupTableAccounts: mergeAddressLookupTableAccounts(
|
|
4639
|
+
swapToA.addressLookupTableAccounts,
|
|
4640
|
+
swapToB.addressLookupTableAccounts
|
|
4641
|
+
),
|
|
4079
4642
|
swapInEstimate: {
|
|
4080
4643
|
inAmountA: swapAmountToA,
|
|
4081
4644
|
inAmountB: swapAmountToB,
|
|
@@ -4090,7 +4653,12 @@ var Zap = class {
|
|
|
4090
4653
|
});
|
|
4091
4654
|
}
|
|
4092
4655
|
/**
|
|
4093
|
-
* Build DAMM v2 zap-in
|
|
4656
|
+
* Build the DAMM v2 zap-in instructions
|
|
4657
|
+
*
|
|
4658
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
4659
|
+
* They must run in that order but can be split across several transactions, because state
|
|
4660
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
4661
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4094
4662
|
*
|
|
4095
4663
|
* @param params.user - The user's public key
|
|
4096
4664
|
* @param params.pool - The pool's public key
|
|
@@ -4107,9 +4675,10 @@ var Zap = class {
|
|
|
4107
4675
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4108
4676
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4109
4677
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4110
|
-
* @param params.
|
|
4678
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
4679
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4111
4680
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4112
|
-
* @returns
|
|
4681
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4113
4682
|
*/
|
|
4114
4683
|
buildZapInDammV2Transaction(params) {
|
|
4115
4684
|
return __async(this, null, function* () {
|
|
@@ -4129,7 +4698,8 @@ var Zap = class {
|
|
|
4129
4698
|
preSqrtPrice,
|
|
4130
4699
|
maxSqrtPriceChangeBps,
|
|
4131
4700
|
preInstructions,
|
|
4132
|
-
|
|
4701
|
+
swapInstructions,
|
|
4702
|
+
addressLookupTableAccounts,
|
|
4133
4703
|
cleanUpInstructions
|
|
4134
4704
|
} = params;
|
|
4135
4705
|
const [
|
|
@@ -4153,37 +4723,33 @@ var Zap = class {
|
|
|
4153
4723
|
tokenBProgram
|
|
4154
4724
|
)
|
|
4155
4725
|
]);
|
|
4156
|
-
const
|
|
4157
|
-
initializeTokenAIx &&
|
|
4158
|
-
initializeTokenBIx &&
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
}
|
|
4162
|
-
const ledgerTransaction = new Transaction2();
|
|
4163
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4164
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4726
|
+
const setupInstructions = [];
|
|
4727
|
+
initializeTokenAIx && setupInstructions.push(initializeTokenAIx);
|
|
4728
|
+
initializeTokenBIx && setupInstructions.push(initializeTokenBIx);
|
|
4729
|
+
setupInstructions.push(...preInstructions);
|
|
4730
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4165
4731
|
if (isDirectPool) {
|
|
4166
4732
|
const isTokenA = params.isTokenA;
|
|
4167
|
-
const
|
|
4733
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4168
4734
|
user,
|
|
4169
4735
|
amount,
|
|
4170
4736
|
isTokenA
|
|
4171
4737
|
);
|
|
4172
|
-
|
|
4173
|
-
if (
|
|
4738
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4739
|
+
if (swapInstructions.length > 0) {
|
|
4174
4740
|
const tokenAccount = isTokenA ? tokenBAccount : tokenAAccount;
|
|
4175
4741
|
const preTokenBalance = yield getTokenAccountBalance(
|
|
4176
4742
|
this.connection,
|
|
4177
4743
|
tokenAccount
|
|
4178
4744
|
);
|
|
4179
|
-
const
|
|
4745
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4180
4746
|
user,
|
|
4181
4747
|
tokenAccount,
|
|
4182
4748
|
new BN5(preTokenBalance),
|
|
4183
4749
|
params.maxTransferAmount,
|
|
4184
4750
|
!isTokenA
|
|
4185
4751
|
);
|
|
4186
|
-
|
|
4752
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4187
4753
|
}
|
|
4188
4754
|
} else {
|
|
4189
4755
|
const preTokenABalance = yield getTokenAccountBalance(
|
|
@@ -4194,7 +4760,7 @@ var Zap = class {
|
|
|
4194
4760
|
this.connection,
|
|
4195
4761
|
tokenBAccount
|
|
4196
4762
|
);
|
|
4197
|
-
const
|
|
4763
|
+
const updateLedgerBalanceTokenAAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4198
4764
|
user,
|
|
4199
4765
|
tokenAAccount,
|
|
4200
4766
|
new BN5(preTokenABalance),
|
|
@@ -4202,7 +4768,7 @@ var Zap = class {
|
|
|
4202
4768
|
true
|
|
4203
4769
|
// is token A
|
|
4204
4770
|
);
|
|
4205
|
-
const
|
|
4771
|
+
const updateLedgerBalanceTokenBAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4206
4772
|
user,
|
|
4207
4773
|
tokenBAccount,
|
|
4208
4774
|
new BN5(preTokenBBalance),
|
|
@@ -4212,14 +4778,17 @@ var Zap = class {
|
|
|
4212
4778
|
);
|
|
4213
4779
|
const swapType = params.swapType;
|
|
4214
4780
|
if (swapType == 0 /* swapToA */) {
|
|
4215
|
-
|
|
4781
|
+
ledgerInstructions.push(updateLedgerBalanceTokenAAfterSwapIx);
|
|
4216
4782
|
} else if (swapType == 1 /* swapToB */) {
|
|
4217
|
-
|
|
4783
|
+
ledgerInstructions.push(updateLedgerBalanceTokenBAfterSwapIx);
|
|
4218
4784
|
} else {
|
|
4219
|
-
|
|
4785
|
+
ledgerInstructions.push(
|
|
4786
|
+
updateLedgerBalanceTokenAAfterSwapIx,
|
|
4787
|
+
updateLedgerBalanceTokenBAfterSwapIx
|
|
4788
|
+
);
|
|
4220
4789
|
}
|
|
4221
4790
|
}
|
|
4222
|
-
const
|
|
4791
|
+
const zapInInstruction = yield this.zapInDammV2({
|
|
4223
4792
|
user,
|
|
4224
4793
|
pool,
|
|
4225
4794
|
position,
|
|
@@ -4235,18 +4804,17 @@ var Zap = class {
|
|
|
4235
4804
|
tokenAAccount,
|
|
4236
4805
|
tokenBAccount
|
|
4237
4806
|
});
|
|
4238
|
-
const
|
|
4239
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4240
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4241
|
-
if (cleanUpInstructions.length > 0) {
|
|
4242
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4243
|
-
}
|
|
4807
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4244
4808
|
return {
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4809
|
+
instructions: [
|
|
4810
|
+
...setupInstructions,
|
|
4811
|
+
...swapInstructions,
|
|
4812
|
+
...ledgerInstructions,
|
|
4813
|
+
zapInInstruction,
|
|
4814
|
+
closeLedgerInstruction,
|
|
4815
|
+
...cleanUpInstructions
|
|
4816
|
+
],
|
|
4817
|
+
addressLookupTableAccounts
|
|
4250
4818
|
};
|
|
4251
4819
|
});
|
|
4252
4820
|
}
|
|
@@ -4263,8 +4831,8 @@ var Zap = class {
|
|
|
4263
4831
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4264
4832
|
* @param params.strategy - The liquidity distribution strategy
|
|
4265
4833
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4266
|
-
* @param params.maxAccounts -
|
|
4267
|
-
* @param params.swapSlippageBps -
|
|
4834
|
+
* @param params.maxAccounts - Max accounts for the Jupiter swap query. Example value is `50`; this is not safe for every pool/size. Combined with Direct estimators (`onlyDirectRoutes=true`) this can select a much thinner route than Jupiter UI.
|
|
4835
|
+
* @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
|
|
4268
4836
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4269
4837
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
4270
4838
|
* @param params.directSwapEstimate - The result from the direct swap estimate
|
|
@@ -4317,12 +4885,14 @@ var Zap = class {
|
|
|
4317
4885
|
initializeWrapSolIx && preInstructions.push(initializeWrapSolIx);
|
|
4318
4886
|
preInstructions.push(...wrapSOL);
|
|
4319
4887
|
}
|
|
4320
|
-
const
|
|
4888
|
+
const swapInstructions = [];
|
|
4889
|
+
let addressLookupTableAccounts = [];
|
|
4321
4890
|
let maxTransferAmount;
|
|
4322
4891
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4323
4892
|
const swapQuote = directSwapEstimate.quote;
|
|
4324
4893
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4325
|
-
const
|
|
4894
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
4895
|
+
this.connection,
|
|
4326
4896
|
user,
|
|
4327
4897
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4328
4898
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
@@ -4332,10 +4902,12 @@ var Zap = class {
|
|
|
4332
4902
|
swapQuote.originalQuote,
|
|
4333
4903
|
{
|
|
4334
4904
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4335
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4905
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4906
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4336
4907
|
}
|
|
4337
4908
|
);
|
|
4338
|
-
|
|
4909
|
+
swapInstructions.push(swap.instruction);
|
|
4910
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4339
4911
|
} else {
|
|
4340
4912
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4341
4913
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4348,6 +4920,9 @@ var Zap = class {
|
|
|
4348
4920
|
user,
|
|
4349
4921
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4350
4922
|
});
|
|
4923
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
4924
|
+
swapTx.instructions
|
|
4925
|
+
);
|
|
4351
4926
|
if (tokenXMint.equals(NATIVE_MINT3) || tokenYMint.equals(NATIVE_MINT3)) {
|
|
4352
4927
|
swapTx.instructions = swapTx.instructions.filter((ix) => {
|
|
4353
4928
|
if (ix.programId.equals(TOKEN_PROGRAM_ID6)) {
|
|
@@ -4356,7 +4931,7 @@ var Zap = class {
|
|
|
4356
4931
|
return true;
|
|
4357
4932
|
});
|
|
4358
4933
|
}
|
|
4359
|
-
|
|
4934
|
+
swapInstructions.push(...swapTx.instructions);
|
|
4360
4935
|
}
|
|
4361
4936
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
4362
4937
|
directSwapEstimate.expectedOutput.toString(),
|
|
@@ -4406,7 +4981,8 @@ var Zap = class {
|
|
|
4406
4981
|
amount,
|
|
4407
4982
|
maxTransferAmount,
|
|
4408
4983
|
preInstructions,
|
|
4409
|
-
|
|
4984
|
+
swapInstructions,
|
|
4985
|
+
addressLookupTableAccounts,
|
|
4410
4986
|
cleanUpInstructions,
|
|
4411
4987
|
binArrays,
|
|
4412
4988
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4487,11 +5063,13 @@ var Zap = class {
|
|
|
4487
5063
|
}
|
|
4488
5064
|
let maxTransferAmountX;
|
|
4489
5065
|
let maxTransferAmountY;
|
|
4490
|
-
const
|
|
5066
|
+
const swapInstructions = [];
|
|
5067
|
+
const swapLookupTables = [];
|
|
4491
5068
|
const swapAmountToXInLamports = indirectSwapEstimate.swapAmountToX;
|
|
4492
5069
|
const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
|
|
4493
5070
|
if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
|
|
4494
|
-
const
|
|
5071
|
+
const swapToX = yield buildJupiterSwapTransaction(
|
|
5072
|
+
this.connection,
|
|
4495
5073
|
user,
|
|
4496
5074
|
inputTokenMint,
|
|
4497
5075
|
tokenXMint,
|
|
@@ -4501,13 +5079,16 @@ var Zap = class {
|
|
|
4501
5079
|
indirectSwapEstimate.swapToX,
|
|
4502
5080
|
{
|
|
4503
5081
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4504
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5082
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5083
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4505
5084
|
}
|
|
4506
5085
|
);
|
|
4507
|
-
|
|
5086
|
+
swapInstructions.push(swapToX.instruction);
|
|
5087
|
+
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
4508
5088
|
}
|
|
4509
5089
|
if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
|
|
4510
|
-
const
|
|
5090
|
+
const swapToY = yield buildJupiterSwapTransaction(
|
|
5091
|
+
this.connection,
|
|
4511
5092
|
user,
|
|
4512
5093
|
inputTokenMint,
|
|
4513
5094
|
tokenYMint,
|
|
@@ -4517,11 +5098,16 @@ var Zap = class {
|
|
|
4517
5098
|
indirectSwapEstimate.swapToY,
|
|
4518
5099
|
{
|
|
4519
5100
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4520
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5101
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5102
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4521
5103
|
}
|
|
4522
5104
|
);
|
|
4523
|
-
|
|
5105
|
+
swapInstructions.push(swapToY.instruction);
|
|
5106
|
+
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
4524
5107
|
}
|
|
5108
|
+
const addressLookupTableAccounts = mergeAddressLookupTableAccounts(
|
|
5109
|
+
...swapLookupTables
|
|
5110
|
+
);
|
|
4525
5111
|
maxTransferAmountX = getExtendMaxAmountTransfer(
|
|
4526
5112
|
indirectSwapEstimate.postSwapX.toString(),
|
|
4527
5113
|
maxTransferAmountExtendPercentage
|
|
@@ -4563,7 +5149,8 @@ var Zap = class {
|
|
|
4563
5149
|
maxTransferAmountX,
|
|
4564
5150
|
maxTransferAmountY,
|
|
4565
5151
|
preInstructions,
|
|
4566
|
-
|
|
5152
|
+
swapInstructions,
|
|
5153
|
+
addressLookupTableAccounts,
|
|
4567
5154
|
cleanUpInstructions,
|
|
4568
5155
|
binArrays,
|
|
4569
5156
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4573,7 +5160,12 @@ var Zap = class {
|
|
|
4573
5160
|
});
|
|
4574
5161
|
}
|
|
4575
5162
|
/**
|
|
4576
|
-
*
|
|
5163
|
+
* Build the DLMM zap-in instructions
|
|
5164
|
+
*
|
|
5165
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
5166
|
+
* They must run in that order but can be split across several transactions, because state
|
|
5167
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
5168
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4577
5169
|
*
|
|
4578
5170
|
* @param params.user - The user's public key
|
|
4579
5171
|
* @param params.lbPair - The DLMM pool's public key
|
|
@@ -4589,13 +5181,14 @@ var Zap = class {
|
|
|
4589
5181
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4590
5182
|
* @param params.strategy - The liquidity distribution strategy
|
|
4591
5183
|
* @param params.preInstructions - Instructions to run before the zap in
|
|
4592
|
-
* @param params.
|
|
5184
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
5185
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4593
5186
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4594
5187
|
* @param params.binArrays - The bin arrays required for the position
|
|
4595
5188
|
* @param params.binArrayBitmapExtension - The bin array bitmap extension account if it exists
|
|
4596
5189
|
* @param params.isDirectRoute - Whether this is a direct route
|
|
4597
5190
|
* @param params.singleSided - Optional single-sided deposit mode (X or Y only) - default is non-single-sided
|
|
4598
|
-
* @returns
|
|
5191
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4599
5192
|
*/
|
|
4600
5193
|
buildZapInDlmmTransaction(params) {
|
|
4601
5194
|
return __async(this, null, function* () {
|
|
@@ -4614,7 +5207,8 @@ var Zap = class {
|
|
|
4614
5207
|
favorXInActiveId,
|
|
4615
5208
|
strategy,
|
|
4616
5209
|
preInstructions,
|
|
4617
|
-
|
|
5210
|
+
swapInstructions,
|
|
5211
|
+
addressLookupTableAccounts,
|
|
4618
5212
|
cleanUpInstructions,
|
|
4619
5213
|
binArrays,
|
|
4620
5214
|
binArrayBitmapExtension,
|
|
@@ -4642,62 +5236,58 @@ var Zap = class {
|
|
|
4642
5236
|
tokenYProgram
|
|
4643
5237
|
)
|
|
4644
5238
|
]);
|
|
4645
|
-
const
|
|
4646
|
-
initializeTokenXIx &&
|
|
4647
|
-
initializeTokenYIx &&
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
}
|
|
4651
|
-
const ledgerTransaction = new Transaction2();
|
|
4652
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4653
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
5239
|
+
const setupInstructions = [];
|
|
5240
|
+
initializeTokenXIx && setupInstructions.push(initializeTokenXIx);
|
|
5241
|
+
initializeTokenYIx && setupInstructions.push(initializeTokenYIx);
|
|
5242
|
+
setupInstructions.push(...preInstructions);
|
|
5243
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4654
5244
|
if (isDirectRoute) {
|
|
4655
5245
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
4656
5246
|
if (singleSided !== void 0) {
|
|
4657
5247
|
const singleSidedX = singleSided === 0 /* X */;
|
|
4658
|
-
if (
|
|
5248
|
+
if (swapInstructions.length > 0) {
|
|
4659
5249
|
const swappedTokenAccount = singleSidedX ? tokenXAccount : tokenYAccount;
|
|
4660
5250
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4661
5251
|
this.connection,
|
|
4662
5252
|
swappedTokenAccount
|
|
4663
5253
|
);
|
|
4664
|
-
const
|
|
5254
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4665
5255
|
user,
|
|
4666
5256
|
swappedTokenAccount,
|
|
4667
5257
|
new BN5(preSwappedTokenBalance),
|
|
4668
5258
|
maxTransferAmount,
|
|
4669
5259
|
singleSidedX
|
|
4670
5260
|
);
|
|
4671
|
-
|
|
5261
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4672
5262
|
} else {
|
|
4673
|
-
const
|
|
5263
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4674
5264
|
user,
|
|
4675
5265
|
amount,
|
|
4676
5266
|
singleSidedX
|
|
4677
5267
|
);
|
|
4678
|
-
|
|
5268
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4679
5269
|
}
|
|
4680
5270
|
} else {
|
|
4681
|
-
const
|
|
5271
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4682
5272
|
user,
|
|
4683
5273
|
amount,
|
|
4684
5274
|
isTokenX
|
|
4685
5275
|
);
|
|
4686
|
-
|
|
4687
|
-
if (
|
|
5276
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
5277
|
+
if (swapInstructions.length > 0) {
|
|
4688
5278
|
const swappedTokenAccount = isTokenX ? tokenYAccount : tokenXAccount;
|
|
4689
5279
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4690
5280
|
this.connection,
|
|
4691
5281
|
swappedTokenAccount
|
|
4692
5282
|
);
|
|
4693
|
-
const
|
|
5283
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4694
5284
|
user,
|
|
4695
5285
|
swappedTokenAccount,
|
|
4696
5286
|
new BN5(preSwappedTokenBalance),
|
|
4697
5287
|
maxTransferAmount,
|
|
4698
5288
|
!isTokenX
|
|
4699
5289
|
);
|
|
4700
|
-
|
|
5290
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4701
5291
|
}
|
|
4702
5292
|
}
|
|
4703
5293
|
} else {
|
|
@@ -4709,14 +5299,14 @@ var Zap = class {
|
|
|
4709
5299
|
this.connection,
|
|
4710
5300
|
swappedTokenAccount
|
|
4711
5301
|
);
|
|
4712
|
-
const
|
|
5302
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4713
5303
|
user,
|
|
4714
5304
|
swappedTokenAccount,
|
|
4715
5305
|
new BN5(preSwappedTokenBalance),
|
|
4716
5306
|
singleSidedX ? maxTransferAmountX : maxTransferAmountY,
|
|
4717
5307
|
singleSidedX
|
|
4718
5308
|
);
|
|
4719
|
-
|
|
5309
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4720
5310
|
} else {
|
|
4721
5311
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
4722
5312
|
this.connection,
|
|
@@ -4726,22 +5316,22 @@ var Zap = class {
|
|
|
4726
5316
|
this.connection,
|
|
4727
5317
|
tokenYAccount
|
|
4728
5318
|
);
|
|
4729
|
-
const
|
|
5319
|
+
const updateLedgerBalanceTokenXAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4730
5320
|
user,
|
|
4731
5321
|
tokenXAccount,
|
|
4732
5322
|
new BN5(preTokenXBalance),
|
|
4733
5323
|
maxTransferAmountX,
|
|
4734
5324
|
true
|
|
4735
5325
|
);
|
|
4736
|
-
const
|
|
5326
|
+
const updateLedgerBalanceTokenYAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4737
5327
|
user,
|
|
4738
5328
|
tokenYAccount,
|
|
4739
5329
|
new BN5(preTokenYBalance),
|
|
4740
5330
|
maxTransferAmountY,
|
|
4741
5331
|
false
|
|
4742
5332
|
);
|
|
4743
|
-
|
|
4744
|
-
|
|
5333
|
+
ledgerInstructions.push(updateLedgerBalanceTokenXAfterSwapIx);
|
|
5334
|
+
ledgerInstructions.push(updateLedgerBalanceTokenYAfterSwapIx);
|
|
4745
5335
|
}
|
|
4746
5336
|
}
|
|
4747
5337
|
const dlmm = yield DLMM3.create(this.connection, lbPair);
|
|
@@ -4755,7 +5345,7 @@ var Zap = class {
|
|
|
4755
5345
|
tokenYProgram,
|
|
4756
5346
|
dlmm.lbPair
|
|
4757
5347
|
);
|
|
4758
|
-
const
|
|
5348
|
+
const zapInInstruction = yield this.zapInDlmmForUninitializedPosition({
|
|
4759
5349
|
user,
|
|
4760
5350
|
lbPair,
|
|
4761
5351
|
position,
|
|
@@ -4769,18 +5359,17 @@ var Zap = class {
|
|
|
4769
5359
|
strategy,
|
|
4770
5360
|
remainingAccountInfo
|
|
4771
5361
|
});
|
|
4772
|
-
const
|
|
4773
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4774
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4775
|
-
if (cleanUpInstructions.length > 0) {
|
|
4776
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4777
|
-
}
|
|
5362
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4778
5363
|
return {
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
5364
|
+
instructions: [
|
|
5365
|
+
...setupInstructions,
|
|
5366
|
+
...swapInstructions,
|
|
5367
|
+
...ledgerInstructions,
|
|
5368
|
+
zapInInstruction,
|
|
5369
|
+
closeLedgerInstruction,
|
|
5370
|
+
...cleanUpInstructions
|
|
5371
|
+
],
|
|
5372
|
+
addressLookupTableAccounts
|
|
4784
5373
|
};
|
|
4785
5374
|
});
|
|
4786
5375
|
}
|
|
@@ -4788,6 +5377,13 @@ var Zap = class {
|
|
|
4788
5377
|
* High level method for DLMM position rebalancing
|
|
4789
5378
|
* Consist of remove liquidity, zap out through Jupiter or DLMM, and zap back in to rebalance the position
|
|
4790
5379
|
*
|
|
5380
|
+
* Instructions are ordered: setup (token accounts), init bin arrays, rebalance position, swap, ledger,
|
|
5381
|
+
* zap in, clean up. They must run in that order but can be split across several transactions.
|
|
5382
|
+
* Splitting loses atomicity, so send split transactions as a bundle.
|
|
5383
|
+
* No compute budget instructions are included. The zap-in instruction was measured at about 462k
|
|
5384
|
+
* compute units. Without a compute unit limit, a transaction gets 200k units per instruction (up to
|
|
5385
|
+
* 1.4M), which may not cover it, so set a compute unit limit on the transaction that holds it.
|
|
5386
|
+
*
|
|
4791
5387
|
* @param params - Rebalancing DLMM position parameters
|
|
4792
5388
|
* @param params.lbPairAddress - The DLMM pool address
|
|
4793
5389
|
* @param params.positionAddress - The position address
|
|
@@ -4800,7 +5396,7 @@ var Zap = class {
|
|
|
4800
5396
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4801
5397
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
4802
5398
|
* @param params.maxAccounts - The maximum number of accounts to use for the swap operation
|
|
4803
|
-
* @returns
|
|
5399
|
+
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
4804
5400
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
4805
5401
|
*/
|
|
4806
5402
|
rebalanceDlmmPosition(params) {
|
|
@@ -4842,9 +5438,9 @@ var Zap = class {
|
|
|
4842
5438
|
tokenYProgram
|
|
4843
5439
|
)
|
|
4844
5440
|
]);
|
|
4845
|
-
const
|
|
4846
|
-
userTokenXIx &&
|
|
4847
|
-
userTokenYIx &&
|
|
5441
|
+
const setupInstructions = [];
|
|
5442
|
+
userTokenXIx && setupInstructions.push(userTokenXIx);
|
|
5443
|
+
userTokenYIx && setupInstructions.push(userTokenYIx);
|
|
4848
5444
|
const strategyParamBuilder = getLiquidityStrategyParameterBuilder(strategy);
|
|
4849
5445
|
const { x0, y0, deltaX, deltaY } = buildLiquidityStrategyParameters(
|
|
4850
5446
|
new BN5(0),
|
|
@@ -4895,19 +5491,23 @@ var Zap = class {
|
|
|
4895
5491
|
{ simulationResult, rebalancePosition },
|
|
4896
5492
|
new BN5(maxActiveBinSlippage)
|
|
4897
5493
|
);
|
|
4898
|
-
let rebalancePositionInstruction =
|
|
5494
|
+
let rebalancePositionInstruction = filterOutComputeBudgetInstructions(
|
|
5495
|
+
_rebalancePositionInstruction
|
|
5496
|
+
);
|
|
4899
5497
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
4900
5498
|
rebalancePositionInstruction = filterOutCloseSplTokenAccountInstructions(
|
|
4901
|
-
|
|
5499
|
+
rebalancePositionInstruction
|
|
4902
5500
|
);
|
|
4903
5501
|
}
|
|
4904
5502
|
const tokenXAmount = new BN5(userPosition.positionData.totalXAmount);
|
|
4905
5503
|
const tokenYAmount = new BN5(userPosition.positionData.totalYAmount);
|
|
4906
|
-
let
|
|
5504
|
+
let swapInstructions = [];
|
|
5505
|
+
let addressLookupTableAccounts = [];
|
|
4907
5506
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4908
5507
|
const swapQuote = directSwapEstimate.quote;
|
|
4909
5508
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4910
|
-
const
|
|
5509
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
5510
|
+
this.connection,
|
|
4911
5511
|
user,
|
|
4912
5512
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
4913
5513
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
@@ -4917,10 +5517,12 @@ var Zap = class {
|
|
|
4917
5517
|
swapQuote.originalQuote,
|
|
4918
5518
|
{
|
|
4919
5519
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4920
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5520
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5521
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4921
5522
|
}
|
|
4922
5523
|
);
|
|
4923
|
-
|
|
5524
|
+
swapInstructions = [swap.instruction];
|
|
5525
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4924
5526
|
} else {
|
|
4925
5527
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4926
5528
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4933,12 +5535,15 @@ var Zap = class {
|
|
|
4933
5535
|
user,
|
|
4934
5536
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4935
5537
|
});
|
|
5538
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
5539
|
+
swapTx.instructions
|
|
5540
|
+
);
|
|
4936
5541
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
4937
5542
|
swapTx.instructions = filterOutCloseSplTokenAccountInstructions(
|
|
4938
5543
|
swapTx.instructions
|
|
4939
5544
|
);
|
|
4940
5545
|
}
|
|
4941
|
-
|
|
5546
|
+
swapInstructions = swapTx.instructions;
|
|
4942
5547
|
}
|
|
4943
5548
|
}
|
|
4944
5549
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
@@ -4953,27 +5558,27 @@ var Zap = class {
|
|
|
4953
5558
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4954
5559
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4955
5560
|
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4956
|
-
const
|
|
5561
|
+
const ledgerInstructions = [];
|
|
4957
5562
|
if (!ledgerAccountInfo) {
|
|
4958
|
-
const
|
|
4959
|
-
|
|
5563
|
+
const initLedgerIx = yield this.initializeLedgerAccount(user, user);
|
|
5564
|
+
ledgerInstructions.push(initLedgerIx);
|
|
4960
5565
|
}
|
|
4961
|
-
const
|
|
5566
|
+
const updateLedgerXIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4962
5567
|
user,
|
|
4963
5568
|
userTokenX,
|
|
4964
5569
|
new BN5(preTokenXBalance),
|
|
4965
5570
|
tokenXAmountAfterSwap,
|
|
4966
5571
|
true
|
|
4967
5572
|
);
|
|
4968
|
-
|
|
4969
|
-
const
|
|
5573
|
+
ledgerInstructions.push(updateLedgerXIx);
|
|
5574
|
+
const updateLedgerYIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4970
5575
|
user,
|
|
4971
5576
|
userTokenY,
|
|
4972
5577
|
new BN5(preTokenYBalance),
|
|
4973
5578
|
tokenYAmountAfterSwap,
|
|
4974
5579
|
false
|
|
4975
5580
|
);
|
|
4976
|
-
|
|
5581
|
+
ledgerInstructions.push(updateLedgerYIx);
|
|
4977
5582
|
const binArrays = getBinArraysRequiredByPositionRange(
|
|
4978
5583
|
lbPair,
|
|
4979
5584
|
new BN5(dlmm.lbPair.activeId + minDeltaId),
|
|
@@ -4994,7 +5599,7 @@ var Zap = class {
|
|
|
4994
5599
|
tokenYProgram,
|
|
4995
5600
|
dlmm.lbPair
|
|
4996
5601
|
);
|
|
4997
|
-
const
|
|
5602
|
+
const zapInInstruction = yield this.zapInDlmmForInitializedPosition({
|
|
4998
5603
|
user,
|
|
4999
5604
|
lbPair,
|
|
5000
5605
|
position,
|
|
@@ -5007,28 +5612,26 @@ var Zap = class {
|
|
|
5007
5612
|
strategy,
|
|
5008
5613
|
remainingAccountInfo
|
|
5009
5614
|
});
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
ComputeBudgetProgram.setComputeUnitLimit({ units: 6e5 })
|
|
5014
|
-
);
|
|
5015
|
-
const cleanUpTransaction = new Transaction2();
|
|
5016
|
-
const closeLedgerTx = yield this.closeLedgerAccount(user, user);
|
|
5017
|
-
cleanUpTransaction.add(closeLedgerTx);
|
|
5615
|
+
const cleanUpInstructions = [
|
|
5616
|
+
yield this.closeLedgerAccount(user, user)
|
|
5617
|
+
];
|
|
5018
5618
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
5019
5619
|
const unwrapIx = unwrapSOLInstruction(user, user);
|
|
5020
5620
|
if (unwrapIx) {
|
|
5021
|
-
|
|
5621
|
+
cleanUpInstructions.push(unwrapIx);
|
|
5022
5622
|
}
|
|
5023
5623
|
}
|
|
5024
5624
|
return {
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5625
|
+
instructions: [
|
|
5626
|
+
...setupInstructions,
|
|
5627
|
+
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5628
|
+
...rebalancePositionInstruction,
|
|
5629
|
+
...swapInstructions,
|
|
5630
|
+
...ledgerInstructions,
|
|
5631
|
+
zapInInstruction,
|
|
5632
|
+
...cleanUpInstructions
|
|
5633
|
+
],
|
|
5634
|
+
addressLookupTableAccounts,
|
|
5032
5635
|
estimation: {
|
|
5033
5636
|
currentBalances: {
|
|
5034
5637
|
tokenX: tokenXAmount,
|
|
@@ -5054,7 +5657,7 @@ var Zap = class {
|
|
|
5054
5657
|
* @param params.ammProgram - AMM program ID to interact with
|
|
5055
5658
|
* @param params.preInstructions - Instructions to run before the zap out
|
|
5056
5659
|
* @param params.postInstructions - Instructions to run after the zap out
|
|
5057
|
-
* @returns
|
|
5660
|
+
* @returns The pre-instructions, the zap out instruction and the post-instructions in order, with no lookup tables
|
|
5058
5661
|
*/
|
|
5059
5662
|
zapOut(params) {
|
|
5060
5663
|
return __async(this, null, function* () {
|
|
@@ -5066,10 +5669,18 @@ var Zap = class {
|
|
|
5066
5669
|
preInstructions,
|
|
5067
5670
|
postInstructions
|
|
5068
5671
|
} = params;
|
|
5069
|
-
|
|
5672
|
+
const zapOutInstruction = yield this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
|
|
5070
5673
|
userTokenInAccount,
|
|
5071
5674
|
ammProgram
|
|
5072
|
-
}).remainingAccounts(remainingAccounts).
|
|
5675
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
5676
|
+
return {
|
|
5677
|
+
instructions: [
|
|
5678
|
+
...preInstructions,
|
|
5679
|
+
zapOutInstruction,
|
|
5680
|
+
...postInstructions
|
|
5681
|
+
],
|
|
5682
|
+
addressLookupTableAccounts: []
|
|
5683
|
+
};
|
|
5073
5684
|
});
|
|
5074
5685
|
}
|
|
5075
5686
|
/**
|
|
@@ -5080,12 +5691,12 @@ var Zap = class {
|
|
|
5080
5691
|
* @param params.user - Public key of the user performing the swap
|
|
5081
5692
|
* @param params.inputMint - Token mint being swapped from
|
|
5082
5693
|
* @param params.outputMint - Token mint being swapped to
|
|
5083
|
-
* @param params.jupiterSwapResponse - Jupiter swap instruction response
|
|
5694
|
+
* @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)
|
|
5084
5695
|
* @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
|
|
5085
5696
|
* @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
|
|
5086
5697
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5087
5698
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5088
|
-
* @returns
|
|
5699
|
+
* @returns The ordered instructions and the lookup tables of the Jupiter swap
|
|
5089
5700
|
*/
|
|
5090
5701
|
zapOutThroughJupiter(params) {
|
|
5091
5702
|
return __async(this, null, function* () {
|
|
@@ -5103,7 +5714,7 @@ var Zap = class {
|
|
|
5103
5714
|
const postInstructions = [];
|
|
5104
5715
|
const [
|
|
5105
5716
|
{ ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
|
|
5106
|
-
{
|
|
5717
|
+
{ ix: outputTokenAccountIx }
|
|
5107
5718
|
] = yield Promise.all([
|
|
5108
5719
|
getOrCreateATAInstruction(
|
|
5109
5720
|
this.connection,
|
|
@@ -5147,27 +5758,36 @@ var Zap = class {
|
|
|
5147
5758
|
jupiterSwapResponse.swapInstruction.data,
|
|
5148
5759
|
"base64"
|
|
5149
5760
|
);
|
|
5150
|
-
const offsetAmountIn =
|
|
5761
|
+
const offsetAmountIn = getJupiterInstructionLayout(
|
|
5762
|
+
payloadData
|
|
5763
|
+
).amountInOffset(payloadData.length);
|
|
5151
5764
|
if (inputMint.equals(NATIVE_MINT3) || outputMint.equals(NATIVE_MINT3)) {
|
|
5152
5765
|
const unwrapInstructions = unwrapSOLInstruction(user, user);
|
|
5153
5766
|
if (unwrapInstructions) {
|
|
5154
5767
|
postInstructions.push(unwrapInstructions);
|
|
5155
5768
|
}
|
|
5156
5769
|
}
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5770
|
+
const [{ instructions }, addressLookupTableAccounts] = yield Promise.all([
|
|
5771
|
+
this.zapOut({
|
|
5772
|
+
userTokenInAccount: inputTokenAccount,
|
|
5773
|
+
zapOutParams: {
|
|
5774
|
+
percentage: percentageToZapOut,
|
|
5775
|
+
offsetAmountIn,
|
|
5776
|
+
preUserTokenBalance: new BN5(preUserTokenBalance),
|
|
5777
|
+
maxSwapAmount,
|
|
5778
|
+
payloadData
|
|
5779
|
+
},
|
|
5780
|
+
remainingAccounts,
|
|
5781
|
+
ammProgram: JUP_V6_PROGRAM_ID,
|
|
5782
|
+
preInstructions,
|
|
5783
|
+
postInstructions
|
|
5784
|
+
}),
|
|
5785
|
+
getJupiterAddressLookupTableAccounts(
|
|
5786
|
+
this.connection,
|
|
5787
|
+
jupiterSwapResponse
|
|
5788
|
+
)
|
|
5789
|
+
]);
|
|
5790
|
+
return { instructions, addressLookupTableAccounts };
|
|
5171
5791
|
});
|
|
5172
5792
|
}
|
|
5173
5793
|
/**
|
|
@@ -5183,6 +5803,7 @@ var Zap = class {
|
|
|
5183
5803
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5184
5804
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5185
5805
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5806
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5186
5807
|
*/
|
|
5187
5808
|
zapOutThroughDammV2(params) {
|
|
5188
5809
|
return __async(this, null, function* () {
|
|
@@ -5279,6 +5900,7 @@ var Zap = class {
|
|
|
5279
5900
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5280
5901
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5281
5902
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5903
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5282
5904
|
*/
|
|
5283
5905
|
zapOutThroughDlmm(params) {
|
|
5284
5906
|
return __async(this, null, function* () {
|
|
@@ -5376,12 +5998,20 @@ export {
|
|
|
5376
5998
|
DAMM_V2_PROGRAM_ID,
|
|
5377
5999
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
5378
6000
|
DEFAULT_JUPITER_API_URL,
|
|
6001
|
+
DEFAULT_JUPITER_API_VERSION,
|
|
6002
|
+
DEFAULT_JUPITER_QUOTE_OPTIONS,
|
|
5379
6003
|
DLMM_PROGRAM_ID,
|
|
5380
6004
|
DLMM_SWAP_DISCRIMINATOR,
|
|
5381
6005
|
DlmmDirectSwapQuoteRoute,
|
|
5382
6006
|
DlmmSingleSided,
|
|
5383
6007
|
DlmmSwapType,
|
|
6008
|
+
JUPITER_INSTRUCTION_LAYOUTS,
|
|
5384
6009
|
JUP_V6_PROGRAM_ID,
|
|
6010
|
+
JUP_V6_ROUTE_DISCRIMINATOR,
|
|
6011
|
+
JUP_V6_ROUTE_V2_DISCRIMINATOR,
|
|
6012
|
+
JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR,
|
|
6013
|
+
JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR,
|
|
6014
|
+
JupiterApiVersion,
|
|
5385
6015
|
MEMO_PROGRAM_ID,
|
|
5386
6016
|
SwapExternalType,
|
|
5387
6017
|
ZAP_PROGRAM_ID,
|
|
@@ -5401,13 +6031,17 @@ export {
|
|
|
5401
6031
|
estimateDlmmDirectSwap,
|
|
5402
6032
|
estimateDlmmIndirectSwap,
|
|
5403
6033
|
estimateDlmmRebalanceSwap,
|
|
6034
|
+
fetchAddressLookupTableAccounts,
|
|
5404
6035
|
filterOutCloseSplTokenAccountInstructions,
|
|
6036
|
+
filterOutComputeBudgetInstructions,
|
|
5405
6037
|
getBinArrayBitmapExtension,
|
|
5406
6038
|
getBitFromBinArrayIndexInBitmapExtension,
|
|
5407
6039
|
getDammV2Pool,
|
|
5408
6040
|
getDammV2RemainingAccounts,
|
|
5409
6041
|
getDlmmRemainingAccounts,
|
|
5410
6042
|
getExtraAccountMetasForTransferHook,
|
|
6043
|
+
getJupiterAddressLookupTableAccounts,
|
|
6044
|
+
getJupiterInstructionLayout,
|
|
5411
6045
|
getJupiterQuote,
|
|
5412
6046
|
getJupiterSwapInstruction,
|
|
5413
6047
|
getLbPairState,
|
|
@@ -5415,8 +6049,13 @@ export {
|
|
|
5415
6049
|
getOrCreateATAInstruction,
|
|
5416
6050
|
getTokenAccountBalance,
|
|
5417
6051
|
getTokenProgramFromMint,
|
|
6052
|
+
isJupiterBuildResponse,
|
|
6053
|
+
isJupiterSwapInstructionForUser,
|
|
5418
6054
|
isSingleSidedA,
|
|
5419
6055
|
isSingleSidedB,
|
|
6056
|
+
mergeAddressLookupTableAccounts,
|
|
6057
|
+
resolveJupiterConfig,
|
|
6058
|
+
toAddressLookupTableAccounts,
|
|
5420
6059
|
toProgramStrategyType,
|
|
5421
6060
|
unwrapSOLInstruction,
|
|
5422
6061
|
wrapSOLInstruction
|