HUNCH Smart Contracts Documentation

Overview

HUNCH uses a modular smart contract architecture with four main contracts working together to create a decentralized prediction market platform.

Contract Architecture

MarketFactory ──┐
                ├── Oracle
Market ─────────┘
MultiOptionMarket

Core Contracts

1. MarketFactory Contract

Purpose: Central factory for creating and managing binary prediction markets.

Key Functions

function createMarket(
    string memory _question,
    string memory _description,
    uint256 _endTime,
    string memory _category
) external returns (uint256 marketId)

Creates a new binary market and returns its unique ID.

Retrieves complete information about a specific market.

Returns array of all created market IDs.

Returns array of currently active market IDs.

Events

2. Market Contract

Purpose: Individual binary market logic with automated market maker.

Core Trading Functions

Purchase shares for YES or NO outcome. Includes:

  • Automatic price calculation

  • 2% trading fee

  • Share issuance

  • Price updates

Sell existing shares back to the market:

  • Calculates current payout value

  • Burns shares from user balance

  • Transfers ETH to user

  • Updates market pricing

Allows users to claim winnings after market resolution:

  • Only works on resolved markets

  • Calculates winnings based on held shares

  • Transfers full payout to user

  • Prevents double claiming

View Functions

Returns current price per share (in wei).

Returns user's current share balances.

Returns comprehensive market information.

AMM Pricing Model

The market uses a constant product formula:

Features:

  • Initial liquidity of 1000 ETH equivalent

  • Dynamic pricing based on share distribution

  • Built-in slippage protection

  • 2% fee on all trades

3. MultiOptionMarketFactory Contract

Purpose: Factory for creating multi-choice prediction markets.

Key Functions

Creates a new multi-option market with 3-8 possible outcomes.

Returns markets filtered by category.

4. MultiOptionMarket Contract

Purpose: Individual multi-choice market logic.

Trading Functions

Purchase shares for a specific option.

Sell shares for a specific option.

Multi-Option Pricing

Each option has independent pricing:

Ensures all option prices sum to approximately 1.00.

5. Oracle Contract

Purpose: Decentralized market resolution system.

Resolution Functions

Resolves a binary market with YES or NO outcome.

Batch resolve multiple markets efficiently.

Access Control

Adds authorized resolver address.

Removes resolver authorization.

Security Features

Access Control

  • Owner-only functions for critical operations

  • Multi-signature support for oracle operations

  • Timelock for critical parameter changes

Reentrancy Protection

  • ReentrancyGuard on all state-changing functions

  • Checks-Effects-Interactions pattern

  • Safe ETH transfers

Input Validation

  • Comprehensive parameter validation

  • Range checks on all numeric inputs

  • String length limits

  • Array bounds checking

Emergency Features

Allows market cancellation in emergency situations.

Gas Optimization

Efficient Storage

  • Packed structs for reduced storage costs

  • Minimal state changes per transaction

  • Batch operations for multiple actions

Optimized Algorithms

  • Efficient price calculations

  • Minimal loops in critical paths

  • Pre-computed values where possible

Deployment Addresses

Mainnet

Polygon

Testnets (Sepolia)

Integration Guide

Basic Market Creation

Trading Shares

Listening to Events

Testing

Unit Tests

Run comprehensive test suite:

Test Coverage

  • 95%+ line coverage

  • All critical functions tested

  • Edge case handling verified

  • Gas usage optimized

Security Audits

  • Multiple professional audits completed

  • No critical vulnerabilities found

  • Regular security reviews

  • Bug bounty program active

Upgrade Path

Current Version: v2.0

  • Multi-option market support

  • Enhanced AMM pricing

  • Gas optimizations

  • Improved security

Future Upgrades

  • Layer 2 deployment

  • Cross-chain bridges

  • Advanced oracle mechanisms

  • Governance token integration

Last updated