AVS-Secured Lending Protocol with Automated Insurance & Basket Rebalancing
Bastion is a decentralized lending protocol built on Base Sepolia that combines EigenLayer's Active Validation Services (AVS), automated insurance protection, and intelligent basket management to create a secure, efficient DeFi lending experience.
- π‘οΈ Automatic Insurance: Every deposit gets depeg protection
- π° Dual Yield: Earn from lending + swap fees
- π Auto-Rebalancing: Basket weights adjust based on volatility
- πΈ Instant Payouts: Automatic compensation on depeg events
- π Dynamic Fees: 0.05-1.00% APR based on market volatility
- π― Basket Collateral: Diversified assets (stETH, cbETH, rETH, USDe)
- β‘ Fast Loans: Over-collateralized (150% ratio)
- π Health Monitoring: Real-time position tracking
- π Token Swaps: Trade with 0.2% fee
- π‘οΈ Insurance Funding: 80% of fees β insurance, 20% β protocol
- π’ Smart Decimals: Automatic conversion (18 β 6 decimals)
- β±οΈ Real-Time Quotes: Live price updates
Bastion consists of four core modules:
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Basket Vault ββββββββ Lending Module ββββββββ Insurance Pool β
β (Multi-Asset) β β (Borrow/Lend) β β (Depeg Cover) β
ββββββββββ¬βββββββββ ββββββββββ¬ββββββββββ ββββββββββ¬βββββββββ
β β β
β βββββββββ΄βββββββββ β
β β AVS Operators β β
β β (Verification) β β
β βββββββββ¬βββββββββ β
β β β
ββββββββββββββββββββββββββ΄ββββββββββββββββββββββββββ
Chainlink Oracles
- Multi-asset collateral basket with automated rebalancing
- Dynamic weight adjustment using Chainlink price feeds
- Supports stETH, cbETH, rETH, and USDe
- DEX integration for automated swaps
- Automated depeg insurance funded by swap fees
- 80% of swap fees automatically fund insurance pool
- AVS-verified depeg detection (20% threshold)
- Automatic payout distribution to affected LPs
- Volatility-based lending fees
- Low (<10%): 0.05% APR
- Medium (10-14%): 0.30% APR
- High (>14%): 1.00% APR
- EigenLayer AVS operators provide security
- Depeg event verification
- Basket rebalancing triggers
- Slashing protection for malicious behavior
- Node.js 18+
- Foundry
- Base Sepolia ETH (Get from faucet)
- MetaMask or compatible wallet
# Clone the repository
git clone https://github.com/big14way/bastion-protocol.git
cd bastion-protocol
# Install dependencies
npm install
forge install
# Setup environment
cp .env.example .env
# Add your PRIVATE_KEY to .env# Deploy full protocol
forge script script/BastionDemo.s.sol:BastionDemo \
--rpc-url https://sepolia.base.org \
--broadcastcd frontend
npm install
npm run devVisit http://localhost:3002
# Mint test tokens to your wallet
cd "/path/to/bastion" && source .env && \
RECIPIENT=0xYourAddress forge script script/MintToUser.s.sol:MintToUser \
--rpc-url https://sepolia.base.org --broadcast| Contract | Address | Purpose |
|---|---|---|
| BastionVault | 0xF5c0325F85b1d0606669956895c6876b15bc33b6 |
Main vault for deposits/withdrawals |
| LendingModule | 0x6825B4E72947fE813c840af63105434283c7db2B |
Borrowing and lending logic |
| InsuranceTranche | 0x2139FDE811D0aF95b5b030A4583aAFa572d0bfBF |
Depeg insurance coverage |
| SimpleSwap | 0xCcbe164367A0f0a0E129eD88efC1C3641765Eb97 |
Token swaps with fee collection |
| VolatilityOracle | 0xD1c62D4208b10AcAaC2879323f486D1fa5756840 |
Volatility calculations |
| BastionTaskManager | 0x6997d539bC80f514e7B015545E22f3Db5672a5f8 |
AVS task coordination |
| stETH (Mock) | 0x60D36283c134bF0f73B67626B47445455e1FbA9e |
Test stETH token |
| USDC (Mock) | 0x7BE60377E17aD50b289F306996fa31494364c56a |
Test USDC token |
Smart Contracts
- Solidity 0.8.26
- Foundry for testing & deployment
- OpenZeppelin for security
- EigenLayer AVS integration
- Chainlink price feeds
Frontend
- Next.js 16 + TypeScript
- Wagmi v3 + Viem
- RainbowKit for wallet connection
- TailwindCSS for styling
- Vercel for hosting
Infrastructure
- Base Sepolia L2
- GitHub for version control
- GitHub Actions for CI/CD
User deposits stETH β Vault mints LP shares β Insurance coverage activated
Check collateral β Calculate max borrow β Mint USDC loan β Track health factor
Swap collects 0.16% fee β Sent to InsuranceTranche β Available for depeg payouts
Oracle detects depeg β AVS verifies β Insurance pays out β LPs made whole
# Run all tests
forge test -vvv
# Run specific test
forge test --match-test testDeposit -vvv
# Gas report
forge test --gas-report
# Coverage
forge coverage# Test full protocol flow
forge script script/BastionDemo.s.sol --fork-url https://sepolia.base.org
# Test swap to insurance
forge script script/TestSwapInsuranceV2.s.sol --rpc-url https://sepolia.base.org --broadcast- Audited Contracts: OpenZeppelin base contracts
- AVS Verification: Dual validation (Oracle + AVS)
- Reentrancy Guards: On all state-changing functions
- Access Control: Role-based permissions
- Slashing Protection: For malicious AVS operators
# Required
PRIVATE_KEY=your_wallet_private_key
# Optional
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
BASESCAN_API_KEY=your_basescan_keybastion/
βββ src/ # Smart contracts
β βββ BastionVault.sol
β βββ LendingModule.sol
β βββ InsuranceTranche.sol
β βββ SimpleSwapFeeCollector.sol
β βββ avs/ # AVS integration
βββ script/ # Deployment scripts
βββ test/ # Contract tests
βββ frontend/ # Next.js app
β βββ app/ # Pages
β βββ components/ # React components
β βββ hooks/ # Custom hooks
βββ deployments/ # Deployment records
We welcome contributions! Please:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Live Demo: https://bastion-protocol-three.vercel.app
- GitHub: github.com/big14way/Bastion
- Base Sepolia Explorer: sepolia.basescan.org
- Core lending protocol
- Insurance module with AVS
- Dynamic fee system
- Swap integration with decimal conversion
- Frontend deployment
- Mainnet launch
- Additional collateral assets
- Cross-chain support
- Mobile app
- Risk-Averse Lenders: Deposit with automatic insurance protection
- Yield Farmers: Earn from lending + swap fees
- Leveraged Traders: Borrow against basket collateral
- Arbitrageurs: Exploit depeg opportunities
- AVS Operators: Earn rewards for securing the protocol
Bastion integrates with multiple protocols to deliver a secure, automated lending experience:
- Integration: Custom hook implementation for dynamic fees and automated basket rebalancing
- Location:
src/BastionHook.sol - Usage:
beforeSwap()- Dynamic fee adjustment based on volatility (lines 263-286)afterSwap()- Basket rebalancing trigger (lines 294-320)afterAddLiquidity()- LP collateral registration (lines 330-341)afterDonate()- Rebasing token reward handling (lines 387-414)
- Key Features: Volatility-based fees (0.05%-1.00%), automated rebalancing, LP collateral tracking
- Integration: Active Validation Services for depeg detection and verification
- Location:
src/avs/BastionTaskManager.sol - Usage:
- AVS operators verify depeg events before insurance payouts (lines 945-998 in BastionHook.sol)
- Consensus-based validation ensures accuracy
- Slashing protection for malicious behavior
- Key Features: Decentralized verification, operator staking, automated task creation
- Integration: Price feeds for volatility calculation and depeg detection
- Location:
src/interfaces/IVolatilityOracle.sol - Usage:
- Real-time volatility data for dynamic fee tiers (line 270 in BastionHook.sol)
- Basket weight adjustment based on price movements
- Depeg threshold monitoring (20% deviation)
- Key Features: Reliable price data, multi-asset support (stETH, cbETH, rETH, USDe)
- Integration: Security libraries and base contracts
- Location: Imported throughout codebase
- Usage:
SafeERC20for secure token transfers (line 19 in BastionHook.sol)ReentrancyGuardinsrc/BastionVault.solOwnableand access control patterns
- Key Features: Battle-tested security, gas optimization, standard implementations
- Integration: Deployed on Base Sepolia testnet
- Location: All contracts deployed at addresses listed in README
- Usage:
- Low-cost transactions for frequent rebalancing
- Fast finality for insurance payouts
- Ethereum-compatible environment
- Key Features: Reduced gas costs, 2-second block times, Ethereum security
Note: All integrations are functional and deployed on Base Sepolia testnet.
Built with:
- EigenLayer for AVS infrastructure
- Chainlink for price feeds
- OpenZeppelin for secure contracts
- Base for L2 scalability
- Uniswap v4 for hook infrastructure
Made with β€οΈ by the Bastion team