From 8f44f08025fe574ce80c10fea87d9ddbd909add6 Mon Sep 17 00:00:00 2001 From: Diana Carvalho Date: Mon, 10 Feb 2025 10:35:41 +0000 Subject: [PATCH] fix: Create a ProtocolComponent::new() that doesn't depend on tycho-core This way, users can create a ProtocolComponent from scratch and don't get deprecation warnings because of address --- don't change below this line --- ENG-4207 Took 10 minutes Took 9 seconds --- src/evm/decoder.rs | 10 ++++++-- src/protocol/models.rs | 52 ++++++++++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/evm/decoder.rs b/src/evm/decoder.rs index 3d7c3aaa..d2d427ad 100644 --- a/src/evm/decoder.rs +++ b/src/evm/decoder.rs @@ -215,7 +215,10 @@ impl TychoStreamDecoder { .collect::>(); if tokens.len() == comp.tokens.len() { - Some((id.clone(), ProtocolComponent::new(tokens, comp.clone()))) + Some(( + id.clone(), + ProtocolComponent::from_with_tokens(comp.clone(), tokens), + )) } else { // We may reach this point if the removed component // contained low quality tokens, in this case the component @@ -274,7 +277,10 @@ impl TychoStreamDecoder { } new_pairs.insert( id.clone(), - ProtocolComponent::new(component_tokens, snapshot.component.clone()), + ProtocolComponent::from_with_tokens( + snapshot.component.clone(), + component_tokens, + ), ); // Construct state from snapshot diff --git a/src/protocol/models.rs b/src/protocol/models.rs index d5f32c9c..cc13e1b2 100644 --- a/src/protocol/models.rs +++ b/src/protocol/models.rs @@ -57,22 +57,50 @@ pub struct ProtocolComponent { impl ProtocolComponent { #[allow(deprecated)] - pub fn new(mut tokens: Vec, core_model: tycho_core::dto::ProtocolComponent) -> Self { - tokens.sort_unstable_by_key(|t| t.address.clone()); - let id = Bytes::from(core_model.id.as_str()); + #[allow(clippy::too_many_arguments)] + pub fn new( + id: Bytes, + protocol_system: String, + protocol_type_name: String, + chain: Chain, + tokens: Vec, + contract_ids: Vec, + static_attributes: HashMap, + creation_tx: Bytes, + created_at: NaiveDateTime, + ) -> Self { ProtocolComponent { - id: id.clone(), - address: id, + address: Default::default(), + id, tokens, - protocol_system: core_model.protocol_system, - protocol_type_name: core_model.protocol_type_name, - chain: core_model.chain, - contract_ids: core_model.contract_ids, - static_attributes: core_model.static_attributes, - creation_tx: core_model.creation_tx, - created_at: core_model.created_at, + protocol_system, + protocol_type_name, + chain, + contract_ids, + static_attributes, + creation_tx, + created_at, } } + + pub fn from_with_tokens( + core_model: tycho_core::dto::ProtocolComponent, + mut tokens: Vec, + ) -> Self { + tokens.sort_unstable_by_key(|t| t.address.clone()); + let id = Bytes::from(core_model.id.as_str()); + ProtocolComponent::new( + id.clone(), + core_model.protocol_system, + core_model.protocol_type_name, + core_model.chain, + tokens, + core_model.contract_ids, + core_model.static_attributes, + core_model.creation_tx, + core_model.created_at, + ) + } } impl From for tycho_core::dto::ProtocolComponent {