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).
When the collateral token is itself an ERC-4626 vault share (e.g. a Morpho vault token like steakUSDC), each conversion redeems the shares through the vault at net asset value and swaps the underlying asset to the borrow token instead of swapping the share token on a DEX; a direct share-token route is only ever used when it prices within 1% of net asset value.
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.
Positions are unwound as far as the swap router can route; on a router-minimum stop the engine still withdraws all collateral not needed to back the residual, and completes a true full close whenever the unwind’s own guaranteed swap surpluses (or the Credit Account’s idle balance) cover the remainder — a residual below the router’s minimum routable size never fails the call, it is reported honestly in the preview (fully_unwound=false).
When other open Aave loops share this position’s collateral reserve, a full close withdraws only this position’s attributed share of the pooled collateral (event-ledger bookkeeping), leaving the rest supplied for the other positions.
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.
arbitrum, base, bsc, ethereum, hyperevm, tempo "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, MORPHO, or EULER.
AAVE, EULER, MORPHO "AAVE"
Morpho only: the bytes32 market id (from /v2/credit/morpho_markets). Required when protocol=MORPHO.
Euler only: the EVK vault the loop's collateral is in. Required when protocol=EULER.
Euler only: the EVK vault the loop borrowed from (the sub-account's controller). Required when protocol=EULER.
Euler only: the EVC sub-account (0-255) holding the looped position to unwind. 0 is the Credit Account itself.
0 <= x <= 255Target 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
If true, build a display estimate only: the swap legs are priced at market rate and no single-use firm quote is ever spent. Set it on every parameter-exploration call and omit it only on the build the user is about to sign.
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 — except firm-priced previews (preview=true with swap_provider='bebop'), which carry numbers only: the firm quotes are fetched at execution time, so there is no payload to sign yet.
EIP-712 typed data for gas-sponsored execution. Present when gas_sponsorship=true.
Which venue priced the swap leg(s): 'one_inch' (market route, slippage-bounded floors) or 'bebop' (firm quotes, one per swap leg, each partially filled at the leg's size). On preview=true responses, 'bebop' means the numbers are INDICATIVE, computed from the firm venue's live maker price levels without spending any quote; execution fetches the firm quotes at signing time. Always present, including on fallbacks.
one_inch, bebop Deadline of the firm swap quotes (the earliest across the unwind's swap legs) — sign and broadcast before it or the transaction reverts on-chain; refresh by re-calling this endpoint (discard the previous payload). Present only on executable swap_provider='bebop' builds; null on previews (no quote is spent for a preview).
Preview-only advisory: whether a firm-quote venue can serve this unwind's swap legs (estimated without spending any quote). Present only on preview=true responses; null otherwise.