Skip to content

bakarilevy/100X

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prediction Market

Hardhat

Local Development

# Compile contracts
bunx hardhat compile

# Start node
bunx hardhat node --verbose

# Deploy script
bunx hardhat run scripts/hardhat_deploy.js --network localhost

Deploy BuildBear during testing switch ENV variables on front and backend to point to contracts on buildbear

bunx hardhat run scripts/buildbear_deploy.js --network buildbear

Production Deployment

Mainnet requires security audit Deployer account should have multi-sig wallet Update hardhat.config.js for mainnet Integration test suite should be run against testnet Ensure all contract addresses on Mainnet are appropriately set as environment variables, and a separate wallet is used for the platform, consider setting another wallet address for the treasury.

Deploy on mainnet

bunx hardhat run scripts/mainnet_deploy.js --network mainnet

Checklist:

✅ Environment variables for mainnet set locally?
✅ Hardhat mainnet network configured correctly?
✅ Testnet dry run completed successfully?
✅ Sufficient ETH in deployer account?
✅ Run mainnet_deploy.js script?
✅ Copy new contract addresses?
✅ Update backend environment variables?
✅ Update frontend environment variables and rebuild?
✅ Deploy updated backend to Render?
✅ Test the live application on mainnet (small test deposit)?

Once all updates have been made after deployment scripts run, add all production environment variables to env.production.local and update prod env variables

Migrate DB

# Generate migration file
bunx drizzle-kit generate

# Apply to DB
bunx drizzle-kit migrate

Build Services

Simple:

# Build locally by running install script on backend and frontend locally then deploy to production environment
bun install
bun start

Advanced:

docker-compose up --build

Flow Control

Prediction Market

User                     Frontend                  Backend Services                 Database                Ethereum Network
  |                          |                           |                            |                         |
  |--- Register -------------|                           |                            |                         |
  |                          |--- POST /register ------->|                            |                         |
  |                          |                           |--- DatabaseUtils.createUser() -->|                   |
  |                          |                           |    (creates user + balance)|                         |
  |<-- Deposit Address ------|                           |                            |                         |
  |                          |                           |                            |                         |
  |--- Send xUSD ----------->|                           |                            |                         |
  |                          |                           |                            |--- Ethereum tx -------->|
  |                          |                           |<-- EVMService: deposit event|                        |
  |                          |                           |    (listens for Transfer)  |                         |
  |                          |<-- Balance Update --------|--- DatabaseUtils.updateBalanceWithTransaction() ->   |
  |                          |                           |    (type: 'deposit')       |                         |
  |                          |                           |                            |                         |
  |--- View Market --------->|                           |                            |                         |
  |                          |--- GET /market/:id ------>|                            |                         |
  |                          |                           |--- PredictionMarketService.getMarket() -->           |
  |                          |                           |    (calls DatabaseUtils.getMarket())                 |
  |<-- Market Data ----------|                           |                            |                         |
  |                          |                           |                            |                         |
  |--- Get Quote ----------->|                           |                            |                         |
  |                          | POST /market/prices/:id ->|                            |                         |
  |                          |                           |--- PredictionMarketService.getMarketPrices()         |
  |                          |                           |    (uses LMSR calculator)  |                         |
  |<-- Trade Quote ----------|                           |                            |                         |
  |                          |                           |                            |                         |
  |--- Place Bet ----------->|                           |                            |                         |
  |                          | POST /market/buy/ ------->|                            |                         |
  |                          |                           |--- PredictionMarketService.buyShares()|              |
  |                          |                           |    (within DB transaction) |                         |
  |                          |                           |   ├─ check balance ------->|                         |
  |                          |                           |   ├─ calculate cost (LMSR) |                         |
  |                          |                           |   ├─ update inventory ---->|                         |
  |                          |                           |   ├─ update position ----->|                         |
  |                          |                           |   ├─ record transaction -->|                         |
  |                          |                           |   └─ emit 'sharesBought'   |                         |
  |<-- Trade Confirmed ------|                           |                            |                         |
  |                          |<-- WebSocket Update ------|                            |                         |
  |                          |                           |                            |                         |
  |--- Wait for Outcome ---- |                           |                            |                         |
  |                          |                           |                            |                         |
  |                          |<-- Admin Resolves ------- |--- PredictionMarketService.resolveMarket() ->|       |
  |                          |                           |    (sets resolved_outcome) |                         |
  |                          |                           |                            |                         |
  |                          |<-- Admin Triggers Payouts |--- PredictionMarketService.processPayouts() ->|      |
  |                          |                           |    (within DB transaction) |                         |
  |                          |                           |   ├─ fetch winning positions|                        |
  |                          |                           |   ├─ update balances ----->|                         |
  |                          |                           |   ├─ mark claimed -------->|                         |
  |                          |                           |   └─ emit 'payoutsProcessed'|                        |
  |<-- Payout Notification --|                           |                            |                         |
  |                          |                           |                            |                         |
  |--- Withdraw ------------>|                           |                            |                         |
  |                          |--- POST /withdraw ------->|                            |                         |
  |                          |                           |--- EVMService.requestWithdrawal()|                   |
  |                          |                           |   ├─ check balance ------->|                         |
  |                          |                           |   ├─ create withdrawal --->|                         |
  |                          |                           |   ├─ EVMService.sendTransaction() |--- Ethereum tx ->|
  |                          |                           |   └─ update withdrawal --->|                         |
  |<-- Withdrawal Complete --|                           |                            |                         |

About

100X Core - Production Ready Stablecoin, Lending Protocol, & Prediction Market

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors