@gearbox-protocol/sdk 13.3.4 → 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.
|
@@ -681,21 +681,30 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
681
681
|
/**
|
|
682
682
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
683
683
|
**/
|
|
684
|
-
async openCA({
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
684
|
+
async openCA(props) {
|
|
685
|
+
const {
|
|
686
|
+
ethAmount,
|
|
687
|
+
creditManager,
|
|
688
|
+
reopenCreditAccount,
|
|
689
|
+
collateral,
|
|
690
|
+
permits,
|
|
691
|
+
debt,
|
|
692
|
+
withdrawToken,
|
|
693
|
+
referralCode,
|
|
694
|
+
to,
|
|
695
|
+
calls: openPathCalls,
|
|
696
|
+
callsAfter,
|
|
697
|
+
minQuota,
|
|
698
|
+
averageQuota
|
|
699
|
+
} = props;
|
|
697
700
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
698
701
|
const cm = cmSuite.creditManager;
|
|
702
|
+
let tokenToWithdraw;
|
|
703
|
+
if (withdrawToken === true) {
|
|
704
|
+
tokenToWithdraw = cm.underlying;
|
|
705
|
+
} else if (typeof withdrawToken === "string") {
|
|
706
|
+
tokenToWithdraw = withdrawToken;
|
|
707
|
+
}
|
|
699
708
|
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
700
709
|
creditManager: cm.address,
|
|
701
710
|
desiredQuotas: averageQuota
|
|
@@ -705,13 +714,26 @@ class AbstractCreditAccountService extends import_base.SDKConstruct {
|
|
|
705
714
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
706
715
|
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
707
716
|
...openPathCalls,
|
|
708
|
-
...
|
|
717
|
+
...tokenToWithdraw ? [
|
|
718
|
+
this.prepareWithdrawToken(
|
|
719
|
+
cm.creditFacade,
|
|
720
|
+
tokenToWithdraw,
|
|
721
|
+
import_constants.MAX_UINT256,
|
|
722
|
+
to
|
|
723
|
+
)
|
|
724
|
+
] : [],
|
|
709
725
|
...this.prepareUpdateQuotas(cm.creditFacade, {
|
|
710
726
|
minQuota,
|
|
711
727
|
averageQuota
|
|
712
|
-
})
|
|
728
|
+
}),
|
|
729
|
+
...callsAfter ?? []
|
|
713
730
|
];
|
|
714
|
-
|
|
731
|
+
let tx;
|
|
732
|
+
if (reopenCreditAccount) {
|
|
733
|
+
tx = await cmSuite.creditFacade.multicall(reopenCreditAccount, calls);
|
|
734
|
+
} else {
|
|
735
|
+
tx = cmSuite.creditFacade.openCreditAccount(to, calls, referralCode);
|
|
736
|
+
}
|
|
715
737
|
tx.value = ethAmount.toString(10);
|
|
716
738
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
717
739
|
}
|
|
@@ -670,21 +670,30 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
670
670
|
/**
|
|
671
671
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
672
672
|
**/
|
|
673
|
-
async openCA({
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
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;
|
|
686
689
|
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
|
|
687
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
|
+
}
|
|
688
697
|
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
|
|
689
698
|
creditManager: cm.address,
|
|
690
699
|
desiredQuotas: averageQuota
|
|
@@ -694,13 +703,26 @@ class AbstractCreditAccountService extends SDKConstruct {
|
|
|
694
703
|
this.#prepareIncreaseDebt(cm.creditFacade, debt),
|
|
695
704
|
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
|
|
696
705
|
...openPathCalls,
|
|
697
|
-
...
|
|
706
|
+
...tokenToWithdraw ? [
|
|
707
|
+
this.prepareWithdrawToken(
|
|
708
|
+
cm.creditFacade,
|
|
709
|
+
tokenToWithdraw,
|
|
710
|
+
MAX_UINT256,
|
|
711
|
+
to
|
|
712
|
+
)
|
|
713
|
+
] : [],
|
|
698
714
|
...this.prepareUpdateQuotas(cm.creditFacade, {
|
|
699
715
|
minQuota,
|
|
700
716
|
averageQuota
|
|
701
|
-
})
|
|
717
|
+
}),
|
|
718
|
+
...callsAfter ?? []
|
|
702
719
|
];
|
|
703
|
-
|
|
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
|
+
}
|
|
704
726
|
tx.value = ethAmount.toString(10);
|
|
705
727
|
return { calls, tx, creditFacade: cmSuite.creditFacade };
|
|
706
728
|
}
|
|
@@ -93,7 +93,7 @@ export declare abstract class AbstractCreditAccountService extends SDKConstruct
|
|
|
93
93
|
/**
|
|
94
94
|
* {@inheritDoc ICreditAccountsService.openCA}
|
|
95
95
|
**/
|
|
96
|
-
openCA(
|
|
96
|
+
openCA(props: OpenCAProps): Promise<CreditAccountOperationResult>;
|
|
97
97
|
/**
|
|
98
98
|
* {@inheritDoc ICreditAccountsService.getBorrowRate}
|
|
99
99
|
**/
|
|
@@ -405,8 +405,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
|
|
|
405
405
|
/**
|
|
406
406
|
* Flag to withdraw debt to wallet after opening credit account;
|
|
407
407
|
* used for borrowing functionality
|
|
408
|
+
* If true, will withdraw underlying token, otherwise will withdraw specified token
|
|
408
409
|
*/
|
|
409
|
-
|
|
410
|
+
withdrawToken?: boolean | Address;
|
|
410
411
|
/**
|
|
411
412
|
* Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
|
|
412
413
|
*/
|
|
@@ -416,10 +417,19 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
|
|
|
416
417
|
* Used for trading and strategy functionality
|
|
417
418
|
*/
|
|
418
419
|
calls: Array<MultiCall>;
|
|
420
|
+
/**
|
|
421
|
+
* Slot for optional call to execute after main tx.
|
|
422
|
+
* For example: add bots
|
|
423
|
+
*/
|
|
424
|
+
callsAfter?: Array<MultiCall>;
|
|
419
425
|
/**
|
|
420
426
|
* Address of credit manager to open credit account on
|
|
421
427
|
*/
|
|
422
428
|
creditManager: Address;
|
|
429
|
+
/**
|
|
430
|
+
* Optional address of credit account to reopen
|
|
431
|
+
*/
|
|
432
|
+
reopenCreditAccount?: Address;
|
|
423
433
|
/**
|
|
424
434
|
* Wallet address to transfer credit account to
|
|
425
435
|
*/
|