Files
grenadeandClaude Opus 5.5 5361dec713
ci / gate (push) Successful in 4m7s
deploy / validate (push) Skipped
deploy / build (push) Successful in 8m55s
deploy / deploy-web (push) Successful in 5s
deploy / deploy-api (push) Successful in 18s
feat: record the Ref pool's bid side over time
Each pool read now writes a snapshot — totals, swap volumes, and what
selling 10, 100, 1,000 and 5,000 of the asset would fetch from the
pool's own `quote` view — and the order book whenever it changed
(migration 0014). `/v1/chains/{chain}/ref/bids` turns that into the
series #41 asks for: posted orders, money held otherwise, net swapped
in, the quotes; the book now against N hours ago; and every level
change, classified by `dcl::level_changes` — a shrink the pool's payout
in the same minute accounts for is "taken by a swap" (consistent with
one, not proof), the rest "withdrawn", allocated nearest the price
first. The `ref-dcl` page shows it as four one-hue sparkline tiles and
two tables, never one chart in several colours.

Also records in CLAUDE.md why three deploys were cancelled: Gitea
cancels runs by commit when a branch at that commit is deleted.

Refs #41

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015pkwBsR54NRmZyU4QVhvfj
2026-10-06 18:17:11 +03:00

44 lines
2.0 KiB
SQL

-- The bid side of Ref DCL pools holding the tracked asset, over time.
-- blackbeard/observer#41.
--
-- The pool's state is read once a minute (refdcl::pools) and was only ever
-- held in memory, so the page could say what the bid side is but never how it
-- got there. A seller deciding when to sell needs the second: whether posted
-- orders are growing or being pulled, and whether buyers' own money is coming
-- in or going out.
--
-- One snapshot row per pool per read: the totals, the cumulative swap
-- volumes, and what selling fixed amounts of the asset would fetch at that
-- moment (the pool's own `quote` view: a computation from pool state, not
-- anyone's offer). Amounts are base units, as the contract reports them.
create table ref_pool_snapshot (
chain text not null references chain (id) on delete cascade,
pool_id text not null,
at timestamptz not null,
current_point integer not null,
total_x numeric not null,
total_y numeric not null,
total_order_x numeric not null,
total_order_y numeric not null,
volume_x_in numeric not null,
volume_x_out numeric not null,
volume_y_in numeric not null,
volume_y_out numeric not null,
-- {"<asset sold, base units>": "<counter received, base units>"}; a size
-- the view could not answer is left out, never written as zero.
quotes jsonb not null default '{}'::jsonb,
primary key (chain, pool_id, at)
);
-- The limit-order book, written only when it differs from the last one
-- written: the book as it stood at any moment is the latest row at or before
-- it. `levels` is `[{"point", "amount_x", "amount_y"}]`, base units as
-- strings, what remained open at each point.
create table ref_pool_book (
chain text not null references chain (id) on delete cascade,
pool_id text not null,
at timestamptz not null,
levels jsonb not null,
primary key (chain, pool_id, at)
);