a3663d03e8
* Added radio buttons to market creation (non functional) * Ignoring vs code files Should this be done in the repo or should everyone using VS Code do that himself globally on his machine(s)? * Removed 'automatic' resolution * added union type for resolution * revert: resolution could be anything here (non binary markets) * Expanded ChoicesToggleGroup for string choices * Added combined resolution and required buttons to market creation * restricted automatic resolution to binary markets * added automatic resolution to contract * added automatic resolution to contract overview * string or number array to mixed array * created const for resolutions * Added comments for leading semicolons * configuration of auto resolution on market creation * v1.22.19 * v1.0.0 * v0.0.0 * v1.0.0 * v1.22.19 * Mock display automatic resolution * Revert changes to market creation * Revert "v1.22.19" This reverts commit22f59adc9c
. * Removed resolutiontype from contract creation * Added auto resolution time to contract * Auto resolution date editable * refactoring * Editable interface for auto resolution * New edit interface for auto resolution * Setting of auto resolve date when changing close date * prohibited changing other peoples markets * removed unnecessary export * refactoring (cherry picked from commit4de86d5b08
) * Added comments for leading semicolons (cherry picked from commit60739c7853
) * Ignoring vs code files Should this be done in the repo or should everyone using VS Code do that himself globally on his machine(s)? (cherry picked from commit944de9398a
) * removed unused imports and variables * added type for binary resolution * Prettier * const for binary resolutions * using the type "resolution" * Prettier * Re-added comment * Update functions/src/create-contract.ts * Revert "Ignoring vs code files" This reverts commit09aea5c207
. * launch config for debugging with vs code WIP * "Launch Chrome" does not work since login via google is not possible in debugger-chrome * Breakpoints are unbound when attached to chrome * Revert "Added comments for leading semicolons" * prettier * linebreak crlf * vscode settings * correct linebreaks * search exclusion * automatic prettifier * vscode settings * correct linebreaks * search exclusion * automatic prettifier * Working debugger config * fix merge * Removed comments, default resolution MKT * removed vscode from gitignore * refactoring description update * Added auto resolution to LiteMarket * fix date, setDate mutates object * fixed firestore.rules * script to add auto resolution to all markets * regularely auto resolve markets * fix description error * moved calculate ts for access in firebase * Revert "moved calculate ts for access in firebase" This reverts commit8380bf4f72
. * fix reference to calculate for firebase * fixed references to time * renamed function * added description * added auto resolution to description * direct bool check instead of != null * direct bool check instead of != undefined * remove explicit type * Fix free response markets * removed contract from functionname * interval set to 1h * query instead of filter * folds ~> contracts * query instead of filter * promise.all instead of foreach * removed contractDoc from function header * removed autoResolution from function header * batchedWaitAll instead of promise.all * removed unused parameter * replaced auto resolution with constant * suggestions from PR * fix comment * removed unused imports * added scripts to add close dates on prod * optimization * removed test script * security: only auto resolve markets which are closed * consistency checks * re-added type check for binary markets * moved check of probability into switch case block * removed unused import * auto resolution every minute * auto resolution time optional * pr fixes
159 lines
3.5 KiB
TypeScript
159 lines
3.5 KiB
TypeScript
import { range } from 'lodash'
|
|
import {
|
|
Binary,
|
|
Contract,
|
|
CPMM,
|
|
DPM,
|
|
FreeResponse,
|
|
Numeric,
|
|
outcomeType,
|
|
} from './contract'
|
|
import { User } from './user'
|
|
import { parseTags } from './util/parse'
|
|
import { removeUndefinedProps } from './util/object'
|
|
|
|
export function getNewContract(
|
|
id: string,
|
|
slug: string,
|
|
creator: User,
|
|
question: string,
|
|
outcomeType: outcomeType,
|
|
description: string,
|
|
initialProb: number,
|
|
ante: number,
|
|
closeTime: number,
|
|
extraTags: string[],
|
|
|
|
// used for numeric markets
|
|
bucketCount: number,
|
|
min: number,
|
|
max: number,
|
|
autoResolutionTime?: number
|
|
) {
|
|
const tags = parseTags(
|
|
`${question} ${description} ${extraTags.map((tag) => `#${tag}`).join(' ')}`
|
|
)
|
|
const lowercaseTags = tags.map((tag) => tag.toLowerCase())
|
|
|
|
const propsByOutcomeType =
|
|
outcomeType === 'BINARY'
|
|
? getBinaryCpmmProps(initialProb, ante) // getBinaryDpmProps(initialProb, ante)
|
|
: outcomeType === 'NUMERIC'
|
|
? getNumericProps(ante, bucketCount, min, max)
|
|
: getFreeAnswerProps(ante)
|
|
|
|
const contract: Contract = removeUndefinedProps({
|
|
id,
|
|
slug,
|
|
...propsByOutcomeType,
|
|
|
|
creatorId: creator.id,
|
|
creatorName: creator.name,
|
|
creatorUsername: creator.username,
|
|
creatorAvatarUrl: creator.avatarUrl,
|
|
|
|
question: question.trim(),
|
|
description: description.trim(),
|
|
tags,
|
|
lowercaseTags,
|
|
visibility: 'public',
|
|
isResolved: false,
|
|
createdTime: Date.now(),
|
|
closeTime,
|
|
autoResolutionTime,
|
|
|
|
volume: 0,
|
|
volume24Hours: 0,
|
|
volume7Days: 0,
|
|
|
|
collectedFees: {
|
|
creatorFee: 0,
|
|
liquidityFee: 0,
|
|
platformFee: 0,
|
|
},
|
|
})
|
|
|
|
return contract as Contract
|
|
}
|
|
|
|
/*
|
|
import { PHANTOM_ANTE } from './antes'
|
|
import { calcDpmInitialPool } from './calculate-dpm'
|
|
const getBinaryDpmProps = (initialProb: number, ante: number) => {
|
|
const { sharesYes, sharesNo, poolYes, poolNo, phantomYes, phantomNo } =
|
|
calcDpmInitialPool(initialProb, ante, PHANTOM_ANTE)
|
|
|
|
const system: DPM & Binary = {
|
|
mechanism: 'dpm-2',
|
|
outcomeType: 'BINARY',
|
|
initialProbability: initialProb / 100,
|
|
phantomShares: { YES: phantomYes, NO: phantomNo },
|
|
pool: { YES: poolYes, NO: poolNo },
|
|
totalShares: { YES: sharesYes, NO: sharesNo },
|
|
totalBets: { YES: poolYes, NO: poolNo },
|
|
}
|
|
|
|
return system
|
|
}
|
|
*/
|
|
|
|
const getBinaryCpmmProps = (initialProb: number, ante: number) => {
|
|
const pool = { YES: ante, NO: ante }
|
|
const p = initialProb / 100
|
|
|
|
const system: CPMM & Binary = {
|
|
mechanism: 'cpmm-1',
|
|
outcomeType: 'BINARY',
|
|
totalLiquidity: ante,
|
|
initialProbability: p,
|
|
p,
|
|
pool: pool,
|
|
}
|
|
|
|
return system
|
|
}
|
|
|
|
const getFreeAnswerProps = (ante: number) => {
|
|
const system: DPM & FreeResponse = {
|
|
mechanism: 'dpm-2',
|
|
outcomeType: 'FREE_RESPONSE',
|
|
pool: { '0': ante },
|
|
totalShares: { '0': ante },
|
|
totalBets: { '0': ante },
|
|
answers: [],
|
|
}
|
|
|
|
return system
|
|
}
|
|
|
|
const getNumericProps = (
|
|
ante: number,
|
|
bucketCount: number,
|
|
min: number,
|
|
max: number
|
|
) => {
|
|
const buckets = range(0, bucketCount).map((i) => i.toString())
|
|
|
|
const betAnte = ante / bucketCount
|
|
const pool = Object.fromEntries(buckets.map((answer) => [answer, betAnte]))
|
|
const totalBets = pool
|
|
|
|
const betShares = Math.sqrt(ante ** 2 / bucketCount)
|
|
const totalShares = Object.fromEntries(
|
|
buckets.map((answer) => [answer, betShares])
|
|
)
|
|
|
|
const system: DPM & Numeric = {
|
|
mechanism: 'dpm-2',
|
|
outcomeType: 'NUMERIC',
|
|
pool,
|
|
totalBets,
|
|
totalShares,
|
|
bucketCount,
|
|
min,
|
|
max,
|
|
}
|
|
|
|
return system
|
|
}
|