Skip to content

Commit

Permalink
Merge pull request #143 from propeller-heads/dc/extend-protocol-compo…
Browse files Browse the repository at this point in the history
…nent-init
  • Loading branch information
dianacarvalho1 authored Feb 10, 2025
2 parents 9658506 + 8f44f08 commit 30cb33b
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/evm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,10 @@ impl TychoStreamDecoder {
.collect::<Vec<_>>();

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
Expand Down Expand Up @@ -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
Expand Down
52 changes: 40 additions & 12 deletions src/protocol/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,50 @@ pub struct ProtocolComponent {

impl ProtocolComponent {
#[allow(deprecated)]
pub fn new(mut tokens: Vec<Token>, 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<Token>,
contract_ids: Vec<Bytes>,
static_attributes: HashMap<String, Bytes>,
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<Token>,
) -> 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<ProtocolComponent> for tycho_core::dto::ProtocolComponent {
Expand Down

0 comments on commit 30cb33b

Please sign in to comment.