2022-01-12 19:01:04 +00:00
|
|
|
import { Bet } from './bet'
|
2022-03-15 22:27:51 +00:00
|
|
|
import { getDpmProbability } from './calculate-dpm'
|
|
|
|
import { Binary, CPMM, DPM, FreeResponse, FullContract } from './contract'
|
2022-01-12 19:01:04 +00:00
|
|
|
import { User } from './user'
|
2022-03-15 22:27:51 +00:00
|
|
|
import { LiquidityProvision } from './liquidity-provision'
|
|
|
|
import { noFees } from './fees'
|
2022-01-12 19:01:04 +00:00
|
|
|
|
2022-02-13 01:19:17 +00:00
|
|
|
export const PHANTOM_ANTE = 0.001
|
2022-04-04 15:47:29 +00:00
|
|
|
export const MINIMUM_ANTE = 50
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
export function getCpmmInitialLiquidity(
|
|
|
|
creator: User,
|
|
|
|
contract: FullContract<CPMM, Binary>,
|
|
|
|
anteId: string,
|
|
|
|
amount: number
|
|
|
|
) {
|
|
|
|
const { createdTime, p } = contract
|
2022-01-12 19:01:04 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
const lp: LiquidityProvision = {
|
|
|
|
id: anteId,
|
|
|
|
userId: creator.id,
|
|
|
|
contractId: contract.id,
|
|
|
|
createdTime,
|
|
|
|
isAnte: true,
|
2022-01-12 19:01:04 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
amount: amount,
|
|
|
|
liquidity: amount,
|
|
|
|
p: p,
|
|
|
|
pool: { YES: 0, NO: 0 },
|
|
|
|
}
|
2022-01-12 19:01:04 +00:00
|
|
|
|
2022-03-15 22:27:51 +00:00
|
|
|
return lp
|
2022-01-12 19:01:04 +00:00
|
|
|
}
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
export function getAnteBets(
|
|
|
|
creator: User,
|
2022-03-15 22:27:51 +00:00
|
|
|
contract: FullContract<DPM, Binary>,
|
2022-01-12 19:01:04 +00:00
|
|
|
yesAnteId: string,
|
|
|
|
noAnteId: string
|
|
|
|
) {
|
2022-03-15 22:27:51 +00:00
|
|
|
const p = getDpmProbability(contract.totalShares)
|
2022-01-12 19:01:04 +00:00
|
|
|
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-03-15 22:27:51 +00:00
|
|
|
fees: noFees,
|
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-03-15 22:27:51 +00:00
|
|
|
fees: noFees,
|
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
|
|
|
}
|
2022-02-17 23:00:19 +00:00
|
|
|
|
|
|
|
export function getFreeAnswerAnte(
|
|
|
|
creator: User,
|
2022-03-15 22:27:51 +00:00
|
|
|
contract: FullContract<DPM, FreeResponse>,
|
2022-02-17 23:00:19 +00:00
|
|
|
anteBetId: string
|
|
|
|
) {
|
|
|
|
const { totalBets, totalShares } = contract
|
|
|
|
const amount = totalBets['0']
|
|
|
|
const shares = totalShares['0']
|
|
|
|
|
|
|
|
const { createdTime } = contract
|
|
|
|
|
|
|
|
const anteBet: Bet = {
|
|
|
|
id: anteBetId,
|
|
|
|
userId: creator.id,
|
|
|
|
contractId: contract.id,
|
|
|
|
amount,
|
|
|
|
shares,
|
|
|
|
outcome: '0',
|
|
|
|
probBefore: 0,
|
|
|
|
probAfter: 1,
|
|
|
|
createdTime,
|
|
|
|
isAnte: true,
|
2022-03-15 22:27:51 +00:00
|
|
|
fees: noFees,
|
2022-02-17 23:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return anteBet
|
|
|
|
}
|