Skip to content

Commit 2a77cf9

Browse files
feat: Add entrypoint (#202)
* feat: add DCI message definitions #time 4m #time 0m * feat: Add add_entrypoint to TransactionChangesBuilder #time 15m #time 0m * fix: Make entrypoints into a HashSet instead of Vec #time 0m * fix: Rollback on message index change in ContractSlot #time 5m * fix: Ignore examples in docstrings when running cargo test --------- Co-authored-by: Louise Poole <louise@datarevenue.com>
1 parent b13b2b3 commit 2a77cf9

File tree

5 files changed

+95
-3
lines changed

5 files changed

+95
-3
lines changed

proto/tycho/evm/v1/common.proto

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,26 @@ message ContractChange {
149149
repeated AccountBalanceChange token_balances = 6;
150150
}
151151

152+
// DCI entities
153+
154+
// An entrypoint to be used for DCI analysis
155+
message EntryPoint {
156+
// The entrypoint id. Recommended to use 'target:signature'.
157+
string id = 1;
158+
// The target contract to analyse this entrypoint on.
159+
bytes target = 2;
160+
// The signature of the function to analyse.
161+
bytes signature = 3;
162+
}
163+
164+
// A contract and associated storage changes
165+
message StorageChanges {
166+
// The contract's address
167+
bytes address = 1;
168+
// The contract's storage changes
169+
repeated ContractSlot slots = 2;
170+
}
171+
152172
// Aggregate entities
153173

154174
// A set of changes aggregated by transaction.
@@ -165,6 +185,16 @@ message TransactionChanges {
165185
repeated ProtocolComponent component_changes = 4;
166186
// An array of balance changes to components.
167187
repeated BalanceChange balance_changes = 5;
188+
// An array of newly added entrypoints. Used for DCI enabled protocols.
189+
repeated EntryPoint entrypoints = 6;
190+
}
191+
192+
// A set of storage changes aggregated by transaction.
193+
message TransactionStorageChanges {
194+
// The transaction instance that results in the changes.
195+
Transaction tx = 1;
196+
// Contains the storage changes induced by the above transaction.
197+
repeated StorageChanges storage_changes = 2;
168198
}
169199

170200
// A set of transaction changes within a single block.
@@ -174,4 +204,7 @@ message BlockChanges {
174204
Block block = 1;
175205
// The set of transaction changes observed in the specified block.
176206
repeated TransactionChanges changes = 2;
207+
// The set of all storage changes from the specified block. Intended as input for the Dynamic Contract Indexer.
208+
// Should be left empty for protocols that do not use the DCI.
209+
repeated TransactionStorageChanges storage_changes = 3;
177210
}

substreams/crates/tycho-substreams/buf.gen.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins:
55
opt:
66
- file_descriptor_set=false
77
- type_attribute=.tycho.evm.v1.Transaction=#[derive(Eq\, Hash)]
8+
- type_attribute=.tycho.evm.v1.EntryPoint=#[derive(Eq\, Hash)]
89
- remote: buf.build/community/neoeinstein-prost-crate:v0.3.1
910
out: src/pb
1011
opt: no_features

substreams/crates/tycho-substreams/src/balances.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn aggregate_balances_changes(
192192
///
193193
/// # Example
194194
///
195-
/// ```
195+
/// ```ignore
196196
/// let predicate = |log_address: &[u8], transfer_address: &[u8]| -> bool {
197197
/// // Your predicate logic here, e.g., checking if the address matches a specific pattern.
198198
/// true

substreams/crates/tycho-substreams/src/models.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub struct TransactionChangesBuilder {
2828
entity_changes: HashMap<String, InterimEntityChanges>,
2929
component_changes: HashMap<String, ProtocolComponent>,
3030
balance_changes: HashMap<(Vec<u8>, Vec<u8>), BalanceChange>,
31+
entrypoints: HashSet<EntryPoint>,
3132
}
3233

3334
impl TransactionChangesBuilder {
@@ -151,6 +152,13 @@ impl TransactionChangesBuilder {
151152
.insert((change.component_id.clone(), change.token.clone()), change.clone());
152153
}
153154

155+
/// Adds a new entrypoint to the transaction. It adds to the set of already existing
156+
/// entrypoints.
157+
pub fn add_entrypoint(&mut self, entrypoint: &EntryPoint) {
158+
self.entrypoints
159+
.insert(entrypoint.clone());
160+
}
161+
154162
pub fn build(self) -> Option<TransactionChanges> {
155163
let tx_changes = TransactionChanges {
156164
tx: self.tx,
@@ -172,6 +180,10 @@ impl TransactionChangesBuilder {
172180
.balance_changes
173181
.into_values()
174182
.collect::<Vec<_>>(),
183+
entrypoints: self
184+
.entrypoints
185+
.into_iter()
186+
.collect::<Vec<_>>(),
175187
};
176188
if tx_changes.is_empty() {
177189
None
@@ -325,7 +337,7 @@ impl ProtocolComponent {
325337
///
326338
/// # Example
327339
///
328-
/// ```
340+
/// ```ignore
329341
/// let attributes_to_check = vec![
330342
/// ("attribute1".to_string(), vec![1, 2, 3]),
331343
/// ("attribute2".to_string(), vec![4, 5, 6]),
@@ -367,7 +379,7 @@ impl ProtocolComponent {
367379
///
368380
/// # Example
369381
///
370-
/// ```
382+
/// ```ignore
371383
/// let attribute_name = "attribute1";
372384
/// if let Some(value) = instance.get_attribute_value(attribute_name) {
373385
/// // Use the attribute value

substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,34 @@ pub struct ContractChange {
173173
#[prost(message, repeated, tag="6")]
174174
pub token_balances: ::prost::alloc::vec::Vec<AccountBalanceChange>,
175175
}
176+
// DCI entities
177+
178+
/// An entrypoint to be used for DCI analysis
179+
#[derive(Eq, Hash)]
180+
#[allow(clippy::derive_partial_eq_without_eq)]
181+
#[derive(Clone, PartialEq, ::prost::Message)]
182+
pub struct EntryPoint {
183+
/// The entrypoint id. Recommended to use 'target:signature'.
184+
#[prost(string, tag="1")]
185+
pub id: ::prost::alloc::string::String,
186+
/// The target contract to analyse this entrypoint on.
187+
#[prost(bytes="vec", tag="2")]
188+
pub target: ::prost::alloc::vec::Vec<u8>,
189+
/// The signature of the function to analyse.
190+
#[prost(bytes="vec", tag="3")]
191+
pub signature: ::prost::alloc::vec::Vec<u8>,
192+
}
193+
/// A contract and associated storage changes
194+
#[allow(clippy::derive_partial_eq_without_eq)]
195+
#[derive(Clone, PartialEq, ::prost::Message)]
196+
pub struct StorageChanges {
197+
/// The contract's address
198+
#[prost(bytes="vec", tag="1")]
199+
pub address: ::prost::alloc::vec::Vec<u8>,
200+
/// The contract's storage changes
201+
#[prost(message, repeated, tag="2")]
202+
pub slots: ::prost::alloc::vec::Vec<ContractSlot>,
203+
}
176204
// Aggregate entities
177205

178206
/// A set of changes aggregated by transaction.
@@ -196,6 +224,20 @@ pub struct TransactionChanges {
196224
/// An array of balance changes to components.
197225
#[prost(message, repeated, tag="5")]
198226
pub balance_changes: ::prost::alloc::vec::Vec<BalanceChange>,
227+
/// An array of newly added entrypoints. Used for DCI enabled protocols.
228+
#[prost(message, repeated, tag="6")]
229+
pub entrypoints: ::prost::alloc::vec::Vec<EntryPoint>,
230+
}
231+
/// A set of storage changes aggregated by transaction.
232+
#[allow(clippy::derive_partial_eq_without_eq)]
233+
#[derive(Clone, PartialEq, ::prost::Message)]
234+
pub struct TransactionStorageChanges {
235+
/// The transaction instance that results in the changes.
236+
#[prost(message, optional, tag="1")]
237+
pub tx: ::core::option::Option<Transaction>,
238+
/// Contains the storage changes induced by the above transaction.
239+
#[prost(message, repeated, tag="2")]
240+
pub storage_changes: ::prost::alloc::vec::Vec<StorageChanges>,
199241
}
200242
/// A set of transaction changes within a single block.
201243
/// This message must be the output of your substreams module.
@@ -208,6 +250,10 @@ pub struct BlockChanges {
208250
/// The set of transaction changes observed in the specified block.
209251
#[prost(message, repeated, tag="2")]
210252
pub changes: ::prost::alloc::vec::Vec<TransactionChanges>,
253+
/// The set of all storage changes from the specified block. Intended as input for the Dynamic Contract Indexer.
254+
/// Should be left empty for protocols that do not use the DCI.
255+
#[prost(message, repeated, tag="3")]
256+
pub storage_changes: ::prost::alloc::vec::Vec<TransactionStorageChanges>,
211257
}
212258
/// Enum to specify the type of a change.
213259
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]

0 commit comments

Comments
 (0)