@levrbet/shared 0.3.3 → 0.3.4
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/dist/core/config/urls.d.ts +8 -0
- package/dist/core/config/urls.js +20 -12
- package/dist/core/config/urls.js.map +1 -1
- package/dist/core/contracts/abis/LevrManager.d.ts +1008 -988
- package/dist/core/contracts/abis/LevrManager.js +1538 -499
- package/dist/core/contracts/abis/LevrManager.js.map +1 -1
- package/dist/core/contracts/abis/index.d.ts +1008 -988
- package/dist/core/contracts/addresses.d.ts +21 -21
- package/dist/core/contracts/addresses.js +19 -19
- package/dist/core/types/oracle/game/game.types.d.ts +3 -2
- package/dist/core/types/oracle/game/game.types.js +0 -1
- package/dist/core/types/oracle/game/game.types.js.map +1 -1
- package/dist/core/types/oracle/market/markets.types.d.ts +4 -2
- package/dist/core/types/oracle/market/markets.types.js.map +1 -1
- package/dist/core/types/oracle/market/positions.types.d.ts +7 -1
- package/dist/react/hooks/contracts/useContracts.d.ts +19 -19
- package/dist/server/config/kms.js +1 -1
- package/dist/server/config/redis.d.ts +5 -0
- package/dist/server/config/redis.js +13 -3
- package/dist/server/config/redis.js.map +1 -1
- package/dist/server/config/urls.d.ts +8 -0
- package/dist/server/contracts/clients/ozRelayerService.d.ts +1 -0
- package/dist/server/contracts/clients/ozRelayerService.js +110 -17
- package/dist/server/contracts/clients/ozRelayerService.js.map +1 -1
- package/dist/server/liquidation-engine/redis.cache.manager/prices.set.manager.d.ts +9 -9
- package/dist/server/liquidation-engine/redis.cache.manager/prices.set.manager.js.map +1 -1
- package/dist/server/liquidation-engine/redis.cache.manager/prices.set.manager.test.js +1 -1
- package/dist/server/liquidation-engine/redis.cache.manager/prices.set.manager.test.js.map +1 -1
- package/dist/server/oracle/config/game-periods/providers/optic-odds.periods.d.ts +4 -0
- package/dist/server/oracle/config/game-periods/providers/optic-odds.periods.js +5 -1
- package/dist/server/oracle/config/game-periods/providers/optic-odds.periods.js.map +1 -1
- package/dist/server/oracle/config/game-periods/sports.config.d.ts +1 -1
- package/dist/server/oracle/config/game-periods/sports.config.js +56 -6
- package/dist/server/oracle/config/game-periods/sports.config.js.map +1 -1
- package/dist/server/oracle/config/game-periods/types.d.ts +9 -1
- package/dist/server/oracle/config/game-periods/types.js +5 -0
- package/dist/server/oracle/config/game-periods/types.js.map +1 -1
- package/dist/server/oracle/redis-cache-manager/channels.d.ts +2 -2
- package/dist/server/oracle/redis-cache-manager/channels.js.map +1 -1
- package/dist/server/oracle/redis-cache-manager/game.progress.d.ts +4 -4
- package/dist/server/oracle/redis-cache-manager/game.progress.js.map +1 -1
- package/dist/server/oracle/redis-cache-manager/leagues.cache.service.d.ts +3 -3
- package/dist/server/oracle/redis-cache-manager/leagues.cache.service.js +5 -1
- package/dist/server/oracle/redis-cache-manager/leagues.cache.service.js.map +1 -1
- package/dist/server/oracle/rmq-manager/base.queue.manager.d.ts +1 -1
- package/dist/server/oracle/rmq-manager/base.queue.manager.js +3 -1
- package/dist/server/oracle/rmq-manager/base.queue.manager.js.map +1 -1
- package/dist/server/services/presigned.urls.js +1 -1
- package/dist/server/services/presigned.urls.js.map +1 -1
- package/dist/server/utils/game_progress/caclulate.game.progress.d.ts +132 -4
- package/dist/server/utils/game_progress/caclulate.game.progress.js +195 -24
- package/dist/server/utils/game_progress/caclulate.game.progress.js.map +1 -1
- package/dist/server/utils/game_progress/game.utils.d.ts +6 -1
- package/dist/server/utils/game_progress/game.utils.js +71 -52
- package/dist/server/utils/game_progress/game.utils.js.map +1 -1
- package/dist/server/utils/game_progress/parser.js +6 -0
- package/dist/server/utils/game_progress/parser.js.map +1 -1
- package/package.json +2 -1
- package/prisma/schema.prisma +54 -15
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Game progress calculation utilities for various sports.
|
|
4
|
+
* This module provides functions to calculate game progress in basis points (BPS)
|
|
5
|
+
* for different sports including Soccer, Basketball, Football, and Baseball.
|
|
6
|
+
* It supports multiple odds providers (LSports, OpticOdds) with provider-specific
|
|
7
|
+
* period mapping logic.
|
|
8
|
+
* @module game_progress/calculate.game.progress
|
|
9
|
+
*/
|
|
2
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.calculateBaseballProgress = exports.calculateFootballProgress = exports.calculateBasketballProgress = exports.calculateSoccerProgress = void 0;
|
|
11
|
+
exports.calculateNCAAFProgress = exports.calculateNCAABProgress = exports.calculateBaseballProgress = exports.calculateFootballProgress = exports.calculateBasketballProgress = exports.calculateSoccerProgress = exports.calculateGameProgress = void 0;
|
|
4
12
|
const client_1 = require("@prisma/client");
|
|
13
|
+
const core_1 = require("../../../core");
|
|
14
|
+
const oracle_1 = require("../../oracle");
|
|
5
15
|
const game_utils_1 = require("../game_progress/game.utils");
|
|
6
16
|
const parser_1 = require("./parser");
|
|
7
|
-
|
|
8
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Provider and sport-specific period mappers.
|
|
19
|
+
* Maps raw period values from odds providers to normalized period numbers.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* - LSports Soccer uses 10 for 1st half, 20 for 2nd half
|
|
23
|
+
* - Other sports typically use sequential period numbers (1, 2, 3, etc.)
|
|
24
|
+
*/
|
|
9
25
|
const PERIOD_MAPPERS = {
|
|
10
26
|
[core_1.OddsServices.LSPORTS]: {
|
|
11
27
|
[client_1.SportGroup.Soccer]: (currentPeriod) => {
|
|
@@ -54,43 +70,198 @@ const PERIOD_MAPPERS = {
|
|
|
54
70
|
},
|
|
55
71
|
},
|
|
56
72
|
};
|
|
57
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Period mappers specifically for NCAA leagues.
|
|
75
|
+
* NCAA sports in LSports use 10/20 notation for halves instead of 1/2.
|
|
76
|
+
*
|
|
77
|
+
* @remarks
|
|
78
|
+
* - LSports: period 10 = 1st half, period 20 = 2nd half
|
|
79
|
+
* - OpticOdds: uses standard sequential period numbering
|
|
80
|
+
*/
|
|
81
|
+
const NCAA_PERIOD_MAPPERS = {
|
|
82
|
+
[core_1.OddsServices.LSPORTS]: (currentPeriod) => {
|
|
83
|
+
if (currentPeriod === 10)
|
|
84
|
+
return 1;
|
|
85
|
+
if (currentPeriod === 20)
|
|
86
|
+
return 2;
|
|
87
|
+
return null;
|
|
88
|
+
},
|
|
89
|
+
[core_1.OddsServices.OPTIC_ODDS]: (currentPeriod, totalPeriods) => {
|
|
90
|
+
if (currentPeriod >= 1 && currentPeriod <= totalPeriods)
|
|
91
|
+
return currentPeriod;
|
|
92
|
+
return null;
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* Calculates the game progress in basis points (BPS) for a given sport.
|
|
97
|
+
* This is the core calculation function used by all sport-specific progress functions.
|
|
98
|
+
*
|
|
99
|
+
* @param currentPeriod - The current period/quarter/half number from the provider
|
|
100
|
+
* @param gameClock - The game clock string (e.g., "12:30", "45:00")
|
|
101
|
+
* @param sportGroup - The sport group enum value (Soccer, Basketball, Football, Baseball)
|
|
102
|
+
* @param provider - The odds service provider (LSports, OpticOdds)
|
|
103
|
+
* @param isTopOfInning - For baseball only: whether it's the top of the inning
|
|
104
|
+
* @param leagueSelector - Optional league identifier for league-specific configurations (e.g., NCAA)
|
|
105
|
+
* @returns The game progress in basis points (0-10000) or null if invalid input
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* // Calculate NBA game progress at 5:30 remaining in Q2
|
|
109
|
+
* calculateGameProgress(2, "05:30", SportGroup.Basketball, OddsServices.LSPORTS)
|
|
110
|
+
* // Returns approximately 3125 BPS (31.25% through the game)
|
|
111
|
+
*/
|
|
112
|
+
const calculateGameProgress = (currentPeriod, gameClock, sportGroup, provider, isTopOfInning, leagueSelector) => {
|
|
58
113
|
const config = oracle_1.SportsGamePeriodClockConfig[sportGroup];
|
|
59
|
-
if (!config
|
|
114
|
+
if (!config)
|
|
115
|
+
return null;
|
|
116
|
+
// Check if this is a league-specific config (NCAA)
|
|
117
|
+
const leagueConfig = leagueSelector ? config[provider].leaguePeriods?.[leagueSelector] : null;
|
|
118
|
+
const mainPeriodsConfig = leagueConfig ?? config[provider].sportPeriods;
|
|
119
|
+
// Extract the actual PeriodConfig (handle nested structure), to cater for league-specific configs
|
|
120
|
+
const periodConfig = "periodConfig" in mainPeriodsConfig ? mainPeriodsConfig.periodConfig : mainPeriodsConfig;
|
|
121
|
+
if (!periodConfig.regular.includes(currentPeriod))
|
|
60
122
|
return null;
|
|
61
|
-
|
|
123
|
+
// Use NCAA period mapper for league-specific calculations
|
|
124
|
+
const periodMapper = leagueConfig ? NCAA_PERIOD_MAPPERS[provider] : PERIOD_MAPPERS[provider]?.[sportGroup];
|
|
62
125
|
if (!periodMapper)
|
|
63
126
|
return null;
|
|
64
|
-
const
|
|
127
|
+
const totalPeriods = leagueConfig ? leagueConfig.totalPeriods : config.totalPeriods;
|
|
128
|
+
const totalPeriodDurationInSeconds = leagueConfig
|
|
129
|
+
? leagueConfig.totalPeriodDurationInSeconds
|
|
130
|
+
: config.totalPeriodDurationInSeconds;
|
|
131
|
+
const period = periodMapper(currentPeriod, totalPeriods);
|
|
65
132
|
if (period === null)
|
|
66
133
|
return null;
|
|
67
134
|
const gameClockInSeconds = (0, parser_1.parseGameClockToSeconds)(gameClock);
|
|
68
135
|
if (gameClockInSeconds === null)
|
|
69
136
|
return null;
|
|
70
|
-
return (0, game_utils_1.getGameProgressBPS)(gameClockInSeconds,
|
|
137
|
+
return (0, game_utils_1.getGameProgressBPS)(gameClockInSeconds, totalPeriodDurationInSeconds, period, totalPeriods, sportGroup, periodConfig.countUpClock, isTopOfInning);
|
|
71
138
|
};
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
139
|
+
exports.calculateGameProgress = calculateGameProgress;
|
|
140
|
+
/**
|
|
141
|
+
* Calculates game progress for Soccer matches in basis points (BPS).
|
|
142
|
+
* Soccer uses 2 x 45 minute halves with a count-up clock.
|
|
143
|
+
*
|
|
144
|
+
* @param currentPeriod - The current half (LSports: 10=1st half, 20=2nd half; OpticOdds: 1 or 2)
|
|
145
|
+
* @param gameClock - The elapsed time in "MM:SS" format (e.g., "32:15")
|
|
146
|
+
* @param provider - The odds service provider
|
|
147
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* // First half at 30 minutes
|
|
151
|
+
* calculateSoccerProgress(10, "30:00", SportGroup.Soccer, OddsServices.LSPORTS)
|
|
152
|
+
* // Returns ~3333 BPS (33.33% through the game)
|
|
153
|
+
*/
|
|
154
|
+
const calculateSoccerProgress = (currentPeriod, gameClock, provider) => {
|
|
155
|
+
return (0, exports.calculateGameProgress)(currentPeriod, gameClock, client_1.SportGroup.Soccer, provider);
|
|
76
156
|
};
|
|
77
157
|
exports.calculateSoccerProgress = calculateSoccerProgress;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
158
|
+
/**
|
|
159
|
+
* Calculates game progress for Basketball (NBA) matches in basis points (BPS).
|
|
160
|
+
* NBA uses 4 x 12 minute quarters with a countdown clock.
|
|
161
|
+
*
|
|
162
|
+
* @param currentPeriod - The current quarter (1-4)
|
|
163
|
+
* @param gameClock - The time remaining in "MM:SS" format (e.g., "08:45")
|
|
164
|
+
* @param provider - The odds service provider
|
|
165
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
166
|
+
*
|
|
167
|
+
* @example
|
|
168
|
+
* // Third quarter with 6 minutes remaining
|
|
169
|
+
* calculateBasketballProgress(3, "06:00", SportGroup.Basketball, OddsServices.LSPORTS)
|
|
170
|
+
* // Returns ~6250 BPS (62.5% through the game)
|
|
171
|
+
*/
|
|
172
|
+
const calculateBasketballProgress = (currentPeriod, gameClock, provider) => {
|
|
173
|
+
return (0, exports.calculateGameProgress)(currentPeriod, gameClock, client_1.SportGroup.Basketball, provider);
|
|
82
174
|
};
|
|
83
175
|
exports.calculateBasketballProgress = calculateBasketballProgress;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
176
|
+
/**
|
|
177
|
+
* Calculates game progress for American Football (NFL) matches in basis points (BPS).
|
|
178
|
+
* NFL uses 4 x 15 minute quarters with a countdown clock.
|
|
179
|
+
*
|
|
180
|
+
* @param currentPeriod - The current quarter (1-4)
|
|
181
|
+
* @param gameClock - The time remaining in "MM:SS" format (e.g., "12:30")
|
|
182
|
+
* @param provider - The odds service provider
|
|
183
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
184
|
+
*
|
|
185
|
+
* @example
|
|
186
|
+
* // Second quarter with 8 minutes remaining
|
|
187
|
+
* calculateFootballProgress(2, "08:00", SportGroup.Football, OddsServices.LSPORTS)
|
|
188
|
+
* // Returns ~3667 BPS (36.67% through the game)
|
|
189
|
+
*/
|
|
190
|
+
const calculateFootballProgress = (currentPeriod, gameClock, provider) => {
|
|
191
|
+
return (0, exports.calculateGameProgress)(currentPeriod, gameClock, client_1.SportGroup.Football, provider);
|
|
88
192
|
};
|
|
89
193
|
exports.calculateFootballProgress = calculateFootballProgress;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
194
|
+
/**
|
|
195
|
+
* Calculates game progress for Baseball (MLB) matches in basis points (BPS).
|
|
196
|
+
* Baseball uses 9 innings, each with a top and bottom half.
|
|
197
|
+
* Progress is calculated based on completed half-innings.
|
|
198
|
+
*
|
|
199
|
+
* @param currentPeriod - The current inning (1-9)
|
|
200
|
+
* @param isTopOfInning - True if it's the top of the inning (away team batting)
|
|
201
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* // Top of the 5th inning
|
|
205
|
+
* calculateBaseballProgress(5, true)
|
|
206
|
+
* // Returns ~4444 BPS (44.44% through the game)
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* // Bottom of the 7th inning
|
|
210
|
+
* calculateBaseballProgress(7, false)
|
|
211
|
+
* // Returns ~7778 BPS (77.78% through the game)
|
|
212
|
+
*/
|
|
213
|
+
const calculateBaseballProgress = (currentPeriod, isTopOfInning) => {
|
|
214
|
+
const config = oracle_1.SportsGamePeriodClockConfig[client_1.SportGroup.Baseball];
|
|
215
|
+
if (!config)
|
|
216
|
+
return null;
|
|
217
|
+
return (0, game_utils_1.calculateBaseballProgressBPS)(currentPeriod, config.totalPeriods, isTopOfInning);
|
|
94
218
|
};
|
|
95
219
|
exports.calculateBaseballProgress = calculateBaseballProgress;
|
|
220
|
+
/**
|
|
221
|
+
* Calculates game progress for NCAA Basketball (NCAAB) matches in basis points (BPS).
|
|
222
|
+
* NCAAB uses 2 x 20 minute halves with a countdown clock (different from NBA's 4 quarters).
|
|
223
|
+
*
|
|
224
|
+
* @param currentPeriod - The current half (LSports: 10=1st half, 20=2nd half; OpticOdds: 1 or 2)
|
|
225
|
+
* @param gameClock - The time remaining
|
|
226
|
+
* @param provider - The odds service provider
|
|
227
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
228
|
+
*
|
|
229
|
+
* @remarks
|
|
230
|
+
* - LSports uses period codes 10 and 20 for 1st and 2nd halves respectively
|
|
231
|
+
* - OpticOdds uses standard 1 and 2 for halves
|
|
232
|
+
* - Total game duration: 40 minutes (2 x 20 min halves)
|
|
233
|
+
*
|
|
234
|
+
* @example
|
|
235
|
+
* // First half with 10 minutes remaining (LSports)
|
|
236
|
+
* calculateNCAABProgress(10, "10:00", OddsServices.LSPORTS)
|
|
237
|
+
* // Returns ~2500 BPS (25% through the game)
|
|
238
|
+
*/
|
|
239
|
+
const calculateNCAABProgress = (currentPeriod, gameClock, provider) => {
|
|
240
|
+
return (0, exports.calculateGameProgress)(currentPeriod, gameClock, client_1.SportGroup.Basketball, provider, undefined, oracle_1.LEAGUE_SELECTORS.NCAA_BASKETBALL);
|
|
241
|
+
};
|
|
242
|
+
exports.calculateNCAABProgress = calculateNCAABProgress;
|
|
243
|
+
/**
|
|
244
|
+
* Calculates game progress for NCAA Football (NCAAF) matches in basis points (BPS).
|
|
245
|
+
* NCAAF uses 2 x 30 minute halves (equivalent to 4 x 15 min quarters) with a countdown clock.
|
|
246
|
+
*
|
|
247
|
+
* @param currentPeriod - The current half (LSports: 10=1st half, 20=2nd half; OpticOdds: 1 or 2)
|
|
248
|
+
* @param gameClock - The time remaining in "MM:SS" format (e.g., "25:00")
|
|
249
|
+
* @param provider - The odds service provider
|
|
250
|
+
* @returns Game progress in BPS (0-10000) or null if invalid
|
|
251
|
+
*
|
|
252
|
+
* @remarks
|
|
253
|
+
* - LSports uses period codes 10 and 20 for 1st and 2nd halves respectively
|
|
254
|
+
* - OpticOdds uses standard 1 and 2 for halves
|
|
255
|
+
* - Total game duration: 60 minutes (2 x 30 min halves)
|
|
256
|
+
* - Quarters are grouped into halves for period tracking
|
|
257
|
+
*
|
|
258
|
+
* @example
|
|
259
|
+
* // First half with 20 minutes remaining (LSports)
|
|
260
|
+
* calculateNCAAFProgress(10, "20:00", OddsServices.LSPORTS)
|
|
261
|
+
* // Returns ~1667 BPS (16.67% through the game)
|
|
262
|
+
*/
|
|
263
|
+
const calculateNCAAFProgress = (currentPeriod, gameClock, provider) => {
|
|
264
|
+
return (0, exports.calculateGameProgress)(currentPeriod, gameClock, client_1.SportGroup.Football, provider, undefined, oracle_1.LEAGUE_SELECTORS.NCAA_FOOTBALL);
|
|
265
|
+
};
|
|
266
|
+
exports.calculateNCAAFProgress = calculateNCAAFProgress;
|
|
96
267
|
//# sourceMappingURL=caclulate.game.progress.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"caclulate.game.progress.js","sourceRoot":"","sources":["../../../../src/server/utils/game_progress/caclulate.game.progress.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"caclulate.game.progress.js","sourceRoot":"","sources":["../../../../src/server/utils/game_progress/caclulate.game.progress.ts"],"names":[],"mappings":";AAAA;;;;;;;G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CAAC,CAAA;AAJY,QAAA,yBAAyB,6BAIrC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACI,MAAM,sBAAsB,GAAG,CAAC,aAAqB,EAAE,SAAiB,EAAE,QAAsB,EAAE,EAAE;IACvG,OAAO,IAAA,6BAAqB,EACxB,aAAa,EACb,SAAS,EACT,mBAAU,CAAC,UAAU,EACrB,QAAQ,EACR,SAAS,EACT,yBAAgB,CAAC,eAAe,CACnC,CAAA;AACL,CAAC,CAAA;AATY,QAAA,sBAAsB,0BASlC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACI,MAAM,sBAAsB,GAAG,CAAC,aAAqB,EAAE,SAAiB,EAAE,QAAsB,EAAE,EAAE;IACvG,OAAO,IAAA,6BAAqB,EACxB,aAAa,EACb,SAAS,EACT,mBAAU,CAAC,QAAQ,EACnB,QAAQ,EACR,SAAS,EACT,yBAAgB,CAAC,aAAa,CACjC,CAAA;AACL,CAAC,CAAA;AATY,QAAA,sBAAsB,0BASlC"}
|
|
@@ -1,2 +1,7 @@
|
|
|
1
1
|
import { SportGroup } from "@prisma/client";
|
|
2
|
-
|
|
2
|
+
/**
|
|
3
|
+
* For sports like Baseball where we only track period (inning) progress, not time.
|
|
4
|
+
* Baseball: 9 innings, each with top (0) and bottom (1) = 18 half-innings total.
|
|
5
|
+
*/
|
|
6
|
+
export declare const calculateBaseballProgressBPS: (period: number, totalPeriods: number, isTopOfInning: boolean) => number;
|
|
7
|
+
export declare const getGameProgressBPS: (gameClockInSeconds: number, totalPeriodDurationInSeconds: number, period: number, totalPeriods: number, sportGroup: SportGroup, clockCountUp: boolean, isTopOfInning?: boolean) => number | null;
|
|
@@ -1,64 +1,83 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getGameProgressBPS = void 0;
|
|
3
|
+
exports.getGameProgressBPS = exports.calculateBaseballProgressBPS = void 0;
|
|
4
4
|
const client_1 = require("@prisma/client");
|
|
5
|
-
const
|
|
5
|
+
const MAX_BASIS_POINTS = 1e4;
|
|
6
|
+
/**
|
|
7
|
+
* Clamps a BPS value between 0 and MAX_BASIS_POINTS
|
|
8
|
+
*/
|
|
9
|
+
const clampBPS = (value) => Math.max(0, Math.min(Math.floor(value), MAX_BASIS_POINTS));
|
|
10
|
+
// Clamp per-period elapsed time to prevent exceeding max period duration
|
|
11
|
+
const clampPeriodElapsed = (elapsed, totalPeriodDurationInSeconds) => Math.max(0, Math.min(elapsed, totalPeriodDurationInSeconds));
|
|
12
|
+
/**
|
|
13
|
+
* Get elapsed seconds from game clock based on clock direction.
|
|
14
|
+
* For countdown: elapsed = total - remaining
|
|
15
|
+
* For count-up: elapsed = clock value directly
|
|
16
|
+
* Clamps per-period elapsed time to valid range [0, totalPeriodDurationInSeconds]
|
|
17
|
+
*/
|
|
18
|
+
const getElapsedSeconds = (gameClockInSeconds, totalPeriodDurationInSeconds, period, isCumulative, clockCountUp) => {
|
|
19
|
+
if (clockCountUp) {
|
|
20
|
+
if (isCumulative) {
|
|
21
|
+
//if it's soccer only clamp if the game clock exceeds duration for that specific period
|
|
22
|
+
if (gameClockInSeconds > totalPeriodDurationInSeconds * period)
|
|
23
|
+
return clampPeriodElapsed(gameClockInSeconds, totalPeriodDurationInSeconds);
|
|
24
|
+
return Math.max(0, gameClockInSeconds);
|
|
25
|
+
}
|
|
26
|
+
return clampPeriodElapsed(gameClockInSeconds, totalPeriodDurationInSeconds);
|
|
27
|
+
}
|
|
28
|
+
// Countdown clock: elapsed = total - remaining
|
|
29
|
+
const elapsedInCurrentPeriod = clampPeriodElapsed(totalPeriodDurationInSeconds - gameClockInSeconds, totalPeriodDurationInSeconds);
|
|
30
|
+
if (isCumulative) {
|
|
31
|
+
// Soccer with countdown: add completed periods
|
|
32
|
+
return (period - 1) * totalPeriodDurationInSeconds + elapsedInCurrentPeriod;
|
|
33
|
+
}
|
|
34
|
+
return elapsedInCurrentPeriod;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* For sports like Baseball where we only track period (inning) progress, not time.
|
|
38
|
+
* Baseball: 9 innings, each with top (0) and bottom (1) = 18 half-innings total.
|
|
39
|
+
*/
|
|
40
|
+
const calculateBaseballProgressBPS = (period, totalPeriods, isTopOfInning) => {
|
|
6
41
|
if (period > totalPeriods)
|
|
7
|
-
return
|
|
8
|
-
|
|
9
|
-
|
|
42
|
+
return MAX_BASIS_POINTS;
|
|
43
|
+
if (period < 1)
|
|
44
|
+
return 0;
|
|
45
|
+
const totalHalfInnings = totalPeriods * 2;
|
|
46
|
+
const currentHalfInning = (period - 1) * 2 + (isTopOfInning ? 1 : 2);
|
|
47
|
+
return clampBPS((currentHalfInning / totalHalfInnings) * MAX_BASIS_POINTS);
|
|
10
48
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
49
|
+
exports.calculateBaseballProgressBPS = calculateBaseballProgressBPS;
|
|
50
|
+
/**
|
|
51
|
+
* Calculate game progress in BPS from elapsed time.
|
|
52
|
+
* @param elapsedSeconds - Time elapsed (cumulative for soccer, current period for others)
|
|
53
|
+
* @param totalPeriodDurationInSeconds - Duration of each period
|
|
54
|
+
* @param totalPeriods - Total number of periods
|
|
55
|
+
* @param period - Current period (only used for non-soccer sports)
|
|
56
|
+
* @param isCumulative - Whether elapsedSeconds is cumulative (soccer) or per-period (others)
|
|
57
|
+
*/
|
|
58
|
+
const calculateProgressBPS = (elapsedSeconds, totalPeriodDurationInSeconds, totalPeriods, period, isCumulative) => {
|
|
15
59
|
if (totalPeriodDurationInSeconds === 0)
|
|
16
60
|
return 0;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return value;
|
|
30
|
-
};
|
|
31
|
-
// Example: { totalPeriods: 2, totalPeriodDurationInSeconds: 45 * 60 }, gameClock: '57:20', period: 2
|
|
32
|
-
// gameClock is cumulative (57:20 = 57 mins into game, which is 12:20 into period 2)
|
|
33
|
-
// Expected: elapsedInPeriod = 3440 - 2700 = 740 seconds → ~63.7% game progress
|
|
34
|
-
const calculateGameProgressBPSWithGameClockCountUp = (gameClockInSeconds, totalPeriodDurationInSeconds, totalPeriods, period) => {
|
|
35
|
-
const cumulativeElapsedSeconds = gameClockInSeconds;
|
|
36
|
-
if (cumulativeElapsedSeconds === null)
|
|
37
|
-
return null;
|
|
38
|
-
// Subtract time from previous periods since gameClock is cumulative
|
|
39
|
-
const previousPeriodsSeconds = (period - 1) * totalPeriodDurationInSeconds;
|
|
40
|
-
const elapsedSecondsInCurrentPeriod = cumulativeElapsedSeconds - previousPeriodsSeconds;
|
|
41
|
-
return calculateGameProgressBPS(elapsedSecondsInCurrentPeriod, totalPeriodDurationInSeconds, totalPeriods, period);
|
|
42
|
-
};
|
|
43
|
-
const calculateGameProgressBPSWithGameClockCountDown = (gameClockInSeconds, totalPeriodDurationInSeconds, totalPeriods, period) => {
|
|
44
|
-
const remainingSeconds = gameClockInSeconds;
|
|
45
|
-
if (remainingSeconds === null)
|
|
46
|
-
return null;
|
|
47
|
-
const elapsedSeconds = totalPeriodDurationInSeconds - remainingSeconds;
|
|
48
|
-
return calculateGameProgressBPS(elapsedSeconds, totalPeriodDurationInSeconds, totalPeriods, period);
|
|
61
|
+
const totalGameDuration = totalPeriods * totalPeriodDurationInSeconds;
|
|
62
|
+
if (isCumulative) {
|
|
63
|
+
// Soccer: elapsed is cumulative across all periods
|
|
64
|
+
const cumulativeElapsed = Math.max(0, Math.min(elapsedSeconds, totalGameDuration));
|
|
65
|
+
return clampBPS((cumulativeElapsed / totalGameDuration) * MAX_BASIS_POINTS);
|
|
66
|
+
}
|
|
67
|
+
// Other sports: elapsed is time in current period only
|
|
68
|
+
const clampedElapsed = Math.max(0, Math.min(elapsedSeconds, totalPeriodDurationInSeconds));
|
|
69
|
+
const periodProgress = clampedElapsed / totalPeriodDurationInSeconds;
|
|
70
|
+
const completedPeriodsProgress = (period - 1) / totalPeriods;
|
|
71
|
+
const currentPeriodContribution = periodProgress / totalPeriods;
|
|
72
|
+
return clampBPS((completedPeriodsProgress + currentPeriodContribution) * MAX_BASIS_POINTS);
|
|
49
73
|
};
|
|
50
|
-
const getGameProgressBPS = (gameClockInSeconds, totalPeriodDurationInSeconds, period, totalPeriods, sportGroup, clockCountUp) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
return calculateGameProgressBPSWithPeriodsOnly(period, totalPeriods);
|
|
54
|
-
default:
|
|
55
|
-
if (clockCountUp) {
|
|
56
|
-
return calculateGameProgressBPSWithGameClockCountUp(gameClockInSeconds, totalPeriodDurationInSeconds, totalPeriods, period);
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return calculateGameProgressBPSWithGameClockCountDown(gameClockInSeconds, totalPeriodDurationInSeconds, totalPeriods, period);
|
|
60
|
-
}
|
|
74
|
+
const getGameProgressBPS = (gameClockInSeconds, totalPeriodDurationInSeconds, period, totalPeriods, sportGroup, clockCountUp, isTopOfInning) => {
|
|
75
|
+
if (sportGroup === client_1.SportGroup.Baseball) {
|
|
76
|
+
return (0, exports.calculateBaseballProgressBPS)(period, totalPeriods, isTopOfInning ?? true);
|
|
61
77
|
}
|
|
78
|
+
const isCumulative = sportGroup === client_1.SportGroup.Soccer;
|
|
79
|
+
const elapsedSeconds = getElapsedSeconds(gameClockInSeconds, totalPeriodDurationInSeconds, period, isCumulative, clockCountUp);
|
|
80
|
+
return calculateProgressBPS(elapsedSeconds, totalPeriodDurationInSeconds, totalPeriods, period, isCumulative);
|
|
62
81
|
};
|
|
63
82
|
exports.getGameProgressBPS = getGameProgressBPS;
|
|
64
83
|
//# sourceMappingURL=game.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"game.utils.js","sourceRoot":"","sources":["../../../../src/server/utils/game_progress/game.utils.ts"],"names":[],"mappings":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,CAAA;IAC1F,MAAM,cAAc,GAAG,cAAc,GAAG,4BAA4B,CAAA;IACpE,MAAM,wBAAwB,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,YAAY,CAAA;IAC5D,MAAM,yBAAyB,GAAG,cAAc,GAAG,YAAY,CAAA;IAE/D,OAAO,QAAQ,CAAC,CAAC,wBAAwB,GAAG,yBAAyB,CAAC,GAAG,gBAAgB,CAAC,CAAA;AAC9F,CAAC,CAAA;AAEM,MAAM,kBAAkB,GAAG,CAC9B,kBAA0B,EAC1B,4BAAoC,EACpC,MAAc,EACd,YAAoB,EACpB,UAAsB,EACtB,YAAqB,EACrB,aAAuB,EACV,EAAE;IACf,IAAI,UAAU,KAAK,mBAAU,CAAC,QAAQ,EAAE,CAAC;QACrC,OAAO,IAAA,oCAA4B,EAAC,MAAM,EAAE,YAAY,EAAE,aAAa,IAAI,IAAI,CAAC,CAAA;IACpF,CAAC;IAED,MAAM,YAAY,GAAG,UAAU,KAAK,mBAAU,CAAC,MAAM,CAAA;IAErD,MAAM,cAAc,GAAG,iBAAiB,CAAC,kBAAkB,EAAE,4BAA4B,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,CAAC,CAAA;IAE9H,OAAO,oBAAoB,CAAC,cAAc,EAAE,4BAA4B,EAAE,YAAY,EAAE,MAAM,EAAE,YAAY,CAAC,CAAA;AACjH,CAAC,CAAA;AAlBY,QAAA,kBAAkB,sBAkB9B"}
|
|
@@ -61,6 +61,8 @@ const parseGameClockToSeconds = (gameClock) => {
|
|
|
61
61
|
if (match?.[1] && match?.[2]) {
|
|
62
62
|
const minutes = parseInt(match[1], 10);
|
|
63
63
|
const seconds = parseInt(match[2], 10);
|
|
64
|
+
if (seconds >= 60)
|
|
65
|
+
return null; // Invalid seconds
|
|
64
66
|
return minutes * 60 + seconds;
|
|
65
67
|
}
|
|
66
68
|
break;
|
|
@@ -70,6 +72,8 @@ const parseGameClockToSeconds = (gameClock) => {
|
|
|
70
72
|
if (match?.[1] && match?.[2]) {
|
|
71
73
|
const minutes = parseInt(match[1], 10);
|
|
72
74
|
const seconds = parseInt(match[2], 10);
|
|
75
|
+
if (seconds >= 60)
|
|
76
|
+
return null; // Invalid seconds
|
|
73
77
|
return minutes * 60 + seconds;
|
|
74
78
|
}
|
|
75
79
|
break;
|
|
@@ -79,6 +83,8 @@ const parseGameClockToSeconds = (gameClock) => {
|
|
|
79
83
|
if (match?.[1] && match?.[2]) {
|
|
80
84
|
const minutes = parseInt(match[1], 10);
|
|
81
85
|
const seconds = parseInt(match[2], 10);
|
|
86
|
+
if (seconds >= 60)
|
|
87
|
+
return null; // Invalid seconds
|
|
82
88
|
return minutes * 60 + seconds;
|
|
83
89
|
}
|
|
84
90
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../../../src/server/utils/game_progress/parser.ts"],"names":[],"mappings":";;;AAAA,yEAAgF;AAEhF;;GAEG;AACH,MAAM,cAAc,GAAG;IACnB,OAAO,EAAE,UAAU;IACnB,UAAU,EAAE,OAAO;IACnB,aAAa,EAAE,qBAAqB;IACpC,WAAW,EAAE,4BAA4B;IACzC,gBAAgB,EAAE,2BAA2B;CACvC,CAAA;AAEV;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,CAAC,SAAiB,EAAoB,EAAE;IAC1E,IAAI,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QACzC,OAAO,wBAAgB,CAAC,cAAc,CAAA;IAC1C,CAAC;IACD,IAAI,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5C,OAAO,wBAAgB,CAAC,UAAU,CAAA;IACtC,CAAC;IACD,IAAI,cAAc,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC/C,OAAO,wBAAgB,CAAC,mBAAmB,CAAA;IAC/C,CAAC;IACD,IAAI,cAAc,CAAC,WAAW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ts",
|
|
6
6
|
"exports": {
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"@types/amqplib": "^0.10.7",
|
|
103
103
|
"amqplib": "^0.10.9",
|
|
104
104
|
"axios": "^1.12.2",
|
|
105
|
+
"axios-retry": "^4.5.0",
|
|
105
106
|
"bson": "^6.10.4",
|
|
106
107
|
"coralogix-logger": "^1.1.34",
|
|
107
108
|
"dayjs": "^1.11.18",
|
package/prisma/schema.prisma
CHANGED
|
@@ -168,6 +168,7 @@ model Fixture {
|
|
|
168
168
|
homeTeam Json
|
|
169
169
|
awayTeam Json
|
|
170
170
|
fixtureStatus FixtureStatus
|
|
171
|
+
sportGroup SportGroup? //optional for now so we don't break staging
|
|
171
172
|
registeredChainIds Int[] // list of chain IDs where this fixture is registered
|
|
172
173
|
|
|
173
174
|
leagueObjectId String @db.ObjectId
|
|
@@ -244,18 +245,20 @@ model LevrGame {
|
|
|
244
245
|
}
|
|
245
246
|
|
|
246
247
|
model Odds {
|
|
247
|
-
objectId
|
|
248
|
-
txHash
|
|
249
|
-
odds
|
|
250
|
-
prices
|
|
251
|
-
timestamp
|
|
252
|
-
marketType
|
|
253
|
-
details
|
|
254
|
-
gamePhase
|
|
255
|
-
gamePeriod
|
|
256
|
-
gameClock
|
|
257
|
-
|
|
258
|
-
|
|
248
|
+
objectId String @id @default(auto()) @map("_id") @db.ObjectId
|
|
249
|
+
txHash String
|
|
250
|
+
odds Json // define for the specific market type
|
|
251
|
+
prices Json
|
|
252
|
+
timestamp DateTime
|
|
253
|
+
marketType MarketType
|
|
254
|
+
details Json? // the unique details for the odds
|
|
255
|
+
gamePhase GamePhase
|
|
256
|
+
gamePeriod Int
|
|
257
|
+
gameClock Int
|
|
258
|
+
gameProgressBps Int?
|
|
259
|
+
chainId Int
|
|
260
|
+
marketPhase MarketStatus
|
|
261
|
+
provider String? // optional for now to avoid breaking staging
|
|
259
262
|
|
|
260
263
|
levrGameObjectId String @db.ObjectId
|
|
261
264
|
marketObjectId String @db.ObjectId
|
|
@@ -321,9 +324,10 @@ model User {
|
|
|
321
324
|
requireWithdrawalConfirmation Boolean @default(true)
|
|
322
325
|
|
|
323
326
|
// Inverse relations (these fix your P1012 errors)
|
|
324
|
-
referralsMade
|
|
325
|
-
referredBy
|
|
326
|
-
referralRewards
|
|
327
|
+
referralsMade Referral[] @relation("ReferrerRelations") // users they referred
|
|
328
|
+
referredBy Referral[] @relation("ReferredRelations") // who referred them
|
|
329
|
+
referralRewards ReferralReward[] @relation("UserRewards") // their reward entries
|
|
330
|
+
transactionHistory TransactionHistory[] @relation("TransactionHistory") // transaction history
|
|
327
331
|
|
|
328
332
|
createdAt DateTime @default(now())
|
|
329
333
|
updatedAt DateTime @updatedAt
|
|
@@ -466,3 +470,38 @@ model AuditLog {
|
|
|
466
470
|
@@index([timestamp])
|
|
467
471
|
@@index([userId])
|
|
468
472
|
}
|
|
473
|
+
|
|
474
|
+
enum TransactionHistoryType {
|
|
475
|
+
Deposit
|
|
476
|
+
Withdrawal
|
|
477
|
+
Wager
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
enum TransactionHistoryStatus {
|
|
481
|
+
Completed
|
|
482
|
+
Pending
|
|
483
|
+
Failed
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
enum TransactionHistoryDescription {
|
|
487
|
+
BetPlaced
|
|
488
|
+
Deposited
|
|
489
|
+
Withdrawn
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
model TransactionHistory {
|
|
493
|
+
objectId String @id @default(cuid()) @map("_id")
|
|
494
|
+
id String
|
|
495
|
+
type TransactionHistoryType
|
|
496
|
+
status TransactionHistoryStatus
|
|
497
|
+
timestamp DateTime @default(now())
|
|
498
|
+
balance Float
|
|
499
|
+
description TransactionHistoryDescription
|
|
500
|
+
amount Float
|
|
501
|
+
// Relations
|
|
502
|
+
walletAddress String
|
|
503
|
+
user User @relation("TransactionHistory", fields: [walletAddress], references: [walletAddress])
|
|
504
|
+
|
|
505
|
+
@@index([timestamp])
|
|
506
|
+
@@index([walletAddress])
|
|
507
|
+
}
|