Skip to content

Commit

Permalink
Fix indie MC loan payouts
Browse files Browse the repository at this point in the history
  • Loading branch information
IanPhilips committed Dec 9, 2024
1 parent 698c627 commit 9569f1a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 1 addition & 3 deletions backend/api/src/resolve-market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion backend/shared/src/resolve-market-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 7 additions & 2 deletions common/src/payouts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9569f1a

Please sign in to comment.