Making the illiquid liquid - An innovative peer-to-pool lending and borrowing protocol with NFT collateral through lottery mechanics
๐ฏ Overview
MeltyFi is a revolutionary DeFi protocol that enables peer-to-pool lending and borrowing with NFT collateral through an innovative lottery-based system inspired by Charlie and the Chocolate Factory. Unlike traditional NFT-backed lending platforms, MeltyFi eliminates the risk of involuntary liquidation by operating independently of off-chain factors like floor prices.
๐ซ The Chocolate Factory Analogy
In MeltyFi, each NFT is like a chocolate bar. When borrowers need liquidity:
- ๐ซ Breaking the Bar: The NFT (chocolate bar) is divided into WonkaBars (chocolate squares)
- ๐ฐ Selling Squares: Lenders buy WonkaBars to fund the loan
- ๐ซ Golden Ticket: If the loan isnโt repaid, one random WonkaBar contains the โgolden ticketโ to win the NFT
- ๐ช ChocoChips: All participants earn governance tokens as rewards
This process โmeltsโ the illiquid NFT into liquid capital while maintaining fairness for all parties.
โจ Key Features
- ๐ Zero Liquidation Risk: NFTs are never forcibly liquidated due to price fluctuations
- ๐ฒ Lottery-Based Funding: Transparent, fair distribution mechanism
- ๐ Win-Win Design: Benefits for both borrowers and lenders
- ๐ฎ Gamified Experience: Engaging chocolate factory theme
- ๐ Fully Decentralized: No dependence on external price oracles
- โก Chainlink Integration: Provably random winner selection
๐๏ธ Protocol Architecture
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ MeltyFiNFT โ โ MeltyFiDAO โ โ ChocoChip โ
โ (Core Logic) โโโโโบโ (Governance) โโโโโบโ (ERC-20 Token) โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ LogoCollection โ โ VRF Consumer โ โ WonkaBars โ
โ (ERC-1155 Meme) โ โ (Randomness) โ โ (ERC-1155 Tickets)โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
Smart Contracts
๐ฏ Core Contracts
- MeltyFiNFT (
0x6c1030B8BbE523671Bcfd774Ae59ef620f9f31b4
) - Main protocol logic - MeltyFiDAO (
0xC4AA65a48fd317070F1A5aC5eBAC70F9d022Fb1e
) - Governance contract - ChocoChip - ERC-20 governance token with voting capabilities
- LogoCollection - ERC-1155 meme token for protocol branding
- VRFv2DirectFundingConsumer - Chainlink VRF for random winner selection
๐ซ Token Standards
- ERC-721: NFT collateral support
- ERC-1155: WonkaBars (lottery tickets) and LogoCollection
- ERC-20: ChocoChip governance token with EIP-2612 permit functionality
๐ฒ Lottery States & Behavior
State Diagram
[Create Lottery]
โ
โผ
โโโโโโโโโโโโโโโ
โ ACTIVE โ
โ (Can buy โ
โ WonkaBars) โ
โโโโโโโโโโโโโโโ
โ
โโโโ Repay Loan โโโโโบ [CANCELLED] โโโบ Refund + ChocoChips
โ
โโโโ Time Expires โโโบ [CONCLUDED] โโโบ Random Winner + ChocoChips
๐ฎ Lottery States Explained
๐ข ACTIVE State
- Duration: From creation until expiration or repayment
- Actions: Lenders can purchase WonkaBars
- Funds: 95% goes to borrower, 5% to DAO treasury
- Transition: Can become CANCELLED (repayment) or CONCLUDED (expiration)
๐ก CANCELLED State
- Trigger: Borrower repays loan before expiration
- Outcome: NFT returned to borrower
- Rewards:
- Lenders get full refund + ChocoChips
- Borrower gets ChocoChips for good behavior
๐ด CONCLUDED State
- Trigger: Expiration date reached without repayment
- Winner Selection: Chainlink VRF randomly selects winner
- Rewards:
- Winner gets NFT + ChocoChips
- Other lenders get ChocoChips only
โซ TRASHED State
- Condition: No WonkaBars were ever purchased
- Result: Lottery automatically cleaned up
๐ Protocol Workflows
๐ Use Cases Overview
๐ฆ BORROWER ๐ฏ LENDER ๐ค ORACLE
โ โ โ
โโ Create Lottery โโ Buy WonkaBars โโ Draw Winner
โโ Repay Loan โโ Melt WonkaBars โโ (Automation)
๐ Detailed Workflows
1๏ธโฃ Create Lottery (Borrower)
sequenceDiagram
participant B as Borrower
participant M as MeltyFiNFT
participant N as NFT Contract
B->>N: approve(MeltyFiNFT, tokenId)
B->>M: createLottery(nftContract, tokenId, price, expiry, maxSupply)
M->>N: transferFrom(borrower, MeltyFiNFT, tokenId)
M->>M: mint WonkaBars for lottery
M-->>B: Lottery created โ
2๏ธโฃ Buy WonkaBars (Lender)
sequenceDiagram
participant L as Lender
participant M as MeltyFiNFT
participant B as Borrower
participant D as DAO
L->>M: buyWonkaBars(lotteryId, quantity) + ETH
M->>M: mint WonkaBars to lender
M->>B: transfer 95% of payment
M->>D: transfer 5% fee
M-->>L: WonkaBars received ๐ซ
3๏ธโฃ Repay Loan (Borrower)
sequenceDiagram
participant B as Borrower
participant M as MeltyFiNFT
participant C as ChocoChip
B->>M: repayLoan(lotteryId)
M->>M: set lottery state to CANCELLED
M->>M: transfer NFT back to borrower
M->>C: mint ChocoChips to borrower
M-->>B: Loan repaid, NFT returned ๐
4๏ธโฃ Melt WonkaBars (Lender)
sequenceDiagram
participant L as Lender
participant M as MeltyFiNFT
participant C as ChocoChip
alt Lottery CANCELLED
L->>M: meltWonkaBars(lotteryId, quantity)
M->>L: refund ETH investment
M->>C: mint ChocoChips to lender
M-->>L: Refund + rewards received ๐ฐ
else Lottery CONCLUDED (Winner)
L->>M: meltWonkaBars(lotteryId, quantity)
M->>L: transfer NFT prize
M->>C: mint ChocoChips to lender
M-->>L: NFT + rewards received ๐
else Lottery CONCLUDED (Non-winner)
L->>M: meltWonkaBars(lotteryId, quantity)
M->>C: mint ChocoChips to lender
M-->>L: ChocoChips received ๐ช
end
5๏ธโฃ Draw Winner (Oracle Automation)
sequenceDiagram
participant O as Oracle
participant M as MeltyFiNFT
participant V as VRF Consumer
O->>M: checkUpkeep() [expired lotteries?]
M-->>O: performData [lottery IDs to conclude]
O->>M: performUpkeep(performData)
M->>V: requestRandomWords()
V-->>M: fulfillRandomWords(requestId, randomWords)
M->>M: select winner based on random number
M->>M: set lottery state to CONCLUDED
M-->>O: Winners drawn for expired lotteries ๐ฒ
๐ฏ Protocol Scenarios
๐ Scenario 1: Successful Repayment
- Borrower creates lottery with valuable NFT
- Multiple lenders buy WonkaBars, funding the loan
- Borrower receives 95% of funds immediately
- Before expiration, borrower repays the loan
- Results:
- โ Borrower gets NFT back + ChocoChips
- โ Lenders get full refund + ChocoChips
- โ Everyone wins!
๐ Scenario 2: Loan Default
- Borrower creates lottery but cannot repay
- Lottery expires and transitions to CONCLUDED
- Chainlink VRF randomly selects winner
- Results:
- ๐ One lucky lender wins the NFT + ChocoChips
- ๐ช Other lenders receive ChocoChips as consolation
- ๐ Borrower loses NFT but keeps the borrowed funds
๐ป Frontend Architecture
๐จ User Interface
Built with modern React ecosystem for optimal user experience:
- React 18 - Component-based UI framework
- React-Bootstrap - Responsive design components
- Ethers.js - Ethereum blockchain interaction
- thirdweb - Web3 authentication and wallet connection
- MetaMask - Primary wallet integration
- OpenSea API - NFT metadata retrieval
๐ฑ Pages & Features
๐ Home Page
- Protocol introduction and chocolate factory explanation
- Key features and benefits overview
- How-to-use guide for new users
๐ฐ Lotteries Page
- Browse Lotteries: View all active lotteries with filtering
- Create Lottery: Select NFTs and set lottery parameters
- Real-time lottery status and participation data
- Interactive lottery cards with NFT previews
๐ค Profile Page
- View owned lotteries and their current status
- Check WonkaBar holdings and win probabilities
- Monitor ChocoChip balance and transaction history
- Manage active positions and claim rewards
๐ ๏ธ Installation & Setup
Prerequisites
# Required software
- Node.js (v16 or higher)
- MetaMask browser extension
- Git
# Required tokens
- Goerli testnet ETH (from faucet)
- LINK tokens (for oracle funding)
๐ง Backend Setup
# Clone the repository
git clone https://github.com/VincenzoImp/MeltyFi.NFT
cd MeltyFi.NFT/src/back-end/MeltyFiProtocol
# Install dependencies
npm install
# Environment configuration
cp .env.example .env
# Add your keys:
# ALCHEMY_API_KEY=your_alchemy_key
# GOERLI_PRIVATE_KEY=your_private_key
# ETHERSCAN_API_KEY=your_etherscan_key
# Compile smart contracts
npx hardhat compile
# Run comprehensive test suite
npx hardhat test
# Deploy to Goerli (if needed)
npx hardhat run scripts/deploy.js --network goerli
# Verify contracts on Etherscan
npx hardhat verify --network goerli CONTRACT_ADDRESS
๐จ Frontend Setup
# Navigate to frontend directory
cd src/front-end/meltyfi.nft
# Install React dependencies
npm install
# Start development server
npm start
# Build for production
npm run build
The application will be available at http://localhost:3000
๐ Contract Interactions
๐ Reading Contract State
// Get lottery information
function getLotteryInfo(uint256 lotteryId)
external view returns (Lottery memory);
// Check WonkaBar balance
function balanceOf(address account, uint256 lotteryId)
external view returns (uint256);
// Get ChocoChip balance
function balanceOf(address account)
external view returns (uint256);
// Check if address won lottery
function isWinner(address account, uint256 lotteryId)
external view returns (bool);
โ๏ธ Writing Contract State
// Create new lottery
function createLottery(
IERC721 _prizeContract,
uint256 _prizeTokenId,
uint256 _wonkaBarPrice,
uint256 _expirationDate,
uint256 _wonkaBarsMaxSupply
) external;
// Purchase lottery tickets
function buyWonkaBars(uint256 _lotteryId, uint256 _amount)
external payable;
// Repay loan and cancel lottery
function repayLoan(uint256 _lotteryId) external;
// Claim rewards and prizes
function meltWonkaBars(uint256 _lotteryId, uint256 _amount)
external;
// Manually trigger winner selection
function drawWinner(uint256 _lotteryId) external;
๐ Security Features
๐ก๏ธ Smart Contract Security
- OpenZeppelin Standards: Battle-tested contract implementations
- Reentrancy Guards: Protection against common attack vectors
- Access Control: Role-based permissions and ownership
- Input Validation: Comprehensive parameter checking
- Emergency Controls: Circuit breakers for critical functions
๐ Oracle Security
- Chainlink VRF: Provably random and tamper-proof randomness
- Direct Funding: Anyone can fund oracles to ensure availability
- Fallback Mechanisms: Manual winner drawing if automation fails
- No External Dependencies: Floor price independence eliminates oracle manipulation
๐จ Protocol Safety
- No Liquidation Risk: Borrowers cannot lose NFTs unexpectedly
- Fair Distribution: Proportional lottery chances based on investment
- Transparent Operations: All actions recorded on-chain
- Automated Processes: Reduced human error through smart contracts
๐ Live Deployment
๐ Contract Addresses (Goerli Testnet)
Contract | Address | Etherscan |
---|---|---|
MeltyFiNFT | 0x6c1030B8BbE523671Bcfd774Ae59ef620f9f31b4 | View |
MeltyFiDAO | 0xC4AA65a48fd317070F1A5aC5eBAC70F9d022Fb1e | View |
๐ Live Applications
- MeltyFi.NFT DApp: https://meltyfi.nft
- MeltyFi.DAO DApp: https://meltyfi.dao (Coming Soon)
๐ Example Transactions
- Create Lottery:
0xe68f3f6...
- Melt WonkaBars:
0xd957d27...
โ ๏ธ Known Limitations
๐ Protocol Limitations
- Slow Funding: Loans require multiple lenders to participate
- Uncertainty: Three possible outcomes create complexity for lenders
- Gas Costs: Complex lottery mechanics increase transaction costs
- Testnet Only: Currently deployed on Goerli for testing
๐ง Technical Limitations
- Oracle Dependency: Relies on Chainlink for automation and randomness
- Frontend Gaps: DAO interface not yet implemented
- Scalability: May face congestion on mainnet deployment
๐ Future Roadmap
๐ฏ Phase 1: Production Ready
- โ Mainnet deployment with audited contracts
- โ Layer 2 integration (Polygon, Arbitrum, Optimism)
- โ Enhanced security audits and bug bounties
- โ Mobile-responsive interface improvements
๐ฏ Phase 2: Advanced Features
- ๐ Dutch auction lottery mechanisms
- ๐ฏ Multi-NFT collateral lotteries
- ๐ Fractional NFT support
- ๐ช NFT marketplace integration
๐ฏ Phase 3: Ecosystem Expansion
- ๐ฑ Native mobile application
- ๐ Cross-chain bridge functionality
- ๐๏ธ Fully functional DAO governance
- ๐ฎ Gamification enhancements
๐ฅ Team
Team Member | Role | Responsibilities |
---|---|---|
Vincenzo Imperati | Project Manager & Backend Developer | Smart contract development, system architecture, project coordination |
Benigno Ansanelli | Frontend Developer | Lottery interface, user experience, documentation |
Andrea Princic | Frontend Developer & UX Designer | Profile management, sequence diagrams, use case design |
๐ค Contributing
We welcome contributions from the community! Hereโs how you can help:
๐ง Development Guidelines
- Fork the repository and create a feature branch
- Follow existing code style and conventions
- Add comprehensive tests for new functionality
- Update documentation as needed
- Test thoroughly on Goerli testnet
๐ Contribution Areas
- ๐ Bug fixes and security improvements
- โจ New features and enhancements
- ๐ Documentation and tutorials
- ๐จ UI/UX improvements
- ๐งช Testing and quality assurance
๐ License
This project is open source. Please refer to the repository for specific license details.
๐ Important Links
๐ Project Resources
- GitHub Repository: VincenzoImp/MeltyFi.NFT
- Live Application: meltyfi.nft
- Documentation: Available in repository
/docs
directory
๐ง Development Tools
- Goerli Faucet: goerlifaucet.com
- OpenSea Testnet: testnets.opensea.io
- Remix IDE: remix.ethereum.org
๐ Educational Resources
- Ethereum Documentation: ethereum.org
- OpenZeppelin Contracts: openzeppelin.com
- Chainlink Documentation: docs.chain.link
MeltyFi Protocol - Where Charlieโs chocolate factory meets DeFi innovation! ๐ซโจ
Making illiquid NFTs liquid through the magic of lottery mechanics and community-driven finance.