Skip to content

big14way/Bastion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

45 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏰 Bastion Protocol

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.

Live Demo License Network


✨ Features

For Lenders (LPs)

  • πŸ›‘οΈ 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

For Borrowers

  • πŸ“Š 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

For Traders

  • πŸ”„ 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

πŸ—οΈ Architecture

Bastion consists of four core modules:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Basket Vault   │──────│  Lending Module  │──────│ Insurance Pool  β”‚
β”‚  (Multi-Asset)  β”‚      β”‚  (Borrow/Lend)   β”‚      β”‚  (Depeg Cover)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚                        β”‚                         β”‚
         β”‚                β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”                β”‚
         β”‚                β”‚ AVS Operators  β”‚                β”‚
         β”‚                β”‚ (Verification) β”‚                β”‚
         β”‚                β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜                β”‚
         β”‚                        β”‚                         β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                            Chainlink Oracles

1. Basket Management

  • 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

2. Insurance Protection

  • 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

3. Dynamic Fee System

  • Volatility-based lending fees
    • Low (<10%): 0.05% APR
    • Medium (10-14%): 0.30% APR
    • High (>14%): 1.00% APR

4. AVS Integration

  • EigenLayer AVS operators provide security
  • Depeg event verification
  • Basket rebalancing triggers
  • Slashing protection for malicious behavior

πŸš€ Quick Start

Prerequisites

  • Node.js 18+
  • Foundry
  • Base Sepolia ETH (Get from faucet)
  • MetaMask or compatible wallet

Installation

# 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 Contracts (Optional)

# Deploy full protocol
forge script script/BastionDemo.s.sol:BastionDemo \
  --rpc-url https://sepolia.base.org \
  --broadcast

Run Frontend

cd frontend
npm install
npm run dev

Visit http://localhost:3002

Get Test Tokens

# 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

πŸ“Š Live Contracts (Base Sepolia)

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

πŸ”§ Technical Stack

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

πŸ“– How It Works

1. Deposit Flow

User deposits stETH β†’ Vault mints LP shares β†’ Insurance coverage activated

2. Borrow Flow

Check collateral β†’ Calculate max borrow β†’ Mint USDC loan β†’ Track health factor

3. Insurance Flow

Swap collects 0.16% fee β†’ Sent to InsuranceTranche β†’ Available for depeg payouts

4. Depeg Response

Oracle detects depeg β†’ AVS verifies β†’ Insurance pays out β†’ LPs made whole

πŸ§ͺ Testing

# Run all tests
forge test -vvv

# Run specific test
forge test --match-test testDeposit -vvv

# Gas report
forge test --gas-report

# Coverage
forge coverage

Example Tests

# 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

πŸ›‘οΈ Security

  • 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

⚠️ Testnet Only: This is experimental software. Do not use with real funds.


🌐 Environment Variables

# Required
PRIVATE_KEY=your_wallet_private_key

# Optional
BASE_SEPOLIA_RPC_URL=https://sepolia.base.org
BASESCAN_API_KEY=your_basescan_key

πŸ“š Project Structure

bastion/
β”œβ”€β”€ 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

🀝 Contributing

We welcome contributions! Please:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ”— Links


🎯 Roadmap

  • 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

πŸ’‘ Use Cases

  1. Risk-Averse Lenders: Deposit with automatic insurance protection
  2. Yield Farmers: Earn from lending + swap fees
  3. Leveraged Traders: Borrow against basket collateral
  4. Arbitrageurs: Exploit depeg opportunities
  5. AVS Operators: Earn rewards for securing the protocol

🀝 Partner Integrations

Bastion integrates with multiple protocols to deliver a secure, automated lending experience:

Uniswap v4 Hooks

  • 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

EigenLayer AVS

  • 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

Chainlink Oracles

  • 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)

OpenZeppelin Contracts

  • Integration: Security libraries and base contracts
  • Location: Imported throughout codebase
  • Usage:
    • SafeERC20 for secure token transfers (line 19 in BastionHook.sol)
    • ReentrancyGuard in src/BastionVault.sol
    • Ownable and access control patterns
  • Key Features: Battle-tested security, gas optimization, standard implementations

Base L2

  • 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.


πŸ† Acknowledgments

Built with:


Made with ❀️ by the Bastion team

⚠️ Disclaimer: This is experimental software deployed on testnet. Audit pending for mainnet launch.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors