@moneypot/hub 1.3.0-dev.4 → 1.3.0-dev.5
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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { Result } from "../util.js";
|
|
2
3
|
declare const InputSchema: z.ZodObject<{
|
|
3
4
|
kind: z.ZodString;
|
|
4
5
|
wager: z.ZodNumber;
|
|
@@ -26,6 +27,7 @@ declare const InputSchema: z.ZodObject<{
|
|
|
26
27
|
profit: number;
|
|
27
28
|
}[]>;
|
|
28
29
|
hashChainId: z.ZodString;
|
|
30
|
+
metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
29
31
|
}, "strict", z.ZodTypeAny, {
|
|
30
32
|
currency: string;
|
|
31
33
|
kind: string;
|
|
@@ -35,6 +37,7 @@ declare const InputSchema: z.ZodObject<{
|
|
|
35
37
|
weight: number;
|
|
36
38
|
profit: number;
|
|
37
39
|
}[];
|
|
40
|
+
metadata?: Record<string, any> | undefined;
|
|
38
41
|
}, {
|
|
39
42
|
currency: string;
|
|
40
43
|
kind: string;
|
|
@@ -44,12 +47,13 @@ declare const InputSchema: z.ZodObject<{
|
|
|
44
47
|
weight: number;
|
|
45
48
|
profit: number;
|
|
46
49
|
}[];
|
|
50
|
+
metadata?: Record<string, any> | undefined;
|
|
47
51
|
}>;
|
|
48
52
|
type Input = z.infer<typeof InputSchema>;
|
|
49
53
|
export type OutcomeBetConfig = {
|
|
50
54
|
houseEdge: number;
|
|
51
55
|
saveOutcomes: boolean;
|
|
52
|
-
|
|
56
|
+
processMetadata?: (input: Input) => Result<Record<string, any>, string>;
|
|
53
57
|
};
|
|
54
58
|
export type OutcomeBetConfigMap<BetKind extends string> = {
|
|
55
59
|
[betKind in BetKind]: OutcomeBetConfig;
|
|
@@ -38,6 +38,7 @@ const InputSchema = z
|
|
|
38
38
|
.refine((data) => data.some((o) => o.profit < 0), "At least one outcome should have profit < 0")
|
|
39
39
|
.refine((data) => data.some((o) => o.profit > 0), "At least one outcome should have profit > 0"),
|
|
40
40
|
hashChainId: z.string().uuid("Invalid hash chain ID"),
|
|
41
|
+
metadata: z.record(z.string(), z.any()).optional(),
|
|
41
42
|
})
|
|
42
43
|
.strict();
|
|
43
44
|
const BetKindSchema = z
|
|
@@ -51,7 +52,7 @@ const BetConfigsSchema = z.record(BetKindSchema, z.object({
|
|
|
51
52
|
.gte(0, "House edge must be >= 0")
|
|
52
53
|
.lte(1, "House edge must be <= 1"),
|
|
53
54
|
saveOutcomes: z.boolean(),
|
|
54
|
-
|
|
55
|
+
processMetadata: z
|
|
55
56
|
.function()
|
|
56
57
|
.args(InputSchema)
|
|
57
58
|
.returns(z.record(z.string(), z.any()))
|
|
@@ -73,6 +74,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
73
74
|
currency: String!
|
|
74
75
|
outcomes: [HubOutcomeInput!]!
|
|
75
76
|
hashChainId: UUID!
|
|
77
|
+
metadata: JSON
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
type HubMakeOutcomeBetOk {
|
|
@@ -118,6 +120,16 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
118
120
|
if (!betKinds.includes(rawInput.kind)) {
|
|
119
121
|
throw new GraphQLError(`Invalid bet kind`);
|
|
120
122
|
}
|
|
123
|
+
let validatedMetadata;
|
|
124
|
+
if (betConfig.processMetadata) {
|
|
125
|
+
const result = betConfig.processMetadata(input);
|
|
126
|
+
if (result.ok) {
|
|
127
|
+
validatedMetadata = result.value;
|
|
128
|
+
}
|
|
129
|
+
else {
|
|
130
|
+
throw new GraphQLError(`Invalid metadata: ${result.error}`);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
121
133
|
const houseEV = calculateHouseEV(input.outcomes);
|
|
122
134
|
const minHouseEV = Math.max(0, betConfig.houseEdge - FLOAT_EPSILON);
|
|
123
135
|
if (houseEV < minHouseEV) {
|
|
@@ -270,9 +282,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
270
282
|
user_id: session.user_id,
|
|
271
283
|
casino_id: session.casino_id,
|
|
272
284
|
experience_id: session.experience_id,
|
|
273
|
-
metadata:
|
|
274
|
-
? await betConfig.getMetadata(input)
|
|
275
|
-
: {},
|
|
285
|
+
metadata: validatedMetadata,
|
|
276
286
|
...(betConfig.saveOutcomes
|
|
277
287
|
? {
|
|
278
288
|
outcomes: input.outcomes,
|