From 648a3bf4198b59ae1f16e6cea8c9809819b67c30 Mon Sep 17 00:00:00 2001 From: Louise Poole Date: Thu, 19 Jun 2025 16:27:26 +0200 Subject: [PATCH] fix: skip processing balances of bpt tokens (#220) --- substreams/Cargo.lock | 2 +- substreams/ethereum-balancer-v2/Cargo.toml | 2 +- .../ethereum-balancer-v2/src/modules.rs | 49 +++++++++++-------- .../src/pool_factories.rs | 4 +- .../ethereum-balancer-v2/substreams.yaml | 2 +- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/substreams/Cargo.lock b/substreams/Cargo.lock index 2edd800..1e3fcce 100644 --- a/substreams/Cargo.lock +++ b/substreams/Cargo.lock @@ -240,7 +240,7 @@ dependencies = [ [[package]] name = "ethereum-balancer-v2" -version = "0.3.0" +version = "0.3.1" dependencies = [ "anyhow", "ethabi 18.0.0", diff --git a/substreams/ethereum-balancer-v2/Cargo.toml b/substreams/ethereum-balancer-v2/Cargo.toml index bf190e7..938b5df 100644 --- a/substreams/ethereum-balancer-v2/Cargo.toml +++ b/substreams/ethereum-balancer-v2/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ethereum-balancer-v2" -version = "0.3.0" +version = "0.3.1" edition = "2021" [lib] diff --git a/substreams/ethereum-balancer-v2/src/modules.rs b/substreams/ethereum-balancer-v2/src/modules.rs index c5c873c..760b4a8 100644 --- a/substreams/ethereum-balancer-v2/src/modules.rs +++ b/substreams/ethereum-balancer-v2/src/modules.rs @@ -76,65 +76,72 @@ pub fn map_relative_balances( abi::vault::events::PoolBalanceChanged::match_and_decode(vault_log.log) { let component_id = format!("0x{}", hex::encode(ev.pool_id)); + let bpt_token = hex::decode(&component_id[2..42]).unwrap(); if store .get_last(format!("pool:{}", &component_id[..42])) .is_some() { - for (token, delta) in ev - .tokens - .iter() - .zip(ev.deltas.iter()) - .filter(|(token, _)| **token != hex::decode(&component_id[2..42]).unwrap()) - { - deltas.push(BalanceDelta { - ord: vault_log.ordinal(), - tx: Some(vault_log.receipt.transaction.into()), - token: token.to_vec(), - delta: delta.to_signed_bytes_be(), - component_id: component_id.as_bytes().to_vec(), - }); + for (token, delta) in ev.tokens.iter().zip(ev.deltas.iter()) { + // BPT tokens not supported - their balance handling is currently bugged + if *token != bpt_token { + deltas.push(BalanceDelta { + ord: vault_log.ordinal(), + tx: Some(vault_log.receipt.transaction.into()), + token: token.to_vec(), + delta: delta.to_signed_bytes_be(), + 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{}", hex::encode(ev.pool_id)); + let bpt_token = hex::decode(&component_id[2..42]).unwrap(); if store .get_last(format!("pool:{}", &component_id[..42])) .is_some() { - deltas.extend_from_slice(&[ - BalanceDelta { + // BPT tokens not supported - their balance handling is currently bugged + if ev.token_in != bpt_token { + deltas.push(BalanceDelta { ord: vault_log.ordinal(), 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.as_bytes().to_vec(), - }, - BalanceDelta { + }); + } + // BPT tokens not supported - their balance handling is currently bugged + if ev.token_out != bpt_token { + deltas.push(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.as_bytes().to_vec(), - }, - ]); + }); + } } } else if let Some(ev) = abi::vault::events::PoolBalanceManaged::match_and_decode(vault_log.log) { let component_id = format!("0x{}", hex::encode(ev.pool_id)); + let bpt_token = hex::decode(&component_id[2..42]).unwrap(); if store .get_last(format!("pool:{}", &component_id[..42])) .is_some() + // BPT tokens not supported - their balance handling is currently bugged + && ev.token != bpt_token { - deltas.extend_from_slice(&[BalanceDelta { + deltas.push(BalanceDelta { ord: vault_log.ordinal(), tx: Some(vault_log.receipt.transaction.into()), token: ev.token.to_vec(), delta: ev.cash_delta.to_signed_bytes_be(), component_id: component_id.as_bytes().to_vec(), - }]); + }); } } diff --git a/substreams/ethereum-balancer-v2/src/pool_factories.rs b/substreams/ethereum-balancer-v2/src/pool_factories.rs index cba8fa3..98520da 100644 --- a/substreams/ethereum-balancer-v2/src/pool_factories.rs +++ b/substreams/ethereum-balancer-v2/src/pool_factories.rs @@ -217,8 +217,8 @@ pub fn address_map( Some( ProtocolComponent::new(&format!("0x{}", hex::encode(pool_registered.pool_id))) .with_contracts(&[pool_created.pool.clone(), VAULT_ADDRESS.to_vec()]) - // .with_tokens(&tokens_registered.tokens) //TODO: does it make sense to include - // BPT token here? + // .with_tokens(&tokens_registered.tokens) // TODO: add this back if we need to + // track BPT .with_tokens(&[ create_call.main_token.clone(), create_call.wrapped_token.clone(), diff --git a/substreams/ethereum-balancer-v2/substreams.yaml b/substreams/ethereum-balancer-v2/substreams.yaml index 24d77c6..24c3432 100644 --- a/substreams/ethereum-balancer-v2/substreams.yaml +++ b/substreams/ethereum-balancer-v2/substreams.yaml @@ -1,7 +1,7 @@ specVersion: v0.1.0 package: name: "ethereum_balancer_v2" - version: v0.3.0 + version: v0.3.1 url: "https://github.com/propeller-heads/tycho-protocol-sdk/tree/main/substreams/ethereum-balancer-v2" protobuf: