@gamelobby/common 1.0.373 → 1.0.375

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.
@@ -76,3 +76,4 @@ export * from './wallet.interface';
76
76
  export * from './imageGallery.interface';
77
77
  export * from './gameDayStatus.interface';
78
78
  export * from './gameDay.interface';
79
+ export * from './prizePool.interface';
@@ -88,3 +88,4 @@ __exportStar(require("./wallet.interface"), exports);
88
88
  __exportStar(require("./imageGallery.interface"), exports);
89
89
  __exportStar(require("./gameDayStatus.interface"), exports);
90
90
  __exportStar(require("./gameDay.interface"), exports);
91
+ __exportStar(require("./prizePool.interface"), exports);
@@ -0,0 +1,123 @@
1
+ /**
2
+ * Prize Pool Configuration
3
+ * Defines how coins are collected and distributed in tournaments
4
+ */
5
+ /**
6
+ * Prize distribution per position
7
+ */
8
+ export interface PrizePosition {
9
+ position: number;
10
+ percentage: number;
11
+ minAmount?: number;
12
+ label?: string;
13
+ }
14
+ /**
15
+ * Platform fee configuration
16
+ */
17
+ export interface PlatformFeeConfig {
18
+ enabled: boolean;
19
+ percentage: number;
20
+ minFee?: number;
21
+ maxFee?: number;
22
+ }
23
+ /**
24
+ * Prize pool source configuration
25
+ */
26
+ export declare enum PrizePoolSource {
27
+ ENTRY_FEES = "entry_fees",
28
+ GUARANTEED = "guaranteed",
29
+ MIXED = "mixed"
30
+ }
31
+ /**
32
+ * Prize pool status
33
+ */
34
+ export declare enum PrizePoolStatus {
35
+ COLLECTING = "collecting",
36
+ LOCKED = "locked",
37
+ DISTRIBUTING = "distributing",
38
+ DISTRIBUTED = "distributed",
39
+ REFUNDED = "refunded"
40
+ }
41
+ /**
42
+ * Individual escrow hold for a participant
43
+ */
44
+ export interface ParticipantEscrow {
45
+ participantId: number;
46
+ participantType: 'team' | 'player';
47
+ amount: number;
48
+ currency: string;
49
+ holdId?: string;
50
+ status: 'held' | 'released' | 'refunded';
51
+ heldAt: Date;
52
+ releasedAt?: Date;
53
+ refundedAt?: Date;
54
+ }
55
+ /**
56
+ * Prize distribution record
57
+ */
58
+ export interface PrizeDistributionRecord {
59
+ participantId: number;
60
+ participantType: 'team' | 'player';
61
+ participantName: string;
62
+ position: number;
63
+ percentage: number;
64
+ amount: number;
65
+ currency: string;
66
+ transactionId?: string;
67
+ distributedAt?: Date;
68
+ status: 'pending' | 'distributed' | 'failed';
69
+ errorMessage?: string;
70
+ }
71
+ /**
72
+ * Complete Prize Pool Configuration for a Room
73
+ */
74
+ export interface PrizePoolConfig {
75
+ enabled: boolean;
76
+ source: PrizePoolSource;
77
+ currency: string;
78
+ entryFee: number;
79
+ entryFeePerPlayer?: boolean;
80
+ guaranteedAmount?: number;
81
+ distribution: PrizePosition[];
82
+ platformFee: PlatformFeeConfig;
83
+ minParticipantsForPrizes: number;
84
+ insufficientParticipantsAction: 'refund_all' | 'distribute_anyway' | 'cancel';
85
+ }
86
+ /**
87
+ * Live Prize Pool State (runtime state)
88
+ */
89
+ export interface PrizePoolState {
90
+ roomId: number;
91
+ gameDayId?: string;
92
+ totalCollected: number;
93
+ guaranteedAmount: number;
94
+ platformFeeAmount: number;
95
+ distributedAmount: number;
96
+ totalPoolAmount: number;
97
+ availableForDistribution: number;
98
+ status: PrizePoolStatus;
99
+ participantCount: number;
100
+ escrows: ParticipantEscrow[];
101
+ distributions: PrizeDistributionRecord[];
102
+ createdAt: Date;
103
+ updatedAt: Date;
104
+ lockedAt?: Date;
105
+ distributedAt?: Date;
106
+ refundedAt?: Date;
107
+ }
108
+ /**
109
+ * Default prize distributions for common tournament sizes
110
+ */
111
+ export declare const DEFAULT_PRIZE_DISTRIBUTIONS: Record<string, PrizePosition[]>;
112
+ /**
113
+ * Helper to calculate prize amount for a position
114
+ */
115
+ export declare function calculatePrizeAmount(position: number, totalPool: number, distribution: PrizePosition[]): number;
116
+ /**
117
+ * Validate that distribution percentages sum to 100 (or less)
118
+ */
119
+ export declare function validateDistribution(distribution: PrizePosition[]): {
120
+ valid: boolean;
121
+ totalPercentage: number;
122
+ message?: string;
123
+ };
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+ /**
3
+ * Prize Pool Configuration
4
+ * Defines how coins are collected and distributed in tournaments
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.validateDistribution = exports.calculatePrizeAmount = exports.DEFAULT_PRIZE_DISTRIBUTIONS = exports.PrizePoolStatus = exports.PrizePoolSource = void 0;
8
+ /**
9
+ * Prize pool source configuration
10
+ */
11
+ var PrizePoolSource;
12
+ (function (PrizePoolSource) {
13
+ PrizePoolSource["ENTRY_FEES"] = "entry_fees";
14
+ PrizePoolSource["GUARANTEED"] = "guaranteed";
15
+ PrizePoolSource["MIXED"] = "mixed"; // Entry fees + guaranteed minimum
16
+ })(PrizePoolSource = exports.PrizePoolSource || (exports.PrizePoolSource = {}));
17
+ /**
18
+ * Prize pool status
19
+ */
20
+ var PrizePoolStatus;
21
+ (function (PrizePoolStatus) {
22
+ PrizePoolStatus["COLLECTING"] = "collecting";
23
+ PrizePoolStatus["LOCKED"] = "locked";
24
+ PrizePoolStatus["DISTRIBUTING"] = "distributing";
25
+ PrizePoolStatus["DISTRIBUTED"] = "distributed";
26
+ PrizePoolStatus["REFUNDED"] = "refunded"; // Tournament cancelled, all refunded
27
+ })(PrizePoolStatus = exports.PrizePoolStatus || (exports.PrizePoolStatus = {}));
28
+ /**
29
+ * Default prize distributions for common tournament sizes
30
+ */
31
+ exports.DEFAULT_PRIZE_DISTRIBUTIONS = {
32
+ // Winner takes all
33
+ 'winner_takes_all': [
34
+ { position: 1, percentage: 100, label: 'Champion' }
35
+ ],
36
+ // Top 2
37
+ 'top_2': [
38
+ { position: 1, percentage: 70, label: 'Champion' },
39
+ { position: 2, percentage: 30, label: 'Runner-up' }
40
+ ],
41
+ // Top 3
42
+ 'top_3': [
43
+ { position: 1, percentage: 50, label: 'Champion' },
44
+ { position: 2, percentage: 30, label: 'Runner-up' },
45
+ { position: 3, percentage: 20, label: '3rd Place' }
46
+ ],
47
+ // Top 4
48
+ 'top_4': [
49
+ { position: 1, percentage: 40, label: 'Champion' },
50
+ { position: 2, percentage: 25, label: 'Runner-up' },
51
+ { position: 3, percentage: 20, label: '3rd Place' },
52
+ { position: 4, percentage: 15, label: '4th Place' }
53
+ ],
54
+ // Top 8
55
+ 'top_8': [
56
+ { position: 1, percentage: 30, label: 'Champion' },
57
+ { position: 2, percentage: 20, label: 'Runner-up' },
58
+ { position: 3, percentage: 15, label: '3rd Place' },
59
+ { position: 4, percentage: 10, label: '4th Place' },
60
+ { position: 5, percentage: 7, label: '5th-8th' },
61
+ { position: 6, percentage: 7, label: '5th-8th' },
62
+ { position: 7, percentage: 6, label: '5th-8th' },
63
+ { position: 8, percentage: 5, label: '5th-8th' }
64
+ ]
65
+ };
66
+ /**
67
+ * Helper to calculate prize amount for a position
68
+ */
69
+ function calculatePrizeAmount(position, totalPool, distribution) {
70
+ var positionConfig = distribution.find(function (d) { return d.position === position; });
71
+ if (!positionConfig)
72
+ return 0;
73
+ var calculatedAmount = Math.floor((totalPool * positionConfig.percentage) / 100);
74
+ // Apply minimum if configured
75
+ if (positionConfig.minAmount && calculatedAmount < positionConfig.minAmount) {
76
+ return positionConfig.minAmount;
77
+ }
78
+ return calculatedAmount;
79
+ }
80
+ exports.calculatePrizeAmount = calculatePrizeAmount;
81
+ /**
82
+ * Validate that distribution percentages sum to 100 (or less)
83
+ */
84
+ function validateDistribution(distribution) {
85
+ var totalPercentage = distribution.reduce(function (sum, pos) { return sum + pos.percentage; }, 0);
86
+ if (totalPercentage > 100) {
87
+ return {
88
+ valid: false,
89
+ totalPercentage: totalPercentage,
90
+ message: "Distribution percentages sum to " + totalPercentage + "%, which exceeds 100%"
91
+ };
92
+ }
93
+ if (totalPercentage < 100) {
94
+ return {
95
+ valid: true,
96
+ totalPercentage: totalPercentage,
97
+ message: "Distribution uses " + totalPercentage + "%, remaining " + (100 - totalPercentage) + "% goes to platform"
98
+ };
99
+ }
100
+ return {
101
+ valid: true,
102
+ totalPercentage: totalPercentage
103
+ };
104
+ }
105
+ exports.validateDistribution = validateDistribution;
@@ -6,6 +6,7 @@ import { Game } from "./game.interface";
6
6
  import { GameDay } from "./gameDay.interface";
