From f4f41a1331eb338115dbd05a85179d00a54dd7ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:51:05 +0100 Subject: [PATCH 1/3] Create columns to track settlement gas info --- database/sql/V116__settlement_gas_cost.sql | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 database/sql/V116__settlement_gas_cost.sql diff --git a/database/sql/V116__settlement_gas_cost.sql b/database/sql/V116__settlement_gas_cost.sql new file mode 100644 index 0000000000..33f711c284 --- /dev/null +++ b/database/sql/V116__settlement_gas_cost.sql @@ -0,0 +1,11 @@ +-- Store the actual on-chain gas cost of each settlement transaction. +-- +-- These values are read from the transaction receipt by the autopilot's +-- settlement observer), letting the orderbook attribute a real gas cost +-- to individual trades and orders. +-- +-- Nullable: only populated for settlements observed after this migration is +-- deployed (no historical backfill). +ALTER TABLE settlements + ADD COLUMN gas_used numeric(78, 0), + ADD COLUMN effective_gas_price numeric(78, 0); From b10e29becad356c92a6656476145f89b36027dc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:55:06 +0100 Subject: [PATCH 2/3] Update database/sql/V116__settlement_gas_cost.sql Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com> --- database/sql/V116__settlement_gas_cost.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/sql/V116__settlement_gas_cost.sql b/database/sql/V116__settlement_gas_cost.sql index 33f711c284..930df68800 100644 --- a/database/sql/V116__settlement_gas_cost.sql +++ b/database/sql/V116__settlement_gas_cost.sql @@ -1,7 +1,7 @@ -- Store the actual on-chain gas cost of each settlement transaction. -- -- These values are read from the transaction receipt by the autopilot's --- settlement observer), letting the orderbook attribute a real gas cost +-- settlement observer, letting the orderbook attribute a real gas cost -- to individual trades and orders. -- -- Nullable: only populated for settlements observed after this migration is From eb5c5046bd5fe2d1e8d815a186ce9d7c64626b41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Duarte?= <15343819+jmg-duarte@users.noreply.github.com> Date: Mon, 3 Aug 2026 15:57:38 +0100 Subject: [PATCH 3/3] update readme --- database/README.md | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/database/README.md b/database/README.md index d9ff276ffe..c389acb414 100644 --- a/database/README.md +++ b/database/README.md @@ -423,14 +423,18 @@ Indexes: Stores data and metadata of [`Settlement`](https://github.com/cowprotocol/contracts/blob/main/src/contracts/GPv2Settlement.sol#L67-L68) events emitted from the settlement contract. - Column | Type | Nullable | Details ----------------|--------|----------|-------- - block\_number | bigint | not null | block in which the settlement happened - log\_index | bigint | not null | index in which the event was emitted - solver | bytea | not null | public address of the executing solver - tx\_hash | bytea | not null | transaction hash in which the settlement got executed - auction\_id | bigint | nullable | corresponding auction ID that initiated the settlement - solution\_uid | bigint | nullable | corresponding winning solver's solution UID, which is also used to identify settlements from the current environment + Column | Type | Nullable | Details +-----------------------|----------------|----------|-------- +block\_number | bigint | not null | block in which the settlement happened +log\_index | bigint | not null | index in which the event was emitted +solver | bytea | not null | public address of the executing solver +tx\_hash | bytea | not null | transaction hash in which the settlement got executed +auction\_id | bigint | nullable | corresponding auction ID that initiated the settlement +solution\_uid | bigint | nullable | corresponding winning solver's solution UID, which is also used to identify settlements from the current environment +gas\_used | numeric(78, 0) | nullable | gas consumed by the settlement transaction, read from the transaction receipt + effective\_gas\_price | numeric(78, 0) | nullable | gas price actually paid per unit of gas (in wei), read from the transaction receipt + +The total on-chain cost of a settlement is `gas_used * effective_gas_price`. Both columns are populated by the `autopilot`'s settlement observer and are only set for settlements observed after the migration that added them; historical rows were not backfilled, so consumers (e.g. the `orderbook` attributing gas cost to individual trades and orders) must handle `NULL`. Indexes: - PRIMARY KEY: btree(`block_number`,`log_index`)