Withdrawing Collateral

Remove tokens from a Credit Account to an external address.

For SDK implementation, see Withdrawing Collateral.

Why

You need to withdraw collateral when:

  • Taking profits - Remove excess collateral while maintaining healthy position

  • Rebalancing - Move funds between accounts or protocols

  • Closing account - Extract all remaining tokens before closing

Withdrawing collateral decreases your account's total weighted value (TWV), which lowers the health factor.

What

withdrawCollateral transfers tokens from the Credit Account to a specified recipient. On execution:

  1. Tokens are transferred from the Credit Account to the recipient

  2. If withdrawing the full balance, the token may be disabled as collateral

  3. Safe pricing is activated for the collateral check (uses min of main and reserve price feeds)

Important: Withdrawals trigger stricter collateral checks using safe prices, so ensure sufficient buffer above the liquidation threshold.

How

Withdraw Full Balance

Use type(uint256).max to withdraw the entire token balance:

Withdraw During Closure

When closing an account, you can withdraw all tokens to yourself:

Gotchas

Safe Prices Are Used

After withdrawal, collateral checks use safe pricing (minimum of main and reserve feeds). This means:

  • Your effective collateral value may be lower than expected

  • Maintain buffer above liquidation threshold

  • Check safe prices before withdrawing large amounts

Forbidden Tokens Block Withdrawal

If any forbidden token is enabled as collateral on the account, withdrawals are blocked in multicalls:

Solution: First swap forbidden tokens to allowed ones, then withdraw.

Phantom Token Unwrapping

If the token being withdrawn is a phantom token (e.g., staked position token), it's automatically unwrapped:

  1. Phantom token is withdrawn from the vault/pool

  2. The underlying deposited token is sent to the recipient

  3. No slippage protection - assumed to happen at non-manipulatable rate

Dust Handling

For clean account closure, use type(uint256).max to handle dust amounts:

Recipient Validation

The recipient address must be a valid address. Common patterns:

See Also

Last updated