Rename open bets to limit bets. Tweak payout calculation

This commit is contained in:
James Grugett 2022-07-05 16:39:40 -04:00
parent 871271ecbb
commit 6cea9de8d3
3 changed files with 29 additions and 15 deletions

View File

@ -45,7 +45,7 @@ import { ProbabilityInput } from './probability-input'
import { track } from 'web/lib/service/analytics' import { track } from 'web/lib/service/analytics'
import { removeUndefinedProps } from 'common/util/object' import { removeUndefinedProps } from 'common/util/object'
import { useUnfilledBets } from 'web/hooks/use-bets' import { useUnfilledBets } from 'web/hooks/use-bets'
import { OpenBets } from './open-bets' import { LimitBets } from './limit-bets'
export function BetPanel(props: { export function BetPanel(props: {
contract: CPMMBinaryContract | PseudoNumericContract contract: CPMMBinaryContract | PseudoNumericContract
@ -101,7 +101,7 @@ export function BetPanel(props: {
<SignUpPrompt /> <SignUpPrompt />
</Col> </Col>
{yourUnfilledBets.length > 0 && ( {yourUnfilledBets.length > 0 && (
<OpenBets className="mt-4" bets={yourUnfilledBets} /> <LimitBets className="mt-4" bets={yourUnfilledBets} />
)} )}
</Col> </Col>
) )
@ -320,11 +320,13 @@ function BuyPanel(props: {
betChoice ?? 'YES' betChoice ?? 'YES'
) )
const limitProbFrac = (limitProb ?? 0) / 100
const { newPool, newP, newBet } = getBinaryCpmmBetInfo( const { newPool, newP, newBet } = getBinaryCpmmBetInfo(
betChoice ?? 'YES', betChoice ?? 'YES',
betAmount ?? 0, betAmount ?? 0,
contract, contract,
isLimitOrder ? limitProb : undefined, isLimitOrder ? limitProbFrac : undefined,
unfilledBets as LimitBet[] unfilledBets as LimitBet[]
) )
@ -339,14 +341,26 @@ function BuyPanel(props: {
const resultProb = getCpmmProbability(newPool, newP) const resultProb = getCpmmProbability(newPool, newP)
const matchedAmount = sumBy(newBet.fills, (fill) => fill.amount) const matchedAmount = sumBy(newBet.fills, (fill) => fill.amount)
const filledShares = sumBy(newBet.fills, (fill) => fill.shares)
const overallShares =
filledShares +
((betAmount ?? 0) - matchedAmount) /
(betChoice === 'YES' ? limitProbFrac : 1 - limitProbFrac)
const currentPayout = matchedAmount console.log(
? calculatePayoutAfterCorrectBet(contract, { 'overallShares',
outcome: betChoice, overallShares,
amount: matchedAmount, 'filledShares',
shares: newBet.shares, filledShares,
} as Bet) 'amount',
: 0 betAmount,
'matchedAmount',
matchedAmount,
'limitProb',
limitProb
)
const currentPayout = overallShares
const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0 const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0
const currentReturnPercent = formatPercent(currentReturn) const currentReturnPercent = formatPercent(currentReturn)
@ -381,7 +395,7 @@ function BuyPanel(props: {
{isLimitOrder && ( {isLimitOrder && (
<> <>
<div className="my-3 text-left text-sm text-gray-500"> <div className="my-3 text-left text-sm text-gray-500">
{betChoice === 'YES' ? 'Max' : 'Min'} probability {betChoice === 'NO' ? 'Min' : 'Max'} probability
</div> </div>
<ProbabilityInput <ProbabilityInput
inputClassName="w-full max-w-none" inputClassName="w-full max-w-none"

View File

@ -8,13 +8,13 @@ import { Col } from './layout/col'
import { LoadingIndicator } from './loading-indicator' import { LoadingIndicator } from './loading-indicator'
import { BinaryOutcomeLabel } from './outcome-label' import { BinaryOutcomeLabel } from './outcome-label'
export function OpenBets(props: { bets: LimitBet[]; className?: string }) { export function LimitBets(props: { bets: LimitBet[]; className?: string }) {
const { bets, className } = props const { bets, className } = props
const recentBets = sortBy(bets, (bet) => bet.createdTime).reverse() const recentBets = sortBy(bets, (bet) => bet.createdTime).reverse()
return ( return (
<Col className={clsx(className, 'gap-2 rounded bg-white')}> <Col className={clsx(className, 'gap-2 rounded bg-white')}>
<div className="px-6 py-3 text-xl">Open bets</div> <div className="px-6 py-3 text-xl">Limit bets</div>
<table className="table-compact table w-full rounded text-gray-500"> <table className="table-compact table w-full rounded text-gray-500">
<tbody> <tbody>
{recentBets.map((bet) => ( {recentBets.map((bet) => (

View File

@ -45,7 +45,7 @@ import { useTracking } from 'web/hooks/use-tracking'
import { CommentTipMap, useTipTxns } from 'web/hooks/use-tip-txns' import { CommentTipMap, useTipTxns } from 'web/hooks/use-tip-txns'
import { useRouter } from 'next/router' import { useRouter } from 'next/router'
import { useLiquidity } from 'web/hooks/use-liquidity' import { useLiquidity } from 'web/hooks/use-liquidity'
import { OpenBets } from 'web/components/open-bets' import { LimitBets } from 'web/components/limit-bets'
export const getStaticProps = fromPropz(getStaticPropz) export const getStaticProps = fromPropz(getStaticPropz)
export async function getStaticPropz(props: { export async function getStaticPropz(props: {
@ -222,7 +222,7 @@ export function ContractPageContent(
<ContractOverview contract={contract} bets={bets} /> <ContractOverview contract={contract} bets={bets} />
{yourUnfilledBets.length > 0 && ( {yourUnfilledBets.length > 0 && (
<OpenBets className="mb-4 xl:hidden" bets={yourUnfilledBets} /> <LimitBets className="mb-4 xl:hidden" bets={yourUnfilledBets} />
)} )}
{isNumeric && ( {isNumeric && (