feat: record the Ref pool's bid side over time
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

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
This commit is contained in:
2026-10-06 18:17:11 +03:00
co-authored by Claude Opus 5.5
parent 1d25689e3d
commit 5361dec713
21 changed files with 1479 additions and 4 deletions
@@ -0,0 +1,23 @@
{
"db_name": "PostgreSQL",
"query": "select min(at) as at from ref_pool_snapshot where chain = $1 and pool_id = $2",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "at",
"type_info": "Timestamptz"
}
],
"parameters": {
"Left": [
"Text",
"Text"
]
},
"nullable": [
null
]
},
"hash": "2e942fa1bbe65e8d4779710df272b2fd7ae4bee99521043a6ee5b005945b19e4"
}
@@ -0,0 +1,84 @@
{
"db_name": "PostgreSQL",
"query": "\n select at, current_point,\n total_x::text as \"total_x!\", total_y::text as \"total_y!\",\n total_order_x::text as \"total_order_x!\", total_order_y::text as \"total_order_y!\",\n volume_x_in::text as \"volume_x_in!\", volume_x_out::text as \"volume_x_out!\",\n volume_y_in::text as \"volume_y_in!\", volume_y_out::text as \"volume_y_out!\",\n quotes\n from ref_pool_snapshot\n where chain = $1 and pool_id = $2 and at >= $3\n order by at\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "at",
"type_info": "Timestamptz"
},
{
"ordinal": 1,
"name": "current_point",
"type_info": "Int4"
},
{
"ordinal": 2,
"name": "total_x!",
"type_info": "Text"
},
{
"ordinal": 3,
"name": "total_y!",
"type_info": "Text"
},
{
"ordinal": 4,
"name": "total_order_x!",
"type_info": "Text"
},
{
"ordinal": 5,
"name": "total_order_y!",
"type_info": "Text"
},
{
"ordinal": 6,
"name": "volume_x_in!",
"type_info": "Text"
},
{
"ordinal": 7,
"name": "volume_x_out!",
"type_info": "Text"
},
{
"ordinal": 8,
"name": "volume_y_in!",
"type_info": "Text"
},
{
"ordinal": 9,
"name": "volume_y_out!",
"type_info": "Text"
},
{
"ordinal": 10,
"name": "quotes",
"type_info": "Jsonb"
}
],
"parameters": {
"Left": [
"Text",
"Text",
"Timestamptz"
]
},
"nullable": [
false,
false,
null,
null,
null,
null,
null,
null,
null,
null,
false
]
},
"hash": "4fe0a5f2a76e82f6044b4fb9761f429156968bd541b854cb643b092c2081b59b"
}
@@ -0,0 +1,26 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into ref_pool_snapshot\n (chain, pool_id, at, current_point, total_x, total_y, total_order_x,\n total_order_y, volume_x_in, volume_x_out, volume_y_in, volume_y_out, quotes)\n values ($1, $2, $3, $4, $5::text::numeric, $6::text::numeric, $7::text::numeric,\n $8::text::numeric, $9::text::numeric, $10::text::numeric,\n $11::text::numeric, $12::text::numeric, $13)\n on conflict (chain, pool_id, at) do nothing\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text",
"Timestamptz",
"Int4",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Text",
"Jsonb"
]
},
"nullable": []
},
"hash": "6610f568efe388ddafd4b33cafae6e17c0fbbb049ce06f2286b2b5ed963adec1"
}
@@ -0,0 +1,17 @@
{
"db_name": "PostgreSQL",
"query": "\n insert into ref_pool_book (chain, pool_id, at, levels)\n select $1, $2, $3, $4\n where not exists (\n select 1 from (\n select levels from ref_pool_book\n where chain = $1 and pool_id = $2\n order by at desc limit 1\n ) last\n where last.levels = $4\n )\n on conflict (chain, pool_id, at) do nothing\n ",
"describe": {
"columns": [],
"parameters": {
"Left": [
"Text",
"Text",
"Timestamptz",
"Jsonb"
]
},
"nullable": []
},
"hash": "cf30b6074ccff2995fbf42200608ba36fc08d7be6c485eb6a836e45aedc3546f"
}
@@ -0,0 +1,30 @@
{
"db_name": "PostgreSQL",
"query": "\n select at as \"at!\", levels as \"levels!\" from (\n (select at, levels from ref_pool_book\n where chain = $1 and pool_id = $2 and at < $3\n order by at desc limit 1)\n union all\n (select at, levels from ref_pool_book\n where chain = $1 and pool_id = $2 and at >= $3)\n ) b\n order by at\n ",
"describe": {
"columns": [
{
"ordinal": 0,
"name": "at!",
"type_info": "Timestamptz"
},
{
"ordinal": 1,
"name": "levels!",
"type_info": "Jsonb"
}
],
"parameters": {
"Left": [
"Text",
"Text",
"Timestamptz"
]
},
"nullable": [
null,
null
]
},
"hash": "f28569d76e122b1dfbd3c7ec04c4038e5d5ce750c5294e089aea74bcf926e9bb"
}