From e9fee047619bc311d53bef27b689951c4d3036dd Mon Sep 17 00:00:00 2001 From: mantikoros Date: Thu, 19 May 2022 22:06:50 -0400 Subject: [PATCH] ante for free FR market now come from house --- common/antes.ts | 4 +- functions/src/create-contract.ts | 106 +++++++++++++++---------------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/common/antes.ts b/common/antes.ts index a6bd733a..07251f06 100644 --- a/common/antes.ts +++ b/common/antes.ts @@ -88,7 +88,7 @@ export function getAnteBets( } export function getFreeAnswerAnte( - creator: User, + anteBettorId: string, contract: FullContract, anteBetId: string ) { @@ -100,7 +100,7 @@ export function getFreeAnswerAnte( const anteBet: Bet = { id: anteBetId, - userId: creator.id, + userId: anteBettorId, contractId: contract.id, amount, shares, diff --git a/functions/src/create-contract.ts b/functions/src/create-contract.ts index 68857e40..4046df5c 100644 --- a/functions/src/create-contract.ts +++ b/functions/src/create-contract.ts @@ -141,72 +141,68 @@ export const createContract = newEndpoint(['POST'], async (req, _res) => { await contractRef.create(contract) - if (ante) { - if (outcomeType === 'BINARY' && contract.mechanism === 'dpm-2') { - const yesBetDoc = firestore - .collection(`contracts/${contract.id}/bets`) - .doc() + const providerId = isFree ? HOUSE_LIQUIDITY_PROVIDER_ID : creator.id - const noBetDoc = firestore - .collection(`contracts/${contract.id}/bets`) - .doc() + if (outcomeType === 'BINARY' && contract.mechanism === 'dpm-2') { + const yesBetDoc = firestore + .collection(`contracts/${contract.id}/bets`) + .doc() - const { yesBet, noBet } = getAnteBets( - creator, - contract as FullContract, - yesBetDoc.id, - noBetDoc.id - ) + const noBetDoc = firestore.collection(`contracts/${contract.id}/bets`).doc() - await yesBetDoc.set(yesBet) - await noBetDoc.set(noBet) - } else if (outcomeType === 'BINARY') { - const liquidityDoc = firestore - .collection(`contracts/${contract.id}/liquidity`) - .doc() + const { yesBet, noBet } = getAnteBets( + creator, + contract as FullContract, + yesBetDoc.id, + noBetDoc.id + ) - const providerId = isFree ? HOUSE_LIQUIDITY_PROVIDER_ID : creator.id + await yesBetDoc.set(yesBet) + await noBetDoc.set(noBet) + } else if (outcomeType === 'BINARY') { + const liquidityDoc = firestore + .collection(`contracts/${contract.id}/liquidity`) + .doc() - const lp = getCpmmInitialLiquidity( - providerId, - contract as FullContract, - liquidityDoc.id, - ante - ) + const lp = getCpmmInitialLiquidity( + providerId, + contract as FullContract, + liquidityDoc.id, + ante + ) - await liquidityDoc.set(lp) - } else if (outcomeType === 'FREE_RESPONSE') { - const noneAnswerDoc = firestore - .collection(`contracts/${contract.id}/answers`) - .doc('0') + await liquidityDoc.set(lp) + } else if (outcomeType === 'FREE_RESPONSE') { + const noneAnswerDoc = firestore + .collection(`contracts/${contract.id}/answers`) + .doc('0') - const noneAnswer = getNoneAnswer(contract.id, creator) - await noneAnswerDoc.set(noneAnswer) + const noneAnswer = getNoneAnswer(contract.id, creator) + await noneAnswerDoc.set(noneAnswer) - const anteBetDoc = firestore - .collection(`contracts/${contract.id}/bets`) - .doc() + const anteBetDoc = firestore + .collection(`contracts/${contract.id}/bets`) + .doc() - const anteBet = getFreeAnswerAnte( - creator, - contract as FullContract, - anteBetDoc.id - ) - await anteBetDoc.set(anteBet) - } else if (outcomeType === 'NUMERIC') { - const anteBetDoc = firestore - .collection(`contracts/${contract.id}/bets`) - .doc() + const anteBet = getFreeAnswerAnte( + providerId, + contract as FullContract, + anteBetDoc.id + ) + await anteBetDoc.set(anteBet) + } else if (outcomeType === 'NUMERIC') { + const anteBetDoc = firestore + .collection(`contracts/${contract.id}/bets`) + .doc() - const anteBet = getNumericAnte( - creator, - contract as FullContract, - ante, - anteBetDoc.id - ) + const anteBet = getNumericAnte( + creator, + contract as FullContract, + ante, + anteBetDoc.id + ) - await anteBetDoc.set(anteBet) - } + await anteBetDoc.set(anteBet) } return { contract: contract }