30 lines
1.1 KiB
Python
30 lines
1.1 KiB
Python
"""Rules of the game that do not depend on how money moves (shared by the simulated ledger and,
|
|||
|
|
later, the chain engine)."""
|
||
|
|
|
||
|
|
from datetime import datetime, timedelta
|
||
|
|
|
||
|
|
from django.utils import timezone
|
||
|
|
|
||
|
|
from .models import Round
|
||
|
|
|
||
|
|
# B-52: a round never grows past what one payout can spend ("it can always be paid out").
|
||
|
|
MAX_PARTICIPANTS_PER_ROUND = 400
|
||
|
|
|
||
|
|
# ADR-14: 70% to the winner, 30% to the platform, the rounding remainder to the platform.
|
||
|
|
WINNER_PERCENT = 70
|
||
|
|
|
||
|
|
|
||
|
|
def winner_share(pool_sats: int) -> int:
|
||
|
|
return pool_sats * WINNER_PERCENT // 100
|
||
|
|
|
||
|
|
|
||
|
|
def round_deadline(round_: Round) -> datetime:
|
||
|
|
"""The round's own deadline: opening plus *its* duration, never the live config (ADR-23, B-61)."""
|
||
|
|
return round_.opened_at + timedelta(seconds=round_.duration_seconds)
|
||
|
|
|
||
|
|
|
||
|
|
def round_accepts_bets(round_: Round, now: datetime | None = None) -> bool:
|
||
|
|
"""The authoritative "yellow light": a bet is refused from the deadline on, even if the
|
||
|
|
scheduler has not flipped the status yet (ADR-23)."""
|
||
|
|
now = now or timezone.now()
|
||
|
|
return round_.status == Round.Status.OPEN and now < round_deadline(round_)
|