96 lines
2.3 KiB
Python
96 lines
2.3 KiB
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, asdict
|
|
from typing import Dict, Any, List
|
|
|
|
|
|
@dataclass
|
|
class LocalExecutionTask:
|
|
"""Canonical LocalExecutionTask per instrument/venue planning unit."""
|
|
task_id: str
|
|
instrument: str
|
|
venue: str
|
|
objective: str
|
|
constraints: Dict[str, Any]
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return asdict(self)
|
|
|
|
|
|
@dataclass
|
|
class SharedMarketContext:
|
|
"""Canonical SharedMarketContext with privacy-safe signals."""
|
|
signals: Dict[str, Any]
|
|
version: int
|
|
contract_id: str
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return asdict(self)
|
|
|
|
|
|
@dataclass
|
|
class PlanDelta:
|
|
"""Incremental routing/size/timing decisions with metadata."""
|
|
delta: Dict[str, Any]
|
|
timestamp: float
|
|
author: str
|
|
contract_id: str
|
|
privacy_budget: float
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return asdict(self)
|
|
|
|
|
|
@dataclass
|
|
class Attestation:
|
|
"""Cryptographic attestation for a delta or event."""
|
|
entry: str
|
|
signer: str
|
|
timestamp: float
|
|
contract_id: str
|
|
version: int
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return asdict(self)
|
|
|
|
|
|
@dataclass
|
|
class AuditLog:
|
|
"""Append-only log of attestations and approvals."""
|
|
entries: List[Attestation]
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return {"entries": [e.to_dict() for e in self.entries]}
|
|
|
|
|
|
@dataclass
|
|
class GraphOfContracts:
|
|
"""Registry for adapters and data-contract schemas."""
|
|
registry: Dict[str, Any]
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
return {"registry": self.registry}
|
|
|
|
|
|
def compute_delta(task: LocalExecutionTask, ctx: SharedMarketContext) -> PlanDelta:
|
|
"""Deterministic, minimal PlanDelta from inputs.
|
|
|
|
This is intentionally deterministic (timestamp=0.0) for replayability in tests
|
|
and backtesting scenarios. Real deployments can replace this with a richer solver.
|
|
"""
|
|
delta = {
|
|
"action": "hold",
|
|
"reason": "base-case",
|
|
"task_id": task.task_id,
|
|
"instrument": task.instrument,
|
|
"venue": task.venue,
|
|
"constraints_snapshot": task.constraints,
|
|
}
|
|
return PlanDelta(
|
|
delta=delta,
|
|
timestamp=0.0,
|
|
author="exprove-solver",
|
|
contract_id=ctx.contract_id,
|
|
privacy_budget=0.0,
|
|
)
|