About
Loophole
Unwind recursive Aave leverage positions before liquidation.
Loophole is an AI agent that monitors your Aave position health, simulates flash-loan-powered unwinds, and executes them atomically — all through a Telegram bot.
The Problem
DeFi users create recursive leverage positions (deposit stETH -> borrow WETH -> deposit again -> repeat). When prices drop, these positions face liquidation with a ~5% penalty. Unwinding manually requires multiple transactions and capital you might not have.
The Solution
Loophole uses Aave V3 flash loans to atomically unwind your entire looped position in a single transaction:
Flash loan the debt asset
Repay all debt loops (iteratively, auto-detects loop count) Pull aTokens from user, withdraw collateral Swap via Uniswap v4 (unlock/callback pattern) Repay flash loan + premium Return remainder as USDC An AI agent (powered by Gemini) monitors your position, simulates outcomes, and recommends when to unwind — all accessible via Telegram.
How it's made
Loophole has two packages: a Solidity contract and a TypeScript agent.
Contract (Loophole.sol) — Deployed on Base at 0x0d0AAC9595152fA9c2Ad80fcc86d4B9bf35F5f99. Takes an Aave V3 flash loan, iteratively repays user debt and withdraws collateral, swaps via Uniswap v4 using the unlock/callback pattern with flash accounting (settle + take), and returns USDC to the user. All in one atomic transaction. Protected by ReentrancyGuard, custom errors, and slippage checks. Fork-tested against real Aave V3 state.
Agent — Built with ADK-TS (Gemini 2.5 Flash) and grammY for Telegram. Six tools: get_position fetches Aave V3 data, get_price pulls from Stork oracle, simulate_unwind estimates output and fees, estimate_liquidation stress-tests under price drops, optimize_unwind generates a risk report, and execute_unwind builds unsigned transaction calldata with EIP-681 QR codes so the user can scan and sign from their mobile wallet.
Uniswap v4 — The contract implements IUnlockCallback. Swaps go through PoolManager using unlock() → unlockCallback() → settle() + take(). No direct swap() calls.
Stork (Arc) — Agent uses the Stork REST API for real-time price feeds to calculate health factor, liquidation distance, and unwind economics. USDC settlement.
Stack — Foundry, viem, ADK-TS agent framework, Base chain.
From the public ETHGlobal showcase page. Votes, swipes and the judge score are hackfeed's own.






