Skip to content

Commit 828314d

Browse files
committed
fix: allow withdrawing arbitrary tokens when opening CA
1 parent 90a31af commit 828314d

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

src/sdk/accounts/AbstractCreditAccountsService.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,7 +1057,7 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
10571057
collateral,
10581058
permits,
10591059
debt,
1060-
withdrawDebt,
1060+
withdrawToken,
10611061
referralCode,
10621062
to,
10631063
calls: openPathCalls,
@@ -1067,6 +1067,12 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
10671067
}: OpenCAProps): Promise<CreditAccountOperationResult> {
10681068
const cmSuite = this.sdk.marketRegister.findCreditManager(creditManager);
10691069
const cm = cmSuite.creditManager;
1070+
let tokenToWithdraw: Address | undefined;
1071+
if (withdrawToken === true) {
1072+
tokenToWithdraw = cm.underlying;
1073+
} else if (typeof withdrawToken === "string") {
1074+
tokenToWithdraw = withdrawToken;
1075+
}
10701076

10711077
const priceUpdatesCalls = await this.getPriceUpdatesForFacade({
10721078
creditManager: cm.address,
@@ -1077,9 +1083,16 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
10771083
...priceUpdatesCalls,
10781084
this.#prepareIncreaseDebt(cm.creditFacade, debt),
10791085
...this.prepareAddCollateral(cm.creditFacade, collateral, permits),
1080-
...openPathCalls,
1081-
...(withdrawDebt
1082-
? [this.prepareWithdrawToken(cm.creditFacade, cm.underlying, debt, to)]
1086+
...openPathCalls, // путь из underlying в withdrawal token
1087+
...(tokenToWithdraw
1088+
? [
1089+
this.prepareWithdrawToken(
1090+
cm.creditFacade,
1091+
tokenToWithdraw,
1092+
MAX_UINT256,
1093+
to,
1094+
),
1095+
]
10831096
: []),
10841097
...this.prepareUpdateQuotas(cm.creditFacade, {
10851098
minQuota,

src/sdk/accounts/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@ export interface OpenCAProps extends PrepareUpdateQuotasProps {
342342
/**
343343
* Flag to withdraw debt to wallet after opening credit account;
344344
* used for borrowing functionality
345+
* If true, will withdraw underlying token, otherwise will withdraw specified token
345346
*/
346-
withdrawDebt?: boolean;
347+
withdrawToken?: boolean | Address;
347348
/**
348349
* Permits of collateral tokens (in any permittable token is present) {@link PermitResult}
349350
*/

0 commit comments

Comments
 (0)