250 lines
12 KiB
JavaScript
250 lines
12 KiB
JavaScript
"use strict";
|
||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||
};
|
||
Object.defineProperty(exports, "__esModule", { value: true });
|
||
const node_test_1 = require("node:test");
|
||
const strict_1 = __importDefault(require("node:assert/strict"));
|
||
const dailyRevenueOutcomeService_1 = require("../services/dailyRevenueOutcomeService");
|
||
const candleGenerationService_1 = require("../services/candleGenerationService");
|
||
(0, node_test_1.describe)('dailyRevenueOutcomeService', () => {
|
||
(0, node_test_1.test)('pickRandomDirectionalOutcome respects RNG', () => {
|
||
strict_1.default.equal((0, dailyRevenueOutcomeService_1.pickRandomDirectionalOutcome)(() => 0.1).winner, 'short');
|
||
strict_1.default.equal((0, dailyRevenueOutcomeService_1.pickRandomDirectionalOutcome)(() => 0.9).winner, 'long');
|
||
});
|
||
(0, node_test_1.test)('keeps random when it is the minority side', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: 'short',
|
||
projectedMajorityRoundPnlRaw: -1000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'short_win');
|
||
strict_1.default.equal(outcome.winner, 'short');
|
||
});
|
||
(0, node_test_1.test)('keeps majority random when floor is respected', () => {
|
||
// daily 10 + round pnl +2 >= target 5
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: 2000000n,
|
||
dailyNetRaw: 10000000n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'long_win');
|
||
strict_1.default.equal(outcome.winner, 'long');
|
||
});
|
||
(0, node_test_1.test)('streak-capped randomWinner still respects financial gate (target reached)', () => {
|
||
// 5 short in a row → streak forces long; long is majority; floor already OK → keep long.
|
||
const streakForced = (0, candleGenerationService_1.resolveAutoNoBetOutcome)(['short_win', 'short_win', 'short_win', 'short_win', 'short_win'], 5);
|
||
strict_1.default.equal(streakForced.winner, 'long');
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: streakForced.winner,
|
||
projectedMajorityRoundPnlRaw: 1000000n,
|
||
dailyNetRaw: 10000000n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'long_win');
|
||
strict_1.default.equal(outcome.winner, 'long');
|
||
});
|
||
(0, node_test_1.test)('streak-capped majority randomWinner still overflows when floor would breach', () => {
|
||
const streakForced = (0, candleGenerationService_1.resolveAutoNoBetOutcome)(['short_win', 'short_win', 'short_win', 'short_win', 'short_win'], 5);
|
||
strict_1.default.equal(streakForced.winner, 'long');
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: streakForced.winner,
|
||
projectedMajorityRoundPnlRaw: -8000000n,
|
||
dailyNetRaw: 10000000n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('streak-capped minority randomWinner bypasses financial gate', () => {
|
||
// 5 long in a row → force short; short is minority → keep short regardless of floor.
|
||
const streakForced = (0, candleGenerationService_1.resolveAutoNoBetOutcome)(['long_win', 'long_win', 'long_win', 'long_win', 'long_win'], 5);
|
||
strict_1.default.equal(streakForced.winner, 'short');
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: streakForced.winner,
|
||
projectedMajorityRoundPnlRaw: -50000000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'short_win');
|
||
strict_1.default.equal(outcome.winner, 'short');
|
||
});
|
||
(0, node_test_1.test)('overflow to neutral when majority would breach floor', () => {
|
||
// daily 10 + round pnl -8 = 2 < target 5
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -8000000n,
|
||
dailyNetRaw: 10000000n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
strict_1.default.equal(outcome.winner, null);
|
||
});
|
||
(0, node_test_1.test)('overflow to minority when configured', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 30,
|
||
longPool: 70,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -8000000n,
|
||
dailyNetRaw: 10000000n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'minority',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'short_win');
|
||
strict_1.default.equal(outcome.winner, 'short');
|
||
});
|
||
(0, node_test_1.test)('equal pools keep random (no majority) when neutrality is not passed', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 50,
|
||
longPool: 50,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -1n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'long_win');
|
||
});
|
||
(0, node_test_1.test)('neutrality pre-filter: equal pools → neutral before random/financial gate', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 50,
|
||
longPool: 50,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -1n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'minority',
|
||
neutralityRules: {
|
||
minTolerancePercent: 2,
|
||
maxTolerancePercent: 95,
|
||
minToleranceEnabled: false,
|
||
maxToleranceEnabled: false,
|
||
},
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('neutrality pre-filter: max imbalance → neutral (solo 100/0)', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 0,
|
||
longPool: 10,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -9000000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'minority',
|
||
neutralityRules: {
|
||
minTolerancePercent: 2,
|
||
maxTolerancePercent: 95,
|
||
minToleranceEnabled: true,
|
||
maxToleranceEnabled: true,
|
||
},
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('with neutrality disabled for max, solo majority still hits financial overflow', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 0,
|
||
longPool: 10,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -9000000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
neutralityRules: {
|
||
minTolerancePercent: 2,
|
||
maxTolerancePercent: 95,
|
||
minToleranceEnabled: false,
|
||
maxToleranceEnabled: false,
|
||
},
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('solo majority that breaches floor → minority overflow (empty side wins)', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 0,
|
||
longPool: 10,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -9000000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'minority',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'short_win');
|
||
strict_1.default.equal(outcome.winner, 'short');
|
||
});
|
||
(0, node_test_1.test)('solo majority that breaches floor → neutral overflow', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 0,
|
||
longPool: 10,
|
||
randomWinner: 'long',
|
||
projectedMajorityRoundPnlRaw: -9000000n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 5000000n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('projectedMajorityRoundPnl = stakes − payouts', () => {
|
||
strict_1.default.equal((0, dailyRevenueOutcomeService_1.projectedMajorityRoundPnl)(20000000n, 19000000n), 1000000n);
|
||
strict_1.default.equal((0, dailyRevenueOutcomeService_1.projectedMajorityRoundPnl)(10000000n, 19000000n), -9000000n);
|
||
});
|
||
(0, node_test_1.test)('empty pools → neutral', () => {
|
||
const outcome = (0, dailyRevenueOutcomeService_1.resolveDailyRevenueOutcome)({
|
||
shortPool: 0,
|
||
longPool: 0,
|
||
randomWinner: 'short',
|
||
projectedMajorityRoundPnlRaw: 0n,
|
||
dailyNetRaw: 0n,
|
||
targetRaw: 0n,
|
||
overflowStrategy: 'neutral',
|
||
});
|
||
strict_1.default.equal(outcome.type, 'neutral');
|
||
});
|
||
(0, node_test_1.test)('projectMajorityWinSettlement sums singles and final multi wins', () => {
|
||
const projected = (0, dailyRevenueOutcomeService_1.projectMajorityWinSettlement)({
|
||
majority: 'long',
|
||
singles: [
|
||
{ direction: 'long', stake_raw: '1000000', stake_account_kind: 'main', interval_minutes: 1 },
|
||
{ direction: 'short', stake_raw: '500000', stake_account_kind: 'main', interval_minutes: 1 },
|
||
{ direction: 'long', stake_raw: '1000000', stake_account_kind: 'test', interval_minutes: 1 },
|
||
],
|
||
multis: [
|
||
{
|
||
sequence_directions: ['long', 'long'],
|
||
multi_level: 2,
|
||
sequence_step: 1,
|
||
stake_raw: '2000000',
|
||
stake_display: '2',
|
||
stake_account_kind: 'bonus',
|
||
},
|
||
],
|
||
singlePayoutMultiplier: () => 1.9,
|
||
multiPayoutMultiplier: () => 2,
|
||
});
|
||
// singles real: 1.0 + 0.5 = 1.5 USDT raw units 1e6; multi final 2.0
|
||
strict_1.default.equal(projected.totalStakeRaw, 3500000n);
|
||
// long single payout 1.9 + multi 2*2=4 → 1.9e6 + 4e6
|
||
strict_1.default.equal(projected.majorityPayoutRaw, 5900000n);
|
||
strict_1.default.equal(projected.roundPnlRaw, 3500000n - 5900000n);
|
||
});
|
||
});
|
||
//# sourceMappingURL=dailyRevenueOutcomeService.test.js.map
|