Skip to content

golden-mane-labs/solana-prediction-market-smart-contract

Repository files navigation

Solana Prediction Market Smart Contract

A decentralized prediction market smart contract on Solana, inspired by Polymarket. Create markets, trade Yes/No positions, and resolve outcomes—all on-chain.

Overview

This project provides a full-featured prediction market built with the Anchor framework. Users can create binary outcome markets for any event, add liquidity, trade positions using Yes/No SPL tokens, and resolve markets based on real-world outcomes. The architecture is modular and the patterns can be adapted for EVM chains.

Features

  • Market Creation — Create binary outcome markets for any event
  • Liquidity Provision — Add and withdraw liquidity to support trading
  • Trading — Trade positions using Yes/No tokens
  • Market Resolution — Resolve markets based on final outcomes with automatic payouts
  • Fee Structure — Configurable platform and LP fees
  • Extensible — Clear patterns for adapting to other chains

Tech Stack

  • Anchor — Solana smart contract framework
  • Solana Web3.js — JavaScript SDK
  • SPL Token Program
  • Associated Token Program

Prerequisites

Installation

  1. Clone the repository:
git clone https://github.com/rustjesty/solana-prediction-market-smart-contract
cd solana-prediction-market-smart-contract
  1. Install dependencies:
yarn install
  1. Build and deploy the program:
anchor build
anchor deploy

Configuration

Configure environment, keypair, and RPC URL:

yarn script config -e devnet -k <your-keypair-path> -r <your-rpc-url>

Usage

Workflow order: configmarketaddlpswap (optional) → withdrawresolution

Create a Market

yarn script market -e devnet -k <your-keypair-path> -r <your-rpc-url>

Add Liquidity

You must add liquidity before you can withdraw it.

yarn script addlp -y <yes-token-address> -n <no-token-address> -a <amount> -e devnet -k <your-keypair-path> -r <your-rpc-url>

Trade Positions

  • -s (style): 0 = buy, 1 = sell
  • -t (token-type): 0 = NO token, 1 = YES token
yarn script swap -y <yes-token-address> -n <no-token-address> -a <amount> -s <style> -t <token-type> -e devnet -k <your-keypair-path> -r <your-rpc-url>

Withdraw Liquidity

Requires that you have added liquidity first via addlp.

yarn script withdraw -y <yes-token-address> -n <no-token-address> -a <amount> -e devnet -k <your-keypair-path> -r <your-rpc-url>

Resolve Market

yarn script resolution -y <yes-token-address> -n <no-token-address> -e devnet -k <your-keypair-path> -r <your-rpc-url>

Example Transaction

Config transaction on Solscan (Devnet)

Create market transaction on Solscan (Devnet)

Yes Token (Devnet)

No Token (Devnet)

Add Liquidity(Devnet)

Resolution (Devnet)

Contact

For questions or custom implementations:

Contributing

Contributions are welcome. Please open an issue or submit a pull request.

License

MIT — see LICENSE for details.

About

A decentralized prediction market smart contract on Solana, inspired by Polymarket. Create markets, trade Yes/No positions, and resolve outcomes—all on-chain.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors