This directory contains the Credit Protocol smart contracts Move (Aptos).
The protocol consists of 5 main modules:
- Manages interest rate calculations (fixed and dynamic rates)
- Handles grace periods and interest accrual
- Supports both time-based and utilization-based rate models
- Manages liquidity deposits and withdrawals from lenders
- Handles borrowing and repayment flows
- Distributes interest to lenders and collects protocol fees
- Tracks utilization rates
- Manages borrower collateral deposits
- Handles collateral locking/unlocking
- Supports liquidation mechanisms
- Tracks collateral status (Active, Locked, Liquidating)
- Tracks borrower credit scores and payment history
- Manages reputation tiers (Bronze, Silver, Gold, Platinum)
- Records defaults and payment behavior
- Updates scores based on repayment patterns
- Core orchestration layer
- Manages credit line creation and management
- Handles borrowing, repayment, and liquidation logic
- Integrates with all other modules
- Manages credit limit increases based on reputation
- Resource-based Architecture: Uses Move's resource model for better safety
- Event System: Comprehensive event emission for all major actions
- Access Control: Granular permission system using Move's safety features
- Error Handling: Detailed error codes and assertions
- Gas Efficiency: Optimized for Aptos transaction costs
- Overcollateralized Lending: Users deposit collateral to borrow
- Dynamic Interest Rates: Rates adjust based on pool utilization
- Reputation System: Credit scores improve with good payment history
- Automated Liquidations: Protocol automatically liquidates unhealthy positions
- Protocol Fees: Built-in fee mechanism for sustainability
- Compile the contracts:
aptos move compile --dev- Deploy using the deployment script:
aptos move run --function-id 0x42::deploy::deploy_credit_protocol --args address:YOUR_ADDRESS- Initialize individual modules if needed:
# Initialize Interest Rate Model
aptos move run --function-id 0x42::interest_rate_model::initialize --args address:ADMIN address:CREDIT_MANAGER
# Initialize other modules similarly...- Deposit funds: Call
lending_pool::deposit() - Earn interest: Interest is distributed automatically
- Withdraw: Call
lending_pool::withdraw()
- Open credit line: Call
credit_manager::open_credit_line()with collateral - Borrow funds: Call
credit_manager::borrow()up to credit limit - Repay loan: Call
credit_manager::repay()with principal and interest - Build reputation: Make on-time payments to improve credit score
- Pause/unpause any module for emergency stops
- Update parameters like interest rates and collateral ratios
- Liquidate unhealthy positions
- Withdraw protocol fees
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Interest Rate │ │ Reputation │ │ Collateral │
│ Model │ │ Manager │ │ Vault │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
└───────────────────────┼───────────────────────┘
│
┌─────────────────┐
│ Credit Manager │ ←─────────────────┐
│ (Orchestrator) │ │
└─────────────────┘ │
│ │
┌─────────────────┐ │
│ Lending Pool │ ───────────────────┘
│ (Liquidity) │
└─────────────────┘
- Reentrancy Protection: Move's resource model prevents reentrancy attacks
- Access Control: Role-based permissions for sensitive operations
- Pausable: Emergency stop functionality in all modules
- Parameter Validation: Comprehensive input validation
- Safe Math: Move's built-in overflow protection
Create test files in tests/ directory:
#[test_only]
module credit_protocol::test_credit_manager {
use credit_protocol::credit_manager;
// Add test functions here
}Run tests:
aptos move test- No Upgradeable Contracts: Move uses a different upgrade pattern
- Resource Model: Assets are represented as resources, not mappings
- Event System: Events are emitted using Move's native event system
- Error Handling: Uses Move's
errormodule instead ofrequirestatements
- AptosCoin Usage: Currently uses AptosCoin as placeholder for USDC
- Coin Standard: Uses Aptos Coin standard instead of ERC-20
- Native Integration: Better integration with Aptos native features
- Batch Operations: More efficient batch processing
- Resource Efficiency: Move's resource model reduces storage costs
- Parallel Execution: Aptos supports parallel transaction execution
Key parameters can be configured:
- Interest rates (base, max, penalty)
- Grace periods
- Collateralization ratios
- Reputation scoring parameters
- Protocol fee rates
- Multi-Asset Support: Support for multiple collateral types
- Flash Loans: Add flash loan functionality
- Governance: Decentralized parameter management
- Oracle Integration: External price feeds for collateral valuation
- Cross-Chain: Bridge functionality for multi-chain lending
For questions or issues:
- Check the test files for usage examples
- Review the inline documentation in each module
- Examine the event structures for debugging
This migration maintains all the core functionality of the original Solidity contracts while leveraging Move's unique features for enhanced security and efficiency.