Bot de liquidation DeFi sur Arbitrum. Utilise des flash loans Aave V3 pour liquider les positions sous-collatéralisées sans capital initial.
# 1. Smart contract
cd contracts
git init
forge install foundry-rs/forge-std
forge test -vvv
# 2. Bot Rust
cd bot
cp .env.example .env
# Edite .env
cargo build --release
cargo run --release├── contracts/
│ ├── src/FlashLiquidator.sol # Smart contract (compilé ✅, testé)
│ ├── test/FlashLiquidator.t.sol # 30+ tests Foundry
│ ├── script/Deploy.s.sol # Déploiement Arbitrum
│ └── foundry.toml
├── bot/
│ ├── src/main.rs # Entry point
│ ├── src/config.rs # Configuration
│ ├── src/indexer.rs # Event subscription (TODO)
│ ├── src/health.rs # Health factor checker (TODO)
│ ├── src/executor.rs # TX execution (TODO)
│ └── src/providers/ # Multi-protocol support
│ ├── mod.rs
│ └── aave_v3.rs # Aave V3 Arbitrum (TODO)
└── docs/
└── ARCHITECTURE.md # Architecture complète + déploiement VPS
- Smart contract FlashLiquidator — compilé, testé (30+ tests)
- Bot Rust — complet (indexer + health checker + executor)
- Guide déploiement VPS — documenté
-
cargo build(nécessite les crates, pas dispo dans ce sandbox) - Déploiement contract sur Arbitrum
- Test sur fork Anvil
- Production
Oui — setPaused(true) est déjà dans le contrat
./contracts/script/stop-smart-contract.sh
cast send 0xCONTRACT_ADDRESS
"setPaused(bool)" true
--private-key 0xTA_CLÉ
--rpc-url https://TON_QUICKNODE
Quand paused = true → toute tentative de liquidation revert. Le bot est neutralisé instantanément.
Ce qu'on ne peut PAS faire :
- Supprimer le contrat (pas de selfdestruct) — il reste sur la blockchain pour toujours mais inactif si paused
- Changer coldWallet ou owner — immutables par design, c'est une feature de sécurité
ssh root@108.61.159.79
- Depuis ta machine Windows — copier les fichiers
rsync -avz --exclude 'target/'
/mnt/d/dev-web3/liquidator-bot/
root@<VPS_IP>:/root/liquidator-bot/
- Sur le VPS — installation
ssh root@<VPS_IP>
apt update && apt upgrade -y
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source $HOME/.cargo/env
rustc --version
- Build du bot
cd /root/liquidator-bot/bot
cat .env
cargo build --release
- Service systemd (redémarre auto si crash ou reboot)
cat > /etc/systemd/system/liquidator.service << 'EOF' [Unit] Description=Aave V3 Liquidator Bot After=network-online.target Wants=network-online.target
[Service] Type=simple User=root WorkingDirectory=/root/liquidator-bot/bot ExecStart=/root/liquidator-bot/bot/target/release/liquidator-bot Restart=always RestartSec=10 Environment=RUST_LOG=info
[Install] WantedBy=multi-user.target EOF
systemctl daemon-reload systemctl enable liquidator systemctl start liquidator
- Voir les logs en direct
journalctl -u liquidator -f
Tu devrais voir en quelques secondes : ✅ Connected. Flash premium: 5 bps 💲 ETH price: $3487.23 (Chainlink) ✅ ETH balance: 0.002800 📡 Indexing borrowers from block ... Found 847 unique borrowers ✅ 312 users tracked, 2 at risk 🔄 Listening for new blocks... 💓 Block 441300000 | 312 tracked | 2 at-risk | 0 liq ($0.00 gross) | ETH $3487
- Commandes utiles
systemctl stop liquidator # arrêter systemctl start liquidator # démarrer systemctl restart liquidator # redémarrer (après update) journalctl -u liquidator -n 100 # 100 dernières lignes journalctl -u liquidator --since "1 hour ago" # dernière heure
- Mise à jour future
rsync -avz --exclude 'target/'
/mnt/d/dev-web3/liquidator-bot/
root@<VPS_IP>:/root/liquidator-bot/
cd /root/liquidator-bot/bot cargo build --release systemctl restart liquidator
systemctl stop liquidator
cd /root/liquidator-bot/contracts ./stop-smart-contract.sh
Ce que le bot cherche
Santé financière d'un emprunteur = Health Factor (HF)
HF = (collateral × liquidation_threshold) / dette
HF > 1.0 → position saine, intouchable HF < 1.0 → position liquidable → TON BOT AGIT
Exemple concret : Alice dépose 1 ETH ($2000) comme collateral Alice emprunte $1400 USDC (threshold 80% → HF = 1600/1400 = 1.14)
ETH tombe à $1600 → HF = (1600 × 0.80) / 1400 = 1280/1400 = 0.91 ← LIQUIDABLE ✅
Ce que le smart contract fait (atomique, une seule TX)
┌─────────────────────────────────────────────────────┐ │ 1. Flash loan : emprunte $700 USDC à Aave │ │ (gratuit, remboursé dans la même TX) │ │ │ │ 2. liquidationCall() sur Aave : │ │ → Repaye $700 de la dette d'Alice │ │ → Reçoit $735 en WETH (5% bonus liquidation) │ │ │ │ 3. Swap WETH → USDC sur Uniswap V3 : │ │ → $735 WETH → ~$733 USDC (0.3% frais swap) │ │ │ │ 4. Rembourse le flash loan : $700 + $0.35 (0.05%) │ │ │ │ 5. Profit net = $733 - $700.35 = ~$32.65 │ │ → envoyé automatiquement à ton cold wallet │ └─────────────────────────────────────────────────────┘
Coût total pour toi : ~$0.20 de gas sur Arbitrum Si non profitable → TX revert → tu perds 0
Le rôle du bot vs le contrat
BOT (Rust) CONTRAT (Solidity) ────────────────────────────────── ────────────────────────── Surveille les blocs WebSocket Exécute l'atomique Calcule qui est liquidable Flash loan Aave Choisit debt + collateral liquidationCall Estime le profit Swap Uniswap V3 Filtre si pas rentable Vérifie minProfit Envoie la TX Envoie profit au cold wallet Notifie Telegram Revert si pas rentable