Recursive Lending Unwind Tool
Free to download on every platform. Comes pre-installed on BotFone, BotPad and BotFlip — with extra free apps included.
About this app
WHAT IT DOES
Recursive Lending Unwind Tool lets you unwind a recursive lending loop in a single batched transaction—repaying all borrowed funds and withdrawing all collateral. If you have used a recursive lending strategy (deposit → borrow → deposit → borrow) to maximize leverage, you need to reverse the process to exit the position: repay the debt, then withdraw the collateral. Instead of manually repaying and withdrawing in separate steps, you enter the lending protocol and token addresses, check your position, and execute a one-click unwind. The tool reads your collateral balance and debt, then repays the debt and withdraws the collateral in one batched operation. This is essential for DeFi users who want to exit leveraged positions efficiently.
HOW TO USE
Connect your EVM wallet and select the network. Enter the lending protocol contract address, the collateral token address, and the borrow token address. Click "Check position" to view your collateral balance, debt balance, and account liquidity (net value). Review the details, then click "Unwind position" to execute the transaction. The tool approves the borrow token for repayment, repays the outstanding debt, and withdraws the collateral in one batched operation.
TECHNICAL MECHANISM
The tool first reads the user's position details using the lending protocol's view functions: balanceOf(token, account) for collateral, borrowBalanceOf(token, account) for debt, and getAccountLiquidity(account) for net value. The unwind is performed in two sequential steps within a single transaction: (1) repay() the borrowed token—this requires prior approval of the borrow token for the lending contract, and (2) withdraw() the collateral token after the debt is cleared. The tool uses receipt.effectiveGasPrice for accurate gas reporting and provides progress feedback during the unwind process. Both operations are batched to minimize gas costs and execution time.
WHAT IT CANNOT SEE
This tool cannot unwind positions that are not owned by the connected wallet or that are already unwound—these conditions are verified before proceeding. It relies on the lending protocol implementing the specific repay/withdraw interface; protocols with non-standard unwind mechanics (e.g., requiring liquidation, multi-step processes, or separate withdrawal of rewards) are not supported. The tool cannot guarantee that the unwind will be profitable—the net value may be lower than expected due to interest accrual or market movements. It also cannot guarantee that liquidation will be avoided during the process if the position is already underwater.
PLEASE NOTE
Unwinding a recursive lending position requires sufficient funds to repay the debt. If you do not have enough borrow tokens in your wallet to cover the repayment, you will need to acquire them first. The lending protocol contract must be trusted; verify its security and audit status before use. This tool is for EVM chains only and does not support non-EVM networks.