manifold/common/new-contract.ts

53 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-01-10 23:52:03 +00:00
import { calcStartPool } from './antes'
2022-01-10 23:52:03 +00:00
import { Contract } from './contract'
import { User } from './user'
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
) {
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,
creatorAvatarUrl: creator.avatarUrl,
2022-01-10 22:49:04 +00:00
question: question.trim(),
description: description.trim(),
tags: parseTags(`${question} ${description}`),
visibility: 'public',
2022-01-10 22:49:04 +00:00
mechanism: 'dpm-2',
phantomShares: { YES: phantomYes, NO: phantomNo },
2022-01-10 22:49:04 +00:00
pool: { YES: poolYes, NO: poolNo },
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
}