Serve time-bucketed token prices and point-in-time settlement history

This commit is contained in:
2026-12-03 04:56:05 +08:00
parent 9a411d5146
commit e397f21321
9 changed files with 334 additions and 1 deletions
+11
View File
@@ -218,3 +218,14 @@ CREATE TABLE IF NOT EXISTS augmented_results (
CREATE TRIGGER IF NOT EXISTS reject_placeholder_orders BEFORE INSERT ON orders
WHEN EXISTS(SELECT 1 FROM augmented_outcomes WHERE market=NEW.market AND role='placeholder')
BEGIN SELECT RAISE(ABORT,'outcome has not been named'); END;
-- Existing resolved rows have no trustworthy settlement timestamp to backfill.
CREATE TABLE IF NOT EXISTS price_settlements (
id INTEGER PRIMARY KEY, market TEXT NOT NULL UNIQUE REFERENCES markets,
winner TEXT NOT NULL, at_ms INTEGER NOT NULL
);
CREATE TRIGGER IF NOT EXISTS record_price_settlement AFTER UPDATE OF phase ON markets
WHEN NEW.phase='resolved' AND OLD.phase<>'resolved' BEGIN
INSERT INTO price_settlements(market,winner,at_ms)
VALUES(NEW.id,NEW.winner,CAST(unixepoch('subsec')*1000 AS INTEGER));
END;