From 3895a3332cd55ee6c7a5c9373343ff1b6dff8f58 Mon Sep 17 00:00:00 2001 From: Florian Pellissier <111426680+flopell@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:38:36 +0100 Subject: [PATCH] Fix bugs in balance substreams --- substreams/ethereum-balancer/src/modules.rs | 22 +++++++------------- substreams/ethereum-balancer/substreams.yaml | 10 ++++++++- substreams/ethereum-template/substreams.yaml | 8 +++++++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/substreams/ethereum-balancer/src/modules.rs b/substreams/ethereum-balancer/src/modules.rs index af6db11..565c672 100644 --- a/substreams/ethereum-balancer/src/modules.rs +++ b/substreams/ethereum-balancer/src/modules.rs @@ -75,13 +75,10 @@ pub fn map_relative_balances( if let Some(ev) = abi::vault::events::PoolBalanceChanged::match_and_decode(vault_log.log) { - let component_id = - format!("0x{}", String::from_utf8(ev.pool_id[..20].to_vec()).unwrap()) - .as_bytes() - .to_vec(); + let component_id = format!("0x{}", hex::encode(&ev.pool_id[..20])); if store - .get_last(format!("pool:{}", hex::encode(&component_id))) + .get_last(format!("pool:{}", component_id)) .is_some() { for (token, delta) in ev.tokens.iter().zip(ev.deltas.iter()) { @@ -90,18 +87,15 @@ pub fn map_relative_balances( tx: Some(vault_log.receipt.transaction.into()), token: token.to_vec(), delta: delta.to_signed_bytes_be(), - component_id: component_id.clone(), + component_id: component_id.as_bytes().to_vec(), }); } } } else if let Some(ev) = abi::vault::events::Swap::match_and_decode(vault_log.log) { - let component_id = - format!("0x{}", String::from_utf8(ev.pool_id[..20].to_vec()).unwrap()) - .as_bytes() - .to_vec(); + let component_id = format!("0x{}", hex::encode(&ev.pool_id[..20])); if store - .get_last(format!("pool:{}", hex::encode(&component_id))) + .get_last(format!("pool:{}", component_id)) .is_some() { deltas.extend_from_slice(&[ @@ -110,14 +104,14 @@ pub fn map_relative_balances( tx: Some(vault_log.receipt.transaction.into()), token: ev.token_in.to_vec(), delta: ev.amount_in.to_signed_bytes_be(), - component_id: component_id.clone(), + component_id: component_id.as_bytes().to_vec(), }, BalanceDelta { ord: vault_log.ordinal(), tx: Some(vault_log.receipt.transaction.into()), token: ev.token_out.to_vec(), delta: ev.amount_out.neg().to_signed_bytes_be(), - component_id, + component_id: component_id.as_bytes().to_vec(), }, ]); } @@ -188,7 +182,7 @@ pub fn map_protocol_changes( &block, |addr| { components_store - .get_last(format!("pool:{0}", hex::encode(addr))) + .get_last(format!("pool:0x{0}", hex::encode(addr))) .is_some() }, &mut transaction_contract_changes, diff --git a/substreams/ethereum-balancer/substreams.yaml b/substreams/ethereum-balancer/substreams.yaml index 9597334..99810e2 100644 --- a/substreams/ethereum-balancer/substreams.yaml +++ b/substreams/ethereum-balancer/substreams.yaml @@ -3,6 +3,14 @@ package: name: "ethereum_balancer" version: v0.1.0 +protobuf: + files: + - tycho/evm/v1/vm.proto + - tycho/evm/v1/common.proto + - tycho/evm/v1/utils.proto + importPaths: + - ../../proto + binaries: default: type: wasm/rust-v1 @@ -42,7 +50,7 @@ modules: inputs: - map: map_relative_balances - - name: map_changes + - name: map_protocol_changes kind: map initialBlock: 12369300 inputs: diff --git a/substreams/ethereum-template/substreams.yaml b/substreams/ethereum-template/substreams.yaml index de5dcbf..903f44a 100644 --- a/substreams/ethereum-template/substreams.yaml +++ b/substreams/ethereum-template/substreams.yaml @@ -3,6 +3,14 @@ package: name: "ethereum_template" version: v0.1.0 +protobuf: + files: + - tycho/evm/v1/vm.proto + - tycho/evm/v1/common.proto + - tycho/evm/v1/utils.proto + importPaths: + - ../../proto + binaries: default: type: wasm/rust-v1