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
90
Hackathon Phase