7
7
  import { QualificationRules } from "./gameDayStatus.interface";
8
8
  import { GameMode } from "./gamemode.interface";
9
+ import { PrizePoolConfig } from "./prizePool.interface";
9
10
  import { Platform } from "./platform.interface";
10
11
  import { Points } from "./points.interface";
11
12
  import { RegistrationType } from "./registrationType";
@@ -107,4 +108,5 @@ export interface Room {
107
108
  bannerImageUrl?: string;
108
109
  showOpponentInInvitation?: boolean;
109
110
  qualificationRules?: QualificationRules;
111
+ prizePoolConfig?: PrizePoolConfig;
110
112
  }
@@ -19,6 +19,13 @@ export declare enum Subjects {
19
19
  EscrowHoldReleased = "escrow:hold-released",
20
20
  EscrowHoldRefunded = "escrow:hold-refunded",
21
21
  EscrowHoldDisputed = "escrow:hold-disputed",
22
+ PrizePoolCreated = "prizepool:created",
23
+ PrizePoolContribution = "prizepool:contribution",
24
+ PrizePoolContributionRefunded = "prizepool:contribution-refunded",
25
+ PrizePoolLocked = "prizepool:locked",
26
+ PrizePoolDistributed = "prizepool:distributed",
27
+ PrizePoolRefunded = "prizepool:refunded",
28
+ PrizePoolCancelled = "prizepool:cancelled",
22
29
  ExternalPaymentReceived = "external-payment:received",
23
30
  ExternalPaymentProcessed = "external-payment:processed",
24
31
  ExternalPaymentFailed = "external-payment:failed",
@@ -29,6 +29,14 @@ var Subjects;
29
29
  Subjects["EscrowHoldReleased"] = "escrow:hold-released";
30
30
  Subjects["EscrowHoldRefunded"] = "escrow:hold-refunded";
31
31
  Subjects["EscrowHoldDisputed"] = "escrow:hold-disputed";
32
+ // Prize Pool Topics
33
+ Subjects["PrizePoolCreated"] = "prizepool:created";
34
+ Subjects["PrizePoolContribution"] = "prizepool:contribution";
35
+ Subjects["PrizePoolContributionRefunded"] = "prizepool:contribution-refunded";
36
+ Subjects["PrizePoolLocked"] = "prizepool:locked";
37
+ Subjects["PrizePoolDistributed"] = "prizepool:distributed";
38
+ Subjects["PrizePoolRefunded"] = "prizepool:refunded";
39
+ Subjects["PrizePoolCancelled"] = "prizepool:cancelled";
32
40
  // External Payment Topics
33
41
  Subjects["ExternalPaymentReceived"] = "external-payment:received";
34
42
  Subjects["ExternalPaymentProcessed"] = "external-payment:processed";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamelobby/common",
3
- "version": "1.0.373",
3
+ "version": "1.0.375",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",