Unwind a leveraged loop
Unwind an Aave or Morpho loop in ONE atomic transaction.
Repeatedly withdraws collateral, swaps it to the borrow token at a GUARANTEED minimum output (enforced on-chain), and repays. The floor discipline means a swap filling anywhere within the slippage tolerance can never break a later step; any positive surplus stays in the Credit Account as borrow-token dust (the preview reports the bound as estimated_max_dust).
Omit target_multiplier for a full close: the debt is cleared exactly — accrued interest included — and the pair collateral is returned to the Credit Account. Pass 1 to clear the debt but keep the collateral supplied, or a value above 1 to delever to that multiplier (it must be below the position’s current multiplier).
Each withdrawal is sized to keep the position’s health factor ≥ 1.02 at that step, so a position opened very close to the liquidation threshold may need more than one transaction to fully close — set allow_partial=true to return the maximum single-transaction progress (preview.fully_unwound=false), then call unloop again to finish. Very large unwinds relative to pool depth can still exceed the slippage tolerance through their own cumulative price impact.
For protocol=MORPHO pass a market_id from /v2/credit/morpho_markets; inspect open loops via /v2/credit/looped_positions.
Body
Unwind a leveraged loop: repeatedly withdraw collateral, swap it back to the borrow token at a guaranteed minimum output, and repay — all in ONE atomic transaction from the Credit Account.
The address that owns the Credit Account.
"0x0E407CdeBD8e078E6966ef6740540d25F5897082"
Blockchain network.
base, ethereum, arbitrum, hyperevm, tempo, bsc "ethereum"
Token supplied as collateral in the loop being unwound. For MORPHO it must be the market's collateral token.
"wstETH"
"WETH"
Token borrowed in the loop; withdrawn collateral is swapped back to it and used to repay. For MORPHO it must be the market's loan token.
"WETH"
"USDC"
Lending protocol to unwind: AAVE or MORPHO. EULER unlooping is not available yet.
AAVE, EULER, MORPHO "AAVE"
Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.
Target leverage after the unwind. Omit (null) for a FULL unwind: the debt is cleared exactly — accrued interest included — and all pair collateral is withdrawn back to the Credit Account. 1 runs the same exact debt close but leaves the collateral supplied (earning). A value greater than 1 delevers the position to that multiplier. Must be below the position's current multiplier.
x >= 12
Per-swap slippage tolerance in percent. Unwind dust is bounded by this per iteration, so tighter slippage means less dust.
0 < x <= 100.3
If the target cannot be reached in one transaction (e.g. a position opened very close to the liquidation threshold), return the maximum-progress plan (preview.fully_unwound=false) instead of a 400. A second unloop call, now from a much lower leverage, finishes the job.
false
If true, returns EIP-712 typed data for gas-sponsored execution instead of an unsigned transaction.
false
Response
Successful Response
The atomic unwind transaction plus its guaranteed-floor preview.
Projected end state, computed on guaranteed swap floors.
Unsigned transaction for direct execution by the owner. Present when gas_sponsorship=false.
{
"chainId": "0x2105",
"data": "0x1688f0b900000000000000000000000029fcb43b46531bca003ddc8fcb67ffe91900c762000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000675f4a3d",
"from": "0x4A83b4413CF41C3244027e1590E35a0F48403F0c",
"gas": "0x7a120",
"maxFeePerGas": "0x59682f00",
"maxPriorityFeePerGas": "0x3b9aca00",
"nonce": "0x5",
"to": "0x4e1DCf7AD4e460CfD30791CCC4F9c8a4f820ec67",
"value": "0x0"
}EIP-712 typed data for gas-sponsored execution. Present when gas_sponsorship=true.
{
"domain": {
"chainId": 8453,
"verifyingContract": "0x6B90E8B4E3E971E74C1A47a3a20976377E2dB4b1"
},
"message": {
"baseGas": "0",
"data": "0x8d80ff0a0000000000000000000000000000000000000000000000000000000000000020",
"gasPrice": "0",
"gasToken": "0x0000000000000000000000000000000000000000",
"nonce": "7",
"operation": 1,
"refundReceiver": "0x0000000000000000000000000000000000000000",
"safeTxGas": "0",
"to": "0x93C23AAE4793C14D6DF35D2A2A2234204e1559dA",
"value": "0"
},
"primaryType": "SafeTx",
"types": {
"EIP712Domain": [
{ "name": "chainId", "type": "uint256" },
{
"name": "verifyingContract",
"type": "address"
}
],
"SafeTx": [
{ "name": "to", "type": "address" },
{ "name": "value", "type": "uint256" },
{ "name": "data", "type": "bytes" },
{ "name": "operation", "type": "uint8" },
{ "name": "safeTxGas", "type": "uint256" },
{ "name": "baseGas", "type": "uint256" },
{ "name": "gasPrice", "type": "uint256" },
{ "name": "gasToken", "type": "address" },
{
"name": "refundReceiver",
"type": "address"
},
{ "name": "nonce", "type": "uint256" }
]
}
}