2022-03-15 22:27:51 +00:00
|
|
|
import { Bet } from './bet'
|
|
|
|
import { getProbability } from './calculate'
|
2022-06-01 02:42:35 +00:00
|
|
|
import { CPMMContract } from './contract'
|
2022-03-15 22:27:51 +00:00
|
|
|
|
|
|
|
export function calculateFixedPayout(
|
2022-06-01 02:42:35 +00:00
|
|
|
contract: CPMMContract,
|
2022-03-15 22:27:51 +00:00
|
|
|
bet: Bet,
|
|
|
|
outcome: string
|
|
|
|
) {
|
|
|
|
if (outcome === 'CANCEL') return calculateFixedCancelPayout(bet)
|
|
|
|
if (outcome === 'MKT') return calculateFixedMktPayout(contract, bet)
|
|
|
|
|
|
|
|
return calculateStandardFixedPayout(bet, outcome)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function calculateFixedCancelPayout(bet: Bet) {
|
|
|
|
return bet.amount
|
|
|
|
}
|
|
|
|
|
|
|
|
export function calculateStandardFixedPayout(bet: Bet, outcome: string) {
|
|
|
|
const { outcome: betOutcome, shares } = bet
|
|
|
|
if (betOutcome !== outcome) return 0
|
|
|
|
return shares
|
|
|
|
}
|
|
|
|
|
2022-06-01 02:42:35 +00:00
|
|
|
function calculateFixedMktPayout(contract: CPMMContract, bet: Bet) {
|
2022-03-15 22:27:51 +00:00
|
|
|
const { resolutionProbability } = contract
|
|
|
|
const p =
|
|
|
|
resolutionProbability !== undefined
|
|
|
|
? resolutionProbability
|
|
|
|
: getProbability(contract)
|
|
|
|
|
|
|
|
const { outcome, shares } = bet
|
|
|
|
|
|
|
|
const betP = outcome === 'YES' ? p : 1 - p
|
|
|
|
|
|
|
|
return betP * shares
|
|
|
|
}
|