Skip to content

Commit

Permalink
Merge pull request #163 from propeller-heads/zz/example-and-decoder-f…
Browse files Browse the repository at this point in the history
…ixes

fix: miscellaneous fixes in the price printer example and evm Tycho decoder
  • Loading branch information
zizou0x authored Mar 6, 2025
2 parents a606597 + b8b9a61 commit 9049d5a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
5 changes: 4 additions & 1 deletion examples/price_printer/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,10 @@ impl App {
if decimals >= prev_decimals {
self.quote_amount *= BigUint::from(10u64).pow((decimals - prev_decimals) as u32);
} else {
self.quote_amount /= BigUint::from(10u64).pow((prev_decimals - decimals) as u32);
let new_amount = self.quote_amount.clone() /
BigUint::from(10u64).pow((prev_decimals - decimals) as u32);
self.quote_amount =
if new_amount > BigUint::ZERO { new_amount } else { BigUint::one() };
}
}
}
Expand Down
39 changes: 19 additions & 20 deletions src/evm/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ struct DecoderState {
tokens: HashMap<Bytes, Token>,
states: HashMap<String, Box<dyn ProtocolSim>>,
// maps contract address to the pools they affect
contracts_map: HashMap<Bytes, Vec<String>>,
contracts_map: HashMap<Bytes, HashSet<String>>,
}

type DecodeFut =
Expand Down Expand Up @@ -279,28 +279,27 @@ impl TychoStreamDecoder {
}
}
}
new_pairs.insert(
id.clone(),
ProtocolComponent::from_with_tokens(
snapshot.component.clone(),
component_tokens,
),
let component = ProtocolComponent::from_with_tokens(
snapshot.component.clone(),
component_tokens,
);

// collect contracts:ids mapping for states that should update on contract changes
for component in new_pairs.values() {
if component
.static_attributes
.contains_key("manual_updates")
{
for contract in &component.contract_ids {
contracts_map
.entry(contract.clone())
.or_insert_with(Vec::new)
.push(id.clone());
}

if component
.static_attributes
.contains_key("manual_updates")
{
for contract in &component.contract_ids {
contracts_map
.entry(contract.clone())
.or_insert_with(HashSet::new)
.insert(id.clone());
}
}

new_pairs.insert(id.clone(), component);

// Construct state from snapshot
if let Some(state_decode_f) = self.registry.get(protocol.as_str()) {
match state_decode_f(snapshot, block.clone(), self.state.clone()).await {
Expand Down Expand Up @@ -465,7 +464,7 @@ impl TychoStreamDecoder {
state_guard
.contracts_map
.entry(key)
.or_insert_with(Vec::new)
.or_insert_with(HashSet::new)
.extend(values);
}

Expand Down Expand Up @@ -653,7 +652,7 @@ mod tests {
.contracts_map
.insert(
Bytes::from("0xba12222222228d8ba445958a75a0704d566bf2c8").lpad(20, 0),
vec![pool_id.clone()],
HashSet::from([pool_id.clone()]),
);

// Load a test message containing a contract update
Expand Down

0 comments on commit 9049d5a

Please sign in to comment.