66 lines
1.8 KiB
TypeScript
66 lines
1.8 KiB
TypeScript
import * as auditLogRepository from '../repositories/auditLogRepository';
|
|
|
|
export type PredictionBetSettlementStatus = 'won' | 'lost' | 'refunded' | 'step_advanced';
|
|
|
|
/**
|
|
* Records audit entry when a prediction bet is validated at maturity.
|
|
*/
|
|
export async function logPredictionBetSettled(data: {
|
|
userId: string;
|
|
betId: string;
|
|
candleOpenMs: number;
|
|
status: PredictionBetSettlementStatus;
|
|
direction?: string;
|
|
outcomeType: string;
|
|
stakeRaw: string;
|
|
payoutRaw?: string;
|
|
predictionMode?: string;
|
|
intervalMinutes?: number;
|
|
}): Promise<void> {
|
|
await auditLogRepository.create({
|
|
userId: data.userId,
|
|
action: 'prediction_settled',
|
|
resourceType: 'candle_predict_bet',
|
|
resourceId: data.betId,
|
|
metadata: {
|
|
candle_open_ms: data.candleOpenMs,
|
|
status: data.status,
|
|
direction: data.direction ?? null,
|
|
outcome: data.outcomeType,
|
|
stake_raw: data.stakeRaw,
|
|
payout_raw: data.payoutRaw ?? null,
|
|
prediction_mode: data.predictionMode ?? 'single',
|
|
interval_minutes: data.intervalMinutes ?? null,
|
|
},
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Records audit entry when a candle predict round is settled at maturity.
|
|
*/
|
|
export async function logPredictionRoundSettled(data: {
|
|
roundId: string;
|
|
candleOpenMs: number;
|
|
intervalMinutes: number;
|
|
outcomeType: string;
|
|
winner: string | null;
|
|
shortPool: number;
|
|
longPool: number;
|
|
betsSettled?: number;
|
|
}): Promise<void> {
|
|
await auditLogRepository.create({
|
|
action: 'prediction_round_settled',
|
|
resourceType: 'candle_predict_round',
|
|
resourceId: data.roundId,
|
|
metadata: {
|
|
candle_open_ms: data.candleOpenMs,
|
|
interval_minutes: data.intervalMinutes,
|
|
outcome: data.outcomeType,
|
|
winner: data.winner,
|
|
short_pool: data.shortPool,
|
|
long_pool: data.longPool,
|
|
bets_settled: data.betsSettled ?? null,
|
|
},
|
|
});
|
|
}
|