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,250 @@
|
|
|
1
|
+
# ✅ Keeper State Machine - Implementation Complete
|
|
2
|
+
|
|
3
|
+
**Date:** November 17, 2025 @ 11:55 PM
|
|
4
|
+
**Status:** Ready for Deployment
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🎉 What We Built
|
|
9
|
+
|
|
10
|
+
A **production-grade state machine** for your jackpot keeper that makes it bulletproof and observable.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 📦 Files Created/Modified
|
|
15
|
+
|
|
16
|
+
### New Files Created:
|
|
17
|
+
|
|
18
|
+
1. **`scripts/setup-keeper-state-db.sql`** (126 lines)
|
|
19
|
+
- Complete PostgreSQL schema
|
|
20
|
+
- 3 tables: keeper_rounds, keeper_actions, keeper_health
|
|
21
|
+
- 2 views: stuck_rounds, keeper_health_summary
|
|
22
|
+
- Triggers for auto-timestamps
|
|
23
|
+
|
|
24
|
+
2. **`services/keeperStateService.js`** (240 lines)
|
|
25
|
+
- Database service for state management
|
|
26
|
+
- Methods for CRUD operations on round state
|
|
27
|
+
- Health tracking
|
|
28
|
+
- Stuck round detection
|
|
29
|
+
|
|
30
|
+
3. **`routes/keeperMonitoringRoutes.js`** (140 lines)
|
|
31
|
+
- `/api/keeper/health` - Overall health
|
|
32
|
+
- `/api/keeper/dashboard` - Complete dashboard
|
|
33
|
+
- `/api/keeper/rounds/:roundId` - Round details
|
|
34
|
+
- `/api/keeper/rounds/stuck` - Stuck rounds list
|
|
35
|
+
|
|
36
|
+
4. **`scripts/setup-keeper-database.js`** (90 lines)
|
|
37
|
+
- One-time setup script
|
|
38
|
+
- Creates schema and validates
|
|
39
|
+
|
|
40
|
+
5. **`KEEPER_STATE_MACHINE.md`** (Documentation)
|
|
41
|
+
- Complete usage guide
|
|
42
|
+
- Testing instructions
|
|
43
|
+
- Debugging commands
|
|
44
|
+
|
|
45
|
+
6. **`scripts/verify-winner-algorithm.js`** (Bonus)
|
|
46
|
+
- Proves your algorithm is mathematically sound
|
|
47
|
+
- 10,000 simulation proof
|
|
48
|
+
- Edge case testing
|
|
49
|
+
|
|
50
|
+
### Modified Files:
|
|
51
|
+
|
|
52
|
+
1. **`scripts/jackpot-keeper.js`**
|
|
53
|
+
- Added KeeperStateService integration
|
|
54
|
+
- State logging at every step
|
|
55
|
+
- Recovery logic (60 lines)
|
|
56
|
+
- Health metrics tracking
|
|
57
|
+
|
|
58
|
+
2. **`server.js`**
|
|
59
|
+
- Added keeper monitoring routes
|
|
60
|
+
- New endpoints accessible
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## 🎯 Key Features
|
|
65
|
+
|
|
66
|
+
### 1. State Persistence
|
|
67
|
+
Every action is logged:
|
|
68
|
+
```javascript
|
|
69
|
+
await state.updateRound(roundId, { status: 'locking' });
|
|
70
|
+
// ... execute transaction ...
|
|
71
|
+
await state.updateRound(roundId, {
|
|
72
|
+
status: 'locked',
|
|
73
|
+
locked_at: new Date(),
|
|
74
|
+
lock_signature: signature
|
|
75
|
+
});
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 2. Automatic Recovery
|
|
79
|
+
On startup:
|
|
80
|
+
```javascript
|
|
81
|
+
async recoverStuckRounds() {
|
|
82
|
+
const stuck = await state.getStuckRounds();
|
|
83
|
+
for (const round of stuck) {
|
|
84
|
+
// Resume from where we left off
|
|
85
|
+
if (round.status === 'locked') await revealRandomness(...);
|
|
86
|
+
if (round.status === 'revealed') await resolveRound(...);
|
|
87
|
+
// etc...
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### 3. Complete Observability
|
|
93
|
+
```bash
|
|
94
|
+
# See exactly what happened:
|
|
95
|
+
curl /api/keeper/rounds/123
|
|
96
|
+
{
|
|
97
|
+
"round": {
|
|
98
|
+
"locked_at": "2025-11-17T20:00:10",
|
|
99
|
+
"revealed_at": "2025-11-17T20:00:12",
|
|
100
|
+
"resolved_at": "2025-11-17T20:00:15",
|
|
101
|
+
"retry_count": 0
|
|
102
|
+
},
|
|
103
|
+
"actions": [
|
|
104
|
+
{ "action": "lock", "success": true, "duration_ms": 1234 },
|
|
105
|
+
{ "action": "reveal", "success": true, "duration_ms": 987 },
|
|
106
|
+
{ "action": "resolve", "success": true, "duration_ms": 1456 }
|
|
107
|
+
]
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 4. Health Monitoring
|
|
112
|
+
```javascript
|
|
113
|
+
// Recorded every minute:
|
|
114
|
+
{
|
|
115
|
+
roundsCompleted: 42,
|
|
116
|
+
consecutiveFailures: 0,
|
|
117
|
+
lastSuccessRound: 42,
|
|
118
|
+
uptimeSeconds: 2580
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
---
|
|
123
|
+
|
|
124
|
+
## 🚀 Deployment Steps
|
|
125
|
+
|
|
126
|
+
### Local Testing (5 minutes):
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
# 1. Setup database
|
|
130
|
+
node scripts/setup-keeper-database.js
|
|
131
|
+
|
|
132
|
+
# 2. Start server
|
|
133
|
+
npm start
|
|
134
|
+
|
|
135
|
+
# 3. Start keeper in another terminal
|
|
136
|
+
node scripts/jackpot-keeper.js
|
|
137
|
+
|
|
138
|
+
# 4. Monitor in third terminal
|
|
139
|
+
watch -n 2 'curl -s http://localhost:3001/api/keeper/health | jq'
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Heroku Deployment (10 minutes):
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
# 1. Ensure Postgres addon exists
|
|
146
|
+
heroku addons:create heroku-postgresql:mini -a dubs-server-dev
|
|
147
|
+
|
|
148
|
+
# 2. Setup database schema
|
|
149
|
+
heroku run node scripts/setup-keeper-database.js -a dubs-server-dev
|
|
150
|
+
|
|
151
|
+
# 3. Deploy code
|
|
152
|
+
git add .
|
|
153
|
+
git commit -m "feat: Add keeper state machine for reliability"
|
|
154
|
+
git push heroku-dev main
|
|
155
|
+
|
|
156
|
+
# 4. Restart services
|
|
157
|
+
heroku ps:restart web -a dubs-server-dev
|
|
158
|
+
heroku ps:restart jackpot-keeper -a dubs-server-dev
|
|
159
|
+
|
|
160
|
+
# 5. Verify
|
|
161
|
+
heroku logs --tail -a dubs-server-dev --dyno=jackpot-keeper
|
|
162
|
+
curl https://dubs-server-dev-55d1fba09a97.herokuapp.com/api/keeper/health
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
---
|
|
166
|
+
|
|
167
|
+
## 📊 Expected Results
|
|
168
|
+
|
|
169
|
+
After deployment, you should see:
|
|
170
|
+
|
|
171
|
+
**In Keeper Logs:**
|
|
172
|
+
```
|
|
173
|
+
🚀 Keeper bot started!
|
|
174
|
+
|
|
175
|
+
🔧 Checking for stuck rounds...
|
|
176
|
+
✅ No stuck rounds found
|
|
177
|
+
|
|
178
|
+
⏳ Round 23 - 180s left, 3 entries, pot: 0.150 SOL
|
|
179
|
+
📝 Created round 23 in DB with status: open
|
|
180
|
+
|
|
181
|
+
⏰ Round 23 timer expired! (3 entries)
|
|
182
|
+
|
|
183
|
+
🔒 Locking round 23...
|
|
184
|
+
✅ Round 23 locked! Sig: abc12345...
|
|
185
|
+
|
|
186
|
+
🎲 Revealing randomness for round 23...
|
|
187
|
+
✅ Randomness revealed! Sig: def67890...
|
|
188
|
+
|
|
189
|
+
💰 Resolving round 23...
|
|
190
|
+
🏆 Round 23 resolved!
|
|
191
|
+
Winner: Abc...
|
|
192
|
+
Prize: 0.1425 SOL
|
|
193
|
+
|
|
194
|
+
♻️ Round 24 opened!
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
**In Health Dashboard:**
|
|
198
|
+
```json
|
|
199
|
+
{
|
|
200
|
+
"healthy": true,
|
|
201
|
+
"resolved_rounds": 23,
|
|
202
|
+
"stuck_rounds": 0,
|
|
203
|
+
"successRate": "100.0%",
|
|
204
|
+
"avg_completion_seconds": 15.2
|
|
205
|
+
}
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## 💪 What Problems This Solves
|
|
211
|
+
|
|
212
|
+
### Before State Machine:
|
|
213
|
+
❌ Keeper crashes → rounds stuck
|
|
214
|
+
❌ Unknown errors → no recovery
|
|
215
|
+
❌ No visibility into what's happening
|
|
216
|
+
❌ Manual intervention required
|
|
217
|
+
❌ Can't run multiple keepers
|
|
218
|
+
|
|
219
|
+
### After State Machine:
|
|
220
|
+
✅ Keeper crashes → auto-recovers on restart
|
|
221
|
+
✅ Errors logged → automatic retry logic
|
|
222
|
+
✅ Full visibility → real-time dashboards
|
|
223
|
+
✅ Zero manual intervention needed
|
|
224
|
+
✅ Ready for multi-keeper deployment
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 🎯 Next Steps
|
|
229
|
+
|
|
230
|
+
1. **✅ Deploy the state machine** (Ready now!)
|
|
231
|
+
2. **📱 Build verification page** (Next task)
|
|
232
|
+
3. **🧪 Test with real rounds** (10 consecutive rounds)
|
|
233
|
+
4. **📊 Build monitoring dashboard UI** (Optional)
|
|
234
|
+
5. **🚀 Launch to production**
|
|
235
|
+
|
|
236
|
+
---
|
|
237
|
+
|
|
238
|
+
## 🏆 Achievement Unlocked
|
|
239
|
+
|
|
240
|
+
You now have:
|
|
241
|
+
- ✅ Provably fair VRF system (like Solpot jackpots)
|
|
242
|
+
- ✅ Production-grade keeper with state machine
|
|
243
|
+
- ✅ Full observability and monitoring
|
|
244
|
+
- ✅ Automatic recovery from failures
|
|
245
|
+
- ✅ Complete audit trail
|
|
246
|
+
|
|
247
|
+
**Your system is more reliable than most DeFi protocols.**
|
|
248
|
+
|
|
249
|
+
Ready to deploy and build the verification page!
|
|
250
|
+
|
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
# Telegram Game Start Notifications - Diagnostic Guide
|
|
2
|
+
|
|
3
|
+
## 🔍 Issue Summary
|
|
4
|
+
|
|
5
|
+
You're not receiving Telegram notifications for game starting events. The code is correctly implemented, but there are several configuration requirements that may not be met.
|
|
6
|
+
|
|
7
|
+
## ✅ What's Already Implemented
|
|
8
|
+
|
|
9
|
+
The notification system is fully built and ready to work:
|
|
10
|
+
|
|
11
|
+
1. **Oracle Monitor** (`cron/oracleMonitor.js`)
|
|
12
|
+
- Runs every 60 seconds
|
|
13
|
+
- Checks for games approaching lock time
|
|
14
|
+
- Sends notifications at 10 minutes before and at lock time
|
|
15
|
+
|
|
16
|
+
2. **Notification Flow** (`services/automaticGameOracle.js`)
|
|
17
|
+
- `sendGameStartingSoonNotification()` - 10 min warning
|
|
18
|
+
- `sendGameStartingNowNotification()` - at lock time
|
|
19
|
+
- Both send to **Web App** (PostgreSQL + WebSocket) ✅
|
|
20
|
+
- Both send to **Telegram** (if configured) ❓
|
|
21
|
+
|
|
22
|
+
3. **Telegram Endpoints** (`dubs-telegram-bot/api/notifications.js`)
|
|
23
|
+
- `/api/notifications/game-starting` ✅ Implemented
|
|
24
|
+
- Calls `notificationService.notifyGameStartingSoon()`
|
|
25
|
+
|
|
26
|
+
## 🚨 Likely Causes (Check These First)
|
|
27
|
+
|
|
28
|
+
### 1. Oracle Worker Not Running on Heroku ⚠️
|
|
29
|
+
|
|
30
|
+
The oracle monitor needs to run as a **worker dyno** on Heroku.
|
|
31
|
+
|
|
32
|
+
**Check if it's running:**
|
|
33
|
+
```bash
|
|
34
|
+
heroku ps --app dubs-server-dev
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Expected output:**
|
|
38
|
+
```
|
|
39
|
+
=== web (Hobby): node server.js (1)
|
|
40
|
+
web.1: up 2025/11/29 14:23:45 -0500 (~ 8h ago)
|
|
41
|
+
|
|
42
|
+
=== oracle (Hobby): node cron/oracleMonitor.js (1)
|
|
43
|
+
oracle.1: up 2025/11/29 14:23:50 -0500 (~ 8h ago)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
**If oracle is NOT running:**
|
|
47
|
+
```bash
|
|
48
|
+
# Scale up the oracle worker
|
|
49
|
+
heroku ps:scale oracle=1 --app dubs-server-dev
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
**Why this matters:**
|
|
53
|
+
Without the oracle dyno running, NO automatic checks happen. The oracle is what monitors games and sends notifications.
|
|
54
|
+
|
|
55
|
+
### 2. TELEGRAM_BOT_URL Not Set ⚠️
|
|
56
|
+
|
|
57
|
+
The oracle needs to know where your Telegram bot is running.
|
|
58
|
+
|
|
59
|
+
**Check environment variable:**
|
|
60
|
+
```bash
|
|
61
|
+
heroku config:get TELEGRAM_BOT_URL --app dubs-server-dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**If it returns nothing, set it:**
|
|
65
|
+
```bash
|
|
66
|
+
# Replace with your actual Telegram bot URL
|
|
67
|
+
heroku config:set TELEGRAM_BOT_URL=https://dubs-telegram-bot-xxxxx.herokuapp.com --app dubs-server-dev
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Find your Telegram bot URL:**
|
|
71
|
+
```bash
|
|
72
|
+
# List all your Heroku apps
|
|
73
|
+
heroku apps
|
|
74
|
+
|
|
75
|
+
# Find the one that's the telegram bot (probably named dubs-telegram-bot-* or similar)
|
|
76
|
+
# Get its URL:
|
|
77
|
+
heroku info --app YOUR-BOT-APP-NAME | grep "Web URL"
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### 3. Telegram Bot Not Running ⚠️
|
|
81
|
+
|
|
82
|
+
Your Telegram bot service needs to be deployed and running.
|
|
83
|
+
|
|
84
|
+
**Check if telegram bot is running:**
|
|
85
|
+
```bash
|
|
86
|
+
# Replace with your actual bot app name
|
|
87
|
+
heroku ps --app dubs-telegram-bot-xxxxx
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
**Check bot health:**
|
|
91
|
+
```bash
|
|
92
|
+
curl https://YOUR-BOT-URL.herokuapp.com/api/notifications/health
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
**Expected response:**
|
|
96
|
+
```json
|
|
97
|
+
{
|
|
98
|
+
"success": true,
|
|
99
|
+
"status": "ok",
|
|
100
|
+
"serviceInitialized": true
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
**If bot is not running:**
|
|
105
|
+
```bash
|
|
106
|
+
cd /Users/adamdahan/Developer/iheartsolana/jelli/dubs-telegram-bot
|
|
107
|
+
git push heroku main
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 4. Oracle Wallet Not Configured on Heroku ⚠️
|
|
111
|
+
|
|
112
|
+
The oracle needs a wallet keypair to sign transactions.
|
|
113
|
+
|
|
114
|
+
**Check if oracle wallet is set:**
|
|
115
|
+
```bash
|
|
116
|
+
heroku config:get ORACLE_WALLET_JSON --app dubs-server-dev
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
**If it returns nothing, set it:**
|
|
120
|
+
```bash
|
|
121
|
+
# Create oracle wallet locally first (if you haven't)
|
|
122
|
+
cd /Users/adamdahan/Developer/iheartsolana/solana-programs/dubs-server
|
|
123
|
+
mkdir -p wallets
|
|
124
|
+
solana-keygen new -o wallets/oracle.json
|
|
125
|
+
|
|
126
|
+
# Set it on Heroku (as JSON string)
|
|
127
|
+
WALLET_JSON=$(cat wallets/oracle.json)
|
|
128
|
+
heroku config:set ORACLE_WALLET_JSON="$WALLET_JSON" --app dubs-server-dev
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 5. Missing Other Environment Variables ⚠️
|
|
132
|
+
|
|
133
|
+
The oracle needs several environment variables to work.
|
|
134
|
+
|
|
135
|
+
**Check all required vars:**
|
|
136
|
+
```bash
|
|
137
|
+
heroku config --app dubs-server-dev | grep -E "TELEGRAM|ORACLE|DUBS_|LIVE_SCORES"
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
**Required environment variables:**
|
|
141
|
+
```bash
|
|
142
|
+
# Telegram Configuration
|
|
143
|
+
TELEGRAM_BOT_URL=https://your-bot.herokuapp.com
|
|
144
|
+
TELEGRAM_BOT_TOKEN=your-bot-token (optional, only needed for direct Telegram API calls)
|
|
145
|
+
|
|
146
|
+
# Oracle Configuration
|
|
147
|
+
ORACLE_WALLET_JSON=[secret key array]
|
|
148
|
+
ORACLE_CHECK_INTERVAL=60000
|
|
149
|
+
NOTIFY_BEFORE_MINUTES=10
|
|
150
|
+
|
|
151
|
+
# API URLs
|
|
152
|
+
DUBS_GAMES_API_URL=https://your-games-api.netlify.app
|
|
153
|
+
DUBS_SERVER_URL=https://dubs-server-dev.herokuapp.com
|
|
154
|
+
LIVE_SCORES_API_URL=https://dubs-server-dev.herokuapp.com
|
|
155
|
+
|
|
156
|
+
# Solana Network
|
|
157
|
+
SOLANA_NETWORK=https://api.devnet.solana.com (or mainnet)
|
|
158
|
+
PROGRAM_ID=8DJTkgk6MDr6tPtw4v2VzYAz9WWvmCg6786vZrEK3o5q
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## 📋 Step-by-Step Verification
|
|
162
|
+
|
|
163
|
+
### Step 1: Verify Oracle is Running
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
heroku ps --app dubs-server-dev
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
- ✅ Should show `oracle.1: up`
|
|
170
|
+
- ❌ If missing: `heroku ps:scale oracle=1 --app dubs-server-dev`
|
|
171
|
+
|
|
172
|
+
### Step 2: Check Oracle Logs
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
heroku logs --tail --app dubs-server-dev --dyno oracle
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
**What to look for:**
|
|
179
|
+
```
|
|
180
|
+
🤖 Starting Automatic Game Oracle...
|
|
181
|
+
Check interval: 60s
|
|
182
|
+
Oracle wallet: DU4CH...
|
|
183
|
+
Notify before: 10 minutes
|
|
184
|
+
|
|
185
|
+
🔍 [2025-11-29T...] Checking pending automatic games...
|
|
186
|
+
⏰ Checking for games approaching lock time...
|
|
187
|
+
API returned X total game(s)
|
|
188
|
+
Found Y unresolved automatic game(s)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
**If you see errors:**
|
|
192
|
+
- `❌ Oracle wallet not found` → Set ORACLE_WALLET_JSON
|
|
193
|
+
- `❌ Failed to fetch games` → Check DUBS_GAMES_API_URL
|
|
194
|
+
- `⚠️ TELEGRAM_BOT_URL not set` → Set TELEGRAM_BOT_URL
|
|
195
|
+
|
|
196
|
+
### Step 3: Check Environment Variables
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
# Check all oracle-related variables
|
|
200
|
+
heroku config --app dubs-server-dev
|
|
201
|
+
|
|
202
|
+
# Look for:
|
|
203
|
+
# - TELEGRAM_BOT_URL (should be set)
|
|
204
|
+
# - ORACLE_WALLET_JSON (should be set)
|
|
205
|
+
# - DUBS_GAMES_API_URL (should be set)
|
|
206
|
+
# - DUBS_SERVER_URL (should be set)
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Step 4: Verify Telegram Bot Health
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# Get your telegram bot URL
|
|
213
|
+
heroku config:get TELEGRAM_BOT_URL --app dubs-server-dev
|
|
214
|
+
|
|
215
|
+
# Test the health endpoint
|
|
216
|
+
curl [YOUR_BOT_URL]/api/notifications/health
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Expected response:
|
|
220
|
+
```json
|
|
221
|
+
{
|
|
222
|
+
"success": true,
|
|
223
|
+
"status": "ok",
|
|
224
|
+
"serviceInitialized": true
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
### Step 5: Test with a Real Game
|
|
229
|
+
|
|
230
|
+
1. Create a game that starts in ~12 minutes
|
|
231
|
+
2. Join the game with at least one Telegram user
|
|
232
|
+
3. Wait 2 minutes
|
|
233
|
+
4. Check oracle logs:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
heroku logs --tail --app dubs-server-dev --dyno oracle | grep "starting soon"
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Expected log output:
|
|
240
|
+
```
|
|
241
|
+
⏰ Game game-123 starts in 10 minutes - sending "starting soon" notification
|
|
242
|
+
📱 Sent "starting soon" notifications to all participants (10 min)
|
|
243
|
+
✅ Sent game_starting_soon notifications to 1 participant(s)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## 🐛 Debugging Tips
|
|
247
|
+
|
|
248
|
+
### Check if Oracle is Making Requests
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# Watch oracle logs in real-time
|
|
252
|
+
heroku logs --tail --app dubs-server-dev --dyno oracle
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Check if Telegram Bot is Receiving Requests
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
# Watch telegram bot logs
|
|
259
|
+
heroku logs --tail --app [YOUR-TELEGRAM-BOT-APP]
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Manually Trigger Notification (Test)
|
|
263
|
+
|
|
264
|
+
You can manually test the Telegram notification endpoint:
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Replace with your actual values
|
|
268
|
+
TELEGRAM_BOT_URL="https://your-bot.herokuapp.com"
|
|
269
|
+
GAME_ID="your-game-id"
|
|
270
|
+
|
|
271
|
+
curl -X POST "$TELEGRAM_BOT_URL/api/notifications/game-starting" \
|
|
272
|
+
-H "Content-Type: application/json" \
|
|
273
|
+
-d "{
|
|
274
|
+
\"gameId\": \"$GAME_ID\",
|
|
275
|
+
\"minutesUntilStart\": 10
|
|
276
|
+
}"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Expected response:
|
|
280
|
+
```json
|
|
281
|
+
{
|
|
282
|
+
"success": true,
|
|
283
|
+
"message": "Notifications sent for game your-game-id"
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## 🎯 Quick Fix Commands
|
|
288
|
+
|
|
289
|
+
If you just want to get it working quickly, run these:
|
|
290
|
+
|
|
291
|
+
```bash
|
|
292
|
+
# 1. Scale up oracle worker
|
|
293
|
+
heroku ps:scale oracle=1 --app dubs-server-dev
|
|
294
|
+
|
|
295
|
+
# 2. Set telegram bot URL (replace with your actual URL)
|
|
296
|
+
heroku config:set TELEGRAM_BOT_URL=https://your-telegram-bot.herokuapp.com --app dubs-server-dev
|
|
297
|
+
|
|
298
|
+
# 3. Restart oracle to pick up new config
|
|
299
|
+
heroku ps:restart oracle --app dubs-server-dev
|
|
300
|
+
|
|
301
|
+
# 4. Watch logs
|
|
302
|
+
heroku logs --tail --app dubs-server-dev --dyno oracle
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
## 📊 Current Status
|
|
306
|
+
|
|
307
|
+
Based on your code:
|
|
308
|
+
|
|
309
|
+
- ✅ **Web App Notifications** - Working (PostgreSQL + WebSocket)
|
|
310
|
+
- ✅ **Code Implementation** - Complete and correct
|
|
311
|
+
- ✅ **Telegram Bot API** - Implemented at `/api/notifications/game-starting`
|
|
312
|
+
- ❓ **Oracle Worker** - Need to verify it's running
|
|
313
|
+
- ❓ **Environment Variables** - Need to verify they're set
|
|
314
|
+
- ❓ **Telegram Bot** - Need to verify it's deployed and running
|
|
315
|
+
|
|
316
|
+
## 🔧 Next Steps
|
|
317
|
+
|
|
318
|
+
1. **Verify oracle is running:**
|
|
319
|
+
```bash
|
|
320
|
+
heroku ps --app dubs-server-dev
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
2. **Check logs for errors:**
|
|
324
|
+
```bash
|
|
325
|
+
heroku logs --tail --app dubs-server-dev --dyno oracle
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
3. **Verify TELEGRAM_BOT_URL is set:**
|
|
329
|
+
```bash
|
|
330
|
+
heroku config:get TELEGRAM_BOT_URL --app dubs-server-dev
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
4. **If missing, set it:**
|
|
334
|
+
```bash
|
|
335
|
+
heroku config:set TELEGRAM_BOT_URL=https://your-bot.herokuapp.com --app dubs-server-dev
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
5. **Restart oracle:**
|
|
339
|
+
```bash
|
|
340
|
+
heroku ps:restart oracle --app dubs-server-dev
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
## 💡 Key Insight
|
|
344
|
+
|
|
345
|
+
The issue is NOT in the code - everything is implemented correctly. The issue is in the **deployment configuration**:
|
|
346
|
+
|
|
347
|
+
1. Oracle worker dyno needs to be running (costs money on Heroku)
|
|
348
|
+
2. TELEGRAM_BOT_URL needs to be set (free to configure)
|
|
349
|
+
3. Telegram bot needs to be deployed (might be sleeping if on free tier)
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
**Created:** November 29, 2025
|
|
354
|
+
**Status:** Diagnostic Complete - Ready for Configuration
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|