Skip to content

dariusjvc/solana-escrow-gambling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Solana Escrow Gambling

Overview

escrow-program is a smart contract built on Solana that facilitates a simple gambling game between two users. The game revolves around betting on the ETH/USDC price movement, where players bet whether the price will increase or decrease by 5%. The contract holds the entry fees in escrow and sends the funds to the winner once a price change condition is met.

Task Overview

The goal of this contract is to facilitate a game where two users compete by betting on the ETH/USDC price. Users can bet on either an increase or decrease of the ETH price by 5%. Once one of these thresholds is reached, the winning player can call the closeGame function, and the escrow contract will verify the win and send the entry fees to the winner.

Minimum Viable Product (MVP) Functionality

  • Entry into game for Player 1:

    • $1000 USDC entrance fee.
    • Player selects either an increase or decrease of the ETH price.
  • Entry into game for Player 2:

    • $1000 USDC entrance fee.
    • Must choose the opposite of Player 1’s choice.
    • Entry allowed only if the price has not fluctuated by more than 1% since Player 1 entered.
  • Withdrawing of entry:

    • Only allowed for Player 1 if Player 2 has not entered the game yet.
    • Once Player 2 enters, no withdrawals are permitted.
  • Closing the game:

    • The winner, once determined by a 5% price movement in their favor, calls the closeGame function to receive the entry fees.

Cloning

git clone https://github.com/dariusjvc/solana-escrow-gambling.git
cd solana-escrow-gambling

Dependencies

After cloning the repository, install the necessary dependencies:

npm install

Wallet Setup (IMPORTANT)

The program uses the default Solana wallet located at:

$HOME/.config/solana/id.json

This file represents both the payer and the account of the player1. It should have enough SOL for transaction fees. Additionally, two more wallets are used by the program:

/wallets/
 ├── escrow.json   # Escrow account for holding entry fees
 ├── player2.json  # Player 2's wallet

These accounts, along with the token accounts to receive USDC winnings, are automatically generated when you run the initialization script:

./init_accounts.sh

Ensure all wallets have enough SOL for transaction fees and the required USDC balances for testing.

Initialization and Deployment

1. Initialize Token Accounts and Wallets

Run:

./init_accounts.sh

2. Deploy the Program

./cicd.sh

After deployment:

  • The DEPLOYED_PROGRAM_ADDRESS and the rest of the variables will be automatically written to your .env file.

Running the Tests

Once .env is updated:

npm run test

Test Descriptions

  1. Create Gameentry_price = 0 fetches price from Pyth Oracle.
  2. Oracle Price Test – No parameters.
  3. Join Gamelast_price = 0 fetches price from Pyth Oracle.
  4. Withdraw Game – No parameters.
  5. Settle Gamelast_price = 0 fetches price from Pyth Oracle.
  6. Close Game – No parameters.

Notes

  • Node Version: v18.20.4 or higher.
  • Solana CLI Version: 2.3.7 (needed for updated account metas order in SPL token program).
  • Always run init_accounts.sh before cicd.sh in a fresh setup.
  • The id.json wallet replaces the old payer.json and is used as the main payer for transactions.

Conclusion

This program demonstrates a simple escrow-based gambling game on Solana, integrating with the Pyth Oracle for real-time price data. It is a fully tested, ready-to-deploy base for more advanced escrow or betting applications.

About

A decentralized escrow-based gambling protocol built on Solana using Rust and TypeScript. Handles bet creation, escrow locking, and fair winner resolution through on-chain logic.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors