diff --git a/proto/tycho/evm/v1/common.proto b/proto/tycho/evm/v1/common.proto index 210b809..22b3cfa 100644 --- a/proto/tycho/evm/v1/common.proto +++ b/proto/tycho/evm/v1/common.proto @@ -168,7 +168,7 @@ message EntryPointParams { // The entrypoint id. string entrypoint_id = 1; // [optional] The component that uses these entrypoint parameters. Currently used for debugging purposes only. - string component_id = 2; + optional string component_id = 2; // The strategy and its corresponding data oneof trace_data { RPCTraceData rpc = 3; diff --git a/substreams/crates/tycho-substreams/buf.gen.yaml b/substreams/crates/tycho-substreams/buf.gen.yaml index b2b7535..b95694b 100644 --- a/substreams/crates/tycho-substreams/buf.gen.yaml +++ b/substreams/crates/tycho-substreams/buf.gen.yaml @@ -5,7 +5,10 @@ plugins: opt: - file_descriptor_set=false - type_attribute=.tycho.evm.v1.Transaction=#[derive(Eq\, Hash)] + - type_attribute=.tycho.evm.v1.TraceData=#[derive(Eq\, Hash)] - type_attribute=.tycho.evm.v1.EntryPoint=#[derive(Eq\, Hash)] + - type_attribute=.tycho.evm.v1.EntryPointParams=#[derive(Eq\, Hash)] + - type_attribute=.tycho.evm.v1.RPCTraceData=#[derive(Eq\, Hash)] - remote: buf.build/community/neoeinstein-prost-crate:v0.3.1 out: src/pb opt: no_features diff --git a/substreams/crates/tycho-substreams/src/entrypoint.rs b/substreams/crates/tycho-substreams/src/entrypoint.rs new file mode 100644 index 0000000..f7b89cc --- /dev/null +++ b/substreams/crates/tycho-substreams/src/entrypoint.rs @@ -0,0 +1,52 @@ +use crate::models::{entry_point_params::TraceData, EntryPoint, EntryPointParams}; + +fn get_entrypoint_id(target: &[u8], signature: &str) -> String { + let target = hex::encode(target); + format!("{target}:{signature}") +} + +/// Creates an entrypoint and its parameters. +pub fn create_entrypoint( + target: Vec, + signature: String, + component_id: String, + trace_data: TraceData, +) -> (EntryPoint, EntryPointParams) { + let entrypoint_id = get_entrypoint_id(&target, &signature); + let entrypoint = EntryPoint { + id: entrypoint_id.clone(), + target, + signature, + component_id: component_id.clone(), + }; + let entrypoint_params = EntryPointParams { + entrypoint_id, + component_id: Some(component_id), + trace_data: Some(trace_data), + }; + (entrypoint, entrypoint_params) +} + +// Adds EntryPointParams associated with an already existing Entrypoint. +pub fn add_entrypoint_params( + target: Vec, + signature: String, + trace_data: TraceData, + component_id: Option, +) -> EntryPointParams { + EntryPointParams { + entrypoint_id: get_entrypoint_id(&target, &signature), + component_id, + trace_data: Some(trace_data), + } +} + +// Adds a component to an existing Entrypoint. +pub fn add_component_to_entrypoint( + target: Vec, + signature: String, + component_id: String, +) -> EntryPoint { + let entrypoint_id = get_entrypoint_id(&target, &signature); + EntryPoint { id: entrypoint_id, target, signature, component_id } +} diff --git a/substreams/crates/tycho-substreams/src/lib.rs b/substreams/crates/tycho-substreams/src/lib.rs index ba19414..54fc71f 100644 --- a/substreams/crates/tycho-substreams/src/lib.rs +++ b/substreams/crates/tycho-substreams/src/lib.rs @@ -3,6 +3,7 @@ pub mod attributes; pub mod balances; pub mod block_storage; pub mod contract; +pub mod entrypoint; mod mock_store; pub mod models; pub mod pb; diff --git a/substreams/crates/tycho-substreams/src/models.rs b/substreams/crates/tycho-substreams/src/models.rs index 81ffaa0..96e0fc5 100644 --- a/substreams/crates/tycho-substreams/src/models.rs +++ b/substreams/crates/tycho-substreams/src/models.rs @@ -29,6 +29,7 @@ pub struct TransactionChangesBuilder { component_changes: HashMap, balance_changes: HashMap<(Vec, Vec), BalanceChange>, entrypoints: HashSet, + entrypoint_params: HashSet, } impl TransactionChangesBuilder { @@ -159,6 +160,11 @@ impl TransactionChangesBuilder { .insert(entrypoint.clone()); } + pub fn add_entrypoint_params(&mut self, entrypoint: &EntryPointParams) { + self.entrypoint_params + .insert(entrypoint.clone()); + } + pub fn build(self) -> Option { let tx_changes = TransactionChanges { tx: self.tx, @@ -184,7 +190,10 @@ impl TransactionChangesBuilder { .entrypoints .into_iter() .collect::>(), - entrypoint_params: Vec::new(), // TODO: Add entrypoint params to builder + entrypoint_params: self + .entrypoint_params + .into_iter() + .collect::>(), }; if tx_changes.is_empty() { None 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 37d8659..23f169f 100644 --- a/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs +++ b/substreams/crates/tycho-substreams/src/pb/tycho.evm.v1.rs @@ -194,6 +194,7 @@ pub struct EntryPoint { pub component_id: ::prost::alloc::string::String, } /// Parameters to trace the entrypoint +#[derive(Eq, Hash)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct EntryPointParams { @@ -201,8 +202,8 @@ pub struct EntryPointParams { #[prost(string, tag="1")] pub entrypoint_id: ::prost::alloc::string::String, /// \[optional\] The component that uses these entrypoint parameters. Currently used for debugging purposes only. - #[prost(string, tag="2")] - pub component_id: ::prost::alloc::string::String, + #[prost(string, optional, tag="2")] + pub component_id: ::core::option::Option<::prost::alloc::string::String>, /// The strategy and its corresponding data #[prost(oneof="entry_point_params::TraceData", tags="3")] pub trace_data: ::core::option::Option, @@ -210,6 +211,7 @@ pub struct EntryPointParams { /// Nested message and enum types in `EntryPointParams`. pub mod entry_point_params { /// The strategy and its corresponding data + #[derive(Eq, Hash)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Oneof)] pub enum TraceData { @@ -219,6 +221,7 @@ pub mod entry_point_params { } } /// RPC tracing strategy with its data +#[derive(Eq, Hash)] #[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, ::prost::Message)] pub struct RpcTraceData {