Skip to content

ChinmayGopal931/wagerly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wagerly - A Prediction Market built entirely on HyperEVM

Wagerly is a prediction market that allows users to speculate on the PnL of a trader's perpetual futures position. By leveraging on-chain position data, our protocol creates a novel financial primitive where you can bet on a trader's performance, as well as an asset's price. This enables new use cases for hedging, speculation, and monetizing trading alpha in a fully transparent and trustless manner. Markets are trustless, and also incentivize market creaters by directing swap revenue to them as LPs.

Finalist for the Hyperliquid Community Hackaton - https://x.com/hl_hackathon/status/1965085820798591198

Link to submission : https://taikai.network/hl-hackathon-organizers/hackathons/hl-hackathon/projects/cmeks4n6d02odw40igiffkw7g/idea

Architecture

Core Contracts

  • PnlBet.sol: Logic contract containing all betting functionality
  • BetFactory.sol: Factory contract that deploys minimal proxies using EIP-1167

Key Features

  • Gas Efficient: Uses minimal proxy pattern to deploy lightweight bet contracts
  • Factory Pattern: Centralized registry for discovering all bets
  • Flexible Betting: Support for both profit and loss predictions
  • Automated Settlement: Mock PnL calculation (ready for Hyperliquid precompile integration)
  • Comprehensive Testing: Full test coverage for both contracts

Getting Started

Prerequisites

Installation

# Clone the repository
git clone <repository-url>
cd project-mosiac

# Install dependencies
forge install

# Copy environment file
cp .env.example .env

Configuration

Edit .env file with your configuration:

PRIVATE_KEY=your-private-key
ETHEREUM_RPC_URL=your-rpc-url
# ... other configuration

Usage

Build

forge build

Test

# Run all tests
forge test

# Run tests with gas reporting
forge test --gas-report

# Run specific test file
forge test --match-path test/PnlBet.t.sol -vvv

Deploy

# Deploy to local fork
forge script script/Deploy.s.sol --rpc-url local --broadcast

# Deploy to Hyperliquid mainnet
forge script script/Deploy.s.sol --rpc-url hyperliquid --broadcast

Create a Bet

After deployment, update your .env file with the factory address and run:

forge script script/CreateBet.s.sol --rpc-url hyperliquid --broadcast

Contract Interaction

Creating a Bet

// Create a bet on user's PnL for perp ID 1, lasting 1 hour
address betAddress = factory.createBet(
    targetUser,  // Address to track
    1,           // Perp ID
    3600         // Duration in seconds
);

Placing Bets

PnlBet bet = PnlBet(betAddress);

// Bet 1 ETH that the position will be profitable
bet.placeBet{value: 1 ether}(true);

// Bet 2 ETH that the position will be unprofitable
bet.placeBet{value: 2 ether}(false);

Settlement and Claims

// After the bet period ends, anyone can settle
bet.settle();

// Winners can claim their proportional share
bet.claimWinnings();

Gas Optimization

The system is optimized for minimal gas usage:

  • Proxy Deployment: ~45,000 gas per new bet (vs ~500,000 for full contract)
  • Factory Registry: O(1) bet creation and discovery
  • Batch Operations: Factory supports batch settlement for keeper bots

Testing

The project includes comprehensive tests covering:

  • Contract deployment and initialization
  • Bet creation and placement
  • Settlement mechanics
  • Winnings calculation and distribution
  • Edge cases and error conditions

Run tests with:

forge test -vvv

Fork Testing with Live Hyperliquid Data

Test against real Hyperliquid mainnet positions:

# Start Hyperliquid fork
anvil --fork-url https://rpc.hyperliquid.xyz/evm

# Run fork tests
forge test --match-contract ForkTest --fork-url https://rpc.hyperliquid.xyz/evm -vvv

# Or use the quick start script
./fork-test.sh

See FORK_TESTING.md for detailed instructions.

Mock Implementation Note

The current implementation uses a mock PnL calculation for testing. In production, this would be replaced with calls to Hyperliquid precompiles:

// Replace _getMockPnl() with actual Hyperliquid integration:
// 1. Call position precompile for target user and perp ID
// 2. Call markPx precompile for current mark price
// 3. Calculate actual PnL based on position data

Security Considerations

  • Uses OpenZeppelin's battle-tested proxy and reentrancy protection
  • All external calls are protected with proper checks
  • Comprehensive test coverage includes edge cases
  • Ready for audit and mainnet deployment

License

MIT License

mosaic

About

Prediction Market on HyperEVM

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published