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