From c4e3376313a427c50289c78bd4225e9c41853fe8 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Mon, 13 Jun 2022 21:14:52 -0500 Subject: [PATCH] check if shares below min pool qty for sales --- functions/src/sell-shares.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/functions/src/sell-shares.ts b/functions/src/sell-shares.ts index 1d0a4c23..dd4e2ec5 100644 --- a/functions/src/sell-shares.ts +++ b/functions/src/sell-shares.ts @@ -3,7 +3,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 { getCpmmSellBetInfo } from '../../common/sell-bet' import { addObjects, removeUndefinedProps } from '../../common/util/object' @@ -57,8 +57,12 @@ export const sellshares = newEndpoint(['POST'], async (req, auth) => { prevLoanAmount ) - if (!isFinite(newP)) { - throw new APIError(500, 'Trade rejected due to overflow error.') + if ( + !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()