Gearbox V2
Credit accounts
Closing credit account

Closing a credit account

To repay the debt and close a Credit Account normally, the following CreditFacade function can be used:

function closeCreditAccount(
    address to,
    uint256 skipTokenMask,
    bool convertWETH,
    MultiCall[] calldata calls
) external payable;
toThe address to which the remaining collateral is sent after repaying the loan and closing the account.
skipTokenMaskA mask that encodes the tokens which should not be sent back to the user. Can be used to avoid sending dust or tokens that revert on transfer.
convertWETHWhether to convert WETH to ETH before sending it to the user.
callsThe array of calls to execute before closing the account.

The multicall within closeCreditAccount would typically be used to convert collateral assets into underlying. If there is not enough underlying on the CA after performing the multicall, the Credit Manager will try to transfer the shortfall from the borrower.

This means that it is possible to normally close even an unhealthy account, as long as either the user deposits more underlying during a multicall through addCollateral, or has enough underlying on their address that is approved to the Credit Manager.

Trying to close a Credit Account normally will fail if the Credit Manager cannot repay the entire debt to the pool.