2022-01-10 23:52:03 +00:00
|
|
|
import { calcStartPool } from './antes'
|
2022-01-12 19:01:04 +00:00
|
|
|
|
2022-01-10 23:52:03 +00:00
|
|
|
import { Contract } from './contract'
|
|
|
|
import { User } from './user'
|
2022-01-21 23:21:46 +00:00
|
|
|
import { parseTags } from './util/parse'
|
2022-01-10 22:49:04 +00:00
|
|
|
|
|
|
|
export function getNewContract(
|
|
|
|
id: string,
|
|
|
|
slug: string,
|
|
|
|
creator: User,
|
|
|
|
question: string,
|
|
|
|
description: string,
|
|
|
|
initialProb: number,
|
|
|
|
ante?: number,
|
|
|
|
closeTime?: number
|
|
|
|
) {
|
2022-01-12 19:01:04 +00:00
|
|
|
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
|
|
|
|
calcStartPool(initialProb, ante)
|
2022-01-10 22:49:04 +00:00
|
|
|
|
|
|
|
const contract: Contract = {
|
|
|
|
id,
|
|
|
|
slug,
|
2022-01-10 23:52:03 +00:00
|
|
|
outcomeType: 'BINARY',
|
2022-01-10 22:49:04 +00:00
|
|
|
|
|
|
|
creatorId: creator.id,
|
|
|
|
creatorName: creator.name,
|
|
|
|
creatorUsername: creator.username,
|
2022-01-16 06:03:59 +00:00
|
|
|
creatorAvatarUrl: creator.avatarUrl,
|
2022-01-10 22:49:04 +00:00
|
|
|
|
|
|
|
question: question.trim(),
|
|
|
|
description: description.trim(),
|
2022-01-21 23:21:46 +00:00
|
|
|
tags: parseTags(`${question} ${description}`),
|
2022-01-13 01:53:50 +00:00
|
|
|
visibility: 'public',
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-12 19:01:04 +00:00
|
|
|
mechanism: 'dpm-2',
|
|
|
|
phantomShares: { YES: phantomYes, NO: phantomNo },
|
2022-01-10 22:49:04 +00:00
|
|
|
pool: { YES: poolYes, NO: poolNo },
|
2022-01-12 19:01:04 +00:00
|
|
|
totalShares: { YES: sharesYes, NO: sharesNo },
|
|
|
|
totalBets: { YES: poolYes, NO: poolNo },
|
2022-01-10 22:49:04 +00:00
|
|
|
isResolved: false,
|
|
|
|
|
|
|
|
createdTime: Date.now(),
|
|
|
|
lastUpdatedTime: Date.now(),
|
|
|
|
|
|
|
|
volume24Hours: 0,
|
|
|
|
volume7Days: 0,
|
2022-01-10 23:52:03 +00:00
|
|
|
}
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-10 23:52:03 +00:00
|
|
|
if (closeTime) contract.closeTime = closeTime
|
2022-01-10 22:49:04 +00:00
|
|
|
|
2022-01-10 23:52:03 +00:00
|
|
|
return contract
|
2022-01-10 22:49:04 +00:00
|
|
|
}
|