Skip to content

Anushlinux/ChitChain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ChitChain πŸ”—

Decentralized Rotating Savings and Credit Association (ROSCA) on Aptos

ChitChain modernizes the centuries-old chit fund model by deploying it on the Aptos blockchain. Using the safety guarantees of Move and the parallel execution of Block-STM, ChitChain eliminates intermediary risk while enabling instant dividend distribution.

Built on Aptos Move Language

🌟 Features

  • Trustless Operation: Smart contracts replace the traditional "Foreman", eliminating fraud risk
  • Instant Dividends: Auction discounts distributed immediately using Aptos parallel execution
  • Low Fees: <1% protocol fee vs 5-7% traditional chit fund fees
  • Zero Default Risk: Phase I collection ensures full collateralization
  • Market-Driven: Bidding mechanism discovers true cost of capital

πŸ“‹ How It Works

Phase 1: Collection

  1. Creator sets up a pool with contribution amount and member limit
  2. Members join and deposit their full contribution as collateral
  3. Once the pool is full, collection phase begins

Phase 2: Auction

  1. Monthly auctions where members bid for the pot
  2. Highest bidder (offering largest discount) wins
  3. Winner receives: Pot - Discount
  4. Other members receive: Discount / (N-1) as immediate dividend
  5. Repeat until all members have won

πŸ—οΈ Project Structure

chitchain/
β”œβ”€β”€ contracts/               # Move smart contracts
β”‚   β”œβ”€β”€ sources/
β”‚   β”‚   β”œβ”€β”€ pool.move       # Pool creation & management
β”‚   β”‚   β”œβ”€β”€ auction.move    # Bidding & auction logic
β”‚   β”‚   β”œβ”€β”€ treasury.move   # Fund distribution & escrow
β”‚   β”‚   β”œβ”€β”€ events.move     # Event definitions
β”‚   β”‚   └── errors.move     # Error codes
β”‚   └── tests/              # Move unit tests
β”‚
β”œβ”€β”€ frontend/               # Next.js web application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ app/           # Next.js App Router pages
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ hooks/         # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ lib/           # Utilities & Aptos client
β”‚   β”‚   └── providers/     # Context providers
β”‚   └── public/
β”‚
└── scripts/                # Deployment scripts

πŸš€ Quick Start

Prerequisites

1. Clone the Repository

git clone https://github.com/yourusername/chitchain.git
cd chitchain

2. Deploy Smart Contracts

cd contracts

# Initialize Aptos (creates .aptos/config.yaml)
aptos init --network testnet

# Compile contracts
aptos move compile --named-addresses chitchain=default

# Run tests
aptos move test --named-addresses chitchain=default

# Deploy to testnet
aptos move publish --named-addresses chitchain=default --assume-yes

Save the deployed module address for the frontend configuration.

3. Set Up Frontend

cd ../frontend

# Install dependencies
npm install

# Configure environment
cp .env.example .env.local
# Edit .env.local with your module address:
# NEXT_PUBLIC_MODULE_ADDRESS=0x<your_deployed_address>
# NEXT_PUBLIC_NETWORK=testnet
# NEXT_PUBLIC_APTOS_API_KEY=your_api_key_here (optional, get from https://geomi.dev)
# NEXT_PUBLIC_APTOS_RPC_URL=https://api.testnet.aptoslabs.com/v1 (optional, custom RPC endpoint)

# Start development server
npm run dev

Open http://localhost:3000 in your browser.

πŸ” Verifying Network Configuration

If you and a friend are on different networks and can't see each other's pools, verify both are using the same configuration:

  1. Check the Configuration Diagnostics card on the pools page - it shows:

    • Network (Configured): The network from your .env.local file
    • Detected from RPC: The network detected from the RPC endpoint URL
    • RPC Endpoint: The actual endpoint being used
    • Module Address: Must match on both devices
  2. Ensure both have the same .env.local file:

    NEXT_PUBLIC_NETWORK=testnet
    NEXT_PUBLIC_MODULE_ADDRESS=c1c71853104465563071e7c615bd4c0fe1cab1a929281588dde3aeda61744163
    NEXT_PUBLIC_APTOS_RPC_URL=https://api.testnet.aptoslabs.com/v1
  3. If you see "Network Mismatch" warning: Your configured network doesn't match the RPC endpoint. Update NEXT_PUBLIC_NETWORK to match.

  4. Restart the dev server after changing environment variables:

    # Stop the server (Ctrl+C) and restart
    npm run dev

πŸ“œ Smart Contract API

Pool Module

Function Description
create_pool Create a new savings pool
join_pool Join an existing pool
start_collection_phase Begin Phase I (creator only)
contribute Deposit contribution
start_auction_phase Begin Phase II (creator only)

Auction Module

Function Description
start_auction Start a new auction round
place_bid Place a bid with discount
finalize_auction End auction and distribute funds

Treasury Module

Function Description
claim_escrow Claim escrowed dividends
withdraw_protocol_fees Admin fee withdrawal

πŸ”§ Configuration

Pool Parameters

Parameter Range Default
max_member_count 2-100 -
contribution_per_member >0 APT -
max_discount_bps 100-5000 3000 (30%)

Protocol Parameters

Parameter Value
Protocol Fee 1% (100 bps)
Auction Duration 24 hours

πŸ›‘οΈ Security

  • Move Safety: Linear type system prevents asset duplication
  • Formal Verification: Critical functions verified with Move Prover
  • Collateralization: Phase I deposits eliminate default risk
  • Griefing Protection: Failed transfers escrowed for manual claim

πŸ—ΊοΈ Roadmap

  • Core smart contracts (Pool, Auction, Treasury)
  • Web frontend with wallet integration
  • Telegram bot for notifications
  • Move Prover specifications
  • Mainnet deployment
  • Thala yield integration for Phase I deposits
  • Cross-chain support via LayerZero

πŸ“Š Comparison with Traditional Chit Funds

Feature Traditional ChitChain
Trust Model Reputation Code Verification
Fees 5-7% <1%
Payout Speed Manual (days) Instant
Default Risk High None
Transparency Limited Full on-chain

🀝 Contributing

Contributions are welcome! Please read our contributing guidelines before submitting PRs.

πŸ“„ License

MIT License - see LICENSE for details.

πŸ”— Links


Built with ❀️ for the Aptos Code Collision Hackathon

About

A trustless, on-chain Rotating Savings and Credit Association (ROSCA) built on Aptos.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors