@@ -1053,42 +1053,33 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
10531053
10541054 /**
10551055 * Executes swap specified by given calls, update quotas of affected tokens
1056- - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
1057- -> update quotas -> (optionally: execute swap path for trading/strategy) ->
1058- -> (optionally: withdraw debt for lending)
1059- - Basic open credit account: price update -> increase debt -> add collateral -> update quotas
1060- - Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
1061- - Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
1062- - In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
1063- * @param {bigint } ethAmount - native token amount to attach to tx
1064- * @param {Address } creditManager - address of credit manager to open credit account on
1065- * @param {Array<Asset> } collateral - array of collateral which can be just directly added or swapped using the path {@link Asset}
1066- * @param {Record<Address, PermitResult> } permits - permits of collateral tokens (in any permittable token is present) {@link PermitResult}
1067- * @param {bigint } debt - debt to open credit account with
1068- * @param {boolean } withdrawDebt - flag to withdraw debt to wallet after opening credit account;
1069- used for borrowing functionality
1070- * @param {bigint } referralCode - referral code to open credit account with
1071- * @param {Address } to - wallet address to transfer credit account to
1072- * @param {Array<MultiCall> } calls - array of MultiCall from router methods findOpenStrategyPath {@link MultiCall}.
1073- Used for trading and strategy functionality
1074- * @param {Array<Asset> } averageQuota - average quota for tokens after open {@link Asset}
1075- * @param {Array<Asset> } minQuota - minimum quota for tokens after open {@link Asset}
1056+ * - Open credit account is executed in the following order: price update -> increase debt -> add collateral ->
1057+ * -> update quotas -> (optionally: execute swap path for trading/strategy) ->
1058+ * -> (optionally: withdraw debt for lending)
1059+ *- Basic open credit account: price update -> increase debt -> add collateral -> update quotas
1060+ *- Lending: price update -> increase debt -> add collateral -> update quotas -> withdraw debt
1061+ *- Strategy/trading: price update -> increase debt -> add collateral -> update quotas -> execute swap path
1062+ *- In strategy is possible situation when collateral is added, but not swapped; the only swapped value in this case will be debt
10761063 * @returns All necessary data to execute the transaction (call, credit facade)
1077- */
1078- public async openCA ( {
1079- ethAmount,
1080- creditManager,
1081- collateral,
1082- permits,
1083- debt,
1084- withdrawToken,
1085- referralCode,
1086- to,
1087- calls : openPathCalls ,
1064+ **/
1065+ public async openCA (
1066+ props : OpenCAProps ,
1067+ ) : Promise < CreditAccountOperationResult > {
1068+ const {
1069+ ethAmount,
1070+ creditManager,
1071+ reopenCreditAccount,
1072+ collateral,
1073+ permits,
1074+ debt,
1075+ withdrawToken,
1076+ referralCode,
1077+ to,
1078+ calls : openPathCalls ,
10881079
1089- minQuota,
1090- averageQuota,
1091- } : OpenCAProps ) : Promise < CreditAccountOperationResult > {
1080+ minQuota,
1081+ averageQuota,
1082+ } = props ;
10921083 const cmSuite = this . sdk . marketRegister . findCreditManager ( creditManager ) ;
10931084 const cm = cmSuite . creditManager ;
10941085 let tokenToWithdraw : Address | undefined ;
@@ -1124,7 +1115,12 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
11241115 } ) ,
11251116 ] ;
11261117
1127- const tx = await this . openCreditAccountTx ( cmSuite , to , calls , referralCode ) ;
1118+ let tx : RawTx ;
1119+ if ( reopenCreditAccount ) {
1120+ tx = await this . multicallTx ( cmSuite , reopenCreditAccount , calls ) ;
1121+ } else {
1122+ tx = await this . openCreditAccountTx ( cmSuite , to , calls , referralCode ) ;
1123+ }
11281124 tx . value = ethAmount . toString ( 10 ) ;
11291125
11301126 return { calls, tx, creditFacade : cmSuite . creditFacade } ;
0 commit comments