dubs-server 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +280 -0
- package/CLAUDE.md +46 -0
- package/CONNECT4_PRODUCTION_DEPLOY.md +155 -0
- package/CURRENT_SESSION.md +171 -0
- package/CURRENT_SESSION_DRAW.md +516 -0
- package/MARCH_MADNESS_SURVIVOR.md +254 -0
- package/PANDA.md +166 -0
- package/Procfile +4 -0
- package/README.md +476 -0
- package/controllers/livescoresController.js +376 -0
- package/controllers/pickemController.js +554 -0
- package/controllers/survivorAdminController.js +887 -0
- package/controllers/survivorController.js +623 -0
- package/cron/oracleMonitor.js +77 -0
- package/cron/pickemOracleMonitor.js +73 -0
- package/data/jackpot-history.json +952 -0
- package/data/ncaaTeams.js +406 -0
- package/documentation/API_SECURITY_GUIDE.md +327 -0
- package/documentation/ARCADE_API.md +593 -0
- package/documentation/ARCADE_IMPLEMENTATION_SUMMARY.md +399 -0
- package/documentation/ARCADE_QUICKSTART.md +242 -0
- package/documentation/AUTOMATIC_MODE_ORACLE.md +321 -0
- package/documentation/BUG_FIX_COHORT_DATE_DISPLAY.md +171 -0
- package/documentation/CLAIM_MIGRATION_INSTRUCTIONS.md +52 -0
- package/documentation/CLAIM_STATUS_FIX.md +67 -0
- package/documentation/CLI_TOOL_GUIDE.md +372 -0
- package/documentation/COHORT_RETENTION_ANALYSIS.md +295 -0
- package/documentation/COHORT_RETENTION_IMPLEMENTATION_COMPLETE.md +461 -0
- package/documentation/COHORT_RETENTION_SUMMARY.md +204 -0
- package/documentation/COMPLETE_PROJECT_SUMMARY.md +490 -0
- package/documentation/DATABASE_QUERIES.md +269 -0
- package/documentation/DATABASE_RETENTION_POLICY.md +390 -0
- package/documentation/DATABASE_SETUP_GUIDE.md +361 -0
- package/documentation/DATABASE_SETUP_SUMMARY.md +247 -0
- package/documentation/DEMO_API_CURL_COMMANDS.md +656 -0
- package/documentation/DEPLOYMENT_SUMMARY.txt +100 -0
- package/documentation/DUPLICATE_NOTIFICATIONS_FIXED.md +201 -0
- package/documentation/EXCHANGE_RATES_INTEGRATION.md +371 -0
- package/documentation/FINAL_API_PROTECTION_TABLE.md +175 -0
- package/documentation/GAME_START_NOTIFICATIONS_DEPLOYMENT.md +256 -0
- package/documentation/GAME_START_NOTIFICATIONS_INTEGRATION.md +275 -0
- package/documentation/HEROKU_DEPLOYMENT.md +134 -0
- package/documentation/HEROKU_SCHEDULER_SETUP.md +271 -0
- package/documentation/JACKPOT_API.md +521 -0
- package/documentation/JACKPOT_DEPLOYMENT_GUIDE.md +362 -0
- package/documentation/JWT_IMPLEMENTATION_SUMMARY.md +373 -0
- package/documentation/JWT_QUICK_SETUP.md +268 -0
- package/documentation/JWT_TESTING_GUIDE.md +404 -0
- package/documentation/KEEPER_RECOVERY_GUIDE.md +381 -0
- package/documentation/KEEPER_SETUP.md +206 -0
- package/documentation/KEEPER_STATE_MACHINE.md +423 -0
- package/documentation/LATEST_PRODUCTION_SETUP.md +387 -0
- package/documentation/LOCAL_VOTING_TEST.md +279 -0
- package/documentation/ORACLE_FIXES_SUMMARY.md +188 -0
- package/documentation/ORACLE_POSTGRESQL_UPDATE.md +202 -0
- package/documentation/PAYMENT_DEPLOYMENT.md +209 -0
- package/documentation/PNL_TRACKING_SETUP.md +189 -0
- package/documentation/PREVENTING_LOCKUP_ERRORS.md +472 -0
- package/documentation/PRODUCTION_READY_SUMMARY.md +227 -0
- package/documentation/PUBLIC_VS_PRIVATE_ENDPOINTS.md +278 -0
- package/documentation/QUICK_AUTH_SETUP.md +99 -0
- package/documentation/QUICK_DEPLOY.md +224 -0
- package/documentation/QUICK_FIX.md +114 -0
- package/documentation/QUICK_START.md +152 -0
- package/documentation/REFEREE_MODE_GUIDE.md +392 -0
- package/documentation/RETENTION_CORE_ACTION_UPDATE.md +313 -0
- package/documentation/RETENTION_UPDATE_SUMMARY.md +108 -0
- package/documentation/RUN_MIGRATION_NOW.md +39 -0
- package/documentation/SCRIPTS_UPDATE_SUMMARY.md +251 -0
- package/documentation/SETUP_GUIDE.md +184 -0
- package/documentation/STATE_MACHINE_IMPLEMENTATION.md +250 -0
- package/documentation/TELEGRAM_NOTIFICATIONS_DIAGNOSIS.md +361 -0
- package/documentation/UNIFIED_ARCHITECTURE.md +231 -0
- package/documentation/VOTING_DEPLOYMENT_SUMMARY.md +392 -0
- package/documentation/WEBSOCKET_ARCHITECTURE.md +881 -0
- package/documentation/WHAT_WE_BUILT_TODAY.md +369 -0
- package/documentation/latest/LATEST_PRODUCTION_SETUP.md +865 -0
- package/ecosystem.config.js +65 -0
- package/env.template +125 -0
- package/middleware/apiKeyAuth.js +136 -0
- package/middleware/authenticate.js +214 -0
- package/middleware/developerUserAuth.js +76 -0
- package/middleware/socketAuth.js +69 -0
- package/package.json +49 -0
- package/postman/Dubs-API-v1-With-Voting.postman_collection.json +555 -0
- package/postman/Dubs-API-v1.postman_collection.json +205 -0
- package/postman/Dubs_Developer_API.postman_collection.json +662 -0
- package/postman/QUICKSTART.md +118 -0
- package/postman/QUICK_REFERENCE.md +246 -0
- package/postman/README.md +71 -0
- package/postman/VOTING_API_GUIDE.md +426 -0
- package/refactor/Animations.md +148 -0
- package/refactor/Chat.md +252 -0
- package/routes/actionsRoutes.js +699 -0
- package/routes/adminRoutes.js +370 -0
- package/routes/analyticsRoutes.js +1262 -0
- package/routes/arcadeRoutes.js +557 -0
- package/routes/authRoutes.js +2310 -0
- package/routes/avatarRoutes.js +85 -0
- package/routes/botRoutes.js +211 -0
- package/routes/chatRoutes.js +377 -0
- package/routes/cryptoPriceRoutes.js +105 -0
- package/routes/developerRoutes.js +4201 -0
- package/routes/deviceRoutes.js +214 -0
- package/routes/dmRoutes.js +167 -0
- package/routes/esportsRoutes.js +806 -0
- package/routes/exchangeRateRoutes.js +233 -0
- package/routes/gamesRoutes.js +3028 -0
- package/routes/jackpotRoutes.js +754 -0
- package/routes/keeperMonitoringRoutes.js +156 -0
- package/routes/keeperWebhookRoutes.js +466 -0
- package/routes/livescoresRoutes.js +31 -0
- package/routes/pickemAdminRoutes.js +199 -0
- package/routes/pickemRoutes.js +231 -0
- package/routes/playerStatsRoutes.js +147 -0
- package/routes/portfolioRoutes.js +217 -0
- package/routes/promoRoutes.js +418 -0
- package/routes/referralEarningsRoutes.js +392 -0
- package/routes/socialRoutes.js +459 -0
- package/routes/sportsRoutes.js +1271 -0
- package/routes/survivorAdminRoutes.js +345 -0
- package/routes/survivorRoutes.js +756 -0
- package/routes/uploadRoutes.js +256 -0
- package/routes/userProfileRoutes.js +244 -0
- package/routes/whatsNewRoutes.js +331 -0
- package/scripts/.claude/settings.local.json +15 -0
- package/scripts/README.md +170 -0
- package/scripts/RESTART_EVERYTHING.sh +104 -0
- package/scripts/add-claim-columns.sql +48 -0
- package/scripts/add-crypto-prices-cache.sql +27 -0
- package/scripts/add-exchange-rates-cache.sql +40 -0
- package/scripts/add-game-invite-column.sql +23 -0
- package/scripts/add-game-invite-notification.sql +33 -0
- package/scripts/add-game-invite-telegram-pref.sql +16 -0
- package/scripts/add-game-joined-notification.sql +16 -0
- package/scripts/add-game-joined-pref.js +40 -0
- package/scripts/add-game-joined-preference.sql +6 -0
- package/scripts/add-game-start-notifications.sql +41 -0
- package/scripts/add-notification-flags-to-games.sql +55 -0
- package/scripts/add-pending-game-dismissals.sql +19 -0
- package/scripts/add-preferred-currency.sql +34 -0
- package/scripts/add-winner-columns.js +61 -0
- package/scripts/add_mention_system.sql +53 -0
- package/scripts/add_payment_system.sql +96 -0
- package/scripts/add_sports_event_id_column.sql +22 -0
- package/scripts/analyze-cohort-data-heroku.js +276 -0
- package/scripts/analyze-cohort-data.js +295 -0
- package/scripts/analyze-prod-cohorts.sh +10 -0
- package/scripts/backfill-matchup-images.js +245 -0
- package/scripts/backfill-missing-signatures.js +175 -0
- package/scripts/backfill-referral-earnings.js +202 -0
- package/scripts/check-chat-schema.js +130 -0
- package/scripts/check-db.sh +14 -0
- package/scripts/check_oracle_in_game.js +54 -0
- package/scripts/cleanup-database.js +193 -0
- package/scripts/clear-notification-cache.js +85 -0
- package/scripts/convert-mnemonic.js +50 -0
- package/scripts/create-users-table.sql +44 -0
- package/scripts/debug-cohort-counts.js +248 -0
- package/scripts/debug-winner-calc.js +84 -0
- package/scripts/deploy-payment-system.sh +118 -0
- package/scripts/deploy-to-heroku.sh +63 -0
- package/scripts/diagnose-locked-round.js +143 -0
- package/scripts/dubs-cli.js +720 -0
- package/scripts/dump-account.js +65 -0
- package/scripts/find-vrf-offset.js +48 -0
- package/scripts/fix-chat-notifications-constraint.sql +122 -0
- package/scripts/fix-claim-columns.js +124 -0
- package/scripts/fix-constraint-now.js +44 -0
- package/scripts/fix-lock-timestamps.js +96 -0
- package/scripts/fix-locked-round.sh +126 -0
- package/scripts/fix-missing-badges.sql +91 -0
- package/scripts/fix-payment-notifications.sql +41 -0
- package/scripts/force-new-round.js +55 -0
- package/scripts/force-resolve-and-claim.js +278 -0
- package/scripts/important/README.md +115 -0
- package/scripts/important/authority-force-lock.js +197 -0
- package/scripts/important/authority-resolve-game.js +267 -0
- package/scripts/important/check-game-status.js +373 -0
- package/scripts/important/list-pending-games-by-version.js +270 -0
- package/scripts/important/reconcile-v1-v2-payouts.js +270 -0
- package/scripts/initialize-jackpot.js +111 -0
- package/scripts/jackpot/.claude/settings.local.json +10 -0
- package/scripts/jackpot/force-reset.js +84 -0
- package/scripts/jackpot/initialize-mainnet.js +100 -0
- package/scripts/jackpot/keeper.js +742 -0
- package/scripts/jackpot/status.js +107 -0
- package/scripts/jackpot/update-round-duration.js +143 -0
- package/scripts/keeper-bot.js +112 -0
- package/scripts/list-pending-games.js +131 -0
- package/scripts/migrate-chat-v2.js +127 -0
- package/scripts/migrate-chat-winners.js +84 -0
- package/scripts/migrate-chat.sh +17 -0
- package/scripts/migrate-game-invite.js +83 -0
- package/scripts/migrate-heroku-game-notifications.sh +159 -0
- package/scripts/migrations/001_analytics_tables.sql +422 -0
- package/scripts/migrations/002_add_matchup_image_url.sql +14 -0
- package/scripts/migrations/003_referral_earnings.sql +208 -0
- package/scripts/migrations/004_add_whats_new_notification_type.sql +62 -0
- package/scripts/migrations/005_add_connect4_your_turn_notification.sql +61 -0
- package/scripts/migrations/005_push_notifications.sql +55 -0
- package/scripts/migrations/006_add_draw_team_players.sql +28 -0
- package/scripts/migrations/006_add_game_cancelled_notification.sql +62 -0
- package/scripts/migrations/007_add_gif_url.sql +8 -0
- package/scripts/migrations/008_add_connect4_columns.sql +139 -0
- package/scripts/migrations/008_add_pool_tracking.sql +22 -0
- package/scripts/migrations/009_create_survivor_pool_tables.sql +174 -0
- package/scripts/migrations/010_add_survivor_pool_outcome.sql +28 -0
- package/scripts/migrations/011_create_developer_tables.sql +67 -0
- package/scripts/migrations/011_fix_keeper_tables.sql +85 -0
- package/scripts/migrations/012_create_developer_webhooks.sql +31 -0
- package/scripts/migrations/013_add_network_mode.sql +18 -0
- package/scripts/migrations/014_create_developer_app_users.sql +19 -0
- package/scripts/migrations/015_add_ui_config.sql +4 -0
- package/scripts/migrations/016_add_resolution_secret.sql +4 -0
- package/scripts/migrations/017_add_external_game_id.sql +3 -0
- package/scripts/migrations/018_create_pickem_tables.sql +115 -0
- package/scripts/migrations/019_expo_push_tokens.sql +19 -0
- package/scripts/migrations/create_whats_new_tables.sql +88 -0
- package/scripts/migrations/drop_live_games_tables.sql +34 -0
- package/scripts/open-jackpot-round.js +85 -0
- package/scripts/purge-all-data.sh +329 -0
- package/scripts/purge-all-data.sql +142 -0
- package/scripts/purge-heroku-data.sh +149 -0
- package/scripts/purge-heroku-data.sql +62 -0
- package/scripts/rebuild-heroku-database.sh +113 -0
- package/scripts/recover-funds.js +357 -0
- package/scripts/regenerate-epl-images.js +278 -0
- package/scripts/resize-s3-matchup-images.js +374 -0
- package/scripts/resolve-direct.js +88 -0
- package/scripts/resolve-mock-game.js +124 -0
- package/scripts/resolve-pickem-game.js +55 -0
- package/scripts/resolve-round-manual.js +83 -0
- package/scripts/resolve-stuck-game.js +382 -0
- package/scripts/resolve-stuck-round.js +42 -0
- package/scripts/run-connect4-migration.sh +16 -0
- package/scripts/run-mention-migration.sh +32 -0
- package/scripts/run-payment-migration.sh +51 -0
- package/scripts/run-preferred-currency-migration.sh +31 -0
- package/scripts/run-referral-earnings-migration.sh +32 -0
- package/scripts/run-survivor-outcome-migration.sh +16 -0
- package/scripts/seed-test-users.js +346 -0
- package/scripts/setup-auth-tables.js +78 -0
- package/scripts/setup-complete-database.sql +992 -0
- package/scripts/setup-database-fresh.sh +359 -0
- package/scripts/setup-heroku-keeper.sh +48 -0
- package/scripts/setup-keeper-database.js +83 -0
- package/scripts/setup-keeper-state-db.sql +110 -0
- package/scripts/setup-oracle.sh +39 -0
- package/scripts/setup-pnl-tracking.js +111 -0
- package/scripts/start-devnet.sh +14 -0
- package/scripts/test-arcade-devnet.sh +160 -0
- package/scripts/test-arcade-match.sh +109 -0
- package/scripts/test-automatic-mode.sh +239 -0
- package/scripts/test-connect4-cancel-claim.js +370 -0
- package/scripts/test-connect4-e2e.js +369 -0
- package/scripts/test-connect4-resolve.js +369 -0
- package/scripts/test-game-state-endpoint.js +136 -0
- package/scripts/test-invite-notification.js +86 -0
- package/scripts/test-jackpot-api.sh +71 -0
- package/scripts/test-poll-confirmation.js +267 -0
- package/scripts/test-resolve-game.js +271 -0
- package/scripts/test-resolve-signature.js +223 -0
- package/scripts/test-signature-preservation.js +124 -0
- package/scripts/test-state-machine.js +291 -0
- package/scripts/test-webhook-receiver.js +60 -0
- package/scripts/update-notification-constraint.js +52 -0
- package/scripts/verify-account-layout.js +145 -0
- package/scripts/verify-winner-algorithm.js +278 -0
- package/server.js +5259 -0
- package/services/arcadeMatchService.js +763 -0
- package/services/automaticGameOracle.js +1596 -0
- package/services/chatService.js +1612 -0
- package/services/connect4GameService.js +1049 -0
- package/services/connect4NotificationService.js +374 -0
- package/services/cryptoPriceService.js +223 -0
- package/services/customGameResolver.js +260 -0
- package/services/db.js +79 -0
- package/services/directMessageService.js +389 -0
- package/services/discordNotifications.js +160 -0
- package/services/exchangeRateService.js +289 -0
- package/services/expoPushService.js +314 -0
- package/services/gamesCacheService.js +539 -0
- package/services/jackpotHistory.js +331 -0
- package/services/jackpotService.js +856 -0
- package/services/keeperStateService.js +355 -0
- package/services/matchupImageService.js +591 -0
- package/services/notificationCacheService.js +407 -0
- package/services/pickemOracle.js +440 -0
- package/services/playerStatsService.js +389 -0
- package/services/portfolioService.js +555 -0
- package/services/promoService.js +757 -0
- package/services/promoTreasuryService.js +239 -0
- package/services/pushNotifications.js +353 -0
- package/services/redisService.js +422 -0
- package/services/referralEarningsService.js +728 -0
- package/services/s3Service.js +396 -0
- package/services/socialService.js +1202 -0
- package/services/survivorOracle.js +469 -0
- package/services/survivorSimulator.js +475 -0
- package/services/telegramNotifications.js +461 -0
- package/services/userProfileStatsService.js +1185 -0
- package/services/whatsNewService.js +388 -0
- package/utils/urlHelper.js +95 -0
|
@@ -0,0 +1,593 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
# 🎮 Arcade Match API Documentation
|
|
4
|
+
|
|
5
|
+
Complete API reference for the Dubs Arcade Match system - head-to-head arcade game betting.
|
|
6
|
+
|
|
7
|
+
## Table of Contents
|
|
8
|
+
|
|
9
|
+
- [Overview](#overview)
|
|
10
|
+
- [Getting Started](#getting-started)
|
|
11
|
+
- [API Endpoints](#api-endpoints)
|
|
12
|
+
- [Match Lifecycle](#match-lifecycle)
|
|
13
|
+
- [Example Workflows](#example-workflows)
|
|
14
|
+
- [Error Handling](#error-handling)
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Overview
|
|
19
|
+
|
|
20
|
+
The Arcade Match API allows players to create and join head-to-head arcade game matches with stakes. Supports games like Asteroids and Snake with Best-of-1 or Best-of-3 formats.
|
|
21
|
+
|
|
22
|
+
### Key Features
|
|
23
|
+
|
|
24
|
+
- ✅ Create matches with SOL stakes
|
|
25
|
+
- ✅ Join existing matches
|
|
26
|
+
- ✅ Submit game scores
|
|
27
|
+
- ✅ Automated winner determination
|
|
28
|
+
- ✅ Operator fees (1%)
|
|
29
|
+
- ✅ Deadline-based match expiration
|
|
30
|
+
- ✅ Refunds for incomplete matches
|
|
31
|
+
|
|
32
|
+
### Program Details
|
|
33
|
+
|
|
34
|
+
- **Program ID**: `EiNzW28xL1a92m1i9T3MyRZqEEszMcVBtrYB3NkphwRq`
|
|
35
|
+
- **Operator Wallet**: `BVZXwZpfgyzTBdRFHohkHZppPHnAyqyctRsKy3vWfQib`
|
|
36
|
+
- **Operator Fee**: 1%
|
|
37
|
+
|
|
38
|
+
---
|
|
39
|
+
|
|
40
|
+
## Getting Started
|
|
41
|
+
|
|
42
|
+
### 1. Start the Arcade Server
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Standalone mode (port 3002)
|
|
46
|
+
node arcade-server.js
|
|
47
|
+
|
|
48
|
+
# Custom port
|
|
49
|
+
PORT=3003 node arcade-server.js
|
|
50
|
+
|
|
51
|
+
# With custom RPC
|
|
52
|
+
ARCADE_RPC_URL=https://api.devnet.solana.com node arcade-server.js
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### 2. Verify Server is Running
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
curl http://localhost:3002/arcade/health
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Expected response:
|
|
62
|
+
```json
|
|
63
|
+
{
|
|
64
|
+
"status": "healthy",
|
|
65
|
+
"service": "arcade-matches",
|
|
66
|
+
"programId": "EiNzW28xL1a92m1i9T3MyRZqEEszMcVBtrYB3NkphwRq",
|
|
67
|
+
"operatorWallet": "BVZXwZpfgyzTBdRFHohkHZppPHnAyqyctRsKy3vWfQib",
|
|
68
|
+
"timestamp": "2024-01-15T10:30:00.000Z"
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
---
|
|
73
|
+
|
|
74
|
+
## API Endpoints
|
|
75
|
+
|
|
76
|
+
### Base URL
|
|
77
|
+
```
|
|
78
|
+
http://localhost:3002/arcade
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
### Match Management
|
|
82
|
+
|
|
83
|
+
#### 1. Create Match
|
|
84
|
+
|
|
85
|
+
**POST** `/arcade/matches/create`
|
|
86
|
+
|
|
87
|
+
Create a new arcade match with a stake.
|
|
88
|
+
|
|
89
|
+
**Request Body:**
|
|
90
|
+
```json
|
|
91
|
+
{
|
|
92
|
+
"creatorName": "player1",
|
|
93
|
+
"stake": 100000000,
|
|
94
|
+
"gameType": "asteroids",
|
|
95
|
+
"matchType": "bestOf1",
|
|
96
|
+
"deadlineMinutes": 60
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Parameters:**
|
|
101
|
+
| Field | Type | Required | Description |
|
|
102
|
+
|-------|------|----------|-------------|
|
|
103
|
+
| creatorName | string | Yes | Player creating the match |
|
|
104
|
+
| stake | number | Yes | Stake amount in lamports (0.1 SOL = 100000000) |
|
|
105
|
+
| gameType | string | No | "asteroids" or "snake" (default: "asteroids") |
|
|
106
|
+
| matchType | string | No | "bestOf1" or "bestOf3" (default: "bestOf1") |
|
|
107
|
+
| deadlineMinutes | number | No | Minutes until match expires (default: 60) |
|
|
108
|
+
|
|
109
|
+
**Response:**
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"success": true,
|
|
113
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
114
|
+
"signature": "3x7ZK...",
|
|
115
|
+
"matchPDA": "DfXG...",
|
|
116
|
+
"creator": "7D47y...",
|
|
117
|
+
"stake": 100000000,
|
|
118
|
+
"gameType": "asteroids",
|
|
119
|
+
"matchType": "bestOf1",
|
|
120
|
+
"deadline": "2024-01-15T11:30:00.000Z"
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**cURL Example:**
|
|
125
|
+
```bash
|
|
126
|
+
curl -X POST http://localhost:3002/arcade/matches/create \
|
|
127
|
+
-H "Content-Type: application/json" \
|
|
128
|
+
-d '{
|
|
129
|
+
"creatorName": "alice",
|
|
130
|
+
"stake": 100000000,
|
|
131
|
+
"gameType": "asteroids",
|
|
132
|
+
"matchType": "bestOf1"
|
|
133
|
+
}'
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
#### 2. Join Match
|
|
139
|
+
|
|
140
|
+
**POST** `/arcade/matches/:matchId/join`
|
|
141
|
+
|
|
142
|
+
Join an existing match by matching the stake.
|
|
143
|
+
|
|
144
|
+
**Request Body:**
|
|
145
|
+
```json
|
|
146
|
+
{
|
|
147
|
+
"opponentName": "player2"
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
**Response:**
|
|
152
|
+
```json
|
|
153
|
+
{
|
|
154
|
+
"success": true,
|
|
155
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
156
|
+
"signature": "4y8AL...",
|
|
157
|
+
"opponent": "8FJdh..."
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
**cURL Example:**
|
|
162
|
+
```bash
|
|
163
|
+
curl -X POST http://localhost:3002/arcade/matches/550e8400-e29b-41d4-a716-446655440000/join \
|
|
164
|
+
-H "Content-Type: application/json" \
|
|
165
|
+
-d '{
|
|
166
|
+
"opponentName": "bob"
|
|
167
|
+
}'
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
---
|
|
171
|
+
|
|
172
|
+
#### 3. Submit Score
|
|
173
|
+
|
|
174
|
+
**POST** `/arcade/matches/:matchId/score`
|
|
175
|
+
|
|
176
|
+
Submit a game score for a round.
|
|
177
|
+
|
|
178
|
+
**Request Body:**
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"playerName": "player1",
|
|
182
|
+
"score": 15000,
|
|
183
|
+
"gameRound": 1
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
**Parameters:**
|
|
188
|
+
| Field | Type | Required | Description |
|
|
189
|
+
|-------|------|----------|-------------|
|
|
190
|
+
| playerName | string | Yes | Player submitting score |
|
|
191
|
+
| score | number | Yes | Game score (0 or higher) |
|
|
192
|
+
| gameRound | number | No | Round number (1-3, default: 1) |
|
|
193
|
+
|
|
194
|
+
**Response:**
|
|
195
|
+
```json
|
|
196
|
+
{
|
|
197
|
+
"success": true,
|
|
198
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
199
|
+
"signature": "5z9BM...",
|
|
200
|
+
"player": "7D47y...",
|
|
201
|
+
"score": 15000,
|
|
202
|
+
"gameRound": 1
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
**cURL Example:**
|
|
207
|
+
```bash
|
|
208
|
+
curl -X POST http://localhost:3002/arcade/matches/550e8400-e29b-41d4-a716-446655440000/score \
|
|
209
|
+
-H "Content-Type: application/json" \
|
|
210
|
+
-d '{
|
|
211
|
+
"playerName": "alice",
|
|
212
|
+
"score": 15000,
|
|
213
|
+
"gameRound": 1
|
|
214
|
+
}'
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
---
|
|
218
|
+
|
|
219
|
+
#### 4. Resolve Match
|
|
220
|
+
|
|
221
|
+
**POST** `/arcade/matches/:matchId/resolve`
|
|
222
|
+
|
|
223
|
+
Resolve the match and distribute winnings.
|
|
224
|
+
|
|
225
|
+
**Request Body:**
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"callerName": "player1"
|
|
229
|
+
}
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Response:**
|
|
233
|
+
```json
|
|
234
|
+
{
|
|
235
|
+
"success": true,
|
|
236
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
237
|
+
"signature": "6A0CN..."
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**cURL Example:**
|
|
242
|
+
```bash
|
|
243
|
+
curl -X POST http://localhost:3002/arcade/matches/550e8400-e29b-41d4-a716-446655440000/resolve \
|
|
244
|
+
-H "Content-Type: application/json" \
|
|
245
|
+
-d '{
|
|
246
|
+
"callerName": "alice"
|
|
247
|
+
}'
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
#### 5. Cancel Match
|
|
253
|
+
|
|
254
|
+
**POST** `/arcade/matches/:matchId/cancel`
|
|
255
|
+
|
|
256
|
+
Cancel a match if no opponent joined (after deadline).
|
|
257
|
+
|
|
258
|
+
**Request Body:**
|
|
259
|
+
```json
|
|
260
|
+
{
|
|
261
|
+
"creatorName": "player1"
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
**Response:**
|
|
266
|
+
```json
|
|
267
|
+
{
|
|
268
|
+
"success": true,
|
|
269
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
270
|
+
"signature": "7B1DO..."
|
|
271
|
+
}
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
**cURL Example:**
|
|
275
|
+
```bash
|
|
276
|
+
curl -X POST http://localhost:3002/arcade/matches/550e8400-e29b-41d4-a716-446655440000/cancel \
|
|
277
|
+
-H "Content-Type: application/json" \
|
|
278
|
+
-d '{
|
|
279
|
+
"creatorName": "alice"
|
|
280
|
+
}'
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
#### 6. Get Match Data
|
|
286
|
+
|
|
287
|
+
**GET** `/arcade/matches/:matchId`
|
|
288
|
+
|
|
289
|
+
Retrieve match information from the blockchain.
|
|
290
|
+
|
|
291
|
+
**Response:**
|
|
292
|
+
```json
|
|
293
|
+
{
|
|
294
|
+
"success": true,
|
|
295
|
+
"match": {
|
|
296
|
+
"matchId": "550e8400-e29b-41d4-a716-446655440000",
|
|
297
|
+
"pda": "DfXG...",
|
|
298
|
+
"exists": true,
|
|
299
|
+
"lamports": 200000000
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
**cURL Example:**
|
|
305
|
+
```bash
|
|
306
|
+
curl http://localhost:3002/arcade/matches/550e8400-e29b-41d4-a716-446655440000
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
---
|
|
310
|
+
|
|
311
|
+
### Wallet Operations
|
|
312
|
+
|
|
313
|
+
#### 7. Airdrop SOL
|
|
314
|
+
|
|
315
|
+
**POST** `/arcade/wallet/airdrop`
|
|
316
|
+
|
|
317
|
+
Airdrop SOL to a wallet (localnet/devnet only).
|
|
318
|
+
|
|
319
|
+
**Request Body:**
|
|
320
|
+
```json
|
|
321
|
+
{
|
|
322
|
+
"playerName": "player1",
|
|
323
|
+
"amount": 2
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
**Response:**
|
|
328
|
+
```json
|
|
329
|
+
{
|
|
330
|
+
"success": true,
|
|
331
|
+
"player": "player1",
|
|
332
|
+
"pubkey": "7D47y...",
|
|
333
|
+
"amount": 2,
|
|
334
|
+
"signature": "8C2EP..."
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**cURL Example:**
|
|
339
|
+
```bash
|
|
340
|
+
curl -X POST http://localhost:3002/arcade/wallet/airdrop \
|
|
341
|
+
-H "Content-Type: application/json" \
|
|
342
|
+
-d '{
|
|
343
|
+
"playerName": "alice",
|
|
344
|
+
"amount": 2
|
|
345
|
+
}'
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
---
|
|
349
|
+
|
|
350
|
+
#### 8. Get Balance
|
|
351
|
+
|
|
352
|
+
**GET** `/arcade/wallet/:playerName/balance`
|
|
353
|
+
|
|
354
|
+
Get a player's wallet balance.
|
|
355
|
+
|
|
356
|
+
**Response:**
|
|
357
|
+
```json
|
|
358
|
+
{
|
|
359
|
+
"success": true,
|
|
360
|
+
"player": "player1",
|
|
361
|
+
"pubkey": "7D47y...",
|
|
362
|
+
"balance": 1.95,
|
|
363
|
+
"lamports": 1950000000
|
|
364
|
+
}
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
**cURL Example:**
|
|
368
|
+
```bash
|
|
369
|
+
curl http://localhost:3002/arcade/wallet/alice/balance
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
---
|
|
373
|
+
|
|
374
|
+
## Match Lifecycle
|
|
375
|
+
|
|
376
|
+
### Phase 1: Match Creation
|
|
377
|
+
1. Player A creates match with stake (e.g., 0.1 SOL)
|
|
378
|
+
2. Match status: **Waiting for Opponent**
|
|
379
|
+
3. Deadline set (e.g., 60 minutes)
|
|
380
|
+
|
|
381
|
+
### Phase 2: Opponent Joins
|
|
382
|
+
1. Player B joins and matches stake
|
|
383
|
+
2. Match status: **Active**
|
|
384
|
+
3. Deadline extended for gameplay (e.g., +1 hour)
|
|
385
|
+
|
|
386
|
+
### Phase 3: Score Submission
|
|
387
|
+
1. Both players play the game
|
|
388
|
+
2. Players submit scores for each round
|
|
389
|
+
3. System tracks scores on-chain
|
|
390
|
+
|
|
391
|
+
### Phase 4: Resolution
|
|
392
|
+
1. When all scores submitted, match can be resolved
|
|
393
|
+
2. Winner determined by:
|
|
394
|
+
- **Best-of-1**: Highest single score
|
|
395
|
+
- **Best-of-3**: Best 2 out of 3 rounds
|
|
396
|
+
3. Operator fee (1%) deducted
|
|
397
|
+
4. Winner receives prize pool
|
|
398
|
+
|
|
399
|
+
### Alternative: Deadline Expiry
|
|
400
|
+
- If deadline passes without all scores:
|
|
401
|
+
- Both players get refunded
|
|
402
|
+
- No operator fee charged
|
|
403
|
+
- Match status: **Cancelled**
|
|
404
|
+
|
|
405
|
+
---
|
|
406
|
+
|
|
407
|
+
## Example Workflows
|
|
408
|
+
|
|
409
|
+
### Example 1: Complete Best-of-1 Match
|
|
410
|
+
|
|
411
|
+
```bash
|
|
412
|
+
# Step 1: Fund wallets
|
|
413
|
+
curl -X POST http://localhost:3002/arcade/wallet/airdrop \
|
|
414
|
+
-H "Content-Type: application/json" \
|
|
415
|
+
-d '{"playerName": "alice", "amount": 2}'
|
|
416
|
+
|
|
417
|
+
curl -X POST http://localhost:3002/arcade/wallet/airdrop \
|
|
418
|
+
-H "Content-Type: application/json" \
|
|
419
|
+
-d '{"playerName": "bob", "amount": 2}'
|
|
420
|
+
|
|
421
|
+
# Step 2: Alice creates match (0.1 SOL stake)
|
|
422
|
+
curl -X POST http://localhost:3002/arcade/matches/create \
|
|
423
|
+
-H "Content-Type: application/json" \
|
|
424
|
+
-d '{
|
|
425
|
+
"creatorName": "alice",
|
|
426
|
+
"stake": 100000000,
|
|
427
|
+
"gameType": "asteroids",
|
|
428
|
+
"matchType": "bestOf1"
|
|
429
|
+
}'
|
|
430
|
+
# Save the matchId from response
|
|
431
|
+
|
|
432
|
+
# Step 3: Bob joins match
|
|
433
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/join \
|
|
434
|
+
-H "Content-Type: application/json" \
|
|
435
|
+
-d '{"opponentName": "bob"}'
|
|
436
|
+
|
|
437
|
+
# Step 4: Alice submits score
|
|
438
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
439
|
+
-H "Content-Type: application/json" \
|
|
440
|
+
-d '{
|
|
441
|
+
"playerName": "alice",
|
|
442
|
+
"score": 15000,
|
|
443
|
+
"gameRound": 1
|
|
444
|
+
}'
|
|
445
|
+
|
|
446
|
+
# Step 5: Bob submits score
|
|
447
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
448
|
+
-H "Content-Type: application/json" \
|
|
449
|
+
-d '{
|
|
450
|
+
"playerName": "bob",
|
|
451
|
+
"score": 12000,
|
|
452
|
+
"gameRound": 1
|
|
453
|
+
}'
|
|
454
|
+
|
|
455
|
+
# Step 6: Resolve match (Alice wins!)
|
|
456
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/resolve \
|
|
457
|
+
-H "Content-Type: application/json" \
|
|
458
|
+
-d '{"callerName": "alice"}'
|
|
459
|
+
|
|
460
|
+
# Step 7: Check balances
|
|
461
|
+
curl http://localhost:3002/arcade/wallet/alice/balance
|
|
462
|
+
curl http://localhost:3002/arcade/wallet/bob/balance
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
---
|
|
466
|
+
|
|
467
|
+
### Example 2: Best-of-3 Match
|
|
468
|
+
|
|
469
|
+
```bash
|
|
470
|
+
# Create and join match (same as above, but matchType: "bestOf3")
|
|
471
|
+
|
|
472
|
+
# Round 1: Alice wins
|
|
473
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
474
|
+
-d '{"playerName": "alice", "score": 15000, "gameRound": 1}'
|
|
475
|
+
|
|
476
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
477
|
+
-d '{"playerName": "bob", "score": 12000, "gameRound": 1}'
|
|
478
|
+
|
|
479
|
+
# Round 2: Bob wins
|
|
480
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
481
|
+
-d '{"playerName": "alice", "score": 10000, "gameRound": 2}'
|
|
482
|
+
|
|
483
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
484
|
+
-d '{"playerName": "bob", "score": 18000, "gameRound": 2}'
|
|
485
|
+
|
|
486
|
+
# Round 3: Alice wins (2-1)
|
|
487
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
488
|
+
-d '{"playerName": "alice", "score": 20000, "gameRound": 3}'
|
|
489
|
+
|
|
490
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/score \
|
|
491
|
+
-d '{"playerName": "bob", "score": 14000, "gameRound": 3}'
|
|
492
|
+
|
|
493
|
+
# Resolve match (Alice wins 2-1)
|
|
494
|
+
curl -X POST http://localhost:3002/arcade/matches/MATCH_ID/resolve \
|
|
495
|
+
-d '{"callerName": "alice"}'
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
---
|
|
499
|
+
|
|
500
|
+
## Error Handling
|
|
501
|
+
|
|
502
|
+
### Common Errors
|
|
503
|
+
|
|
504
|
+
#### 400 Bad Request
|
|
505
|
+
```json
|
|
506
|
+
{
|
|
507
|
+
"error": "Missing required fields: creatorName, stake"
|
|
508
|
+
}
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
**Causes:**
|
|
512
|
+
- Missing required parameters
|
|
513
|
+
- Invalid values (negative stakes, invalid game types, etc.)
|
|
514
|
+
|
|
515
|
+
---
|
|
516
|
+
|
|
517
|
+
#### 404 Not Found
|
|
518
|
+
```json
|
|
519
|
+
{
|
|
520
|
+
"error": "Match not found"
|
|
521
|
+
}
|
|
522
|
+
```
|
|
523
|
+
|
|
524
|
+
**Causes:**
|
|
525
|
+
- Invalid match ID
|
|
526
|
+
- Match hasn't been created yet
|
|
527
|
+
|
|
528
|
+
---
|
|
529
|
+
|
|
530
|
+
#### 500 Internal Server Error
|
|
531
|
+
```json
|
|
532
|
+
{
|
|
533
|
+
"error": "Failed to create match"
|
|
534
|
+
}
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
**Causes:**
|
|
538
|
+
- Blockchain transaction failure
|
|
539
|
+
- Insufficient funds
|
|
540
|
+
- Program constraint violation (e.g., deadline too short, duplicate score submission)
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
## Configuration
|
|
545
|
+
|
|
546
|
+
### Environment Variables
|
|
547
|
+
|
|
548
|
+
```bash
|
|
549
|
+
# Solana RPC URL
|
|
550
|
+
ARCADE_RPC_URL=http://127.0.0.1:8899
|
|
551
|
+
|
|
552
|
+
# Server port
|
|
553
|
+
ARCADE_PORT=3002
|
|
554
|
+
|
|
555
|
+
# Solana network (fallback if ARCADE_RPC_URL not set)
|
|
556
|
+
SOLANA_NETWORK=http://127.0.0.1:8899
|
|
557
|
+
|
|
558
|
+
# General port (fallback)
|
|
559
|
+
PORT=3002
|
|
560
|
+
```
|
|
561
|
+
|
|
562
|
+
---
|
|
563
|
+
|
|
564
|
+
## Integration with Main Server
|
|
565
|
+
|
|
566
|
+
To integrate arcade routes with the main dubs-server:
|
|
567
|
+
|
|
568
|
+
```javascript
|
|
569
|
+
// In server.js
|
|
570
|
+
const ArcadeMatchService = require('./services/arcadeMatchService');
|
|
571
|
+
const arcadeRoutes = require('./routes/arcadeRoutes');
|
|
572
|
+
|
|
573
|
+
const arcadeService = new ArcadeMatchService({
|
|
574
|
+
rpcUrl: RPC_URL,
|
|
575
|
+
walletsDir: WALLETS_DIR,
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
app.use('/arcade', arcadeRoutes(arcadeService));
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
---
|
|
582
|
+
|
|
583
|
+
## Support
|
|
584
|
+
|
|
585
|
+
For issues or questions:
|
|
586
|
+
- Check the main README.md
|
|
587
|
+
- Review the Arcade Program documentation: `docs/ARCADE_MATCH_SYSTEM.md`
|
|
588
|
+
- Contact the development team
|
|
589
|
+
|
|
590
|
+
---
|
|
591
|
+
|
|
592
|
+
**🎮 Happy Gaming!**
|
|
593
|
+
|