@jup-ag/lend 0.1.7 → 0.1.9

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.
@@ -3,17 +3,46 @@ import BN from 'bn.js';
3
3
  import { Program, AnchorProvider } from '@coral-xyz/anchor';
4
4
  import { l as liquidity } from './lend.CioR9-te.mjs';
5
5
  import { getAssociatedTokenAddressSync, ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, NATIVE_MINT } from '@solana/spl-token';
6
- import { a as getTickHasDebt, v as vaultsIdl, c as getPosition, d as getTick, e as getTickIdLiquidation, f as getVaultConfig, h as getBranch, i as getVaultState, j as getVaultMetadata, k as getLiquidity, l as getRateModel, m as getUserBorrowPosition, n as getUserSupplyPosition, o as getLiquidityReserve, p as getPositionTokenAccount, q as getPositionMetadata, r as getPositionMint, g as getVaultAdmin, s as getClaimAccount } from './lend.CsYeVtpe.mjs';
6
+ import { a as getTickHasDebt, v as vaultsIdl, c as getPosition, d as getTick, e as getTickIdLiquidation, f as getVaultConfig, h as getBranch, i as getVaultState, j as getVaultMetadata, k as getLiquidity, l as getRateModel, m as getUserBorrowPosition, n as getUserSupplyPosition, o as getLiquidityReserve, p as getPositionTokenAccount, q as getPositionMetadata, r as getPositionMint, g as getVaultAdmin, s as getClaimAccount } from './lend.Cw-khlBI.mjs';
7
7
  import { e as getReserve } from './lend.BzG5ldOV.mjs';
8
8
 
9
9
  const address = "jupnw4B6Eqs7ft6rxpzYLJZYSnrpRgPcr589n5Kv4oc";
10
10
  const metadata = {
11
11
  name: "oracle",
12
- version: "0.1.0",
12
+ version: "0.1.3",
13
13
  spec: "0.1.0",
14
14
  description: "Created with Anchor"
15
15
  };
16
16
  const instructions = [
17
+ {
18
+ name: "chainlink_data_streams_feed_access_controller",
19
+ discriminator: [
20
+ 181,
21
+ 88,
22
+ 179,
23
+ 151,
24
+ 225,
25
+ 38,
26
+ 9,
27
+ 6
28
+ ],
29
+ accounts: [
30
+ {
31
+ name: "authority",
32
+ signer: true
33
+ },
34
+ {
35
+ name: "chainlink_ds_cache",
36
+ writable: true
37
+ }
38
+ ],
39
+ args: [
40
+ {
41
+ name: "suspend",
42
+ type: "bool"
43
+ }
44
+ ]
45
+ },
17
46
  {
18
47
  name: "get_both_exchange_rate",
19
48
  discriminator: [
@@ -168,6 +197,84 @@ const instructions = [
168
197
  }
169
198
  ]
170
199
  },
200
+ {
201
+ name: "init_chainlink_data_streams_cache",
202
+ discriminator: [
203
+ 47,
204
+ 174,
205
+ 206,
206
+ 189,
207
+ 94,
208
+ 253,
209
+ 25,
210
+ 233
211
+ ],
212
+ accounts: [
213
+ {
214
+ name: "signer",
215
+ writable: true,
216
+ signer: true
217
+ },
218
+ {
219
+ name: "oracle_admin"
220
+ },
221
+ {
222
+ name: "chainlink_ds_cache",
223
+ writable: true,
224
+ pda: {
225
+ seeds: [
226
+ {
227
+ kind: "const",
228
+ value: [
229
+ 99,
230
+ 104,
231
+ 97,
232
+ 105,
233
+ 110,
234
+ 108,
235
+ 105,
236
+ 110,
237
+ 107,
238
+ 95,
239
+ 100,
240
+ 115
241
+ ]
242
+ },
243
+ {
244
+ kind: "arg",
245
+ path: "nonce"
246
+ }
247
+ ]
248
+ }
249
+ },
250
+ {
251
+ name: "system_program",
252
+ address: "11111111111111111111111111111111"
253
+ }
254
+ ],
255
+ args: [
256
+ {
257
+ name: "nonce",
258
+ type: "u16"
259
+ },
260
+ {
261
+ name: "feeds",
262
+ type: {
263
+ vec: {
264
+ defined: {
265
+ name: "FeedEntry"
266
+ }
267
+ }
268
+ }
269
+ },
270
+ {
271
+ name: "keepers",
272
+ type: {
273
+ vec: "pubkey"
274
+ }
275
+ }
276
+ ]
277
+ },
171
278
  {
172
279
  name: "init_oracle_config",
173
280
  discriminator: [
@@ -234,6 +341,59 @@ const instructions = [
234
341
  }
235
342
  ]
236
343
  },
344
+ {
345
+ name: "refresh_price_feed_with_chainlink",
346
+ discriminator: [
347
+ 74,
348
+ 3,
349
+ 0,
350
+ 183,
351
+ 242,
352
+ 117,
353
+ 152,
354
+ 203
355
+ ],
356
+ accounts: [
357
+ {
358
+ name: "signer",
359
+ signer: true
360
+ },
361
+ {
362
+ name: "chainlink_ds_cache",
363
+ writable: true
364
+ },
365
+ {
366
+ name: "verifier_account",
367
+ address: "HJR45sRiFdGncL69HVzRK4HLS2SXcVW3KeTPkp2aFmWC"
368
+ },
369
+ {
370
+ name: "access_controller",
371
+ address: "7mSn5MoBjyRLKoJShgkep8J17ueGG8rYioVAiSg5YWMF"
372
+ },
373
+ {
374
+ name: "config_account"
375
+ },
376
+ {
377
+ name: "verifier_program_id",
378
+ address: "Gt9S41PtjR58CbG9JhJ3J6vxesqrNAswbWYbLNTMZA3c"
379
+ }
380
+ ],
381
+ args: [
382
+ {
383
+ name: "feed_id",
384
+ type: {
385
+ array: [
386
+ "u8",
387
+ 32
388
+ ]
389
+ }
390
+ },
391
+ {
392
+ name: "serialized_report",
393
+ type: "bytes"
394
+ }
395
+ ]
396
+ },
237
397
  {
238
398
  name: "update_authority",
239
399
  discriminator: [
@@ -297,9 +457,100 @@ const instructions = [
297
457
  }
298
458
  }
299
459
  ]
460
+ },
461
+ {
462
+ name: "update_chainlink_data_streams_cache_feeds",
463
+ discriminator: [
464
+ 55,
465
+ 69,
466
+ 93,
467
+ 203,
468
+ 144,
469
+ 30,
470
+ 248,
471
+ 173
472
+ ],
473
+ accounts: [
474
+ {
475
+ name: "signer",
476
+ writable: true,
477
+ signer: true
478
+ },
479
+ {
480
+ name: "oracle_admin"
481
+ },
482
+ {
483
+ name: "chainlink_ds_cache",
484
+ writable: true
485
+ }
486
+ ],
487
+ args: [
488
+ {
489
+ name: "feeds",
490
+ type: {
491
+ vec: {
492
+ defined: {
493
+ name: "FeedEntry"
494
+ }
495
+ }
496
+ }
497
+ }
498
+ ]
499
+ },
500
+ {
501
+ name: "update_chainlink_data_streams_cache_keepers",
502
+ discriminator: [
503
+ 125,
504
+ 168,
505
+ 188,
506
+ 187,
507
+ 148,
508
+ 203,
509
+ 102,
510
+ 87
511
+ ],
512
+ accounts: [
513
+ {
514
+ name: "signer",
515
+ writable: true,
516
+ signer: true
517
+ },
518
+ {
519
+ name: "oracle_admin"
520
+ },
521
+ {
522
+ name: "chainlink_ds_cache",
523
+ writable: true
524
+ }
525
+ ],
526
+ args: [
527
+ {
528
+ name: "keeper_status",
529
+ type: {
530
+ vec: {
531
+ defined: {
532
+ name: "AddressBool"
533
+ }
534
+ }
535
+ }
536
+ }
537
+ ]
300
538
  }
301
539
  ];
302
540
  const accounts = [
541
+ {
542
+ name: "ChainlinkDataStreamsCache",
543
+ discriminator: [
544
+ 65,
545
+ 102,
546
+ 75,
547
+ 47,
548
+ 79,
549
+ 156,
550
+ 109,
551
+ 193
552
+ ]
553
+ },
303
554
  {
304
555
  name: "Oracle",
305
556
  discriminator: [
@@ -328,6 +579,32 @@ const accounts = [
328
579
  }
329
580
  ];
330
581
  const events = [
582
+ {
583
+ name: "LogChainlinkDataStreamsFeedMarketIsInTransition",
584
+ discriminator: [
585
+ 211,
586
+ 67,
587
+ 128,
588
+ 58,
589
+ 147,
590
+ 192,
591
+ 179,
592
+ 111
593
+ ]
594
+ },
595
+ {
596
+ name: "LogChainlinkDataStreamsFeedSuspended",
597
+ discriminator: [
598
+ 63,
599
+ 149,
600
+ 247,
601
+ 255,
602
+ 189,
603
+ 80,
604
+ 154,
605
+ 253
606
+ ]
607
+ },
331
608
  {
332
609
  name: "LogStakePoolHighFeeDetected",
333
610
  discriminator: [
@@ -366,6 +643,32 @@ const events = [
366
643
  76,
367
644
  251
368
645
  ]
646
+ },
647
+ {
648
+ name: "LogUpdateCacheFeeds",
649
+ discriminator: [
650
+ 75,
651
+ 155,
652
+ 134,
653
+ 56,
654
+ 17,
655
+ 94,
656
+ 235,
657
+ 191
658
+ ]
659
+ },
660
+ {
661
+ name: "LogUpdateCacheKeepers",
662
+ discriminator: [
663
+ 33,
664
+ 129,
665
+ 191,
666
+ 130,
667
+ 117,
668
+ 119,
669
+ 198,
670
+ 235
671
+ ]
369
672
  }
370
673
  ];
371
674
  const errors = [
@@ -493,6 +796,106 @@ const errors = [
493
796
  code: 6024,
494
797
  name: "JupLendAccountMismatch",
495
798
  msg: "JUP_LEND_ACCOUNT_MISMATCH"
799
+ },
800
+ {
801
+ code: 6025,
802
+ name: "ChainlinkDataStreamsNoReportData",
803
+ msg: "CHAINLINK_DATA_STREAMS_NO_REPORT_DATA"
804
+ },
805
+ {
806
+ code: 6026,
807
+ name: "ChainlinkDataStreamsInvalidReport",
808
+ msg: "CHAINLINK_DATA_STREAMS_INVALID_REPORT"
809
+ },
810
+ {
811
+ code: 6027,
812
+ name: "ChainlinkDataStreamsFeedIdMismatch",
813
+ msg: "CHAINLINK_DATA_STREAMS_FEED_ID_MISMATCH"
814
+ },
815
+ {
816
+ code: 6028,
817
+ name: "ChainlinkDataStreamsInvalidReportType",
818
+ msg: "CHAINLINK_DATA_STREAMS_INVALID_REPORT_TYPE"
819
+ },
820
+ {
821
+ code: 6029,
822
+ name: "ChainlinkDataStreamsFeedSuspended",
823
+ msg: "CHAINLINK_DATA_STREAMS_FEED_SUSPENDED"
824
+ },
825
+ {
826
+ code: 6030,
827
+ name: "ChainlinkDataStreamsFeedAlreadySuspendedOrResumed",
828
+ msg: "CHAINLINK_DATA_STREAMS_FEED_ALREADY_SUSPENDED_OR_RESUMED"
829
+ },
830
+ {
831
+ code: 6031,
832
+ name: "ChainlinkDataStreamsNotAKeeper",
833
+ msg: "CHAINLINK_DATA_STREAMS_NOT_A_KEEPER"
834
+ },
835
+ {
836
+ code: 6032,
837
+ name: "ChainlinkDataStreamsMaxFeedKeeperCountReached",
838
+ msg: "CHAINLINK_DATA_STREAMS_MAX_FEED_KEEPER_COUNT_REACHED"
839
+ },
840
+ {
841
+ code: 6033,
842
+ name: "ChainlinkDataStreamsMarketStatusUnknown",
843
+ msg: "CHAINLINK_DATA_STREAMS_MARKET_STATUS_UNKNOWN"
844
+ },
845
+ {
846
+ code: 6034,
847
+ name: "ChainlinkDataStreamsPriceTooOld",
848
+ msg: "CHAINLINK_DATA_STREAMS_PRICE_TOO_OLD"
849
+ },
850
+ {
851
+ code: 6035,
852
+ name: "ChainlinkDataStreamsV10PriceNotAllowed",
853
+ msg: "CHAINLINK_DATA_STREAMS_V10_PRICE_NOT_ALLOWED"
854
+ },
855
+ {
856
+ code: 6036,
857
+ name: "ChainlinkDataStreamsMultipleV10Feeds",
858
+ msg: "CHAINLINK_DATA_STREAMS_MULTIPLE_V10_FEEDS"
859
+ },
860
+ {
861
+ code: 6037,
862
+ name: "ChainlinkDataStreamsV11FeedRequiresV10Feed",
863
+ msg: "CHAINLINK_DATA_STREAMS_V11_FEED_REQUIRES_V10_FEED"
864
+ },
865
+ {
866
+ code: 6038,
867
+ name: "ChainlinkDataStreamsAllowedFeedNotFound",
868
+ msg: "CHAINLINK_DATA_STREAMS_ALLOWED_FEED_NOT_FOUND"
869
+ },
870
+ {
871
+ code: 6039,
872
+ name: "ChainlinkDataStreamsMarketStatusNotSupportedByFeed",
873
+ msg: "CHAINLINK_DATA_STREAMS_MARKET_STATUS_NOT_SUPPORTED_BY_FEED"
874
+ },
875
+ {
876
+ code: 6040,
877
+ name: "ChainlinkDataStreamsObservationTimestampTooOld",
878
+ msg: "CHAINLINK_DATA_STREAMS_OBSERVATION_TIMESTAMP_TOO_OLD"
879
+ },
880
+ {
881
+ code: 6041,
882
+ name: "ChainlinkDataStreamsFeedIdZero",
883
+ msg: "CHAINLINK_DATA_STREAMS_FEED_ID_ZERO"
884
+ },
885
+ {
886
+ code: 6042,
887
+ name: "ChainlinkDataStreamsDuplicateFeedIdReportType",
888
+ msg: "CHAINLINK_DATA_STREAMS_DUPLICATE_FEED_ID_REPORT_TYPE"
889
+ },
890
+ {
891
+ code: 6043,
892
+ name: "ChainlinkDataStreamsDuplicateFeedId",
893
+ msg: "CHAINLINK_DATA_STREAMS_DUPLICATE_FEED_ID"
894
+ },
895
+ {
896
+ code: 6044,
897
+ name: "ChainlinkDataStreamsNoFeedKeepers",
898
+ msg: "CHAINLINK_DATA_STREAMS_NO_FEED_KEEPERS"
496
899
  }
497
900
  ];
498
901
  const types = [
@@ -512,6 +915,218 @@ const types = [
512
915
  ]
513
916
  }
514
917
  },
918
+ {
919
+ name: "ChainlinkDataStreamsCache",
920
+ type: {
921
+ kind: "struct",
922
+ fields: [
923
+ {
924
+ name: "nonce",
925
+ type: "u16"
926
+ },
927
+ {
928
+ name: "feeds",
929
+ type: {
930
+ vec: {
931
+ defined: {
932
+ name: "FeedEntry"
933
+ }
934
+ }
935
+ }
936
+ },
937
+ {
938
+ name: "price",
939
+ type: "u128"
940
+ },
941
+ {
942
+ name: "last_update_timestamp_price",
943
+ type: "u64"
944
+ },
945
+ {
946
+ name: "last_update_timestamp_multiplier",
947
+ type: "u64"
948
+ },
949
+ {
950
+ name: "last_observations_timestamp",
951
+ type: "u64"
952
+ },
953
+ {
954
+ name: "generic_data",
955
+ type: {
956
+ defined: {
957
+ name: "ChainlinkDsCacheGenericData"
958
+ }
959
+ }
960
+ },
961
+ {
962
+ name: "keepers",
963
+ type: {
964
+ vec: "pubkey"
965
+ }
966
+ }
967
+ ]
968
+ }
969
+ },
970
+ {
971
+ name: "ChainlinkDsCacheGenericData",
972
+ type: {
973
+ kind: "struct",
974
+ fields: [
975
+ {
976
+ name: "xstocks_activation_date_time",
977
+ type: "u64"
978
+ },
979
+ {
980
+ name: "xstocks_suspended",
981
+ type: "bool"
982
+ },
983
+ {
984
+ name: "market_status",
985
+ docs: [
986
+ "Last market status observed from the most recent report (0 = not yet seen / Unknown).",
987
+ "Set directly from the report's market_status field on every cache refresh.",
988
+ "For V8/V10 feeds this maps to ReportDataMarketStatus; for V11 to ReportDataV11MarketStatus."
989
+ ],
990
+ type: "u32"
991
+ },
992
+ {
993
+ name: "v11_transition_timestamp_s",
994
+ type: "u64"
995
+ },
996
+ {
997
+ name: "xstocks_last_multiplier",
998
+ docs: [
999
+ "Last current_multiplier seen for this feed via a v10 report."
1000
+ ],
1001
+ type: "u128"
1002
+ },
1003
+ {
1004
+ name: "xstocks_last_observations_timestamp_multiplier_s",
1005
+ docs: [
1006
+ "`observations_timestamp` (seconds) from the last accepted V10 report.",
1007
+ "Enforces strictly-monotonic sequencing to prevent replay of old multiplier reports."
1008
+ ],
1009
+ type: "u64"
1010
+ },
1011
+ {
1012
+ name: "_padding",
1013
+ type: {
1014
+ array: [
1015
+ "u8",
1016
+ 24
1017
+ ]
1018
+ }
1019
+ }
1020
+ ]
1021
+ }
1022
+ },
1023
+ {
1024
+ name: "ChainlinkReportType",
1025
+ repr: {
1026
+ kind: "rust"
1027
+ },
1028
+ type: {
1029
+ kind: "enum",
1030
+ variants: [
1031
+ {
1032
+ name: "XStocks"
1033
+ },
1034
+ {
1035
+ name: "RWA"
1036
+ },
1037
+ {
1038
+ name: "NAV"
1039
+ },
1040
+ {
1041
+ name: "RWAAdvanced"
1042
+ },
1043
+ {
1044
+ name: "ExchangeRate"
1045
+ },
1046
+ {
1047
+ name: "CryptoPrice"
1048
+ }
1049
+ ]
1050
+ }
1051
+ },
1052
+ {
1053
+ name: "FeedEntry",
1054
+ docs: [
1055
+ "One entry in the feed map: a 32-byte Chainlink feed ID paired with its report schema",
1056
+ "type and, for V11 feeds, the set of trading sessions the feed supports."
1057
+ ],
1058
+ type: {
1059
+ kind: "struct",
1060
+ fields: [
1061
+ {
1062
+ name: "feed_id",
1063
+ type: {
1064
+ array: [
1065
+ "u8",
1066
+ 32
1067
+ ]
1068
+ }
1069
+ },
1070
+ {
1071
+ name: "report_type",
1072
+ type: {
1073
+ defined: {
1074
+ name: "ChainlinkReportType"
1075
+ }
1076
+ }
1077
+ },
1078
+ {
1079
+ name: "v11_session_type",
1080
+ type: {
1081
+ defined: {
1082
+ name: "V11FeedSessionType"
1083
+ }
1084
+ }
1085
+ }
1086
+ ]
1087
+ }
1088
+ },
1089
+ {
1090
+ name: "LogChainlinkDataStreamsFeedMarketIsInTransition",
1091
+ type: {
1092
+ kind: "struct",
1093
+ fields: [
1094
+ {
1095
+ name: "feed_id",
1096
+ type: {
1097
+ array: [
1098
+ "u8",
1099
+ 32
1100
+ ]
1101
+ }
1102
+ },
1103
+ {
1104
+ name: "v11_transition_timestamp_s",
1105
+ type: "u64"
1106
+ }
1107
+ ]
1108
+ }
1109
+ },
1110
+ {
1111
+ name: "LogChainlinkDataStreamsFeedSuspended",
1112
+ type: {
1113
+ kind: "struct",
1114
+ fields: [
1115
+ {
1116
+ name: "chainlink_data_streams_cache",
1117
+ type: "pubkey"
1118
+ },
1119
+ {
1120
+ name: "keeper",
1121
+ type: "pubkey"
1122
+ },
1123
+ {
1124
+ name: "xstocks_suspended",
1125
+ type: "bool"
1126
+ }
1127
+ ]
1128
+ }
1129
+ },
515
1130
  {
516
1131
  name: "LogStakePoolHighFeeDetected",
517
1132
  type: {
@@ -558,6 +1173,50 @@ const types = [
558
1173
  ]
559
1174
  }
560
1175
  },
1176
+ {
1177
+ name: "LogUpdateCacheFeeds",
1178
+ type: {
1179
+ kind: "struct",
1180
+ fields: [
1181
+ {
1182
+ name: "chainlink_data_streams_cache",
1183
+ type: "pubkey"
1184
+ },
1185
+ {
1186
+ name: "feeds",
1187
+ type: {
1188
+ vec: {
1189
+ defined: {
1190
+ name: "FeedEntry"
1191
+ }
1192
+ }
1193
+ }
1194
+ }
1195
+ ]
1196
+ }
1197
+ },
1198
+ {
1199
+ name: "LogUpdateCacheKeepers",
1200
+ type: {
1201
+ kind: "struct",
1202
+ fields: [
1203
+ {
1204
+ name: "chainlink_data_streams_cache",
1205
+ type: "pubkey"
1206
+ },
1207
+ {
1208
+ name: "keeper_status",
1209
+ type: {
1210
+ vec: {
1211
+ defined: {
1212
+ name: "AddressBool"
1213
+ }
1214
+ }
1215
+ }
1216
+ }
1217
+ ]
1218
+ }
1219
+ },
561
1220
  {
562
1221
  name: "Oracle",
563
1222
  type: {
@@ -627,6 +1286,9 @@ const types = [
627
1286
  },
628
1287
  {
629
1288
  name: "JupLend"
1289
+ },
1290
+ {
1291
+ name: "ChainlinkDataStreams"
630
1292
  }
631
1293
  ]
632
1294
  }
@@ -662,6 +1324,37 @@ const types = [
662
1324
  }
663
1325
  ]
664
1326
  }
1327
+ },
1328
+ {
1329
+ name: "V11FeedSessionType",
1330
+ docs: [
1331
+ "Trading-session scope for a V11 (24/5 US Equities) feed.",
1332
+ "",
1333
+ "Chainlink publishes a `market_status` field in every v11 report that indicates which",
1334
+ "trading phase is currently active. This is done here because even when market is not",
1335
+ "in session chainlink feeds can public other sessions data.",
1336
+ "This enum captures which phases are valid for a given feed so that reports arriving",
1337
+ "with an unsupported status can be rejected early rather than silently accepted.",
1338
+ "",
1339
+ "For non-V11 feed entries (`report_type != RWAAdvanced`) this field is ignored."
1340
+ ],
1341
+ repr: {
1342
+ kind: "rust"
1343
+ },
1344
+ type: {
1345
+ kind: "enum",
1346
+ variants: [
1347
+ {
1348
+ name: "Regular"
1349
+ },
1350
+ {
1351
+ name: "Extended"
1352
+ },
1353
+ {
1354
+ name: "Overnight"
1355
+ }
1356
+ ]
1357
+ }
665
1358
  }
666
1359
  ];
667
1360
  const oracle = {
@@ -1022,7 +1715,9 @@ const EXCHANGE_PRICES_PRECISION = new BN(10).pow(new BN(12));
1022
1715
  const ZERO_TICK_SCALED_RATIO = new BN(281474976710656);
1023
1716
  const TICK_SPACING = new BN(10015);
1024
1717
  const X30 = new BN(1073741823);
1025
- const MIN_I128$1 = new BN("170141183460469231731687303715884105728").neg();
1718
+ const MIN_I128 = new BN("170141183460469231731687303715884105728").neg();
1719
+ const MAX_REPAY_AMOUNT = MIN_I128;
1720
+ const MAX_WITHDRAW_AMOUNT = MIN_I128;
1026
1721
  const getAccountOwner = async (account, connection) => {
1027
1722
  const info = await connection.getAccountInfo(account);
1028
1723
  if (!info)
@@ -1295,10 +1990,10 @@ const getFinalPosition = async ({
1295
1990
  colRaw = colRaw.add(supplyRaw);
1296
1991
  } else if (newColAmount.lt(new BN(0))) {
1297
1992
  let withdrawRaw = new BN(0);
1298
- if (newColAmount.gt(MIN_I128$1)) {
1993
+ if (newColAmount.gt(MIN_I128)) {
1299
1994
  withdrawRaw = newColAmount.abs().mul(EXCHANGE_PRICES_PRECISION).div(supplyExPrice).sub(new BN(1));
1300
1995
  colRaw = colRaw.sub(withdrawRaw);
1301
- } else if (newColAmount.eq(MIN_I128$1)) {
1996
+ } else if (newColAmount.eq(MIN_I128)) {
1302
1997
  withdrawRaw = colRaw.mul(supplyExPrice).div(EXCHANGE_PRICES_PRECISION).mul(new BN(-1)).add(new BN(1));
1303
1998
  colRaw = new BN(0);
1304
1999
  } else {
@@ -1311,10 +2006,10 @@ const getFinalPosition = async ({
1311
2006
  const borrowAmountWithFee = borrowRaw.add(feeAmount);
1312
2007
  debtRaw = debtRaw.add(borrowAmountWithFee);
1313
2008
  } else if (newDebtAmount.lt(new BN(0))) {
1314
- if (newDebtAmount.gt(MIN_I128$1)) {
2009
+ if (newDebtAmount.gt(MIN_I128)) {
1315
2010
  const payback_amount = newDebtAmount.abs().mul(EXCHANGE_PRICES_PRECISION).div(borrowExPrice).add(new BN(1));
1316
2011
  debtRaw = debtRaw.sub(payback_amount);
1317
- } else if (newDebtAmount.eq(MIN_I128$1)) {
2012
+ } else if (newDebtAmount.eq(MIN_I128)) {
1318
2013
  debtRaw = new BN(0);
1319
2014
  } else {
1320
2015
  throw new Error("Invalid newDebtAmount");
@@ -1552,7 +2247,6 @@ const MPL_TOKEN_METADATA_PROGRAM_ID = new PublicKey(
1552
2247
  "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
1553
2248
  );
1554
2249
  const LIQUIDITY_PROGRAM_ID = new PublicKey(liquidity.address);
1555
- const MIN_I128 = new BN("170141183460469231731687303715884105728").neg();
1556
2250
  async function getOtherInstructionsOperate(vaultId, vaultState, currentPosition, finalPosition, currentTick, currentTickId, program, signer) {
1557
2251
  const otherIxs = [];
1558
2252
  const tickToRead = [currentTick];
@@ -1958,11 +2652,14 @@ const getOperateIx = async ({
1958
2652
  program
1959
2653
  });
1960
2654
  if (accounts.borrowToken.toString() !== NATIVE_MINT.toString() && debtAmount.lt(new BN(0))) {
1961
- const userDebtTokenBalance = await connection.getTokenAccountBalance(
1962
- accounts.signerBorrowTokenAccount
1963
- );
1964
- if (userDebtTokenBalance.value.amount === debtAmount.abs().toString()) {
1965
- debtAmount = debtAmount.add(new BN(1));
2655
+ try {
2656
+ const userDebtTokenBalance = await connection.getTokenAccountBalance(
2657
+ accounts.signerBorrowTokenAccount
2658
+ );
2659
+ if (userDebtTokenBalance.value.amount === debtAmount.abs().toString()) {
2660
+ debtAmount = debtAmount.add(new BN(1));
2661
+ }
2662
+ } catch (error) {
1966
2663
  }
1967
2664
  }
1968
2665
  const [operateIx, addressLookupTable] = await Promise.all([
@@ -2320,4 +3017,4 @@ async function getRemainingAccountsLiquidate(vaultId, vaultState, vaultConfig, o
2320
3017
  };
2321
3018
  }
2322
3019
 
2323
- export { findNextTickWithDebt as A, INIT_TICK as I, MIN_TICK$1 as M, TICK_HAS_DEBT_ARRAY_SIZE as T, ZERO_TICK_SCALED_RATIO$1 as Z, getVaultsProgram as a, getOperateContext as b, getInitPositionIx as c, getInitPositionContext as d, getOperateIx as e, getLiquidateContext as f, getLiquidateIx as g, getAccountOwner as h, getCurrentPosition as i, getCurrentPositionState as j, getFinalPosition as k, loadRelevantBranches as l, loadRelevantTicksHasDebtArrays as m, loadRelevantTicksHasDebtArraysLiquidate as n, loadRelevantBranchesForLiquidate as o, MAX_TICK$1 as p, TICKS_PER_TICK_HAS_DEBT as q, readOraclePrice as r, TICK_HAS_DEBT_CHILDREN_SIZE as s, TICK_HAS_DEBT_CHILDREN_SIZE_IN_BITS as t, TOTAL_INDICES_NEEDED as u, getRatioAtTick as v, getTickAtRatio as w, getFirstTickForIndex as x, getTickIndices as y, readTickHasDebtArray as z };
3020
+ export { getFirstTickForIndex as A, getTickIndices as B, readTickHasDebtArray as C, findNextTickWithDebt as D, INIT_TICK as I, MIN_I128 as M, TICK_HAS_DEBT_ARRAY_SIZE as T, ZERO_TICK_SCALED_RATIO$1 as Z, getVaultsProgram as a, getOperateContext as b, getInitPositionIx as c, getInitPositionContext as d, getOperateIx as e, getLiquidateContext as f, getLiquidateIx as g, MAX_REPAY_AMOUNT as h, MAX_WITHDRAW_AMOUNT as i, getAccountOwner as j, getCurrentPosition as k, getCurrentPositionState as l, getFinalPosition as m, loadRelevantBranches as n, loadRelevantTicksHasDebtArrays as o, loadRelevantTicksHasDebtArraysLiquidate as p, loadRelevantBranchesForLiquidate as q, readOraclePrice as r, MIN_TICK$1 as s, MAX_TICK$1 as t, TICKS_PER_TICK_HAS_DEBT as u, TICK_HAS_DEBT_CHILDREN_SIZE as v, TICK_HAS_DEBT_CHILDREN_SIZE_IN_BITS as w, TOTAL_INDICES_NEEDED as x, getRatioAtTick as y, getTickAtRatio as z };