From 8b4611f9bb75041efdd4facb9c7aca44ca6b8e02 Mon Sep 17 00:00:00 2001 From: kayibal Date: Wed, 3 Sep 2025 12:21:10 +0100 Subject: [PATCH] feat: Add previous_value field to ContractSlot This change is required by the DCI to properly detect potential address changes (retriggers) on packed storage slots. --- proto/tycho/evm/v1/common.proto | 2 ++ .../crates/tycho-substreams/src/block_storage.rs | 6 +++++- substreams/crates/tycho-substreams/src/models.rs | 10 +++++++--- .../crates/tycho-substreams/src/pb/tycho.evm.v1.rs | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/proto/tycho/evm/v1/common.proto b/proto/tycho/evm/v1/common.proto index 5c498b3..455e61c 100644 --- a/proto/tycho/evm/v1/common.proto +++ b/proto/tycho/evm/v1/common.proto @@ -123,6 +123,8 @@ message ContractSlot { bytes slot = 2; // The new value for this storage slot. bytes value = 3; + // The old value of this storage slot + bytes previous_value = 4; } // A struct for following the token balance changes for a contract. diff --git a/substreams/crates/tycho-substreams/src/block_storage.rs b/substreams/crates/tycho-substreams/src/block_storage.rs index 7024168..bf05895 100644 --- a/substreams/crates/tycho-substreams/src/block_storage.rs +++ b/substreams/crates/tycho-substreams/src/block_storage.rs @@ -56,7 +56,11 @@ pub fn get_block_storage_changes(block: ð::v2::Block) -> Vec impl Iterator { + pub fn changed_contracts(&self) -> impl Iterator { self.contract_changes .keys() .map(|k| k.as_slice()) @@ -124,7 +124,7 @@ impl TransactionChangesBuilder { .attributes .clone() .iter() - .filter(|&attr| (attr.change == i32::from(ChangeType::Creation))) + .filter(|&attr| attr.change == i32::from(ChangeType::Creation)) .map(|attr| attr.name.clone()) .collect(), }); @@ -578,7 +578,11 @@ impl From for Option { .slots .into_iter() .filter(|(_, value)| value.has_changed()) - .map(|(slot, value)| ContractSlot { slot, value: value.new_value }) + .map(|(slot, value)| ContractSlot { + slot, + value: value.new_value, + previous_value: value.start_value, + }) .collect(), change: value.change.into(), token_balances: value diff --git a/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs b/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs index 34a7208..355eec1 100644 --- a/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs +++ b/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs @@ -138,6 +138,9 @@ pub struct ContractSlot { /// The new value for this storage slot. #[prost(bytes="vec", tag="3")] pub value: ::prost::alloc::vec::Vec, + /// The old value of this storage slot + #[prost(bytes="vec", tag="4")] + pub previous_value: ::prost::alloc::vec::Vec, } /// A struct for following the token balance changes for a contract. #[allow(clippy::derive_partial_eq_without_eq)]