refactor: update protobuf messages

This commit is contained in:
Florian Pellissier
2024-03-11 17:45:58 +01:00
parent b8d7f6686c
commit 66a048fbe2
15 changed files with 261 additions and 380 deletions

View File

@@ -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::<Vec<_>>();
@@ -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<tycho::BlockContractChanges> {

View File

@@ -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<Pool>,
}
#[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<u8>,
#[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<u8>,
#[prost(bytes="vec", tag="2")]
pub to: ::prost::alloc::vec::Vec<u8>,
#[prost(string, tag="3")]
pub token: ::prost::alloc::string::String,
#[prost(string, tag="4")]
pub amount: ::prost::alloc::string::String,
}
// @@protoc_insertion_point(module)

View File

@@ -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<Pool>,
}
#[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<u8>,
#[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<u8>,
#[prost(bytes="vec", tag="2")]
pub to: ::prost::alloc::vec::Vec<u8>,
#[prost(string, tag="3")]
pub token: ::prost::alloc::string::String,
#[prost(string, tag="4")]
pub amount: ::prost::alloc::string::String,
}
// @@protoc_insertion_point(module)

View File

@@ -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<Transfer>,
}
#[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)

View File

@@ -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<Attribute>,
#[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<ProtocolType>,
/// Transaction where this component was created
#[prost(message, optional, tag="7")]
pub tx: ::core::option::Option<Transaction>,
#[prost(message, repeated, tag="2")]
pub components: ::prost::alloc::vec::Vec<ProtocolComponent>,
}
#[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<TransactionProtocolComponents>,
}
/// 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<u8>,
/// 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<u8>,
}
/// 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<Transaction>,
/// The address of the ERC20 token whose balance changed.
#[prost(bytes="vec", tag="3")]
pub token: ::prost::alloc::vec::Vec<u8>,
/// The delta balance of the token.
#[prost(bytes="vec", tag="4")]
pub delta: ::prost::alloc::vec::Vec<u8>,
/// 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<u8>,
}
#[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<BalanceDelta>,
}
/// 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<Self> {
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<Self> {
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<TransactionContractChanges>,
}
/// 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<Transaction>,
/// The address of the ERC20 token whose balance changed.
#[prost(bytes="vec", tag="3")]
pub token: ::prost::alloc::vec::Vec<u8>,
/// The delta balance of the token.
#[prost(bytes="vec", tag="4")]
pub delta: ::prost::alloc::vec::Vec<u8>,
/// 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<u8>,
}
#[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<BalanceDelta>,
}
#[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<Transaction>,
#[prost(message, repeated, tag="2")]
pub components: ::prost::alloc::vec::Vec<ProtocolComponent>,
}
#[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<TransactionProtocolComponents>,
}
// @@protoc_insertion_point(module)

View File

@@ -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<u8>;
#[allow(dead_code)]
fn deserialize_bytes(bytes: &[u8]) -> Vec<BigInt>;
}
@@ -25,7 +27,7 @@ impl SerializableVecBigInt for Vec<BigInt> {
fn deserialize_bytes(bytes: &[u8]) -> Vec<BigInt> {
bytes
.chunks_exact(32)
.map(|chunk| BigInt::from_signed_bytes_be(chunk))
.map(BigInt::from_signed_bytes_be)
.collect::<Vec<BigInt>>()
}
}
@@ -45,6 +47,7 @@ pub fn address_map(
pool_factory_address: &[u8],
log: &Log,
call: &Call,
tx: &Transaction,
) -> Option<tycho::ProtocolComponent> {
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,