@gearbox-protocol/sdk 3.0.0-vfour.1 → 3.0.0-vfour.11

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.
@@ -0,0 +1,781 @@
1
+ 'use strict';
2
+
3
+ var sdk = require('../sdk');
4
+ var viem = require('viem');
5
+
6
+ // src/dev/calcLiquidatableLTs.ts
7
+ async function calcLiquidatableLTs(sdk$1, ca, factor = 9990n) {
8
+ const cm = sdk$1.marketRegister.findCreditManager(ca.creditManager);
9
+ const market = sdk$1.marketRegister.findByCreditManager(ca.creditManager);
10
+ const weightedBalances = ca.tokens.map((t) => {
11
+ const { token, balance } = t;
12
+ const balanceU = market.priceOracle.convertToUnderlying(token, balance);
13
+ const lt = BigInt(cm.collateralTokens[token]);
14
+ return {
15
+ token,
16
+ weightedBalance: balanceU * lt / sdk.PERCENTAGE_FACTOR,
17
+ lt
18
+ };
19
+ }).sort((a, b) => {
20
+ if (a.token === ca.underlying) return 1;
21
+ if (b.token === ca.underlying) return -1;
22
+ return b.weightedBalance > a.weightedBalance ? 1 : -1;
23
+ });
24
+ let divisor = 0n;
25
+ let dividend = factor * (ca.debt + ca.accruedInterest + ca.accruedFees) / sdk.PERCENTAGE_FACTOR;
26
+ for (const { token, weightedBalance } of weightedBalances) {
27
+ if (token === ca.underlying) {
28
+ dividend -= weightedBalance;
29
+ } else {
30
+ divisor += weightedBalance;
31
+ }
32
+ }
33
+ if (divisor === 0n) {
34
+ throw new Error("warning: assets have zero weighted value in underlying");
35
+ }
36
+ if (dividend <= 0n) {
37
+ throw new Error(`warning: account balance in underlying covers debt`);
38
+ }
39
+ const k = sdk.WAD * dividend / divisor;
40
+ const result = {};
41
+ for (const { token, lt: oldLT } of weightedBalances) {
42
+ if (token !== ca.underlying) {
43
+ const newLT = oldLT * k / sdk.WAD;
44
+ result[token] = [Number(oldLT), Number(newLT)];
45
+ }
46
+ }
47
+ return result;
48
+ }
49
+
50
+ // src/dev/abi/v3.ts
51
+ var iaclAbi = [
52
+ {
53
+ type: "function",
54
+ inputs: [{ name: "account", internalType: "address", type: "address" }],
55
+ name: "isConfigurator",
56
+ outputs: [{ name: "", internalType: "bool", type: "bool" }],
57
+ stateMutability: "view"
58
+ },
59
+ {
60
+ type: "function",
61
+ inputs: [{ name: "addr", internalType: "address", type: "address" }],
62
+ name: "isPausableAdmin",
63
+ outputs: [{ name: "", internalType: "bool", type: "bool" }],
64
+ stateMutability: "view"
65
+ },
66
+ {
67
+ type: "function",
68
+ inputs: [{ name: "addr", internalType: "address", type: "address" }],
69
+ name: "isUnpausableAdmin",
70
+ outputs: [{ name: "", internalType: "bool", type: "bool" }],
71
+ stateMutability: "view"
72
+ },
73
+ {
74
+ type: "function",
75
+ inputs: [],
76
+ name: "owner",
77
+ outputs: [{ name: "", internalType: "address", type: "address" }],
78
+ stateMutability: "view"
79
+ },
80
+ {
81
+ type: "function",
82
+ inputs: [],
83
+ name: "version",
84
+ outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
85
+ stateMutability: "view"
86
+ },
87
+ {
88
+ type: "event",
89
+ anonymous: false,
90
+ inputs: [
91
+ {
92
+ name: "newAdmin",
93
+ internalType: "address",
94
+ type: "address",
95
+ indexed: true
96
+ }
97
+ ],
98
+ name: "PausableAdminAdded"
99
+ },
100
+ {
101
+ type: "event",
102
+ anonymous: false,
103
+ inputs: [
104
+ {
105
+ name: "admin",
106
+ internalType: "address",
107
+ type: "address",
108
+ indexed: true
109
+ }
110
+ ],
111
+ name: "PausableAdminRemoved"
112
+ },
113
+ {
114
+ type: "event",
115
+ anonymous: false,
116
+ inputs: [
117
+ {
118
+ name: "newAdmin",
119
+ internalType: "address",
120
+ type: "address",
121
+ indexed: true
122
+ }
123
+ ],
124
+ name: "UnpausableAdminAdded"
125
+ },
126
+ {
127
+ type: "event",
128
+ anonymous: false,
129
+ inputs: [
130
+ {
131
+ name: "admin",
132
+ internalType: "address",
133
+ type: "address",
134
+ indexed: true
135
+ }
136
+ ],
137
+ name: "UnpausableAdminRemoved"
138
+ },
139
+ {
140
+ type: "error",
141
+ inputs: [{ name: "addr", internalType: "address", type: "address" }],
142
+ name: "AddressNotPausableAdminException"
143
+ },
144
+ {
145
+ type: "error",
146
+ inputs: [{ name: "addr", internalType: "address", type: "address" }],
147
+ name: "AddressNotUnpausableAdminException"
148
+ }
149
+ ];
150
+ var iCreditConfiguratorV3Abi = [
151
+ {
152
+ type: "function",
153
+ inputs: [
154
+ { name: "token", internalType: "address", type: "address" },
155
+ { name: "liquidationThreshold", internalType: "uint16", type: "uint16" }
156
+ ],
157
+ name: "addCollateralToken",
158
+ outputs: [],
159
+ stateMutability: "nonpayable"
160
+ },
161
+ {
162
+ type: "function",
163
+ inputs: [{ name: "liquidator", internalType: "address", type: "address" }],
164
+ name: "addEmergencyLiquidator",
165
+ outputs: [],
166
+ stateMutability: "nonpayable"
167
+ },
168
+ {
169
+ type: "function",
170
+ inputs: [],
171
+ name: "addressProvider",
172
+ outputs: [{ name: "", internalType: "address", type: "address" }],
173
+ stateMutability: "view"
174
+ },
175
+ {
176
+ type: "function",
177
+ inputs: [{ name: "adapter", internalType: "address", type: "address" }],
178
+ name: "allowAdapter",
179
+ outputs: [],
180
+ stateMutability: "nonpayable"
181
+ },
182
+ {
183
+ type: "function",
184
+ inputs: [{ name: "token", internalType: "address", type: "address" }],
185
+ name: "allowToken",
186
+ outputs: [],
187
+ stateMutability: "nonpayable"
188
+ },
189
+ {
190
+ type: "function",
191
+ inputs: [],
192
+ name: "allowedAdapters",
193
+ outputs: [{ name: "", internalType: "address[]", type: "address[]" }],
194
+ stateMutability: "view"
195
+ },
196
+ {
197
+ type: "function",
198
+ inputs: [],
199
+ name: "creditFacade",
200
+ outputs: [{ name: "", internalType: "address", type: "address" }],
201
+ stateMutability: "view"
202
+ },
203
+ {
204
+ type: "function",
205
+ inputs: [],
206
+ name: "creditManager",
207
+ outputs: [{ name: "", internalType: "address", type: "address" }],
208
+ stateMutability: "view"
209
+ },
210
+ {
211
+ type: "function",
212
+ inputs: [],
213
+ name: "emergencyLiquidators",
214
+ outputs: [{ name: "", internalType: "address[]", type: "address[]" }],
215
+ stateMutability: "view"
216
+ },
217
+ {
218
+ type: "function",
219
+ inputs: [{ name: "adapter", internalType: "address", type: "address" }],
220
+ name: "forbidAdapter",
221
+ outputs: [],
222
+ stateMutability: "nonpayable"
223
+ },
224
+ {
225
+ type: "function",
226
+ inputs: [],
227
+ name: "forbidBorrowing",
228
+ outputs: [],
229
+ stateMutability: "nonpayable"
230
+ },
231
+ {
232
+ type: "function",
233
+ inputs: [{ name: "token", internalType: "address", type: "address" }],
234
+ name: "forbidToken",
235
+ outputs: [],
236
+ stateMutability: "nonpayable"
237
+ },
238
+ {
239
+ type: "function",
240
+ inputs: [{ name: "token", internalType: "address", type: "address" }],
241
+ name: "makeTokenQuoted",
242
+ outputs: [],
243
+ stateMutability: "nonpayable"
244
+ },
245
+ {
246
+ type: "function",
247
+ inputs: [
248
+ { name: "token", internalType: "address", type: "address" },
249
+ {
250
+ name: "liquidationThresholdFinal",
251
+ internalType: "uint16",
252
+ type: "uint16"
253
+ },
254
+ { name: "rampStart", internalType: "uint40", type: "uint40" },
255
+ { name: "rampDuration", internalType: "uint24", type: "uint24" }
256
+ ],
257
+ name: "rampLiquidationThreshold",
258
+ outputs: [],
259
+ stateMutability: "nonpayable"
260
+ },
261
+ {
262
+ type: "function",
263
+ inputs: [{ name: "liquidator", internalType: "address", type: "address" }],
264
+ name: "removeEmergencyLiquidator",
265
+ outputs: [],
266
+ stateMutability: "nonpayable"
267
+ },
268
+ {
269
+ type: "function",
270
+ inputs: [],
271
+ name: "resetCumulativeLoss",
272
+ outputs: [],
273
+ stateMutability: "nonpayable"
274
+ },
275
+ {
276
+ type: "function",
277
+ inputs: [{ name: "newVersion", internalType: "uint256", type: "uint256" }],
278
+ name: "setBotList",
279
+ outputs: [],
280
+ stateMutability: "nonpayable"
281
+ },
282
+ {
283
+ type: "function",
284
+ inputs: [
285
+ { name: "newCreditFacade", internalType: "address", type: "address" },
286
+ { name: "migrateParams", internalType: "bool", type: "bool" }
287
+ ],
288
+ name: "setCreditFacade",
289
+ outputs: [],
290
+ stateMutability: "nonpayable"
291
+ },
292
+ {
293
+ type: "function",
294
+ inputs: [
295
+ { name: "newExpirationDate", internalType: "uint40", type: "uint40" }
296
+ ],
297
+ name: "setExpirationDate",
298
+ outputs: [],
299
+ stateMutability: "nonpayable"
300
+ },
301
+ {
302
+ type: "function",
303
+ inputs: [
304
+ { name: "feeInterest", internalType: "uint16", type: "uint16" },
305
+ { name: "feeLiquidation", internalType: "uint16", type: "uint16" },
306
+ { name: "liquidationPremium", internalType: "uint16", type: "uint16" },
307
+ { name: "feeLiquidationExpired", internalType: "uint16", type: "uint16" },
308
+ {
309
+ name: "liquidationPremiumExpired",
310
+ internalType: "uint16",
311
+ type: "uint16"
312
+ }
313
+ ],
314
+ name: "setFees",
315
+ outputs: [],
316
+ stateMutability: "nonpayable"
317
+ },
318
+ {
319
+ type: "function",
320
+ inputs: [
321
+ { name: "token", internalType: "address", type: "address" },
322
+ { name: "liquidationThreshold", internalType: "uint16", type: "uint16" }
323
+ ],
324
+ name: "setLiquidationThreshold",
325
+ outputs: [],
326
+ stateMutability: "nonpayable"
327
+ },
328
+ {
329
+ type: "function",
330
+ inputs: [
331
+ {
332
+ name: "newMaxCumulativeLoss",
333
+ internalType: "uint128",
334
+ type: "uint128"
335
+ }
336
+ ],
337
+ name: "setMaxCumulativeLoss",
338
+ outputs: [],
339
+ stateMutability: "nonpayable"
340
+ },
341
+ {
342
+ type: "function",
343
+ inputs: [{ name: "newMaxDebt", internalType: "uint128", type: "uint128" }],
344
+ name: "setMaxDebtLimit",
345
+ outputs: [],
346
+ stateMutability: "nonpayable"
347
+ },
348
+ {
349
+ type: "function",
350
+ inputs: [
351
+ {
352
+ name: "newMaxDebtLimitPerBlockMultiplier",
353
+ internalType: "uint8",
354
+ type: "uint8"
355
+ }
356
+ ],
357
+ name: "setMaxDebtPerBlockMultiplier",
358
+ outputs: [],
359
+ stateMutability: "nonpayable"
360
+ },
361
+ {
362
+ type: "function",
363
+ inputs: [
364
+ { name: "newMaxEnabledTokens", internalType: "uint8", type: "uint8" }
365
+ ],
366
+ name: "setMaxEnabledTokens",
367
+ outputs: [],
368
+ stateMutability: "nonpayable"
369
+ },
370
+ {
371
+ type: "function",
372
+ inputs: [{ name: "newMinDebt", internalType: "uint128", type: "uint128" }],
373
+ name: "setMinDebtLimit",
374
+ outputs: [],
375
+ stateMutability: "nonpayable"
376
+ },
377
+ {
378
+ type: "function",
379
+ inputs: [{ name: "newVersion", internalType: "uint256", type: "uint256" }],
380
+ name: "setPriceOracle",
381
+ outputs: [],
382
+ stateMutability: "nonpayable"
383
+ },
384
+ {
385
+ type: "function",
386
+ inputs: [],
387
+ name: "underlying",
388
+ outputs: [{ name: "", internalType: "address", type: "address" }],
389
+ stateMutability: "view"
390
+ },
391
+ {
392
+ type: "function",
393
+ inputs: [
394
+ {
395
+ name: "newCreditConfigurator",
396
+ internalType: "address",
397
+ type: "address"
398
+ }
399
+ ],
400
+ name: "upgradeCreditConfigurator",
401
+ outputs: [],
402
+ stateMutability: "nonpayable"
403
+ },
404
+ {
405
+ type: "function",
406
+ inputs: [],
407
+ name: "version",
408
+ outputs: [{ name: "", internalType: "uint256", type: "uint256" }],
409
+ stateMutability: "view"
410
+ },
411
+ {
412
+ type: "event",
413
+ anonymous: false,
414
+ inputs: [
415
+ {
416
+ name: "token",
417
+ internalType: "address",
418
+ type: "address",
419
+ indexed: true
420
+ }
421
+ ],
422
+ name: "AddCollateralToken"
423
+ },
424
+ {
425
+ type: "event",
426
+ anonymous: false,
427
+ inputs: [
428
+ {
429
+ name: "liquidator",
430
+ internalType: "address",
431
+ type: "address",
432
+ indexed: true
433
+ }
434
+ ],
435
+ name: "AddEmergencyLiquidator"
436
+ },
437
+ {
438
+ type: "event",
439
+ anonymous: false,
440
+ inputs: [
441
+ {
442
+ name: "targetContract",
443
+ internalType: "address",
444
+ type: "address",
445
+ indexed: true
446
+ },
447
+ {
448
+ name: "adapter",
449
+ internalType: "address",
450
+ type: "address",
451
+ indexed: true
452
+ }
453
+ ],
454
+ name: "AllowAdapter"
455
+ },
456
+ {
457
+ type: "event",
458
+ anonymous: false,
459
+ inputs: [
460
+ {
461
+ name: "token",
462
+ internalType: "address",
463
+ type: "address",
464
+ indexed: true
465
+ }
466
+ ],
467
+ name: "AllowToken"
468
+ },
469
+ {
470
+ type: "event",
471
+ anonymous: false,
472
+ inputs: [
473
+ {
474
+ name: "creditConfigurator",
475
+ internalType: "address",
476
+ type: "address",
477
+ indexed: true
478
+ }
479
+ ],
480
+ name: "CreditConfiguratorUpgraded"
481
+ },
482
+ {
483
+ type: "event",
484
+ anonymous: false,
485
+ inputs: [
486
+ {
487
+ name: "targetContract",
488
+ internalType: "address",
489
+ type: "address",
490
+ indexed: true
491
+ },
492
+ {
493
+ name: "adapter",
494
+ internalType: "address",
495
+ type: "address",
496
+ indexed: true
497
+ }
498
+ ],
499
+ name: "ForbidAdapter"
500
+ },
501
+ {
502
+ type: "event",
503
+ anonymous: false,
504
+ inputs: [
505
+ {
506
+ name: "token",
507
+ internalType: "address",
508
+ type: "address",
509
+ indexed: true
510
+ }
511
+ ],
512
+ name: "ForbidToken"
513
+ },
514
+ {
515
+ type: "event",
516
+ anonymous: false,
517
+ inputs: [
518
+ {
519
+ name: "token",
520
+ internalType: "address",
521
+ type: "address",
522
+ indexed: true
523
+ }
524
+ ],
525
+ name: "QuoteToken"
526
+ },
527
+ {
528
+ type: "event",
529
+ anonymous: false,
530
+ inputs: [
531
+ {
532
+ name: "liquidator",
533
+ internalType: "address",
534
+ type: "address",
535
+ indexed: true
536
+ }
537
+ ],
538
+ name: "RemoveEmergencyLiquidator"
539
+ },
540
+ { type: "event", anonymous: false, inputs: [], name: "ResetCumulativeLoss" },
541
+ {
542
+ type: "event",
543
+ anonymous: false,
544
+ inputs: [
545
+ {
546
+ name: "token",
547
+ internalType: "address",
548
+ type: "address",
549
+ indexed: true
550
+ },
551
+ {
552
+ name: "liquidationThresholdInitial",
553
+ internalType: "uint16",
554
+ type: "uint16",
555
+ indexed: false
556
+ },
557
+ {
558
+ name: "liquidationThresholdFinal",
559
+ internalType: "uint16",
560
+ type: "uint16",
561
+ indexed: false
562
+ },
563
+ {
564
+ name: "timestampRampStart",
565
+ internalType: "uint40",
566
+ type: "uint40",
567
+ indexed: false
568
+ },
569
+ {
570
+ name: "timestampRampEnd",
571
+ internalType: "uint40",
572
+ type: "uint40",
573
+ indexed: false
574
+ }
575
+ ],
576
+ name: "ScheduleTokenLiquidationThresholdRamp"
577
+ },
578
+ {
579
+ type: "event",
580
+ anonymous: false,
581
+ inputs: [
582
+ {
583
+ name: "minDebt",
584
+ internalType: "uint256",
585
+ type: "uint256",
586
+ indexed: false
587
+ },
588
+ {
589
+ name: "maxDebt",
590
+ internalType: "uint256",
591
+ type: "uint256",
592
+ indexed: false
593
+ }
594
+ ],
595
+ name: "SetBorrowingLimits"
596
+ },
597
+ {
598
+ type: "event",
599
+ anonymous: false,
600
+ inputs: [
601
+ {
602
+ name: "botList",
603
+ internalType: "address",
604
+ type: "address",
605
+ indexed: true
606
+ }
607
+ ],
608
+ name: "SetBotList"
609
+ },
610
+ {
611
+ type: "event",
612
+ anonymous: false,
613
+ inputs: [
614
+ {
615
+ name: "creditFacade",
616
+ internalType: "address",
617
+ type: "address",
618
+ indexed: true
619
+ }
620
+ ],
621
+ name: "SetCreditFacade"
622
+ },
623
+ {
624
+ type: "event",
625
+ anonymous: false,
626
+ inputs: [
627
+ {
628
+ name: "expirationDate",
629
+ internalType: "uint40",
630
+ type: "uint40",
631
+ indexed: false
632
+ }
633
+ ],
634
+ name: "SetExpirationDate"
635
+ },
636
+ {
637
+ type: "event",
638
+ anonymous: false,
639
+ inputs: [
640
+ {
641
+ name: "maxCumulativeLoss",
642
+ internalType: "uint128",
643
+ type: "uint128",
644
+ indexed: false
645
+ }
646
+ ],
647
+ name: "SetMaxCumulativeLoss"
648
+ },
649
+ {
650
+ type: "event",
651
+ anonymous: false,
652
+ inputs: [
653
+ {
654
+ name: "maxDebtPerBlockMultiplier",
655
+ internalType: "uint8",
656
+ type: "uint8",
657
+ indexed: false
658
+ }
659
+ ],
660
+ name: "SetMaxDebtPerBlockMultiplier"
661
+ },
662
+ {
663
+ type: "event",
664
+ anonymous: false,
665
+ inputs: [
666
+ {
667
+ name: "maxEnabledTokens",
668
+ internalType: "uint8",
669
+ type: "uint8",
670
+ indexed: false
671
+ }
672
+ ],
673
+ name: "SetMaxEnabledTokens"
674
+ },
675
+ {
676
+ type: "event",
677
+ anonymous: false,
678
+ inputs: [
679
+ {
680
+ name: "priceOracle",
681
+ internalType: "address",
682
+ type: "address",
683
+ indexed: true
684
+ }
685
+ ],
686
+ name: "SetPriceOracle"
687
+ },
688
+ {
689
+ type: "event",
690
+ anonymous: false,
691
+ inputs: [
692
+ {
693
+ name: "token",
694
+ internalType: "address",
695
+ type: "address",
696
+ indexed: true
697
+ },
698
+ {
699
+ name: "liquidationThreshold",
700
+ internalType: "uint16",
701
+ type: "uint16",
702
+ indexed: false
703
+ }
704
+ ],
705
+ name: "SetTokenLiquidationThreshold"
706
+ },
707
+ {
708
+ type: "event",
709
+ anonymous: false,
710
+ inputs: [
711
+ {
712
+ name: "feeInterest",
713
+ internalType: "uint16",
714
+ type: "uint16",
715
+ indexed: false
716
+ },
717
+ {
718
+ name: "feeLiquidation",
719
+ internalType: "uint16",
720
+ type: "uint16",
721
+ indexed: false
722
+ },
723
+ {
724
+ name: "liquidationPremium",
725
+ internalType: "uint16",
726
+ type: "uint16",
727
+ indexed: false
728
+ },
729
+ {
730
+ name: "feeLiquidationExpired",
731
+ internalType: "uint16",
732
+ type: "uint16",
733
+ indexed: false
734
+ },
735
+ {
736
+ name: "liquidationPremiumExpired",
737
+ internalType: "uint16",
738
+ type: "uint16",
739
+ indexed: false
740
+ }
741
+ ],
742
+ name: "UpdateFees"
743
+ }
744
+ ];
745
+
746
+ // src/dev/setLTs.ts
747
+ async function setLTs(sdk$1, cm, newLTs) {
748
+ const aclAddr = sdk$1.addressProvider.getLatestVersion(sdk.AP_ACL);
749
+ const configuratorAddr = await sdk$1.provider.publicClient.readContract({
750
+ address: aclAddr,
751
+ abi: iaclAbi,
752
+ functionName: "owner"
753
+ });
754
+ const anvil = sdk.createAnvilClient({
755
+ transport: sdk$1.provider.transport,
756
+ chain: sdk$1.provider.chain
757
+ });
758
+ await anvil.impersonateAccount({
759
+ address: configuratorAddr
760
+ });
761
+ await anvil.setBalance({
762
+ address: configuratorAddr,
763
+ value: viem.parseEther("100")
764
+ });
765
+ for (const [t, lt] of Object.entries(newLTs)) {
766
+ await anvil.writeContract({
767
+ chain: anvil.chain,
768
+ address: cm.creditConfigurator.address,
769
+ account: configuratorAddr,
770
+ abi: iCreditConfiguratorV3Abi,
771
+ functionName: "setLiquidationThreshold",
772
+ args: [t, lt]
773
+ });
774
+ }
775
+ await anvil.stopImpersonatingAccount({
776
+ address: configuratorAddr
777
+ });
778
+ }
779
+
780
+ exports.calcLiquidatableLTs = calcLiquidatableLTs;
781
+ exports.setLTs = setLTs;