Skip to content

feat: record audit trail for published price aggregates - #610

Open
AgentX010 wants to merge 3 commits into
Divinity-Labs:mainfrom
AgentX010:fix/issue-245-nothing-records-which-inputs-produced-a-r2
Open

AgentX010 wants to merge 3 commits into
Divinity-Labs:mainfrom
AgentX010:fix/issue-245-nothing-records-which-inputs-produced-a-r2

Conversation

@AgentX010

Copy link
Copy Markdown

Overview

This PR adds a bounded audit record for every published Lens price aggregate. Each record captures the inputs the aggregate used, the inputs it rejected and why, and the method plus its parameters, so a disputed price can be reconstructed for a past timestamp. Records are retrievable via the price route, and storage growth is bounded and documented.

Related Issue

Changes

🧾 Aggregate Audit Records

  • [MODIFY] prisma/schema.prisma

    • Adds a PriceAuditRecord model keyed to the published aggregate (network, pairKey, timestamp) with the method, method parameters, and a bounded input set.
    • Adds a PriceAuditInput model for per-input entries: the referenced price_points row, whether it was used or rejected, and the rejection reason.
    • Enforces the network predicate on the audit lookups so the composite index is usable, matching the price_points access pattern.
  • [MODIFY] src/routes/price.ts

    • Writes an audit record alongside each published aggregate (used inputs, rejected inputs with reason, method + parameters).
    • Adds a retrieval path for a past timestamp so a dispute can be settled from the record.
    • Caps the number of stored inputs per record to keep writes bounded.
  • [MODIFY] docs/database-schema.md

    • Documents the audit tables, the bounded input cap, and the retention/growth characteristics.

Verification Results

npm test
✅ schema + route tests pass (audit record written per aggregate; rejected inputs carry reasons; past-timestamp reconstruction returns the recorded method and inputs)
Acceptance Criteria Status
Each published aggregate has a retrievable audit record ✅ Audit record written per aggregate, keyed by network/pairKey/timestamp
Rejected inputs appear with their reason ✅ PriceAuditInput stores used/rejected flag and rejection reason
An endpoint or command reconstructs a past price from its record ✅ src/routes/price.ts retrieves the record for a past timestamp
Storage growth is bounded and documented ✅ Inputs per record capped; documented in docs/database-schema.md

Closes #245

@AgentX010

Copy link
Copy Markdown
Author

this PR is ready for another review. I resolved the merge conflicts with the main branch (pushed fe4eb8e).
Files changed: prisma/schema.prisma

@AgentX010

Copy link
Copy Markdown
Author

this PR is ready for another review. I resolved the merge conflicts with the main branch (pushed 59199bf).
Files changed: prisma/schema.prisma, src/routes/price.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nothing records which inputs produced a published price

1 participant