@meteora-ag/zap-sdk 1.3.1 → 2.0.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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 "@coral-xyz/anchor";
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.0",
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: [189, 122, 172, 13, 122, 54, 54, 51],
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: ["ledger"]
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: [120, 69, 30, 74, 76, 242, 153, 162],
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: [117, 115, 101, 114, 95, 108, 101, 100, 103, 101, 114]
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: [131, 49, 240, 17, 228, 248, 156, 54],
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: ["ledger"]
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: [59, 206, 173, 232, 94, 57, 174, 202],
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: ["ledger"]
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: [243, 243, 119, 52, 199, 44, 154, 186],
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: ["owner of position"],
282
+ docs: [
283
+ "owner of position"
284
+ ],
222
285
  signer: true,
223
- relations: ["ledger"]
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: [184, 71, 198, 231, 129, 110, 193, 67],
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: ["lb pair"],
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: ["owner of position"],
376
+ docs: [
377
+ "owner of position"
378
+ ],
301
379
  signer: true,
302
- relations: ["ledger"]
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: [59, 220, 182, 27, 254, 253, 2, 232],
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: ["lb pair"],
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: ["owner of position"],
510
+ docs: [
511
+ "owner of position"
512
+ ],
420
513
  signer: true,
421
- relations: ["ledger"]
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: [155, 108, 185, 112, 104, 210, 161, 64],
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: [185, 84, 101, 128, 8, 6, 160, 83]
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: ["u8"]
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: "BaseFeeStruct",
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: "cliff_fee_numerator",
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: ["u8", 5]
712
+ array: [
713
+ "u8",
714
+ 32
715
+ ]
614
716
  }
615
- },
616
- {
617
- name: "first_factor",
618
- type: "u16"
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: "second_factor",
731
+ name: "base_fee_info",
622
732
  type: {
623
- array: ["u8", 8]
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: ["u8", 7]
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: ["u8", 1]
842
+ array: [
843
+ "u8",
844
+ 1
845
+ ]
732
846
  }
733
847
  },
734
848
  {
735
849
  name: "bin_step_seed",
736
850
  type: {
737
- array: ["u8", 2]
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: ["u8", 2]
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: ["u8", 32]
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: ["u64", 16]
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: ["u8", 32]
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: ["u8", 8]
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: ["u8", 22]
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: ["Pool fee"],
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: ["token a mint"],
1045
+ docs: [
1046
+ "token a mint"
1047
+ ],
905
1048
  type: "pubkey"
906
1049
  },
907
1050
  {
908
1051
  name: "token_b_mint",
909
- docs: ["token b mint"],
1052
+ docs: [
1053
+ "token b mint"
1054
+ ],
910
1055
  type: "pubkey"
911
1056
  },
912
1057
  {
913
1058
  name: "token_a_vault",
914
- docs: ["token a vault"],
1059
+ docs: [
1060
+ "token a vault"
1061
+ ],
915
1062
  type: "pubkey"
916
1063
  },
917
1064
  {
918
1065
  name: "token_b_vault",
919
- docs: ["token b vault"],
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: "partner",
931
- docs: ["partner"],
932
- type: "pubkey"
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: ["liquidity share"],
1092
+ docs: [
1093
+ "liquidity share"
1094
+ ],
937
1095
  type: "u128"
938
1096
  },
939
1097
  {
940
- name: "_padding",
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: ["protocol a fee"],
1106
+ docs: [
1107
+ "protocol a fee"
1108
+ ],
949
1109
  type: "u64"
950
1110
  },
951
1111
  {
952
1112
  name: "protocol_b_fee",
953
- docs: ["protocol b fee"],
954
- type: "u64"
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: "partner_b_fee",
963
- docs: ["partner b fee"],
964
- type: "u64"
1119
+ name: "padding_2",
1120
+ type: "u128"
965
1121
  },
966
1122
  {
967
1123
  name: "sqrt_min_price",
968
- docs: ["min price"],
1124
+ docs: [
1125
+ "min price"
1126
+ ],
969
1127
  type: "u128"
970
1128
  },
971
1129
  {
972
1130
  name: "sqrt_max_price",
973
- docs: ["max price"],
1131
+ docs: [
1132
+ "max price"
1133
+ ],
974
1134
  type: "u128"
975
1135
  },
976
1136
  {
977
1137
  name: "sqrt_price",
978
- docs: ["current price"],
1138
+ docs: [
1139
+ "current price"
1140
+ ],
979
1141
  type: "u128"
980
1142
  },
981
1143
  {
982
1144
  name: "activation_point",
983
- docs: ["Activation point, can be slot or timestamp"],
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: ["Activation type, 0 means by slot, 1 means by timestamp"],
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: ["pool status, 0: enable, 1 disable"],
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: ["token a flag"],
1166
+ docs: [
1167
+ "token a flag"
1168
+ ],
999
1169
  type: "u8"
1000
1170
  },
1001
1171
  {
1002
1172
  name: "token_b_flag",
1003
- docs: ["token b flag"],
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 in token a, 2 only collect fee in token b"
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: ["pool type"],
1187
+ docs: [
1188
+ "pool type"
1189
+ ],
1016
1190
  type: "u8"
1017
1191
  },
1018
1192
  {
1019
- name: "version",
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: "_padding_0",
1027
- docs: ["padding"],
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: ["cumulative"],
1208
+ docs: [
1209
+ "cumulative"
1210
+ ],
1033
1211
  type: {
1034
- array: ["u8", 32]
1212
+ array: [
1213
+ "u8",
1214
+ 32
1215
+ ]
1035
1216
  }
1036
1217
  },
1037
1218
  {
1038
1219
  name: "fee_b_per_liquidity",
1039
- docs: ["cumulative"],
1220
+ docs: [
1221
+ "cumulative"
1222
+ ],
1040
1223
  type: {
1041
- array: ["u8", 32]
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: ["metrics"],
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: ["pool creator"],
1247
+ docs: [
1248
+ "pool creator"
1249
+ ],
1060
1250
  type: "pubkey"
1061
1251
  },
1062
1252
  {
1063
- name: "_padding_1",
1064
- docs: ["Padding for further use"],
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: ["u64", 6]
1291
+ array: [
1292
+ "u64",
1293
+ 3
1294
+ ]
1067
1295
  }
1068
1296
  },
1069
1297
  {
1070
1298
  name: "reward_infos",
1071
- docs: ["Farming reward information"],
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: "partner_fee_percent",
1127
- docs: ["partner fee"],
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: ["referral fee"],
1363
+ docs: [
1364
+ "referral fee"
1365
+ ],
1133
1366
  type: "u8"
1134
1367
  },
1135
1368
  {
1136
- name: "padding_0",
1137
- docs: ["padding"],
1369
+ name: "padding_1",
1370
+ docs: [
1371
+ "padding"
1372
+ ],
1138
1373
  type: {
1139
- array: ["u8", 5]
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: ["dynamic fee"],
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: "padding_1",
1153
- docs: ["padding"],
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: "total_partner_a_fee",
1188
- type: "u64"
1189
- },
1190
- {
1191
- name: "total_partner_b_fee",
1192
- type: "u64"
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: ["Parameter that set by the protocol"],
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: ["u8", 5]
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: ["Parameters that changes based on dynamic of the market"],
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: ["u8", 4]
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: ["u8", 8]
1661
+ array: [
1662
+ "u8",
1663
+ 8
1664
+ ]
1399
1665
  }
1400
1666
  }
1401
1667
  ]
