Before you start
- An API key. See the Quick Start.
- A Credit Account for the user, holding the collateral token. The loop never pulls from the user’s wallet, so the account must already hold
initial_collateral_amount. See Create an Account and Fund an Account.
1. Pick a market
Name the market the same way as for a loan: token symbols on Aave, amarket_id on Morpho, or collateral_vault and borrow_vault on Euler. See Pick a market for the endpoints that list them.
Two things to check before offering a market: loan_to_value can’t exceed the market’s limit (the reserve LTV on Aave, lltv on Morpho, the collateral’s borrow_ltv on Euler), and the market’s available_liquidity must cover the loop’s total borrow.
2. Preview
Callloop with preview: true to see the projected position without building anything. Use it on every change while the user adjusts leverage. This previews a 2x WETH position on Aave, borrowing USDC at 70% LTV against 1 WETH:
3. Build and sign
Send the same request withpreview: false. The response has a transaction for the user to sign and send, or eip_712 with gas_sponsorship: true. See Gas Sponsorship.
4. Track the position
status (OPEN or CLOSED), the live current state and a full history. The fields to show:
current.leverage: current leverage, from the collateral and debt values.current.health_factor: distance to liquidation. Above 1 is safe.health_factor_scopeismarketon Morpho and Euler, where each position stands alone, andaccounton Aave, where all Aave positions in the account share one health factor.current.net_apy: what the position earns on the user’s equity at today’s rates:leverage × collateral_apy - (leverage - 1) × borrow_apy. Negative means the borrow cost exceeds the collateral yield.current.net_usd_value: what the position is worth now, collateral minus debt, in USD.pnl.total_pnl_usdandpnl.total_pnl_quote: what the position has made or lost since it opened, in USD and in the borrowed token. Both count the entry and exit costs, the carry and the price moves.pnl.total_pnl_percentis the same figure as a return on what the user put in. A closed position keeps its final PnL, and eachhistoryentry shows the equity it put in or took out (equity_flow_quote).
5. Unwind
unloop withdraws collateral, swaps it to the borrow token and repays, in one transaction. Leave out target_multiplier to close the position completely, or set it to reduce leverage to that level:
allow_partial: true, the API returns the most it can do and sets preview.fully_unwound to false; call unloop again to finish. Without it, an unreachable target returns 400.
After a full close, the collateral is back in the Credit Account. Send it to the user’s wallet with transfer. See Withdraw Funds.
Good to know
- Maximum leverage at a given LTV is about
0.9 ÷ (1 - loan_to_value ÷ 100), so 70% LTV allows about 3x. If the requestedmultiplierisn’t reachable, the400message names the reachable figure. - Yield-bearing collateral. Vault shares and Pendle principal tokens work as collateral where a market accepts them. Their rate comes back in
collateral_apy. On principal-token markets,pt_maturitygives the date the fixed rate runs to, andpt_loopabletells you whether new loops are still allowed. - Slippage protection. Every swap has a minimum output enforced on-chain, so a bad fill reverts the whole transaction instead of leaving a half-built position. Anything a swap delivers above the minimum stays in the Credit Account.
- PnL is measured in the borrowed token. On a correlated loop such as wstETH against WETH,
total_pnl_quoteisolates what the loop earned from the borrowed token’s own price, so a positive figure there can still be a USD loss when that token falls;total_pnl_usdshows it. A loop or unwind entry inhistorywithflow_basis: "oracle"means that transaction’s swap cost could not be separated from the amounts moved, so PnL reads slightly high.pnlis absent when part of the position’s history cannot be priced. - Rebalance several positions at once.
POST /v2/credit/rebalancetakes a list of positions, each with a target size, target leverage orclose: true, and moves them all in one transaction. Money freed by closing one position can fund another. It isn’t available on HyperEVM.
Errors
Endpoints
Next
Crypto-Backed Loans
Plain borrowing, repayment and market discovery.
Fund an Account
Get the collateral into the Credit Account.
Gas Sponsorship
Pay gas for your users so they never need ETH.