@moneypot/hub 1.9.0-dev.1 → 1.9.0-dev.3
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,6 +1,6 @@
|
|
|
1
1
|
import { access, context, object, ObjectStep, sideEffect, } from "postgraphile/grafast";
|
|
2
2
|
import { gql, makeExtendSchemaPlugin } from "postgraphile/utils";
|
|
3
|
-
import
|
|
3
|
+
import * as z from "zod";
|
|
4
4
|
import { GraphQLError } from "graphql";
|
|
5
5
|
import { DbHashKind, dbLockPlayerBalanceAndHouseBankroll, exactlyOneRow, maybeOneRow, superuserPool, withPgPoolTransaction, } from "../db/index.js";
|
|
6
6
|
import { assert } from "tsafe";
|
|
@@ -8,6 +8,7 @@ import { dbInsertHubHash, dbLockHubHashChain, } from "../hash-chain/db-hash-chai
|
|
|
8
8
|
import { getIntermediateHash, getPreimageHash, } from "../hash-chain/get-hash.js";
|
|
9
9
|
import { makeFinalHash, pickRandomOutcome } from "../hash-chain/util.js";
|
|
10
10
|
import { logger } from "../logger.js";
|
|
11
|
+
import { formatCurrency } from "@moneypot/frontend-utils";
|
|
11
12
|
const FLOAT_EPSILON = 1e-10;
|
|
12
13
|
function sum(ns) {
|
|
13
14
|
return ns.reduce((a, b) => a + b, 0);
|
|
@@ -65,8 +66,8 @@ const BetConfigsSchema = z.record(BetKindSchema, z.object({
|
|
|
65
66
|
.optional(),
|
|
66
67
|
}));
|
|
67
68
|
const RiskLimitsSchema = z.object({
|
|
68
|
-
maxWager: z.number().finite().int().positive(),
|
|
69
|
-
maxPayout: z.number().finite().int().positive(),
|
|
69
|
+
maxWager: z.number().finite().int().positive().optional(),
|
|
70
|
+
maxPayout: z.number().finite().int().positive().optional(),
|
|
70
71
|
});
|
|
71
72
|
export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
72
73
|
BetConfigsSchema.parse(betConfigs);
|
|
@@ -154,7 +155,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
154
155
|
const dbCurrency = await superuserPool
|
|
155
156
|
.query({
|
|
156
157
|
text: `
|
|
157
|
-
SELECT key
|
|
158
|
+
SELECT key, display_unit_name, display_unit_scale
|
|
158
159
|
FROM hub.currency
|
|
159
160
|
WHERE key = $1
|
|
160
161
|
AND casino_id = $2
|
|
@@ -192,7 +193,7 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
192
193
|
const maxProfitMultiplier = Math.max(...input.outcomes.map((o) => o.profit));
|
|
193
194
|
const maxPayout = input.wager * maxProfitMultiplier;
|
|
194
195
|
if (maxPayout > dbHouseBankroll.amount) {
|
|
195
|
-
throw new GraphQLError(`House cannot cover potential payout (${maxPayout}). Bankroll: ${dbHouseBankroll.amount}`);
|
|
196
|
+
throw new GraphQLError(`House cannot cover potential payout (${maxPayout} units). Bankroll: ${dbHouseBankroll.amount} units`);
|
|
196
197
|
}
|
|
197
198
|
const riskLimitsResult = RiskLimitsSchema.safeParse(betConfig.riskPolicy
|
|
198
199
|
? betConfig.riskPolicy({
|
|
@@ -202,16 +203,29 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
202
203
|
})
|
|
203
204
|
: {});
|
|
204
205
|
if (!riskLimitsResult.success) {
|
|
205
|
-
|
|
206
|
+
logger.error(riskLimitsResult.error, "Invalid risk policy");
|
|
207
|
+
throw new GraphQLError("Invalid risk policy");
|
|
206
208
|
}
|
|
207
209
|
const riskLimits = riskLimitsResult.data;
|
|
208
210
|
if (riskLimits.maxWager != null &&
|
|
209
211
|
input.wager > riskLimits.maxWager) {
|
|
210
|
-
throw new GraphQLError(`Wager exceeds limit (${riskLimits.maxWager
|
|
212
|
+
throw new GraphQLError(`Wager exceeds limit (${formatCurrency(riskLimits.maxWager, {
|
|
213
|
+
displayUnitName: dbCurrency.display_unit_name,
|
|
214
|
+
displayUnitScale: dbCurrency.display_unit_scale,
|
|
215
|
+
})}). Your wager: ${formatCurrency(input.wager, {
|
|
216
|
+
displayUnitName: dbCurrency.display_unit_name,
|
|
217
|
+
displayUnitScale: dbCurrency.display_unit_scale,
|
|
218
|
+
})}`);
|
|
211
219
|
}
|
|
212
220
|
if (riskLimits.maxPayout != null &&
|
|
213
221
|
maxPayout > riskLimits.maxPayout) {
|
|
214
|
-
throw new GraphQLError(`Payout exceeds limit (${riskLimits.maxPayout
|
|
222
|
+
throw new GraphQLError(`Payout exceeds limit (${formatCurrency(riskLimits.maxPayout, {
|
|
223
|
+
displayUnitName: dbCurrency.display_unit_name,
|
|
224
|
+
displayUnitScale: dbCurrency.display_unit_scale,
|
|
225
|
+
})}). Your payout: ${formatCurrency(maxPayout, {
|
|
226
|
+
displayUnitName: dbCurrency.display_unit_name,
|
|
227
|
+
displayUnitScale: dbCurrency.display_unit_scale,
|
|
228
|
+
})}`);
|
|
215
229
|
}
|
|
216
230
|
const dbHashChain = await dbLockHubHashChain(pgClient, {
|
|
217
231
|
userId: session.user_id,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneypot/hub",
|
|
3
|
-
"version": "1.9.0-dev.
|
|
3
|
+
"version": "1.9.0-dev.3",
|
|
4
4
|
"author": "moneypot.com",
|
|
5
5
|
"homepage": "https://moneypot.com/hub",
|
|
6
6
|
"keywords": [
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
48
|
"@graphile-contrib/pg-omit-archived": "^4.0.0-beta.4",
|
|
49
|
+
"@moneypot/frontend-utils": "^0.0.3",
|
|
49
50
|
"@moneypot/hash-herald": "^1.0.0",
|
|
50
51
|
"@moneypot/pg-upgrade-schema": "^2.0.4",
|
|
51
52
|
"@noble/curves": "^1.5.0",
|