Cleanup to resolve market API resolutions input, fixes
This commit is contained in:
parent
f647797037
commit
d07e559e5c
|
@ -48,12 +48,12 @@ export type PayoutInfo = {
|
|||
|
||||
export const getPayouts = (
|
||||
outcome: string | undefined,
|
||||
resolutions: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
contract: Contract,
|
||||
bets: Bet[],
|
||||
liquidities: LiquidityProvision[],
|
||||
resolutions?: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
resolutionProbability?: number
|
||||
): PayoutInfo => {
|
||||
if (contract.mechanism === 'cpmm-1' && contract.outcomeType === 'BINARY') {
|
||||
|
@ -67,9 +67,9 @@ export const getPayouts = (
|
|||
}
|
||||
return getDpmPayouts(
|
||||
outcome,
|
||||
resolutions,
|
||||
contract,
|
||||
bets,
|
||||
resolutions,
|
||||
resolutionProbability
|
||||
)
|
||||
}
|
||||
|
@ -100,11 +100,11 @@ export const getFixedPayouts = (
|
|||
|
||||
export const getDpmPayouts = (
|
||||
outcome: string | undefined,
|
||||
resolutions: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
contract: DPMContract,
|
||||
bets: Bet[],
|
||||
resolutions?: {
|
||||
[outcome: string]: number
|
||||
},
|
||||
resolutionProbability?: number
|
||||
): PayoutInfo => {
|
||||
const openBets = bets.filter((b) => !b.isSold && !b.sale)
|
||||
|
@ -115,8 +115,8 @@ export const getDpmPayouts = (
|
|||
return getDpmStandardPayouts(outcome, contract, openBets)
|
||||
|
||||
case 'MKT':
|
||||
return contract.outcomeType === 'FREE_RESPONSE'
|
||||
? getPayoutsMultiOutcome(resolutions, contract, openBets)
|
||||
return contract.outcomeType === 'FREE_RESPONSE' // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
? getPayoutsMultiOutcome(resolutions!, contract, openBets)
|
||||
: getDpmMktPayouts(contract, openBets, resolutionProbability)
|
||||
case 'CANCEL':
|
||||
case undefined:
|
||||
|
|
|
@ -42,10 +42,10 @@ export function scoreUsersByContract(contract: Contract, bets: Bet[]) {
|
|||
)
|
||||
const { payouts: resolvePayouts } = getPayouts(
|
||||
resolution as string,
|
||||
{},
|
||||
contract,
|
||||
openBets,
|
||||
[],
|
||||
{},
|
||||
resolutionProb
|
||||
)
|
||||
|
||||
|
|
|
@ -28,20 +28,29 @@ const binarySchema = z.object({
|
|||
|
||||
const freeResponseSchema = z.union([
|
||||
z.object({
|
||||
outcome: z.union([z.enum(['CANCEL']), z.number()]),
|
||||
outcome: z.literal('CANCEL'),
|
||||
}),
|
||||
z.object({
|
||||
outcome: z.enum(['MKT']),
|
||||
resolutions: z.map(z.string(), z.number()),
|
||||
outcome: z.literal('MKT'),
|
||||
resolutions: z.array(
|
||||
z.object({
|
||||
answer: z.number().int().nonnegative(),
|
||||
pct: z.number().nonnegative(),
|
||||
})
|
||||
),
|
||||
}),
|
||||
z.object({
|
||||
outcome: z.number().gte(0),
|
||||
}),
|
||||
])
|
||||
|
||||
const numericSchema = z.object({
|
||||
outcome: z.union([z.enum(['CANCEL']), z.string()]),
|
||||
outcome: z.union([z.literal('CANCEL'), z.string()]),
|
||||
value: z.number().optional(),
|
||||
})
|
||||
|
||||
export const resolvemarket = newEndpoint(['POST'], async (req, auth) => {
|
||||
const opts = { secrets: ['MAILGUN_KEY'] }
|
||||
export const resolvemarket = newEndpoint(opts, async (req, auth) => {
|
||||
const { contractId } = validate(bodySchema, req.body)
|
||||
const userId = auth.uid
|
||||
|
||||
|
@ -90,10 +99,10 @@ export const resolvemarket = newEndpoint(['POST'], async (req, auth) => {
|
|||
const { payouts, creatorPayout, liquidityPayouts, collectedFees } =
|
||||
getPayouts(
|
||||
outcome,
|
||||
Object.fromEntries(resolutions || []),
|
||||
contract,
|
||||
bets,
|
||||
liquidities,
|
||||
resolutions,
|
||||
resolutionProbability
|
||||
)
|
||||
|
||||
|
@ -144,7 +153,7 @@ export const resolvemarket = newEndpoint(['POST'], async (req, auth) => {
|
|||
contract,
|
||||
outcome,
|
||||
resolutionProbability,
|
||||
Object.fromEntries(resolutions || [])
|
||||
resolutions
|
||||
)
|
||||
|
||||
return updatedContract
|
||||
|
@ -218,7 +227,9 @@ function getResolutionParams(outcomeType: string, body: string) {
|
|||
const { outcome } = freeResponseParams
|
||||
const resolutions =
|
||||
'resolutions' in freeResponseParams
|
||||
? freeResponseParams.resolutions
|
||||
? Object.fromEntries(
|
||||
freeResponseParams.resolutions.map((r) => [r.answer, r.pct])
|
||||
)
|
||||
: undefined
|
||||
return {
|
||||
// Free Response outcome IDs are numbers by convention,
|
||||
|
|
|
@ -27,10 +27,10 @@ async function checkIfPayOutAgain(contractRef: DocRef, contract: Contract) {
|
|||
|
||||
const { payouts } = getPayouts(
|
||||
resolution,
|
||||
resolutions,
|
||||
contract,
|
||||
openBets,
|
||||
[],
|
||||
resolutions,
|
||||
resolutionProbability
|
||||
)
|
||||
|
||||
|
|
|
@ -31,20 +31,19 @@ export function AnswerResolvePanel(props: {
|
|||
setIsSubmitting(true)
|
||||
|
||||
const totalProb = sum(Object.values(chosenAnswers))
|
||||
const normalizedProbs = mapValues(
|
||||
chosenAnswers,
|
||||
(prob) => (100 * prob) / totalProb
|
||||
)
|
||||
const resolutions = Object.entries(chosenAnswers).map(([i, p]) => {
|
||||
return { answer: parseInt(i), pct: (100 * p) / totalProb }
|
||||
})
|
||||
|
||||
const resolutionProps = removeUndefinedProps({
|
||||
outcome:
|
||||
resolveOption === 'CHOOSE'
|
||||
? answers[0]
|
||||
? parseInt(answers[0])
|
||||
: resolveOption === 'CHOOSE_MULTIPLE'
|
||||
? 'MKT'
|
||||
: 'CANCEL',
|
||||
resolutions:
|
||||
resolveOption === 'CHOOSE_MULTIPLE' ? normalizedProbs : undefined,
|
||||
resolveOption === 'CHOOSE_MULTIPLE' ? resolutions : undefined,
|
||||
contractId: contract.id,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user