Skip to content

Lay3rLabs/wavs-prediction-market

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WAVS Prediction Market Demo

This project implements a prediction market that is resolved by an AVS oracle. There is a frontend to interact with the demo.

System Requirements

Core (Docker, Compose, Make, JQ, NodeJS v21+)

Docker

Docker Compose

  • MacOS: Already installed with Docker installer
  • Linux: sudo apt-get install docker-compose-v2
  • Compose Documentation

Make

JQ

Node.js

Rust v1.84+

Rust Installation

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

rustup toolchain install stable
rustup target add wasm32-wasip2

Upgrade Rust

# Remove old targets if present
rustup target remove wasm32-wasi || true
rustup target remove wasm32-wasip1 || true

# Update and add required target
rustup update stable
rustup target add wasm32-wasip2
Cargo Components

Install Cargo Components

# Install required cargo components
# https://github.com/bytecodealliance/cargo-component#installation
cargo install cargo-binstall
cargo binstall cargo-component warg-cli wkg --locked --no-confirm --force

# Configure default registry
wkg config --default-registry wa.dev

Installation and Setup

Solidity

Install the required packages to build the Solidity contracts. This project supports both submodules and npm packages.

# Install packages (npm & submodules)
make setup

# Build the contracts
forge build

Build WASI components

Now build the WASI rust components into the compiled output directory.

Warning

If you get: error: no registry configured for namespace "wavs"

run, wkg config --default-registry wa.dev

Warning

If you get: failed to find the 'wasm32-wasip1' target and 'rustup' is not available

brew uninstall rust & install it from https://rustup.rs

make wasi-build # or `make build` to include solidity compilation.

WAVS

Note

If you are running on a Mac with an ARM chip, you will need to do the following:

  • Set up Rosetta: softwareupdate --install-rosetta
  • Enable Rosetta (Docker Desktop: Settings -> General -> enable "Use Rosetta for x86_64/amd64 emulation on Apple Silicon")

Configure one of the following networking:

  • Docker Desktop: Settings -> Resources -> Network -> 'Enable Host Networking'
  • brew install chipmk/tap/docker-mac-net-connect && sudo brew services start chipmk/tap/docker-mac-net-connect

Start Environment

Start an ethereum node (anvil), the WAVS service, and deploy eigenlayer contracts to the local network.

cp .env.example .env

# Start the backend
#
# This must remain running in your terminal. Use another terminal to run other commands.
# You can stop the services with `ctrl+c`. Some MacOS terminals require pressing it twice.
make start-all

Run the demo

# Deploy contracts
make deploy-contracts

# Deploy the oracle service component
make deploy-service

# Buy YES in the prediction market
make buy-yes
# Notice in the logs that you start with 1e18 collateral tokens, and then purchase 1e18 YES shares for 525090975565627651 (~5.25e17) collateral tokens, leaving 474909024434372349 (~4.75e17) collateral tokens remaining.

# Trigger the oracle to resolve the market
make trigger-service

# Wait for the component to execute
echo "waiting 3 seconds for the component to execute..."
sleep 3

# Redeem YES in the resolved prediction market
make redeem

Notice in the logs that you redeem 1e18 outcome (YES) shares for 1e18 collateral tokens, ending up with 1474909024434372349 (~1.47e18) collateral tokens. This is more than you started with since you earned a profit from the market by betting on the correct outcome.

Frontend

A frontend application is included for interacting with the prediction market system.

Features

  • Connect your Ethereum wallet
  • Submit predictions to existing markets by buying YES/NO outcome tokens
  • View market history and probabilities with interactive charts
  • Display payout distribution for resolved markets
  • Display past markets and their results
  • Admin/debug interface to trigger the AVS oracle to resolve markets

Running the Frontend

The frontend must be started after the backend is running and the contracts are deployed, since the environment variables are set by the rune2e.sh script and need to be available to the frontend.

# In a terminal, start the backend
make start-all

# In another terminal, deploy the necessary contracts/service.
make deploy-contracts
make deploy-service

# Then install frontend dependencies
cd frontend
npm install

# And start the server
npm run dev

# Frontend will be available at http://localhost:3000

To test the prediction market, follow these steps:

  1. Go to the admin page and use the faucet to get fee tokens
  2. Go to the markets page and click the active market
  3. Buy YES outcome tokens
  4. Go to the admin page and trigger the oracle to resolve the market as YES
  5. Back on the market page, redeem your YES outcome tokens for collateral tokens now that the market has been resolved

Claude Code

To spin up a sandboxed instance of Claude Code in a Docker container that only has access to this project's files, run the following command:

npm run claude-code
# or with no restrictions (--dangerously-skip-permissions)
npm run claude-code:unrestricted

You must have Docker installed.