Skip to content

Commit 2091ef9

Browse files
committed
fix: liquidate KYC
1 parent bf05428 commit 2091ef9

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/sdk/accounts/AbstractCreditAccountsService.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,45 @@ export abstract class AbstractCreditAccountService extends SDKConstruct {
14851485
return mc;
14861486
}
14871487

1488+
/**
1489+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
1490+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
1491+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
1492+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
1493+
* @param creditManager - Credit manager address
1494+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
1495+
*/
1496+
public async getDepositDiffCalls(
1497+
amount: bigint,
1498+
creditManager: Address,
1499+
): Promise<Array<MultiCall> | undefined> {
1500+
const suite = this.sdk.marketRegister.findCreditManager(creditManager);
1501+
const meta = this.sdk.tokensMeta.mustGet(suite.underlying);
1502+
if (!this.sdk.tokensMeta.isKYCUnderlying(meta)) {
1503+
return undefined;
1504+
}
1505+
1506+
const adapter = suite.creditManager.adapters.get(meta.addr);
1507+
const adapterAddress = adapter?.address;
1508+
1509+
if (!adapterAddress) {
1510+
return undefined;
1511+
}
1512+
1513+
const mc: Array<MultiCall> = [
1514+
{
1515+
target: adapterAddress,
1516+
callData: encodeFunctionData({
1517+
abi: ierc4626AdapterAbi,
1518+
functionName: "depositDiff",
1519+
args: [amount],
1520+
}),
1521+
},
1522+
];
1523+
1524+
return mc;
1525+
}
1526+
14881527
/**
14891528
* Returns raw txs that are needed to update all price feeds so that all credit accounts (possibly from different markets) compute
14901529
*

src/sdk/accounts/CreditAccountsServiceV310.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,16 @@ export class CreditAccountServiceV310
203203
creditAccount: ca,
204204
});
205205

206+
const wrapCalls =
207+
(await this.getDepositDiffCalls(1n, ca.creditManager)) ?? [];
208+
206209
const addCollateral = collateralAssets.filter(a => a.balance > 0);
207210

208211
const calls: Array<MultiCall> = [
209212
...priceUpdates,
210213
...this.prepareAddCollateral(ca.creditFacade, addCollateral, permits),
211214
...claimPath.calls,
215+
...wrapCalls,
212216
...assetsToWithdraw.map(t =>
213217
this.prepareWithdrawToken(ca.creditFacade, t.token, MAX_UINT256, to),
214218
),

src/sdk/accounts/types.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -849,6 +849,19 @@ export interface ICreditAccountsService extends Construct {
849849
creditManager: Address,
850850
): Promise<Array<MultiCall> | undefined>;
851851

852+
/**
853+
* Returns multicall entries to call depositDiff on the KYC ERC-4626 adapter for the given credit manager.
854+
* Deposits the leftover underlying (e.g. after decreasing debt) into the vault so the account does not hold excess underlying.
855+
* Only applies when the credit manager's underlying is KYC-gated and has an ERC-4626 adapter configured.
856+
* @param amount - Leftover underlying amount to deposit into the vault (in underlying decimals)
857+
* @param creditManager - Credit manager address
858+
* @returns Array of MultiCall to pass to credit facade multicall, or undefined if underlying is not KYC or no adapter is configured
859+
*/
860+
getDepositDiffCalls(
861+
amount: bigint,
862+
creditManager: Address,
863+
): Promise<Array<MultiCall> | undefined>;
864+
852865
/**
853866
* Withdraws a single collateral from credit account to wallet to and updates quotas;
854867
* technically can withdraw several tokens at once

0 commit comments

Comments
 (0)