diff --git a/substreams/crates/tycho-substreams/src/models.rs b/substreams/crates/tycho-substreams/src/models.rs index 3dcee62..e41cfeb 100644 --- a/substreams/crates/tycho-substreams/src/models.rs +++ b/substreams/crates/tycho-substreams/src/models.rs @@ -515,6 +515,22 @@ impl InterimContractChange { self.code.clear(); self.code.extend_from_slice(code); } + + pub fn upsert_token_balance(&mut self, token: &[u8], balance: &[u8]) { + self.token_balances + .entry(token.to_vec()) + .and_modify(|b| { + b.clear(); + b.extend_from_slice(balance); + }) + .or_insert_with(|| balance.to_vec()); + } + + pub fn upsert_token_balances(&mut self, balances: &HashMap, Vec>) { + for (token, balance) in balances.iter() { + self.upsert_token_balance(token, balance); + } + } } impl From for Option {