# DBIS - Debt-Based Institutional Strategy A comprehensive DeFi leverage management system implementing atomic amortizing cycles to improve position health while maintaining strict invariants. ## ๐Ÿš€ Quick Start ### Prerequisites - **Node.js** >= 18.0.0 - **Foundry** (Forge) - **Git** ### Installation ```bash # Clone repository git clone cd no_five # Install dependencies npm install # Install Foundry (if not installed) curl -L https://foundry.paradigm.xyz | bash foundryup # Install Foundry dependencies forge install ``` ### Environment Setup ```bash # Copy example env file cp .env.example .env # Edit .env with your configuration nano .env ``` ### Compile Contracts ```bash forge build ``` ### Run Tests ```bash # All tests forge test # With coverage forge coverage # Fork tests forge test --fork-url $RPC_URL ``` ## ๐Ÿ“ Project Structure ``` / โ”œโ”€โ”€ contracts/ # Solidity contracts โ”‚ โ”œโ”€โ”€ core/ # Core contracts (Vault, Router, Kernel) โ”‚ โ”œโ”€โ”€ governance/ # Governance contracts (Policies, Config) โ”‚ โ”œโ”€โ”€ oracle/ # Oracle adapter โ”‚ โ””โ”€โ”€ interfaces/ # Contract interfaces โ”œโ”€โ”€ test/ # Foundry tests โ”‚ โ”œโ”€โ”€ kernel/ # Kernel tests โ”‚ โ”œโ”€โ”€ router/ # Router tests โ”‚ โ”œโ”€โ”€ vault/ # Vault tests โ”‚ โ”œโ”€โ”€ integration/ # Integration tests โ”‚ โ””โ”€โ”€ fuzz/ # Fuzz tests โ”œโ”€โ”€ mev-bot/ # MEV bot (TypeScript) โ”‚ โ””โ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ strategy/ # Trading strategies โ”‚ โ”œโ”€โ”€ utils/ # Utilities โ”‚ โ””โ”€โ”€ providers/ # Protocol clients โ”œโ”€โ”€ simulation/ # Simulation framework โ”‚ โ””โ”€โ”€ src/ # Simulation modules โ”œโ”€โ”€ scripts/ # Deployment scripts โ””โ”€โ”€ docs/ # Documentation ``` ## ๐Ÿ—๏ธ Architecture ### Core Components 1. **DBISInstitutionalVault**: Tracks collateral and debt 2. **FlashLoanRouter**: Aggregates flash loans from multiple providers 3. **RecursiveLeverageKernel**: Implements atomic amortizing cycles 4. **PolicyEngine**: Modular governance system 5. **GovernanceGuard**: Enforces invariants and policies ### Key Features - โœ… **Atomic Amortization**: Guaranteed position improvement per cycle - โœ… **Multi-Provider Flash Loans**: Aave, Balancer, Uniswap, DAI - โœ… **Modular Policies**: Plugin-based governance - โœ… **Invariant Enforcement**: On-chain position verification - โœ… **MEV Protection**: Flashbots bundle support - โœ… **Multi-Chain Ready**: Deploy to any EVM chain ## ๐Ÿ“– Documentation - [Architecture](docs/ARCHITECTURE.md) - System design and components - [Invariants](docs/INVARIANTS.md) - Invariant rules and enforcement - [Atomic Cycle](docs/ATOMIC_CYCLE.md) - Amortization cycle mechanics - [Policy System](docs/POLICY.md) - Governance and policy modules - [Deployment](docs/DEPLOYMENT.md) - Deployment guide - [Testing](docs/TESTING.md) - Testing guide - [MEV Bot](docs/MEV_BOT.md) - MEV bot documentation ## ๐Ÿงช Testing ```bash # Unit tests forge test --match-path test/vault/ forge test --match-path test/kernel/ # Integration tests forge test --match-path test/integration/ # Invariant tests forge test --match-test invariant # Fuzz tests forge test --match-test testFuzz # Fork tests forge test --fork-url $RPC_URL ``` ## ๐Ÿšข Deployment ### Testnet ```bash tsx scripts/testnet.ts ``` ### Mainnet ```bash # Deploy contracts tsx scripts/deploy.ts # Configure tsx scripts/configure.ts ``` See [Deployment Guide](docs/DEPLOYMENT.md) for detailed instructions. ## ๐Ÿค– MEV Bot ### Setup ```bash cd mev-bot npm install npm run build ``` ### Run ```bash npm start ``` See [MEV Bot Documentation](docs/MEV_BOT.md) for details. ## ๐Ÿงฎ Simulation Run stress tests and risk analysis: ```bash cd simulation npm install # Run stress tests npm run stress # Price shock simulation npm run price-shock -20 # LTV bounding npm run ltv-bounding # Flash liquidity check npm run flash-liquidity ``` ## ๐Ÿ”’ Security ### Core Invariants Every transaction must satisfy: - Debt never increases - Collateral never decreases - Health factor never worsens - LTV never worsens ### Audit Status โš ๏ธ **Unaudited** - This code is unaudited. Use at your own risk. For production deployments: 1. Complete security audit 2. Start with conservative parameters 3. Monitor closely 4. Have emergency pause ready ## ๐Ÿ“Š Monitoring ### Events Monitor these events: - `AmortizationExecuted`: Successful cycle - `InvariantFail`: Invariant violation - `PositionSnapshot`: Position change - `CollateralAdded`: Collateral increase - `DebtRepaid`: Debt decrease ### Metrics Track: - Health factor trends - Flash loan execution rates - Policy denial rates - Gas costs - Position size ## ๐Ÿค Contributing 1. Fork the repository 2. Create a feature branch 3. Make your changes 4. Add tests 5. Submit a pull request ## ๐Ÿ“ License MIT License ## โš ๏ธ Disclaimer This software is provided "as is" without warranty. Use at your own risk. Always audit code before deploying to mainnet. ## ๐Ÿ†˜ Support For questions or issues: - Open an issue on GitHub - Review documentation - Check test files for examples --- **Built with โค๏ธ for the DeFi community**