@@ -1443,70 +1709,96 @@ var idl_default = {
1443
1709
  fields: [
1444
1710
  {
1445
1711
  name: "initialized",
1446
- docs: ["Indicates if the reward has been initialized"],
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: ["reward token flag"],
1719
+ docs: [
1720
+ "reward token flag"
1721
+ ],
1452
1722
  type: "u8"
1453
1723
  },
1454
1724
  {
1455
1725
  name: "_padding_0",
1456
- docs: ["padding"],
1726
+ docs: [
1727
+ "padding"
1728
+ ],
1457
1729
  type: {
1458
- array: ["u8", 6]
1730
+ array: [
1731
+ "u8",
1732
+ 6
1733
+ ]
1459
1734
  }
1460
1735
  },
1461
1736
  {
1462
- name: "_padding_1",
1737
+ name: "dead_liquidity_reward_checkpoint",
1463
1738
  docs: [
1464
- "Padding to ensure `reward_rate: u128` is 16-byte aligned"
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: ["Reward token mint."],
1745
+ docs: [
1746
+ "Reward token mint."
1747
+ ],
1473
1748
  type: "pubkey"
1474
1749
  },
1475
1750
  {
1476
1751
  name: "vault",
1477
- docs: ["Reward vault token account."],
1752
+ docs: [
1753
+ "Reward vault token account."
1754
+ ],
1478
1755
  type: "pubkey"
1479
1756
  },
1480
1757
  {
1481
1758
  name: "funder",
1482
- docs: ["Authority account that allows to fund rewards"],
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: ["reward duration"],
1766
+ docs: [
1767
+ "reward duration"
1768
+ ],
1488
1769
  type: "u64"
1489
1770
  },
1490
1771
  {
1491
1772
  name: "reward_duration_end",
1492
- docs: ["reward duration end"],
1773
+ docs: [
1774
+ "reward duration end"
1775
+ ],
1493
1776
  type: "u64"
1494
1777
  },
1495
1778
  {
1496
1779
  name: "reward_rate",
1497
- docs: ["reward rate"],
1780
+ docs: [
1781
+ "reward rate"
1782
+ ],
1498
1783
  type: "u128"
1499
1784
  },
1500
1785
  {
1501
1786
  name: "reward_per_token_stored",
1502
- docs: ["Reward per token stored"],
1787
+ docs: [
1788
+ "Reward per token stored"
1789
+ ],
1503
1790
  type: {
1504
- array: ["u8", 32]
1791
+ array: [
1792
+ "u8",
1793
+ 32
1794
+ ]
1505
1795
  }
1506
1796
  },
1507
1797
  {
1508
1798
  name: "last_update_time",
1509
- docs: ["The last time reward states were updated."],
1799
+ docs: [
1800
+ "The last time reward states were updated."
1801
+ ],
1510
1802
  type: "u64"
1511
1803
  },
1512
1804
  {
@@ -1569,44 +1861,6 @@ var idl_default = {
1569
1861
  }
1570
1862
  ],
1571
1863
  constants: [
1572
- {
1573
- name: "DAMM_V2",
1574
- type: "pubkey",
1575
- value: "cpamdpZCGKUy5JxQXB4dcpGPiikHawvSWAd6mEn1sGG"
1576
- },
1577
- {
1578
- name: "DAMM_V2_SWAP_DISC",
1579
- type: {
1580
- array: ["u8", 8]
1581
- },
1582
- value: "[248, 198, 158, 145, 225, 117, 135, 200]"
1583
- },
1584
- {
1585
- name: "DLMM_SWAP2_DISC",
1586
- type: {
1587
- array: ["u8", 8]
1588
- },
1589
- value: "[65, 75, 63, 76, 235, 91, 91, 136]"
1590
- },
1591
- {
1592
- name: "JUP_V6",
1593
- type: "pubkey",
1594
- value: "JUP6LkbZbjS1jKKwapdHNy74zcZ3tLUZoi5QNyVTaV4"
1595
- },
1596
- {
1597
- name: "JUP_V6_ROUTE_DISC",
1598
- type: {
1599
- array: ["u8", 8]
1600
- },
1601
- value: "[229, 23, 203, 151, 122, 227, 173, 42]"
1602
- },
1603
- {
1604
- name: "JUP_V6_SHARED_ACCOUNT_ROUTE_DISC",
1605
- type: {
1606
- array: ["u8", 8]
1607
- },
1608
- value: "[193, 32, 155, 51, 65, 214, 156, 129]"
1609
- },
1610
1864
  {
1611
1865
  name: "MAX_BASIS_POINT",
1612
1866
  type: "u16",
@@ -1621,6 +1875,11 @@ var idl_default = {
1621
1875
  };
1622
1876
 
1623
1877
  // src/types.ts
1878
+ var JupiterApiVersion = /* @__PURE__ */ ((JupiterApiVersion3) => {
1879
+ JupiterApiVersion3["V1"] = "v1";
1880
+ JupiterApiVersion3["V2"] = "v2";
1881
+ return JupiterApiVersion3;
1882
+ })(JupiterApiVersion || {});
1624
1883
  var ZapInDammV2PoolSwapRoute = /* @__PURE__ */ ((ZapInDammV2PoolSwapRoute2) => {
1625
1884
  ZapInDammV2PoolSwapRoute2["Jupiter"] = "jupiter";
1626
1885
  ZapInDammV2PoolSwapRoute2["DammV2"] = "dammV2";
@@ -1651,8 +1910,9 @@ var DlmmSingleSided = /* @__PURE__ */ ((DlmmSingleSided2) => {
1651
1910
 
1652
1911
  // src/helpers/jupiter.ts
1653
1912
  import {
1913
+ AddressLookupTableAccount,
1914
+ AddressLookupTableProgram,
1654
1915
  PublicKey as PublicKey2,
1655
- Transaction,
1656
1916
  TransactionInstruction
1657
1917
  } from "@solana/web3.js";
1658
1918
 
@@ -1698,6 +1958,68 @@ var AccountsType = {
1698
1958
  var DLMM_SWAP_DISCRIMINATOR = [65, 75, 63, 76, 235, 91, 91, 136];
1699
1959
  var AMOUNT_IN_DLMM_OFFSET = 8;
1700
1960
  var AMOUNT_IN_JUP_V6_REVERSE_OFFSET = 19;
1961
+ var JUP_V6_ROUTE_DISCRIMINATOR = [
1962
+ 229,
1963
+ 23,
1964
+ 203,
1965
+ 151,
1966
+ 122,
1967
+ 227,
1968
+ 173,
1969
+ 42
1970
+ ];
1971
+ var JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR = [
1972
+ 193,
1973
+ 32,
1974
+ 155,
1975
+ 51,
1976
+ 65,
1977
+ 214,
1978
+ 156,
1979
+ 129
1980
+ ];
1981
+ var JUP_V6_ROUTE_V2_DISCRIMINATOR = [
1982
+ 187,
1983
+ 100,
1984
+ 250,
1985
+ 204,
1986
+ 49,
1987
+ 196,
1988
+ 175,
1989
+ 20
1990
+ ];
1991
+ var JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR = [
1992
+ 209,
1993
+ 152,
1994
+ 83,
1995
+ 147,
1996
+ 124,
1997
+ 254,
1998
+ 216,
1999
+ 233
2000
+ ];
2001
+ var JUPITER_INSTRUCTION_LAYOUTS = {
2002
+ // route
2003
+ [Buffer.from(JUP_V6_ROUTE_DISCRIMINATOR).toString("hex")]: {
2004
+ amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
2005
+ userTransferAuthorityIndex: 1
2006
+ },
2007
+ // shared_accounts_route
2008
+ [Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR).toString("hex")]: {
2009
+ amountInOffset: (dataLength) => dataLength - AMOUNT_IN_JUP_V6_REVERSE_OFFSET,
2010
+ userTransferAuthorityIndex: 2
2011
+ },
2012
+ // route_v2
2013
+ [Buffer.from(JUP_V6_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
2014
+ amountInOffset: () => 8,
2015
+ userTransferAuthorityIndex: 0
2016
+ },
2017
+ // shared_accounts_route_v2
2018
+ [Buffer.from(JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR).toString("hex")]: {
2019
+ amountInOffset: () => 9,
2020
+ userTransferAuthorityIndex: 1
2021
+ }
2022
+ };
1701
2023
  var AMOUNT_IN_DAMM_V2_OFFSET = 8;
1702
2024
  var DAMM_V2_SWAP_DISCRIMINATOR = [
1703
2025
  248,
@@ -1710,41 +2032,132 @@ var DAMM_V2_SWAP_DISCRIMINATOR = [
1710
2032
  200
1711
2033
  ];
1712
2034
  var DEFAULT_JUPITER_API_URL = "https://api.jup.ag";
2035
+ var DEFAULT_JUPITER_API_VERSION = "v2" /* V2 */;
2036
+ var DEFAULT_JUPITER_QUOTE_OPTIONS = {
2037
+ dynamicSlippage: false,
2038
+ onlyDirectRoutes: true,
2039
+ restrictIntermediateTokens: true,
2040
+ forJitoBundle: true
2041
+ };
1713
2042
 
1714
2043
  // src/helpers/jupiter.ts
1715
- function getJupiterQuote(_0, _1, _2, _3, _4) {
1716
- return __async(this, arguments, function* (inputMint, outputMint, amount, maxAccounts, slippageBps, dynamicSlippage = false, onlyDirectRoutes, restrictIntermediateTokens, config = {}) {
1717
- const params = new URLSearchParams({
1718
- inputMint: inputMint.toString(),
1719
- outputMint: outputMint.toString(),
1720
- amount: amount.toString(),
1721
- slippageBps: slippageBps.toString(),
1722
- maxAccounts: maxAccounts.toString(),
1723
- onlyDirectRoutes: onlyDirectRoutes.toString(),
1724
- restrictIntermediateTokens: restrictIntermediateTokens.toString(),
1725
- dynamicSlippage: dynamicSlippage.toString()
1726
- });
1727
- const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/quote?${params.toString()}`;
2044
+ function resolveJupiterConfig(config = {}) {
2045
+ var _a;
2046
+ return {
2047
+ url: config.jupiterApiUrl || DEFAULT_JUPITER_API_URL,
2048
+ apiKey: config.jupiterApiKey || "",
2049
+ version: (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION
2050
+ };
2051
+ }
2052
+ function getJupiterInstructionLayout(data) {
2053
+ const discriminator = data.subarray(0, 8).toString("hex");
2054
+ const layout = JUPITER_INSTRUCTION_LAYOUTS[discriminator];
2055
+ if (!layout) {
2056
+ throw new Error(
2057
+ `Unsupported Jupiter instruction discriminator ${discriminator}`
2058
+ );
2059
+ }
2060
+ return layout;
2061
+ }
2062
+ function isJupiterBuildResponse(quoteResponse) {
2063
+ return quoteResponse.swapInstruction !== void 0;
2064
+ }
2065
+ function isJupiterSwapInstructionForUser(swapInstruction, user) {
2066
+ const layout = getJupiterInstructionLayout(
2067
+ Buffer.from(swapInstruction.data, "base64")
2068
+ );
2069
+ const authority = swapInstruction.accounts[layout.userTransferAuthorityIndex];
2070
+ return authority !== void 0 && new PublicKey2(authority.pubkey).equals(user);
2071
+ }
2072
+ function jupiterHeaders(apiKey, json) {
2073
+ return __spreadValues(__spreadValues({
2074
+ Accept: "application/json"
2075
+ }, json ? { "Content-Type": "application/json" } : {}), apiKey ? { "x-api-key": apiKey } : {});
2076
+ }
2077
+ function toSearchParams(query) {
2078
+ var _a;
2079
+ const params = new URLSearchParams(__spreadProps(__spreadValues({
2080
+ inputMint: query.inputMint.toString(),
2081
+ outputMint: query.outputMint.toString(),
2082
+ amount: query.amount,
2083
+ slippageBps: query.slippageBps.toString()
2084
+ }, query.maxAccounts !== void 0 ? { maxAccounts: query.maxAccounts.toString() } : {}), {
2085
+ onlyDirectRoutes: query.onlyDirectRoutes.toString(),
2086
+ restrictIntermediateTokens: query.restrictIntermediateTokens.toString(),
2087
+ dynamicSlippage: query.dynamicSlippage.toString(),
2088
+ forJitoBundle: query.forJitoBundle.toString()
2089
+ }));
2090
+ for (const [name, value] of Object.entries(
2091
+ (_a = query.additionalQueryParams) != null ? _a : {}
2092
+ )) {
2093
+ params.set(name, value);
2094
+ }
2095
+ return params;
2096
+ }
2097
+ function fetchJupiterQuoteV1(query, config) {
2098
+ return __async(this, null, function* () {
2099
+ const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
2100
+ const url = `${baseUrl}/swap/v1/quote?${toSearchParams(query).toString()}`;
1728
2101
  try {
1729
2102
  const response = yield fetch(url, {
1730
2103
  method: "GET",
1731
- headers: __spreadValues({
1732
- Accept: "application/json"
1733
- }, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {})
2104
+ headers: jupiterHeaders(apiKey, false)
1734
2105
  });
1735
2106
  if (!response.ok) {
1736
2107
  return null;
1737
2108
  }
1738
- const result = yield response.json();
1739
- return result;
2109
+ return yield response.json();
1740
2110
  } catch (error) {
1741
2111
  return null;
1742
2112
  }
1743
2113
  });
1744
2114
  }
1745
- function getJupiterSwapInstruction(_0, _1) {
1746
- return __async(this, arguments, function* (userPublicKey, quoteResponse, config = {}) {
1747
- const url = `${config.jupiterApiUrl || DEFAULT_JUPITER_API_URL}/swap/v1/swap-instructions`;
2115
+ function fetchJupiterBuildV2(query, taker, config) {
2116
+ return __async(this, null, function* () {
2117
+ const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
2118
+ const params = toSearchParams(query);
2119
+ params.set("taker", taker.toString());
2120
+ const url = `${baseUrl}/swap/v2/build?${params.toString()}`;
2121
+ try {
2122
+ const response = yield fetch(url, {
2123
+ method: "GET",
2124
+ headers: jupiterHeaders(apiKey, false)
2125
+ });
2126
+ if (!response.ok) {
2127
+ return null;
2128
+ }
2129
+ return yield response.json();
2130
+ } catch (error) {
2131
+ return null;
2132
+ }
2133
+ });
2134
+ }
2135
+ function getJupiterQuote(_0) {
2136
+ return __async(this, arguments, function* (params, config = {}) {
2137
+ var _a, _b, _c, _d;
2138
+ const query = {
2139
+ inputMint: params.inputMint,
2140
+ outputMint: params.outputMint,
2141
+ amount: params.amount.toString(),
2142
+ slippageBps: params.slippageBps,
2143
+ maxAccounts: params.maxAccounts,
2144
+ dynamicSlippage: (_a = params.dynamicSlippage) != null ? _a : DEFAULT_JUPITER_QUOTE_OPTIONS.dynamicSlippage,
2145
+ onlyDirectRoutes: (_b = params.onlyDirectRoutes) != null ? _b : DEFAULT_JUPITER_QUOTE_OPTIONS.onlyDirectRoutes,
2146
+ restrictIntermediateTokens: (_c = params.restrictIntermediateTokens) != null ? _c : DEFAULT_JUPITER_QUOTE_OPTIONS.restrictIntermediateTokens,
2147
+ forJitoBundle: (_d = params.forJitoBundle) != null ? _d : DEFAULT_JUPITER_QUOTE_OPTIONS.forJitoBundle,
2148
+ additionalQueryParams: params.additionalQueryParams
2149
+ };
2150
+ const { version } = resolveJupiterConfig(config);
2151
+ if (version === "v1" /* V1 */) {
2152
+ return fetchJupiterQuoteV1(query, config);
2153
+ }
2154
+ return fetchJupiterBuildV2(query, params.user, config);
2155
+ });
2156
+ }
2157
+ function fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config) {
2158
+ return __async(this, null, function* () {
2159
+ const { url: baseUrl, apiKey } = resolveJupiterConfig(config);
2160
+ const url = `${baseUrl}/swap/v1/swap-instructions`;
1748
2161
  const requestBody = {
1749
2162
  userPublicKey: userPublicKey.toString(),
1750
2163
  quoteResponse
@@ -1753,10 +2166,7 @@ function getJupiterSwapInstruction(_0, _1) {
1753
2166
  try {
1754
2167
  response = yield fetch(url, {
1755
2168
  method: "POST",
1756
- headers: __spreadValues({
1757
- "Content-Type": "application/json",
1758
- Accept: "application/json"
1759
- }, config.jupiterApiKey ? { "x-api-key": config.jupiterApiKey } : {}),
2169
+ headers: jupiterHeaders(apiKey, true),
1760
2170
  body: JSON.stringify(requestBody)
1761
2171
  });
1762
2172
  if (!response.ok) {
@@ -1768,21 +2178,111 @@ function getJupiterSwapInstruction(_0, _1) {
1768
2178
  } catch (error) {
1769
2179
  throw new Error(`Jupiter swap instruction failed to fetch`);
1770
2180
  }
1771
- const result = yield response.json();
1772
- return result;
2181
+ return yield response.json();
1773
2182
  });
1774
2183
  }
1775
- function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1776
- return __async(this, arguments, function* (user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}) {
2184
+ function getJupiterSwapInstruction(_0, _1) {
2185
+ return __async(this, arguments, function* (userPublicKey, quoteResponse, config = {}) {
2186
+ const { version } = resolveJupiterConfig(config);
2187
+ if (version === "v1" /* V1 */) {
2188
+ return fetchJupiterSwapInstructionV1(userPublicKey, quoteResponse, config);
2189
+ }
2190
+ if (!isJupiterBuildResponse(quoteResponse)) {
2191
+ throw new Error(
2192
+ "Jupiter quote has no swap instructions, get the quote with getJupiterQuote under Jupiter API v2"
2193
+ );
2194
+ }
2195
+ if (!isJupiterSwapInstructionForUser(
2196
+ quoteResponse.swapInstruction,
2197
+ userPublicKey
2198
+ )) {
2199
+ throw new Error(
2200
+ `Jupiter quote swap instructions are not built for ${userPublicKey.toBase58()}`
2201
+ );
2202
+ }
2203
+ return quoteResponse;
2204
+ });
2205
+ }
2206
+ function isQuoteMatchesSwap(quoteResponse, user, amount) {
2207
+ if (quoteResponse.inAmount !== amount.toString()) {
2208
+ return false;
2209
+ }
2210
+ if (isJupiterBuildResponse(quoteResponse)) {
2211
+ return isJupiterSwapInstructionForUser(quoteResponse.swapInstruction, user);
2212
+ }
2213
+ return true;
2214
+ }
2215
+ var ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT = BigInt("0xffffffffffffffff");
2216
+ function toAddressLookupTableAccounts(addressesByLookupTableAddress) {
2217
+ return Object.entries(addressesByLookupTableAddress != null ? addressesByLookupTableAddress : {}).map(
2218
+ ([key, addresses]) => new AddressLookupTableAccount({
2219
+ key: new PublicKey2(key),
2220
+ state: {
2221
+ addresses: addresses.map((address) => new PublicKey2(address)),
2222
+ deactivationSlot: ACTIVE_LOOKUP_TABLE_DEACTIVATION_SLOT,
2223
+ lastExtendedSlot: 0,
2224
+ lastExtendedSlotStartIndex: 0
2225
+ }
2226
+ })
2227
+ );
2228
+ }
2229
+ function fetchAddressLookupTableAccounts(connection, addresses) {
2230
+ return __async(this, null, function* () {
2231
+ if (addresses.length === 0) {
2232
+ return [];
2233
+ }
2234
+ const keys = addresses.map((address) => new PublicKey2(address));
2235
+ const accounts = yield connection.getMultipleAccountsInfo(keys);
2236
+ return keys.map((key, i) => {
2237
+ const account = accounts[i];
2238
+ if (!account || !account.owner.equals(AddressLookupTableProgram.programId)) {
2239
+ throw new Error(`Address lookup table not found: ${key.toBase58()}`);
2240
+ }
2241
+ return new AddressLookupTableAccount({
2242
+ key,
2243
+ state: AddressLookupTableAccount.deserialize(account.data)
2244
+ });
2245
+ });
2246
+ });
2247
+ }
2248
+ function mergeAddressLookupTableAccounts(...lists) {
2249
+ const merged = /* @__PURE__ */ new Map();
2250
+ for (const table of lists.flat()) {
2251
+ const key = table.key.toBase58();
2252
+ if (!merged.has(key)) {
2253
+ merged.set(key, table);
2254
+ }
2255
+ }
2256
+ return [...merged.values()];
2257
+ }
2258
+ function getJupiterAddressLookupTableAccounts(connection, response) {
2259
+ return __async(this, null, function* () {
2260
+ var _a;
2261
+ if (response.addressesByLookupTableAddress) {
2262
+ return toAddressLookupTableAccounts(response.addressesByLookupTableAddress);
2263
+ }
2264
+ return fetchAddressLookupTableAccounts(
2265
+ connection,
2266
+ (_a = response.addressLookupTableAddresses) != null ? _a : []
2267
+ );
2268
+ });
2269
+ }
2270
+ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6, _7) {
2271
+ return __async(this, arguments, function* (connection, user, inputMint, outputMint, amount, maxAccounts, slippageBps, jupiterQuoteResponse, config = {}, jupiterQuoteOptions = {}) {
2272
+ if (jupiterQuoteResponse && !isQuoteMatchesSwap(jupiterQuoteResponse, user, amount)) {
2273
+ throw new Error(
2274
+ `Jupiter quote does not match the swap of ${amount.toString()} by ${user.toBase58()} (quoted inAmount ${jupiterQuoteResponse.inAmount})`
2275
+ );
2276
+ }
1777
2277
  const quoteResponse = jupiterQuoteResponse != null ? jupiterQuoteResponse : yield getJupiterQuote(
1778
- inputMint,
1779
- outputMint,
1780
- amount,
1781
- maxAccounts,
1782
- slippageBps,
1783
- false,
1784
- true,
1785
- true,
2278
+ __spreadValues({
2279
+ inputMint,
2280
+ outputMint,
2281
+ amount,
2282
+ user,
2283
+ maxAccounts,
2284
+ slippageBps
2285
+ }, jupiterQuoteOptions),
1786
2286
  config
1787
2287
  );
1788
2288
  if (!quoteResponse) {
@@ -1806,7 +2306,11 @@ function buildJupiterSwapTransaction(_0, _1, _2, _3, _4, _5, _6) {
1806
2306
  programId: new PublicKey2(swapInstructionResponse.swapInstruction.programId),
1807
2307
  data: Buffer.from(swapInstructionResponse.swapInstruction.data, "base64")
1808
2308
  });
1809
- return { transaction: new Transaction().add(instruction), quoteResponse };
2309
+ const addressLookupTableAccounts = yield getJupiterAddressLookupTableAccounts(
2310
+ connection,
2311
+ swapInstructionResponse
2312
+ );
2313
+ return { instruction, addressLookupTableAccounts, quoteResponse };
1810
2314
  });
1811
2315
  }
1812
2316
 
@@ -1944,11 +2448,11 @@ function createDammV2SwapPayload(amountIn, minimumSwapAmountOut) {
1944
2448
  }
1945
2449
 
1946
2450
  // src/helpers/common.ts
2451
+ import { NATIVE_MINT, TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2 } from "@solana/spl-token";
1947
2452
  import {
1948
- NATIVE_MINT,
1949
- TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID2
1950
- } from "@solana/spl-token";
1951
- import { PublicKey as PublicKey4 } from "@solana/web3.js";
2453
+ ComputeBudgetProgram,
2454
+ PublicKey as PublicKey4
2455
+ } from "@solana/web3.js";
1952
2456
  import Decimal from "decimal.js";
1953
2457
  function getTokenProgramFromMint(connection, mint) {
1954
2458
  return __async(this, null, function* () {
@@ -1982,6 +2486,11 @@ function convertLamportsToUiAmount(amount, decimals) {
1982
2486
  function convertUiAmountToLamports(amount, decimals) {
1983
2487
  return amount.mul(Decimal.pow(10, decimals));
1984
2488
  }
2489
+ function filterOutComputeBudgetInstructions(instructions) {
2490
+ return instructions.filter(
2491
+ (ix) => !ix.programId.equals(ComputeBudgetProgram.programId)
2492
+ );
2493
+ }
1985
2494
 
1986
2495
  // src/helpers/token.ts
1987
2496
  import {
@@ -1993,9 +2502,9 @@ import {
1993
2502
  } from "@solana/spl-token";
1994
2503
  import {
1995
2504
  SystemProgram,
1996
- TransactionInstruction as TransactionInstruction2
2505
+ TransactionInstruction as TransactionInstruction3
1997
2506
  } from "@solana/web3.js";
1998
- var getOrCreateATAInstruction = (connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
2507
+ var getOrCreateATAInstruction = (_connection, tokenMint, owner, payer, allowOwnerOffCurve = true, tokenProgram) => __async(null, null, function* () {
1999
2508
  const toAccount = getAssociatedTokenAddressSync(
2000
2509
  tokenMint,
2001
2510
  owner,
@@ -2047,7 +2556,7 @@ function wrapSOLInstruction(from, to, amount, tokenProgram = TOKEN_PROGRAM_ID3)
2047
2556
  toPubkey: to,
2048
2557
  lamports: amount
2049
2558
  }),
2050
- new TransactionInstruction2({
2559
+ new TransactionInstruction3({
2051
2560
  keys: [
2052
2561
  {
2053
2562
  pubkey: to,
@@ -2087,7 +2596,7 @@ import DLMM, {
2087
2596
  import {
2088
2597
  createTransferCheckedWithTransferHookInstruction,
2089
2598
  getTransferHook,
2090
- TOKEN_2022_PROGRAM_ID as TOKEN_2022_PROGRAM_ID2,
2599
+ TOKEN_2022_PROGRAM_ID,
2091
2600
  TOKEN_PROGRAM_ID as TOKEN_PROGRAM_ID4,
2092
2601
  unpackMint
2093
2602
  } from "@solana/spl-token";
@@ -2107,7 +2616,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
2107
2616
  const mintInfo = unpackMint(
2108
2617
  mint,
2109
2618
  accountInfoWithBuffer,
2110
- TOKEN_2022_PROGRAM_ID2
2619
+ TOKEN_2022_PROGRAM_ID
2111
2620
  );
2112
2621
  const transferHook = getTransferHook(mintInfo);
2113
2622
  if (!transferHook) {
@@ -2123,7 +2632,7 @@ function getExtraAccountMetasForTransferHook(connection, mint) {
2123
2632
  mintInfo.decimals,
2124
2633
  [],
2125
2634
  "confirmed",
2126
- TOKEN_2022_PROGRAM_ID2
2635
+ TOKEN_2022_PROGRAM_ID
2127
2636
  );
2128
2637
  return (yield transferWithHookIx).keys.slice(4);
2129
2638
  }
@@ -2447,8 +2956,8 @@ function estimateSwapOutput(inAmount, effectiveRate) {
2447
2956
  const estimatedOutput = inAmountDecimal.mul(effectiveRate);
2448
2957
  return new BN3(estimatedOutput.floor().toString());
2449
2958
  }
2450
- function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
2451
- return __async(this, arguments, function* (dlmm, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}) {
2959
+ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6, _7) {
2960
+ return __async(this, arguments, function* (dlmm, user, inMint, outMint, inAmount, swapSlippageBps, swapForY, binArrays, config = {}, jupiterQuoteOptions = {}) {
2452
2961
  let dlmmQuoteResult = null;
2453
2962
  try {
2454
2963
  dlmmQuoteResult = dlmm.swapQuote(
@@ -2461,14 +2970,14 @@ function getBestSwapQuoteJupiterDlmm(_0, _1, _2, _3, _4, _5, _6) {
2461
2970
  console.error("Error getting DLMM quote, using jupiter quote only:", error);
2462
2971
  }
2463
2972
  const jupiterQuoteResult = yield getJupiterQuote(
2464
- inMint,
2465
- outMint,
2466
- inAmount,
2467
- 50,
2468
- swapSlippageBps,
2469
- false,
2470
- true,
2471
- true,
2973
+ __spreadValues({
2974
+ inputMint: inMint,
2975
+ outputMint: outMint,
2976
+ amount: inAmount,
2977
+ user,
2978
+ maxAccounts: 50,
2979
+ slippageBps: swapSlippageBps
2980
+ }, jupiterQuoteOptions),
2472
2981
  config
2473
2982
  );
2474
2983
  const jupiterQuote = jupiterQuoteResult ? {
@@ -2584,6 +3093,7 @@ function binarySearchRefineDirectSwapAmount(dlmm, initialActiveBin, initialMinBi
2584
3093
  }
2585
3094
  function estimateDlmmIndirectSwap(_0) {
2586
3095
  return __async(this, arguments, function* ({
3096
+ user,
2587
3097
  amountIn,
2588
3098
  inputTokenMint,
2589
3099
  lbPair,
@@ -2593,6 +3103,7 @@ function estimateDlmmIndirectSwap(_0) {
2593
3103
  maxDeltaId,
2594
3104
  strategy,
2595
3105
  singleSided,
3106
+ jupiterQuoteOptions,
2596
3107
  config = {}
2597
3108
  }) {
2598
3109
  const dlmm = yield DLMM2.create(connection, lbPair);
@@ -2617,14 +3128,14 @@ function estimateDlmmIndirectSwap(_0) {
2617
3128
  const singleSidedX = singleSided === 0 /* X */;
2618
3129
  const outputTokenMint = singleSidedX ? tokenXMint : tokenYMint;
2619
3130
  const quote = yield getJupiterQuote(
2620
- inputTokenMint,
2621
- outputTokenMint,
2622
- amountIn,
2623
- 50,
2624
- swapSlippageBps,
2625
- false,
2626
- true,
2627
- true,
3131
+ __spreadValues({
3132
+ inputMint: inputTokenMint,
3133
+ outputMint: outputTokenMint,
3134
+ amount: amountIn,
3135
+ user,
3136
+ maxAccounts: 50,
3137
+ slippageBps: swapSlippageBps
3138
+ }, jupiterQuoteOptions),
2628
3139
  config
2629
3140
  );
2630
3141
  if (!quote) {
@@ -2647,25 +3158,25 @@ function estimateDlmmIndirectSwap(_0) {
2647
3158
  const halfAmount = amountIn.div(new BN3(2));
2648
3159
  const [quoteToXResult, quoteToYResult] = yield Promise.allSettled([
2649
3160
  getJupiterQuote(
2650
- inputTokenMint,
2651
- tokenXMint,
2652
- halfAmount,
2653
- 50,
2654
- swapSlippageBps,
2655
- false,
2656
- true,
2657
- true,
3161
+ __spreadValues({
3162
+ inputMint: inputTokenMint,
3163
+ outputMint: tokenXMint,
3164
+ amount: halfAmount,
3165
+ user,
3166
+ maxAccounts: 50,
3167
+ slippageBps: swapSlippageBps
3168
+ }, jupiterQuoteOptions),
2658
3169
  config
2659
3170
  ),
2660
3171
  getJupiterQuote(
2661
- inputTokenMint,
2662
- tokenYMint,
2663
- halfAmount,
2664
- 50,
2665
- swapSlippageBps,
2666
- false,
2667
- true,
2668
- true,
3172
+ __spreadValues({
3173
+ inputMint: inputTokenMint,
3174
+ outputMint: tokenYMint,
3175
+ amount: halfAmount,
3176
+ user,
3177
+ maxAccounts: 50,
3178
+ slippageBps: swapSlippageBps
3179
+ }, jupiterQuoteOptions),
2669
3180
  config
2670
3181
  )
2671
3182
  ]);
@@ -2761,25 +3272,25 @@ function estimateDlmmIndirectSwap(_0) {
2761
3272
  }
2762
3273
  const [finalQuoteToXResult, finalQuoteToYResult] = yield Promise.allSettled([
2763
3274
  getJupiterQuote(
2764
- inputTokenMint,
2765
- tokenXMint,
2766
- bestAmountToX,
2767
- 50,
2768
- swapSlippageBps,
2769
- false,
2770
- true,
2771
- true,
3275
+ __spreadValues({
3276
+ inputMint: inputTokenMint,
3277
+ outputMint: tokenXMint,
3278
+ amount: bestAmountToX,
3279
+ user,
3280
+ maxAccounts: 50,
3281
+ slippageBps: swapSlippageBps
3282
+ }, jupiterQuoteOptions),
2772
3283
  config
2773
3284
  ),
2774
3285
  getJupiterQuote(
2775
- inputTokenMint,
2776
- tokenYMint,
2777
- bestAmountToY,
2778
- 50,
2779
- swapSlippageBps,
2780
- false,
2781
- true,
2782
- true,
3286
+ __spreadValues({
3287
+ inputMint: inputTokenMint,
3288
+ outputMint: tokenYMint,
3289
+ amount: bestAmountToY,
3290
+ user,
3291
+ maxAccounts: 50,
3292
+ slippageBps: swapSlippageBps
3293
+ }, jupiterQuoteOptions),
2783
3294
  config
2784
3295
  )
2785
3296
  ]);
@@ -2815,6 +3326,7 @@ function estimateDlmmIndirectSwap(_0) {
2815
3326
  }
2816
3327
  function estimateDlmmDirectSwapCore(_0) {
2817
3328
  return __async(this, arguments, function* ({
3329
+ user,
2818
3330
  tokenXAmount,
2819
3331
  tokenYAmount,
2820
3332
  dlmm,
@@ -2823,6 +3335,7 @@ function estimateDlmmDirectSwapCore(_0) {
2823
3335
  maxDeltaId,
2824
3336
  strategy,
2825
3337
  singleSided,
3338
+ jupiterQuoteOptions,
2826
3339
  config = {}
2827
3340
  }) {
2828
3341
  if (singleSided !== void 0) {
@@ -2835,13 +3348,15 @@ function estimateDlmmDirectSwapCore(_0) {
2835
3348
  );
2836
3349
  const quote = yield getBestSwapQuoteJupiterDlmm(
2837
3350
  dlmm,
3351
+ user,
2838
3352
  dlmm.lbPair.tokenYMint,
2839
3353
  dlmm.lbPair.tokenXMint,
2840
3354
  tokenYAmount,
2841
3355
  swapSlippageBps,
2842
3356
  swapForY2,
2843
3357
  binArrayForSwap2,
2844
- config
3358
+ config,
3359
+ jupiterQuoteOptions
2845
3360
  );
2846
3361
  if (!quote) {
2847
3362
  throw new Error(
@@ -2864,13 +3379,15 @@ function estimateDlmmDirectSwapCore(_0) {
2864
3379
  );
2865
3380
  const quote = yield getBestSwapQuoteJupiterDlmm(
2866
3381
  dlmm,
3382
+ user,
2867
3383
  dlmm.lbPair.tokenXMint,
2868
3384
  dlmm.lbPair.tokenYMint,
2869
3385
  tokenXAmount,
2870
3386
  swapSlippageBps,
2871
3387
  swapForY2,
2872
3388
  binArrayForSwap2,
2873
- config
3389
+ config,
3390
+ jupiterQuoteOptions
2874
3391
  );
2875
3392
  if (!quote) {
2876
3393
  throw new Error(
@@ -2959,13 +3476,15 @@ function estimateDlmmDirectSwapCore(_0) {
2959
3476
  );
2960
3477
  const initialQuote = yield getBestSwapQuoteJupiterDlmm(
2961
3478
  dlmm,
3479
+ user,
2962
3480
  inMint,
2963
3481
  outMint,
2964
3482
  initialSwapAmount,
2965
3483
  swapSlippageBps,
2966
3484
  swapForY,
2967
3485
  binArrayForSwap,
2968
- config
3486
+ config,
3487
+ jupiterQuoteOptions
2969
3488
  );
2970
3489
  if (!initialQuote) {
2971
3490
  throw new Error(
@@ -3017,13 +3536,15 @@ function estimateDlmmDirectSwapCore(_0) {
3017
3536
  );
3018
3537
  const finalQuote = yield getBestSwapQuoteJupiterDlmm(
3019
3538
  dlmm,
3539
+ user,
3020
3540
  inMint,
3021
3541
  outMint,
3022
3542
  refinedAmount,
3023
3543
  swapSlippageBps,
3024
3544
  swapForY,
3025
3545
  binArrayForSwap,
3026
- config
3546
+ config,
3547
+ jupiterQuoteOptions
3027
3548
  );
3028
3549
  if (!finalQuote) {
3029
3550
  return {
@@ -3049,6 +3570,7 @@ function estimateDlmmDirectSwapCore(_0) {
3049
3570
  }
3050
3571
  function estimateDlmmDirectSwap(_0) {
3051
3572
  return __async(this, arguments, function* ({
3573
+ user,
3052
3574
  amountIn,
3053
3575
  inputTokenMint,
3054
3576
  lbPair,
@@ -3058,6 +3580,7 @@ function estimateDlmmDirectSwap(_0) {
3058
3580
  maxDeltaId,
3059
3581
  strategy,
3060
3582
  singleSided,
3583
+ jupiterQuoteOptions,
3061
3584
  config = {}
3062
3585
  }) {
3063
3586
  const dlmm = yield DLMM2.create(connection, lbPair);
@@ -3069,6 +3592,7 @@ function estimateDlmmDirectSwap(_0) {
3069
3592
  const tokenXAmount = isInputTokenX ? amountIn : new BN3(0);
3070
3593
  const tokenYAmount = isInputTokenX ? new BN3(0) : amountIn;
3071
3594
  const result = yield estimateDlmmDirectSwapCore({
3595
+ user,
3072
3596
  tokenXAmount,
3073
3597
  tokenYAmount,
3074
3598
  dlmm,
@@ -3077,6 +3601,7 @@ function estimateDlmmDirectSwap(_0) {
3077
3601
  maxDeltaId,
3078
3602
  strategy,
3079
3603
  singleSided,
3604
+ jupiterQuoteOptions,
3080
3605
  config
3081
3606
  });
3082
3607
  return {
@@ -3096,6 +3621,7 @@ function estimateDlmmDirectSwap(_0) {
3096
3621
  }
3097
3622
  function estimateDlmmRebalanceSwap(_0) {
3098
3623
  return __async(this, arguments, function* ({
3624
+ user,
3099
3625
  lbPair,
3100
3626
  position,
3101
3627
  connection,
@@ -3103,11 +3629,13 @@ function estimateDlmmRebalanceSwap(_0) {
3103
3629
  minDeltaId,
3104
3630
  maxDeltaId,
3105
3631
  strategy,
3632
+ jupiterQuoteOptions,
3106
3633
  config = {}
3107
3634
  }) {
3108
3635
  const dlmm = yield DLMM2.create(connection, lbPair);
3109
3636
  const userPosition = yield dlmm.getPosition(position);
3110
3637
  const result = yield estimateDlmmDirectSwapCore({
3638
+ user,
3111
3639
  tokenXAmount: new BN3(userPosition.positionData.totalXAmount),
3112
3640
  tokenYAmount: new BN3(userPosition.positionData.totalYAmount),
3113
3641
  dlmm,
@@ -3117,6 +3645,7 @@ function estimateDlmmRebalanceSwap(_0) {
3117
3645
  strategy,
3118
3646
  singleSided: void 0,
3119
3647
  // rebalance does not use single-sided deposits
3648
+ jupiterQuoteOptions,
3120
3649
  config
3121
3650
  });
3122
3651
  return {
@@ -3205,13 +3734,15 @@ function getExtendMaxAmountTransfer(amount, percentage) {
3205
3734
  var Zap = class {
3206
3735
  /**
3207
3736
  * @param connection - The connection to the Solana cluster
3208
- * @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag) and API key (default: empty string)
3737
+ * @param config - Optional configuration for Jupiter API URL (default: https://api.jup.ag), API key (default: empty string) and API version (default: JupiterApiVersion.V2)
3209
3738
  */
3210
3739
  constructor(connection, config = {}) {
3740
+ var _a;
3211
3741
  this.connection = connection;
3212
3742
  this.zapProgram = new Program(idl_default, { connection });
3213
3743
  this.jupiterApiUrl = config.jupiterApiUrl || DEFAULT_JUPITER_API_URL;
3214
3744
  this.jupiterApiKey = config.jupiterApiKey || "";
3745
+ this.jupiterApiVersion = (_a = config.jupiterApiVersion) != null ? _a : DEFAULT_JUPITER_API_VERSION;
3215
3746
  }
3216
3747
  /////// PRIVATE FUNDTIONS //////
3217
3748
  initializeLedgerAccount(owner, payer) {
@@ -3220,7 +3751,7 @@ var Zap = class {
3220
3751
  ledger: deriveLedgerAccount(owner),
3221
3752
  owner,
3222
3753
  payer
3223
- }).transaction();
3754
+ }).instruction();
3224
3755
  });
3225
3756
  }
3226
3757
  closeLedgerAccount(owner, rentReceiver) {
@@ -3229,7 +3760,7 @@ var Zap = class {
3229
3760
  ledger: deriveLedgerAccount(owner),
3230
3761
  owner,
3231
3762
  rentReceiver
3232
- }).transaction();
3763
+ }).instruction();
3233
3764
  });
3234
3765
  }
3235
3766
  setLedgerBalance(owner, amount, isTokenA) {
@@ -3237,7 +3768,7 @@ var Zap = class {
3237
3768
  return yield this.zapProgram.methods.setLedgerBalance(amount, isTokenA).accountsPartial({
3238
3769
  ledger: deriveLedgerAccount(owner),
3239
3770
  owner
3240
- }).transaction();
3771
+ }).instruction();
3241
3772
  });
3242
3773
  }
3243
3774
  updateLedgerBalanceAfterSwap(owner, tokenAccount, preSourceTokenAccount, maxTransferAmount, isTokenA) {
@@ -3250,7 +3781,7 @@ var Zap = class {
3250
3781
  ledger: deriveLedgerAccount(owner),
3251
3782
  tokenAccount,
3252
3783
  owner
3253
- }).transaction();
3784
+ }).instruction();
3254
3785
  });
3255
3786
  }
3256
3787
  zapInDammV2(params) {
@@ -3288,7 +3819,7 @@ var Zap = class {
3288
3819
  tokenBProgram,
3289
3820
  dammProgram: DAMM_V2_PROGRAM_ID,
3290
3821
  dammEventAuthority: deriveDammV2EventAuthority()
3291
- }).transaction();
3822
+ }).instruction();
3292
3823
  });
3293
3824
  }
3294
3825
  resetOrInitializeLedgerAccount(user) {
@@ -3298,9 +3829,9 @@ var Zap = class {
3298
3829
  if (accountInfo) {
3299
3830
  const closeLedger = yield this.closeLedgerAccount(user, user);
3300
3831
  const reInitializeLedger = yield this.initializeLedgerAccount(user, user);
3301
- return new Transaction2().add(closeLedger).add(reInitializeLedger);
3832
+ return [closeLedger, reInitializeLedger];
3302
3833
  }
3303
- return yield this.initializeLedgerAccount(user, user);
3834
+ return [yield this.initializeLedgerAccount(user, user)];
3304
3835
  });
3305
3836
  }
3306
3837
  zapInDlmmForInitializedPosition(params) {
@@ -3367,7 +3898,7 @@ var Zap = class {
3367
3898
  memoProgram: MEMO_PROGRAM_ID,
3368
3899
  dlmmEventAuthority: deriveDlmmEventAuthority(),
3369
3900
  systemProgram: SystemProgram2.programId
3370
- }).remainingAccounts(binArrays).transaction();
3901
+ }).remainingAccounts(binArrays).instruction();
3371
3902
  });
3372
3903
  }
3373
3904
  zapInDlmmForUninitializedPosition(params) {
@@ -3431,7 +3962,7 @@ var Zap = class {
3431
3962
  memoProgram: MEMO_PROGRAM_ID,
3432
3963
  dlmmEventAuthority: deriveDlmmEventAuthority(),
3433
3964
  systemProgram: SystemProgram2.programId
3434
- }).remainingAccounts(binArrays).transaction();
3965
+ }).remainingAccounts(binArrays).instruction();
3435
3966
  });
3436
3967
  }
3437
3968
  //#region Zap In
@@ -3451,6 +3982,7 @@ var Zap = class {
3451
3982
  * @param params.dammV2Quote - The DAMM V2 swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
3452
3983
  * @param params.jupiterQuote - The Jupiter swap quote for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
3453
3984
  * @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
3985
+ * @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
3454
3986
  * @returns The zap-in transaction parameters for a DAMM V2 direct pool
3455
3987
  * @throws if input token mint matches either tokenA or tokenB in the pool
3456
3988
  * @throws if failed to get both Jupiter and DAMM v2 swap quotes
@@ -3469,7 +4001,8 @@ var Zap = class {
3469
4001
  slippageBps,
3470
4002
  dammV2Quote,
3471
4003
  jupiterQuote,
3472
- maxTransferAmountExtendPercentage
4004
+ maxTransferAmountExtendPercentage,
4005
+ jupiterQuoteOptions
3473
4006
  } = params;
3474
4007
  const poolState = yield getDammV2Pool(this.connection, pool);
3475
4008
  const {
@@ -3489,7 +4022,7 @@ var Zap = class {
3489
4022
  const tokenAProgram = getTokenProgram(tokenAFlag);
3490
4023
  const tokenBProgram = getTokenProgram(tokenBFlag);
3491
4024
  const preInstructions = [];
3492
- if (tokenAMint.equals(NATIVE_MINT3) || tokenBMint.equals(NATIVE_MINT3)) {
4025
+ if (inputTokenMint.equals(NATIVE_MINT3)) {
3493
4026
  const { ataPubkey: userWrapSolAcc, ix: initializeUserWrapSOLAta } = yield getOrCreateATAInstruction(
3494
4027
  this.connection,
3495
4028
  NATIVE_MINT3,
@@ -3541,7 +4074,8 @@ var Zap = class {
3541
4074
  const singleSidedA = isSingleSidedA(poolState);
3542
4075
  const singleSidedB = isSingleSidedB(poolState);
3543
4076
  let amount;
3544
- let swapTransactions = [];
4077
+ let swapInstructions = [];
4078
+ let addressLookupTableAccounts = [];
3545
4079
  let maxTransferAmount;
3546
4080
  let swapInAmount;
3547
4081
  let swapRoute;
@@ -3555,6 +4089,7 @@ var Zap = class {
3555
4089
  swapInAmount = amountIn;
3556
4090
  amount = new BN5(0);
3557
4091
  const result = yield buildJupiterSwapTransaction(
4092
+ this.connection,
3558
4093
  user,
3559
4094
  inputTokenMint,
3560
4095
  outputTokenMint,
@@ -3564,10 +4099,13 @@ var Zap = class {
3564
4099
  void 0,
3565
4100
  {
3566
4101
  jupiterApiUrl: this.jupiterApiUrl,
3567
- jupiterApiKey: this.jupiterApiKey
3568
- }
4102
+ jupiterApiKey: this.jupiterApiKey,
4103
+ jupiterApiVersion: this.jupiterApiVersion
4104
+ },
4105
+ jupiterQuoteOptions
3569
4106
  );
3570
- swapTransactions = [result.transaction];
4107
+ swapInstructions = [result.instruction];
4108
+ addressLookupTableAccounts = result.addressLookupTableAccounts;
3571
4109
  maxTransferAmount = getExtendMaxAmountTransfer(
3572
4110
  result.quoteResponse.outAmount,
3573
4111
  maxTransferAmountExtendPercentage
@@ -3604,6 +4142,7 @@ var Zap = class {
3604
4142
  );
3605
4143
  amount = amountIn.sub(swapInAmount);
3606
4144
  const result = yield buildJupiterSwapTransaction(
4145
+ this.connection,
3607
4146
  user,
3608
4147
  inputTokenMint,
3609
4148
  outputTokenMint,
@@ -3613,10 +4152,13 @@ var Zap = class {
3613
4152
  void 0,
3614
4153
  {
3615
4154
  jupiterApiUrl: this.jupiterApiUrl,
3616
- jupiterApiKey: this.jupiterApiKey
3617
- }
4155
+ jupiterApiKey: this.jupiterApiKey,
4156
+ jupiterApiVersion: this.jupiterApiVersion
4157
+ },
4158
+ jupiterQuoteOptions
3618
4159
  );
3619
- swapTransactions = [result.transaction];
4160
+ swapInstructions = [result.instruction];
4161
+ addressLookupTableAccounts = result.addressLookupTableAccounts;
3620
4162
  maxTransferAmount = getExtendMaxAmountTransfer(
3621
4163
  result.quoteResponse.outAmount,
3622
4164
  maxTransferAmountExtendPercentage
@@ -3674,7 +4216,8 @@ var Zap = class {
3674
4216
  preSqrtPrice: poolState.sqrtPrice,
3675
4217
  maxSqrtPriceChangeBps,
3676
4218
  preInstructions,
3677
- swapTransactions,
4219
+ swapInstructions,
4220
+ addressLookupTableAccounts,
3678
4221
  cleanUpInstructions,
3679
4222
  swapInEstimate: {
3680
4223
  inAmount: swapInAmount,
@@ -3699,6 +4242,7 @@ var Zap = class {
3699
4242
  * @param params.jupiterQuoteToA - The Jupiter quote for swapping to tokenA for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
3700
4243
  * @param params.jupiterQuoteToB - The Jupiter quote for swapping to tokenB for exactly 1 input token in lamports (used for price calculation, not the actual amountIn)
3701
4244
  * @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
4245
+ * @param params.jupiterQuoteOptions - Optional Jupiter quote options, see `JupiterQuoteOptions`
3702
4246
  * @returns The zap-in transaction parameters for a DAMM V2 indirect pool
3703
4247
  * @throws if input token mint matches either tokenA or tokenB in the pool
3704
4248
  * @throws if no Jupiter quote provided for both tokens
@@ -3717,7 +4261,8 @@ var Zap = class {
3717
4261
  maxTransferAmountExtendPercentage,
3718
4262
  slippageBps,
3719
4263
  jupiterQuoteToA,
3720
- jupiterQuoteToB
4264
+ jupiterQuoteToB,
4265
+ jupiterQuoteOptions
3721
4266
  } = params;
3722
4267
  const poolState = yield getDammV2Pool(this.connection, pool);
3723
4268
  const {
@@ -3802,6 +4347,7 @@ var Zap = class {
3802
4347
  );
3803
4348
  }
3804
4349
  const result = yield buildJupiterSwapTransaction(
4350
+ this.connection,
3805
4351
  user,
3806
4352
  inputTokenMint,
3807
4353
  tokenAMint,
@@ -3811,8 +4357,10 @@ var Zap = class {
3811
4357
  void 0,
3812
4358
  {
3813
4359
  jupiterApiUrl: this.jupiterApiUrl,
3814
- jupiterApiKey: this.jupiterApiKey
3815
- }
4360
+ jupiterApiKey: this.jupiterApiKey,
4361
+ jupiterApiVersion: this.jupiterApiVersion
4362
+ },
4363
+ jupiterQuoteOptions
3816
4364
  );
3817
4365
  return {
3818
4366
  user,
@@ -3836,7 +4384,8 @@ var Zap = class {
3836
4384
  maxTransferAmountB: new BN5(0),
3837
4385
  preSqrtPrice: poolState.sqrtPrice,
3838
4386
  preInstructions,
3839
- swapTransactions: [result.transaction],
4387
+ swapInstructions: [result.instruction],
4388
+ addressLookupTableAccounts: result.addressLookupTableAccounts,
3840
4389
  cleanUpInstructions,
3841
4390
  swapInEstimate: {
3842
4391
  inAmountA: amountIn,
@@ -3853,6 +4402,7 @@ var Zap = class {
3853
4402
  );
3854
4403
  }
3855
4404
  const result = yield buildJupiterSwapTransaction(
4405
+ this.connection,
3856
4406
  user,
3857
4407
  inputTokenMint,
3858
4408
  tokenBMint,
@@ -3862,8 +4412,10 @@ var Zap = class {
3862
4412
  void 0,
3863
4413
  {
3864
4414
  jupiterApiUrl: this.jupiterApiUrl,
3865
- jupiterApiKey: this.jupiterApiKey
3866
- }
4415
+ jupiterApiKey: this.jupiterApiKey,
4416
+ jupiterApiVersion: this.jupiterApiVersion
4417
+ },
4418
+ jupiterQuoteOptions
3867
4419
  );
3868
4420
  return {
3869
4421
  user,
@@ -3887,7 +4439,8 @@ var Zap = class {
3887
4439
  swapType: 1 /* swapToB */,
3888
4440
  preSqrtPrice: poolState.sqrtPrice,
3889
4441
  preInstructions,
3890
- swapTransactions: [result.transaction],
4442
+ swapInstructions: [result.instruction],
4443
+ addressLookupTableAccounts: result.addressLookupTableAccounts,
3891
4444
  cleanUpInstructions,
3892
4445
  swapInEstimate: {
3893
4446
  inAmountA: new BN5(0),
@@ -3899,6 +4452,7 @@ var Zap = class {
3899
4452
  }
3900
4453
  if (jupiterQuoteToA && jupiterQuoteToB === null) {
3901
4454
  const result = yield buildJupiterSwapTransaction(
4455
+ this.connection,
3902
4456
  user,
3903
4457
  inputTokenMint,
3904
4458
  tokenAMint,
@@ -3908,8 +4462,10 @@ var Zap = class {
3908
4462
  void 0,
3909
4463
  {
3910
4464
  jupiterApiUrl: this.jupiterApiUrl,
3911
- jupiterApiKey: this.jupiterApiKey
3912
- }
4465
+ jupiterApiKey: this.jupiterApiKey,
4466
+ jupiterApiVersion: this.jupiterApiVersion
4467
+ },
4468
+ jupiterQuoteOptions
3913
4469
  );
3914
4470
  return {
3915
4471
  user,
@@ -3933,7 +4489,8 @@ var Zap = class {
3933
4489
  maxTransferAmountB: new BN5(0),
3934
4490
  preSqrtPrice: poolState.sqrtPrice,
3935
4491
  preInstructions,
3936
- swapTransactions: [result.transaction],
4492
+ swapInstructions: [result.instruction],
4493
+ addressLookupTableAccounts: result.addressLookupTableAccounts,
3937
4494
  cleanUpInstructions,
3938
4495
  swapInEstimate: {
3939
4496
  inAmountA: amountIn,
@@ -3945,6 +4502,7 @@ var Zap = class {
3945
4502
  }
3946
4503
  if (jupiterQuoteToB && jupiterQuoteToA === null) {
3947
4504
  const result = yield buildJupiterSwapTransaction(
4505
+ this.connection,
3948
4506
  user,
3949
4507
  inputTokenMint,
3950
4508
  tokenBMint,
@@ -3954,8 +4512,10 @@ var Zap = class {
3954
4512
  void 0,
3955
4513
  {
3956
4514
  jupiterApiUrl: this.jupiterApiUrl,
3957
- jupiterApiKey: this.jupiterApiKey
3958
- }
4515
+ jupiterApiKey: this.jupiterApiKey,
4516
+ jupiterApiVersion: this.jupiterApiVersion
4517
+ },
4518
+ jupiterQuoteOptions
3959
4519
  );
3960
4520
  return {
3961
4521
  user,
@@ -3979,7 +4539,8 @@ var Zap = class {
3979
4539
  swapType: 1 /* swapToB */,
3980
4540
  preSqrtPrice: poolState.sqrtPrice,
3981
4541
  preInstructions,
3982
- swapTransactions: [result.transaction],
4542
+ swapInstructions: [result.instruction],
4543
+ addressLookupTableAccounts: result.addressLookupTableAccounts,
3983
4544
  cleanUpInstructions,
3984
4545
  swapInEstimate: {
3985
4546
  inAmountA: new BN5(0),
@@ -4031,7 +4592,8 @@ var Zap = class {
4031
4592
  preSqrtPrice: poolState.sqrtPrice,
4032
4593
  cleanUpInstructions
4033
4594
  };
4034
- const { transaction: swapToATransaction, quoteResponse: swapToAQuote } = yield buildJupiterSwapTransaction(
4595
+ const swapToA = yield buildJupiterSwapTransaction(
4596
+ this.connection,
4035
4597
  user,
4036
4598
  inputTokenMint,
4037
4599
  tokenAMint,
@@ -4041,10 +4603,13 @@ var Zap = class {
4041
4603
  void 0,
4042
4604
  {
4043
4605
  jupiterApiUrl: this.jupiterApiUrl,
4044
- jupiterApiKey: this.jupiterApiKey
4045
- }
4606
+ jupiterApiKey: this.jupiterApiKey,
4607
+ jupiterApiVersion: this.jupiterApiVersion
4608
+ },
4609
+ jupiterQuoteOptions
4046
4610
  );
4047
- const { transaction: swapToBTransaction, quoteResponse: swapToBQuote } = yield buildJupiterSwapTransaction(
4611
+ const swapToB = yield buildJupiterSwapTransaction(
4612
+ this.connection,
4048
4613
  user,
4049
4614
  inputTokenMint,
4050
4615
  tokenBMint,
@@ -4054,20 +4619,26 @@ var Zap = class {
4054
4619
  void 0,
4055
4620
  {
4056
4621
  jupiterApiUrl: this.jupiterApiUrl,
4057
- jupiterApiKey: this.jupiterApiKey
4058
- }
4622
+ jupiterApiKey: this.jupiterApiKey,
4623
+ jupiterApiVersion: this.jupiterApiVersion
4624
+ },
4625
+ jupiterQuoteOptions
4059
4626
  );
4060
4627
  return __spreadProps(__spreadValues({}, baseParams), {
4061
4628
  maxTransferAmountA: getExtendMaxAmountTransfer(
4062
- swapToAQuote.outAmount,
4629
+ swapToA.quoteResponse.outAmount,
4063
4630
  maxTransferAmountExtendPercentage
4064
4631
  ),
4065
4632
  maxTransferAmountB: getExtendMaxAmountTransfer(
4066
- swapToBQuote.outAmount,
4633
+ swapToB.quoteResponse.outAmount,
4067
4634
  maxTransferAmountExtendPercentage
4068
4635
  ),
4069
4636
  swapType: 2 /* swapToBoth */,
4070
- swapTransactions: [swapToATransaction, swapToBTransaction],
4637
+ swapInstructions: [swapToA.instruction, swapToB.instruction],
4638
+ addressLookupTableAccounts: mergeAddressLookupTableAccounts(
4639
+ swapToA.addressLookupTableAccounts,
4640
+ swapToB.addressLookupTableAccounts
4641
+ ),
4071
4642
  swapInEstimate: {
4072
4643
  inAmountA: swapAmountToA,
4073
4644
  inAmountB: swapAmountToB,
@@ -4082,7 +4653,12 @@ var Zap = class {
4082
4653
  });
4083
4654
  }
4084
4655
  /**
4085
- * Build DAMM v2 zap-in transaction
4656
+ * Build the DAMM v2 zap-in instructions
4657
+ *
4658
+ * Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
4659
+ * They must run in that order but can be split across several transactions, because state
4660
+ * between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
4661
+ * No compute budget instructions are included; the client sets the compute budget for each transaction.
4086
4662
  *
4087
4663
  * @param params.user - The user's public key
4088
4664
  * @param params.pool - The pool's public key
@@ -4099,9 +4675,10 @@ var Zap = class {
4099
4675
  * @param params.preSqrtPrice - The sqrt price before the operation
4100
4676
  * @param params.maxSqrtPriceChangeBps - The maximum sqrt price change in basis points
4101
4677
  * @param params.preInstructions - Instructions to run before the zap in
4102
- * @param params.swapTransactions - Swap transactions to execute
4678
+ * @param params.swapInstructions - Swap instructions to execute
4679
+ * @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
4103
4680
  * @param params.cleanUpInstructions - Instructions to run after the zap in
4104
- * @returns Response containing transaction components
4681
+ * @returns The ordered instructions and the lookup tables they use
4105
4682
  */
4106
4683
  buildZapInDammV2Transaction(params) {
4107
4684
  return __async(this, null, function* () {
@@ -4121,7 +4698,8 @@ var Zap = class {
4121
4698
  preSqrtPrice,
4122
4699
  maxSqrtPriceChangeBps,
4123
4700
  preInstructions,
4124
- swapTransactions,
4701
+ swapInstructions,
4702
+ addressLookupTableAccounts,
4125
4703
  cleanUpInstructions
4126
4704
  } = params;
4127
4705
  const [
@@ -4145,37 +4723,33 @@ var Zap = class {
4145
4723
  tokenBProgram
4146
4724
  )
4147
4725
  ]);
4148
- const setupTransaction = new Transaction2();
4149
- initializeTokenAIx && setupTransaction.add(initializeTokenAIx);
4150
- initializeTokenBIx && setupTransaction.add(initializeTokenBIx);
4151
- if (preInstructions.length > 0) {
4152
- setupTransaction.add(...preInstructions);
4153
- }
4154
- const ledgerTransaction = new Transaction2();
4155
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
4156
- ledgerTransaction.add(resetOrInitializeLedgerTx);
4726
+ const setupInstructions = [];
4727
+ initializeTokenAIx && setupInstructions.push(initializeTokenAIx);
4728
+ initializeTokenBIx && setupInstructions.push(initializeTokenBIx);
4729
+ setupInstructions.push(...preInstructions);
4730
+ const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
4157
4731
  if (isDirectPool) {
4158
4732
  const isTokenA = params.isTokenA;
4159
- const setLedgerBalanceTx = yield this.setLedgerBalance(
4733
+ const setLedgerBalanceIx = yield this.setLedgerBalance(
4160
4734
  user,
4161
4735
  amount,
4162
4736
  isTokenA
4163
4737
  );
4164
- ledgerTransaction.add(setLedgerBalanceTx);
4165
- if (swapTransactions.length > 0) {
4738
+ ledgerInstructions.push(setLedgerBalanceIx);
4739
+ if (swapInstructions.length > 0) {
4166
4740
  const tokenAccount = isTokenA ? tokenBAccount : tokenAAccount;
4167
4741
  const preTokenBalance = yield getTokenAccountBalance(
4168
4742
  this.connection,
4169
4743
  tokenAccount
4170
4744
  );
4171
- const updateLedgerBalanceAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
4745
+ const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4172
4746
  user,
4173
4747
  tokenAccount,
4174
4748
  new BN5(preTokenBalance),
4175
4749
  params.maxTransferAmount,
4176
4750
  !isTokenA
4177
4751
  );
4178
- ledgerTransaction.add(updateLedgerBalanceAfterSwapTx);
4752
+ ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
4179
4753
  }
4180
4754
  } else {
4181
4755
  const preTokenABalance = yield getTokenAccountBalance(
@@ -4186,7 +4760,7 @@ var Zap = class {
4186
4760
  this.connection,
4187
4761
  tokenBAccount
4188
4762
  );
4189
- const updateLedgerBalanceTokenAAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
4763
+ const updateLedgerBalanceTokenAAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4190
4764
  user,
4191
4765
  tokenAAccount,
4192
4766
  new BN5(preTokenABalance),
@@ -4194,7 +4768,7 @@ var Zap = class {
4194
4768
  true
4195
4769
  // is token A
4196
4770
  );
4197
- const updateLedgerBalanceTokenBAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
4771
+ const updateLedgerBalanceTokenBAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4198
4772
  user,
4199
4773
  tokenBAccount,
4200
4774
  new BN5(preTokenBBalance),
@@ -4204,14 +4778,17 @@ var Zap = class {
4204
4778
  );
4205
4779
  const swapType = params.swapType;
4206
4780
  if (swapType == 0 /* swapToA */) {
4207
- ledgerTransaction.add(updateLedgerBalanceTokenAAfterSwapTx);
4781
+ ledgerInstructions.push(updateLedgerBalanceTokenAAfterSwapIx);
4208
4782
  } else if (swapType == 1 /* swapToB */) {
4209
- ledgerTransaction.add(updateLedgerBalanceTokenBAfterSwapTx);
4783
+ ledgerInstructions.push(updateLedgerBalanceTokenBAfterSwapIx);
4210
4784
  } else {
4211
- ledgerTransaction.add(updateLedgerBalanceTokenAAfterSwapTx).add(updateLedgerBalanceTokenBAfterSwapTx);
4785
+ ledgerInstructions.push(
4786
+ updateLedgerBalanceTokenAAfterSwapIx,
4787
+ updateLedgerBalanceTokenBAfterSwapIx
4788
+ );
4212
4789
  }
4213
4790
  }
4214
- const zapInTransaction = yield this.zapInDammV2({
4791
+ const zapInInstruction = yield this.zapInDammV2({
4215
4792
  user,
4216
4793
  pool,
4217
4794
  position,
@@ -4227,18 +4804,17 @@ var Zap = class {
4227
4804
  tokenAAccount,
4228
4805
  tokenBAccount
4229
4806
  });
4230
- const cleanUpTransaction = new Transaction2();
4231
- const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
4232
- cleanUpTransaction.add(closeLedgerTransaction);
4233
- if (cleanUpInstructions.length > 0) {
4234
- cleanUpTransaction.add(...cleanUpInstructions);
4235
- }
4807
+ const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
4236
4808
  return {
4237
- setupTransaction: setupTransaction.instructions.length > 0 ? setupTransaction : void 0,
4238
- swapTransactions,
4239
- ledgerTransaction,
4240
- zapInTransaction,
4241
- cleanUpTransaction
4809
+ instructions: [
4810
+ ...setupInstructions,
4811
+ ...swapInstructions,
4812
+ ...ledgerInstructions,
4813
+ zapInInstruction,
4814
+ closeLedgerInstruction,
4815
+ ...cleanUpInstructions
4816
+ ],
4817
+ addressLookupTableAccounts
4242
4818
  };
4243
4819
  });
4244
4820
  }
@@ -4255,8 +4831,8 @@ var Zap = class {
4255
4831
  * @param params.maxDeltaId - The bin delta relative to the active bin for the upper bin position
4256
4832
  * @param params.strategy - The liquidity distribution strategy
4257
4833
  * @param params.favorXInActiveId - Whether to favor token X in the active bin
4258
- * @param params.maxAccounts - The maximum number of accounts for the Jupiter swap query
4259
- * @param params.swapSlippageBps - The swap slippage tolerance in basis points
4834
+ * @param params.maxAccounts - Max accounts for the Jupiter swap query. Example value is `50`; this is not safe for every pool/size. Combined with Direct estimators (`onlyDirectRoutes=true`) this can select a much thinner route than Jupiter UI.
4835
+ * @param params.swapSlippageBps - Swap slippage vs the **quoted route**, not vs a fair input/output price. Validate `directSwapEstimate` / `outAmount` before send.
4260
4836
  * @param params.maxTransferAmountExtendPercentage - The percentage to extend the max transfer amount after the swap
4261
4837
  * @param params.maxActiveBinSlippage - The maximum active bin slippage
4262
4838
  * @param params.directSwapEstimate - The result from the direct swap estimate
@@ -4309,12 +4885,14 @@ var Zap = class {
4309
4885
  initializeWrapSolIx && preInstructions.push(initializeWrapSolIx);
4310
4886
  preInstructions.push(...wrapSOL);
4311
4887
  }
4312
- const swapTransactions = [];
4888
+ const swapInstructions = [];
4889
+ let addressLookupTableAccounts = [];
4313
4890
  let maxTransferAmount;
4314
4891
  if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
4315
4892
  const swapQuote = directSwapEstimate.quote;
4316
4893
  if (swapQuote.route === 0 /* Jupiter */) {
4317
- const { transaction: swapTx } = yield buildJupiterSwapTransaction(
4894
+ const swap = yield buildJupiterSwapTransaction(
4895
+ this.connection,
4318
4896
  user,
4319
4897
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenXMint : tokenYMint,
4320
4898
  directSwapEstimate.swapType === 0 /* XToY */ ? tokenYMint : tokenXMint,
@@ -4324,10 +4902,12 @@ var Zap = class {
4324
4902
  swapQuote.originalQuote,
4325
4903
  {
4326
4904
  jupiterApiUrl: this.jupiterApiUrl,
4327
- jupiterApiKey: this.jupiterApiKey
4905
+ jupiterApiKey: this.jupiterApiKey,
4906
+ jupiterApiVersion: this.jupiterApiVersion
4328
4907
  }
4329
4908
  );
4330
- swapTransactions.push(swapTx);
4909
+ swapInstructions.push(swap.instruction);
4910
+ addressLookupTableAccounts = swap.addressLookupTableAccounts;
4331
4911
  } else {
4332
4912
  const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
4333
4913
  const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
@@ -4340,6 +4920,9 @@ var Zap = class {
4340
4920
  user,
4341
4921
  binArraysPubkey: binArrays2.map((item) => item.publicKey)
4342
4922
  });
4923
+ swapTx.instructions = filterOutComputeBudgetInstructions(
4924
+ swapTx.instructions
4925
+ );
4343
4926
  if (tokenXMint.equals(NATIVE_MINT3) || tokenYMint.equals(NATIVE_MINT3)) {
4344
4927
  swapTx.instructions = swapTx.instructions.filter((ix) => {
4345
4928
  if (ix.programId.equals(TOKEN_PROGRAM_ID6)) {
@@ -4348,7 +4931,7 @@ var Zap = class {
4348
4931
  return true;
4349
4932
  });
4350
4933
  }
4351
- swapTransactions.push(swapTx);
4934
+ swapInstructions.push(...swapTx.instructions);
4352
4935
  }
4353
4936
  maxTransferAmount = getExtendMaxAmountTransfer(
4354
4937
  directSwapEstimate.expectedOutput.toString(),
@@ -4398,7 +4981,8 @@ var Zap = class {
4398
4981
  amount,
4399
4982
  maxTransferAmount,
4400
4983
  preInstructions,
4401
- swapTransactions,
4984
+ swapInstructions,
4985
+ addressLookupTableAccounts,
4402
4986
  cleanUpInstructions,
4403
4987
  binArrays,
4404
4988
  binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
@@ -4479,11 +5063,13 @@ var Zap = class {
4479
5063
  }
4480
5064
  let maxTransferAmountX;
4481
5065
  let maxTransferAmountY;
4482
- const swapTransactions = [];
5066
+ const swapInstructions = [];
5067
+ const swapLookupTables = [];
4483
5068
  const swapAmountToXInLamports = indirectSwapEstimate.swapAmountToX;
4484
5069
  const swapAmountToYInLamports = indirectSwapEstimate.swapAmountToY;
4485
5070
  if (!indirectSwapEstimate.swapAmountToX.isZero() && indirectSwapEstimate.swapToX !== null) {
4486
- const { transaction: swapToXTransaction } = yield buildJupiterSwapTransaction(
5071
+ const swapToX = yield buildJupiterSwapTransaction(
5072
+ this.connection,
4487
5073
  user,
4488
5074
  inputTokenMint,
4489
5075
  tokenXMint,
@@ -4493,13 +5079,16 @@ var Zap = class {
4493
5079
  indirectSwapEstimate.swapToX,
4494
5080
  {
4495
5081
  jupiterApiUrl: this.jupiterApiUrl,
4496
- jupiterApiKey: this.jupiterApiKey
5082
+ jupiterApiKey: this.jupiterApiKey,
5083
+ jupiterApiVersion: this.jupiterApiVersion
4497
5084
  }
4498
5085
  );
4499
- swapTransactions.push(swapToXTransaction);
5086
+ swapInstructions.push(swapToX.instruction);
5087
+ swapLookupTables.push(swapToX.addressLookupTableAccounts);
4500
5088
  }
4501
5089
  if (!indirectSwapEstimate.swapAmountToY.isZero() && indirectSwapEstimate.swapToY !== null) {
4502
- const { transaction: swapToYTransaction } = yield buildJupiterSwapTransaction(
5090
+ const swapToY = yield buildJupiterSwapTransaction(
5091
+ this.connection,
4503
5092
  user,
4504
5093
  inputTokenMint,
4505
5094
  tokenYMint,
@@ -4509,11 +5098,16 @@ var Zap = class {
4509
5098
  indirectSwapEstimate.swapToY,
4510
5099
  {
4511
5100
  jupiterApiUrl: this.jupiterApiUrl,
4512
- jupiterApiKey: this.jupiterApiKey
5101
+ jupiterApiKey: this.jupiterApiKey,
5102
+ jupiterApiVersion: this.jupiterApiVersion
4513
5103
  }
4514
5104
  );
4515
- swapTransactions.push(swapToYTransaction);
5105
+ swapInstructions.push(swapToY.instruction);
5106
+ swapLookupTables.push(swapToY.addressLookupTableAccounts);
4516
5107
  }
5108
+ const addressLookupTableAccounts = mergeAddressLookupTableAccounts(
5109
+ ...swapLookupTables
5110
+ );
4517
5111
  maxTransferAmountX = getExtendMaxAmountTransfer(
4518
5112
  indirectSwapEstimate.postSwapX.toString(),
4519
5113
  maxTransferAmountExtendPercentage
@@ -4555,7 +5149,8 @@ var Zap = class {
4555
5149
  maxTransferAmountX,
4556
5150
  maxTransferAmountY,
4557
5151
  preInstructions,
4558
- swapTransactions,
5152
+ swapInstructions,
5153
+ addressLookupTableAccounts,
4559
5154
  cleanUpInstructions,
4560
5155
  binArrays,
4561
5156
  binArrayBitmapExtension: binArrayBitmapExtensionData ? binArrayBitmapExtension : null,
@@ -4565,7 +5160,12 @@ var Zap = class {
4565
5160
  });
4566
5161
  }
4567
5162
  /**
4568
- * Builds a DLMM zap-in transaction
5163
+ * Build the DLMM zap-in instructions
5164
+ *
5165
+ * Instructions are ordered: setup (token accounts, wrap SOL), swaps, ledger, zap in, clean up.
5166
+ * They must run in that order but can be split across several transactions, because state
5167
+ * between steps lives in accounts. Splitting loses atomicity, so send split transactions as a bundle.
5168
+ * No compute budget instructions are included; the client sets the compute budget for each transaction.
4569
5169
  *
4570
5170
  * @param params.user - The user's public key
4571
5171
  * @param params.lbPair - The DLMM pool's public key
@@ -4581,13 +5181,14 @@ var Zap = class {
4581
5181
  * @param params.favorXInActiveId - Whether to favor token X in the active bin
4582
5182
  * @param params.strategy - The liquidity distribution strategy
4583
5183
  * @param params.preInstructions - Instructions to run before the zap in
4584
- * @param params.swapTransactions - Swap transactions to execute
5184
+ * @param params.swapInstructions - Swap instructions to execute
5185
+ * @param params.addressLookupTableAccounts - Lookup tables used by the swap instructions
4585
5186
  * @param params.cleanUpInstructions - Instructions to run after the zap in
4586
5187
  * @param params.binArrays - The bin arrays required for the position
4587
5188
  * @param params.binArrayBitmapExtension - The bin array bitmap extension account if it exists
4588
5189
  * @param params.isDirectRoute - Whether this is a direct route
4589
5190
  * @param params.singleSided - Optional single-sided deposit mode (X or Y only) - default is non-single-sided
4590
- * @returns Response containing transaction components
5191
+ * @returns The ordered instructions and the lookup tables they use
4591
5192
  */
4592
5193
  buildZapInDlmmTransaction(params) {
4593
5194
  return __async(this, null, function* () {
@@ -4606,7 +5207,8 @@ var Zap = class {
4606
5207
  favorXInActiveId,
4607
5208
  strategy,
4608
5209
  preInstructions,
4609
- swapTransactions,
5210
+ swapInstructions,
5211
+ addressLookupTableAccounts,
4610
5212
  cleanUpInstructions,
4611
5213
  binArrays,
4612
5214
  binArrayBitmapExtension,
@@ -4634,62 +5236,58 @@ var Zap = class {
4634
5236
  tokenYProgram
4635
5237
  )
4636
5238
  ]);
4637
- const setupTransaction = new Transaction2();
4638
- initializeTokenXIx && setupTransaction.add(initializeTokenXIx);
4639
- initializeTokenYIx && setupTransaction.add(initializeTokenYIx);
4640
- if (preInstructions.length > 0) {
4641
- setupTransaction.add(...preInstructions);
4642
- }
4643
- const ledgerTransaction = new Transaction2();
4644
- const resetOrInitializeLedgerTx = yield this.resetOrInitializeLedgerAccount(user);
4645
- ledgerTransaction.add(resetOrInitializeLedgerTx);
5239
+ const setupInstructions = [];
5240
+ initializeTokenXIx && setupInstructions.push(initializeTokenXIx);
5241
+ initializeTokenYIx && setupInstructions.push(initializeTokenYIx);
5242
+ setupInstructions.push(...preInstructions);
5243
+ const ledgerInstructions = yield this.resetOrInitializeLedgerAccount(user);
4646
5244
  if (isDirectRoute) {
4647
5245
  const { isTokenX, amount, maxTransferAmount } = params;
4648
5246
  if (singleSided !== void 0) {
4649
5247
  const singleSidedX = singleSided === 0 /* X */;
4650
- if (swapTransactions.length > 0) {
5248
+ if (swapInstructions.length > 0) {
4651
5249
  const swappedTokenAccount = singleSidedX ? tokenXAccount : tokenYAccount;
4652
5250
  const preSwappedTokenBalance = yield getTokenAccountBalance(
4653
5251
  this.connection,
4654
5252
  swappedTokenAccount
4655
5253
  );
4656
- const updateLedgerBalanceAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
5254
+ const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4657
5255
  user,
4658
5256
  swappedTokenAccount,
4659
5257
  new BN5(preSwappedTokenBalance),
4660
5258
  maxTransferAmount,
4661
5259
  singleSidedX
4662
5260
  );
4663
- ledgerTransaction.add(updateLedgerBalanceAfterSwapTx);
5261
+ ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
4664
5262
  } else {
4665
- const setLedgerBalanceTx = yield this.setLedgerBalance(
5263
+ const setLedgerBalanceIx = yield this.setLedgerBalance(
4666
5264
  user,
4667
5265
  amount,
4668
5266
  singleSidedX
4669
5267
  );
4670
- ledgerTransaction.add(setLedgerBalanceTx);
5268
+ ledgerInstructions.push(setLedgerBalanceIx);
4671
5269
  }
4672
5270
  } else {
4673
- const setLedgerBalanceTx = yield this.setLedgerBalance(
5271
+ const setLedgerBalanceIx = yield this.setLedgerBalance(
4674
5272
  user,
4675
5273
  amount,
4676
5274
  isTokenX
4677
5275
  );
4678
- ledgerTransaction.add(setLedgerBalanceTx);
4679
- if (swapTransactions.length > 0) {
5276
+ ledgerInstructions.push(setLedgerBalanceIx);
5277
+ if (swapInstructions.length > 0) {
4680
5278
  const swappedTokenAccount = isTokenX ? tokenYAccount : tokenXAccount;
4681
5279
  const preSwappedTokenBalance = yield getTokenAccountBalance(
4682
5280
  this.connection,
4683
5281
  swappedTokenAccount
4684
5282
  );
4685
- const updateLedgerBalanceAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
5283
+ const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4686
5284
  user,
4687
5285
  swappedTokenAccount,
4688
5286
  new BN5(preSwappedTokenBalance),
4689
5287
  maxTransferAmount,
4690
5288
  !isTokenX
4691
5289
  );
4692
- ledgerTransaction.add(updateLedgerBalanceAfterSwapTx);
5290
+ ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
4693
5291
  }
4694
5292
  }
4695
5293
  } else {
@@ -4701,14 +5299,14 @@ var Zap = class {
4701
5299
  this.connection,
4702
5300
  swappedTokenAccount
4703
5301
  );
4704
- const updateLedgerBalanceAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
5302
+ const updateLedgerBalanceAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4705
5303
  user,
4706
5304
  swappedTokenAccount,
4707
5305
  new BN5(preSwappedTokenBalance),
4708
5306
  singleSidedX ? maxTransferAmountX : maxTransferAmountY,
4709
5307
  singleSidedX
4710
5308
  );
4711
- ledgerTransaction.add(updateLedgerBalanceAfterSwapTx);
5309
+ ledgerInstructions.push(updateLedgerBalanceAfterSwapIx);
4712
5310
  } else {
4713
5311
  const preTokenXBalance = yield getTokenAccountBalance(
4714
5312
  this.connection,
@@ -4718,22 +5316,22 @@ var Zap = class {
4718
5316
  this.connection,
4719
5317
  tokenYAccount
4720
5318
  );
4721
- const updateLedgerBalanceTokenXAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
5319
+ const updateLedgerBalanceTokenXAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4722
5320
  user,
4723
5321
  tokenXAccount,
4724
5322
  new BN5(preTokenXBalance),
4725
5323
  maxTransferAmountX,
4726
5324
  true
4727
5325
  );
4728
- const updateLedgerBalanceTokenYAfterSwapTx = yield this.updateLedgerBalanceAfterSwap(
5326
+ const updateLedgerBalanceTokenYAfterSwapIx = yield this.updateLedgerBalanceAfterSwap(
4729
5327
  user,
4730
5328
  tokenYAccount,
4731
5329
  new BN5(preTokenYBalance),
4732
5330
  maxTransferAmountY,
4733
5331
  false
4734
5332
  );
4735
- ledgerTransaction.add(updateLedgerBalanceTokenXAfterSwapTx);
4736
- ledgerTransaction.add(updateLedgerBalanceTokenYAfterSwapTx);
5333
+ ledgerInstructions.push(updateLedgerBalanceTokenXAfterSwapIx);
5334
+ ledgerInstructions.push(updateLedgerBalanceTokenYAfterSwapIx);
4737
5335
  }
4738
5336
  }
4739
5337
  const dlmm = yield DLMM3.create(this.connection, lbPair);
@@ -4747,7 +5345,7 @@ var Zap = class {
4747
5345
  tokenYProgram,
4748
5346
  dlmm.lbPair
4749
5347
  );
4750
- const zapInTransaction = yield this.zapInDlmmForUninitializedPosition({
5348
+ const zapInInstruction = yield this.zapInDlmmForUninitializedPosition({
4751
5349
  user,
4752
5350
  lbPair,
4753
5351
  position,
@@ -4761,18 +5359,17 @@ var Zap = class {
4761
5359
  strategy,
4762
5360
  remainingAccountInfo
4763
5361
  });
4764
- const cleanUpTransaction = new Transaction2();
4765
- const closeLedgerTransaction = yield this.closeLedgerAccount(user, user);
4766
- cleanUpTransaction.add(closeLedgerTransaction);
4767
- if (cleanUpInstructions.length > 0) {
4768
- cleanUpTransaction.add(...cleanUpInstructions);
4769
- }
5362
+ const closeLedgerInstruction = yield this.closeLedgerAccount(user, user);
4770
5363
  return {
4771
- setupTransaction: setupTransaction.instructions.length > 0 ? setupTransaction : void 0,
4772
- swapTransactions,
4773
- ledgerTransaction,
4774
- zapInTransaction,
4775
- cleanUpTransaction
5364
+ instructions: [
5365
+ ...setupInstructions,
5366
+ ...swapInstructions,
5367
+ ...ledgerInstructions,
5368
+ zapInInstruction,
5369
+ closeLedgerInstruction,
5370
+ ...cleanUpInstructions
5371
+ ],
5372
+ addressLookupTableAccounts
4776
5373
  };
4777
5374
  });
4778
5375
  }
@@ -4780,6 +5377,13 @@ var Zap = class {
4780
5377
  * High level method for DLMM position rebalancing
4781
5378
  * Consist of remove liquidity, zap out through Jupiter or DLMM, and zap back in to rebalance the position
4782
5379
  *
5380
+ * Instructions are ordered: setup (token accounts), init bin arrays, rebalance position, swap, ledger,
5381
+ * zap in, clean up. They must run in that order but can be split across several transactions.
5382
+ * Splitting loses atomicity, so send split transactions as a bundle.
5383
+ * No compute budget instructions are included. The zap-in instruction was measured at about 462k
5384
+ * compute units. Without a compute unit limit, a transaction gets 200k units per instruction (up to
5385
+ * 1.4M), which may not cover it, so set a compute unit limit on the transaction that holds it.
5386
+ *
4783
5387
  * @param params - Rebalancing DLMM position parameters
4784
5388
  * @param params.lbPairAddress - The DLMM pool address
4785
5389
  * @param params.positionAddress - The position address
@@ -4792,7 +5396,7 @@ var Zap = class {
4792
5396
  * @param params.favorXInActiveId - Whether to favor token X in the active bin
4793
5397
  * @param params.directSwapEstimate - The estimate of the direct swap operation
4794
5398
  * @param params.maxAccounts - The maximum number of accounts to use for the swap operation
4795
- * @returns Response containing transactions and estimation details
5399
+ * @returns The ordered instructions, the lookup tables they use, and the estimated balances
4796
5400
  * @throws if fail to get jupiter quote or jupiter swap instruction
4797
5401
  */
4798
5402
  rebalanceDlmmPosition(params) {
@@ -4834,9 +5438,9 @@ var Zap = class {
4834
5438
  tokenYProgram
4835
5439
  )
4836
5440
  ]);
4837
- const setupTransaction = new Transaction2();
4838
- userTokenXIx && setupTransaction.add(userTokenXIx);
4839
- userTokenYIx && setupTransaction.add(userTokenYIx);
5441
+ const setupInstructions = [];
5442
+ userTokenXIx && setupInstructions.push(userTokenXIx);
5443
+ userTokenYIx && setupInstructions.push(userTokenYIx);
4840
5444
  const strategyParamBuilder = getLiquidityStrategyParameterBuilder(strategy);
4841
5445
  const { x0, y0, deltaX, deltaY } = buildLiquidityStrategyParameters(
4842
5446
  new BN5(0),
@@ -4887,19 +5491,23 @@ var Zap = class {
4887
5491
  { simulationResult, rebalancePosition },
4888
5492
  new BN5(maxActiveBinSlippage)
4889
5493
  );
4890
- let rebalancePositionInstruction = _rebalancePositionInstruction;
5494
+ let rebalancePositionInstruction = filterOutComputeBudgetInstructions(
5495
+ _rebalancePositionInstruction
5496
+ );
4891
5497
  if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
4892
5498
  rebalancePositionInstruction = filterOutCloseSplTokenAccountInstructions(
4893
- _rebalancePositionInstruction
5499
+ rebalancePositionInstruction
4894
5500
  );
4895
5501
  }
4896
5502
  const tokenXAmount = new BN5(userPosition.positionData.totalXAmount);
4897
5503
  const tokenYAmount = new BN5(userPosition.positionData.totalYAmount);
4898
- let swapTransaction;
5504
+ let swapInstructions = [];
5505
+ let addressLookupTableAccounts = [];
4899
5506
  if (directSwapEstimate.swapType !== 2 /* NoSwap */ && directSwapEstimate.quote) {
4900
5507
  const swapQuote = directSwapEstimate.quote;
4901
5508
  if (swapQuote.route === 0 /* Jupiter */) {
4902
- const { transaction: swapTx } = yield buildJupiterSwapTransaction(
5509
+ const swap = yield buildJupiterSwapTransaction(
5510
+ this.connection,
4903
5511
  user,
4904
5512
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenXMint : dlmm.lbPair.tokenYMint,
4905
5513
  directSwapEstimate.swapType === 0 /* XToY */ ? dlmm.lbPair.tokenYMint : dlmm.lbPair.tokenXMint,
@@ -4909,10 +5517,12 @@ var Zap = class {
4909
5517
  swapQuote.originalQuote,
4910
5518
  {
4911
5519
  jupiterApiUrl: this.jupiterApiUrl,
4912
- jupiterApiKey: this.jupiterApiKey
5520
+ jupiterApiKey: this.jupiterApiKey,
5521
+ jupiterApiVersion: this.jupiterApiVersion
4913
5522
  }
4914
5523
  );
4915
- swapTransaction = swapTx;
5524
+ swapInstructions = [swap.instruction];
5525
+ addressLookupTableAccounts = swap.addressLookupTableAccounts;
4916
5526
  } else {
4917
5527
  const swapForY = directSwapEstimate.swapType === 0 /* XToY */;
4918
5528
  const binArrays2 = yield dlmm.getBinArrayForSwap(swapForY);
@@ -4925,12 +5535,15 @@ var Zap = class {
4925
5535
  user,
4926
5536
  binArraysPubkey: binArrays2.map((item) => item.publicKey)
4927
5537
  });
5538
+ swapTx.instructions = filterOutComputeBudgetInstructions(
5539
+ swapTx.instructions
5540
+ );
4928
5541
  if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
4929
5542
  swapTx.instructions = filterOutCloseSplTokenAccountInstructions(
4930
5543
  swapTx.instructions
4931
5544
  );
4932
5545
  }
4933
- swapTransaction = swapTx;
5546
+ swapInstructions = swapTx.instructions;
4934
5547
  }
4935
5548
  }
4936
5549
  const preTokenXBalance = yield getTokenAccountBalance(
@@ -4945,27 +5558,27 @@ var Zap = class {
4945
5558
  const tokenYAmountAfterSwap = directSwapEstimate.swapType === 0 /* XToY */ ? tokenYAmount.add(directSwapEstimate.expectedOutput) : directSwapEstimate.swapType === 1 /* YToX */ ? tokenYAmount.sub(directSwapEstimate.swapAmount) : tokenYAmount;
4946
5559
  const ledgerAddress = deriveLedgerAccount(user);
4947
5560
  const ledgerAccountInfo = yield this.connection.getAccountInfo(ledgerAddress);
4948
- const ledgerTransaction = new Transaction2();
5561
+ const ledgerInstructions = [];
4949
5562
  if (!ledgerAccountInfo) {
4950
- const initLedgerTx = yield this.initializeLedgerAccount(user, user);
4951
- ledgerTransaction.add(...initLedgerTx.instructions);
5563
+ const initLedgerIx = yield this.initializeLedgerAccount(user, user);
5564
+ ledgerInstructions.push(initLedgerIx);
4952
5565
  }
4953
- const updateLedgerXTx = yield this.updateLedgerBalanceAfterSwap(
5566
+ const updateLedgerXIx = yield this.updateLedgerBalanceAfterSwap(
4954
5567
  user,
4955
5568
  userTokenX,
4956
5569
  new BN5(preTokenXBalance),
4957
5570
  tokenXAmountAfterSwap,
4958
5571
  true
4959
5572
  );
4960
- ledgerTransaction.add(...updateLedgerXTx.instructions);
4961
- const updateLedgerYTx = yield this.updateLedgerBalanceAfterSwap(
5573
+ ledgerInstructions.push(updateLedgerXIx);
5574
+ const updateLedgerYIx = yield this.updateLedgerBalanceAfterSwap(
4962
5575
  user,
4963
5576
  userTokenY,
4964
5577
  new BN5(preTokenYBalance),
4965
5578
  tokenYAmountAfterSwap,
4966
5579
  false
4967
5580
  );
4968
- ledgerTransaction.add(...updateLedgerYTx.instructions);
5581
+ ledgerInstructions.push(updateLedgerYIx);
4969
5582
  const binArrays = getBinArraysRequiredByPositionRange(
4970
5583
  lbPair,
4971
5584
  new BN5(dlmm.lbPair.activeId + minDeltaId),
@@ -4986,7 +5599,7 @@ var Zap = class {
4986
5599
  tokenYProgram,
4987
5600
  dlmm.lbPair
4988
5601
  );
4989
- const zapInTransaction = yield this.zapInDlmmForInitializedPosition({
5602
+ const zapInInstruction = yield this.zapInDlmmForInitializedPosition({
4990
5603
  user,
4991
5604
  lbPair,
4992
5605
  position,
@@ -4999,28 +5612,26 @@ var Zap = class {
4999
5612
  strategy,
5000
5613
  remainingAccountInfo
5001
5614
  });
5002
- zapInTransaction.instructions.unshift(
5003
- // based on 1 tx that consumed 462_610. Add 20% for safety and round up to nearest 100,000
5004
- // 462_610 * 1.2 = 555_132 => 600_000
5005
- ComputeBudgetProgram.setComputeUnitLimit({ units: 6e5 })
5006
- );
5007
- const cleanUpTransaction = new Transaction2();
5008
- const closeLedgerTx = yield this.closeLedgerAccount(user, user);
5009
- cleanUpTransaction.add(closeLedgerTx);
5615
+ const cleanUpInstructions = [
5616
+ yield this.closeLedgerAccount(user, user)
5617
+ ];
5010
5618
  if (dlmm.lbPair.tokenXMint.equals(NATIVE_MINT3) || dlmm.lbPair.tokenYMint.equals(NATIVE_MINT3)) {
5011
5619
  const unwrapIx = unwrapSOLInstruction(user, user);
5012
5620
  if (unwrapIx) {
5013
- cleanUpTransaction.add(unwrapIx);
5621
+ cleanUpInstructions.push(unwrapIx);
5014
5622
  }
5015
5623
  }
5016
5624
  return {
5017
- setupTransaction,
5018
- initBinArrayTransaction: initBinArrayInstructions.length > 0 ? new Transaction2().add(...initBinArrayInstructions) : void 0,
5019
- rebalancePositionTransaction: rebalancePositionInstruction.length > 0 ? new Transaction2().add(...rebalancePositionInstruction) : void 0,
5020
- swapTransaction,
5021
- ledgerTransaction,
5022
- zapInTransaction,
5023
- cleanUpTransaction,
5625
+ instructions: [
5626
+ ...setupInstructions,
5627
+ ...filterOutComputeBudgetInstructions(initBinArrayInstructions),
5628
+ ...rebalancePositionInstruction,
5629
+ ...swapInstructions,
5630
+ ...ledgerInstructions,
5631
+ zapInInstruction,
5632
+ ...cleanUpInstructions
5633
+ ],
5634
+ addressLookupTableAccounts,
5024
5635
  estimation: {
5025
5636
  currentBalances: {
5026
5637
  tokenX: tokenXAmount,
@@ -5046,7 +5657,7 @@ var Zap = class {
5046
5657
  * @param params.ammProgram - AMM program ID to interact with
5047
5658
  * @param params.preInstructions - Instructions to run before the zap out
5048
5659
  * @param params.postInstructions - Instructions to run after the zap out
5049
- * @returns builder transaction
5660
+ * @returns The pre-instructions, the zap out instruction and the post-instructions in order, with no lookup tables
5050
5661
  */
5051
5662
  zapOut(params) {
5052
5663
  return __async(this, null, function* () {
@@ -5058,10 +5669,18 @@ var Zap = class {
5058
5669
  preInstructions,
5059
5670
  postInstructions
5060
5671
  } = params;
5061
- return this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
5672
+ const zapOutInstruction = yield this.zapProgram.methods.zapOut(zapOutParams).accountsPartial({
5062
5673
  userTokenInAccount,
5063
5674
  ammProgram
5064
- }).remainingAccounts(remainingAccounts).preInstructions(preInstructions).postInstructions(postInstructions).transaction();
5675
+ }).remainingAccounts(remainingAccounts).instruction();
5676
+ return {
5677
+ instructions: [
5678
+ ...preInstructions,
5679
+ zapOutInstruction,
5680
+ ...postInstructions
5681
+ ],
5682
+ addressLookupTableAccounts: []
5683
+ };
5065
5684
  });
5066
5685
  }
5067
5686
  /**
@@ -5072,12 +5691,12 @@ var Zap = class {
5072
5691
  * @param params.user - Public key of the user performing the swap
5073
5692
  * @param params.inputMint - Token mint being swapped from
5074
5693
  * @param params.outputMint - Token mint being swapped to
5075
- * @param params.jupiterSwapResponse - Jupiter swap instruction response
5694
+ * @param params.jupiterSwapResponse - Jupiter swap instruction response. Its lookup table fields, when present, are returned as `addressLookupTableAccounts` (v1 tables are fetched with one RPC call)
5076
5695
  * @param params.inputTokenProgram - Token program for the input token (defaults to SPL Token)
5077
5696
  * @param params.outputTokenProgram - Token program for the output token (defaults to SPL Token)
5078
5697
  * @param params.maxSwapAmount - Maximum amount of input token to swap
5079
5698
  * @param params.percentageToZapOut - Percentage of input token to zap out
5080
- * @returns built transaction
5699
+ * @returns The ordered instructions and the lookup tables of the Jupiter swap
5081
5700
  */
5082
5701
  zapOutThroughJupiter(params) {
5083
5702
  return __async(this, null, function* () {
@@ -5095,7 +5714,7 @@ var Zap = class {
5095
5714
  const postInstructions = [];
5096
5715
  const [
5097
5716
  { ataPubkey: inputTokenAccount, ix: inputTokenAccountIx },
5098
- { ataPubkey: outputTokenAccount, ix: outputTokenAccountIx }
5717
+ { ix: outputTokenAccountIx }
5099
5718
  ] = yield Promise.all([
5100
5719
  getOrCreateATAInstruction(
5101
5720
  this.connection,
@@ -5139,27 +5758,36 @@ var Zap = class {
5139
5758
  jupiterSwapResponse.swapInstruction.data,
5140
5759
  "base64"
5141
5760
  );
5142
- const offsetAmountIn = payloadData.length - AMOUNT_IN_JUP_V6_REVERSE_OFFSET;
5761
+ const offsetAmountIn = getJupiterInstructionLayout(
5762
+ payloadData
5763
+ ).amountInOffset(payloadData.length);
5143
5764
  if (inputMint.equals(NATIVE_MINT3) || outputMint.equals(NATIVE_MINT3)) {
5144
5765
  const unwrapInstructions = unwrapSOLInstruction(user, user);
5145
5766
  if (unwrapInstructions) {
5146
5767
  postInstructions.push(unwrapInstructions);
5147
5768
  }
5148
5769
  }
5149
- return yield this.zapOut({
5150
- userTokenInAccount: inputTokenAccount,
5151
- zapOutParams: {
5152
- percentage: percentageToZapOut,
5153
- offsetAmountIn,
5154
- preUserTokenBalance: new BN5(preUserTokenBalance),
5155
- maxSwapAmount,
5156
- payloadData
5157
- },
5158
- remainingAccounts,
5159
- ammProgram: JUP_V6_PROGRAM_ID,
5160
- preInstructions,
5161
- postInstructions
5162
- });
5770
+ const [{ instructions }, addressLookupTableAccounts] = yield Promise.all([
5771
+ this.zapOut({
5772
+ userTokenInAccount: inputTokenAccount,
5773
+ zapOutParams: {
5774
+ percentage: percentageToZapOut,
5775
+ offsetAmountIn,
5776
+ preUserTokenBalance: new BN5(preUserTokenBalance),
5777
+ maxSwapAmount,
5778
+ payloadData
5779
+ },
5780
+ remainingAccounts,
5781
+ ammProgram: JUP_V6_PROGRAM_ID,
5782
+ preInstructions,
5783
+ postInstructions
5784
+ }),
5785
+ getJupiterAddressLookupTableAccounts(
5786
+ this.connection,
5787
+ jupiterSwapResponse
5788
+ )
5789
+ ]);
5790
+ return { instructions, addressLookupTableAccounts };
5163
5791
  });
5164
5792
  }
5165
5793
  /**
@@ -5175,6 +5803,7 @@ var Zap = class {
5175
5803
  * @param params.minimumSwapAmountOut - Minimum amount of output token to receive
5176
5804
  * @param params.maxSwapAmount - Maximum amount of input token to swap
5177
5805
  * @param params.percentageToZapOut - Percentage of input token to zap out
5806
+ * @returns The ordered instructions, with no lookup tables
5178
5807
  */
5179
5808
  zapOutThroughDammV2(params) {
5180
5809
  return __async(this, null, function* () {
@@ -5271,6 +5900,7 @@ var Zap = class {
5271
5900
  * @param params.minimumSwapAmountOut - Minimum amount of output token to receive
5272
5901
  * @param params.maxSwapAmount - Maximum amount of input token to swap
5273
5902
  * @param params.percentageToZapOut - Percentage of input token to zap out
5903
+ * @returns The ordered instructions, with no lookup tables
5274
5904
  */
5275
5905
  zapOutThroughDlmm(params) {
5276
5906
  return __async(this, null, function* () {
@@ -5368,12 +5998,20 @@ export {
5368
5998
  DAMM_V2_PROGRAM_ID,
5369
5999
  DAMM_V2_SWAP_DISCRIMINATOR,
5370
6000
  DEFAULT_JUPITER_API_URL,
6001
+ DEFAULT_JUPITER_API_VERSION,
6002
+ DEFAULT_JUPITER_QUOTE_OPTIONS,
5371
6003
  DLMM_PROGRAM_ID,
5372
6004
  DLMM_SWAP_DISCRIMINATOR,
5373
6005
  DlmmDirectSwapQuoteRoute,
5374
6006
  DlmmSingleSided,
5375
6007
  DlmmSwapType,
6008
+ JUPITER_INSTRUCTION_LAYOUTS,
5376
6009
  JUP_V6_PROGRAM_ID,
6010
+ JUP_V6_ROUTE_DISCRIMINATOR,
6011
+ JUP_V6_ROUTE_V2_DISCRIMINATOR,
6012
+ JUP_V6_SHARED_ACCOUNTS_ROUTE_DISCRIMINATOR,
6013
+ JUP_V6_SHARED_ACCOUNTS_ROUTE_V2_DISCRIMINATOR,
6014
+ JupiterApiVersion,
5377
6015
  MEMO_PROGRAM_ID,
5378
6016
  SwapExternalType,
5379
6017
  ZAP_PROGRAM_ID,
@@ -5393,13 +6031,17 @@ export {
5393
6031
  estimateDlmmDirectSwap,
5394
6032
  estimateDlmmIndirectSwap,
5395
6033
  estimateDlmmRebalanceSwap,
6034
+ fetchAddressLookupTableAccounts,
5396
6035
  filterOutCloseSplTokenAccountInstructions,
6036
+ filterOutComputeBudgetInstructions,
5397
6037
  getBinArrayBitmapExtension,
5398
6038
  getBitFromBinArrayIndexInBitmapExtension,
5399
6039
  getDammV2Pool,
5400
6040
  getDammV2RemainingAccounts,
5401
6041
  getDlmmRemainingAccounts,
5402
6042
  getExtraAccountMetasForTransferHook,
6043
+ getJupiterAddressLookupTableAccounts,
6044
+ getJupiterInstructionLayout,
5403
6045
  getJupiterQuote,
5404
6046
  getJupiterSwapInstruction,
5405
6047
  getLbPairState,
@@ -5407,8 +6049,13 @@ export {
5407
6049
  getOrCreateATAInstruction,
5408
6050
  getTokenAccountBalance,
5409
6051
  getTokenProgramFromMint,
6052
+ isJupiterBuildResponse,
6053
+ isJupiterSwapInstructionForUser,
5410
6054
  isSingleSidedA,
5411
6055
  isSingleSidedB,
6056
+ mergeAddressLookupTableAccounts,
6057
+ resolveJupiterConfig,
6058
+ toAddressLookupTableAccounts,
5412
6059
  toProgramStrategyType,
5413
6060
  unwrapSOLInstruction,
5414
6061
  wrapSOLInstruction