A simplified decentralized lending protocol built with Solidity that allows users to earn yield on their crypto assets while introducing the foundation for a credit-based borrowing system.
CrediFi is a DeFi lending protocol that enables users to deposit ETH, USDC, and MATIC to earn yield through a rebasing token system. The protocol uses share tokens (saTokens) to represent user deposits and automatically adjusts token balances when interest is added to the pools.
- Multi-Asset Support: Deposit ETH, USDC, and MATIC
- Rebasing Tokens: Automatic yield distribution through share token rebasing
- Credit-Based Foundation: Architecture designed to support future credit-based borrowing
- Secure: Built with OpenZeppelin contracts and reentrancy protection
- Gas Efficient: Optimized for cost-effective transactions
CrediFiProtocol.sol: Main protocol contract handling deposits, withdrawals, and interest distributionSaToken.sol: Rebasing ERC20 tokens representing shares in the lending pools
- Deposits: Users deposit assets and receive corresponding saTokens (saETH, saUSDC, saMATIC)
- Yield Generation: Protocol generates yield through lending activities
- Rebasing: When interest is added, saToken balances automatically increase proportionally
- Withdrawals: Users can withdraw their assets by burning saTokens
The main protocol contract that manages:
- Asset deposits and withdrawals
- Interest distribution
- Pool reserves tracking
- saToken minting and burning
Key Functions:
depositETH()/depositUSDC()/depositMATIC(): Deposit assetswithdrawETH()/withdrawUSDC()/withdrawMATIC(): Withdraw assetsaddETHInterest()/addUSDCInterest()/addMATICInterest(): Add interest to pools
Rebasing ERC20 tokens that represent shares in the lending pools:
- Automatic balance adjustments when interest is added
- Share-based accounting system
- Standard ERC20 functionality with rebasing mechanics
# Clone the repository
git clone <repository-url>
cd CrediFi
# Install dependencies
forge installCreate a .env file with the following variables:
ETHEREUM_RPC_URL=your_ethereum_rpc_url
POLYGON_RPC_URL=your_polygon_rpc_url
ETHERSCAN_MAINNET_KEY=your_etherscan_key
ETHERSCAN_API_KEY=your_polygonscan_keyDo NOT add your private key to .env or commit it to version control.
Instead, create a secure wallet keystore and use it with Foundry's cast and forge tools.
Credits to Patrick Collins for the keystore workflow.
cast wallet import myKeystoreName --interactive- Enter your wallet's private key when prompted.
- Provide a password to encrypt the keystore file.
# Compile contracts
forge build# Run all tests
forge test
# Generate HTML coverage report
forge coverage --report lcov && genhtml lcov.info --output-directory coverage- Fork the repository
- Create a 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.
This software is for educational purposes only. Use at your own risk. The authors are not responsible for any financial losses incurred through the use of this software.