Fix overflow (#472)
* fix pool overflow bug by enforcing minimum share quantity in pool * CPMM_MIN_POOL_QTY = 0.01 * use newPool
This commit is contained in:
parent
6fac56d2c9
commit
c59d93979c
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user