diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index 493b5fa9..b5153355 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -123,6 +123,7 @@ export function calculateCpmmAmountToProb( prob: number, outcome: 'YES' | 'NO' ) { + if (prob <= 0 || prob >= 1 || isNaN(prob)) return Infinity if (outcome === 'NO') prob = 1 - prob // First, find an upper bound that leads to a more extreme probability than prob. diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index a31957cb..426a9371 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -41,7 +41,7 @@ export function AmountInput(props: { {label} = highLimitProb - const betDisabled = isSubmitting || !betAmount || rangeError || error + const outOfRangeError = + (lowLimitProb !== undefined && + (lowLimitProb <= 0 || lowLimitProb >= 100)) || + (highLimitProb !== undefined && + (highLimitProb <= 0 || highLimitProb >= 100)) + + const initialLow = initialProb * 0.9 + const initialHigh = initialProb + (1 - initialProb) * 0.1 + const lowPlaceholder = Math.round( + isPseudoNumeric ? getMappedValue(contract)(initialLow) : initialLow * 100 + ).toString() + const highPlaceholder = Math.round( + isPseudoNumeric ? getMappedValue(contract)(initialHigh) : initialHigh * 100 + ).toString() const hasYesLimitBet = lowLimitProb !== undefined && !!betAmount const hasNoLimitBet = highLimitProb !== undefined && !!betAmount const hasTwoBets = hasYesLimitBet && hasNoLimitBet - const yesLimitProb = (lowLimitProb ?? initialProb * 100) / 100 - const noLimitProb = (highLimitProb ?? initialProb * 100) / 100 + const betDisabled = + isSubmitting || + !betAmount || + rangeError || + outOfRangeError || + error || + (!hasYesLimitBet && !hasNoLimitBet) - const shares = Math.min( - (betAmount ?? 0) / yesLimitProb, - (betAmount ?? 0) / (1 - noLimitProb) - ) - const yesAmount = shares * yesLimitProb - const noAmount = shares * (1 - noLimitProb) + const yesLimitProb = + lowLimitProb === undefined ? undefined : lowLimitProb / 100 + const noLimitProb = + highLimitProb === undefined ? undefined : highLimitProb / 100 + + const shares = + yesLimitProb !== undefined && noLimitProb !== undefined + ? Math.min( + (betAmount ?? 0) / yesLimitProb, + (betAmount ?? 0) / (1 - noLimitProb) + ) + : (betAmount ?? 0) / (yesLimitProb ?? 1 - (noLimitProb ?? 1)) + + const yesAmount = shares * (yesLimitProb ?? 1) + const noAmount = shares * (1 - (noLimitProb ?? 1)) const profitIfBothFilled = shares - (yesAmount + noAmount) @@ -466,7 +493,7 @@ function LimitOrderPanel(props: { 'YES', yesAmount, contract, - yesLimitProb, + Math.min(yesLimitProb ?? initialLow, 0.999), unfilledBets as LimitBet[] ) const yesReturnPercent = formatPercent(yesReturn) @@ -480,7 +507,7 @@ function LimitOrderPanel(props: { 'NO', noAmount, contract, - noLimitProb, + Math.max(noLimitProb ?? initialHigh, 0.01), unfilledBets as LimitBet[] ) const noReturnPercent = formatPercent(noReturn) @@ -488,8 +515,8 @@ function LimitOrderPanel(props: { return (