πŸŒ™ Moonight Protocol: Bringing Social Lending to Starknet

Inspiration

Traditional banking systems have failed millions worldwide, leaving communities without access to basic financial services. Meanwhile, informal lending circles (ROSCAs - Rotating Savings and Credit Associations) have existed for centuries across culturesβ€”from African chamas to Asian hui to Latin American tandas. These community-based savings systems have helped billions of people build credit, access capital, and support each other financially.

The problem? Traditional lending circles rely entirely on trust and have no transparency, making them vulnerable to fraud and defaults. Members have no way to verify others' creditworthiness, track contributions, or enforce payouts.

Our vision: Combine the social power of lending circles with blockchain transparency, creating a trustless yet trust-building system on Starknet. Moonight Protocol brings financial inclusion to the unbanked while leveraging crypto's transparency and programmability.


What it does

Moonight Protocol is a decentralized social lending platform on Starknet that enables communities to create and participate in lending circles with crypto collateral backing.

Core Features

πŸ”΅ Lending Circles (ROSCAs)

  • Users create savings circles with customizable parameters:
    • Contribution amount (e.g., 100 STRK per cycle)
    • Cycle duration (weekly, bi-weekly, monthly)
    • Number of members (3-10 people)
    • Collateral requirements
  • Each cycle, members contribute a fixed amount
  • One member receives the total pot each cycle
  • Payouts rotate until everyone has received their share
  • All contributions and payouts are transparent on-chain

⭐ On-Chain Trust Scoring

  • Every user has a trust score (0-1000)
  • Score increases with:
    • Completed circles (+50 points)
    • On-time payments (+10 points)
    • Account age
    • Total volume
  • Score decreases with:
    • Missed payments (-50 points)
    • Circle abandonment (-100 points)
  • Trust scores determine access to larger circles and better terms

πŸ”’ Collateral Management

  • Members lock collateral when joining (120% of contribution value)
  • Collateral ensures commitment and protects against defaults
  • Released automatically upon circle completion
  • Supports STRK and ETH tokens

πŸ“Š Real-Time Dashboard

  • View all active circles
  • Track contribution status
  • Monitor payout schedules
  • See trust score analytics
  • Browse available circles to join

How we built it

Smart Contract Layer (Cairo)

We built three core smart contracts on Starknet:

1. Trust Registry Contract

- Tracks user reputation across the protocol
- Calculates trust scores based on activity
- Records payment history
- Manages user statistics
- Uses OpenZeppelin components for security

2. Lending Circle Contract

- Manages individual circle operations
- Handles member joins with collateral locking
- Processes contributions each cycle
- Executes automatic payouts
- Advances cycles based on time
- Integrates with Trust Registry for score updates

3. Circle Factory Contract

- Deploys new lending circles
- Maintains registry of all circles
- Maps users to their circles
- Implements pause/unpause functionality
- Uses proxy pattern for upgradeability

Security Features:

  • OpenZeppelin Ownable and Pausable components
  • ReentrancyGuard on all write functions
  • Comprehensive input validation
  • Role-based access control

Frontend Layer (Next.js + TypeScript)

Built a modern, responsive web application:

Tech Stack:

  • Next.js 14 (App Router) - Server and client components
  • TypeScript - Type-safe development
  • Tailwind CSS - Responsive styling
  • shadcn/ui - Beautiful UI components
  • Starknet.js - Contract interactions
  • @starknet-react/core - React hooks for Starknet
  • TanStack Query - Data fetching and caching
  • Framer Motion - Smooth animations

Key Components:

  • Wallet connection (Argent X, Braavos)
  • Circle creation wizard
  • Interactive circle cards
  • Real-time activity feeds
  • Trust score visualization
  • Member contribution tracking
  • Payout timeline

Pages Implemented:

  1. Landing page with protocol overview
  2. Dashboard with user statistics
  3. Browse circles marketplace
  4. Circle detail with full information
  5. Create circle multi-step form
  6. User profile with trust analytics

Integration Architecture

Cairo Contracts (Starknet)
        ↓
    Deploy & Get ABIs
        ↓
Contract Wrapper Classes (TypeScript)
        ↓
React Hooks (Data Layer)
        ↓
UI Components (Presentation)

Contract Integration:

  • Extracted ABIs from compiled contracts
  • Created type-safe wrapper classes
  • Built custom React hooks for each contract
  • Implemented real-time event listeners
  • Added transaction status tracking

Challenges we ran into

1. Cairo Development Learning Curve

Challenge: Cairo's unique syntax and concepts (felts, storage maps, component system) were initially difficult to grasp.

Solution:

  • Studied OpenZeppelin Cairo contracts extensively
  • Broke down complex logic into smaller functions
  • Used Scarb's testing framework for rapid iteration
  • Leveraged Cairo community documentation

2. BigInt Handling in JavaScript

Challenge: Starknet uses 252-bit integers (felt252) which don't directly map to JavaScript numbers.

Solution:

  • Used BigInt everywhere for contract interactions
  • Created utility functions for safe conversions
  • Added proper serialization for JSON responses
  • Implemented display formatters for UI

3. Transaction UX

Challenge: Multi-step transactions (approve + execute) were confusing for users.

Solution:

  • Built clear transaction flow visualization
  • Added progress indicators for each step
  • Implemented optimistic UI updates
  • Showed helpful error messages with solutions

4. Contract Event Listening

