@meteora-ag/zap-sdk 1.3.2 → 2.0.0-rc.1
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 +1436 -1040
- package/dist/index.d.ts +1436 -1040
- package/dist/index.js +1387 -811
- package/dist/index.mjs +1351 -777
- 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
|
+
],
|
|
1278
|
+
type: {
|
|
1279
|
+
array: [
|
|
1280
|
+
"u8",
|
|
1281
|
+
7
|
|
1282
|
+
]
|
|
1283
|
+
}
|
|
1284
|
+
},
|
|
1285
|
+
{
|
|
1286
|
+
name: "padding_5",
|
|
1287
|
+
docs: [
|
|
1288
|
+
"Padding for further use"
|
|
1289
|
+
],
|
|
1065
1290
|
type: {
|
|
1066
|
-
array: [
|
|
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,71 +1709,97 @@ 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: [
|
|
1510
|
-
|
|
1799
|
+
docs: [
|
|
1800
|
+
"The last time reward states were updated."
|
|
1801
|
+
],
|
|
1802
|
+
type: "u64"
|
|
1511
1803
|
},
|
|
1512
1804
|
{
|
|
1513
1805
|
name: "cumulative_seconds_with_empty_liquidity_reward",
|
|
@@ -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,9 +1910,10 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
|
|
|
1651
1910
|
|
|
1652
1911
|
// src/helpers/jupiter.ts
|
|
1653
1912
|
import {
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1913
|
+
AddressLookupTableAccount,
|
|
1914
|
+
AddressLookupTableProgram,
|
|
1915
|
+
PublicKey as PublicKey3,
|
|
1916
|
+
TransactionInstruction as TransactionInstruction2
|
|
1657
1917
|
} from "@solana/web3.js";
|
|
1658
1918
|
|
|
1659
1919
|
// src/constants.ts
|
|
@@ -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,224 @@ 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
|
+
|
|
2037
|
+
// src/helpers/token.ts
|
|
2038
|
+
import {
|
|
2039
|
+
ASSOCIATED_TOKEN_PROGRAM_ID,
|
|
2040
|
+
createAssociatedTokenAccountIdempotentInstruction,
|
|
2041
|
+
createCloseAccountInstruction,
|
|
2042
|
+
getAssociatedTokenAddressSync,
|
|
2043
|
+
NATIVE_MINT,
|
|
2044
|
+
TOKEN_PROGRAM_ID
|
|
2045
|
+
} from "@solana/spl-token";
|
|
2046
|
+
import {
|
|
2047
|
+
SystemProgram,
|
|
2048
|
+
TransactionInstruction
|
|
2049
|
+
} from "@solana/web3.js";
|
|
2050
|
+
var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2051
|
+
const toAccount = getAssociatedTokenAddressSync(
|
|
2052
|
+
tokenMint,
|
|
2053
|
+
owner,
|
|
2054
|
+
allowOwnerOffCurve,
|
|
2055
|
+
tokenProgram
|
|
2056
|
+
);
|
|
2057
|
+
const ix = createAssociatedTokenAccountIdempotentInstruction(
|
|
2058
|
+
payer,
|
|
2059
|
+
toAccount,
|
|
2060
|
+
owner,
|
|
2061
|
+
tokenMint,
|
|
2062
|
+
tokenProgram
|
|
2063
|
+
);
|
|
2064
|
+
return { ataPubkey: toAccount, ix };
|
|
2065
|
+
});
|
|
2066
|
+
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2067
|
+
const wSolATAAccount = getAssociatedTokenAddressSync(
|
|
2068
|
+
NATIVE_MINT,
|
|
2069
|
+
owner,
|
|
2070
|
+
allowOwnerOffCurve
|
|
2071
|
+
);
|
|
2072
|
+
if (wSolATAAccount) {
|
|
2073
|
+
const closedWrappedSolInstruction = createCloseAccountInstruction(
|
|
2074
|
+
wSolATAAccount,
|
|
2075
|
+
receiver,
|
|
2076
|
+
owner,
|
|
2077
|
+
[],
|
|
2078
|
+
TOKEN_PROGRAM_ID
|
|
2079
|
+
);
|
|
2080
|
+
return closedWrappedSolInstruction;
|
|
2081
|
+
}
|
|
2082
|
+
return null;
|
|
2083
|
+
}
|
|
2084
|
+
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2085
|
+
return __async(this, null, function* () {
|
|
2086
|
+
let balance;
|
|
2087
|
+
try {
|
|
2088
|
+
balance = (yield connection.getTokenAccountBalance(tokenAccount)).value.amount;
|
|
2089
|
+
} catch (e) {
|
|
2090
|
+
balance = "0";
|
|
2091
|
+
}
|
|
2092
|
+
return balance;
|
|
2093
|
+
});
|
|
2094
|
+
}
|
|
2095
|
+
function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID) {
|
|
2096
|
+
return [
|
|
2097
|
+
SystemProgram.transfer({
|
|
2098
|
+
fromPubkey: from,
|
|
2099
|
+
toPubkey: to,
|
|
2100
|
+
lamports: amount
|
|
2101
|
+
}),
|
|
2102
|
+
new TransactionInstruction({
|
|
2103
|
+
keys: [
|
|
2104
|
+
{
|
|
2105
|
+
pubkey: to,
|
|
2106
|
+
isSigner: false,
|
|
2107
|
+
isWritable: true
|
|
2108
|
+
}
|
|
2109
|
+
],
|
|
2110
|
+
data: Buffer.from(new Uint8Array([17])),
|
|
2111
|
+
programId: tokenProgram
|
|
2112
|
+
})
|
|
2113
|
+
];
|
|
2114
|
+
}
|
|
2115
|
+
var CLOSE_ACCOUNT_DISCRIMINATOR = 9;
|
|
2116
|
+
function filterOutCloseSplTokenAccountInstructions(instructions) {
|
|
2117
|
+
return instructions.filter((ix) => {
|
|
2118
|
+
if (ix.programId.equals(TOKEN_PROGRAM_ID)) {
|
|
2119
|
+
return ix.data[0] !== CLOSE_ACCOUNT_DISCRIMINATOR;
|
|
2120
|
+
}
|
|
2121
|
+
return true;
|
|
2122
|
+
});
|
|
2123
|
+
}
|
|
2124
|
+
function getCreateAtaInstructions(user, tokens) {
|
|
2125
|
+
const tokenAccounts = tokens.map(
|
|
2126
|
+
({ mint, tokenProgram }) => getAssociatedTokenAddressSync(mint, user, true, tokenProgram)
|
|
2127
|
+
);
|
|
2128
|
+
const instructions = tokens.map(
|
|
2129
|
+
({ mint, tokenProgram }, i) => createAssociatedTokenAccountIdempotentInstruction(
|
|
2130
|
+
user,
|
|
2131
|
+
tokenAccounts[i],
|
|
2132
|
+
user,
|
|
2133
|
+
mint,
|
|
2134
|
+
tokenProgram
|
|
2135
|
+
)
|
|
2136
|
+
);
|
|
2137
|
+
return { tokenAccounts, instructions };
|
|
2138
|
+
}
|
|
2139
|
+
function isCreateAtaInstruction(ix) {
|
|
2140
|
+
return ix.programId.equals(ASSOCIATED_TOKEN_PROGRAM_ID) && (ix.data.length === 0 || ix.data[0] === 0 || ix.data[0] === 1);
|
|
2141
|
+
}
|
|
2142
|
+
function dedupeCreateAtaInstructions(instructions) {
|
|
2143
|
+
const createdAccounts = /* @__PURE__ */ new Set();
|
|
2144
|
+
return instructions.filter((ix) => {
|
|
2145
|
+
if (!isCreateAtaInstruction(ix)) {
|
|
2146
|
+
return true;
|
|
2147
|
+
}
|
|
2148
|
+
const account = ix.keys[1].pubkey.toBase58();
|
|
2149
|
+
if (createdAccounts.has(account)) {
|
|
2150
|
+
return false;
|
|
2151
|
+
}
|
|
2152
|
+
createdAccounts.add(account);
|
|
2153
|
+
return true;
|
|
2154
|
+
});
|
|
2155
|
+
}
|
|
1713
2156
|
|
|
1714
2157
|
// src/helpers/jupiter.ts
|
|
1715
|
-
function
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
2158
|
+
function resolveJupiterConfig(config) {
|
|
2159
|
+
var _a;
|
|
2160
|
+
return {
|
|
2161
|
+
url: (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL,
|
|
2162
|
+
apiKey: (config == null ? void 0 : config.jupiterApiKey) || "",
|
|
2163
|
+
version: (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
function getJupiterInstructionLayout(data) {
|
|
2167
|
+
const discriminator = data.subarray(0, 8).toString("hex");
|
|
2168
|
+
const layout = JUPITER_INSTRUCTION_LAYOUTS[discriminator];
|
|
2169
|
+
if (!layout) {
|
|
2170
|
+
throw new Error(
|
|
2171
|
+
`Unsupported Jupiter instruction discriminator ${discriminator}`
|
|
2172
|
+
);
|
|
2173
|
+
}
|
|
2174
|
+
return layout;
|
|
2175
|
+
}
|
|
2176
|
+
function isJupiterBuildResponse(quoteResponse) {
|
|
2177
|
+
return quoteResponse.swapInstruction !== void 0;
|
|
2178
|
+
}
|
|
2179
|
+
function isJupiterSwapInstructionForUser(swapInstruction, user) {
|
|
2180
|
+
const layout = getJupiterInstructionLayout(
|
|
2181
|
+
Buffer.from(swapInstruction.data, "base64")
|
|
2182
|
+
);
|
|
2183
|
+
const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
|
|
2184
|
+
return authority !== void 0 && new PublicKey3(authority.pubkey).equals(user);
|
|
2185
|
+
}
|
|
2186
|
+
function jupiterHeaders(apiKey, json) {
|
|
2187
|
+
return __spreadValues(__spreadValues({
|
|
2188
|
+
Accept: "application/json"
|
|
2189
|
+
}, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
|
|
2190
|
+
}
|
|
2191
|
+
function toSearchParams(params) {
|
|
2192
|
+
var _a;
|
|
2193
|
+
const searchParams = new URLSearchParams();
|
|
2194
|
+
for (const [name, value] of Object.entries((_a = params.queryParams) != null ? _a : {})) {
|
|
2195
|
+
searchParams.set(name, value.toString());
|
|
2196
|
+
}
|
|
2197
|
+
searchParams.set("inputMint", params.inputMint.toString());
|
|
2198
|
+
searchParams.set("outputMint", params.outputMint.toString());
|
|
2199
|
+
searchParams.set("amount", params.amount.toString());
|
|
2200
|
+
return searchParams;
|
|
2201
|
+
}
|
|
2202
|
+
function fetchJupiterQuoteV1(params, config) {
|
|
2203
|
+
return __async(this, null, function* () {
|
|
2204
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2205
|
+
const url = `${baseUrl}/swap/v1/quote?${toSearchParams(params).toString()}`;
|
|
2206
|
+
try {
|
|
2207
|
+
const response = yield fetch(url, {
|
|
2208
|
+
method: "GET",
|
|
2209
|
+
headers: jupiterHeaders(apiKey, false)
|
|
2210
|
+
});
|
|
2211
|
+
if (!response.ok) {
|
|
2212
|
+
return null;
|
|
2213
|
+
}
|
|
2214
|
+
return yield response.json();
|
|
2215
|
+
} catch (error) {
|
|
2216
|
+
return null;
|
|
2217
|
+
}
|
|
2218
|
+
});
|
|
2219
|
+
}
|
|
2220
|
+
function fetchJupiterBuildV2(params, config) {
|
|
2221
|
+
return __async(this, null, function* () {
|
|
2222
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2223
|
+
const searchParams = toSearchParams(params);
|
|
2224
|
+
searchParams.set("taker", params.user.toString());
|
|
2225
|
+
const url = `${baseUrl}/swap/v2/build?${searchParams.toString()}`;
|
|
1729
2226
|
try {
|
|
1730
2227
|
const response = yield fetch(url, {
|
|
1731
2228
|
method: "GET",
|
|
1732
|
-
headers:
|
|
1733
|
-
Accept: "application/json"
|
|
1734
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
|
|
2229
|
+
headers: jupiterHeaders(apiKey, false)
|
|
1735
2230
|
});
|
|
1736
2231
|
if (!response.ok) {
|
|
1737
2232
|
return null;
|
|
1738
2233
|
}
|
|
1739
|
-
|
|
1740
|
-
return result;
|
|
2234
|
+
return yield response.json();
|
|
1741
2235
|
} catch (error) {
|
|
1742
2236
|
return null;
|
|
1743
2237
|
}
|
|
1744
2238
|
});
|
|
1745
2239
|
}
|
|
1746
|
-
function
|
|
1747
|
-
return __async(this,
|
|
1748
|
-
const
|
|
2240
|
+
function getJupiterQuote(params, config) {
|
|
2241
|
+
return __async(this, null, function* () {
|
|
2242
|
+
const { version } = resolveJupiterConfig(config);
|
|
2243
|
+
if (version === "v1" /* V1 */) {
|
|
2244
|
+
return fetchJupiterQuoteV1(params, config);
|
|
2245
|
+
}
|
|
2246
|
+
return fetchJupiterBuildV2(params, config);
|
|
2247
|
+
});
|
|
2248
|
+
}
|
|
2249
|
+
function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
|
|
2250
|
+
return __async(this, null, function* () {
|
|
2251
|
+
const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
|
|
2252
|
+
const url = `${baseUrl}/swap/v1/swap-instructions`;
|
|
1749
2253
|
const requestBody = {
|
|
1750
2254
|
userPublicKey: userPublicKey.toString(),
|
|
1751
2255
|
quoteResponse
|
|
@@ -1754,10 +2258,7 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1754
2258
|
try {
|
|
1755
2259
|
response = yield fetch(url, {
|
|
1756
2260
|
method: "POST",
|
|
1757
|
-
headers:
|
|
1758
|
-
"Content-Type": "application/json",
|
|
1759
|
-
Accept: "application/json"
|
|
1760
|
-
}, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
|
|
2261
|
+
headers: jupiterHeaders(apiKey, true),
|
|
1761
2262
|
body: JSON.stringify(requestBody)
|
|
1762
2263
|
});
|
|
1763
2264
|
if (!response.ok) {
|
|
@@ -1769,22 +2270,124 @@ function getJupiterSwapInstruction(_0, _1) {
|
|
|
1769
2270
|
} catch (error) {
|
|
1770
2271
|
throw new Error(`Jupiter swap instruction failed to fetch`);
|
|
1771
2272
|
}
|
|
1772
|
-
|
|
1773
|
-
|
|
2273
|
+
return yield response.json();
|
|
2274
|
+
});
|
|
2275
|
+
}
|
|
2276
|
+
function getJupiterSwapInstruction(userPublicKey, quoteResponse, config) {
|
|
2277
|
+
return __async(this, null, function* () {
|
|
2278
|
+
const { version } = resolveJupiterConfig(config);
|
|
2279
|
+
if (version === "v1" /* V1 */) {
|
|
2280
|
+
return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
|
|
2281
|
+
}
|
|
2282
|
+
if (!isJupiterBuildResponse(quoteResponse)) {
|
|
2283
|
+
throw new Error(
|
|
2284
|
+
"Jupiter quote has no swap instructions, get the quote with getJupiterQuote under Jupiter API v2"
|
|
2285
|
+
);
|
|
2286
|
+
}
|
|
2287
|
+
if (!isJupiterSwapInstructionForUser(
|
|
2288
|
+
quoteResponse.swapInstruction,
|
|
2289
|
+
userPublicKey
|
|
2290
|
+
)) {
|
|
2291
|
+
throw new Error(
|
|
2292
|
+
`Jupiter quote swap instructions are not built for ${userPublicKey.toBase58()}`
|
|
2293
|
+
);
|
|
2294
|
+
}
|
|
2295
|
+
return quoteResponse;
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2298
|
+
function isQuoteMatchesSwap(quoteResponse, user, amount) {
|
|
2299
|
+
if (quoteResponse.inAmount !== amount.toString()) {
|
|
2300
|
+
return false;
|
|
2301
|
+
}
|
|
2302
|
+
if (isJupiterBuildResponse(quoteResponse)) {
|
|
2303
|
+
return isJupiterSwapInstructionForUser(quoteResponse.swapInstruction, user);
|
|
2304
|
+
}
|
|
2305
|
+
return true;
|
|
2306
|
+
}
|
|
2307
|
+
var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
|
|
2308
|
+
function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
|
|
2309
|
+
return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
|
|
2310
|
+
([key, addresses]) => new AddressLookupTableAccount({
|
|
2311
|
+
key: new PublicKey3(key),
|
|
2312
|
+
state: {
|
|
2313
|
+
addresses: addresses.map((address) => new PublicKey3(address)),
|
|
2314
|
+
deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
|
|
2315
|
+
lastExtendedSlot: 0,
|
|
2316
|
+
lastExtendedSlotStartIndex: 0
|
|
2317
|
+
}
|
|
2318
|
+
})
|
|
2319
|
+
);
|
|
2320
|
+
}
|
|
2321
|
+
function fetchAddressLookupTableAccounts(connection, addresses) {
|
|
2322
|
+
return __async(this, null, function* () {
|
|
2323
|
+
if (addresses.length === 0) {
|
|
2324
|
+
return [];
|
|
2325
|
+
}
|
|
2326
|
+
const keys = addresses.map((address) => new PublicKey3(address));
|
|
2327
|
+
const accounts = yield connection.getMultipleAccountsInfo(keys);
|
|
2328
|
+
return keys.map((key, i) => {
|
|
2329
|
+
const account = accounts[i];
|
|
2330
|
+
if (!account || !account.owner.equals(AddressLookupTableProgram.programId)) {
|
|
2331
|
+
throw new Error(`Address lookup table not found: ${key.toBase58()}`);
|
|
2332
|
+
}
|
|
2333
|
+
return new AddressLookupTableAccount({
|
|
2334
|
+
key,
|
|
2335
|
+
state: AddressLookupTableAccount.deserialize(account.data)
|
|
2336
|
+
});
|
|
2337
|
+
});
|
|
2338
|
+
});
|
|
2339
|
+
}
|
|
2340
|
+
function mergeAddressLookupTableAccounts(...lists) {
|
|
2341
|
+
const merged = /* @__PURE__ */ new Map();
|
|
2342
|
+
for (const table of lists.flat()) {
|
|
2343
|
+
const key = table.key.toBase58();
|
|
2344
|
+
if (!merged.has(key)) {
|
|
2345
|
+
merged.set(key, table);
|
|
2346
|
+
}
|
|
2347
|
+
}
|
|
2348
|
+
return [...merged.values()];
|
|
2349
|
+
}
|
|
2350
|
+
function getJupiterAddressLookupTableAccounts(connection, response) {
|
|
2351
|
+
return __async(this, null, function* () {
|
|
2352
|
+
var _a;
|
|
2353
|
+
if (response.addressesByLookupTableAddress) {
|
|
2354
|
+
return toAddressLookupTableAccounts(response.addressesByLookupTableAddress);
|
|
2355
|
+
}
|
|
2356
|
+
return fetchAddressLookupTableAccounts(
|
|
2357
|
+
connection,
|
|
2358
|
+
(_a = response.addressLookupTableAddresses) != null ? _a : []
|
|
2359
|
+
);
|
|
1774
2360
|
});
|
|
1775
2361
|
}
|
|
1776
|
-
function
|
|
1777
|
-
return
|
|
2362
|
+
function toTransactionInstruction(instruction) {
|
|
2363
|
+
return new TransactionInstruction2({
|
|
2364
|
+
keys: instruction.accounts.map((item) => ({
|
|
2365
|
+
pubkey: new PublicKey3(item.pubkey),
|
|
2366
|
+
isSigner: item.isSigner,
|
|
2367
|
+
isWritable: item.isWritable
|
|
2368
|
+
})),
|
|
2369
|
+
programId: new PublicKey3(instruction.programId),
|
|
2370
|
+
data: Buffer.from(instruction.data, "base64")
|
|
2371
|
+
});
|
|
2372
|
+
}
|
|
2373
|
+
function getJupiterCreateAtaInstructions(setupInstructions) {
|
|
2374
|
+
return setupInstructions.filter(isCreateAtaInstruction);
|
|
2375
|
+
}
|
|
2376
|
+
function buildJupiterSwapTransaction(connection, user, inputMint, outputMint, amount, slippageBps, jupiterQuoteResponse, config, jupiterQuoteOptions) {
|
|
2377
|
+
return __async(this, null, function* () {
|
|
2378
|
+
if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
|
|
2379
|
+
throw new Error(
|
|
2380
|
+
`Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
|
|
2381
|
+
);
|
|
2382
|
+
}
|
|
1778
2383
|
const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
true,
|
|
1787
|
-
true,
|
|
2384
|
+
{
|
|
2385
|
+
inputMint,
|
|
2386
|
+
outputMint,
|
|
2387
|
+
amount,
|
|
2388
|
+
user,
|
|
2389
|
+
queryParams: __spreadValues({ slippageBps }, jupiterQuoteOptions)
|
|
2390
|
+
},
|
|
1788
2391
|
config
|
|
1789
2392
|
);
|
|
1790
2393
|
if (!quoteResponse) {
|
|
@@ -1797,23 +2400,27 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
1797
2400
|
quoteResponse,
|
|
1798
2401
|
config
|
|
1799
2402
|
);
|
|
1800
|
-
const instruction =
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
-
|
|
1807
|
-
|
|
1808
|
-
|
|
1809
|
-
|
|
1810
|
-
|
|
1811
|
-
|
|
2403
|
+
const instruction = toTransactionInstruction(
|
|
2404
|
+
swapInstructionResponse.swapInstruction
|
|
2405
|
+
);
|
|
2406
|
+
const setupInstructions = swapInstructionResponse.setupInstructions.map(
|
|
2407
|
+
toTransactionInstruction
|
|
2408
|
+
);
|
|
2409
|
+
const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
|
|
2410
|
+
connection,
|
|
2411
|
+
swapInstructionResponse
|
|
2412
|
+
);
|
|
2413
|
+
return {
|
|
2414
|
+
instruction,
|
|
2415
|
+
setupInstructions,
|
|
2416
|
+
addressLookupTableAccounts,
|
|
2417
|
+
quoteResponse
|
|
2418
|
+
};
|
|
1812
2419
|
});
|
|
1813
2420
|
}
|
|
1814
2421
|
|
|
1815
2422
|
// src/helpers/dammV2.ts
|
|
1816
|
-
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
|
|
2423
|
+
import { TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
|
|
1817
2424
|
import {
|
|
1818
2425
|
CollectFeeMode,
|
|
1819
2426
|
CpAmm,
|
|
@@ -1821,27 +2428,27 @@ import {
|
|
|
1821
2428
|
} from "@meteora-ag/cp-amm-sdk";
|
|
1822
2429
|
|
|
1823
2430
|
// src/helpers/pda.ts
|
|
1824
|
-
import { PublicKey as
|
|
2431
|
+
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
1825
2432
|
function deriveDammV2EventAuthority() {
|
|
1826
|
-
return
|
|
2433
|
+
return PublicKey4.findProgramAddressSync(
|
|
1827
2434
|
[Buffer.from("__event_authority")],
|
|
1828
2435
|
DAMM_V2_PROGRAM_ID
|
|
1829
2436
|
)[0];
|
|
1830
2437
|
}
|
|
1831
2438
|
function deriveDammV2PoolAuthority() {
|
|
1832
|
-
return
|
|
2439
|
+
return PublicKey4.findProgramAddressSync(
|
|
1833
2440
|
[Buffer.from("pool_authority")],
|
|
1834
2441
|
DAMM_V2_PROGRAM_ID
|
|
1835
2442
|
)[0];
|
|
1836
2443
|
}
|
|
1837
2444
|
function deriveLedgerAccount(owner) {
|
|
1838
|
-
return
|
|
2445
|
+
return PublicKey4.findProgramAddressSync(
|
|
1839
2446
|
[Buffer.from("user_ledger"), owner.toBuffer()],
|
|
1840
2447
|
ZAP_PROGRAM_ID
|
|
1841
2448
|
)[0];
|
|
1842
2449
|
}
|
|
1843
2450
|
function deriveDlmmEventAuthority() {
|
|
1844
|
-
return
|
|
2451
|
+
return PublicKey4.findProgramAddressSync(
|
|
1845
2452
|
[Buffer.from("__event_authority")],
|
|
1846
2453
|
DLMM_PROGRAM_ID
|
|
1847
2454
|
)[0];
|
|
@@ -1855,7 +2462,7 @@ function getDammV2Pool(connection, poolAddress) {
|
|
|
1855
2462
|
});
|
|
1856
2463
|
}
|
|
1857
2464
|
function getDammV2RemainingAccounts(_0, _1, _2, _3) {
|
|
1858
|
-
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram =
|
|
2465
|
+
return __async(this, arguments, function* (poolAddress, user, userInputTokenAccount, userTokenOutAccount, tokenAProgram = TOKEN_PROGRAM_ID2, tokenBProgram = TOKEN_PROGRAM_ID2, poolState) {
|
|
1859
2466
|
const remainingAccounts = [
|
|
1860
2467
|
{
|
|
1861
2468
|
isSigner: false,
|
|
@@ -1946,130 +2553,48 @@ function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
|
|
|
1946
2553
|
}
|
|
1947
2554
|
|
|
1948
2555
|
// src/helpers/common.ts
|
|
2556
|
+
import { NATIVE_MINT as NATIVE_MINT2, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3 } from "@solana/spl-token";
|
|
1949
2557
|
import {
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
} from "@solana/
|
|
1953
|
-
import { PublicKey as PublicKey4 } from "@solana/web3.js";
|
|
2558
|
+
ComputeBudgetProgram,
|
|
2559
|
+
PublicKey as PublicKey5
|
|
2560
|
+
} from "@solana/web3.js";
|
|
1954
2561
|
import Decimal from "decimal.js";
|
|
1955
2562
|
function getTokenProgramFromMint(connection, mint) {
|
|
1956
2563
|
return __async(this, null, function* () {
|
|
1957
|
-
if (mint.equals(
|
|
1958
|
-
return
|
|
1959
|
-
}
|
|
1960
|
-
try {
|
|
1961
|
-
const mintInfo = yield connection.getAccountInfo(mint);
|
|
1962
|
-
if (!mintInfo) {
|
|
1963
|
-
throw new Error(`Mint account not found: ${mint.toString()}`);
|
|
1964
|
-
}
|
|
1965
|
-
if (mintInfo.owner.equals(
|
|
1966
|
-
new PublicKey4("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
1967
|
-
)) {
|
|
1968
|
-
return new PublicKey4("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
1969
|
-
} else {
|
|
1970
|
-
return TOKEN_PROGRAM_ID2;
|
|
1971
|
-
}
|
|
1972
|
-
} catch (error) {
|
|
1973
|
-
console.warn(
|
|
1974
|
-
`Failed to determine token program for ${mint.toString()}, defaulting to TOKEN_PROGRAM_ID:`,
|
|
1975
|
-
error
|
|
1976
|
-
);
|
|
1977
|
-
return TOKEN_PROGRAM_ID2;
|
|
1978
|
-
}
|
|
1979
|
-
});
|
|
1980
|
-
}
|
|
1981
|
-
function convertLamportsToUiAmount(amount, decimals) {
|
|
1982
|
-
return amount.div(Decimal.pow(10, decimals));
|
|
1983
|
-
}
|
|
1984
|
-
function convertUiAmountToLamports(amount, decimals) {
|
|
1985
|
-
return amount.mul(Decimal.pow(10, decimals));
|
|
1986
|
-
}
|
|
1987
|
-
|
|
1988
|
-
// src/helpers/token.ts
|
|
1989
|
-
import {
|
|
1990
|
-
createAssociatedTokenAccountIdempotentInstruction,
|
|
1991
|
-
createCloseAccountInstruction,
|
|
1992
|
-
getAssociatedTokenAddressSync,
|
|
1993
|
-
NATIVE_MINT as NATIVE_MINT2,
|
|
1994
|
-
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID3
|
|
1995
|
-
} from "@solana/spl-token";
|
|
1996
|
-
import {
|
|
1997
|
-
SystemProgram,
|
|
1998
|
-
TransactionInstruction as TransactionInstruction2
|
|
1999
|
-
} from "@solana/web3.js";
|
|
2000
|
-
var getOrCreateATAInstruction = (connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
|
|
2001
|
-
const toAccount = getAssociatedTokenAddressSync(
|
|
2002
|
-
tokenMint,
|
|
2003
|
-
owner,
|
|
2004
|
-
allowOwnerOffCurve,
|
|
2005
|
-
tokenProgram
|
|
2006
|
-
);
|
|
2007
|
-
const ix = createAssociatedTokenAccountIdempotentInstruction(
|
|
2008
|
-
payer,
|
|
2009
|
-
toAccount,
|
|
2010
|
-
owner,
|
|
2011
|
-
tokenMint,
|
|
2012
|
-
tokenProgram
|
|
2013
|
-
);
|
|
2014
|
-
return { ataPubkey: toAccount, ix };
|
|
2015
|
-
});
|
|
2016
|
-
function unwrapSOLInstruction(owner, receiver, allowOwnerOffCurve = true) {
|
|
2017
|
-
const wSolATAAccount = getAssociatedTokenAddressSync(
|
|
2018
|
-
NATIVE_MINT2,
|
|
2019
|
-
owner,
|
|
2020
|
-
allowOwnerOffCurve
|
|
2021
|
-
);
|
|
2022
|
-
if (wSolATAAccount) {
|
|
2023
|
-
const closedWrappedSolInstruction = createCloseAccountInstruction(
|
|
2024
|
-
wSolATAAccount,
|
|
2025
|
-
receiver,
|
|
2026
|
-
owner,
|
|
2027
|
-
[],
|
|
2028
|
-
TOKEN_PROGRAM_ID3
|
|
2029
|
-
);
|
|
2030
|
-
return closedWrappedSolInstruction;
|
|
2031
|
-
}
|
|
2032
|
-
return null;
|
|
2033
|
-
}
|
|
2034
|
-
function getTokenAccountBalance(connection, tokenAccount) {
|
|
2035
|
-
return __async(this, null, function* () {
|
|
2036
|
-
let balance;
|
|
2564
|
+
if (mint.equals(NATIVE_MINT2)) {
|
|
2565
|
+
return TOKEN_PROGRAM_ID3;
|
|
2566
|
+
}
|
|
2037
2567
|
try {
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2568
|
+
const mintInfo = yield connection.getAccountInfo(mint);
|
|
2569
|
+
if (!mintInfo) {
|
|
2570
|
+
throw new Error(`Mint account not found: ${mint.toString()}`);
|
|
2571
|
+
}
|
|
2572
|
+
if (mintInfo.owner.equals(
|
|
2573
|
+
new PublicKey5("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb")
|
|
2574
|
+
)) {
|
|
2575
|
+
return new PublicKey5("TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb");
|
|
2576
|
+
} else {
|
|
2577
|
+
return TOKEN_PROGRAM_ID3;
|
|
2578
|
+
}
|
|
2579
|
+
} catch (error) {
|
|
2580
|
+
console.warn(
|
|
2581
|
+
`Failed to determine token program for ${mint.toString()}, defaulting to TOKEN_PROGRAM_ID:`,
|
|
2582
|
+
error
|
|
2583
|
+
);
|
|
2584
|
+
return TOKEN_PROGRAM_ID3;
|
|
2041
2585
|
}
|
|
2042
|
-
return balance;
|
|
2043
2586
|
});
|
|
2044
2587
|
}
|
|
2045
|
-
function
|
|
2046
|
-
return
|
|
2047
|
-
SystemProgram.transfer({
|
|
2048
|
-
fromPubkey: from,
|
|
2049
|
-
toPubkey: to,
|
|
2050
|
-
lamports: amount
|
|
2051
|
-
}),
|
|
2052
|
-
new TransactionInstruction2({
|
|
2053
|
-
keys: [
|
|
2054
|
-
{
|
|
2055
|
-
pubkey: to,
|
|
2056
|
-
isSigner: false,
|
|
2057
|
-
isWritable: true
|
|
2058
|
-
}
|
|
2059
|
-
],
|
|
2060
|
-
data: Buffer.from(new Uint8Array([17])),
|
|
2061
|
-
programId: tokenProgram
|
|
2062
|
-
})
|
|
2063
|
-
];
|
|
2588
|
+
function convertLamportsToUiAmount(amount, decimals) {
|
|
2589
|
+
return amount.div(Decimal.pow(10, decimals));
|
|
2064
2590
|
}
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
|
|
2072
|
-
});
|
|
2591
|
+
function convertUiAmountToLamports(amount, decimals) {
|
|
2592
|
+
return amount.mul(Decimal.pow(10, decimals));
|
|
2593
|
+
}
|
|
2594
|
+
function filterOutComputeBudgetInstructions(instructions) {
|
|
2595
|
+
return instructions.filter(
|
|
2596
|
+
(ix) => !ix.programId.equals(ComputeBudgetProgram.programId)
|
|
2597
|
+
);
|
|
2073
2598
|
}
|
|
2074
2599
|
|
|
2075
2600
|
// src/helpers/dlmm.ts
|
|
@@ -2089,7 +2614,7 @@ import DLMM, {
|
|
|
2089
2614
|
import {
|
|
2090
2615
|
createTransferCheckedWithTransferHookInstruction,
|
|
2091
2616
|
getTransferHook,
|
|
2092
|
-
TOKEN_2022_PROGRAM_ID
|
|
2617
|
+
TOKEN_2022_PROGRAM_ID,
|
|
2093
2618
|
TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4,
|
|
2094
2619
|
unpackMint
|
|
2095
2620
|
} from "@solana/spl-token";
|
|
@@ -2109,7 +2634,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
|
|
|
2109
2634
|
const mintInfo = unpackMint(
|
|
2110
2635
|
mint,
|
|
2111
2636
|
accountInfoWithBuffer,
|
|
2112
|
-
|
|
2637
|
+
TOKEN_2022_PROGRAM_ID
|
|
2113
2638
|
);
|
|
2114
2639
|
const transferHook = getTransferHook(mintInfo);
|
|
2115
2640
|
if (!transferHook) {
|
|
@@ -2125,7 +2650,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
|
|
|
2125
2650
|
mintInfo.decimals,
|
|
2126
2651
|
[],
|
|
2127
2652
|
"confirmed",
|
|
2128
|
-
|
|
2653
|
+
TOKEN_2022_PROGRAM_ID
|
|
2129
2654
|
);
|
|
2130
2655
|
return (yield transferWithHookIx).keys.slice(4);
|
|
2131
2656
|
}
|
|
@@ -2449,8 +2974,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
|
|
|
2449
2974
|
const estimatedOutput = inAmountDecimal.mul(effectiveRate);
|
|
2450
2975
|
return new BN3(estimatedOutput.floor().toString());
|
|
2451
2976
|
}
|
|
2452
|
-
function getBestSwapQuoteJupiterDlmm(
|
|
2453
|
-
return __async(this,
|
|
2977
|
+
function getBestSwapQuoteJupiterDlmm(dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config, jupiterQuoteOptions) {
|
|
2978
|
+
return __async(this, null, function* () {
|
|
2454
2979
|
let dlmmQuoteResult = null;
|
|
2455
2980
|
try {
|
|
2456
2981
|
dlmmQuoteResult = dlmm.swapQuote(
|
|
@@ -2463,15 +2988,15 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
|
|
|
2463
2988
|
console.error("Error getting DLMM quote, using jupiter quote only:", error);
|
|
2464
2989
|
}
|
|
2465
2990
|
const jupiterQuoteResult = yield getJupiterQuote(
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2474
|
-
|
|
2991
|
+
{
|
|
2992
|
+
inputMint: inMint,
|
|
2993
|
+
outputMint: outMint,
|
|
2994
|
+
amount: inAmount,
|
|
2995
|
+
user,
|
|
2996
|
+
queryParams: __spreadValues({
|
|
2997
|
+
slippageBps: swapSlippageBps
|
|
2998
|
+
}, jupiterQuoteOptions)
|
|
2999
|
+
},
|
|
2475
3000
|
config
|
|
2476
3001
|
);
|
|
2477
3002
|
const jupiterQuote = jupiterQuoteResult ? {
|
|
@@ -2587,6 +3112,7 @@ function binarySearchRefineDirectSwapAmount(dlmm, initialActiveBin, initialMinBi
|
|
|
2587
3112
|
}
|
|
2588
3113
|
function estimateDlmmIndirectSwap(_0) {
|
|
2589
3114
|
return __async(this, arguments, function* ({
|
|
3115
|
+
user,
|
|
2590
3116
|
amountIn,
|
|
2591
3117
|
inputTokenMint,
|
|
2592
3118
|
lbPair,
|
|
@@ -2596,7 +3122,8 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2596
3122
|
maxDeltaId,
|
|
2597
3123
|
strategy,
|
|
2598
3124
|
singleSided,
|
|
2599
|
-
|
|
3125
|
+
jupiterQuoteOptions,
|
|
3126
|
+
config
|
|
2600
3127
|
}) {
|
|
2601
3128
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
2602
3129
|
const activeBin = yield dlmm.getActiveBin();
|
|
@@ -2620,15 +3147,15 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2620
3147
|
const singleSidedX = singleSided === 0 /* X */;
|
|
2621
3148
|
const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
|
|
2622
3149
|
const quote = yield getJupiterQuote(
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
3150
|
+
{
|
|
3151
|
+
inputMint: inputTokenMint,
|
|
3152
|
+
outputMint: outputTokenMint,
|
|
3153
|
+
amount: amountIn,
|
|
3154
|
+
user,
|
|
3155
|
+
queryParams: __spreadValues({
|
|
3156
|
+
slippageBps: swapSlippageBps
|
|
3157
|
+
}, jupiterQuoteOptions)
|
|
3158
|
+
},
|
|
2632
3159
|
config
|
|
2633
3160
|
);
|
|
2634
3161
|
if (!quote) {
|
|
@@ -2651,27 +3178,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2651
3178
|
const halfAmount = amountIn.div(new BN3(2));
|
|
2652
3179
|
const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
|
|
2653
3180
|
getJupiterQuote(
|
|
2654
|
-
|
|
2655
|
-
|
|
2656
|
-
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
|
|
2661
|
-
|
|
2662
|
-
|
|
3181
|
+
{
|
|
3182
|
+
inputMint: inputTokenMint,
|
|
3183
|
+
outputMint: tokenXMint,
|
|
3184
|
+
amount: halfAmount,
|
|
3185
|
+
user,
|
|
3186
|
+
queryParams: __spreadValues({
|
|
3187
|
+
slippageBps: swapSlippageBps
|
|
3188
|
+
}, jupiterQuoteOptions)
|
|
3189
|
+
},
|
|
2663
3190
|
config
|
|
2664
3191
|
),
|
|
2665
3192
|
getJupiterQuote(
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
3193
|
+
{
|
|
3194
|
+
inputMint: inputTokenMint,
|
|
3195
|
+
outputMint: tokenYMint,
|
|
3196
|
+
amount: halfAmount,
|
|
3197
|
+
user,
|
|
3198
|
+
queryParams: __spreadValues({
|
|
3199
|
+
slippageBps: swapSlippageBps
|
|
3200
|
+
}, jupiterQuoteOptions)
|
|
3201
|
+
},
|
|
2675
3202
|
config
|
|
2676
3203
|
)
|
|
2677
3204
|
]);
|
|
@@ -2767,27 +3294,27 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2767
3294
|
}
|
|
2768
3295
|
const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
|
|
2769
3296
|
getJupiterQuote(
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
3297
|
+
{
|
|
3298
|
+
inputMint: inputTokenMint,
|
|
3299
|
+
outputMint: tokenXMint,
|
|
3300
|
+
amount: bestAmountToX,
|
|
3301
|
+
user,
|
|
3302
|
+
queryParams: __spreadValues({
|
|
3303
|
+
slippageBps: swapSlippageBps
|
|
3304
|
+
}, jupiterQuoteOptions)
|
|
3305
|
+
},
|
|
2779
3306
|
config
|
|
2780
3307
|
),
|
|
2781
3308
|
getJupiterQuote(
|
|
2782
|
-
|
|
2783
|
-
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
3309
|
+
{
|
|
3310
|
+
inputMint: inputTokenMint,
|
|
3311
|
+
outputMint: tokenYMint,
|
|
3312
|
+
amount: bestAmountToY,
|
|
3313
|
+
user,
|
|
3314
|
+
queryParams: __spreadValues({
|
|
3315
|
+
slippageBps: swapSlippageBps
|
|
3316
|
+
}, jupiterQuoteOptions)
|
|
3317
|
+
},
|
|
2791
3318
|
config
|
|
2792
3319
|
)
|
|
2793
3320
|
]);
|
|
@@ -2823,6 +3350,7 @@ function estimateDlmmIndirectSwap(_0) {
|
|
|
2823
3350
|
}
|
|
2824
3351
|
function estimateDlmmDirectSwapCore(_0) {
|
|
2825
3352
|
return __async(this, arguments, function* ({
|
|
3353
|
+
user,
|
|
2826
3354
|
tokenXAmount,
|
|
2827
3355
|
tokenYAmount,
|
|
2828
3356
|
dlmm,
|
|
@@ -2831,7 +3359,8 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2831
3359
|
maxDeltaId,
|
|
2832
3360
|
strategy,
|
|
2833
3361
|
singleSided,
|
|
2834
|
-
|
|
3362
|
+
jupiterQuoteOptions,
|
|
3363
|
+
config
|
|
2835
3364
|
}) {
|
|
2836
3365
|
if (singleSided !== void 0) {
|
|
2837
3366
|
const singleSidedX = singleSided === 0 /* X */;
|
|
@@ -2843,13 +3372,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2843
3372
|
);
|
|
2844
3373
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2845
3374
|
dlmm,
|
|
3375
|
+
user,
|
|
2846
3376
|
dlmm.lbPair.tokenYMint,
|
|
2847
3377
|
dlmm.lbPair.tokenXMint,
|
|
2848
3378
|
tokenYAmount,
|
|
2849
3379
|
swapSlippageBps,
|
|
2850
3380
|
swapForY2,
|
|
2851
3381
|
binArrayForSwap2,
|
|
2852
|
-
config
|
|
3382
|
+
config,
|
|
3383
|
+
jupiterQuoteOptions
|
|
2853
3384
|
);
|
|
2854
3385
|
if (!quote) {
|
|
2855
3386
|
throw new Error(
|
|
@@ -2872,13 +3403,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2872
3403
|
);
|
|
2873
3404
|
const quote = yield getBestSwapQuoteJupiterDlmm(
|
|
2874
3405
|
dlmm,
|
|
3406
|
+
user,
|
|
2875
3407
|
dlmm.lbPair.tokenXMint,
|
|
2876
3408
|
dlmm.lbPair.tokenYMint,
|
|
2877
3409
|
tokenXAmount,
|
|
2878
3410
|
swapSlippageBps,
|
|
2879
3411
|
swapForY2,
|
|
2880
3412
|
binArrayForSwap2,
|
|
2881
|
-
config
|
|
3413
|
+
config,
|
|
3414
|
+
jupiterQuoteOptions
|
|
2882
3415
|
);
|
|
2883
3416
|
if (!quote) {
|
|
2884
3417
|
throw new Error(
|
|
@@ -2967,13 +3500,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
2967
3500
|
);
|
|
2968
3501
|
const initialQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
2969
3502
|
dlmm,
|
|
3503
|
+
user,
|
|
2970
3504
|
inMint,
|
|
2971
3505
|
outMint,
|
|
2972
3506
|
initialSwapAmount,
|
|
2973
3507
|
swapSlippageBps,
|
|
2974
3508
|
swapForY,
|
|
2975
3509
|
binArrayForSwap,
|
|
2976
|
-
config
|
|
3510
|
+
config,
|
|
3511
|
+
jupiterQuoteOptions
|
|
2977
3512
|
);
|
|
2978
3513
|
if (!initialQuote) {
|
|
2979
3514
|
throw new Error(
|
|
@@ -3025,13 +3560,15 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3025
3560
|
);
|
|
3026
3561
|
const finalQuote = yield getBestSwapQuoteJupiterDlmm(
|
|
3027
3562
|
dlmm,
|
|
3563
|
+
user,
|
|
3028
3564
|
inMint,
|
|
3029
3565
|
outMint,
|
|
3030
3566
|
refinedAmount,
|
|
3031
3567
|
swapSlippageBps,
|
|
3032
3568
|
swapForY,
|
|
3033
3569
|
binArrayForSwap,
|
|
3034
|
-
config
|
|
3570
|
+
config,
|
|
3571
|
+
jupiterQuoteOptions
|
|
3035
3572
|
);
|
|
3036
3573
|
if (!finalQuote) {
|
|
3037
3574
|
return {
|
|
@@ -3057,6 +3594,7 @@ function estimateDlmmDirectSwapCore(_0) {
|
|
|
3057
3594
|
}
|
|
3058
3595
|
function estimateDlmmDirectSwap(_0) {
|
|
3059
3596
|
return __async(this, arguments, function* ({
|
|
3597
|
+
user,
|
|
3060
3598
|
amountIn,
|
|
3061
3599
|
inputTokenMint,
|
|
3062
3600
|
lbPair,
|
|
@@ -3066,7 +3604,8 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3066
3604
|
maxDeltaId,
|
|
3067
3605
|
strategy,
|
|
3068
3606
|
singleSided,
|
|
3069
|
-
|
|
3607
|
+
jupiterQuoteOptions,
|
|
3608
|
+
config
|
|
3070
3609
|
}) {
|
|
3071
3610
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3072
3611
|
invariant(
|
|
@@ -3077,6 +3616,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3077
3616
|
const tokenXAmount = isInputTokenX ? amountIn : new BN3(0);
|
|
3078
3617
|
const tokenYAmount = isInputTokenX ? new BN3(0) : amountIn;
|
|
3079
3618
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3619
|
+
user,
|
|
3080
3620
|
tokenXAmount,
|
|
3081
3621
|
tokenYAmount,
|
|
3082
3622
|
dlmm,
|
|
@@ -3085,6 +3625,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3085
3625
|
maxDeltaId,
|
|
3086
3626
|
strategy,
|
|
3087
3627
|
singleSided,
|
|
3628
|
+
jupiterQuoteOptions,
|
|
3088
3629
|
config
|
|
3089
3630
|
});
|
|
3090
3631
|
return {
|
|
@@ -3104,6 +3645,7 @@ function estimateDlmmDirectSwap(_0) {
|
|
|
3104
3645
|
}
|
|
3105
3646
|
function estimateDlmmRebalanceSwap(_0) {
|
|
3106
3647
|
return __async(this, arguments, function* ({
|
|
3648
|
+
user,
|
|
3107
3649
|
lbPair,
|
|
3108
3650
|
position,
|
|
3109
3651
|
connection,
|
|
@@ -3111,11 +3653,13 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3111
3653
|
minDeltaId,
|
|
3112
3654
|
maxDeltaId,
|
|
3113
3655
|
strategy,
|
|
3114
|
-
|
|
3656
|
+
jupiterQuoteOptions,
|
|
3657
|
+
config
|
|
3115
3658
|
}) {
|
|
3116
3659
|
const dlmm = yield DLMM2.create(connection, lbPair);
|
|
3117
3660
|
const userPosition = yield dlmm.getPosition(position);
|
|
3118
3661
|
const result = yield estimateDlmmDirectSwapCore({
|
|
3662
|
+
user,
|
|
3119
3663
|
tokenXAmount: new BN3(userPosition.positionData.totalXAmount),
|
|
3120
3664
|
tokenYAmount: new BN3(userPosition.positionData.totalYAmount),
|
|
3121
3665
|
dlmm,
|
|
@@ -3125,6 +3669,7 @@ function estimateDlmmRebalanceSwap(_0) {
|
|
|
3125
3669
|
strategy,
|
|
3126
3670
|
singleSided: void 0,
|
|
3127
3671
|
// rebalance does not use single-sided deposits
|
|
3672
|
+
jupiterQuoteOptions,
|
|
3128
3673
|
config
|
|
3129
3674
|
});
|
|
3130
3675
|
return {
|
|
@@ -3213,13 +3758,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
|
|
|
3213
3758
|
var Zap = class {
|
|
3214
3759
|
/**
|
|
3215
3760
|
* @param connection - The connection to the Solana cluster
|
|
3216
|
-
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag)
|
|
3761
|
+
* @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
|
|
3217
3762
|
*/
|
|
3218
|
-
constructor(connection, config
|
|
3763
|
+
constructor(connection, config) {
|
|
3764
|
+
var _a;
|
|
3219
3765
|
this.connection = connection;
|
|
3220
3766
|
this.zapProgram = new Program(idl_default, { connection });
|
|
3221
|
-
this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
|
|
3222
|
-
this.jupiterApiKey = config.jupiterApiKey || "";
|
|
3767
|
+
this.jupiterApiUrl = (config == null ? void 0 : config.jupiterApiUrl) || DEFAULT_JUPITER_API_URL;
|
|
3768
|
+
this.jupiterApiKey = (config == null ? void 0 : config.jupiterApiKey) || "";
|
|
3769
|
+
this.jupiterApiVersion = (_a = config == null ? void 0 : config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
|
|
3223
3770
|
}
|
|
3224
3771
|
/////// PRIVATE FUNDTIONS //////
|
|
3225
3772
|
initializeLedgerAccount(owner, payer) {
|
|
@@ -3228,7 +3775,7 @@ var Zap = class {
|
|
|
3228
3775
|
ledger: deriveLedgerAccount(owner),
|
|
3229
3776
|
owner,
|
|
3230
3777
|
payer
|
|
3231
|
-
}).
|
|
3778
|
+
}).instruction();
|
|
3232
3779
|
});
|
|
3233
3780
|
}
|
|
3234
3781
|
closeLedgerAccount(owner, rentReceiver) {
|
|
@@ -3237,7 +3784,7 @@ var Zap = class {
|
|
|
3237
3784
|
ledger: deriveLedgerAccount(owner),
|
|
3238
3785
|
owner,
|
|
3239
3786
|
rentReceiver
|
|
3240
|
-
}).
|
|
3787
|
+
}).instruction();
|
|
3241
3788
|
});
|
|
3242
3789
|
}
|
|
3243
3790
|
setLedgerBalance(owner, amount, isTokenA) {
|
|
@@ -3245,7 +3792,7 @@ var Zap = class {
|
|
|
3245
3792
|
return yield this.zapProgram.methods.setLedgerBalance(amount, isTokenA).accountsPartial({
|
|
3246
3793
|
ledger: deriveLedgerAccount(owner),
|
|
3247
3794
|
owner
|
|
3248
|
-
}).
|
|
3795
|
+
}).instruction();
|
|
3249
3796
|
});
|
|
3250
3797
|
}
|
|
3251
3798
|
updateLedgerBalanceAfterSwap(owner, tokenAccount, preSourceTokenAccount, maxTransferAmount, isTokenA) {
|
|
@@ -3258,7 +3805,7 @@ var Zap = class {
|
|
|
3258
3805
|
ledger: deriveLedgerAccount(owner),
|
|
3259
3806
|
tokenAccount,
|
|
3260
3807
|
owner
|
|
3261
|
-
}).
|
|
3808
|
+
}).instruction();
|
|
3262
3809
|
});
|
|
3263
3810
|
}
|
|
3264
3811
|
zapInDammV2(params) {
|
|
@@ -3296,7 +3843,7 @@ var Zap = class {
|
|
|
3296
3843
|
tokenBProgram,
|
|
3297
3844
|
dammProgram: DAMM_V2_PROGRAM_ID,
|
|
3298
3845
|
dammEventAuthority: deriveDammV2EventAuthority()
|
|
3299
|
-
}).
|
|
3846
|
+
}).instruction();
|
|
3300
3847
|
});
|
|
3301
3848
|
}
|
|
3302
3849
|
resetOrInitializeLedgerAccount(user) {
|
|
@@ -3306,9 +3853,9 @@ var Zap = class {
|
|
|
3306
3853
|
if (accountInfo) {
|
|
3307
3854
|
const closeLedger = yield this.closeLedgerAccount(user, user);
|
|
3308
3855
|
const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
|
|
3309
|
-
return
|
|
3856
|
+
return [closeLedger, reInitializeLedger];
|
|
3310
3857
|
}
|
|
3311
|
-
return yield this.initializeLedgerAccount(user, user);
|
|
3858
|
+
return [yield this.initializeLedgerAccount(user, user)];
|
|
3312
3859
|
});
|
|
3313
3860
|
}
|
|
3314
3861
|
zapInDlmmForInitializedPosition(params) {
|
|
@@ -3375,7 +3922,7 @@ var Zap = class {
|
|
|
3375
3922
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3376
3923
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3377
3924
|
systemProgram: SystemProgram2.programId
|
|
3378
|
-
}).remainingAccounts(binArrays).
|
|
3925
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3379
3926
|
});
|
|
3380
3927
|
}
|
|
3381
3928
|
zapInDlmmForUninitializedPosition(params) {
|
|
@@ -3439,7 +3986,7 @@ var Zap = class {
|
|
|
3439
3986
|
memoProgram: MEMO_PROGRAM_ID,
|
|
3440
3987
|
dlmmEventAuthority: deriveDlmmEventAuthority(),
|
|
3441
3988
|
systemProgram: SystemProgram2.programId
|
|
3442
|
-
}).remainingAccounts(binArrays).
|
|
3989
|
+
}).remainingAccounts(binArrays).instruction();
|
|
3443
3990
|
});
|
|
3444
3991
|
}
|
|
3445
3992
|
//#region Zap In
|
|
@@ -3453,12 +4000,12 @@ var Zap = class {
|
|
|
3453
4000
|
* @param params.amountIn - The amount of input token
|
|
3454
4001
|
* @param params.inputTokenMint - The input token mint
|
|
3455
4002
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
3456
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
3457
4003
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
3458
4004
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
3459
4005
|
* @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3460
4006
|
* @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3461
4007
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4008
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
3462
4009
|
* @returns The zap-in transaction parameters for a DAMM V2 direct pool
|
|
3463
4010
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3464
4011
|
* @throws if failed to get both Jupiter and DAMM v2 swap quotes
|
|
@@ -3472,12 +4019,12 @@ var Zap = class {
|
|
|
3472
4019
|
inputTokenMint,
|
|
3473
4020
|
amountIn,
|
|
3474
4021
|
positionNftMint,
|
|
3475
|
-
maxAccounts,
|
|
3476
4022
|
maxSqrtPriceChangeBps,
|
|
3477
4023
|
slippageBps,
|
|
3478
4024
|
dammV2Quote,
|
|
3479
4025
|
jupiterQuote,
|
|
3480
|
-
maxTransferAmountExtendPercentage
|
|
4026
|
+
maxTransferAmountExtendPercentage,
|
|
4027
|
+
jupiterQuoteOptions
|
|
3481
4028
|
} = params;
|
|
3482
4029
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3483
4030
|
const {
|
|
@@ -3497,7 +4044,7 @@ var Zap = class {
|
|
|
3497
4044
|
const tokenAProgram = getTokenProgram(tokenAFlag);
|
|
3498
4045
|
const tokenBProgram = getTokenProgram(tokenBFlag);
|
|
3499
4046
|
const preInstructions = [];
|
|
3500
|
-
if (
|
|
4047
|
+
if (inputTokenMint.equals(NATIVE_MINT3)) {
|
|
3501
4048
|
const { ataPubkey: userWrapSolAcc, ix: initializeUserWrapSOLAta } = yield getOrCreateATAInstruction(
|
|
3502
4049
|
this.connection,
|
|
3503
4050
|
NATIVE_MINT3,
|
|
@@ -3549,7 +4096,8 @@ var Zap = class {
|
|
|
3549
4096
|
const singleSidedA = isSingleSidedA(poolState);
|
|
3550
4097
|
const singleSidedB = isSingleSidedB(poolState);
|
|
3551
4098
|
let amount;
|
|
3552
|
-
let
|
|
4099
|
+
let swapInstructions = [];
|
|
4100
|
+
let addressLookupTableAccounts = [];
|
|
3553
4101
|
let maxTransferAmount;
|
|
3554
4102
|
let swapInAmount;
|
|
3555
4103
|
let swapRoute;
|
|
@@ -3563,19 +4111,25 @@ var Zap = class {
|
|
|
3563
4111
|
swapInAmount = amountIn;
|
|
3564
4112
|
amount = new BN5(0);
|
|
3565
4113
|
const result = yield buildJupiterSwapTransaction(
|
|
4114
|
+
this.connection,
|
|
3566
4115
|
user,
|
|
3567
4116
|
inputTokenMint,
|
|
3568
4117
|
outputTokenMint,
|
|
3569
4118
|
swapInAmount,
|
|
3570
|
-
maxAccounts,
|
|
3571
4119
|
slippageBps,
|
|
3572
4120
|
void 0,
|
|
3573
4121
|
{
|
|
3574
4122
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3575
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3576
|
-
|
|
4123
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4124
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4125
|
+
},
|
|
4126
|
+
jupiterQuoteOptions
|
|
3577
4127
|
);
|
|
3578
|
-
|
|
4128
|
+
preInstructions.push(
|
|
4129
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4130
|
+
);
|
|
4131
|
+
swapInstructions = [result.instruction];
|
|
4132
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3579
4133
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3580
4134
|
result.quoteResponse.outAmount,
|
|
3581
4135
|
maxTransferAmountExtendPercentage
|
|
@@ -3612,19 +4166,25 @@ var Zap = class {
|
|
|
3612
4166
|
);
|
|
3613
4167
|
amount = amountIn.sub(swapInAmount);
|
|
3614
4168
|
const result = yield buildJupiterSwapTransaction(
|
|
4169
|
+
this.connection,
|
|
3615
4170
|
user,
|
|
3616
4171
|
inputTokenMint,
|
|
3617
4172
|
outputTokenMint,
|
|
3618
4173
|
swapInAmount,
|
|
3619
|
-
maxAccounts,
|
|
3620
4174
|
slippageBps,
|
|
3621
4175
|
void 0,
|
|
3622
4176
|
{
|
|
3623
4177
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3624
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3625
|
-
|
|
4178
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4179
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4180
|
+
},
|
|
4181
|
+
jupiterQuoteOptions
|
|
3626
4182
|
);
|
|
3627
|
-
|
|
4183
|
+
preInstructions.push(
|
|
4184
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
4185
|
+
);
|
|
4186
|
+
swapInstructions = [result.instruction];
|
|
4187
|
+
addressLookupTableAccounts = result.addressLookupTableAccounts;
|
|
3628
4188
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
3629
4189
|
result.quoteResponse.outAmount,
|
|
3630
4190
|
maxTransferAmountExtendPercentage
|
|
@@ -3682,7 +4242,8 @@ var Zap = class {
|
|
|
3682
4242
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3683
4243
|
maxSqrtPriceChangeBps,
|
|
3684
4244
|
preInstructions,
|
|
3685
|
-
|
|
4245
|
+
swapInstructions,
|
|
4246
|
+
addressLookupTableAccounts,
|
|
3686
4247
|
cleanUpInstructions,
|
|
3687
4248
|
swapInEstimate: {
|
|
3688
4249
|
inAmount: swapInAmount,
|
|
@@ -3701,12 +4262,12 @@ var Zap = class {
|
|
|
3701
4262
|
* @param params.amountIn - The amount of input token
|
|
3702
4263
|
* @param params.inputTokenMint - The input token mint
|
|
3703
4264
|
* @param params.positionNftMint - The position NFT mint account's public key
|
|
3704
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
3705
4265
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
3706
4266
|
* @param params.slippageBps - The swap slippage tolerance in basis points
|
|
3707
4267
|
* @param params.jupiterQuoteToA - The Jupiter quote for swapping to tokenA for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3708
4268
|
* @param params.jupiterQuoteToB - The Jupiter quote for swapping to tokenB for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
|
|
3709
4269
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4270
|
+
* @param params.jupiterQuoteOptions - Optional Jupiter query parameters, see `GetJupiterQuoteParams.queryParams`
|
|
3710
4271
|
* @returns The zap-in transaction parameters for a DAMM V2 indirect pool
|
|
3711
4272
|
* @throws if input token mint matches either tokenA or tokenB in the pool
|
|
3712
4273
|
* @throws if no Jupiter quote provided for both tokens
|
|
@@ -3720,12 +4281,12 @@ var Zap = class {
|
|
|
3720
4281
|
pool,
|
|
3721
4282
|
positionNftMint,
|
|
3722
4283
|
amountIn,
|
|
3723
|
-
maxAccounts,
|
|
3724
4284
|
maxSqrtPriceChangeBps,
|
|
3725
4285
|
maxTransferAmountExtendPercentage,
|
|
3726
4286
|
slippageBps,
|
|
3727
4287
|
jupiterQuoteToA,
|
|
3728
|
-
jupiterQuoteToB
|
|
4288
|
+
jupiterQuoteToB,
|
|
4289
|
+
jupiterQuoteOptions
|
|
3729
4290
|
} = params;
|
|
3730
4291
|
const poolState = yield getDammV2Pool(this.connection, pool);
|
|
3731
4292
|
const {
|
|
@@ -3810,17 +4371,22 @@ var Zap = class {
|
|
|
3810
4371
|
);
|
|
3811
4372
|
}
|
|
3812
4373
|
const result = yield buildJupiterSwapTransaction(
|
|
4374
|
+
this.connection,
|
|
3813
4375
|
user,
|
|
3814
4376
|
inputTokenMint,
|
|
3815
4377
|
tokenAMint,
|
|
3816
4378
|
amountIn,
|
|
3817
|
-
maxAccounts,
|
|
3818
4379
|
slippageBps,
|
|
3819
4380
|
void 0,
|
|
3820
4381
|
{
|
|
3821
4382
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3822
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3823
|
-
|
|
4383
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4384
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4385
|
+
},
|
|
4386
|
+
jupiterQuoteOptions
|
|
4387
|
+
);
|
|
4388
|
+
preInstructions.push(
|
|
4389
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
3824
4390
|
);
|
|
3825
4391
|
return {
|
|
3826
4392
|
user,
|
|
@@ -3844,7 +4410,8 @@ var Zap = class {
|
|
|
3844
4410
|
maxTransferAmountB: new BN5(0),
|
|
3845
4411
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3846
4412
|
preInstructions,
|
|
3847
|
-
|
|
4413
|
+
swapInstructions: [result.instruction],
|
|
4414
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3848
4415
|
cleanUpInstructions,
|
|
3849
4416
|
swapInEstimate: {
|
|
3850
4417
|
inAmountA: amountIn,
|
|
@@ -3861,17 +4428,22 @@ var Zap = class {
|
|
|
3861
4428
|
);
|
|
3862
4429
|
}
|
|
3863
4430
|
const result = yield buildJupiterSwapTransaction(
|
|
4431
|
+
this.connection,
|
|
3864
4432
|
user,
|
|
3865
4433
|
inputTokenMint,
|
|
3866
4434
|
tokenBMint,
|
|
3867
4435
|
amountIn,
|
|
3868
|
-
maxAccounts,
|
|
3869
4436
|
slippageBps,
|
|
3870
4437
|
void 0,
|
|
3871
4438
|
{
|
|
3872
4439
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3873
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3874
|
-
|
|
4440
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4441
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4442
|
+
},
|
|
4443
|
+
jupiterQuoteOptions
|
|
4444
|
+
);
|
|
4445
|
+
preInstructions.push(
|
|
4446
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
3875
4447
|
);
|
|
3876
4448
|
return {
|
|
3877
4449
|
user,
|
|
@@ -3895,7 +4467,8 @@ var Zap = class {
|
|
|
3895
4467
|
swapType: 1 /* swapToB */,
|
|
3896
4468
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3897
4469
|
preInstructions,
|
|
3898
|
-
|
|
4470
|
+
swapInstructions: [result.instruction],
|
|
4471
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3899
4472
|
cleanUpInstructions,
|
|
3900
4473
|
swapInEstimate: {
|
|
3901
4474
|
inAmountA: new BN5(0),
|
|
@@ -3907,17 +4480,22 @@ var Zap = class {
|
|
|
3907
4480
|
}
|
|
3908
4481
|
if (jupiterQuoteToA && jupiterQuoteToB === null) {
|
|
3909
4482
|
const result = yield buildJupiterSwapTransaction(
|
|
4483
|
+
this.connection,
|
|
3910
4484
|
user,
|
|
3911
4485
|
inputTokenMint,
|
|
3912
4486
|
tokenAMint,
|
|
3913
4487
|
amountIn,
|
|
3914
|
-
maxAccounts,
|
|
3915
4488
|
slippageBps,
|
|
3916
4489
|
void 0,
|
|
3917
4490
|
{
|
|
3918
4491
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3919
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3920
|
-
|
|
4492
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4493
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4494
|
+
},
|
|
4495
|
+
jupiterQuoteOptions
|
|
4496
|
+
);
|
|
4497
|
+
preInstructions.push(
|
|
4498
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
3921
4499
|
);
|
|
3922
4500
|
return {
|
|
3923
4501
|
user,
|
|
@@ -3941,7 +4519,8 @@ var Zap = class {
|
|
|
3941
4519
|
maxTransferAmountB: new BN5(0),
|
|
3942
4520
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3943
4521
|
preInstructions,
|
|
3944
|
-
|
|
4522
|
+
swapInstructions: [result.instruction],
|
|
4523
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3945
4524
|
cleanUpInstructions,
|
|
3946
4525
|
swapInEstimate: {
|
|
3947
4526
|
inAmountA: amountIn,
|
|
@@ -3953,17 +4532,22 @@ var Zap = class {
|
|
|
3953
4532
|
}
|
|
3954
4533
|
if (jupiterQuoteToB && jupiterQuoteToA === null) {
|
|
3955
4534
|
const result = yield buildJupiterSwapTransaction(
|
|
4535
|
+
this.connection,
|
|
3956
4536
|
user,
|
|
3957
4537
|
inputTokenMint,
|
|
3958
4538
|
tokenBMint,
|
|
3959
4539
|
amountIn,
|
|
3960
|
-
maxAccounts,
|
|
3961
4540
|
slippageBps,
|
|
3962
4541
|
void 0,
|
|
3963
4542
|
{
|
|
3964
4543
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
3965
|
-
jupiterApiKey: this.jupiterApiKey
|
|
3966
|
-
|
|
4544
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4545
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4546
|
+
},
|
|
4547
|
+
jupiterQuoteOptions
|
|
4548
|
+
);
|
|
4549
|
+
preInstructions.push(
|
|
4550
|
+
...getJupiterCreateAtaInstructions(result.setupInstructions)
|
|
3967
4551
|
);
|
|
3968
4552
|
return {
|
|
3969
4553
|
user,
|
|
@@ -3987,7 +4571,8 @@ var Zap = class {
|
|
|
3987
4571
|
swapType: 1 /* swapToB */,
|
|
3988
4572
|
preSqrtPrice: poolState.sqrtPrice,
|
|
3989
4573
|
preInstructions,
|
|
3990
|
-
|
|
4574
|
+
swapInstructions: [result.instruction],
|
|
4575
|
+
addressLookupTableAccounts: result.addressLookupTableAccounts,
|
|
3991
4576
|
cleanUpInstructions,
|
|
3992
4577
|
swapInEstimate: {
|
|
3993
4578
|
inAmountA: new BN5(0),
|
|
@@ -4039,43 +4624,57 @@ var Zap = class {
|
|
|
4039
4624
|
preSqrtPrice: poolState.sqrtPrice,
|
|
4040
4625
|
cleanUpInstructions
|
|
4041
4626
|
};
|
|
4042
|
-
const
|
|
4627
|
+
const swapToA = yield buildJupiterSwapTransaction(
|
|
4628
|
+
this.connection,
|
|
4043
4629
|
user,
|
|
4044
4630
|
inputTokenMint,
|
|
4045
4631
|
tokenAMint,
|
|
4046
4632
|
swapAmountToA,
|
|
4047
|
-
maxAccounts,
|
|
4048
4633
|
slippageBps,
|
|
4049
4634
|
void 0,
|
|
4050
4635
|
{
|
|
4051
4636
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4052
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4053
|
-
|
|
4637
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4638
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4639
|
+
},
|
|
4640
|
+
jupiterQuoteOptions
|
|
4054
4641
|
);
|
|
4055
|
-
|
|
4642
|
+
preInstructions.push(
|
|
4643
|
+
...getJupiterCreateAtaInstructions(swapToA.setupInstructions)
|
|
4644
|
+
);
|
|
4645
|
+
const swapToB = yield buildJupiterSwapTransaction(
|
|
4646
|
+
this.connection,
|
|
4056
4647
|
user,
|
|
4057
4648
|
inputTokenMint,
|
|
4058
4649
|
tokenBMint,
|
|
4059
4650
|
swapAmountToB,
|
|
4060
|
-
maxAccounts,
|
|
4061
4651
|
slippageBps,
|
|
4062
4652
|
void 0,
|
|
4063
4653
|
{
|
|
4064
4654
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4065
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4066
|
-
|
|
4655
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4656
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4657
|
+
},
|
|
4658
|
+
jupiterQuoteOptions
|
|
4659
|
+
);
|
|
4660
|
+
preInstructions.push(
|
|
4661
|
+
...getJupiterCreateAtaInstructions(swapToB.setupInstructions)
|
|
4067
4662
|
);
|
|
4068
4663
|
return __spreadProps(__spreadValues({}, baseParams), {
|
|
4069
4664
|
maxTransferAmountA: getExtendMaxAmountTransfer(
|
|
4070
|
-
|
|
4665
|
+
swapToA.quoteResponse.outAmount,
|
|
4071
4666
|
maxTransferAmountExtendPercentage
|
|
4072
4667
|
),
|
|
4073
4668
|
maxTransferAmountB: getExtendMaxAmountTransfer(
|
|
4074
|
-
|
|
4669
|
+
swapToB.quoteResponse.outAmount,
|
|
4075
4670
|
maxTransferAmountExtendPercentage
|
|
4076
4671
|
),
|
|
4077
4672
|
swapType: 2 /* swapToBoth */,
|
|
4078
|
-
|
|
4673
|
+
swapInstructions: [swapToA.instruction, swapToB.instruction],
|
|
4674
|
+
addressLookupTableAccounts: mergeAddressLookupTableAccounts(
|
|
4675
|
+
swapToA.addressLookupTableAccounts,
|
|
4676
|
+
swapToB.addressLookupTableAccounts
|
|
4677
|
+
),
|
|
4079
4678
|
swapInEstimate: {
|
|
4080
4679
|
inAmountA: swapAmountToA,
|
|
4081
4680
|
inAmountB: swapAmountToB,
|
|
@@ -4090,7 +4689,12 @@ var Zap = class {
|
|
|
4090
4689
|
});
|
|
4091
4690
|
}
|
|
4092
4691
|
/**
|
|
4093
|
-
* Build DAMM v2 zap-in
|
|
4692
|
+
* Build the DAMM v2 zap-in instructions
|
|
4693
|
+
*
|
|
4694
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
4695
|
+
* They must run in that order but can be split across several transactions, because state
|
|
4696
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
4697
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4094
4698
|
*
|
|
4095
4699
|
* @param params.user - The user's public key
|
|
4096
4700
|
* @param params.pool - The pool's public key
|
|
@@ -4106,10 +4710,11 @@ var Zap = class {
|
|
|
4106
4710
|
* @param params.amount - The amount to deposit
|
|
4107
4711
|
* @param params.preSqrtPrice - The sqrt price before the operation
|
|
4108
4712
|
* @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
|
|
4109
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
4110
|
-
* @param params.
|
|
4713
|
+
* @param params.preInstructions - Instructions to run before the zap in, including the token accounts the Jupiter swaps need. Token account creation repeated here is removed
|
|
4714
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
4715
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4111
4716
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4112
|
-
* @returns
|
|
4717
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4113
4718
|
*/
|
|
4114
4719
|
buildZapInDammV2Transaction(params) {
|
|
4115
4720
|
return __async(this, null, function* () {
|
|
@@ -4129,61 +4734,41 @@ var Zap = class {
|
|
|
4129
4734
|
preSqrtPrice,
|
|
4130
4735
|
maxSqrtPriceChangeBps,
|
|
4131
4736
|
preInstructions,
|
|
4132
|
-
|
|
4737
|
+
swapInstructions,
|
|
4738
|
+
addressLookupTableAccounts,
|
|
4133
4739
|
cleanUpInstructions
|
|
4134
4740
|
} = params;
|
|
4135
|
-
const
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
|
|
4141
|
-
tokenAMint,
|
|
4142
|
-
user,
|
|
4143
|
-
user,
|
|
4144
|
-
false,
|
|
4145
|
-
tokenAProgram
|
|
4146
|
-
),
|
|
4147
|
-
getOrCreateATAInstruction(
|
|
4148
|
-
this.connection,
|
|
4149
|
-
tokenBMint,
|
|
4150
|
-
user,
|
|
4151
|
-
user,
|
|
4152
|
-
false,
|
|
4153
|
-
tokenBProgram
|
|
4154
|
-
)
|
|
4741
|
+
const {
|
|
4742
|
+
tokenAccounts: [tokenAAccount, tokenBAccount],
|
|
4743
|
+
instructions: setupInstructions
|
|
4744
|
+
} = getCreateAtaInstructions(user, [
|
|
4745
|
+
{ mint: tokenAMint, tokenProgram: tokenAProgram },
|
|
4746
|
+
{ mint: tokenBMint, tokenProgram: tokenBProgram }
|
|
4155
4747
|
]);
|
|
4156
|
-
|
|
4157
|
-
|
|
4158
|
-
initializeTokenBIx && setupTransaction.add(initializeTokenBIx);
|
|
4159
|
-
if (preInstructions.length > 0) {
|
|
4160
|
-
setupTransaction.add(...preInstructions);
|
|
4161
|
-
}
|
|
4162
|
-
const ledgerTransaction = new Transaction2();
|
|
4163
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4164
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
4748
|
+
setupInstructions.push(...preInstructions);
|
|
4749
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4165
4750
|
if (isDirectPool) {
|
|
4166
4751
|
const isTokenA = params.isTokenA;
|
|
4167
|
-
const
|
|
4752
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4168
4753
|
user,
|
|
4169
4754
|
amount,
|
|
4170
4755
|
isTokenA
|
|
4171
4756
|
);
|
|
4172
|
-
|
|
4173
|
-
if (
|
|
4757
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4758
|
+
if (swapInstructions.length > 0) {
|
|
4174
4759
|
const tokenAccount = isTokenA ? tokenBAccount : tokenAAccount;
|
|
4175
4760
|
const preTokenBalance = yield getTokenAccountBalance(
|
|
4176
4761
|
this.connection,
|
|
4177
4762
|
tokenAccount
|
|
4178
4763
|
);
|
|
4179
|
-
const
|
|
4764
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4180
4765
|
user,
|
|
4181
4766
|
tokenAccount,
|
|
4182
4767
|
new BN5(preTokenBalance),
|
|
4183
4768
|
params.maxTransferAmount,
|
|
4184
4769
|
!isTokenA
|
|
4185
4770
|
);
|
|
4186
|
-
|
|
4771
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4187
4772
|
}
|
|
4188
4773
|
} else {
|
|
4189
4774
|
const preTokenABalance = yield getTokenAccountBalance(
|
|
@@ -4194,7 +4779,7 @@ var Zap = class {
|
|
|
4194
4779
|
this.connection,
|
|
4195
4780
|
tokenBAccount
|
|
4196
4781
|
);
|
|
4197
|
-
const
|
|
4782
|
+
const updateLedgerBalanceTokenAAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4198
4783
|
user,
|
|
4199
4784
|
tokenAAccount,
|
|
4200
4785
|
new BN5(preTokenABalance),
|
|
@@ -4202,7 +4787,7 @@ var Zap = class {
|
|
|
4202
4787
|
true
|
|
4203
4788
|
// is token A
|
|
4204
4789
|
);
|
|
4205
|
-
const
|
|
4790
|
+
const updateLedgerBalanceTokenBAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4206
4791
|
user,
|
|
4207
4792
|
tokenBAccount,
|
|
4208
4793
|
new BN5(preTokenBBalance),
|
|
@@ -4212,14 +4797,17 @@ var Zap = class {
|
|
|
4212
4797
|
);
|
|
4213
4798
|
const swapType = params.swapType;
|
|
4214
4799
|
if (swapType == 0 /* swapToA */) {
|
|
4215
|
-
|
|
4800
|
+
ledgerInstructions.push(updateLedgerBalanceTokenAAfterSwapIx);
|
|
4216
4801
|
} else if (swapType == 1 /* swapToB */) {
|
|
4217
|
-
|
|
4802
|
+
ledgerInstructions.push(updateLedgerBalanceTokenBAfterSwapIx);
|
|
4218
4803
|
} else {
|
|
4219
|
-
|
|
4804
|
+
ledgerInstructions.push(
|
|
4805
|
+
updateLedgerBalanceTokenAAfterSwapIx,
|
|
4806
|
+
updateLedgerBalanceTokenBAfterSwapIx
|
|
4807
|
+
);
|
|
4220
4808
|
}
|
|
4221
4809
|
}
|
|
4222
|
-
const
|
|
4810
|
+
const zapInInstruction = yield this.zapInDammV2({
|
|
4223
4811
|
user,
|
|
4224
4812
|
pool,
|
|
4225
4813
|
position,
|
|
@@ -4235,18 +4823,17 @@ var Zap = class {
|
|
|
4235
4823
|
tokenAAccount,
|
|
4236
4824
|
tokenBAccount
|
|
4237
4825
|
});
|
|
4238
|
-
const
|
|
4239
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4240
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4241
|
-
if (cleanUpInstructions.length > 0) {
|
|
4242
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4243
|
-
}
|
|
4826
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4244
4827
|
return {
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4828
|
+
instructions: [
|
|
4829
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
4830
|
+
...swapInstructions,
|
|
4831
|
+
...ledgerInstructions,
|
|
4832
|
+
zapInInstruction,
|
|
4833
|
+
closeLedgerInstruction,
|
|
4834
|
+
...cleanUpInstructions
|
|
4835
|
+
],
|
|
4836
|
+
addressLookupTableAccounts
|
|
4250
4837
|
};
|
|
4251
4838
|
});
|
|
4252
4839
|
}
|
|
@@ -4263,8 +4850,7 @@ var Zap = class {
|
|
|
4263
4850
|
* @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
|
|
4264
4851
|
* @param params.strategy - The liquidity distribution strategy
|
|
4265
4852
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4266
|
-
* @param params.
|
|
4267
|
-
* @param params.swapSlippageBps - The swap slippage tolerance in basis points
|
|
4853
|
+
* @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
|
|
4268
4854
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4269
4855
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
4270
4856
|
* @param params.directSwapEstimate - The result from the direct swap estimate
|
|
@@ -4284,7 +4870,6 @@ var Zap = class {
|
|
|
4284
4870
|
maxDeltaId,
|
|
4285
4871
|
strategy,
|
|
4286
4872
|
favorXInActiveId,
|
|
4287
|
-
maxAccounts,
|
|
4288
4873
|
swapSlippageBps,
|
|
4289
4874
|
maxTransferAmountExtendPercentage,
|
|
4290
4875
|
maxActiveBinSlippage,
|
|
@@ -4317,25 +4902,31 @@ var Zap = class {
|
|
|
4317
4902
|
initializeWrapSolIx && preInstructions.push(initializeWrapSolIx);
|
|
4318
4903
|
preInstructions.push(...wrapSOL);
|
|
4319
4904
|
}
|
|
4320
|
-
const
|
|
4905
|
+
const swapInstructions = [];
|
|
4906
|
+
let addressLookupTableAccounts = [];
|
|
4321
4907
|
let maxTransferAmount;
|
|
4322
4908
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4323
4909
|
const swapQuote = directSwapEstimate.quote;
|
|
4324
4910
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4325
|
-
const
|
|
4911
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
4912
|
+
this.connection,
|
|
4326
4913
|
user,
|
|
4327
4914
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
|
|
4328
4915
|
directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
|
|
4329
4916
|
directSwapEstimate.swapAmount,
|
|
4330
|
-
maxAccounts,
|
|
4331
4917
|
swapSlippageBps,
|
|
4332
4918
|
swapQuote.originalQuote,
|
|
4333
4919
|
{
|
|
4334
4920
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4335
|
-
jupiterApiKey: this.jupiterApiKey
|
|
4921
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
4922
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4336
4923
|
}
|
|
4337
4924
|
);
|
|
4338
|
-
|
|
4925
|
+
preInstructions.push(
|
|
4926
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
4927
|
+
);
|
|
4928
|
+
swapInstructions.push(swap.instruction);
|
|
4929
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4339
4930
|
} else {
|
|
4340
4931
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4341
4932
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4348,6 +4939,9 @@ var Zap = class {
|
|
|
4348
4939
|
user,
|
|
4349
4940
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4350
4941
|
});
|
|
4942
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
4943
|
+
swapTx.instructions
|
|
4944
|
+
);
|
|
4351
4945
|
if (tokenXMint.equals(NATIVE_MINT3) || tokenYMint.equals(NATIVE_MINT3)) {
|
|
4352
4946
|
swapTx.instructions = swapTx.instructions.filter((ix) => {
|
|
4353
4947
|
if (ix.programId.equals(TOKEN_PROGRAM_ID6)) {
|
|
@@ -4356,7 +4950,7 @@ var Zap = class {
|
|
|
4356
4950
|
return true;
|
|
4357
4951
|
});
|
|
4358
4952
|
}
|
|
4359
|
-
|
|
4953
|
+
swapInstructions.push(...swapTx.instructions);
|
|
4360
4954
|
}
|
|
4361
4955
|
maxTransferAmount = getExtendMaxAmountTransfer(
|
|
4362
4956
|
directSwapEstimate.expectedOutput.toString(),
|
|
@@ -4406,7 +5000,8 @@ var Zap = class {
|
|
|
4406
5000
|
amount,
|
|
4407
5001
|
maxTransferAmount,
|
|
4408
5002
|
preInstructions,
|
|
4409
|
-
|
|
5003
|
+
swapInstructions,
|
|
5004
|
+
addressLookupTableAccounts,
|
|
4410
5005
|
cleanUpInstructions,
|
|
4411
5006
|
binArrays,
|
|
4412
5007
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4428,7 +5023,6 @@ var Zap = class {
|
|
|
4428
5023
|
* @param params.strategy - The liquidity distribution strategy
|
|
4429
5024
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4430
5025
|
* @param params.indirectSwapEstimate - The result from the indirect swap estimate
|
|
4431
|
-
* @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
|
|
4432
5026
|
* @param params.swapSlippageBps - The swap slippage tolerance in basis points
|
|
4433
5027
|
* @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
|
|
4434
5028
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
@@ -4449,7 +5043,6 @@ var Zap = class {
|
|
|
4449
5043
|
strategy,
|
|
4450
5044
|
favorXInActiveId,
|
|
4451
5045
|
indirectSwapEstimate,
|
|
4452
|
-
maxAccounts,
|
|
4453
5046
|
swapSlippageBps,
|
|
4454
5047
|
maxTransferAmountExtendPercentage,
|
|
4455
5048
|
maxActiveBinSlippage,
|
|
@@ -4487,41 +5080,55 @@ var Zap = class {
|
|
|
4487
5080
|
}
|
|
4488
5081
|
let maxTransferAmountX;
|
|
4489
5082
|
let maxTransferAmountY;
|
|
4490
|
-
const
|
|
5083
|
+
const swapInstructions = [];
|
|
5084
|
+
const swapLookupTables = [];
|
|
4491
5085
|
const swapAmountToXInLamports = indirectSwapEstimate.swapAmountToX;
|
|
4492
5086
|
const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
|
|
4493
5087
|
if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
|
|
4494
|
-
const
|
|
5088
|
+
const swapToX = yield buildJupiterSwapTransaction(
|
|
5089
|
+
this.connection,
|
|
4495
5090
|
user,
|
|
4496
5091
|
inputTokenMint,
|
|
4497
5092
|
tokenXMint,
|
|
4498
5093
|
swapAmountToXInLamports,
|
|
4499
|
-
maxAccounts,
|
|
4500
5094
|
swapSlippageBps,
|
|
4501
5095
|
indirectSwapEstimate.swapToX,
|
|
4502
5096
|
{
|
|
4503
5097
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4504
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5098
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5099
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4505
5100
|
}
|
|
4506
5101
|
);
|
|
4507
|
-
|
|
5102
|
+
preInstructions.push(
|
|
5103
|
+
...getJupiterCreateAtaInstructions(swapToX.setupInstructions)
|
|
5104
|
+
);
|
|
5105
|
+
swapInstructions.push(swapToX.instruction);
|
|
5106
|
+
swapLookupTables.push(swapToX.addressLookupTableAccounts);
|
|
4508
5107
|
}
|
|
4509
5108
|
if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
|
|
4510
|
-
const
|
|
5109
|
+
const swapToY = yield buildJupiterSwapTransaction(
|
|
5110
|
+
this.connection,
|
|
4511
5111
|
user,
|
|
4512
5112
|
inputTokenMint,
|
|
4513
5113
|
tokenYMint,
|
|
4514
5114
|
swapAmountToYInLamports,
|
|
4515
|
-
maxAccounts,
|
|
4516
5115
|
swapSlippageBps,
|
|
4517
5116
|
indirectSwapEstimate.swapToY,
|
|
4518
5117
|
{
|
|
4519
5118
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4520
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5119
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5120
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4521
5121
|
}
|
|
4522
5122
|
);
|
|
4523
|
-
|
|
5123
|
+
preInstructions.push(
|
|
5124
|
+
...getJupiterCreateAtaInstructions(swapToY.setupInstructions)
|
|
5125
|
+
);
|
|
5126
|
+
swapInstructions.push(swapToY.instruction);
|
|
5127
|
+
swapLookupTables.push(swapToY.addressLookupTableAccounts);
|
|
4524
5128
|
}
|
|
5129
|
+
const addressLookupTableAccounts = mergeAddressLookupTableAccounts(
|
|
5130
|
+
...swapLookupTables
|
|
5131
|
+
);
|
|
4525
5132
|
maxTransferAmountX = getExtendMaxAmountTransfer(
|
|
4526
5133
|
indirectSwapEstimate.postSwapX.toString(),
|
|
4527
5134
|
maxTransferAmountExtendPercentage
|
|
@@ -4563,7 +5170,8 @@ var Zap = class {
|
|
|
4563
5170
|
maxTransferAmountX,
|
|
4564
5171
|
maxTransferAmountY,
|
|
4565
5172
|
preInstructions,
|
|
4566
|
-
|
|
5173
|
+
swapInstructions,
|
|
5174
|
+
addressLookupTableAccounts,
|
|
4567
5175
|
cleanUpInstructions,
|
|
4568
5176
|
binArrays,
|
|
4569
5177
|
binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
|
|
@@ -4573,7 +5181,12 @@ var Zap = class {
|
|
|
4573
5181
|
});
|
|
4574
5182
|
}
|
|
4575
5183
|
/**
|
|
4576
|
-
*
|
|
5184
|
+
* Build the DLMM zap-in instructions
|
|
5185
|
+
*
|
|
5186
|
+
* Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
|
|
5187
|
+
* They must run in that order but can be split across several transactions, because state
|
|
5188
|
+
* between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
|
|
5189
|
+
* No compute budget instructions are included; the client sets the compute budget for each transaction.
|
|
4577
5190
|
*
|
|
4578
5191
|
* @param params.user - The user's public key
|
|
4579
5192
|
* @param params.lbPair - The DLMM pool's public key
|
|
@@ -4588,14 +5201,15 @@ var Zap = class {
|
|
|
4588
5201
|
* @param params.maxActiveBinSlippage - The maximum active bin slippage
|
|
4589
5202
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4590
5203
|
* @param params.strategy - The liquidity distribution strategy
|
|
4591
|
-
* @param params.preInstructions - Instructions to run before the zap in
|
|
4592
|
-
* @param params.
|
|
5204
|
+
* @param params.preInstructions - Instructions to run before the zap in, including the token accounts the Jupiter swaps need. Token account creation repeated here is removed
|
|
5205
|
+
* @param params.swapInstructions - Swap instructions to execute
|
|
5206
|
+
* @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
|
|
4593
5207
|
* @param params.cleanUpInstructions - Instructions to run after the zap in
|
|
4594
5208
|
* @param params.binArrays - The bin arrays required for the position
|
|
4595
5209
|
* @param params.binArrayBitmapExtension - The bin array bitmap extension account if it exists
|
|
4596
5210
|
* @param params.isDirectRoute - Whether this is a direct route
|
|
4597
5211
|
* @param params.singleSided - Optional single-sided deposit mode (X or Y only) - default is non-single-sided
|
|
4598
|
-
* @returns
|
|
5212
|
+
* @returns The ordered instructions and the lookup tables they use
|
|
4599
5213
|
*/
|
|
4600
5214
|
buildZapInDlmmTransaction(params) {
|
|
4601
5215
|
return __async(this, null, function* () {
|
|
@@ -4614,90 +5228,70 @@ var Zap = class {
|
|
|
4614
5228
|
favorXInActiveId,
|
|
4615
5229
|
strategy,
|
|
4616
5230
|
preInstructions,
|
|
4617
|
-
|
|
5231
|
+
swapInstructions,
|
|
5232
|
+
addressLookupTableAccounts,
|
|
4618
5233
|
cleanUpInstructions,
|
|
4619
5234
|
binArrays,
|
|
4620
5235
|
binArrayBitmapExtension,
|
|
4621
5236
|
isDirectRoute,
|
|
4622
5237
|
singleSided
|
|
4623
5238
|
} = params;
|
|
4624
|
-
const
|
|
4625
|
-
|
|
4626
|
-
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
|
|
4630
|
-
tokenXMint,
|
|
4631
|
-
user,
|
|
4632
|
-
user,
|
|
4633
|
-
false,
|
|
4634
|
-
tokenXProgram
|
|
4635
|
-
),
|
|
4636
|
-
getOrCreateATAInstruction(
|
|
4637
|
-
this.connection,
|
|
4638
|
-
tokenYMint,
|
|
4639
|
-
user,
|
|
4640
|
-
user,
|
|
4641
|
-
false,
|
|
4642
|
-
tokenYProgram
|
|
4643
|
-
)
|
|
5239
|
+
const {
|
|
5240
|
+
tokenAccounts: [tokenXAccount, tokenYAccount],
|
|
5241
|
+
instructions: setupInstructions
|
|
5242
|
+
} = getCreateAtaInstructions(user, [
|
|
5243
|
+
{ mint: tokenXMint, tokenProgram: tokenXProgram },
|
|
5244
|
+
{ mint: tokenYMint, tokenProgram: tokenYProgram }
|
|
4644
5245
|
]);
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
initializeTokenYIx && setupTransaction.add(initializeTokenYIx);
|
|
4648
|
-
if (preInstructions.length > 0) {
|
|
4649
|
-
setupTransaction.add(...preInstructions);
|
|
4650
|
-
}
|
|
4651
|
-
const ledgerTransaction = new Transaction2();
|
|
4652
|
-
const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
|
|
4653
|
-
ledgerTransaction.add(resetOrInitializeLedgerTx);
|
|
5246
|
+
setupInstructions.push(...preInstructions);
|
|
5247
|
+
const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
|
|
4654
5248
|
if (isDirectRoute) {
|
|
4655
5249
|
const { isTokenX, amount, maxTransferAmount } = params;
|
|
4656
5250
|
if (singleSided !== void 0) {
|
|
4657
5251
|
const singleSidedX = singleSided === 0 /* X */;
|
|
4658
|
-
if (
|
|
5252
|
+
if (swapInstructions.length > 0) {
|
|
4659
5253
|
const swappedTokenAccount = singleSidedX ? tokenXAccount : tokenYAccount;
|
|
4660
5254
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4661
5255
|
this.connection,
|
|
4662
5256
|
swappedTokenAccount
|
|
4663
5257
|
);
|
|
4664
|
-
const
|
|
5258
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4665
5259
|
user,
|
|
4666
5260
|
swappedTokenAccount,
|
|
4667
5261
|
new BN5(preSwappedTokenBalance),
|
|
4668
5262
|
maxTransferAmount,
|
|
4669
5263
|
singleSidedX
|
|
4670
5264
|
);
|
|
4671
|
-
|
|
5265
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4672
5266
|
} else {
|
|
4673
|
-
const
|
|
5267
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4674
5268
|
user,
|
|
4675
5269
|
amount,
|
|
4676
5270
|
singleSidedX
|
|
4677
5271
|
);
|
|
4678
|
-
|
|
5272
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
4679
5273
|
}
|
|
4680
5274
|
} else {
|
|
4681
|
-
const
|
|
5275
|
+
const setLedgerBalanceIx = yield this.setLedgerBalance(
|
|
4682
5276
|
user,
|
|
4683
5277
|
amount,
|
|
4684
5278
|
isTokenX
|
|
4685
5279
|
);
|
|
4686
|
-
|
|
4687
|
-
if (
|
|
5280
|
+
ledgerInstructions.push(setLedgerBalanceIx);
|
|
5281
|
+
if (swapInstructions.length > 0) {
|
|
4688
5282
|
const swappedTokenAccount = isTokenX ? tokenYAccount : tokenXAccount;
|
|
4689
5283
|
const preSwappedTokenBalance = yield getTokenAccountBalance(
|
|
4690
5284
|
this.connection,
|
|
4691
5285
|
swappedTokenAccount
|
|
4692
5286
|
);
|
|
4693
|
-
const
|
|
5287
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4694
5288
|
user,
|
|
4695
5289
|
swappedTokenAccount,
|
|
4696
5290
|
new BN5(preSwappedTokenBalance),
|
|
4697
5291
|
maxTransferAmount,
|
|
4698
5292
|
!isTokenX
|
|
4699
5293
|
);
|
|
4700
|
-
|
|
5294
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4701
5295
|
}
|
|
4702
5296
|
}
|
|
4703
5297
|
} else {
|
|
@@ -4709,14 +5303,14 @@ var Zap = class {
|
|
|
4709
5303
|
this.connection,
|
|
4710
5304
|
swappedTokenAccount
|
|
4711
5305
|
);
|
|
4712
|
-
const
|
|
5306
|
+
const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4713
5307
|
user,
|
|
4714
5308
|
swappedTokenAccount,
|
|
4715
5309
|
new BN5(preSwappedTokenBalance),
|
|
4716
5310
|
singleSidedX ? maxTransferAmountX : maxTransferAmountY,
|
|
4717
5311
|
singleSidedX
|
|
4718
5312
|
);
|
|
4719
|
-
|
|
5313
|
+
ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
|
|
4720
5314
|
} else {
|
|
4721
5315
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
4722
5316
|
this.connection,
|
|
@@ -4726,22 +5320,22 @@ var Zap = class {
|
|
|
4726
5320
|
this.connection,
|
|
4727
5321
|
tokenYAccount
|
|
4728
5322
|
);
|
|
4729
|
-
const
|
|
5323
|
+
const updateLedgerBalanceTokenXAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4730
5324
|
user,
|
|
4731
5325
|
tokenXAccount,
|
|
4732
5326
|
new BN5(preTokenXBalance),
|
|
4733
5327
|
maxTransferAmountX,
|
|
4734
5328
|
true
|
|
4735
5329
|
);
|
|
4736
|
-
const
|
|
5330
|
+
const updateLedgerBalanceTokenYAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4737
5331
|
user,
|
|
4738
5332
|
tokenYAccount,
|
|
4739
5333
|
new BN5(preTokenYBalance),
|
|
4740
5334
|
maxTransferAmountY,
|
|
4741
5335
|
false
|
|
4742
5336
|
);
|
|
4743
|
-
|
|
4744
|
-
|
|
5337
|
+
ledgerInstructions.push(updateLedgerBalanceTokenXAfterSwapIx);
|
|
5338
|
+
ledgerInstructions.push(updateLedgerBalanceTokenYAfterSwapIx);
|
|
4745
5339
|
}
|
|
4746
5340
|
}
|
|
4747
5341
|
const dlmm = yield DLMM3.create(this.connection, lbPair);
|
|
@@ -4755,7 +5349,7 @@ var Zap = class {
|
|
|
4755
5349
|
tokenYProgram,
|
|
4756
5350
|
dlmm.lbPair
|
|
4757
5351
|
);
|
|
4758
|
-
const
|
|
5352
|
+
const zapInInstruction = yield this.zapInDlmmForUninitializedPosition({
|
|
4759
5353
|
user,
|
|
4760
5354
|
lbPair,
|
|
4761
5355
|
position,
|
|
@@ -4769,18 +5363,17 @@ var Zap = class {
|
|
|
4769
5363
|
strategy,
|
|
4770
5364
|
remainingAccountInfo
|
|
4771
5365
|
});
|
|
4772
|
-
const
|
|
4773
|
-
const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
|
|
4774
|
-
cleanUpTransaction.add(closeLedgerTransaction);
|
|
4775
|
-
if (cleanUpInstructions.length > 0) {
|
|
4776
|
-
cleanUpTransaction.add(...cleanUpInstructions);
|
|
4777
|
-
}
|
|
5366
|
+
const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
|
|
4778
5367
|
return {
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
5368
|
+
instructions: [
|
|
5369
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5370
|
+
...swapInstructions,
|
|
5371
|
+
...ledgerInstructions,
|
|
5372
|
+
zapInInstruction,
|
|
5373
|
+
closeLedgerInstruction,
|
|
5374
|
+
...cleanUpInstructions
|
|
5375
|
+
],
|
|
5376
|
+
addressLookupTableAccounts
|
|
4784
5377
|
};
|
|
4785
5378
|
});
|
|
4786
5379
|
}
|
|
@@ -4788,6 +5381,13 @@ var Zap = class {
|
|
|
4788
5381
|
* High level method for DLMM position rebalancing
|
|
4789
5382
|
* Consist of remove liquidity, zap out through Jupiter or DLMM, and zap back in to rebalance the position
|
|
4790
5383
|
*
|
|
5384
|
+
* Instructions are ordered: setup (token accounts), init bin arrays, rebalance position, swap, ledger,
|
|
5385
|
+
* zap in, clean up. They must run in that order but can be split across several transactions.
|
|
5386
|
+
* Splitting loses atomicity, so send split transactions as a bundle.
|
|
5387
|
+
* No compute budget instructions are included. The zap-in instruction was measured at about 462k
|
|
5388
|
+
* compute units. Without a compute unit limit, a transaction gets 200k units per instruction (up to
|
|
5389
|
+
* 1.4M), which may not cover it, so set a compute unit limit on the transaction that holds it.
|
|
5390
|
+
*
|
|
4791
5391
|
* @param params - Rebalancing DLMM position parameters
|
|
4792
5392
|
* @param params.lbPairAddress - The DLMM pool address
|
|
4793
5393
|
* @param params.positionAddress - The position address
|
|
@@ -4799,8 +5399,7 @@ var Zap = class {
|
|
|
4799
5399
|
* @param params.strategy - The strategy to use for the rebalance
|
|
4800
5400
|
* @param params.favorXInActiveId - Whether to favor token X in the active bin
|
|
4801
5401
|
* @param params.directSwapEstimate - The estimate of the direct swap operation
|
|
4802
|
-
* @
|
|
4803
|
-
* @returns Response containing transactions and estimation details
|
|
5402
|
+
* @returns The ordered instructions, the lookup tables they use, and the estimated balances
|
|
4804
5403
|
* @throws if fail to get jupiter quote or jupiter swap instruction
|
|
4805
5404
|
*/
|
|
4806
5405
|
rebalanceDlmmPosition(params) {
|
|
@@ -4815,36 +5414,18 @@ var Zap = class {
|
|
|
4815
5414
|
swapSlippageBps,
|
|
4816
5415
|
strategy,
|
|
4817
5416
|
favorXInActiveId,
|
|
4818
|
-
directSwapEstimate
|
|
4819
|
-
maxAccounts = 50
|
|
5417
|
+
directSwapEstimate
|
|
4820
5418
|
} = params;
|
|
4821
5419
|
const dlmm = yield DLMM3.create(this.connection, lbPair);
|
|
4822
5420
|
const userPosition = yield dlmm.getPosition(position);
|
|
4823
5421
|
const { tokenXProgram, tokenYProgram } = getTokenProgramId(dlmm.lbPair);
|
|
4824
|
-
const
|
|
4825
|
-
|
|
4826
|
-
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
dlmm.lbPair.tokenXMint,
|
|
4831
|
-
user,
|
|
4832
|
-
user,
|
|
4833
|
-
true,
|
|
4834
|
-
tokenXProgram
|
|
4835
|
-
),
|
|
4836
|
-
getOrCreateATAInstruction(
|
|
4837
|
-
this.connection,
|
|
4838
|
-
dlmm.lbPair.tokenYMint,
|
|
4839
|
-
user,
|
|
4840
|
-
user,
|
|
4841
|
-
true,
|
|
4842
|
-
tokenYProgram
|
|
4843
|
-
)
|
|
5422
|
+
const {
|
|
5423
|
+
tokenAccounts: [userTokenX, userTokenY],
|
|
5424
|
+
instructions: setupInstructions
|
|
5425
|
+
} = getCreateAtaInstructions(user, [
|
|
5426
|
+
{ mint: dlmm.lbPair.tokenXMint, tokenProgram: tokenXProgram },
|
|
5427
|
+
{ mint: dlmm.lbPair.tokenYMint, tokenProgram: tokenYProgram }
|
|
4844
5428
|
]);
|
|
4845
|
-
const setupTransaction = new Transaction2();
|
|
4846
|
-
userTokenXIx && setupTransaction.add(userTokenXIx);
|
|
4847
|
-
userTokenYIx && setupTransaction.add(userTokenYIx);
|
|
4848
5429
|
const strategyParamBuilder = getLiquidityStrategyParameterBuilder(strategy);
|
|
4849
5430
|
const { x0, y0, deltaX, deltaY } = buildLiquidityStrategyParameters(
|
|
4850
5431
|
new BN5(0),
|
|
@@ -4895,32 +5476,40 @@ var Zap = class {
|
|
|
4895
5476
|
{ simulationResult, rebalancePosition },
|
|
4896
5477
|
new BN5(maxActiveBinSlippage)
|
|
4897
5478
|
);
|
|
4898
|
-
let rebalancePositionInstruction =
|
|
5479
|
+
let rebalancePositionInstruction = filterOutComputeBudgetInstructions(
|
|
5480
|
+
_rebalancePositionInstruction
|
|
5481
|
+
);
|
|
4899
5482
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
4900
5483
|
rebalancePositionInstruction = filterOutCloseSplTokenAccountInstructions(
|
|
4901
|
-
|
|
5484
|
+
rebalancePositionInstruction
|
|
4902
5485
|
);
|
|
4903
5486
|
}
|
|
4904
5487
|
const tokenXAmount = new BN5(userPosition.positionData.totalXAmount);
|
|
4905
5488
|
const tokenYAmount = new BN5(userPosition.positionData.totalYAmount);
|
|
4906
|
-
let
|
|
5489
|
+
let swapInstructions = [];
|
|
5490
|
+
let addressLookupTableAccounts = [];
|
|
4907
5491
|
if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
|
|
4908
5492
|
const swapQuote = directSwapEstimate.quote;
|
|
4909
5493
|
if (swapQuote.route === 0 /* Jupiter */) {
|
|
4910
|
-
const
|
|
5494
|
+
const swap = yield buildJupiterSwapTransaction(
|
|
5495
|
+
this.connection,
|
|
4911
5496
|
user,
|
|
4912
5497
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
|
|
4913
5498
|
directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
|
|
4914
5499
|
directSwapEstimate.swapAmount,
|
|
4915
|
-
maxAccounts,
|
|
4916
5500
|
swapSlippageBps,
|
|
4917
5501
|
swapQuote.originalQuote,
|
|
4918
5502
|
{
|
|
4919
5503
|
jupiterApiUrl: this.jupiterApiUrl,
|
|
4920
|
-
jupiterApiKey: this.jupiterApiKey
|
|
5504
|
+
jupiterApiKey: this.jupiterApiKey,
|
|
5505
|
+
jupiterApiVersion: this.jupiterApiVersion
|
|
4921
5506
|
}
|
|
4922
5507
|
);
|
|
4923
|
-
|
|
5508
|
+
setupInstructions.push(
|
|
5509
|
+
...getJupiterCreateAtaInstructions(swap.setupInstructions)
|
|
5510
|
+
);
|
|
5511
|
+
swapInstructions = [swap.instruction];
|
|
5512
|
+
addressLookupTableAccounts = swap.addressLookupTableAccounts;
|
|
4924
5513
|
} else {
|
|
4925
5514
|
const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
|
|
4926
5515
|
const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
|
|
@@ -4933,12 +5522,15 @@ var Zap = class {
|
|
|
4933
5522
|
user,
|
|
4934
5523
|
binArraysPubkey: binArrays2.map((item) => item.publicKey)
|
|
4935
5524
|
});
|
|
5525
|
+
swapTx.instructions = filterOutComputeBudgetInstructions(
|
|
5526
|
+
swapTx.instructions
|
|
5527
|
+
);
|
|
4936
5528
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
4937
5529
|
swapTx.instructions = filterOutCloseSplTokenAccountInstructions(
|
|
4938
5530
|
swapTx.instructions
|
|
4939
5531
|
);
|
|
4940
5532
|
}
|
|
4941
|
-
|
|
5533
|
+
swapInstructions = swapTx.instructions;
|
|
4942
5534
|
}
|
|
4943
5535
|
}
|
|
4944
5536
|
const preTokenXBalance = yield getTokenAccountBalance(
|
|
@@ -4953,27 +5545,27 @@ var Zap = class {
|
|
|
4953
5545
|
const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
|
|
4954
5546
|
const ledgerAddress = deriveLedgerAccount(user);
|
|
4955
5547
|
const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
|
|
4956
|
-
const
|
|
5548
|
+
const ledgerInstructions = [];
|
|
4957
5549
|
if (!ledgerAccountInfo) {
|
|
4958
|
-
const
|
|
4959
|
-
|
|
5550
|
+
const initLedgerIx = yield this.initializeLedgerAccount(user, user);
|
|
5551
|
+
ledgerInstructions.push(initLedgerIx);
|
|
4960
5552
|
}
|
|
4961
|
-
const
|
|
5553
|
+
const updateLedgerXIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4962
5554
|
user,
|
|
4963
5555
|
userTokenX,
|
|
4964
5556
|
new BN5(preTokenXBalance),
|
|
4965
5557
|
tokenXAmountAfterSwap,
|
|
4966
5558
|
true
|
|
4967
5559
|
);
|
|
4968
|
-
|
|
4969
|
-
const
|
|
5560
|
+
ledgerInstructions.push(updateLedgerXIx);
|
|
5561
|
+
const updateLedgerYIx = yield this.updateLedgerBalanceAfterSwap(
|
|
4970
5562
|
user,
|
|
4971
5563
|
userTokenY,
|
|
4972
5564
|
new BN5(preTokenYBalance),
|
|
4973
5565
|
tokenYAmountAfterSwap,
|
|
4974
5566
|
false
|
|
4975
5567
|
);
|
|
4976
|
-
|
|
5568
|
+
ledgerInstructions.push(updateLedgerYIx);
|
|
4977
5569
|
const binArrays = getBinArraysRequiredByPositionRange(
|
|
4978
5570
|
lbPair,
|
|
4979
5571
|
new BN5(dlmm.lbPair.activeId + minDeltaId),
|
|
@@ -4994,7 +5586,7 @@ var Zap = class {
|
|
|
4994
5586
|
tokenYProgram,
|
|
4995
5587
|
dlmm.lbPair
|
|
4996
5588
|
);
|
|
4997
|
-
const
|
|
5589
|
+
const zapInInstruction = yield this.zapInDlmmForInitializedPosition({
|
|
4998
5590
|
user,
|
|
4999
5591
|
lbPair,
|
|
5000
5592
|
position,
|
|
@@ -5007,28 +5599,26 @@ var Zap = class {
|
|
|
5007
5599
|
strategy,
|
|
5008
5600
|
remainingAccountInfo
|
|
5009
5601
|
});
|
|
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);
|
|
5602
|
+
const cleanUpInstructions = [
|
|
5603
|
+
yield this.closeLedgerAccount(user, user)
|
|
5604
|
+
];
|
|
5018
5605
|
if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
|
|
5019
5606
|
const unwrapIx = unwrapSOLInstruction(user, user);
|
|
5020
5607
|
if (unwrapIx) {
|
|
5021
|
-
|
|
5608
|
+
cleanUpInstructions.push(unwrapIx);
|
|
5022
5609
|
}
|
|
5023
5610
|
}
|
|
5024
5611
|
return {
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5612
|
+
instructions: [
|
|
5613
|
+
...dedupeCreateAtaInstructions(setupInstructions),
|
|
5614
|
+
...filterOutComputeBudgetInstructions(initBinArrayInstructions),
|
|
5615
|
+
...rebalancePositionInstruction,
|
|
5616
|
+
...swapInstructions,
|
|
5617
|
+
...ledgerInstructions,
|
|
5618
|
+
zapInInstruction,
|
|
5619
|
+
...cleanUpInstructions
|
|
5620
|
+
],
|
|
5621
|
+
addressLookupTableAccounts,
|
|
5032
5622
|
estimation: {
|
|
5033
5623
|
currentBalances: {
|
|
5034
5624
|
tokenX: tokenXAmount,
|
|
@@ -5054,7 +5644,7 @@ var Zap = class {
|
|
|
5054
5644
|
* @param params.ammProgram - AMM program ID to interact with
|
|
5055
5645
|
* @param params.preInstructions - Instructions to run before the zap out
|
|
5056
5646
|
* @param params.postInstructions - Instructions to run after the zap out
|
|
5057
|
-
* @returns
|
|
5647
|
+
* @returns The pre-instructions, the zap out instruction and the post-instructions in order, with no lookup tables
|
|
5058
5648
|
*/
|
|
5059
5649
|
zapOut(params) {
|
|
5060
5650
|
return __async(this, null, function* () {
|
|
@@ -5066,10 +5656,18 @@ var Zap = class {
|
|
|
5066
5656
|
preInstructions,
|
|
5067
5657
|
postInstructions
|
|
5068
5658
|
} = params;
|
|
5069
|
-
|
|
5659
|
+
const zapOutInstruction = yield this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
|
|
5070
5660
|
userTokenInAccount,
|
|
5071
5661
|
ammProgram
|
|
5072
|
-
}).remainingAccounts(remainingAccounts).
|
|
5662
|
+
}).remainingAccounts(remainingAccounts).instruction();
|
|
5663
|
+
return {
|
|
5664
|
+
instructions: [
|
|
5665
|
+
...preInstructions,
|
|
5666
|
+
zapOutInstruction,
|
|
5667
|
+
...postInstructions
|
|
5668
|
+
],
|
|
5669
|
+
addressLookupTableAccounts: []
|
|
5670
|
+
};
|
|
5073
5671
|
});
|
|
5074
5672
|
}
|
|
5075
5673
|
/**
|
|
@@ -5080,15 +5678,16 @@ var Zap = class {
|
|
|
5080
5678
|
* @param params.user - Public key of the user performing the swap
|
|
5081
5679
|
* @param params.inputMint - Token mint being swapped from
|
|
5082
5680
|
* @param params.outputMint - Token mint being swapped to
|
|
5083
|
-
* @param params.jupiterSwapResponse - Jupiter swap instruction response
|
|
5681
|
+
* @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
5682
|
* @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
|
|
5085
5683
|
* @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
|
|
5086
5684
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5087
5685
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5088
|
-
* @returns
|
|
5686
|
+
* @returns The ordered instructions and the lookup tables of the Jupiter swap
|
|
5089
5687
|
*/
|
|
5090
5688
|
zapOutThroughJupiter(params) {
|
|
5091
5689
|
return __async(this, null, function* () {
|
|
5690
|
+
var _a;
|
|
5092
5691
|
const {
|
|
5093
5692
|
user,
|
|
5094
5693
|
inputMint,
|
|
@@ -5101,29 +5700,21 @@ var Zap = class {
|
|
|
5101
5700
|
} = params;
|
|
5102
5701
|
const preInstructions = [];
|
|
5103
5702
|
const postInstructions = [];
|
|
5104
|
-
const
|
|
5105
|
-
|
|
5106
|
-
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
inputMint,
|
|
5111
|
-
user,
|
|
5112
|
-
user,
|
|
5113
|
-
true,
|
|
5114
|
-
inputTokenProgram
|
|
5115
|
-
),
|
|
5116
|
-
getOrCreateATAInstruction(
|
|
5117
|
-
this.connection,
|
|
5118
|
-
outputMint,
|
|
5119
|
-
user,
|
|
5120
|
-
user,
|
|
5121
|
-
true,
|
|
5122
|
-
outputTokenProgram
|
|
5123
|
-
)
|
|
5703
|
+
const {
|
|
5704
|
+
tokenAccounts: [inputTokenAccount],
|
|
5705
|
+
instructions: createAtaInstructions
|
|
5706
|
+
} = getCreateAtaInstructions(user, [
|
|
5707
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5708
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5124
5709
|
]);
|
|
5125
|
-
|
|
5126
|
-
|
|
5710
|
+
preInstructions.push(...createAtaInstructions);
|
|
5711
|
+
preInstructions.push(
|
|
5712
|
+
...getJupiterCreateAtaInstructions(
|
|
5713
|
+
((_a = jupiterSwapResponse.setupInstructions) != null ? _a : []).map(
|
|
5714
|
+
toTransactionInstruction
|
|
5715
|
+
)
|
|
5716
|
+
)
|
|
5717
|
+
);
|
|
5127
5718
|
let preUserTokenBalance;
|
|
5128
5719
|
try {
|
|
5129
5720
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5147,27 +5738,36 @@ var Zap = class {
|
|
|
5147
5738
|
jupiterSwapResponse.swapInstruction.data,
|
|
5148
5739
|
"base64"
|
|
5149
5740
|
);
|
|
5150
|
-
const offsetAmountIn =
|
|
5741
|
+
const offsetAmountIn = getJupiterInstructionLayout(
|
|
5742
|
+
payloadData
|
|
5743
|
+
).amountInOffset(payloadData.length);
|
|
5151
5744
|
if (inputMint.equals(NATIVE_MINT3) || outputMint.equals(NATIVE_MINT3)) {
|
|
5152
5745
|
const unwrapInstructions = unwrapSOLInstruction(user, user);
|
|
5153
5746
|
if (unwrapInstructions) {
|
|
5154
5747
|
postInstructions.push(unwrapInstructions);
|
|
5155
5748
|
}
|
|
5156
5749
|
}
|
|
5157
|
-
|
|
5158
|
-
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5163
|
-
|
|
5164
|
-
|
|
5165
|
-
|
|
5166
|
-
|
|
5167
|
-
|
|
5168
|
-
|
|
5169
|
-
|
|
5170
|
-
|
|
5750
|
+
const [{ instructions }, addressLookupTableAccounts] = yield Promise.all([
|
|
5751
|
+
this.zapOut({
|
|
5752
|
+
userTokenInAccount: inputTokenAccount,
|
|
5753
|
+
zapOutParams: {
|
|
5754
|
+
percentage: percentageToZapOut,
|
|
5755
|
+
offsetAmountIn,
|
|
5756
|
+
preUserTokenBalance: new BN5(preUserTokenBalance),
|
|
5757
|
+
maxSwapAmount,
|
|
5758
|
+
payloadData
|
|
5759
|
+
},
|
|
5760
|
+
remainingAccounts,
|
|
5761
|
+
ammProgram: JUP_V6_PROGRAM_ID,
|
|
5762
|
+
preInstructions: dedupeCreateAtaInstructions(preInstructions),
|
|
5763
|
+
postInstructions
|
|
5764
|
+
}),
|
|
5765
|
+
getJupiterAddressLookupTableAccounts(
|
|
5766
|
+
this.connection,
|
|
5767
|
+
jupiterSwapResponse
|
|
5768
|
+
)
|
|
5769
|
+
]);
|
|
5770
|
+
return { instructions, addressLookupTableAccounts };
|
|
5171
5771
|
});
|
|
5172
5772
|
}
|
|
5173
5773
|
/**
|
|
@@ -5183,6 +5783,7 @@ var Zap = class {
|
|
|
5183
5783
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5184
5784
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5185
5785
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5786
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5186
5787
|
*/
|
|
5187
5788
|
zapOutThroughDammV2(params) {
|
|
5188
5789
|
return __async(this, null, function* () {
|
|
@@ -5201,29 +5802,14 @@ var Zap = class {
|
|
|
5201
5802
|
const poolState = yield getDammV2Pool(this.connection, poolAddress);
|
|
5202
5803
|
const preInstructions = [];
|
|
5203
5804
|
const postInstructions = [];
|
|
5204
|
-
const
|
|
5205
|
-
|
|
5206
|
-
|
|
5207
|
-
|
|
5208
|
-
|
|
5209
|
-
|
|
5210
|
-
inputMint,
|
|
5211
|
-
user,
|
|
5212
|
-
user,
|
|
5213
|
-
true,
|
|
5214
|
-
inputTokenProgram
|
|
5215
|
-
),
|
|
5216
|
-
getOrCreateATAInstruction(
|
|
5217
|
-
this.connection,
|
|
5218
|
-
outputMint,
|
|
5219
|
-
user,
|
|
5220
|
-
user,
|
|
5221
|
-
true,
|
|
5222
|
-
outputTokenProgram
|
|
5223
|
-
)
|
|
5805
|
+
const {
|
|
5806
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5807
|
+
instructions: createAtaInstructions
|
|
5808
|
+
} = getCreateAtaInstructions(user, [
|
|
5809
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5810
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5224
5811
|
]);
|
|
5225
|
-
|
|
5226
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5812
|
+
preInstructions.push(...createAtaInstructions);
|
|
5227
5813
|
let preUserTokenBalance;
|
|
5228
5814
|
try {
|
|
5229
5815
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5279,6 +5865,7 @@ var Zap = class {
|
|
|
5279
5865
|
* @param params.minimumSwapAmountOut - Minimum amount of output token to receive
|
|
5280
5866
|
* @param params.maxSwapAmount - Maximum amount of input token to swap
|
|
5281
5867
|
* @param params.percentageToZapOut - Percentage of input token to zap out
|
|
5868
|
+
* @returns The ordered instructions, with no lookup tables
|
|
5282
5869
|
*/
|
|
5283
5870
|
zapOutThroughDlmm(params) {
|
|
5284
5871
|
return __async(this, null, function* () {
|
|
@@ -5297,29 +5884,14 @@ var Zap = class {
|
|
|
5297
5884
|
const lbPairState = yield getLbPairState(this.connection, lbPairAddress);
|
|
5298
5885
|
const preInstructions = [];
|
|
5299
5886
|
const postInstructions = [];
|
|
5300
|
-
const
|
|
5301
|
-
|
|
5302
|
-
|
|
5303
|
-
|
|
5304
|
-
|
|
5305
|
-
|
|
5306
|
-
inputMint,
|
|
5307
|
-
user,
|
|
5308
|
-
user,
|
|
5309
|
-
true,
|
|
5310
|
-
inputTokenProgram
|
|
5311
|
-
),
|
|
5312
|
-
getOrCreateATAInstruction(
|
|
5313
|
-
this.connection,
|
|
5314
|
-
outputMint,
|
|
5315
|
-
user,
|
|
5316
|
-
user,
|
|
5317
|
-
true,
|
|
5318
|
-
outputTokenProgram
|
|
5319
|
-
)
|
|
5887
|
+
const {
|
|
5888
|
+
tokenAccounts: [inputTokenAccount, outputTokenAccount],
|
|
5889
|
+
instructions: createAtaInstructions
|
|
5890
|
+
} = getCreateAtaInstructions(user, [
|
|
5891
|
+
{ mint: inputMint, tokenProgram: inputTokenProgram },
|
|
5892
|
+
{ mint: outputMint, tokenProgram: outputTokenProgram }
|
|
5320
5893
|
]);
|
|
5321
|
-
|
|
5322
|
-
outputTokenAccountIx && preInstructions.push(outputTokenAccountIx);
|
|
5894
|
+
preInstructions.push(...createAtaInstructions);
|
|
5323
5895
|
let preUserTokenBalance;
|
|
5324
5896
|
try {
|
|
5325
5897
|
preUserTokenBalance = yield getTokenAccountBalance(
|
|
@@ -5376,12 +5948,14 @@ export {
|
|
|
5376
5948
|
DAMM_V2_PROGRAM_ID,
|
|
5377
5949
|
DAMM_V2_SWAP_DISCRIMINATOR,
|
|
5378
5950
|
DEFAULT_JUPITER_API_URL,
|
|
5951
|
+
DEFAULT_JUPITER_API_VERSION,
|
|
5379
5952
|
DLMM_PROGRAM_ID,
|
|
5380
5953
|
DLMM_SWAP_DISCRIMINATOR,
|
|
5381
5954
|
DlmmDirectSwapQuoteRoute,
|
|
5382
5955
|
DlmmSingleSided,
|
|
5383
5956
|
DlmmSwapType,
|
|
5384
5957
|
JUP_V6_PROGRAM_ID,
|
|
5958
|
+
JupiterApiVersion,
|
|
5385
5959
|
MEMO_PROGRAM_ID,
|
|
5386
5960
|
SwapExternalType,
|
|
5387
5961
|
ZAP_PROGRAM_ID,
|