From 9569f1af25b775f5780fabc4862089f5c7954b74 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Mon, 9 Dec 2024 10:24:53 -0800 Subject: [PATCH] Fix indie MC loan payouts --- backend/api/src/resolve-market.ts | 4 +--- backend/shared/src/resolve-market-helpers.ts | 2 +- common/src/payouts.ts | 9 +++++++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/backend/api/src/resolve-market.ts b/backend/api/src/resolve-market.ts index 42ff3ac08d..8c433afd37 100644 --- a/backend/api/src/resolve-market.ts +++ b/backend/api/src/resolve-market.ts @@ -45,9 +45,7 @@ export const resolveMarketMain: APIHandler< if (outcomeType === 'STONK') { throw new APIError(403, 'STONK contracts cannot be resolved') } - if (outcomeType === 'MULTIPLE_CHOICE' && contract.mechanism === 'cpmm-multi-1' && !contract.shouldAnswersSumToOne) { - throw new APIError(403, 'Independent multiple choice markets cannot currently be resolved') - } + const caller = await getUser(auth.uid) if (!caller) throw new APIError(400, 'Caller not found') if (caller.isBannedFromPosting || caller.userDeleted) diff --git a/backend/shared/src/resolve-market-helpers.ts b/backend/shared/src/resolve-market-helpers.ts index 2700798942..7ede236a79 100644 --- a/backend/shared/src/resolve-market-helpers.ts +++ b/backend/shared/src/resolve-market-helpers.ts @@ -349,7 +349,7 @@ export const getPayoutInfo = ( : undefined // Calculate loan payouts from contract metrics - const loanPayouts = getLoanPayouts(contractMetrics) + const loanPayouts = getLoanPayouts(contractMetrics, answerId) // Calculate payouts using contract metrics instead of bets const { traderPayouts, liquidityPayouts } = getPayouts( diff --git a/common/src/payouts.ts b/common/src/payouts.ts index 88b9ed0d18..272c6ce5ec 100644 --- a/common/src/payouts.ts +++ b/common/src/payouts.ts @@ -18,8 +18,13 @@ export type Payout = { userId: string payout: number } -export const getLoanPayouts = (contractMetrics: ContractMetric[]): Payout[] => { - const metricsWithLoans = contractMetrics.filter((metric) => metric.loan) +export const getLoanPayouts = ( + contractMetrics: ContractMetric[], + answerId?: string +): Payout[] => { + const metricsWithLoans = contractMetrics + .filter((metric) => metric.loan) + .filter((metric) => (answerId ? metric.answerId === answerId : true)) const metricsByUser = groupBy(metricsWithLoans, (metric) => metric.userId) const loansByUser = mapValues(metricsByUser, (metrics) => sumBy(metrics, (metric) => -(metric.loan ?? 0))