From 12369c3981ddd35bb3fc02cdde166cb3efe3bdf3 Mon Sep 17 00:00:00 2001 From: Zizou <111426680+zizou0x@users.noreply.github.com> Date: Thu, 25 Sep 2025 17:41:07 +0200 Subject: [PATCH] fix: update `get_block_storage_changes` to correctly emit previous value (#280) Before this commit we were using the latest `ContractSlot` for both previous and new value. This is not correct because if the value changed twice we would have the middle value emitted as "previous". For example if a value was changed like this in a single transaction 1 -> 10 -> 2 we would have `new_value=2` and `previous_values=10` while the previous value was actually 1. Co-authored-by: zizou <111426680+flopell@users.noreply.github.com> --- substreams/Cargo.lock | 34 +++++++++---------- substreams/crates/tycho-substreams/Cargo.toml | 2 +- .../tycho-substreams/src/block_storage.rs | 14 +++++--- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/substreams/Cargo.lock b/substreams/Cargo.lock index 3552236..760d35d 100644 --- a/substreams/Cargo.lock +++ b/substreams/Cargo.lock @@ -250,7 +250,7 @@ dependencies = [ "num-bigint", "substreams", "substreams-ethereum", - "tycho-substreams 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tycho-substreams 0.5.0", ] [[package]] @@ -1758,22 +1758,6 @@ dependencies = [ "substreams-ethereum", ] -[[package]] -name = "tycho-substreams" -version = "0.5.0" -dependencies = [ - "ethabi 18.0.0", - "hex", - "itertools 0.12.1", - "num-bigint", - "prost 0.11.9", - "rstest", - "serde", - "serde_json", - "substreams", - "substreams-ethereum", -] - [[package]] name = "tycho-substreams" version = "0.5.0" @@ -1791,6 +1775,22 @@ dependencies = [ "substreams-ethereum", ] +[[package]] +name = "tycho-substreams" +version = "0.5.1" +dependencies = [ + "ethabi 18.0.0", + "hex", + "itertools 0.12.1", + "num-bigint", + "prost 0.11.9", + "rstest", + "serde", + "serde_json", + "substreams", + "substreams-ethereum", +] + [[package]] name = "typenum" version = "1.17.0" diff --git a/substreams/crates/tycho-substreams/Cargo.toml b/substreams/crates/tycho-substreams/Cargo.toml index 360180a..af5005b 100644 --- a/substreams/crates/tycho-substreams/Cargo.toml +++ b/substreams/crates/tycho-substreams/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tycho-substreams" -version = "0.5.0" +version = "0.5.1" edition = "2021" description = "Tycho substreams development kit, contains tycho-indexer block changes model and helper functions for common indexing tasks." repository = "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/crates/tycho-substreams" diff --git a/substreams/crates/tycho-substreams/src/block_storage.rs b/substreams/crates/tycho-substreams/src/block_storage.rs index bf05895..39bc7bc 100644 --- a/substreams/crates/tycho-substreams/src/block_storage.rs +++ b/substreams/crates/tycho-substreams/src/block_storage.rs @@ -54,14 +54,18 @@ pub fn get_block_storage_changes(block: ð::v2::Block) -> Vec, ContractSlot> = HashMap::new(); for change in changes { - latest_changes.insert( - change.key.clone(), - ContractSlot { + latest_changes + .entry(change.key.clone()) + .and_modify(|slot| { + // Only update the latest value, previous value stays the first seen + // one. + slot.value = change.new_value.clone(); + }) + .or_insert(ContractSlot { slot: change.key, value: change.new_value, previous_value: change.old_value, - }, - ); + }); } StorageChanges { address, slots: latest_changes.into_values().collect() }