enable resolve MKT
This commit is contained in:
parent
87e7a2a6d1
commit
389e11db48
|
@ -24,7 +24,7 @@ export const resolveMarket = functions
|
||||||
|
|
||||||
const { outcome, contractId } = data
|
const { outcome, contractId } = data
|
||||||
|
|
||||||
if (!['YES', 'NO', 'CANCEL'].includes(outcome))
|
if (!['YES', 'NO', 'MKT', 'CANCEL'].includes(outcome))
|
||||||
return { status: 'error', message: 'Invalid outcome' }
|
return { status: 'error', message: 'Invalid outcome' }
|
||||||
|
|
||||||
const contractDoc = firestore.doc(`contracts/${contractId}`)
|
const contractDoc = firestore.doc(`contracts/${contractId}`)
|
||||||
|
|
|
@ -357,11 +357,12 @@ function SellButton(props: { contract: Contract; bet: Bet }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function OutcomeLabel(props: { outcome: 'YES' | 'NO' | 'CANCEL' }) {
|
function OutcomeLabel(props: { outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT' }) {
|
||||||
const { outcome } = props
|
const { outcome } = props
|
||||||
|
|
||||||
if (outcome === 'YES') return <YesLabel />
|
if (outcome === 'YES') return <YesLabel />
|
||||||
if (outcome === 'NO') return <NoLabel />
|
if (outcome === 'NO') return <NoLabel />
|
||||||
|
if (outcome === 'MKT') return <MarketLabel />
|
||||||
return <CancelLabel />
|
return <CancelLabel />
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -376,3 +377,7 @@ function NoLabel() {
|
||||||
function CancelLabel() {
|
function CancelLabel() {
|
||||||
return <span className="text-yellow-400">N/A</span>
|
return <span className="text-yellow-400">N/A</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MarketLabel() {
|
||||||
|
return <span className="text-blue-400">MKT</span>
|
||||||
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ export const ContractOverview = (props: {
|
||||||
const resolutionColor = {
|
const resolutionColor = {
|
||||||
YES: 'text-primary',
|
YES: 'text-primary',
|
||||||
NO: 'text-red-400',
|
NO: 'text-red-400',
|
||||||
|
MKT: 'text-blue-400',
|
||||||
CANCEL: 'text-yellow-400',
|
CANCEL: 'text-yellow-400',
|
||||||
'': '', // Empty if unresolved
|
'': '', // Empty if unresolved
|
||||||
}[contract.resolution || '']
|
}[contract.resolution || '']
|
||||||
|
|
|
@ -44,6 +44,7 @@ function ContractCard(props: { contract: Contract }) {
|
||||||
const resolutionColor = {
|
const resolutionColor = {
|
||||||
YES: 'text-primary',
|
YES: 'text-primary',
|
||||||
NO: 'text-red-400',
|
NO: 'text-red-400',
|
||||||
|
MKT: 'text-blue-400',
|
||||||
CANCEL: 'text-yellow-400',
|
CANCEL: 'text-yellow-400',
|
||||||
'': '', // Empty if unresolved
|
'': '', // Empty if unresolved
|
||||||
}[contract.resolution || '']
|
}[contract.resolution || '']
|
||||||
|
@ -51,6 +52,7 @@ function ContractCard(props: { contract: Contract }) {
|
||||||
const resolutionText = {
|
const resolutionText = {
|
||||||
YES: 'YES',
|
YES: 'YES',
|
||||||
NO: 'NO',
|
NO: 'NO',
|
||||||
|
MKT: 'MKT',
|
||||||
CANCEL: 'N/A',
|
CANCEL: 'N/A',
|
||||||
'': '',
|
'': '',
|
||||||
}[contract.resolution || '']
|
}[contract.resolution || '']
|
||||||
|
|
|
@ -20,7 +20,9 @@ export function ResolutionPanel(props: {
|
||||||
}) {
|
}) {
|
||||||
const { contract, className } = props
|
const { contract, className } = props
|
||||||
|
|
||||||
const [outcome, setOutcome] = useState<'YES' | 'NO' | 'CANCEL' | undefined>()
|
const [outcome, setOutcome] = useState<
|
||||||
|
'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
|
||||||
|
>()
|
||||||
|
|
||||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||||
const [error, setError] = useState<string | undefined>(undefined)
|
const [error, setError] = useState<string | undefined>(undefined)
|
||||||
|
@ -48,6 +50,8 @@ export function ResolutionPanel(props: {
|
||||||
? 'bg-red-400 hover:bg-red-500'
|
? 'bg-red-400 hover:bg-red-500'
|
||||||
: outcome === 'CANCEL'
|
: outcome === 'CANCEL'
|
||||||
? 'bg-yellow-400 hover:bg-yellow-500'
|
? 'bg-yellow-400 hover:bg-yellow-500'
|
||||||
|
: outcome === 'MKT'
|
||||||
|
? 'bg-blue-400 hover:bg-blue-500'
|
||||||
: 'btn-disabled'
|
: 'btn-disabled'
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -74,6 +78,11 @@ export function ResolutionPanel(props: {
|
||||||
<>Winnings will be paid out to NO bettors. You earn 1% of the pool.</>
|
<>Winnings will be paid out to NO bettors. You earn 1% of the pool.</>
|
||||||
) : outcome === 'CANCEL' ? (
|
) : outcome === 'CANCEL' ? (
|
||||||
<>The pool will be returned to traders with no fees.</>
|
<>The pool will be returned to traders with no fees.</>
|
||||||
|
) : outcome === 'MKT' ? (
|
||||||
|
<>
|
||||||
|
Traders will be paid out at the current implied probability. You
|
||||||
|
earn 1% of the pool.
|
||||||
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>Resolving this market will immediately pay out traders.</>
|
<>Resolving this market will immediately pay out traders.</>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { Col } from './layout/col'
|
||||||
import { Row } from './layout/row'
|
import { Row } from './layout/row'
|
||||||
|
|
||||||
export function YesNoSelector(props: {
|
export function YesNoSelector(props: {
|
||||||
|
@ -29,48 +30,60 @@ export function YesNoSelector(props: {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function YesNoCancelSelector(props: {
|
export function YesNoCancelSelector(props: {
|
||||||
selected: 'YES' | 'NO' | 'CANCEL' | undefined
|
selected: 'YES' | 'NO' | 'MKT' | 'CANCEL' | undefined
|
||||||
onSelect: (selected: 'YES' | 'NO' | 'CANCEL') => void
|
onSelect: (selected: 'YES' | 'NO' | 'MKT' | 'CANCEL') => void
|
||||||
className?: string
|
className?: string
|
||||||
btnClassName?: string
|
btnClassName?: string
|
||||||
}) {
|
}) {
|
||||||
const { selected, onSelect, className } = props
|
const { selected, onSelect, className } = props
|
||||||
|
|
||||||
const btnClassName = clsx('px-6', props.btnClassName)
|
const btnClassName = clsx('px-6 flex-1', props.btnClassName)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Row className={clsx('space-x-3', className)}>
|
<Col>
|
||||||
<Button
|
<Row className={clsx('space-x-3 w-full', className)}>
|
||||||
color={selected === 'YES' ? 'green' : 'gray'}
|
<Button
|
||||||
onClick={() => onSelect('YES')}
|
color={selected === 'YES' ? 'green' : 'gray'}
|
||||||
className={btnClassName}
|
onClick={() => onSelect('YES')}
|
||||||
>
|
className={btnClassName}
|
||||||
YES
|
>
|
||||||
</Button>
|
YES
|
||||||
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
color={selected === 'NO' ? 'red' : 'gray'}
|
color={selected === 'NO' ? 'red' : 'gray'}
|
||||||
onClick={() => onSelect('NO')}
|
onClick={() => onSelect('NO')}
|
||||||
className={btnClassName}
|
className={btnClassName}
|
||||||
>
|
>
|
||||||
NO
|
NO
|
||||||
</Button>
|
</Button>
|
||||||
|
</Row>
|
||||||
|
|
||||||
<Button
|
<Row className={clsx('space-x-3 w-full', className)}>
|
||||||
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
|
<Button
|
||||||
onClick={() => onSelect('CANCEL')}
|
color={selected === 'MKT' ? 'blue' : 'gray'}
|
||||||
className={btnClassName}
|
onClick={() => onSelect('MKT')}
|
||||||
>
|
className={clsx(btnClassName, 'btn-sm')}
|
||||||
N/A
|
>
|
||||||
</Button>
|
MKT
|
||||||
</Row>
|
</Button>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
color={selected === 'CANCEL' ? 'yellow' : 'gray'}
|
||||||
|
onClick={() => onSelect('CANCEL')}
|
||||||
|
className={clsx(btnClassName, 'btn-sm')}
|
||||||
|
>
|
||||||
|
N/A
|
||||||
|
</Button>
|
||||||
|
</Row>
|
||||||
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Button(props: {
|
function Button(props: {
|
||||||
className?: string
|
className?: string
|
||||||
onClick?: () => void
|
onClick?: () => void
|
||||||
color: 'green' | 'red' | 'yellow' | 'gray'
|
color: 'green' | 'red' | 'blue' | 'yellow' | 'gray'
|
||||||
children?: any
|
children?: any
|
||||||
}) {
|
}) {
|
||||||
const { className, onClick, children, color } = props
|
const { className, onClick, children, color } = props
|
||||||
|
@ -83,6 +96,7 @@ function Button(props: {
|
||||||
color === 'green' && 'btn-primary',
|
color === 'green' && 'btn-primary',
|
||||||
color === 'red' && 'bg-red-400 hover:bg-red-500',
|
color === 'red' && 'bg-red-400 hover:bg-red-500',
|
||||||
color === 'yellow' && 'bg-yellow-400 hover:bg-yellow-500',
|
color === 'yellow' && 'bg-yellow-400 hover:bg-yellow-500',
|
||||||
|
color === 'blue' && 'bg-blue-400 hover:bg-blue-500',
|
||||||
color === 'gray' && 'text-gray-700 bg-gray-300 hover:bg-gray-400',
|
color === 'gray' && 'text-gray-700 bg-gray-300 hover:bg-gray-400',
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -37,27 +37,36 @@ export function calculateShares(
|
||||||
export function calculatePayout(
|
export function calculatePayout(
|
||||||
contract: Contract,
|
contract: Contract,
|
||||||
bet: Bet,
|
bet: Bet,
|
||||||
outcome: 'YES' | 'NO' | 'CANCEL'
|
outcome: 'YES' | 'NO' | 'CANCEL' | 'MKT'
|
||||||
) {
|
) {
|
||||||
const { amount, outcome: betOutcome, shares } = bet
|
const { amount, outcome: betOutcome, shares } = bet
|
||||||
|
|
||||||
if (outcome === 'CANCEL') return amount
|
if (outcome === 'CANCEL') return amount
|
||||||
if (betOutcome !== outcome) return 0
|
|
||||||
|
const impliedProbabilility =
|
||||||
|
contract.pool.YES ** 2 / (contract.pool.YES ** 2 + contract.pool.NO ** 2)
|
||||||
|
|
||||||
|
const p =
|
||||||
|
outcome === 'MKT'
|
||||||
|
? betOutcome === 'YES'
|
||||||
|
? impliedProbabilility
|
||||||
|
: 1 - impliedProbabilility
|
||||||
|
: outcome === 'YES'
|
||||||
|
? 1
|
||||||
|
: 0
|
||||||
|
|
||||||
const { totalShares, totalBets } = contract
|
const { totalShares, totalBets } = contract
|
||||||
|
|
||||||
if (totalShares[outcome] === 0) return 0
|
|
||||||
|
|
||||||
const startPool = contract.startPool.YES + contract.startPool.NO
|
const startPool = contract.startPool.YES + contract.startPool.NO
|
||||||
const truePool = contract.pool.YES + contract.pool.NO - startPool
|
const truePool = contract.pool.YES + contract.pool.NO - startPool
|
||||||
|
|
||||||
if (totalBets[outcome] <= truePool)
|
if (totalBets[betOutcome] <= truePool)
|
||||||
return (amount / totalBets[outcome]) * truePool
|
return p * (amount / totalBets[betOutcome]) * truePool
|
||||||
|
|
||||||
const total = totalShares[outcome] - totalBets[outcome]
|
const total = totalShares[betOutcome] - totalBets[betOutcome]
|
||||||
const winningsPool = truePool - totalBets[outcome]
|
const winningsPool = truePool - totalBets[betOutcome]
|
||||||
|
|
||||||
return (1 - fees) * (amount + ((shares - amount) / total) * winningsPool)
|
return p * (1 - fees) * (amount + ((shares - amount) / total) * winningsPool)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolvedPayout(contract: Contract, bet: Bet) {
|
export function resolvedPayout(contract: Contract, bet: Bet) {
|
||||||
|
|
|
@ -2,8 +2,8 @@ import { getFirestore } from '@firebase/firestore'
|
||||||
import { initializeApp } from 'firebase/app'
|
import { initializeApp } from 'firebase/app'
|
||||||
|
|
||||||
// TODO: Reenable this when we have a way to set the Firebase db in dev
|
// TODO: Reenable this when we have a way to set the Firebase db in dev
|
||||||
// export const isProd = process.env.NODE_ENV === 'production'
|
export const isProd = process.env.NODE_ENV === 'production'
|
||||||
export const isProd = true
|
// export const isProd = true
|
||||||
|
|
||||||
const firebaseConfig = isProd
|
const firebaseConfig = isProd
|
||||||
? {
|
? {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user