From f1e778fa965e4e82680a6d46634dd273e99de3a7 Mon Sep 17 00:00:00 2001 From: Lucas Meier Date: Thu, 12 Sep 2024 15:18:11 -0700 Subject: [PATCH] pindexer: Allow for multiple BatchSwaps in a single block This fixes a bug where we assumed there was only one swap per block, ignoring the fact that each trading pair will have a different batch swap. --- crates/bin/pindexer/src/dex/dex.sql | 3 ++- crates/bin/pindexer/src/dex/mod.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/bin/pindexer/src/dex/dex.sql b/crates/bin/pindexer/src/dex/dex.sql index 720dbce968..a5d1c3c13d 100644 --- a/crates/bin/pindexer/src/dex/dex.sql +++ b/crates/bin/pindexer/src/dex/dex.sql @@ -116,7 +116,8 @@ CREATE TABLE IF NOT EXISTS dex_lp_execution ( --- Represents instances where swap executions happened. CREATE TABLE IF NOT EXISTS dex_batch_swap ( - height BIGINT PRIMARY KEY, + id SERIAL PRIMARY KEY, + height BIGINT NOT NULL, trace12_start INTEGER REFERENCES dex_trace (id), trace12_end INTEGER REFERENCES dex_trace (id), trace21_start INTEGER REFERENCES dex_trace (id), diff --git a/crates/bin/pindexer/src/dex/mod.rs b/crates/bin/pindexer/src/dex/mod.rs index f084a25d08..ec668d7bb8 100644 --- a/crates/bin/pindexer/src/dex/mod.rs +++ b/crates/bin/pindexer/src/dex/mod.rs @@ -368,7 +368,7 @@ impl Event { insert_swap_execution(dbtx, execution12.as_ref()).await?; let (trace21_start, trace21_end) = insert_swap_execution(dbtx, execution21.as_ref()).await?; - sqlx::query(r#"INSERT INTO dex_batch_swap VALUES ($1, $2, $3, $4, $5, $6, $7, CAST($8 AS Amount), CAST($9 AS Amount), CAST($10 AS Amount), CAST($11 AS Amount), CAST($12 AS Amount), CAST($13 AS Amount));"#) + sqlx::query(r#"INSERT INTO dex_batch_swap VALUES (DEFAULT, $1, $2, $3, $4, $5, $6, $7, CAST($8 AS Amount), CAST($9 AS Amount), CAST($10 AS Amount), CAST($11 AS Amount), CAST($12 AS Amount), CAST($13 AS Amount));"#) .bind(i64::try_from(*height)?) .bind(trace12_start) .bind(trace12_end)