Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/cowprotocol/solver-rewards/llms.txt

Use this file to discover all available pages before exploring further.

AccountingPeriod encapsulates a contiguous date interval used to scope all solver reward queries. Every pipeline run targets exactly one period, and the period’s start and end dates are threaded through to Dune queries and CSV output filenames. Defined in src/models/accounting_period.py.

Date format

DATE_FORMAT = "%Y-%m-%d"
All date strings must conform to YYYY-MM-DD (ISO 8601). The module-level constant DATE_FORMAT is used consistently for both parsing and formatting.

AccountingPeriod class

class AccountingPeriod:
    """Class handling the date arithmetic and string conversions for date intervals"""

    def __init__(self, start: str, length_days: int = 7):
        self.start = datetime.strptime(start, DATE_FORMAT)
        self.end = self.start + timedelta(days=length_days)

Constructor parameters

start
str
required
Start date of the accounting period as an ISO 8601 string (YYYY-MM-DD). Parsed with datetime.strptime(start, "%Y-%m-%d") and stored as a datetime object.
period = AccountingPeriod("2024-01-01")
# period.start == datetime(2024, 1, 1, 0, 0)
length_days
int
Number of days in the period. The end date is computed as start + timedelta(days=length_days).Default: 7 (one calendar week)
period = AccountingPeriod("2024-01-01", length_days=14)
# period.end == datetime(2024, 1, 15, 0, 0)

Attributes

start
datetime
datetime object for the first instant of the period (midnight on the start date).
end
datetime
datetime object for the first instant after the period ends (midnight on start + length_days).

Methods

__str__()

Returns the period as a human-readable range string used in CSV filenames and log messages.
def __str__(self) -> str:
    return "-to-".join(
        [self.start.strftime(DATE_FORMAT), self.end.strftime(DATE_FORMAT)]
    )
Format: YYYY-MM-DD-to-YYYY-MM-DD
str(AccountingPeriod("2024-01-01"))
# "2024-01-01-to-2024-01-08"

str(AccountingPeriod("2024-03-25", length_days=14))
# "2024-03-25-to-2024-04-08"

__hash__()

Produces a stable integer hash from the concatenated date digits of start and end. This allows AccountingPeriod instances to be used as dictionary keys or in sets.
def __hash__(self) -> int:
    """Turns (1985-03-10, 1994-04-05) into only the digits 1985031019940405"""
    return int(
        "".join([self.start.strftime("%Y%m%d"), self.end.strftime("%Y%m%d")])
    )
Example: a period from 1985-03-10 to 1994-04-05 hashes to the integer 1985031019940405.
The hash is derived purely from the date values, so two AccountingPeriod instances with identical start and length_days will always produce the same hash regardless of when they were constructed.

as_query_params()

Converts the period into a pair of Dune QueryParameter objects for use in parametrised Dune queries.
def as_query_params(self) -> list[QueryParameter]:
    return [
        QueryParameter.date_type("start_time", self.start),
        QueryParameter.date_type("end_time", self.end),
    ]
Returns a list of two parameters:
Parameter nameValue
start_timeself.start as a Dune date parameter
end_timeself.end as a Dune date parameter
These parameters are consumed by DuneFetcher when executing on-chain queries for solver performance within the period.

Usage example

from src.models.accounting_period import AccountingPeriod

period = AccountingPeriod("2024-01-01")

print(str(period))          # "2024-01-01-to-2024-01-08"
print(period.start)         # 2024-01-01 00:00:00
print(period.end)           # 2024-01-08 00:00:00
print(hash(period))         # 2024010120240108
print(period.as_query_params())
# [
#   QueryParameter(name='start_time', value=datetime(2024, 1, 1, 0, 0)),
#   QueryParameter(name='end_time',   value=datetime(2024, 1, 8, 0, 0)),
# ]