Merge fixes

This commit is contained in:
James Grugett 2022-08-15 15:36:22 -05:00
parent cf85a8cc61
commit 84d66d8462
2 changed files with 25 additions and 19 deletions

View File

@ -75,10 +75,8 @@ export const createanswer = newEndpoint(opts, async (req, auth) => {
}
transaction.create(newAnswerDoc, answer)
const loanAmount = 0
const { newBet, newPool, newTotalShares, newTotalBets } =
getNewMultiBetInfo(answerId, amount, contract, loanAmount)
getNewMultiBetInfo(answerId, amount, contract)
const newBalance = user.balance - amount
const betDoc = firestore.collection(`contracts/${contractId}/bets`).doc()

View File

@ -1,7 +1,7 @@
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
import { getValues, log, writeAsync } from './utils'
import { Bet } from 'common/bet'
import { Bet, LimitBet } from 'common/bet'
import { Contract, CPMMContract, FreeResponseContract } from 'common/contract'
import { User } from 'common/user'
import { Dictionary, groupBy, keyBy, minBy, sumBy } from 'lodash'
@ -34,12 +34,14 @@ async function updateLoansCore() {
const contractsById = keyBy(contracts, (contract) => contract.id)
const betsByUser = groupBy(bets, (bet) => bet.userId)
const userLoanUpdates = users.map((user) =>
const userLoanUpdates = users
.map(
(user) =>
getUserLoanUpdates(betsByUser[user.id] ?? [], contractsById).betUpdates
).flat()
)
.flat()
const betUpdates = userLoanUpdates
.map((update) => ({
const betUpdates = userLoanUpdates.map((update) => ({
doc: firestore
.collection('contracts')
.doc(update.contractId)
@ -91,7 +93,13 @@ const getBinaryContractLoanUpdate = (contract: CPMMContract, bets: Bet[]) => {
const shares = YES || NO
const outcome = YES ? 'YES' : 'NO'
const { saleValue } = calculateCpmmSale(contract, shares, outcome)
const unfilledBets: LimitBet[] = []
const { saleValue } = calculateCpmmSale(
contract,
shares,
outcome,
unfilledBets
)
const loanAmount = sumBy(bets, (bet) => bet.loanAmount ?? 0)
const oldestBet = minBy(bets, (bet) => bet.createdTime)