@gearbox-protocol/sdk 13.3.3 → 13.3.5
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/sdk/GearboxSDK.js +135 -20
- package/dist/cjs/sdk/accounts/AbstractCreditAccountsService.js +78 -157
- package/dist/cjs/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/cjs/sdk/base/BaseContract.js +26 -6
- package/dist/cjs/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/cjs/sdk/base/Construct.js +15 -3
- package/dist/cjs/sdk/base/TokensMeta.js +23 -0
- package/dist/cjs/sdk/constants/address-provider.js +0 -22
- package/dist/cjs/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/cjs/sdk/market/MarketRegister.js +74 -3
- package/dist/cjs/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/cjs/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/cjs/sdk/options.js +30 -24
- package/dist/cjs/sdk/plugins/BasePlugin.js +24 -0
- package/dist/cjs/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/cjs/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/cjs/sdk/router/RouterV310Contract.js +20 -15
- package/dist/cjs/sdk/utils/AddressMap.js +53 -17
- package/dist/cjs/sdk/utils/AddressSet.js +9 -0
- package/dist/cjs/sdk/utils/viem/sendRawTx.js +16 -0
- package/dist/esm/sdk/GearboxSDK.js +135 -20
- package/dist/esm/sdk/accounts/AbstractCreditAccountsService.js +78 -157
- package/dist/esm/sdk/accounts/CreditAccountsServiceV310.js +5 -5
- package/dist/esm/sdk/base/BaseContract.js +26 -6
- package/dist/esm/sdk/base/ChainContractsRegister.js +39 -2
- package/dist/esm/sdk/base/Construct.js +15 -3
- package/dist/esm/sdk/base/TokensMeta.js +23 -0
- package/dist/esm/sdk/constants/address-provider.js +0 -21
- package/dist/esm/sdk/core/AbstractAddressProviderContract.js +15 -0
- package/dist/esm/sdk/market/MarketRegister.js +74 -3
- package/dist/esm/sdk/market/oracle/PriceOracleBaseContract.js +31 -50
- package/dist/esm/sdk/market/pricefeeds/PriceFeedRef.js +16 -0
- package/dist/esm/sdk/market/pricefeeds/PriceFeedsRegister.js +55 -12
- package/dist/esm/sdk/options.js +30 -24
- package/dist/esm/sdk/plugins/BasePlugin.js +24 -0
- package/dist/esm/sdk/pools/AbstractPoolService.js +6 -0
- package/dist/esm/sdk/router/AbstractRouterContract.js +4 -1
- package/dist/esm/sdk/router/RouterV310Contract.js +20 -15
- package/dist/esm/sdk/utils/AddressMap.js +53 -17
- package/dist/esm/sdk/utils/AddressSet.js +9 -0
- package/dist/esm/sdk/utils/viem/sendRawTx.js +19 -1
- package/dist/types/sdk/GearboxSDK.d.ts +236 -34
- package/dist/types/sdk/accounts/AbstractCreditAccountsService.d.ts +56 -142
- package/dist/types/sdk/accounts/CreditAccountsServiceV310.d.ts +14 -5
- package/dist/types/sdk/accounts/types.d.ts +230 -18
- package/dist/types/sdk/base/BaseContract.d.ts +67 -6
- package/dist/types/sdk/base/ChainContractsRegister.d.ts +51 -2
- package/dist/types/sdk/base/Construct.d.ts +31 -0
- package/dist/types/sdk/base/PlaceholderContract.d.ts +3 -0
- package/dist/types/sdk/base/SDKConstruct.d.ts +10 -0
- package/dist/types/sdk/base/TokensMeta.d.ts +59 -2
- package/dist/types/sdk/base/types.d.ts +185 -25
- package/dist/types/sdk/chain/chains.d.ts +78 -18
- package/dist/types/sdk/chain/detectNetwork.d.ts +7 -0
- package/dist/types/sdk/constants/address-provider.d.ts +4 -3
- package/dist/types/sdk/core/AbstractAddressProviderContract.d.ts +23 -0
- package/dist/types/sdk/core/types.d.ts +46 -0
- package/dist/types/sdk/market/MarketRegister.d.ts +81 -0
- package/dist/types/sdk/market/adapters/PlaceholderAdapterContracts.d.ts +3 -0
- package/dist/types/sdk/market/oracle/PriceOracleBaseContract.d.ts +40 -50
- package/dist/types/sdk/market/oracle/types.d.ts +76 -57
- package/dist/types/sdk/market/pricefeeds/AbstractLPPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/AbstractPriceFeed.d.ts +3 -0
- package/dist/types/sdk/market/pricefeeds/PriceFeedRef.d.ts +22 -2
- package/dist/types/sdk/market/pricefeeds/PriceFeedsRegister.d.ts +77 -13
- package/dist/types/sdk/market/pricefeeds/types.d.ts +70 -10
- package/dist/types/sdk/options.d.ts +13 -4
- package/dist/types/sdk/plugins/BasePlugin.d.ts +39 -0
- package/dist/types/sdk/plugins/types.d.ts +73 -43
- package/dist/types/sdk/pools/AbstractPoolService.d.ts +12 -0
- package/dist/types/sdk/pools/types.d.ts +75 -6
- package/dist/types/sdk/router/AbstractRouterContract.d.ts +21 -2
- package/dist/types/sdk/router/RouterV310Contract.d.ts +27 -15
- package/dist/types/sdk/router/types.d.ts +51 -69
- package/dist/types/sdk/types/state.d.ts +32 -3
- package/dist/types/sdk/utils/AddressMap.d.ts +61 -17
- package/dist/types/sdk/utils/AddressSet.d.ts +15 -0
- package/dist/types/sdk/utils/viem/sendRawTx.d.ts +5 -1
- package/package.json +4 -2
|
@@ -46,12 +46,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
46
46
|
);
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
|
|
51
|
-
* @param account
|
|
52
|
-
* @param blockNumber
|
|
53
|
-
* @returns
|
|
54
|
-
*/
|
|
49
|
+
* {@inheritDoc ICreditAccountsService.getCreditAccountData}
|
|
50
|
+
**/
|
|
55
51
|
async getCreditAccountData(account, blockNumber) {
|
|
56
52
|
let raw;
|
|
57
53
|
try {
|
|
@@ -90,13 +86,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
90
86
|
return cad;
|
|
91
87
|
}
|
|
92
88
|
/**
|
|
93
|
-
*
|
|
94
|
-
|
|
95
|
-
*
|
|
96
|
-
* @param options
|
|
97
|
-
* @param blockNumber
|
|
98
|
-
* @returns returned credit accounts are sorted by health factor in ascending order
|
|
99
|
-
*/
|
|
89
|
+
* {@inheritDoc ICreditAccountsService.getCreditAccounts}
|
|
90
|
+
**/
|
|
100
91
|
async getCreditAccounts(options, blockNumber) {
|
|
101
92
|
const {
|
|
102
93
|
creditManager,
|
|
@@ -149,11 +140,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
149
140
|
return allCAs.sort((a, b) => Number(a.healthFactor - b.healthFactor));
|
|
150
141
|
}
|
|
151
142
|
/**
|
|
152
|
-
*
|
|
153
|
-
|
|
154
|
-
* @param {Address} creditAccount - address of credit account to get rewards for
|
|
155
|
-
* @returns {Array<Rewards>} list of {@link Rewards} that can be claimed
|
|
156
|
-
*/
|
|
143
|
+
* {@inheritDoc ICreditAccountsService.getRewards}
|
|
144
|
+
**/
|
|
157
145
|
async getRewards(creditAccount) {
|
|
158
146
|
const rewards = await this.client.readContract({
|
|
159
147
|
abi: rewardsCompressorAbi,
|
|
@@ -193,11 +181,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
193
181
|
return Object.values(r);
|
|
194
182
|
}
|
|
195
183
|
/**
|
|
196
|
-
*
|
|
197
|
-
|
|
198
|
-
and their credit managers to check connected bots on
|
|
199
|
-
* @returns call result of getConnectedBots for each credit account
|
|
200
|
-
*/
|
|
184
|
+
* {@inheritDoc ICreditAccountsService.getConnectedBots}
|
|
185
|
+
**/
|
|
201
186
|
async getConnectedBots(accountsToCheck, legacyMigrationBot, additionalBots) {
|
|
202
187
|
const allResp = await this.client.multicall({
|
|
203
188
|
contracts: [
|
|
@@ -301,10 +286,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
301
286
|
return void 0;
|
|
302
287
|
}
|
|
303
288
|
/**
|
|
304
|
-
*
|
|
305
|
-
|
|
306
|
-
* @returns
|
|
307
|
-
*/
|
|
289
|
+
* {@inheritDoc ICreditAccountsService.fullyLiquidate}
|
|
290
|
+
**/
|
|
308
291
|
async fullyLiquidate(props) {
|
|
309
292
|
const {
|
|
310
293
|
account,
|
|
@@ -354,21 +337,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
354
337
|
};
|
|
355
338
|
}
|
|
356
339
|
/**
|
|
357
|
-
*
|
|
358
|
-
|
|
359
|
-
-> disable quotas of exiting tokens -> decrease debt -> disable exiting tokens tokens -> withdraw underlying tokenz
|
|
360
|
-
* @param {CloseOptions} operation - {@link CloseOptions}: close or zeroDebt
|
|
361
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
362
|
-
* @param {Array<Address>} assetsToWithdraw - tokens to withdraw from credit account.
|
|
363
|
-
For credit account closing this is the underlying token, because during the closure,
|
|
364
|
-
all tokens on account are swapped into the underlying,
|
|
365
|
-
and only the underlying token will remain on the credit account
|
|
366
|
-
* @param {Address} to - Wallet address to withdraw underlying to
|
|
367
|
-
* @param {number} slippage - Slippage in PERCENTAGE_FORMAT (100% = 10_000) per operation
|
|
368
|
-
* @default 50n
|
|
369
|
-
* @param {RouterCloseResult | undefined} closePath - result of findBestClosePath method from router; if omited, calls marketRegister.findCreditManager {@link RouterCloseResult}
|
|
370
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
371
|
-
*/
|
|
340
|
+
* {@inheritDoc ICreditAccountsService.closeCreditAccount}
|
|
341
|
+
**/
|
|
372
342
|
async closeCreditAccount({
|
|
373
343
|
operation,
|
|
374
344
|
assetsToWithdraw,
|
|
@@ -400,13 +370,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
400
370
|
return { tx, calls, routerCloseResult, creditFacade: cm.creditFacade };
|
|
401
371
|
}
|
|
402
372
|
/**
|
|
403
|
-
*
|
|
404
|
-
|
|
405
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
406
|
-
* @param {Array<Asset>} averageQuota - average quota for desired tokens {@link Asset}
|
|
407
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired tokens {@link Asset}
|
|
408
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
409
|
-
*/
|
|
373
|
+
* {@inheritDoc ICreditAccountsService.updateQuotas}
|
|
374
|
+
**/
|
|
410
375
|
async updateQuotas({
|
|
411
376
|
minQuota,
|
|
412
377
|
averageQuota,
|
|
@@ -430,16 +395,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
430
395
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
431
396
|
}
|
|
432
397
|
/**
|
|
433
|
-
*
|
|
434
|
-
|
|
435
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
436
|
-
* @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
|
|
437
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
|
|
438
|
-
* @param {Asset} asset - asset to add as collateral {@link Asset}
|
|
439
|
-
* @param {PermitResult | undefined} permits - permits of collateral asset if it is permittable {@link PermitResult}
|
|
440
|
-
* @param {bigint} ethAmount - native token amount to attach to tx
|
|
441
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
442
|
-
*/
|
|
398
|
+
* {@inheritDoc ICreditAccountsService.addCollateral}
|
|
399
|
+
**/
|
|
443
400
|
async addCollateral({
|
|
444
401
|
creditAccount,
|
|
445
402
|
asset,
|
|
@@ -473,15 +430,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
473
430
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
474
431
|
}
|
|
475
432
|
/**
|
|
476
|
-
*
|
|
477
|
-
|
|
478
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
479
|
-
* @param {bigint} amount - amount to change debt by;
|
|
480
|
-
0 - prohibited value;
|
|
481
|
-
negative value for debt decrease;
|
|
482
|
-
positive value for debt increase.
|
|
483
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
484
|
-
*/
|
|
433
|
+
* {@inheritDoc ICreditAccountsService.changeDebt}
|
|
434
|
+
**/
|
|
485
435
|
async changeDebt({
|
|
486
436
|
creditAccount,
|
|
487
437
|
amount,
|
|
@@ -518,14 +468,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
518
468
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
519
469
|
}
|
|
520
470
|
/**
|
|
521
|
-
*
|
|
522
|
-
|
|
523
|
-
* @param {RouterCASlice} creditAccount - minimal credit account data {@link RouterCASlice} on which operation is performed
|
|
524
|
-
* @param {Array<Asset>} averageQuota - average quota for desired token {@link Asset}
|
|
525
|
-
* @param {Array<Asset>} minQuota - minimum quota for desired token {@link Asset}
|
|
526
|
-
* @param {Array<MultiCall>} calls - array of MultiCall from router methods getSingleSwap or getAllSwaps {@link MultiCall}
|
|
527
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
528
|
-
*/
|
|
471
|
+
* {@inheritDoc ICreditAccountsService.executeSwap}
|
|
472
|
+
**/
|
|
529
473
|
async executeSwap({
|
|
530
474
|
creditAccount,
|
|
531
475
|
calls: swapCalls,
|
|
@@ -553,10 +497,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
553
497
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
554
498
|
}
|
|
555
499
|
/**
|
|
556
|
-
*
|
|
557
|
-
|
|
558
|
-
* @returns
|
|
559
|
-
*/
|
|
500
|
+
* {@inheritDoc ICreditAccountsService.previewDelayedWithdrawal}
|
|
501
|
+
**/
|
|
560
502
|
async previewDelayedWithdrawal({
|
|
561
503
|
creditAccount,
|
|
562
504
|
amount,
|
|
@@ -580,10 +522,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
580
522
|
return resp;
|
|
581
523
|
}
|
|
582
524
|
/**
|
|
583
|
-
*
|
|
584
|
-
|
|
585
|
-
* @returns
|
|
586
|
-
*/
|
|
525
|
+
* {@inheritDoc ICreditAccountsService.getPendingWithdrawals}
|
|
526
|
+
**/
|
|
587
527
|
async getPendingWithdrawals({
|
|
588
528
|
creditAccount
|
|
589
529
|
}) {
|
|
@@ -609,11 +549,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
609
549
|
return respResult;
|
|
610
550
|
}
|
|
611
551
|
/**
|
|
612
|
-
*
|
|
613
|
-
|
|
614
|
-
* @param props - {@link StartDelayedWithdrawalProps}
|
|
615
|
-
* @returns
|
|
616
|
-
*/
|
|
552
|
+
* {@inheritDoc ICreditAccountsService.startDelayedWithdrawal}
|
|
553
|
+
**/
|
|
617
554
|
async startDelayedWithdrawal({
|
|
618
555
|
creditAccount,
|
|
619
556
|
minQuota,
|
|
@@ -669,11 +606,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
669
606
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
670
607
|
}
|
|
671
608
|
/**
|
|
672
|
-
*
|
|
673
|
-
|
|
674
|
-
* @param props - {@link ClaimDelayedProps}
|
|
675
|
-
* @returns
|
|
676
|
-
*/
|
|
609
|
+
* {@inheritDoc ICreditAccountsService.claimDelayed}
|
|
610
|
+
**/
|
|
677
611
|
async claimDelayed({
|
|
678
612
|
creditAccount,
|
|
679
613
|
minQuota,
|
|
@@ -734,44 +668,32 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
734
668
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
735
669
|
}
|
|
736
670
|
/**
|
|
737
|
-
*
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
Used for trading and strategy functionality
|
|
756
|
-
* @param {Array<Asset>} averageQuota - average quota for tokens after open {@link Asset}
|
|
757
|
-
* @param {Array<Asset>} minQuota - minimum quota for tokens after open {@link Asset}
|
|
758
|
-
* @returns All necessary data to execute the transaction (call, credit facade)
|
|
759
|
-
*/
|
|
760
|
-
async openCA({
|
|
761
|
-
ethAmount,
|
|
762
|
-
creditManager,
|
|
763
|
-
collateral,
|
|
764
|
-
permits,
|
|
765
|
-
debt,
|
|
766
|
-
withdrawDebt,
|
|
767
|
-
referralCode,
|
|
768
|
-
to,
|
|
769
|
-
calls: openPathCalls,
|
|
770
|
-
minQuota,
|
|
771
|
-
averageQuota
|
|
772
|
-
}) {
|
|
671
|
+
* {@inheritDoc ICreditAccountsService.openCA}
|
|
672
|
+
**/
|
|
673
|
+
async openCA(props) {
|
|
674
|
+
const {
|
|
675
|
+
ethAmount,
|
|
676
|
+
creditManager,
|
|
677
|
+
reopenCreditAccount,
|
|
678
|
+
collateral,
|
|
679
|
+
permits,
|
|
680
|
+
debt,
|
|
681
|
+
withdrawToken,
|
|
682
|
+
referralCode,
|
|
683
|
+
to,
|
|
684
|
+
calls: openPathCalls,
|
|
685
|
+
callsAfter,
|
|
686
|
+
minQuota,
|
|
687
|
+
averageQuota
|
|
688
|
+
} = props;
|
|
773
689
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
774
690
|
const cm = cmSuite.creditManager;
|
|
691
|
+
let tokenToWithdraw;
|
|
692
|
+
if (withdrawToken === true) {
|
|
693
|
+
tokenToWithdraw = cm.underlying;
|
|
694
|
+
} else if (typeof withdrawToken === "string") {
|
|
695
|
+
tokenToWithdraw = withdrawToken;
|
|
696
|
+
}
|
|
775
697
|
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
776
698
|
creditManager: cm.address,
|
|
777
699
|
desiredQuotas: averageQuota
|
|
@@ -781,21 +703,32 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
781
703
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
782
704
|
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
783
705
|
...openPathCalls,
|
|
784
|
-
...
|
|
706
|
+
...tokenToWithdraw ? [
|
|
707
|
+
this.prepareWithdrawToken(
|
|
708
|
+
cm.creditFacade,
|
|
709
|
+
tokenToWithdraw,
|
|
710
|
+
MAX_UINT256,
|
|
711
|
+
to
|
|
712
|
+
)
|
|
713
|
+
] : [],
|
|
785
714
|
...this.prepareUpdateQuotas(cm.creditFacade, {
|
|
786
715
|
minQuota,
|
|
787
716
|
averageQuota
|
|
788
|
-
})
|
|
717
|
+
}),
|
|
718
|
+
...callsAfter ?? []
|
|
789
719
|
];
|
|
790
|
-
|
|
720
|
+
let tx;
|
|
721
|
+
if (reopenCreditAccount) {
|
|
722
|
+
tx = await cmSuite.creditFacade.multicall(reopenCreditAccount, calls);
|
|
723
|
+
} else {
|
|
724
|
+
tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
|
|
725
|
+
}
|
|
791
726
|
tx.value = ethAmount.toString(10);
|
|
792
727
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
793
728
|
}
|
|
794
729
|
/**
|
|
795
|
-
*
|
|
796
|
-
|
|
797
|
-
* @returns
|
|
798
|
-
*/
|
|
730
|
+
* {@inheritDoc ICreditAccountsService.getBorrowRate}
|
|
731
|
+
**/
|
|
799
732
|
getBorrowRate(ca) {
|
|
800
733
|
const { creditManager } = this.sdk.marketRegister.findCreditManager(
|
|
801
734
|
ca.creditManager
|
|
@@ -821,9 +754,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
821
754
|
return r + qr;
|
|
822
755
|
}
|
|
823
756
|
/**
|
|
824
|
-
*
|
|
825
|
-
|
|
826
|
-
*/
|
|
757
|
+
* {@inheritDoc ICreditAccountsService.getOptimalHFForPartialLiquidation}
|
|
758
|
+
**/
|
|
827
759
|
getOptimalHFForPartialLiquidation(ca) {
|
|
828
760
|
const borrowRate = this.getBorrowRate(ca);
|
|
829
761
|
return PERCENTAGE_FACTOR + (borrowRate < 100n ? borrowRate : 100n);
|
|
@@ -872,12 +804,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
872
804
|
return resp;
|
|
873
805
|
}
|
|
874
806
|
/**
|
|
875
|
-
*
|
|
876
|
-
|
|
877
|
-
* This can be used by batch liquidator
|
|
878
|
-
* @param accounts
|
|
879
|
-
* @returns
|
|
880
|
-
*/
|
|
807
|
+
* {@inheritDoc ICreditAccountsService.getUpdateForAccounts}
|
|
808
|
+
**/
|
|
881
809
|
async getUpdateForAccounts(accounts) {
|
|
882
810
|
const tokensByPool = /* @__PURE__ */ new Map();
|
|
883
811
|
const oracleByPool = /* @__PURE__ */ new Map();
|
|
@@ -949,10 +877,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
949
877
|
return this.sdk.priceFeeds.generatePriceFeedsUpdateTxs(priceFeeds);
|
|
950
878
|
}
|
|
951
879
|
/**
|
|
952
|
-
*
|
|
953
|
-
|
|
954
|
-
* @returns
|
|
955
|
-
*/
|
|
880
|
+
* {@inheritDoc ICreditAccountsService.getOnDemandPriceUpdates}
|
|
881
|
+
**/
|
|
956
882
|
async getOnDemandPriceUpdates(options) {
|
|
957
883
|
const { creditManager, creditAccount } = options;
|
|
958
884
|
const market = this.sdk.marketRegister.findByCreditManager(creditManager);
|
|
@@ -968,13 +894,8 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
968
894
|
);
|
|
969
895
|
}
|
|
970
896
|
/**
|
|
971
|
-
*
|
|
972
|
-
|
|
973
|
-
* - If there is creditAccount update balance > 10n && isEnabled. Is used in credit account actions when quota is not being bought.
|
|
974
|
-
* - If there is desiredQuotas update quotaBalance > 0. Is used on credit account opening, when quota is bought for the first time.
|
|
975
|
-
* @param acc
|
|
976
|
-
* @returns
|
|
977
|
-
*/
|
|
897
|
+
* {@inheritDoc ICreditAccountsService.getPriceUpdatesForFacade}
|
|
898
|
+
**/
|
|
978
899
|
async getPriceUpdatesForFacade(options) {
|
|
979
900
|
const updates = await this.getOnDemandPriceUpdates(options);
|
|
980
901
|
return updates.multicall;
|
|
@@ -4,7 +4,7 @@ import { MAX_UINT256 } from "../constants/math.js";
|
|
|
4
4
|
import { AbstractCreditAccountService } from "./AbstractCreditAccountsService.js";
|
|
5
5
|
class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* {@inheritDoc ICreditAccountsService.setBot}
|
|
8
8
|
*/
|
|
9
9
|
async setBot({
|
|
10
10
|
botAddress,
|
|
@@ -46,7 +46,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
46
46
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
49
|
+
* {@inheritDoc ICreditAccountsService.withdrawCollateral}
|
|
50
50
|
*/
|
|
51
51
|
async withdrawCollateral({
|
|
52
52
|
creditAccount,
|
|
@@ -81,7 +81,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
81
81
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
82
82
|
}
|
|
83
83
|
/**
|
|
84
|
-
*
|
|
84
|
+
* {@inheritDoc ICreditAccountsService.repayCreditAccount}
|
|
85
85
|
*/
|
|
86
86
|
async repayCreditAccount({
|
|
87
87
|
operation,
|
|
@@ -117,7 +117,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
117
117
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
118
118
|
}
|
|
119
119
|
/**
|
|
120
|
-
*
|
|
120
|
+
* {@inheritDoc ICreditAccountsService.repayAndLiquidateCreditAccount}
|
|
121
121
|
*/
|
|
122
122
|
async repayAndLiquidateCreditAccount({
|
|
123
123
|
collateralAssets,
|
|
@@ -154,7 +154,7 @@ class CreditAccountServiceV310 extends AbstractCreditAccountService {
|
|
|
154
154
|
return { tx, calls, creditFacade: cm.creditFacade };
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
157
|
+
* {@inheritDoc ICreditAccountsService.claimFarmRewards}
|
|
158
158
|
*/
|
|
159
159
|
async claimFarmRewards({
|
|
160
160
|
calls: externalCalls,
|
|
@@ -35,11 +35,30 @@ class ContractParseError extends BaseError {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
class BaseContract extends Construct {
|
|
38
|
+
/**
|
|
39
|
+
* Viem contract instance for direct read calls
|
|
40
|
+
**/
|
|
38
41
|
contract;
|
|
42
|
+
/**
|
|
43
|
+
* Contract ABI
|
|
44
|
+
**/
|
|
39
45
|
abi;
|
|
46
|
+
/**
|
|
47
|
+
* Gearbox contract type identifier (e.g. `"CREDIT_MANAGER"`), or empty string if unknown.
|
|
48
|
+
**/
|
|
40
49
|
contractType;
|
|
50
|
+
/**
|
|
51
|
+
* Contract version number.
|
|
52
|
+
* @default 0
|
|
53
|
+
**/
|
|
41
54
|
version;
|
|
55
|
+
/**
|
|
56
|
+
* On-chain address of the contract.
|
|
57
|
+
**/
|
|
42
58
|
address;
|
|
59
|
+
/**
|
|
60
|
+
* Display name for the contract.
|
|
61
|
+
**/
|
|
43
62
|
name;
|
|
44
63
|
constructor(options, args) {
|
|
45
64
|
super(options);
|
|
@@ -63,6 +82,7 @@ class BaseContract extends Construct {
|
|
|
63
82
|
register.setAddressLabel(this.address, this.name);
|
|
64
83
|
}
|
|
65
84
|
}
|
|
85
|
+
/** {@inheritDoc IBaseContract.stateHuman} */
|
|
66
86
|
stateHuman(_ = true) {
|
|
67
87
|
return {
|
|
68
88
|
address: this.labelAddress(this.address),
|
|
@@ -71,9 +91,10 @@ class BaseContract extends Construct {
|
|
|
71
91
|
};
|
|
72
92
|
}
|
|
73
93
|
/**
|
|
74
|
-
*
|
|
75
|
-
*
|
|
76
|
-
|
|
94
|
+
* Applies an on-chain event to update this contract's local state.
|
|
95
|
+
*
|
|
96
|
+
* @param _log - Decoded event log emitted by this contract.
|
|
97
|
+
**/
|
|
77
98
|
processLog(_log) {
|
|
78
99
|
}
|
|
79
100
|
/**
|
|
@@ -148,9 +169,8 @@ class BaseContract extends Construct {
|
|
|
148
169
|
}
|
|
149
170
|
}
|
|
150
171
|
/**
|
|
151
|
-
* Same as {@link
|
|
152
|
-
* @param calldata
|
|
153
|
-
* @returns
|
|
172
|
+
* Same as {@link stringifyFunctionData}, but throws if error occurs.
|
|
173
|
+
* @param calldata - Raw ABI-encoded calldata.
|
|
154
174
|
*/
|
|
155
175
|
mustStringifyFunctionData(calldata) {
|
|
156
176
|
const decoded = decodeFunctionData({
|
|
@@ -9,8 +9,8 @@ class ChainContractsRegister {
|
|
|
9
9
|
labels = new AddressMap([], "labels");
|
|
10
10
|
client;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
12
|
+
* Shared token metadata (symbol, decimals) for all tokens known on this chain.
|
|
13
|
+
**/
|
|
14
14
|
tokensMeta;
|
|
15
15
|
logger;
|
|
16
16
|
constructor(client, logger) {
|
|
@@ -18,6 +18,9 @@ class ChainContractsRegister {
|
|
|
18
18
|
this.tokensMeta = new TokensMeta(client);
|
|
19
19
|
this.logger = logger;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Clears all registered contracts, address labels, and token metadata.
|
|
23
|
+
**/
|
|
21
24
|
resetContracts() {
|
|
22
25
|
this.logger?.debug(
|
|
23
26
|
`resetting contacts register with ${this.contracts.size} contracts`
|
|
@@ -26,9 +29,19 @@ class ChainContractsRegister {
|
|
|
26
29
|
this.contracts.clear();
|
|
27
30
|
this.tokensMeta.reset();
|
|
28
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Looks up a contract by address.
|
|
34
|
+
* @param address - On-chain address.
|
|
35
|
+
* @returns The contract wrapper, or `undefined` if not registered.
|
|
36
|
+
*/
|
|
29
37
|
getContract(address) {
|
|
30
38
|
return this.contracts.get(address);
|
|
31
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Looks up a contract by address, throwing if not found.
|
|
42
|
+
* @param address - On-chain address.
|
|
43
|
+
* @throws If no contract is registered at this address.
|
|
44
|
+
*/
|
|
32
45
|
mustGetContract(address) {
|
|
33
46
|
const contract = this.contracts.mustGet(address);
|
|
34
47
|
if (!contract) {
|
|
@@ -36,9 +49,21 @@ class ChainContractsRegister {
|
|
|
36
49
|
}
|
|
37
50
|
return contract;
|
|
38
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Registers (or replaces) a contract at the given address.
|
|
54
|
+
* @param address - On-chain address.
|
|
55
|
+
* @param contract - Contract wrapper instance.
|
|
56
|
+
*/
|
|
39
57
|
setContract(address, contract) {
|
|
40
58
|
this.contracts.upsert(address, contract);
|
|
41
59
|
}
|
|
60
|
+
/**
|
|
61
|
+
* Assigns a human-readable label to an address for use in logging and
|
|
62
|
+
* parsed call output.
|
|
63
|
+
* @param address - On-chain address.
|
|
64
|
+
* @param label - Static label string, or a function that receives the
|
|
65
|
+
* current label and returns a new one.
|
|
66
|
+
*/
|
|
42
67
|
setAddressLabel(address, label) {
|
|
43
68
|
if (address === NOT_DEPLOYED) {
|
|
44
69
|
return;
|
|
@@ -49,13 +74,25 @@ class ChainContractsRegister {
|
|
|
49
74
|
this.labels.upsert(address, label(this.labels.get(address)));
|
|
50
75
|
}
|
|
51
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Returns a display string for an address, incorporating its label if one exists.
|
|
79
|
+
* @param address - On-chain address.
|
|
80
|
+
* @param omitAddress - When `true`, returns only the label (no address prefix).
|
|
81
|
+
* Falls back to the raw address when no label is set.
|
|
82
|
+
*/
|
|
52
83
|
labelAddress(address, omitAddress) {
|
|
53
84
|
const label = this.labels.get(address);
|
|
54
85
|
return label ? omitAddress ? label : `${address} [${label}]` : address;
|
|
55
86
|
}
|
|
87
|
+
/**
|
|
88
|
+
* The viem {@link Chain} object for this register's connected client.
|
|
89
|
+
**/
|
|
56
90
|
get chain() {
|
|
57
91
|
return this.client.chain;
|
|
58
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Numeric chain ID (e.g. `1` for Ethereum mainnet).
|
|
95
|
+
**/
|
|
59
96
|
get chainId() {
|
|
60
97
|
return this.client.chain.id;
|
|
61
98
|
}
|
|
@@ -4,9 +4,6 @@ class Construct {
|
|
|
4
4
|
logger;
|
|
5
5
|
client;
|
|
6
6
|
#register;
|
|
7
|
-
/**
|
|
8
|
-
* Indicates that contract state needs to be updated
|
|
9
|
-
*/
|
|
10
7
|
#dirty = false;
|
|
11
8
|
constructor(options) {
|
|
12
9
|
if (options instanceof ChainContractsRegister) {
|
|
@@ -38,12 +35,22 @@ class Construct {
|
|
|
38
35
|
safeGetRegister() {
|
|
39
36
|
return this.#register;
|
|
40
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The viem {@link Chain} object associated with the connected client.
|
|
40
|
+
**/
|
|
41
41
|
get chain() {
|
|
42
42
|
return this.client.chain;
|
|
43
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Numeric chain ID (e.g. `1` for Ethereum mainnet).
|
|
46
|
+
**/
|
|
44
47
|
get chainId() {
|
|
45
48
|
return this.client.chain.id;
|
|
46
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Gearbox network type for this chain (e.g. `"Mainnet"`, `"Arbitrum"`).
|
|
52
|
+
* @throws If the chain was not created by the Gearbox SDK.
|
|
53
|
+
*/
|
|
47
54
|
get networkType() {
|
|
48
55
|
if ("network" in this.chain) {
|
|
49
56
|
return this.chain.network;
|
|
@@ -51,6 +58,7 @@ class Construct {
|
|
|
51
58
|
throw new Error(`chain ${this.chain.id} is not a Gearbox SDK chain`);
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
61
|
+
* @internal
|
|
54
62
|
* Indicates that contract state diverged from onchain state and needs to be updated
|
|
55
63
|
*/
|
|
56
64
|
get dirty() {
|
|
@@ -59,6 +67,9 @@ class Construct {
|
|
|
59
67
|
set dirty(value) {
|
|
60
68
|
this.#dirty = value;
|
|
61
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Information about tokens known on this chain
|
|
72
|
+
*/
|
|
62
73
|
get tokensMeta() {
|
|
63
74
|
return this.register.tokensMeta;
|
|
64
75
|
}
|
|
@@ -66,6 +77,7 @@ class Construct {
|
|
|
66
77
|
return this.#register?.labelAddress(address, omitAddress) ?? address;
|
|
67
78
|
}
|
|
68
79
|
/**
|
|
80
|
+
* @internal
|
|
69
81
|
* Returns list of addresses that should be watched for events to sync state
|
|
70
82
|
*/
|
|
71
83
|
get watchAddresses() {
|
|
@@ -12,13 +12,26 @@ class TokensMeta extends AddressMap {
|
|
|
12
12
|
super(void 0, "tokensMeta");
|
|
13
13
|
this.#client = client;
|
|
14
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Clears all token metadata
|
|
17
|
+
**/
|
|
15
18
|
reset() {
|
|
16
19
|
this.clear();
|
|
17
20
|
this.#phantomTokensLoaded = void 0;
|
|
18
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns the symbol string for a token.
|
|
24
|
+
* @param token - Token address.
|
|
25
|
+
* @throws If the token is not in the registry.
|
|
26
|
+
*/
|
|
19
27
|
symbol(token) {
|
|
20
28
|
return this.mustGet(token).symbol;
|
|
21
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Returns the decimal count for a token.
|
|
32
|
+
* @param token - Token address.
|
|
33
|
+
* @throws If the token is not in the registry.
|
|
34
|
+
*/
|
|
22
35
|
decimals(token) {
|
|
23
36
|
return this.mustGet(token).decimals;
|
|
24
37
|
}
|
|
@@ -53,9 +66,19 @@ class TokensMeta extends AddressMap {
|
|
|
53
66
|
const asStr = formatBN(amount, this.decimals(token), precision);
|
|
54
67
|
return symbol ? `${asStr} ${this.symbol(token)}` : asStr;
|
|
55
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Finds a token by its symbol (e.g. `"USDC"`).
|
|
71
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
72
|
+
* @returns The matching metadata, or `undefined` if no token has this symbol.
|
|
73
|
+
*/
|
|
56
74
|
findBySymbol(symbol) {
|
|
57
75
|
return this.values().find((v) => v.symbol === symbol);
|
|
58
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Finds a token by its symbol, throwing if not found.
|
|
79
|
+
* @param symbol - Case-sensitive ticker symbol.
|
|
80
|
+
* @throws If no token matches the symbol.
|
|
81
|
+
*/
|
|
59
82
|
mustFindBySymbol(symbol) {
|
|
60
83
|
const meta = this.findBySymbol(symbol);
|
|
61
84
|
if (!meta) {
|