This repository contains the smart contracts for a decentralized lending protocol built on Ethereum. The protocol allows users to issue and transfer stablecoins, submit loan applications, and vote on freezing or unfreezing users. Governance tokens facilitate the voting process, ensuring a decentralized decision-making mechanism. Additionally, the protocol's factory design allows for the creation of diverse credit economies by specifying different collateral tokens and their respective minimum collateralization ratios (MCP) and oracle feeds.
Users can issue stablecoins by providing collateral.
Users can submit loan applications, which other users can vote on based on their transaction history.
Users with governance tokens can vote to freeze or unfreeze other users.
The protocol calculates credit scores based on transaction history, which influences voting power.
The protocol can generate multiple instances of lending systems with different collateral tokens, MCPs, and price oracles through the factory mechanism.
- Functionality: Can deposit, borrow, repay, and withdraw funds.
- Stablecoin Issuance: Issue stablecoins by providing a specified ERC-20 token as collateral.
- Loan Application: Apply for loans based on credit score.
- Functionality: Can vote on loan applications and unfreeze proposals.
- Voting Power: Determined by transaction history.
- Loan Votes: Participate in voting for or against loan applications.
- Unfreeze Votes: Vote to unfreeze users based on community consensus.
- Functionality: Can propose governance token minting for lending pool procurement/reward and freeze actions, and vote on them.
- Staking: Stake governance tokens to gain voting power and participate in governance.
- Mint Votes: Initiate proposals to mint governance tokens and can vote.
- Freeze Votes: Initiate proposals to freeze users and can vote.
- Functionality: Eligible for rewards based on timely loan repayments.
- Rewards: Receive additional governance tokens for successful and timely loan repayments.
- Credit Score Improvement: Boost credit score through timely repayments.
- Purpose: Initializes the protocol with the stablecoin's name, symbol, and decimals.
- Setup: Configures the fee rate, collateral token, minimum collateralization ratio, and integrates the PriceConsumer for fetching the latest price.
- Purpose: Handles core operations including deposit, borrow, repay, withdraw, redeem, and sweep functions.
- Functionality: Manages individual collateralization ratios and updates the priority registry.
- Purpose: Provides basic ERC-20 functions like transfer, approve, transferFrom, balanceOf, allowance, name, symbol, decimals, and totalSupply.
- Additional Features: Integrates reputation data handling in transfer and transferFrom functions.
- Purpose: Allows staked users to propose and vote on freezing other users.
- Impact: Freezing a user reduces the credit scores of users who transacted with them by 10%.
- Purpose: Manages the submission and voting process for loan applications.
- Voting Power Calculation: Based on past transaction amounts.
- Purpose: Allows staked users to propose and vote on unfreezing frozen users.
- Purpose: Manages the lending pool, minting new governance tokens, and user withdrawals based on credit scores.
- Loan Repayment: Handles loan repayments and rewards users for successful repayments.
- Purpose: Implements a governance token that can be staked to gain voting power.
- Voting: Users can vote to freeze or unfreeze other users.
- Purpose: Allows users to stake their governance tokens for a period of 4 years.
- Staking Benefits: Increases voting power and participation in governance.
- Purpose: Initializes the governance token with the name, symbol, and decimals.
- Purpose: Defines data structures used by the main protocol.
- Data Types: User data, loan applications, mint proposals.
- Purpose: Provides storage access for the main protocol's state.
- Purpose: Defines data structures used by the governance protocol.
- Data Types: Balances, allowances, staked balances, voting power, votes.
- Purpose: Provides storage access for the governance protocol's state.
The protocol is built using a modular architecture, where each functionality is encapsulated in a separate contract. This approach allows for easier maintenance and upgrades.
For a detailed overview of the protocol's structure and flow, refer to the UML diagrams in ./docs/uml.md.
Welcome to the Meta Contract Template! This template is your fast track to smart contract development, offering a pre-configured setup with the Meta Contract framework and essential tools like the ERC-7201 Storage Location Calculator. It's designed for developers looking to leverage advanced features and best practices right from the start.
Ensure you have Foundry installed, then initialize your project with:
$ forge init <Your Project Name> -t metacontract/template