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.
Files changed (304) hide show
  1. package/.claude/settings.local.json +280 -0
  2. package/CLAUDE.md +46 -0
  3. package/CONNECT4_PRODUCTION_DEPLOY.md +155 -0
  4. package/CURRENT_SESSION.md +171 -0
  5. package/CURRENT_SESSION_DRAW.md +516 -0
  6. package/MARCH_MADNESS_SURVIVOR.md +254 -0
  7. package/PANDA.md +166 -0
  8. package/Procfile +4 -0
  9. package/README.md +476 -0
  10. package/controllers/livescoresController.js +376 -0
  11. package/controllers/pickemController.js +554 -0
  12. package/controllers/survivorAdminController.js +887 -0
  13. package/controllers/survivorController.js +623 -0
  14. package/cron/oracleMonitor.js +77 -0
  15. package/cron/pickemOracleMonitor.js +73 -0
  16. package/data/jackpot-history.json +952 -0
  17. package/data/ncaaTeams.js +406 -0
  18. package/documentation/API_SECURITY_GUIDE.md +327 -0
  19. package/documentation/ARCADE_API.md +593 -0
  20. package/documentation/ARCADE_IMPLEMENTATION_SUMMARY.md +399 -0
  21. package/documentation/ARCADE_QUICKSTART.md +242 -0
  22. package/documentation/AUTOMATIC_MODE_ORACLE.md +321 -0
  23. package/documentation/BUG_FIX_COHORT_DATE_DISPLAY.md +171 -0
  24. package/documentation/CLAIM_MIGRATION_INSTRUCTIONS.md +52 -0
  25. package/documentation/CLAIM_STATUS_FIX.md +67 -0
  26. package/documentation/CLI_TOOL_GUIDE.md +372 -0
  27. package/documentation/COHORT_RETENTION_ANALYSIS.md +295 -0
  28. package/documentation/COHORT_RETENTION_IMPLEMENTATION_COMPLETE.md +461 -0
  29. package/documentation/COHORT_RETENTION_SUMMARY.md +204 -0
  30. package/documentation/COMPLETE_PROJECT_SUMMARY.md +490 -0
  31. package/documentation/DATABASE_QUERIES.md +269 -0
  32. package/documentation/DATABASE_RETENTION_POLICY.md +390 -0
  33. package/documentation/DATABASE_SETUP_GUIDE.md +361 -0
  34. package/documentation/DATABASE_SETUP_SUMMARY.md +247 -0
  35. package/documentation/DEMO_API_CURL_COMMANDS.md +656 -0
  36. package/documentation/DEPLOYMENT_SUMMARY.txt +100 -0
  37. package/documentation/DUPLICATE_NOTIFICATIONS_FIXED.md +201 -0
  38. package/documentation/EXCHANGE_RATES_INTEGRATION.md +371 -0
  39. package/documentation/FINAL_API_PROTECTION_TABLE.md +175 -0
  40. package/documentation/GAME_START_NOTIFICATIONS_DEPLOYMENT.md +256 -0
  41. package/documentation/GAME_START_NOTIFICATIONS_INTEGRATION.md +275 -0
  42. package/documentation/HEROKU_DEPLOYMENT.md +134 -0
  43. package/documentation/HEROKU_SCHEDULER_SETUP.md +271 -0
  44. package/documentation/JACKPOT_API.md +521 -0
  45. package/documentation/JACKPOT_DEPLOYMENT_GUIDE.md +362 -0
  46. package/documentation/JWT_IMPLEMENTATION_SUMMARY.md +373 -0
  47. package/documentation/JWT_QUICK_SETUP.md +268 -0
  48. package/documentation/JWT_TESTING_GUIDE.md +404 -0
  49. package/documentation/KEEPER_RECOVERY_GUIDE.md +381 -0
  50. package/documentation/KEEPER_SETUP.md +206 -0
  51. package/documentation/KEEPER_STATE_MACHINE.md +423 -0
  52. package/documentation/LATEST_PRODUCTION_SETUP.md +387 -0
  53. package/documentation/LOCAL_VOTING_TEST.md +279 -0
  54. package/documentation/ORACLE_FIXES_SUMMARY.md +188 -0
  55. package/documentation/ORACLE_POSTGRESQL_UPDATE.md +202 -0
  56. package/documentation/PAYMENT_DEPLOYMENT.md +209 -0
  57. package/documentation/PNL_TRACKING_SETUP.md +189 -0
  58. package/documentation/PREVENTING_LOCKUP_ERRORS.md +472 -0
  59. package/documentation/PRODUCTION_READY_SUMMARY.md +227 -0
  60. package/documentation/PUBLIC_VS_PRIVATE_ENDPOINTS.md +278 -0
  61. package/documentation/QUICK_AUTH_SETUP.md +99 -0
  62. package/documentation/QUICK_DEPLOY.md +224 -0
  63. package/documentation/QUICK_FIX.md +114 -0
  64. package/documentation/QUICK_START.md +152 -0
  65. package/documentation/REFEREE_MODE_GUIDE.md +392 -0
  66. package/documentation/RETENTION_CORE_ACTION_UPDATE.md +313 -0
  67. package/documentation/RETENTION_UPDATE_SUMMARY.md +108 -0
  68. package/documentation/RUN_MIGRATION_NOW.md +39 -0
  69. package/documentation/SCRIPTS_UPDATE_SUMMARY.md +251 -0
  70. package/documentation/SETUP_GUIDE.md +184 -0
  71. package/documentation/STATE_MACHINE_IMPLEMENTATION.md +250 -0
  72. package/documentation/TELEGRAM_NOTIFICATIONS_DIAGNOSIS.md +361 -0
  73. package/documentation/UNIFIED_ARCHITECTURE.md +231 -0
  74. package/documentation/VOTING_DEPLOYMENT_SUMMARY.md +392 -0
  75. package/documentation/WEBSOCKET_ARCHITECTURE.md +881 -0
  76. package/documentation/WHAT_WE_BUILT_TODAY.md +369 -0
  77. package/documentation/latest/LATEST_PRODUCTION_SETUP.md +865 -0
  78. package/ecosystem.config.js +65 -0
  79. package/env.template +125 -0
  80. package/middleware/apiKeyAuth.js +136 -0
  81. package/middleware/authenticate.js +214 -0
  82. package/middleware/developerUserAuth.js +76 -0
  83. package/middleware/socketAuth.js +69 -0
  84. package/package.json +49 -0
  85. package/postman/Dubs-API-v1-With-Voting.postman_collection.json +555 -0
  86. package/postman/Dubs-API-v1.postman_collection.json +205 -0
  87. package/postman/Dubs_Developer_API.postman_collection.json +662 -0
  88. package/postman/QUICKSTART.md +118 -0
  89. package/postman/QUICK_REFERENCE.md +246 -0
  90. package/postman/README.md +71 -0
  91. package/postman/VOTING_API_GUIDE.md +426 -0
  92. package/refactor/Animations.md +148 -0
  93. package/refactor/Chat.md +252 -0
  94. package/routes/actionsRoutes.js +699 -0
  95. package/routes/adminRoutes.js +370 -0
  96. package/routes/analyticsRoutes.js +1262 -0
  97. package/routes/arcadeRoutes.js +557 -0
  98. package/routes/authRoutes.js +2310 -0
  99. package/routes/avatarRoutes.js +85 -0
  100. package/routes/botRoutes.js +211 -0
  101. package/routes/chatRoutes.js +377 -0
  102. package/routes/cryptoPriceRoutes.js +105 -0
  103. package/routes/developerRoutes.js +4201 -0
  104. package/routes/deviceRoutes.js +214 -0
  105. package/routes/dmRoutes.js +167 -0
  106. package/routes/esportsRoutes.js +806 -0
  107. package/routes/exchangeRateRoutes.js +233 -0
  108. package/routes/gamesRoutes.js +3028 -0
  109. package/routes/jackpotRoutes.js +754 -0
  110. package/routes/keeperMonitoringRoutes.js +156 -0
  111. package/routes/keeperWebhookRoutes.js +466 -0
  112. package/routes/livescoresRoutes.js +31 -0
  113. package/routes/pickemAdminRoutes.js +199 -0
  114. package/routes/pickemRoutes.js +231 -0
  115. package/routes/playerStatsRoutes.js +147 -0
  116. package/routes/portfolioRoutes.js +217 -0
  117. package/routes/promoRoutes.js +418 -0
  118. package/routes/referralEarningsRoutes.js +392 -0
  119. package/routes/socialRoutes.js +459 -0
  120. package/routes/sportsRoutes.js +1271 -0
  121. package/routes/survivorAdminRoutes.js +345 -0
  122. package/routes/survivorRoutes.js +756 -0
  123. package/routes/uploadRoutes.js +256 -0
  124. package/routes/userProfileRoutes.js +244 -0
  125. package/routes/whatsNewRoutes.js +331 -0
  126. package/scripts/.claude/settings.local.json +15 -0
  127. package/scripts/README.md +170 -0
  128. package/scripts/RESTART_EVERYTHING.sh +104 -0
  129. package/scripts/add-claim-columns.sql +48 -0
  130. package/scripts/add-crypto-prices-cache.sql +27 -0
  131. package/scripts/add-exchange-rates-cache.sql +40 -0
  132. package/scripts/add-game-invite-column.sql +23 -0
  133. package/scripts/add-game-invite-notification.sql +33 -0
  134. package/scripts/add-game-invite-telegram-pref.sql +16 -0
  135. package/scripts/add-game-joined-notification.sql +16 -0
  136. package/scripts/add-game-joined-pref.js +40 -0
  137. package/scripts/add-game-joined-preference.sql +6 -0
  138. package/scripts/add-game-start-notifications.sql +41 -0
  139. package/scripts/add-notification-flags-to-games.sql +55 -0
  140. package/scripts/add-pending-game-dismissals.sql +19 -0
  141. package/scripts/add-preferred-currency.sql +34 -0
  142. package/scripts/add-winner-columns.js +61 -0
  143. package/scripts/add_mention_system.sql +53 -0
  144. package/scripts/add_payment_system.sql +96 -0
  145. package/scripts/add_sports_event_id_column.sql +22 -0
  146. package/scripts/analyze-cohort-data-heroku.js +276 -0
  147. package/scripts/analyze-cohort-data.js +295 -0
  148. package/scripts/analyze-prod-cohorts.sh +10 -0
  149. package/scripts/backfill-matchup-images.js +245 -0
  150. package/scripts/backfill-missing-signatures.js +175 -0
  151. package/scripts/backfill-referral-earnings.js +202 -0
  152. package/scripts/check-chat-schema.js +130 -0
  153. package/scripts/check-db.sh +14 -0
  154. package/scripts/check_oracle_in_game.js +54 -0
  155. package/scripts/cleanup-database.js +193 -0
  156. package/scripts/clear-notification-cache.js +85 -0
  157. package/scripts/convert-mnemonic.js +50 -0
  158. package/scripts/create-users-table.sql +44 -0
  159. package/scripts/debug-cohort-counts.js +248 -0
  160. package/scripts/debug-winner-calc.js +84 -0
  161. package/scripts/deploy-payment-system.sh +118 -0
  162. package/scripts/deploy-to-heroku.sh +63 -0
  163. package/scripts/diagnose-locked-round.js +143 -0
  164. package/scripts/dubs-cli.js +720 -0
  165. package/scripts/dump-account.js +65 -0
  166. package/scripts/find-vrf-offset.js +48 -0
  167. package/scripts/fix-chat-notifications-constraint.sql +122 -0
  168. package/scripts/fix-claim-columns.js +124 -0
  169. package/scripts/fix-constraint-now.js +44 -0
  170. package/scripts/fix-lock-timestamps.js +96 -0
  171. package/scripts/fix-locked-round.sh +126 -0
  172. package/scripts/fix-missing-badges.sql +91 -0
  173. package/scripts/fix-payment-notifications.sql +41 -0
  174. package/scripts/force-new-round.js +55 -0
  175. package/scripts/force-resolve-and-claim.js +278 -0
  176. package/scripts/important/README.md +115 -0
  177. package/scripts/important/authority-force-lock.js +197 -0
  178. package/scripts/important/authority-resolve-game.js +267 -0
  179. package/scripts/important/check-game-status.js +373 -0
  180. package/scripts/important/list-pending-games-by-version.js +270 -0
  181. package/scripts/important/reconcile-v1-v2-payouts.js +270 -0
  182. package/scripts/initialize-jackpot.js +111 -0
  183. package/scripts/jackpot/.claude/settings.local.json +10 -0
  184. package/scripts/jackpot/force-reset.js +84 -0
  185. package/scripts/jackpot/initialize-mainnet.js +100 -0
  186. package/scripts/jackpot/keeper.js +742 -0
  187. package/scripts/jackpot/status.js +107 -0
  188. package/scripts/jackpot/update-round-duration.js +143 -0
  189. package/scripts/keeper-bot.js +112 -0
  190. package/scripts/list-pending-games.js +131 -0
  191. package/scripts/migrate-chat-v2.js +127 -0
  192. package/scripts/migrate-chat-winners.js +84 -0
  193. package/scripts/migrate-chat.sh +17 -0
  194. package/scripts/migrate-game-invite.js +83 -0
  195. package/scripts/migrate-heroku-game-notifications.sh +159 -0
  196. package/scripts/migrations/001_analytics_tables.sql +422 -0
  197. package/scripts/migrations/002_add_matchup_image_url.sql +14 -0
  198. package/scripts/migrations/003_referral_earnings.sql +208 -0
  199. package/scripts/migrations/004_add_whats_new_notification_type.sql +62 -0
  200. package/scripts/migrations/005_add_connect4_your_turn_notification.sql +61 -0
  201. package/scripts/migrations/005_push_notifications.sql +55 -0
  202. package/scripts/migrations/006_add_draw_team_players.sql +28 -0
  203. package/scripts/migrations/006_add_game_cancelled_notification.sql +62 -0
  204. package/scripts/migrations/007_add_gif_url.sql +8 -0
  205. package/scripts/migrations/008_add_connect4_columns.sql +139 -0
  206. package/scripts/migrations/008_add_pool_tracking.sql +22 -0
  207. package/scripts/migrations/009_create_survivor_pool_tables.sql +174 -0
  208. package/scripts/migrations/010_add_survivor_pool_outcome.sql +28 -0
  209. package/scripts/migrations/011_create_developer_tables.sql +67 -0
  210. package/scripts/migrations/011_fix_keeper_tables.sql +85 -0
  211. package/scripts/migrations/012_create_developer_webhooks.sql +31 -0
  212. package/scripts/migrations/013_add_network_mode.sql +18 -0
  213. package/scripts/migrations/014_create_developer_app_users.sql +19 -0
  214. package/scripts/migrations/015_add_ui_config.sql +4 -0
  215. package/scripts/migrations/016_add_resolution_secret.sql +4 -0
  216. package/scripts/migrations/017_add_external_game_id.sql +3 -0
  217. package/scripts/migrations/018_create_pickem_tables.sql +115 -0
  218. package/scripts/migrations/019_expo_push_tokens.sql +19 -0
  219. package/scripts/migrations/create_whats_new_tables.sql +88 -0
  220. package/scripts/migrations/drop_live_games_tables.sql +34 -0
  221. package/scripts/open-jackpot-round.js +85 -0
  222. package/scripts/purge-all-data.sh +329 -0
  223. package/scripts/purge-all-data.sql +142 -0
  224. package/scripts/purge-heroku-data.sh +149 -0
  225. package/scripts/purge-heroku-data.sql +62 -0
  226. package/scripts/rebuild-heroku-database.sh +113 -0
  227. package/scripts/recover-funds.js +357 -0
  228. package/scripts/regenerate-epl-images.js +278 -0
  229. package/scripts/resize-s3-matchup-images.js +374 -0
  230. package/scripts/resolve-direct.js +88 -0
  231. package/scripts/resolve-mock-game.js +124 -0
  232. package/scripts/resolve-pickem-game.js +55 -0
  233. package/scripts/resolve-round-manual.js +83 -0
  234. package/scripts/resolve-stuck-game.js +382 -0
  235. package/scripts/resolve-stuck-round.js +42 -0
  236. package/scripts/run-connect4-migration.sh +16 -0
  237. package/scripts/run-mention-migration.sh +32 -0
  238. package/scripts/run-payment-migration.sh +51 -0
  239. package/scripts/run-preferred-currency-migration.sh +31 -0
  240. package/scripts/run-referral-earnings-migration.sh +32 -0
  241. package/scripts/run-survivor-outcome-migration.sh +16 -0
  242. package/scripts/seed-test-users.js +346 -0
  243. package/scripts/setup-auth-tables.js +78 -0
  244. package/scripts/setup-complete-database.sql +992 -0
  245. package/scripts/setup-database-fresh.sh +359 -0
  246. package/scripts/setup-heroku-keeper.sh +48 -0
  247. package/scripts/setup-keeper-database.js +83 -0
  248. package/scripts/setup-keeper-state-db.sql +110 -0
  249. package/scripts/setup-oracle.sh +39 -0
  250. package/scripts/setup-pnl-tracking.js +111 -0
  251. package/scripts/start-devnet.sh +14 -0
  252. package/scripts/test-arcade-devnet.sh +160 -0
  253. package/scripts/test-arcade-match.sh +109 -0
  254. package/scripts/test-automatic-mode.sh +239 -0
  255. package/scripts/test-connect4-cancel-claim.js +370 -0
  256. package/scripts/test-connect4-e2e.js +369 -0
  257. package/scripts/test-connect4-resolve.js +369 -0
  258. package/scripts/test-game-state-endpoint.js +136 -0
  259. package/scripts/test-invite-notification.js +86 -0
  260. package/scripts/test-jackpot-api.sh +71 -0
  261. package/scripts/test-poll-confirmation.js +267 -0
  262. package/scripts/test-resolve-game.js +271 -0
  263. package/scripts/test-resolve-signature.js +223 -0
  264. package/scripts/test-signature-preservation.js +124 -0
  265. package/scripts/test-state-machine.js +291 -0
  266. package/scripts/test-webhook-receiver.js +60 -0
  267. package/scripts/update-notification-constraint.js +52 -0
  268. package/scripts/verify-account-layout.js +145 -0
  269. package/scripts/verify-winner-algorithm.js +278 -0
  270. package/server.js +5259 -0
  271. package/services/arcadeMatchService.js +763 -0
  272. package/services/automaticGameOracle.js +1596 -0
  273. package/services/chatService.js +1612 -0
  274. package/services/connect4GameService.js +1049 -0
  275. package/services/connect4NotificationService.js +374 -0
  276. package/services/cryptoPriceService.js +223 -0
  277. package/services/customGameResolver.js +260 -0
  278. package/services/db.js +79 -0
  279. package/services/directMessageService.js +389 -0
  280. package/services/discordNotifications.js +160 -0
  281. package/services/exchangeRateService.js +289 -0
  282. package/services/expoPushService.js +314 -0
  283. package/services/gamesCacheService.js +539 -0
  284. package/services/jackpotHistory.js +331 -0
  285. package/services/jackpotService.js +856 -0
  286. package/services/keeperStateService.js +355 -0
  287. package/services/matchupImageService.js +591 -0
  288. package/services/notificationCacheService.js +407 -0
  289. package/services/pickemOracle.js +440 -0
  290. package/services/playerStatsService.js +389 -0
  291. package/services/portfolioService.js +555 -0
  292. package/services/promoService.js +757 -0
  293. package/services/promoTreasuryService.js +239 -0
  294. package/services/pushNotifications.js +353 -0
  295. package/services/redisService.js +422 -0
  296. package/services/referralEarningsService.js +728 -0
  297. package/services/s3Service.js +396 -0
  298. package/services/socialService.js +1202 -0
  299. package/services/survivorOracle.js +469 -0
  300. package/services/survivorSimulator.js +475 -0
  301. package/services/telegramNotifications.js +461 -0
  302. package/services/userProfileStatsService.js +1185 -0
  303. package/services/whatsNewService.js +388 -0
  304. package/utils/urlHelper.js +95 -0
@@ -0,0 +1,387 @@
1
+ # 🚀 DUBS Server Production Setup
2
+
3
+ **Created:** December 14, 2025
4
+ **Last Updated:** December 14, 2025
5
+
6
+ This document contains critical operational information for the `dubs-server-prod` Heroku application.
7
+
8
+ ---
9
+
10
+ ## 📋 Quick Reference
11
+
12
+ | Field | Value |
13
+ |-------|-------|
14
+ | **App Name** | `dubs-server-prod` |
15
+ | **Production URL** | https://dubs-server-prod-9c91d3f01199.herokuapp.com/ |
16
+ | **Git Remote** | `heroku-prod` |
17
+ | **Team** | dubs |
18
+ | **Region** | US |
19
+ | **Stack** | heroku-24 |
20
+
21
+ ---
22
+
23
+ ## 🖥️ Infrastructure
24
+
25
+ ### Dynos (Compute)
26
+
27
+ | Dyno | Type | Size | Purpose |
28
+ |------|------|------|---------|
29
+ | `web.1` | Standard-1X | 512MB RAM | Express.js API server |
30
+ | `oracle.1` | Standard-1X | 512MB RAM | Automatic game resolution oracle |
31
+
32
+ ### Database
33
+
34
+ | Field | Value |
35
+ |-------|-------|
36
+ | **Addon** | `postgresql-regular-65857` |
37
+ | **Plan** | Standard-0 |
38
+ | **Cost** | $50/month |
39
+ | **Storage** | 10GB |
40
+ | **Max Connections** | 200 |
41
+ | **Region** | US East (AWS) |
42
+
43
+ ---
44
+
45
+ ## 🗄️ Database Access
46
+
47
+ ### Connect via Heroku CLI (Recommended)
48
+
49
+ ```bash
50
+ # Interactive psql session
51
+ heroku pg:psql --app dubs-server-prod
52
+
53
+ # Run a single query
54
+ heroku pg:psql --app dubs-server-prod -c "SELECT COUNT(*) FROM users;"
55
+
56
+ # Run a SQL file
57
+ heroku pg:psql --app dubs-server-prod < scripts/some-migration.sql
58
+ ```
59
+
60
+ ### Get Connection String
61
+
62
+ ```bash
63
+ # View DATABASE_URL (contains credentials)
64
+ heroku config:get DATABASE_URL --app dubs-server-prod
65
+ ```
66
+
67
+ ### Connect with External Tools (pgAdmin, DBeaver, TablePlus)
68
+
69
+ ```bash
70
+ # Get connection info
71
+ heroku pg:credentials:url --app dubs-server-prod
72
+ ```
73
+
74
+ The output will give you:
75
+ - **Host**: `ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com`
76
+ - **Port**: `5432`
77
+ - **Database**: `d6jpka002e1ept`
78
+ - **User**: `uddg5sp8vh4l8g`
79
+ - **Password**: (shown in output)
80
+
81
+ ⚠️ **Important:** Heroku Postgres requires SSL. Set `sslmode=require` in your connection.
82
+
83
+ ### Database Backup & Restore
84
+
85
+ ```bash
86
+ # Create manual backup
87
+ heroku pg:backups:capture --app dubs-server-prod
88
+
89
+ # List backups
90
+ heroku pg:backups --app dubs-server-prod
91
+
92
+ # Download latest backup
93
+ heroku pg:backups:download --app dubs-server-prod
94
+
95
+ # Restore from backup
96
+ heroku pg:backups:restore b001 DATABASE_URL --app dubs-server-prod
97
+ ```
98
+
99
+ ### Database Maintenance
100
+
101
+ ```bash
102
+ # View database info
103
+ heroku pg:info --app dubs-server-prod
104
+
105
+ # View active connections
106
+ heroku pg:psql --app dubs-server-prod -c "SELECT * FROM pg_stat_activity WHERE datname = current_database();"
107
+
108
+ # Kill idle connections (if needed)
109
+ heroku pg:killall --app dubs-server-prod
110
+ ```
111
+
112
+ ---
113
+
114
+ ## ⚙️ Configuration Variables
115
+
116
+ ### Solana / Blockchain
117
+
118
+ | Variable | Value | Description |
119
+ |----------|-------|-------------|
120
+ | `PROGRAM_ID` | `85wJGp9uc8w2FeKX9CEHsudTo1UVCrmuRFy37oCcaoG1` | Mainnet program ID |
121
+ | `JACKPOT_PROGRAM_ID` | `85wJGp9uc8w2FeKX9CEHsudTo1UVCrmuRFy37oCcaoG1` | Same as PROGRAM_ID |
122
+ | `SOLANA_NETWORK` | `https://api.mainnet-beta.solana.com` | Mainnet RPC endpoint |
123
+ | `ORACLE_WALLET_JSON` | `[...]` | Oracle keypair (JSON array) |
124
+ | `KEEPER_PRIVATE_KEY` | `[...]` | Keeper keypair (JSON array) |
125
+
126
+ ### API Endpoints
127
+
128
+ | Variable | Value |
129
+ |----------|-------|
130
+ | `API_BASE_URL` | `https://dubs-server-prod-9c91d3f01199.herokuapp.com` |
131
+ | `DUBS_SERVER_URL` | `https://dubs-server-prod-9c91d3f01199.herokuapp.com` |
132
+ | `LIVE_SCORES_API_URL` | `https://dubs-api-prod-9e38ab6733f8.herokuapp.com` |
133
+ | `DUBS_GAMES_API_URL` | `https://dubs-games-api-prod-e41f330fdacc.herokuapp.com` |
134
+ | `TELEGRAM_BOT_URL` | `https://dubs-telegram-bot-eb6ad9ec87b7.herokuapp.com` |
135
+
136
+ ### Timing Configuration
137
+
138
+ | Variable | Value | Description |
139
+ |----------|-------|-------------|
140
+ | `ORACLE_CHECK_INTERVAL` | `60000` | Check games every 60 seconds |
141
+ | `LIVE_GAME_DISCOVERY_INTERVAL` | `60000` | Discover new games every 60 seconds |
142
+ | `LIVE_GAME_POLL_INTERVAL` | `5000` | Poll live scores every 5 seconds |
143
+ | `LIVE_GAME_STATS_INTERVAL` | `30000` | Update stats every 30 seconds |
144
+
145
+ ### View All Config
146
+
147
+ ```bash
148
+ heroku config --app dubs-server-prod
149
+ ```
150
+
151
+ ### Update Config
152
+
153
+ ```bash
154
+ # Set single variable
155
+ heroku config:set VARIABLE_NAME=value --app dubs-server-prod
156
+
157
+ # Set multiple variables
158
+ heroku config:set VAR1=value1 VAR2=value2 --app dubs-server-prod
159
+ ```
160
+
161
+ ---
162
+
163
+ ## 🚀 Deployment
164
+
165
+ ### Deploy from Local
166
+
167
+ ```bash
168
+ cd /path/to/dubs-server
169
+
170
+ # Deploy main branch to production
171
+ git push heroku-prod main
172
+
173
+ # Deploy specific branch
174
+ git push heroku-prod feature-branch:main
175
+ ```
176
+
177
+ ### Rollback
178
+
179
+ ```bash
180
+ # View releases
181
+ heroku releases --app dubs-server-prod
182
+
183
+ # Rollback to previous release
184
+ heroku rollback --app dubs-server-prod
185
+
186
+ # Rollback to specific version
187
+ heroku rollback v10 --app dubs-server-prod
188
+ ```
189
+
190
+ ---
191
+
192
+ ## 📊 Monitoring & Logs
193
+
194
+ ### View Logs
195
+
196
+ ```bash
197
+ # Tail all logs
198
+ heroku logs --tail --app dubs-server-prod
199
+
200
+ # View specific dyno logs
201
+ heroku logs --tail --dyno web.1 --app dubs-server-prod
202
+ heroku logs --tail --dyno oracle.1 --app dubs-server-prod
203
+
204
+ # View last N lines
205
+ heroku logs -n 500 --app dubs-server-prod
206
+
207
+ # Filter by source
208
+ heroku logs --source app --app dubs-server-prod
209
+ heroku logs --source heroku --app dubs-server-prod
210
+ ```
211
+
212
+ ### Check Dyno Status
213
+
214
+ ```bash
215
+ # View running dynos
216
+ heroku ps --app dubs-server-prod
217
+
218
+ # Restart all dynos
219
+ heroku restart --app dubs-server-prod
220
+
221
+ # Restart specific dyno
222
+ heroku restart web.1 --app dubs-server-prod
223
+ heroku restart oracle.1 --app dubs-server-prod
224
+ ```
225
+
226
+ ### Database Monitoring
227
+
228
+ ```bash
229
+ # View database metrics
230
+ heroku pg:info --app dubs-server-prod
231
+
232
+ # View slow queries (requires pg:diagnose)
233
+ heroku pg:diagnose --app dubs-server-prod
234
+
235
+ # View table sizes
236
+ heroku pg:psql --app dubs-server-prod -c "
237
+ SELECT
238
+ schemaname,
239
+ tablename,
240
+ pg_size_pretty(pg_total_relation_size(schemaname||'.'||tablename)) as size
241
+ FROM pg_tables
242
+ WHERE schemaname = 'public'
243
+ ORDER BY pg_total_relation_size(schemaname||'.'||tablename) DESC;
244
+ "
245
+ ```
246
+
247
+ ---
248
+
249
+ ## 🔐 Security Notes
250
+
251
+ ### Sensitive Variables
252
+
253
+ The following variables contain sensitive data - **NEVER commit to git**:
254
+
255
+ - `DATABASE_URL` - Database connection string with password
256
+ - `JWT_SECRET` - Token signing secret
257
+ - `ORACLE_WALLET_JSON` - Oracle private key
258
+ - `KEEPER_PRIVATE_KEY` - Keeper private key
259
+ - `TELEGRAM_BOT_TOKEN` - Bot authentication token
260
+ - `AWS_SECRET_ACCESS_KEY` - AWS S3 access
261
+
262
+ ### Oracle Wallet
263
+
264
+ The oracle wallet is stored in `ORACLE_WALLET_JSON` as a JSON array (Solana keypair format).
265
+
266
+ **Public Key:** `DU4CHEHUJ2EeezAXyfyi8vLB7dmXKq41myKnA5DZ9Mru`
267
+
268
+ This wallet is hardcoded in the Solana program and receives 0.2% oracle fees.
269
+
270
+ ---
271
+
272
+ ## 🔧 Maintenance Tasks
273
+
274
+ ### Run Database Migrations
275
+
276
+ ```bash
277
+ # Run complete schema setup
278
+ heroku pg:psql --app dubs-server-prod < scripts/setup-complete-database.sql
279
+
280
+ # Run specific migration
281
+ heroku pg:psql --app dubs-server-prod < scripts/add-preferred-currency.sql
282
+ ```
283
+
284
+ ### Scale Dynos
285
+
286
+ ```bash
287
+ # Scale up (more dynos or bigger size)
288
+ heroku ps:scale web=2:standard-2x --app dubs-server-prod
289
+
290
+ # Scale down
291
+ heroku ps:scale web=1:standard-1x --app dubs-server-prod
292
+
293
+ # Turn off oracle (if needed)
294
+ heroku ps:scale oracle=0 --app dubs-server-prod
295
+ ```
296
+
297
+ ### Run One-Off Commands
298
+
299
+ ```bash
300
+ # Run a script
301
+ heroku run node scripts/some-script.js --app dubs-server-prod
302
+
303
+ # Open a shell
304
+ heroku run bash --app dubs-server-prod
305
+ ```
306
+
307
+ ---
308
+
309
+ ## 🚨 Troubleshooting
310
+
311
+ ### App Not Responding
312
+
313
+ 1. Check dyno status: `heroku ps --app dubs-server-prod`
314
+ 2. Check logs: `heroku logs --tail --app dubs-server-prod`
315
+ 3. Restart: `heroku restart --app dubs-server-prod`
316
+
317
+ ### Database Connection Issues
318
+
319
+ 1. Check connection count: `heroku pg:info --app dubs-server-prod`
320
+ 2. Kill idle connections: `heroku pg:killall --app dubs-server-prod`
321
+ 3. Restart app: `heroku restart --app dubs-server-prod`
322
+
323
+ ### Oracle Not Resolving Games
324
+
325
+ 1. Check oracle logs: `heroku logs --tail --dyno oracle.1 --app dubs-server-prod`
326
+ 2. Verify `ORACLE_WALLET_JSON` is set correctly
327
+ 3. Check Solana RPC endpoint is responsive
328
+ 4. Verify oracle wallet has SOL for transaction fees
329
+
330
+ ### High Memory Usage
331
+
332
+ 1. Check metrics: `heroku ps --app dubs-server-prod`
333
+ 2. Scale to larger dyno: `heroku ps:scale web=1:standard-2x --app dubs-server-prod`
334
+
335
+ ---
336
+
337
+ ## 💰 Cost Summary
338
+
339
+ | Resource | Monthly Cost |
340
+ |----------|--------------|
341
+ | Postgres Standard-0 | $50 |
342
+ | Standard-1X Dyno (web) | ~$25 |
343
+ | Standard-1X Dyno (oracle) | ~$25 |
344
+ | **Total Estimated** | **~$100/month** |
345
+
346
+ ---
347
+
348
+ ## 🔗 Related Resources
349
+
350
+ - **Mainnet Deployment Docs:** `../dubs/docs/LATEST_MAINNET_DEPLOYMENT.md`
351
+ - **Program ID:** `85wJGp9uc8w2FeKX9CEHsudTo1UVCrmuRFy37oCcaoG1`
352
+ - **Solana Explorer:** https://explorer.solana.com/address/85wJGp9uc8w2FeKX9CEHsudTo1UVCrmuRFy37oCcaoG1
353
+
354
+ ---
355
+
356
+ ## 📞 Quick Commands Cheat Sheet
357
+
358
+ ```bash
359
+ # Logs
360
+ heroku logs --tail --app dubs-server-prod
361
+
362
+ # Restart
363
+ heroku restart --app dubs-server-prod
364
+
365
+ # Deploy
366
+ git push heroku-prod main
367
+
368
+ # Database shell
369
+ heroku pg:psql --app dubs-server-prod
370
+
371
+ # Config
372
+ heroku config --app dubs-server-prod
373
+
374
+ # Status
375
+ heroku ps --app dubs-server-prod
376
+
377
+ # Open in browser
378
+ heroku open --app dubs-server-prod
379
+ ```
380
+
381
+ ---
382
+
383
+ **Document maintained by:** Dubs Team
384
+ **For questions:** Check Heroku dashboard or logs first
385
+
386
+
387
+
@@ -0,0 +1,279 @@
1
+ # 🧪 LOCAL VOTING TEST - COMPLETE GUIDE
2
+
3
+ ## ✅ **Local Environment Running:**
4
+
5
+ ```
6
+ ✅ solana-test-validator → localhost:8899
7
+ ✅ Dubs program (with voting) → Deployed locally
8
+ ✅ dubs-server → http://localhost:3001
9
+ ```
10
+
11
+ ---
12
+
13
+ ## 🎮 **Complete Test Flow**
14
+
15
+ ### **Step 1: Create Game with Voting**
16
+ ```bash
17
+ POST http://localhost:3001/api/v1/demo/game/create
18
+
19
+ {
20
+ "player": "creator",
21
+ "buyIn": 0.5,
22
+ "maxPlayers": 3,
23
+ "operatorFee": 10
24
+ }
25
+
26
+ Response:
27
+ {
28
+ "success": true,
29
+ "gameId": "uuid-here", ← SAVE THIS!
30
+ "transaction": "signature",
31
+ "gameAddress": "PDA"
32
+ }
33
+ ```
34
+
35
+ ---
36
+
37
+ ### **Step 2: Players Join**
38
+ ```bash
39
+ # Alice joins
40
+ POST http://localhost:3001/api/v1/demo/game/join
41
+ {
42
+ "player": "alice",
43
+ "gameId": "SAVED_GAME_ID"
44
+ }
45
+
46
+ # Bob joins
47
+ POST http://localhost:3001/api/v1/demo/game/join
48
+ {
49
+ "player": "bob",
50
+ "gameId": "SAVED_GAME_ID"
51
+ }
52
+ ```
53
+
54
+ ---
55
+
56
+ ### **Step 3: Check Game State**
57
+ ```bash
58
+ GET http://localhost:3001/api/v1/demo/game/SAVED_GAME_ID
59
+
60
+ Response shows:
61
+ {
62
+ "game": {
63
+ "players": [
64
+ "CreatorAddress...",
65
+ "AliceAddress...",
66
+ "BobAddress..."
67
+ ],
68
+ "totalPot": 1.5,
69
+ "votes": [],
70
+ "votingEnabled": true ← Confirmed!
71
+ }
72
+ }
73
+ ```
74
+
75
+ **Copy the 3 player addresses from response!**
76
+
77
+ ---
78
+
79
+ ### **Step 4: Cast Votes** 🗳️
80
+ ```bash
81
+ # Creator votes for Alice
82
+ POST http://localhost:3001/api/v1/demo/vote/cast
83
+ {
84
+ "player": "creator",
85
+ "gameId": "SAVED_GAME_ID",
86
+ "votedFor": "ALICE_ADDRESS_FROM_GAME_INFO"
87
+ }
88
+
89
+ # Alice votes for Alice (vote for herself!)
90
+ POST http://localhost:3001/api/v1/demo/vote/cast
91
+ {
92
+ "player": "alice",
93
+ "gameId": "SAVED_GAME_ID",
94
+ "votedFor": "ALICE_ADDRESS_FROM_GAME_INFO"
95
+ }
96
+
97
+ Response:
98
+ {
99
+ "success": true,
100
+ "message": "alice voted for...",
101
+ "votesCount": 2,
102
+ "votingProgress": "2/3 votes" ← Majority reached!
103
+ }
104
+ ```
105
+
106
+ ---
107
+
108
+ ### **Step 5: Check Voting Results**
109
+ ```bash
110
+ GET http://localhost:3001/api/v1/demo/game/SAVED_GAME_ID
111
+
112
+ Response:
113
+ {
114
+ "game": {
115
+ "votes": [
116
+ {"voter": "Creator...", "votedFor": "Alice..."},
117
+ {"voter": "Alice...", "votedFor": "Alice..."}
118
+ ],
119
+ "votingEnabled": true
120
+ }
121
+ }
122
+
123
+ Alice has 2 votes! (Majority reached with 2/3 players!)
124
+ ```
125
+
126
+ ---
127
+
128
+ ### **Step 6: Distribute by Vote** 🏆
129
+ ```bash
130
+ POST http://localhost:3001/api/v1/demo/vote/distribute
131
+ {
132
+ "gameId": "SAVED_GAME_ID"
133
+ }
134
+
135
+ Response:
136
+ {
137
+ "success": true,
138
+ "message": "Winnings distributed by vote to 1 winners",
139
+ "transaction": "signature",
140
+ "winners": ["AliceAddress..."],
141
+ "voteCounts": {
142
+ "CreatorAddress": 0,
143
+ "AliceAddress": 2, ← WINNER!
144
+ "BobAddress": 0
145
+ },
146
+ "winnersCount": 1
147
+ }
148
+ ```
149
+
150
+ **🎉 ALICE WINS BY DEMOCRATIC VOTE!**
151
+
152
+ ---
153
+
154
+ ### **Step 7: Verify Results**
155
+ ```bash
156
+ GET http://localhost:3001/api/v1/demo/wallets
157
+
158
+ Response shows:
159
+ - Creator: balance (paid buy-in, didn't win)
160
+ - Alice: balance (WON! Prize pool added!)
161
+ - Bob: balance (paid buy-in, didn't win)
162
+ - Operator: balance (received 10% fee!)
163
+ ```
164
+
165
+ ---
166
+
167
+ ## 🎯 **Testing Scenarios**
168
+
169
+ ### **Scenario 1: Clear Winner**
170
+ ```
171
+ 3 players vote:
172
+ - Creator votes for Alice
173
+ - Alice votes for Alice
174
+ - Bob votes for Alice
175
+ → Alice gets 100% (all 3 voted for her!)
176
+ ```
177
+
178
+ ### **Scenario 2: Tie (Equal Split)**
179
+ ```
180
+ 3 players vote:
181
+ - Creator votes for Alice
182
+ - Alice votes for Bob
183
+ - Bob votes for Creator
184
+ → All tied at 1 vote each!
185
+ → Prize split 33/33/33
186
+ ```
187
+
188
+ ### **Scenario 3: Majority (2/3 votes)**
189
+ ```
190
+ Only 2 players vote:
191
+ - Creator votes for Alice
192
+ - Alice votes for Alice
193
+ → Majority reached (2/3)!
194
+ → Alice wins!
195
+ → Bob never voted (doesn't matter!)
196
+ ```
197
+
198
+ ---
199
+
200
+ ## 🗳️ **Demo Voting Endpoints**
201
+
202
+ ### **NEW Demo Endpoints:**
203
+ ```
204
+ POST /api/v1/demo/vote/cast
205
+ Body: {
206
+ player: "alice",
207
+ gameId: "uuid",
208
+ votedFor: "player-address"
209
+ }
210
+
211
+ POST /api/v1/demo/vote/distribute
212
+ Body: {
213
+ gameId: "uuid"
214
+ }
215
+ ```
216
+
217
+ ---
218
+
219
+ ## 📊 **Test Checklist**
220
+
221
+ - [ ] Start local validator
222
+ - [ ] Deploy program locally
223
+ - [ ] Start dubs-server (localhost:3001)
224
+ - [ ] Create game with voting
225
+ - [ ] 3 players join
226
+ - [ ] Get player addresses
227
+ - [ ] Cast votes (2-3 players)
228
+ - [ ] Check vote counts
229
+ - [ ] Distribute by vote
230
+ - [ ] Verify balances
231
+ - [ ] Test tie scenario
232
+ - [ ] Test majority scenario
233
+
234
+ ---
235
+
236
+ ## 🚀 **Quick Commands**
237
+
238
+ ### **Start Everything:**
239
+ ```bash
240
+ # Terminal 1: Validator
241
+ solana-test-validator --reset
242
+
243
+ # Terminal 2: Deploy & Start Server
244
+ cd dubs
245
+ solana program deploy target/deploy/hello_world.so --url localhost
246
+
247
+ cd ../dubs-server
248
+ node server.js
249
+ ```
250
+
251
+ ### **Test with Curl:**
252
+ ```bash
253
+ # Create game
254
+ curl -X POST http://localhost:3001/api/v1/demo/game/create \
255
+ -H "Content-Type: application/json" \
256
+ -d '{"player":"creator","buyIn":0.5,"maxPlayers":3,"operatorFee":10}'
257
+
258
+ # Cast vote
259
+ curl -X POST http://localhost:3001/api/v1/demo/vote/cast \
260
+ -H "Content-Type: application/json" \
261
+ -d '{"player":"alice","gameId":"GAME_ID","votedFor":"ALICE_ADDRESS"}'
262
+
263
+ # Distribute by vote
264
+ curl -X POST http://localhost:3001/api/v1/demo/vote/distribute \
265
+ -H "Content-Type: application/json" \
266
+ -d '{"gameId":"GAME_ID"}'
267
+ ```
268
+
269
+ ---
270
+
271
+ ## 🎉 **NO HEROKU NEEDED!**
272
+
273
+ **Test the complete democratic voting system RIGHT NOW on your local machine!**
274
+
275
+ **Everything works offline! No waiting for outage! 🚀**
276
+
277
+ ---
278
+
279
+ **Ready to test? Fire up Postman and point it to `localhost:3001`! 🎮🗳️**