diff --git a/substreams/Cargo.lock b/substreams/Cargo.lock index 0654435..84e0b41 100644 --- a/substreams/Cargo.lock +++ b/substreams/Cargo.lock @@ -1051,6 +1051,7 @@ dependencies = [ "substreams", "substreams-ethereum", "substreams-helper", + "tycho-substreams", ] [[package]] diff --git a/substreams/ethereum-uniswap-v2/Cargo.toml b/substreams/ethereum-uniswap-v2/Cargo.toml index ab2e76a..6348817 100644 --- a/substreams/ethereum-uniswap-v2/Cargo.toml +++ b/substreams/ethereum-uniswap-v2/Cargo.toml @@ -15,6 +15,7 @@ ethabi.workspace = true anyhow = { workspace = true, features = [] } hex-literal.workspace = true substreams-helper.workspace = true +tycho-substreams.workspace = true num-bigint = "0.4.4" itertools = "0.12.1" serde_qs = "0.13.0" diff --git a/substreams/ethereum-uniswap-v2/arbitrum-uniswap-v2.yaml b/substreams/ethereum-uniswap-v2/arbitrum-uniswap-v2.yaml index 7f287bc..22b4ee3 100644 --- a/substreams/ethereum-uniswap-v2/arbitrum-uniswap-v2.yaml +++ b/substreams/ethereum-uniswap-v2/arbitrum-uniswap-v2.yaml @@ -5,12 +5,9 @@ package: protobuf: files: - - tycho/evm/v1/common.proto - - tycho/evm/v1/entity.proto - uniswap.proto importPaths: - ./proto/v1 - - ../../proto/ binaries: default: diff --git a/substreams/ethereum-uniswap-v2/buf.gen.yaml b/substreams/ethereum-uniswap-v2/buf.gen.yaml new file mode 100644 index 0000000..d2e6544 --- /dev/null +++ b/substreams/ethereum-uniswap-v2/buf.gen.yaml @@ -0,0 +1,12 @@ + +version: v1 +plugins: +- plugin: buf.build/community/neoeinstein-prost:v0.2.2 + out: src/pb + opt: + - file_descriptor_set=false + +- plugin: buf.build/community/neoeinstein-prost-crate:v0.3.1 + out: src/pb + opt: + - no_features diff --git a/substreams/ethereum-uniswap-v2/ethereum-pancakeswap.yaml b/substreams/ethereum-uniswap-v2/ethereum-pancakeswap.yaml index 7424d6c..1944e69 100644 --- a/substreams/ethereum-uniswap-v2/ethereum-pancakeswap.yaml +++ b/substreams/ethereum-uniswap-v2/ethereum-pancakeswap.yaml @@ -5,12 +5,9 @@ package: protobuf: files: - - tycho/evm/v1/common.proto - - tycho/evm/v1/entity.proto - uniswap.proto importPaths: - ./proto/v1 - - ../../proto/ binaries: default: diff --git a/substreams/ethereum-uniswap-v2/ethereum-sushiswap.yaml b/substreams/ethereum-uniswap-v2/ethereum-sushiswap.yaml index e5334d1..8a9233c 100644 --- a/substreams/ethereum-uniswap-v2/ethereum-sushiswap.yaml +++ b/substreams/ethereum-uniswap-v2/ethereum-sushiswap.yaml @@ -5,12 +5,9 @@ package: protobuf: files: - - tycho/evm/v1/common.proto - - tycho/evm/v1/entity.proto - uniswap.proto importPaths: - ./proto/v1 - - ../../proto/ binaries: default: diff --git a/substreams/ethereum-uniswap-v2/ethereum-uniswap-v2.yaml b/substreams/ethereum-uniswap-v2/ethereum-uniswap-v2.yaml index 1ed8f63..c1e8bb1 100644 --- a/substreams/ethereum-uniswap-v2/ethereum-uniswap-v2.yaml +++ b/substreams/ethereum-uniswap-v2/ethereum-uniswap-v2.yaml @@ -5,12 +5,9 @@ package: protobuf: files: - - tycho/evm/v1/common.proto - - tycho/evm/v1/entity.proto - uniswap.proto importPaths: - ./proto/v1 - - ../../proto/ binaries: default: diff --git a/substreams/ethereum-uniswap-v2/src/modules/1_map_pool_created.rs b/substreams/ethereum-uniswap-v2/src/modules/1_map_pool_created.rs index 8e6a6dd..582706c 100644 --- a/substreams/ethereum-uniswap-v2/src/modules/1_map_pool_created.rs +++ b/substreams/ethereum-uniswap-v2/src/modules/1_map_pool_created.rs @@ -7,14 +7,9 @@ use substreams_ethereum::pb::eth::v2::{self as eth}; use substreams_helper::{event_handler::EventHandler, hex::Hexable}; -use crate::{ - abi::factory::events::PairCreated, - pb::tycho::evm::v1::{ - Attribute, Block, BlockChanges, ChangeType, EntityChanges, FinancialType, - ImplementationType, ProtocolComponent, ProtocolType, Transaction, TransactionChanges, - }, -}; +use crate::abi::factory::events::PairCreated; +use tycho_substreams::prelude::*; #[derive(Debug, Deserialize)] struct Params { factory_address: String, @@ -32,7 +27,7 @@ pub fn map_pools_created( get_pools(&block, &mut new_pools, ¶ms); - let tycho_block: Block = block.into(); + let tycho_block: Block = (&block).into(); Ok(BlockChanges { block: Some(tycho_block), changes: new_pools }) } diff --git a/substreams/ethereum-uniswap-v2/src/modules/2_store_pools.rs b/substreams/ethereum-uniswap-v2/src/modules/2_store_pools.rs index b0d8256..6b85384 100644 --- a/substreams/ethereum-uniswap-v2/src/modules/2_store_pools.rs +++ b/substreams/ethereum-uniswap-v2/src/modules/2_store_pools.rs @@ -1,9 +1,7 @@ use substreams::store::{StoreNew, StoreSetIfNotExists, StoreSetIfNotExistsProto}; -use crate::{ - pb::tycho::evm::v1::{BlockChanges, ProtocolComponent}, - store_key::StoreKey, -}; +use crate::store_key::StoreKey; +use tycho_substreams::prelude::*; #[substreams::handlers::store] pub fn store_pools( diff --git a/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs b/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs index c4e902d..2e6b264 100644 --- a/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs +++ b/substreams/ethereum-uniswap-v2/src/modules/3_map_pool_events.rs @@ -5,18 +5,8 @@ use substreams_ethereum::pb::eth::v2::{self as eth}; use substreams_helper::{event_handler::EventHandler, hex::Hexable}; -use crate::{ - abi::pool::events::Sync, - pb::tycho::evm::{ - v1, - v1::{ - Attribute, BalanceChange, BlockChanges, ChangeType, EntityChanges, ProtocolComponent, - TransactionChanges, - }, - }, - store_key::StoreKey, - traits::PoolAddresser, -}; +use crate::{abi::pool::events::Sync, store_key::StoreKey, traits::PoolAddresser}; +use tycho_substreams::prelude::*; // Auxiliary struct to serve as a key for the HashMaps. #[derive(Clone, Hash, Eq, PartialEq)] @@ -33,7 +23,7 @@ impl ComponentKey { #[derive(Clone)] struct PartialChanges { - transaction: v1::Transaction, + transaction: Transaction, entity_changes: HashMap, Attribute>, balance_changes: HashMap>, BalanceChange>, } diff --git a/substreams/ethereum-uniswap-v2/src/pb/mod.rs b/substreams/ethereum-uniswap-v2/src/pb/mod.rs index f868620..c200c9b 100644 --- a/substreams/ethereum-uniswap-v2/src/pb/mod.rs +++ b/substreams/ethereum-uniswap-v2/src/pb/mod.rs @@ -8,10 +8,5 @@ pub mod tycho { // @@protoc_insertion_point(tycho.evm.uniswap.v2) } } - // @@protoc_insertion_point(attribute:tycho.evm.v1) - pub mod v1 { - include!("tycho.evm.v1.rs"); - // @@protoc_insertion_point(tycho.evm.v1) - } } } diff --git a/substreams/ethereum-uniswap-v2/src/pb/tycho.evm.v1.rs b/substreams/ethereum-uniswap-v2/src/pb/tycho.evm.v1.rs deleted file mode 100644 index 6dac022..0000000 --- a/substreams/ethereum-uniswap-v2/src/pb/tycho.evm.v1.rs +++ /dev/null @@ -1,307 +0,0 @@ -// @generated -// This file contains the proto definitions for Substreams common to all integrations. - -/// A struct describing a block. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Block { - /// The blocks hash. - #[prost(bytes="vec", tag="1")] - pub hash: ::prost::alloc::vec::Vec, - /// The parent blocks hash. - #[prost(bytes="vec", tag="2")] - pub parent_hash: ::prost::alloc::vec::Vec, - /// The block number. - #[prost(uint64, tag="3")] - pub number: u64, - /// The block timestamp. - #[prost(uint64, tag="4")] - pub ts: u64, -} -/// A struct describing a transaction. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Transaction { - /// The transaction hash. - #[prost(bytes="vec", tag="1")] - pub hash: ::prost::alloc::vec::Vec, - /// The sender of the transaction. - #[prost(bytes="vec", tag="2")] - pub from: ::prost::alloc::vec::Vec, - /// The receiver of the transaction. - #[prost(bytes="vec", tag="3")] - pub to: ::prost::alloc::vec::Vec, - /// The transactions index within the block. - #[prost(uint64, tag="4")] - pub index: u64, -} -/// A custom struct representing an arbitrary attribute of a protocol component. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct Attribute { - /// The name of the attribute. - #[prost(string, tag="1")] - pub name: ::prost::alloc::string::String, - /// The value of the attribute. - #[prost(bytes="vec", tag="2")] - pub value: ::prost::alloc::vec::Vec, - /// The type of change the attribute underwent. - #[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. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct ProtocolComponent { - /// A unique identifier for the component within the protocol. - /// Can be a stringified address or a string describing the trading pair. - #[prost(string, tag="1")] - pub id: ::prost::alloc::string::String, - /// Addresses of the ERC20 tokens used by the component. - #[prost(bytes="vec", repeated, tag="2")] - pub tokens: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, - /// Addresses of the contracts used by the component. - #[prost(bytes="vec", repeated, tag="3")] - pub contracts: ::prost::alloc::vec::Vec<::prost::alloc::vec::Vec>, - /// Attributes of the component. - /// The inner ChangeType of the attribute has to match the ChangeType of the ProtocolComponent. - #[prost(message, repeated, tag="4")] - pub static_att: ::prost::alloc::vec::Vec, - /// Type of change the component underwent. - #[prost(enumeration="ChangeType", tag="5")] - pub change: i32, - /// / 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, -} -/// A struct for following the changes of Total Value Locked (TVL) of a protocol component. -/// Note that if the ProtocolComponent contains multiple contracts, the TVL is tracked for the component as a whole. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct BalanceChange { - /// The address of the ERC20 token whose balance changed. - #[prost(bytes="vec", tag="1")] - pub token: ::prost::alloc::vec::Vec, - /// 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. Note: This MUST be utf8 encoded. - #[prost(bytes="vec", tag="3")] - pub component_id: ::prost::alloc::vec::Vec, -} -// Native entities - -/// A component is a set of attributes that are associated with a custom entity. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct EntityChanges { - /// A unique identifier of the entity within the protocol. - #[prost(string, tag="1")] - pub component_id: ::prost::alloc::string::String, - /// The set of attributes that are associated with the entity. - #[prost(message, repeated, tag="2")] - pub attributes: ::prost::alloc::vec::Vec, -} -// VM entities - -/// A key value entry into contract storage. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct ContractSlot { - /// A contract's storage slot. - #[prost(bytes="vec", tag="2")] - pub slot: ::prost::alloc::vec::Vec, - /// The new value for this storage slot. - #[prost(bytes="vec", tag="3")] - pub value: ::prost::alloc::vec::Vec, -} -/// Changes made to a single contract's state. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct ContractChange { - /// The contract's address - #[prost(bytes="vec", tag="1")] - pub address: ::prost::alloc::vec::Vec, - /// The new balance of the contract, empty bytes indicates no change. - #[prost(bytes="vec", tag="2")] - pub balance: ::prost::alloc::vec::Vec, - /// The new code of the contract, empty bytes indicates no change. - #[prost(bytes="vec", tag="3")] - pub code: ::prost::alloc::vec::Vec, - /// The changes to this contract's slots, empty sequence indicates no change. - #[prost(message, repeated, tag="4")] - pub slots: ::prost::alloc::vec::Vec, - /// Whether this is an update, a creation or a deletion. - #[prost(enumeration="ChangeType", tag="5")] - pub change: i32, -} -// Aggregate entities - -/// A set of changes aggregated by transaction. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TransactionChanges { - /// The transaction instance that results in the changes. - #[prost(message, optional, tag="1")] - pub tx: ::core::option::Option, - /// Contains the changes induced by the above transaction, aggregated on a per-contract basis. - /// Contains the contract changes induced by the above transaction, usually for tracking VM components. - #[prost(message, repeated, tag="2")] - pub contract_changes: ::prost::alloc::vec::Vec, - /// Contains the entity changes induced by the above transaction. - /// Usually for tracking native components or used for VM extensions (plugins). - #[prost(message, repeated, tag="3")] - pub entity_changes: ::prost::alloc::vec::Vec, - /// An array of newly added components. - #[prost(message, repeated, tag="4")] - pub component_changes: ::prost::alloc::vec::Vec, - /// An array of balance changes to components. - #[prost(message, repeated, tag="5")] - pub balance_changes: ::prost::alloc::vec::Vec, -} -/// A set of transaction changes within a single block. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct BlockChanges { - /// The block for which these changes are collectively computed. - #[prost(message, optional, tag="1")] - pub block: ::core::option::Option, - /// The set of transaction changes observed in the specified block. - #[prost(message, repeated, tag="2")] - pub changes: ::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)] -pub enum ChangeType { - Unspecified = 0, - Update = 1, - Creation = 2, - Deletion = 3, -} -impl ChangeType { - /// 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 { - ChangeType::Unspecified => "CHANGE_TYPE_UNSPECIFIED", - ChangeType::Update => "CHANGE_TYPE_UPDATE", - ChangeType::Creation => "CHANGE_TYPE_CREATION", - ChangeType::Deletion => "CHANGE_TYPE_DELETION", - } - } - /// Creates an enum from field names used in the ProtoBuf definition. - pub fn from_str_name(value: &str) -> ::core::option::Option { - match value { - "CHANGE_TYPE_UNSPECIFIED" => Some(Self::Unspecified), - "CHANGE_TYPE_UPDATE" => Some(Self::Update), - "CHANGE_TYPE_CREATION" => Some(Self::Creation), - "CHANGE_TYPE_DELETION" => Some(Self::Deletion), - _ => None, - } - } -} -#[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, - } - } -} -// WARNING: DEPRECATED. Please use common.proto's TransactionChanges and BlockChanges instead. -// This file contains the definition for the native integration of Substreams. - -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct TransactionEntityChanges { - #[prost(message, optional, tag="1")] - pub tx: ::core::option::Option, - #[prost(message, repeated, tag="2")] - pub entity_changes: ::prost::alloc::vec::Vec, - /// An array of newly added components. - #[prost(message, repeated, tag="3")] - pub component_changes: ::prost::alloc::vec::Vec, - /// An array of balance changes to components. - #[prost(message, repeated, tag="4")] - pub balance_changes: ::prost::alloc::vec::Vec, -} -/// A set of transaction changes within a single block. -#[allow(clippy::derive_partial_eq_without_eq)] -#[derive(Clone, PartialEq, ::prost::Message)] -pub struct BlockEntityChanges { - /// The block for which these changes are collectively computed. - #[prost(message, optional, tag="1")] - pub block: ::core::option::Option, - /// The set of transaction changes observed in the specified block. - #[prost(message, repeated, tag="2")] - pub changes: ::prost::alloc::vec::Vec, -} -// @@protoc_insertion_point(module) diff --git a/substreams/ethereum-uniswap-v2/src/traits.rs b/substreams/ethereum-uniswap-v2/src/traits.rs index 9edd693..b3aa69d 100644 --- a/substreams/ethereum-uniswap-v2/src/traits.rs +++ b/substreams/ethereum-uniswap-v2/src/traits.rs @@ -1,13 +1,11 @@ use ethabi::ethereum_types::Address; use substreams::store::{StoreGet, StoreGetProto}; -use substreams_ethereum::pb::eth::v2::{self as eth}; use substreams_helper::{common::HasAddresser, hex::Hexable}; -use crate::{ - pb::tycho::evm::v1::{Block, ProtocolComponent, Transaction}, - store_key::StoreKey, -}; +use tycho_substreams::prelude::*; + +use crate::store_key::StoreKey; pub struct PoolAddresser<'a> { pub store: &'a StoreGetProto, @@ -22,30 +20,3 @@ impl<'a> HasAddresser for PoolAddresser<'a> { pool.is_some() } } - -impl From for Block { - fn from(block: eth::Block) -> Self { - Self { - hash: block.hash.clone(), - parent_hash: block - .header - .as_ref() - .expect("Block header not present") - .parent_hash - .clone(), - number: block.number, - ts: block.timestamp_seconds(), - } - } -} - -impl From<ð::TransactionTrace> for Transaction { - fn from(tx: ð::TransactionTrace) -> Self { - Self { - hash: tx.hash.clone(), - from: tx.from.clone(), - to: tx.to.clone(), - index: tx.index.into(), - } - } -}