diff --git a/common/contract.ts b/common/contract.ts index f75cfa4b..8427c84b 100644 --- a/common/contract.ts +++ b/common/contract.ts @@ -94,6 +94,9 @@ export type outcomeType = AnyOutcomeType['outcomeType'] export type resolution = 'YES' | 'NO' | 'MKT' | 'CANCEL' export const RESOLUTIONS = ['YES', 'NO', 'MKT', 'CANCEL'] as const export const OUTCOME_TYPES = ['BINARY', 'FREE_RESPONSE', 'NUMERIC'] as const + export const MAX_QUESTION_LENGTH = 480 export const MAX_DESCRIPTION_LENGTH = 10000 export const MAX_TAG_LENGTH = 60 + +export const CPMM_MIN_POOL_QTY = 0.01 diff --git a/functions/src/place-bet.ts b/functions/src/place-bet.ts index 3de47aef..26678f24 100644 --- a/functions/src/place-bet.ts +++ b/functions/src/place-bet.ts @@ -2,7 +2,7 @@ import * as admin from 'firebase-admin' import { z } from 'zod' import { APIError, newEndpoint, validate } from './api' -import { Contract } from '../../common/contract' +import { Contract, CPMM_MIN_POOL_QTY } from '../../common/contract' import { User } from '../../common/user' import { BetInfo, @@ -81,8 +81,13 @@ export const placebet = newEndpoint(['POST'], async (req, [bettor, _]) => { } })() - if (newP != null && !isFinite(newP)) { - throw new APIError(400, 'Trade rejected due to overflow error.') + if ( + mechanism == 'cpmm-1' && + (!newP || + !isFinite(newP) || + Math.min(...Object.values(newPool ?? {})) < CPMM_MIN_POOL_QTY) + ) { + throw new APIError(400, 'Bet too large for current liquidity pool.') } const newBalance = user.balance - amount - loanAmount