A safety layer that prevents catastrophic swap losses in DeFi. SwapShield is an early-stage DeFi risk engine focused on pre-trade protection.
In AMM-based DEXs (like Uniswap), large swaps can silently suffer from extreme price impact due to limited liquidity.
Users often:
- Execute swaps without understanding slippage
- Lose a significant portion of their funds
- Have no clear warning before execution
Real-world incidents have shown users losing 50–90%+ of value in a single trade.
SwapShield simulates swaps before execution and provides real-time risk analysis:
- 📊 Accurate price impact calculation (execution-based)
- 💧 Liquidity usage detection
⚠️ Clear risk classification system- 🧠 Human-readable warnings for better decision making
SwapShield uses a constant product AMM model:
- Applies standard 0.3% fee (Uniswap-style)
- Calculates expected output (
amountOut) - Computes execution price vs spot price
- Derives true price impact
- Evaluates liquidity consumption
----------------------------------------
=== Large Trade ===
Token In: 50000.00 USDT
Amount Out: 120.500000 AAVE
Price Impact: 65.30%
Liquidity Usage: 50.00%
Risk Level: 🔴 CRITICAL
Message: You may lose more than 50% due to extreme price impact | Trade consumes a large portion of pool liquidity
🚨 WARNING: This trade is extremely unsafe!
----------------------------------------
Simulate swaps before execution to prevent unexpected losses.
Uses execution price, not just pool price — matching real DEX behavior.
Detects when a trade consumes a significant portion of pool liquidity.
Classifies trades into:
- 🟢 LOW
- 🟡 MEDIUM
- 🟠 HIGH
- 🔴 CRITICAL
Clean separation of:
- AMM logic
- Simulation engine
- Risk analysis
swapshield/
├── cmd/ # Entry point
├── internal/
│ ├── amm/ # AMM math (constant product formula)
│ ├── simulation/ # Swap simulation engine
│ ├── risk/ # Risk evaluation logic
│ ├── models/ # Data structures
│ └── dex/ # DEX data source (mock / future real integration)
git clone https://github.com/OprekerSejati/SwapShield.git
cd SwapShieldgo run cmd/main.go- 🛡️ Protect users from high-slippage trades
- 📊 Integrate into DEX frontends
- 🤖 Power trading bots with risk awareness
- 🧪 Simulate large trades safely
- 🧱 Build DeFi safety infrastructure
Contributions are welcome!
Feel free to:
- Open issues
- Suggest improvements
- Submit pull requests
- Integrate real on-chain data (Uniswap pools)
- REST API for external integrations
- Frontend dashboard
- Multi-chain support
- Trade splitting optimization
SwapShield is designed to evolve into an API that can be integrated into:
- 🧩 DEX frontends (pre-trade risk warnings)
- 🤖 Trading bots (risk-aware execution)
- 💼 Portfolio dashboards
- 🛡️ Wallet safety layers
The goal is to provide a reusable risk engine across the DeFi ecosystem.
DeFi is powerful — but unsafe UX leads to user losses.
SwapShield can prevent losses of up to 90%+ in extreme low-liquidity swaps.
SwapShield aims to:
Make every swap transparent, predictable, and safe
GitHub: https://github.com/OprekerSejati
If you find this useful, consider giving it a star ⭐