Challenge: Real-time updates required polling Starknet nodes, which was slow and inefficient.

Solution:

  • Implemented smart polling with TanStack Query
  • Used staleTime and refetchInterval strategically
  • Added manual refetch on user actions
  • Cached data aggressively to reduce calls

5. Collateral Calculations

Challenge: Ensuring correct collateral amounts to prevent defaults while not over-collateralizing.

Solution:

  • Researched DeFi lending protocols (Aave, Compound)
  • Settled on 120% collateralization ratio
  • Added buffer for price volatility
  • Implemented oracle integration (for future)

6. State Synchronization

Challenge: Keeping frontend state in sync with blockchain state across multiple contracts.

Solution:

  • Used React Query for automatic cache invalidation
  • Implemented event-driven refetching
  • Added optimistic updates for better UX
  • Created global state for connected wallet

7. Gas Optimization

Challenge: Complex circle operations were expensive on Starknet.

Solution:

  • Minimized storage writes
  • Batched operations where possible
  • Used efficient data structures (Maps instead of Arrays)
  • Removed unnecessary computations

Accomplishments that we're proud of

✨ Technical Achievements

  1. Complete End-to-End Implementation

    • Fully functional smart contracts deployed on Starknet
    • Production-ready frontend with 7+ pages
    • 15+ reusable components
    • Type-safe contract integration
  2. On-Chain Trust System

    • First decentralized reputation system for lending circles
    • Dynamic score calculation
    • Transparent and tamper-proof
    • Integrates across all circles
  3. Seamless UX

    • One-click circle creation
    • Intuitive contribution flow
    • Real-time updates
    • Beautiful, modern design
  4. Security First

    • OpenZeppelin security components
    • Comprehensive input validation
    • Pausable emergency stops
    • Collateral protection

🌟 Impact Potential

  1. Financial Inclusion

    • Brings lending circles to crypto
    • No traditional bank required
    • Global accessibility
    • Transparent and fair
  2. Community Building

    • Encourages cooperation
    • Rewards good behavior
    • Punishes bad actors
    • Builds on-chain reputation
  3. DeFi Innovation

    • Novel use case for Starknet
    • Bridges traditional finance with crypto
    • Creates new primitive for social lending
    • Foundation for future features

What we learned

Technical Learnings

  1. Cairo & Starknet Development

    • Cairo's component-based architecture
    • Storage optimization techniques
    • Contract upgradeability patterns
    • Event emission best practices
    • Starknet transaction lifecycle
  2. Frontend-Blockchain Integration

    • Contract ABI extraction and usage
    • Type-safe contract calls with TypeScript
    • Managing BigInt in JavaScript
    • Real-time data synchronization
    • Wallet connection flows
  3. Smart Contract Design Patterns

    • Factory pattern for contract deployment
    • Proxy pattern for upgradeability
    • Access control with OpenZeppelin
    • Event-driven architecture
    • Gas optimization strategies

Product & Design Learnings

  1. User Experience in Web3

    • Transaction flows must be explicit
    • Loading states are critical
    • Error messages must be actionable
    • Users need constant feedback
    • Wallet UX is make-or-break
  2. Social DeFi Mechanics

    • Trust systems need clear incentives
    • Collateral must balance safety and accessibility
    • Transparency builds confidence
    • Community features drive adoption
    • Simple mechanics are most powerful
  3. Hackathon Development

    • MVP scope is crucial
    • Focus on core features first
    • Polish can wait
    • Demo readiness matters
    • Documentation is important

What's next for Moonight Protocol

Phase 2: Enhanced Features (1-2 months)

🀝 P2P Direct Lending

  • One-on-one loans between users
  • Flexible terms negotiation
  • Custom collateral requirements
  • Interest rate marketplace

πŸ—³οΈ Democratic Voting

  • Members vote on payout recipients
  • Governance for circle parameters
  • Dispute resolution system
  • Proposal mechanism

πŸ’° Yield Integration

  • Integrate with Vesu protocol
  • Earn yield on idle capital
  • Auto-compound contributions
  • Liquidity pools for lenders

Phase 3: Cross-Chain & Advanced (3-6 months)

β‚Ώ Bitcoin Integration

  • Atomiq bridge integration
  • Use BTC as collateral
  • Cross-chain payouts
  • Lightning Network support

🌐 Multi-Chain Deployment

  • Expand to other Starknet L2s
  • Bridge to Ethereum mainnet
  • Support more tokens
  • Cross-chain reputation

🎯 Advanced Features

  • Credit scoring AI
  • Social vouching system
  • Referral rewards
  • Achievement badges
  • Mobile app (React Native)

Phase 4: Scale & Ecosystem (6-12 months)

🏒 Business Expansion

  • Partner with microfinance organizations
  • Regional community managers
  • Educational content
  • Developer grants program

πŸ“Š Analytics & Tools

  • Circle performance metrics
  • Risk assessment dashboard
  • Lending analytics
  • API for integrations

🌍 Real-World Impact

  • Target emerging markets
  • Remittance solutions
  • Small business lending
  • Agricultural financing

Long-term Vision

Moonight Protocol aims to become the global standard for decentralized social lending, bringing financial services to the 1.7 billion unbanked adults worldwide. By combining the time-tested model of lending circles with blockchain transparency and security, we're building infrastructure for financial inclusion at scale.


Built With

Share this project:

Updates