use new calculations
This commit is contained in:
		
							parent
							
								
									fdea1d5ba6
								
							
						
					
					
						commit
						89f020ffcc
					
				|  | @ -88,6 +88,14 @@ export function calculateCpmmSale( | ||||||
|   return { saleValue, newPool } |   return { saleValue, newPool } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function getCpmmProbabilityAfterSale( | ||||||
|  |   contract: FullContract<CPMM, Binary>, | ||||||
|  |   bet: Bet | ||||||
|  | ) { | ||||||
|  |   const { newPool } = calculateCpmmSale(contract, bet) | ||||||
|  |   return getCpmmProbability(newPool) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function calculateFixedPayout( | export function calculateFixedPayout( | ||||||
|   contract: FullContract<CPMM, Binary>, |   contract: FullContract<CPMM, Binary>, | ||||||
|   bet: Bet, |   bet: Bet, | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ import { | ||||||
|   calculateCpmmShares, |   calculateCpmmShares, | ||||||
|   getCpmmProbability, |   getCpmmProbability, | ||||||
|   getCpmmProbabilityAfterBet, |   getCpmmProbabilityAfterBet, | ||||||
|  |   getCpmmProbabilityAfterSale, | ||||||
| } from './calculate-cpmm' | } from './calculate-cpmm' | ||||||
| import { | import { | ||||||
|   calculateDpmPayoutAfterCorrectBet, |   calculateDpmPayoutAfterCorrectBet, | ||||||
|  | @ -10,6 +11,7 @@ import { | ||||||
|   getDpmOutcomeProbability, |   getDpmOutcomeProbability, | ||||||
|   getDpmProbability, |   getDpmProbability, | ||||||
|   getDpmProbabilityAfterBet, |   getDpmProbabilityAfterBet, | ||||||
|  |   getDpmProbabilityAfterSale, | ||||||
| } from './calculate-dpm' | } from './calculate-dpm' | ||||||
| import { Binary, Contract, CPMM, DPM, FullContract } from './contract' | import { Binary, Contract, CPMM, DPM, FullContract } from './contract' | ||||||
| import { FEES } from './fees' | import { FEES } from './fees' | ||||||
|  | @ -20,6 +22,14 @@ export function getProbability(contract: FullContract<DPM | CPMM, Binary>) { | ||||||
|     : getDpmProbability(contract.totalShares) |     : getDpmProbability(contract.totalShares) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function getInitialProbability( | ||||||
|  |   contract: FullContract<DPM | CPMM, Binary> | ||||||
|  | ) { | ||||||
|  |   return contract.mechanism === 'cpmm-1' | ||||||
|  |     ? getCpmmProbability(contract.liquidity[contract.creatorId]) | ||||||
|  |     : getDpmProbability(contract.phantomShares ?? contract.totalShares) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function getOutcomeProbability(contract: Contract, outcome: string) { | export function getOutcomeProbability(contract: Contract, outcome: string) { | ||||||
|   return contract.mechanism === 'cpmm-1' |   return contract.mechanism === 'cpmm-1' | ||||||
|     ? getCpmmProbability(contract.pool) |     ? getCpmmProbability(contract.pool) | ||||||
|  | @ -56,6 +66,19 @@ export function calculatePayoutAfterCorrectBet(contract: Contract, bet: Bet) { | ||||||
|     : calculateDpmPayoutAfterCorrectBet(contract, bet) |     : calculateDpmPayoutAfterCorrectBet(contract, bet) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function getProbabilityAfterSale( | ||||||
|  |   contract: Contract, | ||||||
|  |   outcome: string, | ||||||
|  |   shares: number | ||||||
|  | ) { | ||||||
|  |   return contract.mechanism === 'cpmm-1' | ||||||
|  |     ? getCpmmProbabilityAfterSale( | ||||||
|  |         contract as FullContract<CPMM, Binary>, | ||||||
|  |         { shares, outcome } as Bet | ||||||
|  |       ) | ||||||
|  |     : getDpmProbabilityAfterSale(contract.totalShares, outcome, shares) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export const deductFees = (betAmount: number, winnings: number) => { | export const deductFees = (betAmount: number, winnings: number) => { | ||||||
|   return winnings > betAmount |   return winnings > betAmount | ||||||
|     ? betAmount + (1 - FEES) * (winnings - betAmount) |     ? betAmount + (1 - FEES) * (winnings - betAmount) | ||||||
|  |  | ||||||
|  | @ -1,14 +1,15 @@ | ||||||
| import clsx from 'clsx' | import clsx from 'clsx' | ||||||
| import { Fragment, useState } from 'react' | import { Fragment, useState } from 'react' | ||||||
| import { Dialog, Transition } from '@headlessui/react' | import { Dialog, Transition } from '@headlessui/react' | ||||||
| import { Contract } from '../lib/firebase/contracts' | 
 | ||||||
| import { BetPanel } from './bet-panel' | import { BetPanel } from './bet-panel' | ||||||
| import { Row } from './layout/row' | import { Row } from './layout/row' | ||||||
| import { YesNoSelector } from './yes-no-selector' | import { YesNoSelector } from './yes-no-selector' | ||||||
|  | import { Binary, CPMM, DPM, FullContract } from '../../common/contract' | ||||||
| 
 | 
 | ||||||
| // Inline version of a bet panel. Opens BetPanel in a new modal.
 | // Inline version of a bet panel. Opens BetPanel in a new modal.
 | ||||||
| export default function BetRow(props: { | export default function BetRow(props: { | ||||||
|   contract: Contract |   contract: FullContract<DPM | CPMM, Binary> | ||||||
|   className?: string |   className?: string | ||||||
|   labelClassName?: string |   labelClassName?: string | ||||||
| }) { | }) { | ||||||
|  |  | ||||||
|  | @ -25,9 +25,6 @@ import { UserLink } from './user-page' | ||||||
| import { | import { | ||||||
|   calculateDpmPayout, |   calculateDpmPayout, | ||||||
|   calculateDpmSaleAmount, |   calculateDpmSaleAmount, | ||||||
|   getDpmOutcomeProbability, |  | ||||||
|   getDpmProbability, |  | ||||||
|   getDpmProbabilityAfterSale, |  | ||||||
|   resolvedDpmPayout, |   resolvedDpmPayout, | ||||||
| } from '../../common/calculate-dpm' | } from '../../common/calculate-dpm' | ||||||
| import { sellBet } from '../lib/firebase/api-call' | import { sellBet } from '../lib/firebase/api-call' | ||||||
|  | @ -36,6 +33,11 @@ import { OutcomeLabel, YesLabel, NoLabel } from './outcome-label' | ||||||
| import { filterDefined } from '../../common/util/array' | import { filterDefined } from '../../common/util/array' | ||||||
| import { LoadingIndicator } from './loading-indicator' | import { LoadingIndicator } from './loading-indicator' | ||||||
| import { SiteLink } from './site-link' | import { SiteLink } from './site-link' | ||||||
|  | import { | ||||||
|  |   getOutcomeProbability, | ||||||
|  |   getProbability, | ||||||
|  |   getProbabilityAfterSale, | ||||||
|  | } from '../../common/calculate' | ||||||
| 
 | 
 | ||||||
| type BetSort = 'newest' | 'profit' | 'settled' | 'value' | type BetSort = 'newest' | 'profit' | 'settled' | 'value' | ||||||
| 
 | 
 | ||||||
|  | @ -385,7 +387,7 @@ export function MyBetsSummary(props: { | ||||||
|                     <> |                     <> | ||||||
|                       Payout at{' '} |                       Payout at{' '} | ||||||
|                       <span className="text-blue-400"> |                       <span className="text-blue-400"> | ||||||
|                         {formatPercent(getDpmProbability(contract.totalShares))} |                         {formatPercent(getProbability(contract))} | ||||||
|                       </span> |                       </span> | ||||||
|                     </> |                     </> | ||||||
|                   ) : ( |                   ) : ( | ||||||
|  | @ -519,16 +521,12 @@ function SellButton(props: { contract: Contract; bet: Bet }) { | ||||||
| 
 | 
 | ||||||
|   const [isSubmitting, setIsSubmitting] = useState(false) |   const [isSubmitting, setIsSubmitting] = useState(false) | ||||||
| 
 | 
 | ||||||
|   const initialProb = getDpmOutcomeProbability( |   const initialProb = getOutcomeProbability( | ||||||
|     contract.totalShares, |     contract, | ||||||
|     outcome === 'NO' ? 'YES' : outcome |     outcome === 'NO' ? 'YES' : outcome | ||||||
|   ) |   ) | ||||||
| 
 | 
 | ||||||
|   const outcomeProb = getDpmProbabilityAfterSale( |   const outcomeProb = getProbabilityAfterSale(contract, outcome, shares) | ||||||
|     contract.totalShares, |  | ||||||
|     outcome, |  | ||||||
|     shares |  | ||||||
|   ) |  | ||||||
| 
 | 
 | ||||||
|   const saleAmount = calculateDpmSaleAmount(contract, bet) |   const saleAmount = calculateDpmSaleAmount(contract, bet) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -2,20 +2,21 @@ import { DatumValue } from '@nivo/core' | ||||||
| import { ResponsiveLine } from '@nivo/line' | import { ResponsiveLine } from '@nivo/line' | ||||||
| import dayjs from 'dayjs' | import dayjs from 'dayjs' | ||||||
| import { Bet } from '../../common/bet' | import { Bet } from '../../common/bet' | ||||||
| import { getDpmProbability } from '../../common/calculate-dpm' | import { getInitialProbability } from '../../common/calculate' | ||||||
|  | import { Binary, CPMM, DPM, FullContract } from '../../common/contract' | ||||||
| import { useBetsWithoutAntes } from '../hooks/use-bets' | import { useBetsWithoutAntes } from '../hooks/use-bets' | ||||||
| import { useWindowSize } from '../hooks/use-window-size' | import { useWindowSize } from '../hooks/use-window-size' | ||||||
| import { Contract } from '../lib/firebase/contracts' |  | ||||||
| 
 | 
 | ||||||
| export function ContractProbGraph(props: { contract: Contract; bets: Bet[] }) { | export function ContractProbGraph(props: { | ||||||
|  |   contract: FullContract<DPM | CPMM, Binary> | ||||||
|  |   bets: Bet[] | ||||||
|  | }) { | ||||||
|   const { contract } = props |   const { contract } = props | ||||||
|   const { phantomShares, resolutionTime, closeTime } = contract |   const { resolutionTime, closeTime } = contract | ||||||
| 
 | 
 | ||||||
|   const bets = useBetsWithoutAntes(contract, props.bets) |   const bets = useBetsWithoutAntes(contract, props.bets) | ||||||
| 
 | 
 | ||||||
|   const startProb = getDpmProbability( |   const startProb = getInitialProbability(contract) | ||||||
|     phantomShares as { [outcome: string]: number } |  | ||||||
|   ) |  | ||||||
| 
 | 
 | ||||||
|   const times = bets |   const times = bets | ||||||
|     ? [contract.createdTime, ...bets.map((bet) => bet.createdTime)].map( |     ? [contract.createdTime, ...bets.map((bet) => bet.createdTime)].map( | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ import { Col } from './layout/col' | ||||||
| import { SiteLink } from './site-link' | import { SiteLink } from './site-link' | ||||||
| import { ContractCard } from './contract-card' | import { ContractCard } from './contract-card' | ||||||
| import { Sort, useQueryAndSortParams } from '../hooks/use-sort-and-query-params' | import { Sort, useQueryAndSortParams } from '../hooks/use-sort-and-query-params' | ||||||
|  | import { Answer } from '../../common/answer' | ||||||
| 
 | 
 | ||||||
| export function ContractsGrid(props: { | export function ContractsGrid(props: { | ||||||
|   contracts: Contract[] |   contracts: Contract[] | ||||||
|  | @ -217,7 +218,11 @@ export function SearchableGrid(props: { | ||||||
|       check(c.creatorName) || |       check(c.creatorName) || | ||||||
|       check(c.creatorUsername) || |       check(c.creatorUsername) || | ||||||
|       check(c.lowercaseTags.map((tag) => `#${tag}`).join(' ')) || |       check(c.lowercaseTags.map((tag) => `#${tag}`).join(' ')) || | ||||||
|       check((c.answers ?? []).map((answer) => answer.text).join(' ')) |       check( | ||||||
|  |         ((c as any).answers ?? []) | ||||||
|  |           .map((answer: Answer) => answer.text) | ||||||
|  |           .join(' ') | ||||||
|  |       ) | ||||||
|   ) |   ) | ||||||
| 
 | 
 | ||||||
|   if (sort === 'newest' || sort === 'all') { |   if (sort === 'newest' || sort === 'all') { | ||||||
|  |  | ||||||
|  | @ -1,7 +1,6 @@ | ||||||
| import clsx from 'clsx' | import clsx from 'clsx' | ||||||
| import React, { useEffect, useState } from 'react' | import React, { useEffect, useState } from 'react' | ||||||
| 
 | 
 | ||||||
| import { Contract } from '../lib/firebase/contracts' |  | ||||||
| import { Col } from './layout/col' | import { Col } from './layout/col' | ||||||
| import { Title } from './title' | import { Title } from './title' | ||||||
| import { User } from '../lib/firebase/users' | import { User } from '../lib/firebase/users' | ||||||
|  | @ -10,12 +9,13 @@ import { Spacer } from './layout/spacer' | ||||||
| import { ResolveConfirmationButton } from './confirmation-button' | import { ResolveConfirmationButton } from './confirmation-button' | ||||||
| import { resolveMarket } from '../lib/firebase/api-call' | import { resolveMarket } from '../lib/firebase/api-call' | ||||||
| import { ProbabilitySelector } from './probability-selector' | import { ProbabilitySelector } from './probability-selector' | ||||||
| import { getDpmProbability } from '../../common/calculate-dpm' |  | ||||||
| import { CREATOR_FEE } from '../../common/fees' | import { CREATOR_FEE } from '../../common/fees' | ||||||
|  | import { getProbability } from '../../common/calculate' | ||||||
|  | import { Binary, CPMM, DPM, FullContract } from '../../common/contract' | ||||||
| 
 | 
 | ||||||
| export function ResolutionPanel(props: { | export function ResolutionPanel(props: { | ||||||
|   creator: User |   creator: User | ||||||
|   contract: Contract |   contract: FullContract<DPM | CPMM, Binary> | ||||||
|   className?: string |   className?: string | ||||||
| }) { | }) { | ||||||
|   useEffect(() => { |   useEffect(() => { | ||||||
|  | @ -29,9 +29,7 @@ export function ResolutionPanel(props: { | ||||||
|     'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined |     'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined | ||||||
|   >() |   >() | ||||||
| 
 | 
 | ||||||
|   const [prob, setProb] = useState( |   const [prob, setProb] = useState(getProbability(contract) * 100) | ||||||
|     getDpmProbability(contract.totalShares) * 100 |  | ||||||
|   ) |  | ||||||
| 
 | 
 | ||||||
|   const [isSubmitting, setIsSubmitting] = useState(false) |   const [isSubmitting, setIsSubmitting] = useState(false) | ||||||
|   const [error, setError] = useState<string | undefined>(undefined) |   const [error, setError] = useState<string | undefined>(undefined) | ||||||
|  |  | ||||||
|  | @ -1,7 +1,7 @@ | ||||||
| import { Bet } from '../../../../common/bet' | import { Bet } from '../../../../common/bet' | ||||||
| import { getDpmProbability } from '../../../../common/calculate-dpm' | import { getDpmProbability } from '../../../../common/calculate-dpm' | ||||||
| import { Comment } from '../../../../common/comment' | import { Comment } from '../../../../common/comment' | ||||||
| import { Contract } from '../../../../common/contract' | import { DPM, FullContract } from '../../../../common/contract' | ||||||
| 
 | 
 | ||||||
| export type LiteMarket = { | export type LiteMarket = { | ||||||
|   // Unique identifer for this market
 |   // Unique identifer for this market
 | ||||||
|  | @ -56,7 +56,7 @@ export function toLiteMarket({ | ||||||
|   isResolved, |   isResolved, | ||||||
|   resolution, |   resolution, | ||||||
|   resolutionTime, |   resolutionTime, | ||||||
| }: Contract): LiteMarket { | }: FullContract<DPM, any>): LiteMarket { | ||||||
|   return { |   return { | ||||||
|     id, |     id, | ||||||
|     creatorUsername, |     creatorUsername, | ||||||
|  |  | ||||||
|  | @ -3,11 +3,12 @@ import dayjs from 'dayjs' | ||||||
| import Link from 'next/link' | import Link from 'next/link' | ||||||
| import { useState } from 'react' | import { useState } from 'react' | ||||||
| import Textarea from 'react-expanding-textarea' | import Textarea from 'react-expanding-textarea' | ||||||
| import { getDpmProbability } from '../../common/calculate-dpm' | 
 | ||||||
|  | import { getProbability } from '../../common/calculate' | ||||||
|  | import { Binary, CPMM, DPM, FullContract } from '../../common/contract' | ||||||
| import { parseWordsAsTags } from '../../common/util/parse' | import { parseWordsAsTags } from '../../common/util/parse' | ||||||
| import { AmountInput } from '../components/amount-input' | import { AmountInput } from '../components/amount-input' | ||||||
| import { InfoTooltip } from '../components/info-tooltip' | import { InfoTooltip } from '../components/info-tooltip' | ||||||
| 
 |  | ||||||
| import { Col } from '../components/layout/col' | import { Col } from '../components/layout/col' | ||||||
| import { Row } from '../components/layout/row' | import { Row } from '../components/layout/row' | ||||||
| import { Spacer } from '../components/layout/spacer' | import { Spacer } from '../components/layout/spacer' | ||||||
|  | @ -16,7 +17,7 @@ import { Page } from '../components/page' | ||||||
| import { Title } from '../components/title' | import { Title } from '../components/title' | ||||||
| import { useUser } from '../hooks/use-user' | import { useUser } from '../hooks/use-user' | ||||||
| import { createContract } from '../lib/firebase/api-call' | import { createContract } from '../lib/firebase/api-call' | ||||||
| import { Contract, contractPath } from '../lib/firebase/contracts' | import { contractPath } from '../lib/firebase/contracts' | ||||||
| 
 | 
 | ||||||
| type Prediction = { | type Prediction = { | ||||||
|   question: string |   question: string | ||||||
|  | @ -25,8 +26,8 @@ type Prediction = { | ||||||
|   createdUrl?: string |   createdUrl?: string | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function toPrediction(contract: Contract): Prediction { | function toPrediction(contract: FullContract<DPM | CPMM, Binary>): Prediction { | ||||||
|   const startProb = getDpmProbability(contract.totalShares) |   const startProb = getProbability(contract) | ||||||
|   return { |   return { | ||||||
|     question: contract.question, |     question: contract.question, | ||||||
|     description: contract.description, |     description: contract.description, | ||||||
|  | @ -101,7 +102,9 @@ export default function MakePredictions() { | ||||||
|   const [description, setDescription] = useState('') |   const [description, setDescription] = useState('') | ||||||
|   const [tags, setTags] = useState('') |   const [tags, setTags] = useState('') | ||||||
|   const [isSubmitting, setIsSubmitting] = useState(false) |   const [isSubmitting, setIsSubmitting] = useState(false) | ||||||
|   const [createdContracts, setCreatedContracts] = useState<Contract[]>([]) |   const [createdContracts, setCreatedContracts] = useState< | ||||||
|  |     FullContract<DPM | CPMM, Binary>[] | ||||||
|  |   >([]) | ||||||
| 
 | 
 | ||||||
|   const [ante, setAnte] = useState<number | undefined>(100) |   const [ante, setAnte] = useState<number | undefined>(100) | ||||||
|   const [anteError, setAnteError] = useState<string | undefined>() |   const [anteError, setAnteError] = useState<string | undefined>() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user