A decentralized NFT-collateralized lending platform implemented using the Diamond Pattern (EIP-2535). This platform enables users to deposit NFTs as collateral to borrow ETH, with fixed-term loans and interest rates.
This platform provides a secure and efficient way to use NFTs as collateral for ETH loans. Built using the Diamond Pattern, it offers modular functionality and upgradeability while maintaining high security standards.
- NFT collateralization
- Fixed-term loans
- Configurable interest rates
- Automated liquidation process
- Whitelisted NFT collections
- Emergency pause functionality
- Platform fee management
- Treasury management
The platform is built using the Diamond Pattern (EIP-2535) and consists of the following main components:
-
NFT Management Facet
- NFT deposits and withdrawals
- Ownership tracking
- Collection management
-
Lending Facet
- Loan creation and management
- Interest calculation
- Repayment processing
- Default handling
-
Collateral Manager Facet
- Price feed management
- Collateral ratio enforcement
- Liquidation process
- Value calculations
-
Treasury Facet
- ETH deposits and withdrawals
- Platform fee collection
- Revenue distribution
- Balance tracking
-
Admin Facet
- Platform parameter management
- Emergency controls
- Collection whitelisting
- Fee configuration
LibStorage.sol
: Central storage managementLibNFTLending.sol
: Core lending logicLibSecurity.sol
: Security and access control
- Solidity version: ^0.8.0
- Framework: Foundry
- Pattern: Diamond Standard (EIP-2535)
- Diamond Pattern (EIP-2535)
- Facet Pattern
- Storage Pattern
- Access Control Pattern
- Emergency Stop Pattern
- Event-Emission Pattern
- Guard Pattern
- Clone the repository:
git clone https://github.com/DonGuillotine/NFT-Collateralized-lending-platform.git
cd NFT-Collateralized-lending-platform
- Install dependencies:
forge install
- Compile contracts:
forge build
- Run tests:
forge test
- Deploy the Diamond contract:
forge script scripts/deploy.s.sol:DeployScript --rpc-url <your_rpc_url> --private-key <your_private_key>
- Initialize the platform with default parameters:
forge script scripts/initialize.s.sol:InitializeScript --rpc-url <your_rpc_url> --private-key <your_private_key>
- Deposit NFT:
INFTManagement(diamondAddress).depositNFT(collection, tokenId);
- Create loan:
ILending(diamondAddress).createLoan(collection, tokenId, amount);
- Repay loan:
ILending(diamondAddress).repayLoan(loanId);
- Deposit ETH:
ITreasury(diamondAddress).depositETH{value: amount}();
- Withdraw ETH:
ITreasury(diamondAddress).withdrawETH(amount);
The platform includes comprehensive tests for all components:
# Run all tests
forge test
# Run specific test file
forge test --match-path test/LendingFacetTest.t.sol
# Run tests with gas reporting
forge test --gas-report
- All functions include proper access control
- Reentrancy protection on ETH transfers
- Parameter validation and bounds checking
- Emergency pause functionality
- Secure NFT handling
- Protected admin functions
Default parameters (configurable by admin):
- Interest Rate: 10% (1000)
- Collateral Ratio: 150% (15000)
- Loan Duration: 7 days
- Platform Fee: 1% (100)
- Minimum Deposit: 0.1 ETH
- Multi-token support
- Variable interest rates
- NFT basket loans
- Secondary market for loans
- Integration with NFT price oracles
- Enhanced liquidation mechanisms
- Governance implementation
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Create a new Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Based on the Foundry-Hardhat-Diamonds template
- Implements EIP-2535 Diamond Standard
For support, please open an issue in the repository or contact the development team.
This software is provided "as is", without warranty of any kind. Use at your own risk.