@gearbox-protocol/sdk 10.4.5 → 10.6.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/cjs/abi/310/generated.js +239 -25
- package/dist/cjs/dev/RevolverTransport.js +124 -83
- package/dist/cjs/sdk/market/MarketSuite.js +4 -0
- package/dist/cjs/sdk/market/credit/CreditFacadeV300Contract.js +4 -1
- package/dist/cjs/sdk/market/credit/CreditFacadeV310Contract.js +2 -2
- package/dist/cjs/sdk/market/loss-policy/AliasLossPolicyV310Contract.js +40 -0
- package/dist/cjs/sdk/market/loss-policy/LossPolicyContract.js +40 -0
- package/dist/cjs/sdk/market/loss-policy/createLossPolicy.js +48 -0
- package/dist/cjs/sdk/market/loss-policy/index.js +28 -0
- package/dist/cjs/sdk/market/loss-policy/types.js +16 -0
- package/dist/esm/abi/310/generated.js +238 -25
- package/dist/esm/dev/RevolverTransport.js +125 -83
- package/dist/esm/sdk/market/MarketSuite.js +6 -0
- package/dist/esm/sdk/market/credit/CreditFacadeV300Contract.js +4 -1
- package/dist/esm/sdk/market/credit/CreditFacadeV310Contract.js +2 -2
- package/dist/esm/sdk/market/loss-policy/AliasLossPolicyV310Contract.js +16 -0
- package/dist/esm/sdk/market/loss-policy/LossPolicyContract.js +16 -0
- package/dist/esm/sdk/market/loss-policy/createLossPolicy.js +24 -0
- package/dist/esm/sdk/market/loss-policy/index.js +4 -0
- package/dist/esm/sdk/market/loss-policy/types.js +0 -0
- package/dist/types/abi/310/generated.d.ts +292 -22
- package/dist/types/dev/RevolverTransport.d.ts +14 -6
- package/dist/types/sdk/market/MarketSuite.d.ts +2 -0
- package/dist/types/sdk/market/credit/CreditFacadeV300Contract.d.ts +2 -2
- package/dist/types/sdk/market/credit/CreditFacadeV310Contract.d.ts +2 -2
- package/dist/types/sdk/market/loss-policy/AliasLossPolicyV310Contract.d.ts +277 -0
- package/dist/types/sdk/market/loss-policy/LossPolicyContract.d.ts +133 -0
- package/dist/types/sdk/market/loss-policy/createLossPolicy.d.ts +16 -0
- package/dist/types/sdk/market/loss-policy/index.d.ts +4 -0
- package/dist/types/sdk/market/loss-policy/types.d.ts +5 -0
- package/dist/types/sdk/types/state-human.d.ts +1 -0
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var generated_exports = {};
|
|
20
20
|
__export(generated_exports, {
|
|
21
21
|
iAddressProviderV310Abi: () => iAddressProviderV310Abi,
|
|
22
|
+
iAliasedLossPolicyV310Abi: () => iAliasedLossPolicyV310Abi,
|
|
22
23
|
iBotListV310Abi: () => iBotListV310Abi,
|
|
23
24
|
iCreditConfiguratorV310Abi: () => iCreditConfiguratorV310Abi,
|
|
24
25
|
iCreditFacadeMulticallV310Abi: () => iCreditFacadeMulticallV310Abi,
|
|
@@ -2361,101 +2362,313 @@ const iGaugeV310Abi = [
|
|
|
2361
2362
|
const iLossPolicyV310Abi = [
|
|
2362
2363
|
{
|
|
2363
2364
|
type: "function",
|
|
2364
|
-
inputs: [],
|
|
2365
2365
|
name: "accessMode",
|
|
2366
|
+
inputs: [],
|
|
2366
2367
|
outputs: [
|
|
2367
|
-
{ name: "", internalType: "enum ILossPolicy.AccessMode"
|
|
2368
|
+
{ name: "", type: "uint8", internalType: "enum ILossPolicy.AccessMode" }
|
|
2368
2369
|
],
|
|
2369
2370
|
stateMutability: "view"
|
|
2370
2371
|
},
|
|
2371
2372
|
{
|
|
2372
2373
|
type: "function",
|
|
2373
|
-
inputs: [],
|
|
2374
2374
|
name: "checksEnabled",
|
|
2375
|
-
|
|
2375
|
+
inputs: [],
|
|
2376
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
2376
2377
|
stateMutability: "view"
|
|
2377
2378
|
},
|
|
2378
2379
|
{
|
|
2379
2380
|
type: "function",
|
|
2380
|
-
inputs: [],
|
|
2381
2381
|
name: "contractType",
|
|
2382
|
-
|
|
2382
|
+
inputs: [],
|
|
2383
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
2383
2384
|
stateMutability: "view"
|
|
2384
2385
|
},
|
|
2385
2386
|
{
|
|
2386
2387
|
type: "function",
|
|
2388
|
+
name: "isLiquidatableWithLoss",
|
|
2387
2389
|
inputs: [
|
|
2388
|
-
{ name: "creditAccount",
|
|
2389
|
-
{ name: "caller",
|
|
2390
|
+
{ name: "creditAccount", type: "address", internalType: "address" },
|
|
2391
|
+
{ name: "caller", type: "address", internalType: "address" },
|
|
2390
2392
|
{
|
|
2391
2393
|
name: "params",
|
|
2394
|
+
type: "tuple",
|
|
2392
2395
|
internalType: "struct ILossPolicy.Params",
|
|
2396
|
+
components: [
|
|
2397
|
+
{ name: "totalDebtUSD", type: "uint256", internalType: "uint256" },
|
|
2398
|
+
{ name: "twvUSD", type: "uint256", internalType: "uint256" },
|
|
2399
|
+
{ name: "extraData", type: "bytes", internalType: "bytes" }
|
|
2400
|
+
]
|
|
2401
|
+
}
|
|
2402
|
+
],
|
|
2403
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
2404
|
+
stateMutability: "nonpayable"
|
|
2405
|
+
},
|
|
2406
|
+
{
|
|
2407
|
+
type: "function",
|
|
2408
|
+
name: "serialize",
|
|
2409
|
+
inputs: [],
|
|
2410
|
+
outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
|
|
2411
|
+
stateMutability: "view"
|
|
2412
|
+
},
|
|
2413
|
+
{
|
|
2414
|
+
type: "function",
|
|
2415
|
+
name: "setAccessMode",
|
|
2416
|
+
inputs: [
|
|
2417
|
+
{
|
|
2418
|
+
name: "mode",
|
|
2419
|
+
type: "uint8",
|
|
2420
|
+
internalType: "enum ILossPolicy.AccessMode"
|
|
2421
|
+
}
|
|
2422
|
+
],
|
|
2423
|
+
outputs: [],
|
|
2424
|
+
stateMutability: "nonpayable"
|
|
2425
|
+
},
|
|
2426
|
+
{
|
|
2427
|
+
type: "function",
|
|
2428
|
+
name: "setChecksEnabled",
|
|
2429
|
+
inputs: [{ name: "enabled", type: "bool", internalType: "bool" }],
|
|
2430
|
+
outputs: [],
|
|
2431
|
+
stateMutability: "nonpayable"
|
|
2432
|
+
},
|
|
2433
|
+
{
|
|
2434
|
+
type: "function",
|
|
2435
|
+
name: "version",
|
|
2436
|
+
inputs: [],
|
|
2437
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
2438
|
+
stateMutability: "view"
|
|
2439
|
+
},
|
|
2440
|
+
{
|
|
2441
|
+
type: "event",
|
|
2442
|
+
name: "SetAccessMode",
|
|
2443
|
+
inputs: [
|
|
2444
|
+
{
|
|
2445
|
+
name: "mode",
|
|
2446
|
+
type: "uint8",
|
|
2447
|
+
indexed: false,
|
|
2448
|
+
internalType: "enum ILossPolicy.AccessMode"
|
|
2449
|
+
}
|
|
2450
|
+
],
|
|
2451
|
+
anonymous: false
|
|
2452
|
+
},
|
|
2453
|
+
{
|
|
2454
|
+
type: "event",
|
|
2455
|
+
name: "SetChecksEnabled",
|
|
2456
|
+
inputs: [
|
|
2457
|
+
{ name: "enabled", type: "bool", indexed: false, internalType: "bool" }
|
|
2458
|
+
],
|
|
2459
|
+
anonymous: false
|
|
2460
|
+
}
|
|
2461
|
+
];
|
|
2462
|
+
const iAliasedLossPolicyV310Abi = [
|
|
2463
|
+
{
|
|
2464
|
+
type: "function",
|
|
2465
|
+
name: "accessMode",
|
|
2466
|
+
inputs: [],
|
|
2467
|
+
outputs: [
|
|
2468
|
+
{ name: "", type: "uint8", internalType: "enum ILossPolicy.AccessMode" }
|
|
2469
|
+
],
|
|
2470
|
+
stateMutability: "view"
|
|
2471
|
+
},
|
|
2472
|
+
{
|
|
2473
|
+
type: "function",
|
|
2474
|
+
name: "acl",
|
|
2475
|
+
inputs: [],
|
|
2476
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2477
|
+
stateMutability: "view"
|
|
2478
|
+
},
|
|
2479
|
+
{
|
|
2480
|
+
type: "function",
|
|
2481
|
+
name: "checksEnabled",
|
|
2482
|
+
inputs: [],
|
|
2483
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
2484
|
+
stateMutability: "view"
|
|
2485
|
+
},
|
|
2486
|
+
{
|
|
2487
|
+
type: "function",
|
|
2488
|
+
name: "contractType",
|
|
2489
|
+
inputs: [],
|
|
2490
|
+
outputs: [{ name: "", type: "bytes32", internalType: "bytes32" }],
|
|
2491
|
+
stateMutability: "view"
|
|
2492
|
+
},
|
|
2493
|
+
{
|
|
2494
|
+
type: "function",
|
|
2495
|
+
name: "getAliasPriceFeedParams",
|
|
2496
|
+
inputs: [{ name: "token", type: "address", internalType: "address" }],
|
|
2497
|
+
outputs: [
|
|
2498
|
+
{
|
|
2499
|
+
name: "",
|
|
2393
2500
|
type: "tuple",
|
|
2501
|
+
internalType: "struct PriceFeedParams",
|
|
2394
2502
|
components: [
|
|
2395
|
-
{ name: "
|
|
2396
|
-
{ name: "
|
|
2397
|
-
{ name: "
|
|
2503
|
+
{ name: "priceFeed", type: "address", internalType: "address" },
|
|
2504
|
+
{ name: "stalenessPeriod", type: "uint32", internalType: "uint32" },
|
|
2505
|
+
{ name: "skipCheck", type: "bool", internalType: "bool" },
|
|
2506
|
+
{ name: "tokenDecimals", type: "uint8", internalType: "uint8" }
|
|
2398
2507
|
]
|
|
2399
2508
|
}
|
|
2400
2509
|
],
|
|
2510
|
+
stateMutability: "view"
|
|
2511
|
+
},
|
|
2512
|
+
{
|
|
2513
|
+
type: "function",
|
|
2514
|
+
name: "getRequiredAliasPriceFeeds",
|
|
2515
|
+
inputs: [
|
|
2516
|
+
{ name: "creditAccount", type: "address", internalType: "address" }
|
|
2517
|
+
],
|
|
2518
|
+
outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
|
|
2519
|
+
stateMutability: "view"
|
|
2520
|
+
},
|
|
2521
|
+
{
|
|
2522
|
+
type: "function",
|
|
2523
|
+
name: "getTokensWithAlias",
|
|
2524
|
+
inputs: [],
|
|
2525
|
+
outputs: [{ name: "", type: "address[]", internalType: "address[]" }],
|
|
2526
|
+
stateMutability: "view"
|
|
2527
|
+
},
|
|
2528
|
+
{
|
|
2529
|
+
type: "function",
|
|
2401
2530
|
name: "isLiquidatableWithLoss",
|
|
2402
|
-
|
|
2531
|
+
inputs: [
|
|
2532
|
+
{ name: "creditAccount", type: "address", internalType: "address" },
|
|
2533
|
+
{ name: "caller", type: "address", internalType: "address" },
|
|
2534
|
+
{
|
|
2535
|
+
name: "params",
|
|
2536
|
+
type: "tuple",
|
|
2537
|
+
internalType: "struct ILossPolicy.Params",
|
|
2538
|
+
components: [
|
|
2539
|
+
{ name: "totalDebtUSD", type: "uint256", internalType: "uint256" },
|
|
2540
|
+
{ name: "twvUSD", type: "uint256", internalType: "uint256" },
|
|
2541
|
+
{ name: "extraData", type: "bytes", internalType: "bytes" }
|
|
2542
|
+
]
|
|
2543
|
+
}
|
|
2544
|
+
],
|
|
2545
|
+
outputs: [{ name: "", type: "bool", internalType: "bool" }],
|
|
2403
2546
|
stateMutability: "nonpayable"
|
|
2404
2547
|
},
|
|
2405
2548
|
{
|
|
2406
2549
|
type: "function",
|
|
2550
|
+
name: "pool",
|
|
2551
|
+
inputs: [],
|
|
2552
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2553
|
+
stateMutability: "view"
|
|
2554
|
+
},
|
|
2555
|
+
{
|
|
2556
|
+
type: "function",
|
|
2557
|
+
name: "priceFeedStore",
|
|
2407
2558
|
inputs: [],
|
|
2559
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2560
|
+
stateMutability: "view"
|
|
2561
|
+
},
|
|
2562
|
+
{
|
|
2563
|
+
type: "function",
|
|
2408
2564
|
name: "serialize",
|
|
2409
|
-
|
|
2565
|
+
inputs: [],
|
|
2566
|
+
outputs: [{ name: "serializedData", type: "bytes", internalType: "bytes" }],
|
|
2410
2567
|
stateMutability: "view"
|
|
2411
2568
|
},
|
|
2412
2569
|
{
|
|
2413
2570
|
type: "function",
|
|
2571
|
+
name: "setAccessMode",
|
|
2414
2572
|
inputs: [
|
|
2415
2573
|
{
|
|
2416
2574
|
name: "mode",
|
|
2417
|
-
|
|
2418
|
-
|
|
2575
|
+
type: "uint8",
|
|
2576
|
+
internalType: "enum ILossPolicy.AccessMode"
|
|
2419
2577
|
}
|
|
2420
2578
|
],
|
|
2421
|
-
name: "setAccessMode",
|
|
2422
2579
|
outputs: [],
|
|
2423
2580
|
stateMutability: "nonpayable"
|
|
2424
2581
|
},
|
|
2425
2582
|
{
|
|
2426
2583
|
type: "function",
|
|
2427
|
-
|
|
2584
|
+
name: "setAliasPriceFeed",
|
|
2585
|
+
inputs: [
|
|
2586
|
+
{ name: "token", type: "address", internalType: "address" },
|
|
2587
|
+
{ name: "priceFeed", type: "address", internalType: "address" }
|
|
2588
|
+
],
|
|
2589
|
+
outputs: [],
|
|
2590
|
+
stateMutability: "nonpayable"
|
|
2591
|
+
},
|
|
2592
|
+
{
|
|
2593
|
+
type: "function",
|
|
2428
2594
|
name: "setChecksEnabled",
|
|
2595
|
+
inputs: [{ name: "enabled", type: "bool", internalType: "bool" }],
|
|
2429
2596
|
outputs: [],
|
|
2430
2597
|
stateMutability: "nonpayable"
|
|
2431
2598
|
},
|
|
2432
2599
|
{
|
|
2433
2600
|
type: "function",
|
|
2601
|
+
name: "underlying",
|
|
2434
2602
|
inputs: [],
|
|
2603
|
+
outputs: [{ name: "", type: "address", internalType: "address" }],
|
|
2604
|
+
stateMutability: "view"
|
|
2605
|
+
},
|
|
2606
|
+
{
|
|
2607
|
+
type: "function",
|
|
2435
2608
|
name: "version",
|
|
2436
|
-
|
|
2609
|
+
inputs: [],
|
|
2610
|
+
outputs: [{ name: "", type: "uint256", internalType: "uint256" }],
|
|
2437
2611
|
stateMutability: "view"
|
|
2438
2612
|
},
|
|
2439
2613
|
{
|
|
2440
2614
|
type: "event",
|
|
2441
|
-
|
|
2615
|
+
name: "SetAccessMode",
|
|
2442
2616
|
inputs: [
|
|
2443
2617
|
{
|
|
2444
2618
|
name: "mode",
|
|
2445
|
-
internalType: "enum ILossPolicy.AccessMode",
|
|
2446
2619
|
type: "uint8",
|
|
2447
|
-
indexed: false
|
|
2620
|
+
indexed: false,
|
|
2621
|
+
internalType: "enum ILossPolicy.AccessMode"
|
|
2448
2622
|
}
|
|
2449
2623
|
],
|
|
2450
|
-
|
|
2624
|
+
anonymous: false
|
|
2451
2625
|
},
|
|
2452
2626
|
{
|
|
2453
2627
|
type: "event",
|
|
2454
|
-
|
|
2628
|
+
name: "SetAliasPriceFeed",
|
|
2455
2629
|
inputs: [
|
|
2456
|
-
{
|
|
2630
|
+
{
|
|
2631
|
+
name: "token",
|
|
2632
|
+
type: "address",
|
|
2633
|
+
indexed: true,
|
|
2634
|
+
internalType: "address"
|
|
2635
|
+
},
|
|
2636
|
+
{
|
|
2637
|
+
name: "priceFeed",
|
|
2638
|
+
type: "address",
|
|
2639
|
+
indexed: true,
|
|
2640
|
+
internalType: "address"
|
|
2641
|
+
},
|
|
2642
|
+
{
|
|
2643
|
+
name: "stalenessPeriod",
|
|
2644
|
+
type: "uint32",
|
|
2645
|
+
indexed: false,
|
|
2646
|
+
internalType: "uint32"
|
|
2647
|
+
},
|
|
2648
|
+
{ name: "skipCheck", type: "bool", indexed: false, internalType: "bool" }
|
|
2649
|
+
],
|
|
2650
|
+
anonymous: false
|
|
2651
|
+
},
|
|
2652
|
+
{
|
|
2653
|
+
type: "event",
|
|
2654
|
+
name: "SetChecksEnabled",
|
|
2655
|
+
inputs: [
|
|
2656
|
+
{ name: "enabled", type: "bool", indexed: false, internalType: "bool" }
|
|
2657
|
+
],
|
|
2658
|
+
anonymous: false
|
|
2659
|
+
},
|
|
2660
|
+
{
|
|
2661
|
+
type: "event",
|
|
2662
|
+
name: "UnsetAliasPriceFeed",
|
|
2663
|
+
inputs: [
|
|
2664
|
+
{
|
|
2665
|
+
name: "token",
|
|
2666
|
+
type: "address",
|
|
2667
|
+
indexed: true,
|
|
2668
|
+
internalType: "address"
|
|
2669
|
+
}
|
|
2457
2670
|
],
|
|
2458
|
-
|
|
2671
|
+
anonymous: false
|
|
2459
2672
|
}
|
|
2460
2673
|
];
|
|
2461
2674
|
const iMarketConfiguratorV310Abi = [
|
|
@@ -5151,6 +5364,7 @@ const iTumblerV310Abi = [
|
|
|
5151
5364
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5152
5365
|
0 && (module.exports = {
|
|
5153
5366
|
iAddressProviderV310Abi,
|
|
5367
|
+
iAliasedLossPolicyV310Abi,
|
|
5154
5368
|
iBotListV310Abi,
|
|
5155
5369
|
iCreditConfiguratorV310Abi,
|
|
5156
5370
|
iCreditFacadeMulticallV310Abi,
|
|
@@ -29,11 +29,11 @@ class NoAvailableTransportsError extends import_viem.BaseError {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
class RevolverTransport {
|
|
32
|
-
#transports;
|
|
33
|
-
#index = 0;
|
|
34
32
|
#config;
|
|
35
|
-
#rotating = false;
|
|
36
33
|
#requests = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
#selector;
|
|
35
|
+
#rotating = false;
|
|
36
|
+
#isSingle;
|
|
37
37
|
overrides;
|
|
38
38
|
/**
|
|
39
39
|
* Create a new RevolverTransport
|
|
@@ -57,9 +57,9 @@ class RevolverTransport {
|
|
|
57
57
|
...config,
|
|
58
58
|
shouldRetry: config.shouldRetry ?? defaultShouldRetry
|
|
59
59
|
};
|
|
60
|
-
|
|
60
|
+
const transports = config.providers.map(
|
|
61
61
|
({ url, name, cooldown }) => ({
|
|
62
|
-
|
|
62
|
+
name,
|
|
63
63
|
transport: (0, import_viem.http)(url, {
|
|
64
64
|
retryCount: config.retryCount,
|
|
65
65
|
retryDelay: config.retryDelay,
|
|
@@ -73,40 +73,45 @@ class RevolverTransport {
|
|
|
73
73
|
cooldown: cooldown ?? 0
|
|
74
74
|
})
|
|
75
75
|
);
|
|
76
|
-
if (
|
|
76
|
+
if (transports.length === 0) {
|
|
77
77
|
throw new NoAvailableTransportsError();
|
|
78
78
|
}
|
|
79
|
+
this.#isSingle = transports.length === 1;
|
|
80
|
+
const selectionStrategy = config.selectionStrategy ?? "simple";
|
|
81
|
+
this.#selector = selectionStrategy === "simple" ? new SimpleTransportSelector(transports, config.cooldown) : new OrderedTransportSelector(transports, config.cooldown);
|
|
79
82
|
}
|
|
80
83
|
get value() {
|
|
81
84
|
return {
|
|
82
85
|
rotate: (reason) => this.rotate(reason),
|
|
83
|
-
currentTransportName: () => this.
|
|
84
|
-
statuses: () => this.statuses()
|
|
86
|
+
currentTransportName: () => this.#selector.transportName(),
|
|
87
|
+
statuses: () => this.#selector.statuses()
|
|
85
88
|
};
|
|
86
89
|
}
|
|
87
90
|
request = async (r) => {
|
|
88
|
-
if (this.#
|
|
89
|
-
return this.#
|
|
91
|
+
if (this.#isSingle) {
|
|
92
|
+
return this.#selector.select()({
|
|
93
|
+
...this.overrides
|
|
94
|
+
}).request(r);
|
|
90
95
|
}
|
|
91
96
|
let error;
|
|
92
97
|
do {
|
|
93
98
|
try {
|
|
94
|
-
this.#requests.set(r, this.
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
99
|
+
this.#requests.set(r, this.#selector.transportName());
|
|
100
|
+
const transport = this.#selector.select()({
|
|
101
|
+
...this.overrides
|
|
102
|
+
});
|
|
103
|
+
const resp = await (0, import_viem.withRetry)(() => transport.request(r), {
|
|
104
|
+
delay: this.#config.retryDelay,
|
|
105
|
+
retryCount: this.#config.retryCount,
|
|
106
|
+
shouldRetry: this.#config.shouldRetry
|
|
107
|
+
});
|
|
103
108
|
this.#requests.delete(r);
|
|
104
109
|
return resp;
|
|
105
110
|
} catch (e) {
|
|
106
111
|
error = error ?? e;
|
|
107
112
|
if (e instanceof import_viem.RpcError || e instanceof import_viem.HttpRequestError) {
|
|
108
113
|
const reqTransport = this.#requests.get(r);
|
|
109
|
-
if (reqTransport === this.
|
|
114
|
+
if (reqTransport === this.#selector.transportName()) {
|
|
110
115
|
await this.rotate(e);
|
|
111
116
|
} else {
|
|
112
117
|
this.#logger?.debug(
|
|
@@ -118,7 +123,7 @@ class RevolverTransport {
|
|
|
118
123
|
throw e;
|
|
119
124
|
}
|
|
120
125
|
}
|
|
121
|
-
} while (this.#
|
|
126
|
+
} while (this.#selector.canRotate());
|
|
122
127
|
this.#requests.delete(r);
|
|
123
128
|
throw new NoAvailableTransportsError(error);
|
|
124
129
|
};
|
|
@@ -140,82 +145,34 @@ class RevolverTransport {
|
|
|
140
145
|
* @returns true if rotation was successful
|
|
141
146
|
*/
|
|
142
147
|
async rotate(reason) {
|
|
143
|
-
if (this.#transports.length === 1) {
|
|
144
|
-
return true;
|
|
145
|
-
}
|
|
146
148
|
if (this.#rotating) {
|
|
147
149
|
this.#logger?.debug("already rotating, skipping");
|
|
148
|
-
return
|
|
150
|
+
return;
|
|
149
151
|
}
|
|
150
152
|
this.#rotating = true;
|
|
151
|
-
this.#
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
"rotating transport"
|
|
158
|
-
);
|
|
159
|
-
const oldTransportName = this.currentTransportName();
|
|
160
|
-
const now = Date.now();
|
|
161
|
-
this.#transports[this.#index].cooldown = now + (this.#config.cooldown ?? 6e4);
|
|
162
|
-
for (let i = 0; i < this.#transports.length - 1; i++) {
|
|
163
|
-
this.#index = (this.#index + 1) % this.#transports.length;
|
|
164
|
-
if (this.#transports[this.#index].cooldown < now) {
|
|
165
|
-
this.#logger?.info(
|
|
166
|
-
{
|
|
167
|
-
current: this.currentTransportName,
|
|
168
|
-
total: this.#transports.length
|
|
169
|
-
},
|
|
170
|
-
"switched to next transport"
|
|
171
|
-
);
|
|
153
|
+
const from = this.#selector.transportName();
|
|
154
|
+
const success = this.#selector.rotate();
|
|
155
|
+
const to = this.#selector.transportName();
|
|
156
|
+
if (success) {
|
|
157
|
+
if (from !== to) {
|
|
158
|
+
this.#logger?.debug({ from, to, reason }, "transport rotated");
|
|
172
159
|
try {
|
|
173
|
-
await this.#config.onRotateSuccess?.(
|
|
174
|
-
oldTransportName,
|
|
175
|
-
this.currentTransportName(),
|
|
176
|
-
reason
|
|
177
|
-
);
|
|
160
|
+
await this.#config.onRotateSuccess?.(from, to, reason);
|
|
178
161
|
} catch {
|
|
179
162
|
}
|
|
180
|
-
this.#rotating = false;
|
|
181
|
-
return true;
|
|
182
|
-
} else {
|
|
183
|
-
this.#logger?.warn(
|
|
184
|
-
{
|
|
185
|
-
current: this.currentTransportName,
|
|
186
|
-
total: this.#transports.length
|
|
187
|
-
},
|
|
188
|
-
"transport is still on cooldown"
|
|
189
|
-
);
|
|
190
163
|
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
164
|
+
} else {
|
|
165
|
+
this.#logger?.warn({ from, reason }, "transport rotation failed");
|
|
166
|
+
try {
|
|
167
|
+
await this.#config.onRotateFailed?.(from, reason);
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
195
170
|
}
|
|
196
171
|
this.#rotating = false;
|
|
197
|
-
return false;
|
|
198
|
-
}
|
|
199
|
-
currentTransportName() {
|
|
200
|
-
return this.#transport({}).config.name;
|
|
201
|
-
}
|
|
202
|
-
statuses() {
|
|
203
|
-
const now = Date.now();
|
|
204
|
-
return this.#transports.map((t, i) => ({
|
|
205
|
-
id: t.transport({}).config.name,
|
|
206
|
-
status: t.cooldown < now ? this.#index === i ? "active" : "standby" : "cooldown"
|
|
207
|
-
}));
|
|
208
172
|
}
|
|
209
173
|
get #logger() {
|
|
210
174
|
return this.#config.logger;
|
|
211
175
|
}
|
|
212
|
-
get #transport() {
|
|
213
|
-
return this.#transports[this.#index].transport;
|
|
214
|
-
}
|
|
215
|
-
get #hasAvailableTransports() {
|
|
216
|
-
const now = Date.now();
|
|
217
|
-
return this.#transports.some((t) => t.cooldown < now);
|
|
218
|
-
}
|
|
219
176
|
}
|
|
220
177
|
const retryCodes = /* @__PURE__ */ new Set([
|
|
221
178
|
import_viem.InvalidRequestRpcError.code,
|
|
@@ -227,11 +184,95 @@ const retryCodes = /* @__PURE__ */ new Set([
|
|
|
227
184
|
const defaultShouldRetry = ({
|
|
228
185
|
error
|
|
229
186
|
}) => {
|
|
187
|
+
if (error instanceof import_viem.CallExecutionError && error.details === "header not found") {
|
|
188
|
+
return true;
|
|
189
|
+
}
|
|
230
190
|
if ("code" in error && typeof error.code === "number") {
|
|
231
191
|
return retryCodes.has(error.code);
|
|
232
192
|
}
|
|
233
193
|
return false;
|
|
234
194
|
};
|
|
195
|
+
class AbstractTransportSelector {
|
|
196
|
+
transports;
|
|
197
|
+
cooldown;
|
|
198
|
+
index = 0;
|
|
199
|
+
constructor(transports, cooldown = 6e4) {
|
|
200
|
+
this.transports = transports;
|
|
201
|
+
this.cooldown = cooldown;
|
|
202
|
+
}
|
|
203
|
+
transportName() {
|
|
204
|
+
return this.transports[this.index].name;
|
|
205
|
+
}
|
|
206
|
+
canRotate() {
|
|
207
|
+
const now = Date.now();
|
|
208
|
+
return this.transports.some((t) => t.cooldown < now);
|
|
209
|
+
}
|
|
210
|
+
statuses() {
|
|
211
|
+
const now = Date.now();
|
|
212
|
+
return this.transports.map((t, i) => ({
|
|
213
|
+
id: t.name,
|
|
214
|
+
status: t.cooldown < now ? this.index === i ? "active" : "standby" : "cooldown"
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
class SimpleTransportSelector extends AbstractTransportSelector {
|
|
219
|
+
/**
|
|
220
|
+
* For simple selector, transport status is not re-evaluated on each request
|
|
221
|
+
* @returns
|
|
222
|
+
*/
|
|
223
|
+
select() {
|
|
224
|
+
return this.transports[this.index].transport;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Simply selects next transport that is not in cooldown by checking all transports in cyclic order
|
|
228
|
+
* @returns true if rotation was successful
|
|
229
|
+
*/
|
|
230
|
+
rotate() {
|
|
231
|
+
if (this.transports.length === 1) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
const now = Date.now();
|
|
235
|
+
this.transports[this.index].cooldown = now + this.cooldown;
|
|
236
|
+
for (let i = 0; i < this.transports.length - 1; i++) {
|
|
237
|
+
this.index = (this.index + 1) % this.transports.length;
|
|
238
|
+
if (this.transports[this.index].cooldown < now) {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
class OrderedTransportSelector extends AbstractTransportSelector {
|
|
246
|
+
/**
|
|
247
|
+
* Will select first transport that is not in cooldown
|
|
248
|
+
* @returns
|
|
249
|
+
*/
|
|
250
|
+
select() {
|
|
251
|
+
this.#updateIndex(Date.now());
|
|
252
|
+
return this.transports[this.index].transport;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Will put current transport into cooldown and select first available transport that is not in cooldown
|
|
256
|
+
* @returns true if rotation was successful
|
|
257
|
+
*/
|
|
258
|
+
rotate() {
|
|
259
|
+
if (this.transports.length === 1) {
|
|
260
|
+
return true;
|
|
261
|
+
}
|
|
262
|
+
const now = Date.now();
|
|
263
|
+
this.transports[this.index].cooldown = now + this.cooldown;
|
|
264
|
+
return this.#updateIndex(now);
|
|
265
|
+
}
|
|
266
|
+
#updateIndex(now) {
|
|
267
|
+
for (let i = 0; i < this.transports.length; i++) {
|
|
268
|
+
if (this.transports[i].cooldown < now) {
|
|
269
|
+
this.index = i;
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
235
276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
236
277
|
0 && (module.exports = {
|
|
237
278
|
NoAvailableTransportsError,
|
|
@@ -23,6 +23,7 @@ __export(MarketSuite_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(MarketSuite_exports);
|
|
24
24
|
var import_base = require("../base/index.js");
|
|
25
25
|
var import_credit = require("./credit/index.js");
|
|
26
|
+
var import_loss_policy = require("./loss-policy/index.js");
|
|
26
27
|
var import_MarketConfiguratorContract = require("./MarketConfiguratorContract.js");
|
|
27
28
|
var import_oracle = require("./oracle/index.js");
|
|
28
29
|
var import_pool = require("./pool/index.js");
|
|
@@ -32,6 +33,7 @@ class MarketSuite extends import_base.SDKConstruct {
|
|
|
32
33
|
configurator;
|
|
33
34
|
pool;
|
|
34
35
|
priceOracle;
|
|
36
|
+
lossPolicy;
|
|
35
37
|
creditManagers = [];
|
|
36
38
|
/**
|
|
37
39
|
* Original data received from compressor
|
|
@@ -58,6 +60,7 @@ class MarketSuite extends import_base.SDKConstruct {
|
|
|
58
60
|
this.creditManagers.push(new import_credit.CreditSuite(sdk, marketData, i));
|
|
59
61
|
}
|
|
60
62
|
this.priceOracle = (0, import_oracle.getOrCreatePriceOracle)(sdk, marketData.priceOracle);
|
|
63
|
+
this.lossPolicy = (0, import_loss_policy.createLossPolicy)(sdk, marketData.lossPolicy);
|
|
61
64
|
}
|
|
62
65
|
get dirty() {
|
|
63
66
|
return this.configurator.dirty || this.pool.dirty || this.priceOracle.dirty || this.creditManagers.some((cm) => cm.dirty);
|
|
@@ -77,6 +80,7 @@ class MarketSuite extends import_base.SDKConstruct {
|
|
|
77
80
|
pool: this.pool.stateHuman(raw),
|
|
78
81
|
creditManagers: this.creditManagers.map((cm) => cm.stateHuman(raw)),
|
|
79
82
|
priceOracle: this.priceOracle.stateHuman(raw),
|
|
83
|
+
lossPolicy: this.lossPolicy.stateHuman(raw),
|
|
80
84
|
pausableAdmins: this.state.pausableAdmins.map((a) => this.labelAddress(a)),
|
|
81
85
|
unpausableAdmins: this.state.unpausableAdmins.map(
|
|
82
86
|
(a) => this.labelAddress(a)
|
|
@@ -81,7 +81,10 @@ class CreditFacadeV300Contract extends import_base.BaseContract {
|
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
|
-
liquidateCreditAccount(ca, to, calls) {
|
|
84
|
+
liquidateCreditAccount(ca, to, calls, lossPolicyData) {
|
|
85
|
+
if (lossPolicyData) {
|
|
86
|
+
this.logger?.warn("loss policy data is not supported");
|
|
87
|
+
}
|
|
85
88
|
return this.createRawTx({
|
|
86
89
|
functionName: "liquidateCreditAccount",
|
|
87
90
|
args: [ca, to, calls]
|