A comprehensive DeFi lending protocol built using Solidity (Foundry) and Arbitrum Stylus (Rust)
A comprehensive DeFi lending protocol with cross-chain capabilities built using Solidity (Foundry) and Arbitrum Stylus (Rust)
SlemanFi is a modular, upgradeable DeFi lending protocol that enables:
Isolated lending pools for risk separation between token pairs
Collateral management with multiple token support
Dynamic interest rate models with configurable parameters
Liquidation mechanisms to maintain protocol health
DEX integration to repay loans using collateral (no need for borrow token)
The project consists of two technology stacks:
sleman-sc - Solidity smart contracts (Foundry)
sleman-stylus - Rust smart contracts (Arbitrum Stylus SDK)
├── sleman-sc/ # Main Solidity contracts (Foundry)
│ ├── src/ # Core protocol contracts
│ │ ├── LendingPool.sol # Main lending operations
│ │ ├── LendingPoolStorage.sol # Storage & accounting
│ │ ├── Router.sol # Central coordination hub
│ │ ├── TokenDataStream.sol # Oracle/price feed system
│ │ ├── InterestRateModel.sol # Interest calculations
│ │ ├── IsHealthy.sol # Health factor calculations
│ │ ├── Pricefeed.sol # Price feed aggregator
│ │ ├── WrappedNative.sol # Native token wrapper
│ │ ├── hooks/ # Protocol hook contracts
│ │ ├── interfaces/ # Contract interfaces
│ │ └── mocks/ # Mock tokens for testing
│ ├── script/ # Deployment scripts
│ │ ├── DeploySlemanCore.s.sol # Base deployment logic
│ │ └── steps/ # 15 modular deployment steps
│ └── test/ # Unit and integration tests
│
├── sleman-stylus/ # Rust smart contracts (Stylus SDK)
│ ├── src/ # Rust source code
│ ├── abi/ # Exported ABIs
│ ├── tests/ # Rust tests
│ └── examples/ # Usage examples
│
└── nitro-devnode/ # Local development node
The main entry point for user interactions:
supplyCollateral() - Deposit tokens as collateral
withdrawCollateral() - Withdraw collateral tokens
supplyLiquidity() - Provide liquidity to earn interest
withdrawLiquidity() - Withdraw liquidity position
borrow() - Borrow tokens from liquidity pool
repay() - Repay borrowed tokens
repayWithCollateral() - Swap collateral to repay debt
liquidation() - Liquidate unhealthy positions
Features:
UUPS Upgradeable pattern
Role-based access control (OWNER_ROLE, ADMIN_ROLE)
Pausable for emergency situations
Reentrancy protection
Native token (ETH/native) support
Separated storage contract for upgradeable patterns:
Manages all state variables and accounting
Tracks user collateral, supply shares, and borrow shares
Handles interest accrual
Validates health factors before operations
Calculates share-to-asset conversions
Key Mappings:
mapping(address => mapping(address => uint256)) userCollateral;mapping(address => uint256) userSupplyShares;
mapping(address => uint256) userBorrowShares;
Central configuration and routing contract:
Manages lending pool registrations
Stores external contract addresses (Oracle, DEX, etc.)
Handles protocol fee configuration
Controls wrapped native token address
Manages reserve factors
Contract | Purpose |
|---|---|
InterestRateModel.sol | Dynamic interest rate calculations |
IsHealthy.sol | Health factor & liquidation threshold calculations |
TokenDataStream.sol | Oracle/price feed aggregation |
Pricefeed.sol | Price feed interface |
The protocol uses a hook pattern for extensibility:
Hook | Description |
|---|---|
LendingPoolHook.sol | Events, errors, constants for LendingPool |
LendingPoolStorageHook.sol | Events, errors, constants for Storage |
RouterHook.sol | Events, errors, constants for Router |
InterestRateModelHook.sol | Interest rate configuration |
IsHealthyHook.sol | Health/liquidation parameters |
TokenDataStreamHook.sol | Oracle configuration |
PricefeedHook.sol | Price feed settings |
├── ILendingPool.sol # Main lending operations
├── ILendingPoolStorage.sol # Storage access
├── IRouter.sol # Router configuration
├── IInterestRateModel.sol # Interest calculations
├── IIsHealthy.sol # Health checks
├── ITokenDataStream.sol # Oracle data
├── IOracle.sol # External oracle interface
├── IAerodromeRouter.sol # DEX (Aerodrome) integration
├── ILiquidator.sol # Liquidation logic
├── INusaVault.sol # Vault integration
└── IWrapped.sol # Wrapped token interface
The project features a 14-step modular deployment system:
Phase 8: IntegrationPhase 7: ParametersPhase 6: Lending ConfigPhase 5: Core LendingPhase 4: Router ConfigPhase 3: UtilitiesPhase 2: Oracle ConfigPhase 1: Infrastructure0. Deploy Mock Tokens1. Deploy Router2. Deploy TokenDataStream3. Set Price Feed4. Deploy IsHealthy5. Deploy InterestRateModel6. Config Router7. Deploy LendingPoolStorage8. Deploy LendingPool9. Config Router For LendingPool10. Config LendingPoolStorage11. Tweaking InterestRateModel12. Tweaking IsHealthy13. Set DEX Router14. Set Protocol✅ Granular Control: Deploy/re-run only needed steps
✅ Easy Debugging: Identify issues at specific steps
✅ Fast Iteration: Skip successful steps
✅ Reusability: Works across networks (testnet/mainnet)
✅ Self-Documenting: Folder structure shows deployment order
Located in src/mocks/:
MOCKWBTC, MOCKWETH, MOCKUSDC, MOCKUSDT
MOCKARB
All mocks have public mint() and burn() functions for testing.
# Buildforge build
# Run tests
forge test
# Deploy single step
forge script script/steps/1.DeployRouter.s.sol --broadcast -vvv
# Deploy with verification
forge script ScriptName --broadcast -vvv \
--verify --verifier etherscan \
--etherscan-api-key $ETHERSCAN_API_KEY
# Check compilationcargo stylus check
# Export ABI
cargo stylus export-abi
# Deploy
cargo stylus deploy --private-key-path=<PATH>
# Run tests
cargo test
Layer | Technology |
|---|---|
Smart Contracts | Solidity 0.8.20, Rust (Stylus) |
Framework | Foundry, cargo-stylus |
Upgradability | UUPS Proxy Pattern |
Access Control | OpenZeppelin AccessControl |
Security | ReentrancyGuard, Pausable |
Cross-chain | LayerZero (OApp) |
DEX Integration | Aerodrome Router |
Oracle | Custom TokenDataStream + External oracles |
Isolated Pool Design: Risk separation between token pairs, no contagion
Collateral Repayment: Repay loans using collateral via DEX integration
Dual Technology Stack: Solidity + Stylus for optimal gas efficiency
Modular Architecture: Hook-based extensibility pattern
Professional Deployment: 14-step modular deployment with dependency tracking
Upgradeable Design: UUPS pattern with separated storage
Project: SlemanFi Protocol
Status: Active Development