check if shares below min pool qty for sales

This commit is contained in:
mantikoros 2022-06-13 21:14:52 -05:00
parent dd4444caf9
commit c4e3376313

View File

@ -3,7 +3,7 @@ import * as admin from 'firebase-admin'
import { z } from 'zod' import { z } from 'zod'
import { APIError, newEndpoint, validate } from './api' 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 { User } from '../../common/user'
import { getCpmmSellBetInfo } from '../../common/sell-bet' import { getCpmmSellBetInfo } from '../../common/sell-bet'
import { addObjects, removeUndefinedProps } from '../../common/util/object' import { addObjects, removeUndefinedProps } from '../../common/util/object'
@ -57,8 +57,12 @@ export const sellshares = newEndpoint(['POST'], async (req, auth) => {
prevLoanAmount prevLoanAmount
) )
if (!isFinite(newP)) { if (
throw new APIError(500, 'Trade rejected due to overflow error.') !newP ||
!isFinite(newP) ||
Math.min(...Object.values(newPool ?? {})) < CPMM_MIN_POOL_QTY
) {
throw new APIError(400, 'Sale too large for current liquidity pool.')
} }
const newBetDoc = firestore.collection(`contracts/${contractId}/bets`).doc() const newBetDoc = firestore.collection(`contracts/${contractId}/bets`).doc()