From 66a048fbe2333c3cdcf17ae4c07914bc565fa07b Mon Sep 17 00:00:00 2001 From: Florian Pellissier <111426680+flopell@users.noreply.github.com> Date: Mon, 11 Mar 2024 17:45:58 +0100 Subject: [PATCH] refactor: update protobuf messages --- proto/tycho/evm/v1/balancer.proto | 32 ++++ proto/tycho/evm/v1/common.proto | 27 ++- substreams/ethereum-balancer/Cargo.lock | 36 ++-- .../ethereum-balancer/proto/factory.proto | 19 --- substreams/ethereum-balancer/proto/pool.proto | 15 -- .../proto/tycho/evm/v1/common.proto | 113 ------------- .../proto/tycho/evm/v1/entity.proto | 32 ---- .../proto/tycho/evm/v1/vm.proto | 50 ------ substreams/ethereum-balancer/src/modules.rs | 11 +- .../src/pb/eth.balancer.v1.rs | 28 ---- .../src/pb/eth.factory.v1.rs | 28 ---- .../ethereum-balancer/src/pb/eth.pool.v1.rs | 22 --- .../ethereum-balancer/src/pb/tycho.evm.v1.rs | 158 +++++++++++++----- .../ethereum-balancer/src/pool_factories.rs | 66 +++++++- substreams/ethereum-balancer/substreams.yaml | 4 +- 15 files changed, 261 insertions(+), 380 deletions(-) create mode 100644 proto/tycho/evm/v1/balancer.proto delete mode 100644 substreams/ethereum-balancer/proto/factory.proto delete mode 100644 substreams/ethereum-balancer/proto/pool.proto delete mode 100644 substreams/ethereum-balancer/proto/tycho/evm/v1/common.proto delete mode 100644 substreams/ethereum-balancer/proto/tycho/evm/v1/entity.proto delete mode 100644 substreams/ethereum-balancer/proto/tycho/evm/v1/vm.proto delete mode 100644 substreams/ethereum-balancer/src/pb/eth.balancer.v1.rs delete mode 100644 substreams/ethereum-balancer/src/pb/eth.factory.v1.rs delete mode 100644 substreams/ethereum-balancer/src/pb/eth.pool.v1.rs diff --git a/proto/tycho/evm/v1/balancer.proto b/proto/tycho/evm/v1/balancer.proto new file mode 100644 index 0000000..f5a4c63 --- /dev/null +++ b/proto/tycho/evm/v1/balancer.proto @@ -0,0 +1,32 @@ +syntax = "proto3"; + +package tycho.evm.v1; + +import "tycho/evm/v1/common.proto"; + +// A struct for following the changes of Total Value Locked (TVL). +message BalanceDelta { + uint64 ord = 1; + // The tx hash of the transaction that caused the balance change. + Transaction tx = 2; + // The address of the ERC20 token whose balance changed. + bytes token = 3; + // The delta balance of the token. + bytes delta = 4; + // 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. + bytes component_id = 5; +} + +message BalanceDeltas { + repeated BalanceDelta balance_deltas = 1; +} + +message TransactionProtocolComponents { + Transaction tx = 1; + repeated ProtocolComponent components = 2; +} + +message GroupedTransactionProtocolComponents { + repeated TransactionProtocolComponents tx_components = 1; +} \ No newline at end of file diff --git a/proto/tycho/evm/v1/common.proto b/proto/tycho/evm/v1/common.proto index d52dbed..545cad0 100644 --- a/proto/tycho/evm/v1/common.proto +++ b/proto/tycho/evm/v1/common.proto @@ -25,6 +25,7 @@ message Transaction { // The receiver of the transaction. bytes to = 3; // The transactions index within the block. + // TODO: should this be uint32? to match the type from the native substream type? uint64 index = 4; } @@ -47,6 +48,26 @@ message Attribute { ChangeType change = 3; } +enum FinancialType{ + SWAP = 0; + LEND = 1; + LEVERAGE = 2; + PSM = 3; +} + + +enum ImplementationType { + VM = 0; + CUSTOM = 1; +} + +message ProtocolType{ + string name = 1; + FinancialType financial_type = 2; + repeated Attribute attribute_schema = 3; + ImplementationType implementation_type = 4; +} + // A struct describing a part of the protocol. // Note: For example this can be a UniswapV2 pair, that tracks the two ERC20 tokens used by the pair, // the component would represent a single contract. In case of VM integration, such component would @@ -67,6 +88,10 @@ message ProtocolComponent { repeated Attribute static_att = 4; // Type of change the component underwent. ChangeType change = 5; + /// Represents the functionality of the component. + ProtocolType protocol_type = 6; + // Transaction where this component was created + Transaction tx = 7; } // A struct for following the changes of Total Value Locked (TVL) of a protocol component. @@ -77,7 +102,7 @@ message BalanceChange { bytes token = 1; // The new balance of the token. bytes balance = 2; - // The id of the component whose TVL is tracked. + // The id of the component whose TVL is tracked. Note: This MUST be utf8 encoded. // If the protocol component includes multiple contracts, the balance change must be aggregated to reflect how much tokens can be traded. bytes component_id = 3; } diff --git a/substreams/ethereum-balancer/Cargo.lock b/substreams/ethereum-balancer/Cargo.lock index c96455e..b05dce5 100644 --- a/substreams/ethereum-balancer/Cargo.lock +++ b/substreams/ethereum-balancer/Cargo.lock @@ -884,24 +884,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "substreams-balancer" -version = "0.1.0" -dependencies = [ - "anyhow", - "bytes", - "ethabi 18.0.0", - "getrandom", - "hex", - "hex-literal 0.4.1", - "itertools 0.12.0", - "num-bigint", - "prost 0.11.9", - "prost-types 0.12.3", - "substreams", - "substreams-ethereum", -] - [[package]] name = "substreams-ethereum" version = "0.9.9" @@ -933,6 +915,24 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "substreams-ethereum-balancer" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytes", + "ethabi 18.0.0", + "getrandom", + "hex", + "hex-literal 0.4.1", + "itertools 0.12.0", + "num-bigint", + "prost 0.11.9", + "prost-types 0.12.3", + "substreams", + "substreams-ethereum", +] + [[package]] name = "substreams-ethereum-core" version = "0.9.9" diff --git a/substreams/ethereum-balancer/proto/factory.proto b/substreams/ethereum-balancer/proto/factory.proto deleted file mode 100644 index f191ea8..0000000 --- a/substreams/ethereum-balancer/proto/factory.proto +++ /dev/null @@ -1,19 +0,0 @@ -syntax = "proto3"; - -package eth.factory.v1; - -message Pools { - repeated Pool pools = 1; -} - -message Pool { - bytes pool_id = 1; - fixed64 log_ordinal = 2; -} - -message Transfer { - bytes from = 1; - bytes to = 2; - string token = 3; - string amount = 4; -} diff --git a/substreams/ethereum-balancer/proto/pool.proto b/substreams/ethereum-balancer/proto/pool.proto deleted file mode 100644 index c4dd94c..0000000 --- a/substreams/ethereum-balancer/proto/pool.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -package eth.pool.v1; - -message Transfers { - repeated Transfer transfers = 1; -} - -message Transfer { - string from = 1; - string to = 2; - uint64 token_id = 3; - string trx_hash = 4; - uint64 ordinal = 5; -} diff --git a/substreams/ethereum-balancer/proto/tycho/evm/v1/common.proto b/substreams/ethereum-balancer/proto/tycho/evm/v1/common.proto deleted file mode 100644 index 1a5caf4..0000000 --- a/substreams/ethereum-balancer/proto/tycho/evm/v1/common.proto +++ /dev/null @@ -1,113 +0,0 @@ -syntax = "proto3"; - -package tycho.evm.v1; - -// This file contains the proto definitions for Substreams common to all integrations. - -// A struct describing a block. -message Block { - // The blocks hash. - bytes hash = 1; - // The parent blocks hash. - bytes parent_hash = 2; - // The block number. - uint64 number = 3; - // The block timestamp. - uint64 ts = 4; -} - -// A struct describing a transaction. -message Transaction { - // The transaction hash. - bytes hash = 1; - // The sender of the transaction. - bytes from = 2; - // The receiver of the transaction. - bytes to = 3; - // The transactions index within the block. - // TODO: should this be uint32? to match the type from the native substream type? - uint64 index = 4; -} - -// Enum to specify the type of a change. -enum ChangeType { - CHANGE_TYPE_UNSPECIFIED = 0; - CHANGE_TYPE_UPDATE = 1; - CHANGE_TYPE_CREATION = 2; - CHANGE_TYPE_DELETION = 3; -} - -// A custom struct representing an arbitrary attribute of a protocol component. -// This is mainly used by the native integration to track the necessary information about the protocol. -message Attribute { - // The name of the attribute. - string name = 1; - // The value of the attribute. - bytes value = 2; - // The type of change the attribute underwent. - ChangeType change = 3; -} - -// A struct describing a part of the protocol. -// Note: For example this can be a UniswapV2 pair, that tracks the two ERC20 tokens used by the pair, -// the component would represent a single contract. In case of VM integration, such component would -// not need any attributes, because all the relevant info would be tracked via storage slots and balance changes. -// It can also be a wrapping contract, like WETH, that has a constant price, but it allows swapping tokens. -// This is why the name ProtocolComponent is used instead of "Pool" or "Pair". -message ProtocolComponent { - // A unique identifier for the component within the protocol. - // Can be e.g. a stringified address or a string describing the trading pair. - string id = 1; - // Addresses of the ERC20 tokens used by the component. - repeated bytes tokens = 2; - // Addresses of the contracts used by the component. - // Usually it is a single contract, but some protocols use multiple contracts. - repeated bytes contracts = 3; - // Attributes of the component. Used mainly be the native integration. - // The inner ChangeType of the attribute has to match the ChangeType of the ProtocolComponent. - repeated Attribute static_att = 4; - // Type of change the component underwent. - ChangeType change = 5; -} - -message TransactionProtocolComponents { - Transaction tx = 1; - repeated ProtocolComponent components = 2; -} - -message GroupedTransactionProtocolComponents { - repeated TransactionProtocolComponents tx_components = 1; -} - -// A struct for following the changes of Total Value Locked (TVL) of a protocol component. -// Note that if a ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole. -// E.g. for UniswapV2 pair WETH/USDC, this tracks the USDC and WETH balance of the pair contract. -message BalanceChange { - // The address of the ERC20 token whose balance changed. - bytes token = 1; - // The new balance of the token. - bytes balance = 2; - // 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. - bytes component_id = 3; -} - -// A struct for following the changes of Total Value Locked (TVL) of a protocol component. -// Note that if a ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole. -// E.g. for UniswapV2 pair WETH/USDC, this tracks the USDC and WETH balance of the pair contract. -message BalanceDelta { - uint64 ord = 1; - // The tx hash of the transaction that caused the balance change. - Transaction tx = 2; - // The address of the ERC20 token whose balance changed. - bytes token = 3; - // The delta balance of the token. - bytes delta = 4; - // 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. - bytes component_id = 5; -} - -message BalanceDeltas { - repeated BalanceDelta balance_deltas = 1; -} diff --git a/substreams/ethereum-balancer/proto/tycho/evm/v1/entity.proto b/substreams/ethereum-balancer/proto/tycho/evm/v1/entity.proto deleted file mode 100644 index 14539e4..0000000 --- a/substreams/ethereum-balancer/proto/tycho/evm/v1/entity.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -package tycho.evm.v1; - -import "tycho/evm/v1/common.proto"; - -// This file contains the definition for the native integration of Substreams. - -// A component is a set of attributes that are associated with a custom entity. -message EntityChanges { - // A unique identifier of the entity within the protocol. - string component_id = 1; - // The set of attributes that are associated with the entity. - repeated Attribute attributes = 2; -} - -message TransactionEntityChanges { - Transaction tx = 1; - repeated EntityChanges entity_changes = 2; - // An array of newly added components. - repeated ProtocolComponent component_changes = 3; - // An array of balance changes to components. - repeated BalanceChange balance_changes = 4; -} - -// A set of transaction changes within a single block. -message BlockEntityChanges { - // The block for which these changes are collectively computed. - Block block = 1; - // The set of transaction changes observed in the specified block. - repeated TransactionEntityChanges changes = 2; -} diff --git a/substreams/ethereum-balancer/proto/tycho/evm/v1/vm.proto b/substreams/ethereum-balancer/proto/tycho/evm/v1/vm.proto deleted file mode 100644 index a49dcf0..0000000 --- a/substreams/ethereum-balancer/proto/tycho/evm/v1/vm.proto +++ /dev/null @@ -1,50 +0,0 @@ -syntax = "proto3"; - -package tycho.evm.v1; - -import "tycho/evm/v1/common.proto"; - -// This file contains proto definitions specific to the VM integration. - -// A key value entry into contract storage. -message ContractSlot { - // A contract's storage slot. - bytes slot = 2; - // The new value for this storage slot. - bytes value = 3; -} - -// Changes made to a single contract's state. -message ContractChange { - // The contract's address - bytes address = 1; - // The new native balance of the contract, empty bytes indicates no change. - bytes balance = 2; - // The new code of the contract, empty bytes indicates no change. - bytes code = 3; - // The changes to this contract's slots, empty sequence indicates no change. - repeated ContractSlot slots = 4; - // Whether this is an update, a creation or a deletion. - ChangeType change = 5; -} - -// A set of changes aggregated by transaction. -message TransactionContractChanges { - // The transaction instance that results in the changes. - Transaction tx = 1; - // Contains the changes induced by the above transaction, aggregated on a per-contract basis. - // Must include changes to every contract that is tracked by all ProtocolComponents. - repeated ContractChange contract_changes = 2; - // An array of any component changes. - repeated ProtocolComponent component_changes = 3; - // An array of balance changes to components. - repeated BalanceChange balance_changes = 4; -} - -// A set of transaction changes within a single block. -message BlockContractChanges { - // The block for which these changes are collectively computed. - Block block = 1; - // The set of transaction changes observed in the specified block. - repeated TransactionContractChanges changes = 2; -} diff --git a/substreams/ethereum-balancer/src/modules.rs b/substreams/ethereum-balancer/src/modules.rs index 2ac0f0e..d121c2d 100644 --- a/substreams/ethereum-balancer/src/modules.rs +++ b/substreams/ethereum-balancer/src/modules.rs @@ -17,6 +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::{abi, contract_changes, pb, pool_factories}; const VAULT_ADDRESS: &[u8] = &hex!("BA12222222228d8Ba445958a75a0704d566BF2C8"); @@ -50,6 +51,12 @@ pub fn map_pools_created( call.call.address.as_slice(), log, call.call, + &tycho::Transaction { + hash: tx.hash.clone(), + from: tx.from.clone(), + to: tx.to.clone(), + index: tx.index.into(), + }, )?) }) .collect::>(); @@ -156,8 +163,8 @@ pub fn store_balance_changes(deltas: tycho::BalanceDeltas, store: StoreAddBigInt #[substreams::handlers::map] pub fn map_changes( block: eth::v2::Block, - grouped_components: tycho::GroupedTransactionProtocolComponents, - deltas: tycho::BalanceDeltas, + grouped_components: GroupedTransactionProtocolComponents, + deltas: BalanceDeltas, components_store: StoreGetInt64, balance_store: StoreDeltas, // Note, this map module is using the `deltas` mode for the store. ) -> Result { diff --git a/substreams/ethereum-balancer/src/pb/eth.balancer.v1.rs b/substreams/ethereum-balancer/src/pb/eth.balancer.v1.rs deleted file mode 100644 index 47065d4..0000000 --- a/substreams/ethereum-balancer/src/pb/eth.balancer.v1.rs +++ /dev/null @@ -1,28 +0,0 @@ -// @generated -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Pools { - #[prost(message, repeated, tag="1")] - pub pools: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Pool { - #[prost(bytes="vec", tag="1")] - pub pool_id: ::prost::alloc::vec::Vec, - #[prost(fixed64, tag="2")] - pub log_ordinal: u64, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfer { - #[prost(bytes="vec", tag="1")] - pub from: ::prost::alloc::vec::Vec, - #[prost(bytes="vec", tag="2")] - pub to: ::prost::alloc::vec::Vec, - #[prost(string, tag="3")] - pub token: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub amount: ::prost::alloc::string::String, -} -// @@protoc_insertion_point(module) diff --git a/substreams/ethereum-balancer/src/pb/eth.factory.v1.rs b/substreams/ethereum-balancer/src/pb/eth.factory.v1.rs deleted file mode 100644 index 47065d4..0000000 --- a/substreams/ethereum-balancer/src/pb/eth.factory.v1.rs +++ /dev/null @@ -1,28 +0,0 @@ -// @generated -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Pools { - #[prost(message, repeated, tag="1")] - pub pools: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Pool { - #[prost(bytes="vec", tag="1")] - pub pool_id: ::prost::alloc::vec::Vec, - #[prost(fixed64, tag="2")] - pub log_ordinal: u64, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfer { - #[prost(bytes="vec", tag="1")] - pub from: ::prost::alloc::vec::Vec, - #[prost(bytes="vec", tag="2")] - pub to: ::prost::alloc::vec::Vec, - #[prost(string, tag="3")] - pub token: ::prost::alloc::string::String, - #[prost(string, tag="4")] - pub amount: ::prost::alloc::string::String, -} -// @@protoc_insertion_point(module) diff --git a/substreams/ethereum-balancer/src/pb/eth.pool.v1.rs b/substreams/ethereum-balancer/src/pb/eth.pool.v1.rs deleted file mode 100644 index 16ad6e5..0000000 --- a/substreams/ethereum-balancer/src/pb/eth.pool.v1.rs +++ /dev/null @@ -1,22 +0,0 @@ -// @generated -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfers { - #[prost(message, repeated, tag="1")] - pub transfers: ::prost::alloc::vec::Vec, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transfer { - #[prost(string, tag="1")] - pub from: ::prost::alloc::string::String, - #[prost(string, tag="2")] - pub to: ::prost::alloc::string::String, - #[prost(uint64, tag="3")] - pub token_id: u64, - #[prost(string, tag="4")] - pub trx_hash: ::prost::alloc::string::String, - #[prost(uint64, tag="5")] - pub ordinal: u64, -} -// @@protoc_insertion_point(module) diff --git a/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs b/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs index affc411..21d371d 100644 --- a/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs +++ b/substreams/ethereum-balancer/src/pb/tycho.evm.v1.rs @@ -51,6 +51,18 @@ pub struct Attribute { #[prost(enumeration="ChangeType", tag="3")] pub change: i32, } +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ProtocolType { + #[prost(string, tag="1")] + pub name: ::prost::alloc::string::String, + #[prost(enumeration="FinancialType", tag="2")] + pub financial_type: i32, + #[prost(message, repeated, tag="3")] + pub attribute_schema: ::prost::alloc::vec::Vec, + #[prost(enumeration="ImplementationType", tag="4")] + pub implementation_type: i32, +} /// A struct describing a part of the protocol. /// Note: For example this can be a UniswapV2 pair, that tracks the two ERC20 tokens used by the pair, /// the component would represent a single contract. In case of VM integration, such component would @@ -78,20 +90,12 @@ pub struct ProtocolComponent { /// Type of change the component underwent. #[prost(enumeration="ChangeType", tag="5")] pub change: i32, -} -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TransactionProtocolComponents { - #[prost(message, optional, tag="1")] + /// / Represents the functionality of the component. + #[prost(message, optional, tag="6")] + pub protocol_type: ::core::option::Option, + /// Transaction where this component was created + #[prost(message, optional, tag="7")] 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, } /// A struct for following the changes of Total Value Locked (TVL) of a protocol component. /// Note that if a ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole. @@ -105,39 +109,11 @@ pub struct BalanceChange { /// The new balance of the token. #[prost(bytes="vec", tag="2")] pub balance: ::prost::alloc::vec::Vec, - /// The id of the component whose TVL is tracked. + /// The id of the component whose TVL is tracked. Note: This MUST be utf8 encoded. /// 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="3")] pub component_id: ::prost::alloc::vec::Vec, } -/// A struct for following the changes of Total Value Locked (TVL) of a protocol component. -/// Note that if a ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole. -/// E.g. for UniswapV2 pair WETH/USDC, this tracks the USDC and WETH balance of the pair contract. -#[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, -} /// Enum to specify the type of a change. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[repr(i32)] @@ -171,6 +147,64 @@ impl ChangeType { } } } +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum FinancialType { + Swap = 0, + Lend = 1, + Leverage = 2, + Psm = 3, +} +impl FinancialType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + FinancialType::Swap => "SWAP", + FinancialType::Lend => "LEND", + FinancialType::Leverage => "LEVERAGE", + FinancialType::Psm => "PSM", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "SWAP" => Some(Self::Swap), + "LEND" => Some(Self::Lend), + "LEVERAGE" => Some(Self::Leverage), + "PSM" => Some(Self::Psm), + _ => None, + } + } +} +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] +#[repr(i32)] +pub enum ImplementationType { + Vm = 0, + Custom = 1, +} +impl ImplementationType { + /// String value of the enum field names used in the ProtoBuf definition. + /// + /// The values are not transformed in any way and thus are considered stable + /// (if the ProtoBuf definition does not change) and safe for programmatic use. + pub fn as_str_name(&self) -> &'static str { + match self { + ImplementationType::Vm => "VM", + ImplementationType::Custom => "CUSTOM", + } + } + /// Creates an enum from field names used in the ProtoBuf definition. + pub fn from_str_name(value: &str) -> ::core::option::Option { + match value { + "VM" => Some(Self::Vm), + "CUSTOM" => Some(Self::Custom), + _ => None, + } + } +} // This file contains proto definitions specific to the VM integration. /// A key value entry into contract storage. @@ -233,4 +267,44 @@ 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/src/pool_factories.rs b/substreams/ethereum-balancer/src/pool_factories.rs index 62f1601..fb99696 100644 --- a/substreams/ethereum-balancer/src/pool_factories.rs +++ b/substreams/ethereum-balancer/src/pool_factories.rs @@ -3,6 +3,7 @@ use substreams_ethereum::{Event, Function}; use crate::abi; use crate::pb; +use crate::pb::tycho::evm::v1::{FinancialType, ImplementationType, ProtocolType, Transaction}; use pb::tycho::evm::v1::{self as tycho}; use substreams::hex; @@ -13,6 +14,7 @@ use substreams::scalar::BigInt; /// handled by any downstream application. trait SerializableVecBigInt { fn serialize_bytes(&self) -> Vec; + #[allow(dead_code)] fn deserialize_bytes(bytes: &[u8]) -> Vec; } @@ -25,7 +27,7 @@ impl SerializableVecBigInt for Vec { fn deserialize_bytes(bytes: &[u8]) -> Vec { bytes .chunks_exact(32) - .map(|chunk| BigInt::from_signed_bytes_be(chunk)) + .map(BigInt::from_signed_bytes_be) .collect::>() } } @@ -45,6 +47,7 @@ pub fn address_map( pool_factory_address: &[u8], log: &Log, call: &Call, + tx: &Transaction, ) -> Option { match *pool_factory_address { hex!("897888115Ada5773E02aA29F775430BFB5F34c51") => { @@ -70,6 +73,13 @@ pub fn address_map( }, ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } hex!("DB8d758BCb971e482B2C45f7F8a7740283A1bd3A") => { @@ -82,14 +92,19 @@ pub fn address_map( id: hex::encode(&pool_created.pool), tokens: create_call.tokens, contracts: vec![pool_factory_address.into(), pool_created.pool], - static_att: vec![ - tycho::Attribute { - name: "pool_type".into(), - value: "ComposableStablePoolFactory".into(), - change: tycho::ChangeType::Creation.into(), - }, - ], + static_att: vec![tycho::Attribute { + name: "pool_type".into(), + value: "ComposableStablePoolFactory".into(), + change: tycho::ChangeType::Creation.into(), + }], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } hex!("813EE7a840CE909E7Fea2117A44a90b8063bd4fd") => { @@ -117,6 +132,13 @@ pub fn address_map( // Note, rate provider might be provided as `create.protocol_id`, but as a BigInt. needs investigation ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } hex!("5F43FBa61f63Fa6bFF101a0A0458cEA917f6B347") => { @@ -142,6 +164,13 @@ pub fn address_map( }, ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } // ❌ Reading the deployed factory for Gearbox showcases that it's currently disabled @@ -214,6 +243,13 @@ pub fn address_map( }, ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } hex!("5F5222Ffa40F2AEd6380D022184D6ea67C776eE0") => { @@ -239,6 +275,13 @@ pub fn address_map( }, ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } // The `WeightedPool2TokenFactory` is a deprecated contract but we've included it since one @@ -266,6 +309,13 @@ pub fn address_map( }, ], change: tycho::ChangeType::Creation.into(), + protocol_type: Some(ProtocolType { + name: "balancer".to_string(), + financial_type: FinancialType::Swap.into(), + attribute_schema: vec![], + implementation_type: ImplementationType::Vm.into(), + }), + tx: Some(tx.clone()), }) } _ => None, diff --git a/substreams/ethereum-balancer/substreams.yaml b/substreams/ethereum-balancer/substreams.yaml index f1bc3af..9919f23 100644 --- a/substreams/ethereum-balancer/substreams.yaml +++ b/substreams/ethereum-balancer/substreams.yaml @@ -7,9 +7,9 @@ protobuf: files: - tycho/evm/v1/vm.proto - tycho/evm/v1/common.proto + - tycho/evm/v1/balancer.proto importPaths: - - ../../proto/tycho/evm/v1/ - - ./proto + - ../../proto binaries: default: