2022-01-12 19:01:04 +00:00
|
|
|
import { Bet } from './bet'
|
|
|
|
import { getProbability } from './calculate'
|
|
|
|
import { Contract } from './contract'
|
|
|
|
import { User } from './user'
|
|
|
|
|
2022-01-14 23:39:17 +00:00
|
|
|
export const PHANTOM_ANTE = 100
|
|
|
|
export const MINIMUM_ANTE = 10
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
export const calcStartPool = (initialProbInt: number, ante = 0) => {
|
2022-01-10 23:52:03 +00:00
|
|
|
const p = initialProbInt / 100.0
|
2022-01-12 19:01:04 +00:00
|
|
|
const totalAnte = PHANTOM_ANTE + ante
|
|
|
|
|
|
|
|
const sharesYes = Math.sqrt(p * totalAnte ** 2)
|
|
|
|
const sharesNo = Math.sqrt(totalAnte ** 2 - sharesYes ** 2)
|
|
|
|
|
|
|
|
const poolYes = p * ante
|
|
|
|
const poolNo = (1 - p) * ante
|
|
|
|
|
|
|
|
const phantomYes = Math.sqrt(p) * PHANTOM_ANTE
|
|
|
|
const phantomNo = Math.sqrt(1 - p) * PHANTOM_ANTE
|
|
|
|
|
|
|
|
return { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo }
|
|
|
|
}
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
export function getAnteBets(
|
|
|
|
creator: User,
|
|
|
|
contract: Contract,
|
|
|
|
yesAnteId: string,
|
|
|
|
noAnteId: string
|
|
|
|
) {
|
|
|
|
const p = getProbability(contract.totalShares)
|
|
|
|
const ante = contract.totalBets.YES + contract.totalBets.NO
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-13 16:40:08 +00:00
|
|
|
const { createdTime } = contract
|
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
const yesBet: Bet = {
|
|
|
|
id: yesAnteId,
|
|
|
|
userId: creator.id,
|
|
|
|
contractId: contract.id,
|
|
|
|
amount: p * ante,
|
|
|
|
shares: Math.sqrt(p) * ante,
|
|
|
|
outcome: 'YES',
|
|
|
|
probBefore: p,
|
|
|
|
probAfter: p,
|
2022-01-13 16:40:08 +00:00
|
|
|
createdTime,
|
2022-01-19 22:36:55 +00:00
|
|
|
isAnte: true,
|
2022-01-12 19:01:04 +00:00
|
|
|
}
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
const noBet: Bet = {
|
|
|
|
id: noAnteId,
|
|
|
|
userId: creator.id,
|
|
|
|
contractId: contract.id,
|
|
|
|
amount: (1 - p) * ante,
|
|
|
|
shares: Math.sqrt(1 - p) * ante,
|
|
|
|
outcome: 'NO',
|
|
|
|
probBefore: p,
|
|
|
|
probAfter: p,
|
2022-01-13 16:40:08 +00:00
|
|
|
createdTime,
|
2022-01-19 22:36:55 +00:00
|
|
|
isAnte: true,
|
2022-01-12 19:01:04 +00:00
|
|
|
}
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
return { yesBet, noBet }
|
2022-01-10 23:52:03 +00:00
|
|
|
}
|