From a1864e3cd4bb09dfda2f25d4ce2887e9646e8cb5 Mon Sep 17 00:00:00 2001 From: kayibal Date: Mon, 11 Mar 2024 19:10:28 +0000 Subject: [PATCH] Don't include balancer specific pb in tycho pbs. --- .../ethereum-balancer/proto}/balancer.proto | 8 ++-- substreams/ethereum-balancer/src/modules.rs | 18 ++++---- .../ethereum-balancer/src/pb/balancer.rs | 42 +++++++++++++++++++ substreams/ethereum-balancer/src/pb/mod.rs | 5 +++ .../ethereum-balancer/src/pb/tycho.evm.v1.rs | 40 ------------------ substreams/ethereum-balancer/substreams.yaml | 3 +- 6 files changed, 62 insertions(+), 54 deletions(-) rename {proto/tycho/evm/v1 => substreams/ethereum-balancer/proto}/balancer.proto (84%) create mode 100644 substreams/ethereum-balancer/src/pb/balancer.rs diff --git a/proto/tycho/evm/v1/balancer.proto b/substreams/ethereum-balancer/proto/balancer.proto similarity index 84% rename from proto/tycho/evm/v1/balancer.proto rename to substreams/ethereum-balancer/proto/balancer.proto index f5a4c63..6efe1c9 100644 --- a/proto/tycho/evm/v1/balancer.proto +++ b/substreams/ethereum-balancer/proto/balancer.proto @@ -1,6 +1,6 @@ syntax = "proto3"; -package tycho.evm.v1; +package balancer; import "tycho/evm/v1/common.proto"; @@ -8,7 +8,7 @@ import "tycho/evm/v1/common.proto"; message BalanceDelta { uint64 ord = 1; // The tx hash of the transaction that caused the balance change. - Transaction tx = 2; + tycho.evm.v1.Transaction tx = 2; // The address of the ERC20 token whose balance changed. bytes token = 3; // The delta balance of the token. @@ -23,8 +23,8 @@ message BalanceDeltas { } message TransactionProtocolComponents { - Transaction tx = 1; - repeated ProtocolComponent components = 2; + tycho.evm.v1.Transaction tx = 1; + repeated tycho.evm.v1.ProtocolComponent components = 2; } message GroupedTransactionProtocolComponents { diff --git a/substreams/ethereum-balancer/src/modules.rs b/substreams/ethereum-balancer/src/modules.rs index 7d666cc..96554ca 100644 --- a/substreams/ethereum-balancer/src/modules.rs +++ b/substreams/ethereum-balancer/src/modules.rs @@ -17,7 +17,7 @@ use pb::tycho::evm::v1::{self as tycho}; use contract_changes::extract_contract_changes; -use crate::pb::tycho::evm::v1::{BalanceDeltas, GroupedTransactionProtocolComponents}; +use crate::pb::balancer::{BalanceDelta, BalanceDeltas, GroupedTransactionProtocolComponents, TransactionProtocolComponents}; use crate::{abi, contract_changes, pb, pool_factories}; const VAULT_ADDRESS: &[u8] = &hex!("BA12222222228d8Ba445958a75a0704d566BF2C8"); @@ -36,10 +36,10 @@ impl PartialEq for TransactionWrapper { #[substreams::handlers::map] pub fn map_pools_created( block: eth::v2::Block, -) -> Result { +) -> Result { // Gather contract changes by indexing `PoolCreated` events and analysing the `Create` call // We store these as a hashmap by tx hash since we need to agg by tx hash later - Ok(tycho::GroupedTransactionProtocolComponents { + Ok(GroupedTransactionProtocolComponents { tx_components: block .transactions() .filter_map(|tx| { @@ -62,7 +62,7 @@ pub fn map_pools_created( .collect::>(); if !components.is_empty() { - Some(tycho::TransactionProtocolComponents { + Some(TransactionProtocolComponents { tx: Some(tycho::Transaction { hash: tx.hash.clone(), from: tx.from.clone(), @@ -81,7 +81,7 @@ pub fn map_pools_created( /// Simply stores the `ProtocolComponent`s with the pool id as the key #[substreams::handlers::store] -pub fn store_pools_created(map: tycho::GroupedTransactionProtocolComponents, store: StoreAddInt64) { +pub fn store_pools_created(map: GroupedTransactionProtocolComponents, store: StoreAddInt64) { store.add_many( 0, &map.tx_components @@ -99,8 +99,8 @@ pub fn store_pools_created(map: tycho::GroupedTransactionProtocolComponents, sto pub fn map_balance_deltas( block: eth::v2::Block, store: StoreGetInt64, -) -> Result { - Ok(tycho::BalanceDeltas { +) -> Result { + Ok(BalanceDeltas { balance_deltas: block .events::(&[VAULT_ADDRESS]) .flat_map(|(event, log)| { @@ -113,7 +113,7 @@ pub fn map_balance_deltas( store.get_last(format!("pool:{0}", hex::encode(&component_id)))?; - Some(tycho::BalanceDelta { + Some(BalanceDelta { ord: log.log.ordinal, tx: Some(tycho::Transaction { hash: log.receipt.transaction.hash.clone(), @@ -135,7 +135,7 @@ pub fn map_balance_deltas( /// It's significant to include both the `pool_id` and the `token_id` for each balance delta as the /// store key to ensure that there's a unique balance being tallied for each. #[substreams::handlers::store] -pub fn store_balance_changes(deltas: tycho::BalanceDeltas, store: StoreAddBigInt) { +pub fn store_balance_changes(deltas: BalanceDeltas, store: StoreAddBigInt) { deltas.balance_deltas.iter().for_each(|delta| { store.add( delta.ord, diff --git a/substreams/ethereum-balancer/src/pb/balancer.rs b/substreams/ethereum-balancer/src/pb/balancer.rs new file mode 100644 index 0000000..b2f52d2 --- /dev/null +++ b/substreams/ethereum-balancer/src/pb/balancer.rs @@ -0,0 +1,42 @@ +// @generated +/// A struct for following the changes of Total Value Locked (TVL). +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct BalanceDelta { + #[prost(uint64, tag="1")] + pub ord: u64, + /// The tx hash of the transaction that caused the balance change. + #[prost(message, optional, tag="2")] + pub tx: ::core::option::Option, + /// The address of the ERC20 token whose balance changed. + #[prost(bytes="vec", tag="3")] + pub token: ::prost::alloc::vec::Vec, + /// The delta balance of the token. + #[prost(bytes="vec", tag="4")] + pub delta: ::prost::alloc::vec::Vec, + /// The id of the component whose TVL is tracked. + /// If the protocol component includes multiple contracts, the balance change must be aggregated to reflect how much tokens can be traded. + #[prost(bytes="vec", tag="5")] + pub component_id: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct BalanceDeltas { + #[prost(message, repeated, tag="1")] + pub balance_deltas: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct TransactionProtocolComponents { + #[prost(message, optional, tag="1")] + pub tx: ::core::option::Option, + #[prost(message, repeated, tag="2")] + pub components: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct GroupedTransactionProtocolComponents { + #[prost(message, repeated, tag="1")] + pub tx_components: ::prost::alloc::vec::Vec, +} +// @@protoc_insertion_point(module) diff --git a/substreams/ethereum-balancer/src/pb/mod.rs b/substreams/ethereum-balancer/src/pb/mod.rs index 43d8838..1d5f1e8 100644 --- a/substreams/ethereum-balancer/src/pb/mod.rs +++ b/substreams/ethereum-balancer/src/pb/mod.rs @@ -1,4 +1,9 @@ // @generated +// @@protoc_insertion_point(attribute:balancer) +pub mod balancer { + include!("balancer.rs"); + // @@protoc_insertion_point(balancer) +} pub mod tycho { pub mod evm { // @@protoc_insertion_point(attribute:tycho.evm.v1) diff --git a/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs b/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs index 21d371d..cf81ed2 100644 --- a/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs +++ b/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs @@ -267,44 +267,4 @@ pub struct BlockContractChanges { #[prost(message, repeated, tag="2")] pub changes: ::prost::alloc::vec::Vec, } -/// A struct for following the changes of Total Value Locked (TVL). -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct BalanceDelta { - #[prost(uint64, tag="1")] - pub ord: u64, - /// The tx hash of the transaction that caused the balance change. - #[prost(message, optional, tag="2")] - pub tx: ::core::option::Option, - /// The address of the ERC20 token whose balance changed. - #[prost(bytes="vec", tag="3")] - pub token: ::prost::alloc::vec::Vec, - /// The delta balance of the token. - #[prost(bytes="vec", tag="4")] - pub delta: ::prost::alloc::vec::Vec, - /// The id of the component whose TVL is tracked. - /// If the protocol component includes multiple contracts, the balance change must be aggregated to reflect how much tokens can be traded. - #[prost(bytes="vec", tag="5")] - pub component_id: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct BalanceDeltas { - #[prost(message, repeated, tag="1")] - pub balance_deltas: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TransactionProtocolComponents { - #[prost(message, optional, tag="1")] - pub tx: ::core::option::Option, - #[prost(message, repeated, tag="2")] - pub components: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct GroupedTransactionProtocolComponents { - #[prost(message, repeated, tag="1")] - pub tx_components: ::prost::alloc::vec::Vec, -} // @@protoc_insertion_point(module) diff --git a/substreams/ethereum-balancer/substreams.yaml b/substreams/ethereum-balancer/substreams.yaml index 9919f23..c5b56d0 100644 --- a/substreams/ethereum-balancer/substreams.yaml +++ b/substreams/ethereum-balancer/substreams.yaml @@ -7,9 +7,10 @@ protobuf: files: - tycho/evm/v1/vm.proto - tycho/evm/v1/common.proto - - tycho/evm/v1/balancer.proto + - balancer.proto importPaths: - ../../proto + - ./proto binaries: default: