Ekubo TWAMM & MEV-resist integration (#192)

* Add Ekubo TWAMM support

* Change order of words

* Account TWAMM order balances

* Fix tracking wrong component balance deltas

Swapped and PositionUpdated are the only events affecting pool TVL

* Fix fee addition

Fees are a .64 instead of a .128 since v2 & the result is rounded

* Consistent naming

* cargo fmt

* Add method for selecting store method from change type

* Only store the affected sale rate delta on OrderUpdated events

* Remove unnecessary parameterization

* Index Ekubo MEV-resist pools

* cargo clippy
This commit is contained in:
die-herdplatte
2025-06-30 16:45:08 +02:00
committed by GitHub
parent ef6c826a8a
commit 1ff97ff43f
28 changed files with 3750 additions and 313 deletions

View File

@@ -1,5 +1,6 @@
// @generated
/// Copy of tycho.evm.v1.Transaction to be able to implement conversions to/from TransactionTrace
/// Copy of tycho.evm.v1.Transaction to be able to implement conversions to/from
/// TransactionTrace
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct Transaction {
@@ -36,6 +37,30 @@ pub struct TickDeltas {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OrderSaleRateDelta {
/// bytes32
#[prost(bytes="vec", tag="1")]
pub pool_id: ::prost::alloc::vec::Vec<u8>,
#[prost(uint64, tag="2")]
pub time: u64,
/// int112
#[prost(bytes="vec", tag="3")]
pub sale_rate_delta: ::prost::alloc::vec::Vec<u8>,
#[prost(bool, tag="4")]
pub is_token1: bool,
#[prost(uint64, tag="5")]
pub ordinal: u64,
#[prost(message, optional, tag="6")]
pub transaction: ::core::option::Option<Transaction>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OrderSaleRateDeltas {
#[prost(message, repeated, tag="1")]
pub deltas: ::prost::alloc::vec::Vec<OrderSaleRateDelta>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct LiquidityChange {
/// bytes32
#[prost(bytes="vec", tag="1")]
@@ -43,7 +68,7 @@ pub struct LiquidityChange {
/// uint128 or int128, depending on change_type
#[prost(bytes="vec", tag="2")]
pub value: ::prost::alloc::vec::Vec<u8>,
#[prost(enumeration="LiquidityChangeType", tag="3")]
#[prost(enumeration="ChangeType", tag="3")]
pub change_type: i32,
#[prost(uint64, tag="4")]
pub ordinal: u64,
@@ -58,6 +83,31 @@ pub struct LiquidityChanges {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SaleRateChange {
/// bytes32
#[prost(bytes="vec", tag="1")]
pub pool_id: ::prost::alloc::vec::Vec<u8>,
/// uint112 or int112, depending on change_type
#[prost(bytes="vec", tag="2")]
pub token0_value: ::prost::alloc::vec::Vec<u8>,
/// uint112 or int112, depending on change_type
#[prost(bytes="vec", tag="3")]
pub token1_value: ::prost::alloc::vec::Vec<u8>,
#[prost(enumeration="ChangeType", tag="4")]
pub change_type: i32,
#[prost(uint64, tag="5")]
pub ordinal: u64,
#[prost(message, optional, tag="6")]
pub transaction: ::core::option::Option<Transaction>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct SaleRateChanges {
#[prost(message, repeated, tag="1")]
pub changes: ::prost::alloc::vec::Vec<SaleRateChange>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PoolDetails {
/// address
#[prost(bytes="vec", tag="1")]
@@ -73,6 +123,9 @@ pub struct PoolDetails {
pub struct BlockTransactionEvents {
#[prost(message, repeated, tag="1")]
pub block_transaction_events: ::prost::alloc::vec::Vec<block_transaction_events::TransactionEvents>,
/// block timestamp
#[prost(uint64, tag="2")]
pub timestamp: u64,
}
/// Nested message and enum types in `BlockTransactionEvents`.
pub mod block_transaction_events {
@@ -138,16 +191,6 @@ pub mod block_transaction_events {
pub delta1: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PositionFeesCollected {
/// uint128
#[prost(bytes="vec", tag="1")]
pub amount0: ::prost::alloc::vec::Vec<u8>,
/// uint128
#[prost(bytes="vec", tag="2")]
pub amount1: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PoolInitialized {
/// address
@@ -176,6 +219,8 @@ pub mod block_transaction_events {
Unknown = 0,
Base = 1,
Oracle = 2,
Twamm = 3,
MevResist = 4,
}
impl Extension {
/// String value of the enum field names used in the ProtoBuf definition.
@@ -187,6 +232,8 @@ pub mod block_transaction_events {
Extension::Unknown => "EXTENSION_UNKNOWN",
Extension::Base => "EXTENSION_BASE",
Extension::Oracle => "EXTENSION_ORACLE",
Extension::Twamm => "EXTENSION_TWAMM",
Extension::MevResist => "EXTENSION_MEV_RESIST",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
@@ -195,6 +242,8 @@ pub mod block_transaction_events {
"EXTENSION_UNKNOWN" => Some(Self::Unknown),
"EXTENSION_BASE" => Some(Self::Base),
"EXTENSION_ORACLE" => Some(Self::Oracle),
"EXTENSION_TWAMM" => Some(Self::Twamm),
"EXTENSION_MEV_RESIST" => Some(Self::MevResist),
_ => None,
}
}
@@ -202,13 +251,43 @@ pub mod block_transaction_events {
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct FeesAccumulated {
/// uint128
pub struct VirtualOrdersExecuted {
/// int112
#[prost(bytes="vec", tag="1")]
pub amount0: ::prost::alloc::vec::Vec<u8>,
/// uint128
pub token0_sale_rate: ::prost::alloc::vec::Vec<u8>,
/// int112
#[prost(bytes="vec", tag="2")]
pub amount1: ::prost::alloc::vec::Vec<u8>,
pub token1_sale_rate: ::prost::alloc::vec::Vec<u8>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OrderUpdated {
#[prost(message, optional, tag="1")]
pub order_key: ::core::option::Option<order_updated::OrderKey>,
/// int112
#[prost(bytes="vec", tag="2")]
pub sale_rate_delta: ::prost::alloc::vec::Vec<u8>,
}
/// Nested message and enum types in `OrderUpdated`.
pub mod order_updated {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct OrderKey {
/// address
#[prost(bytes="vec", tag="1")]
pub sell_token: ::prost::alloc::vec::Vec<u8>,
/// address
#[prost(bytes="vec", tag="2")]
pub buy_token: ::prost::alloc::vec::Vec<u8>,
#[prost(fixed64, tag="3")]
pub fee: u64,
/// block timestamp
#[prost(uint64, tag="4")]
pub start_time: u64,
/// block timestamp
#[prost(uint64, tag="5")]
pub end_time: u64,
}
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
@@ -218,30 +297,30 @@ pub mod block_transaction_events {
#[prost(message, tag="4")]
PositionUpdated(PositionUpdated),
#[prost(message, tag="5")]
PositionFeesCollected(PositionFeesCollected),
#[prost(message, tag="6")]
PoolInitialized(PoolInitialized),
#[prost(message, tag="6")]
VirtualOrdersExecuted(VirtualOrdersExecuted),
#[prost(message, tag="7")]
FeesAccumulated(FeesAccumulated),
OrderUpdated(OrderUpdated),
}
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum LiquidityChangeType {
pub enum ChangeType {
Delta = 0,
Absolute = 1,
}
impl LiquidityChangeType {
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 {
LiquidityChangeType::Delta => "DELTA",
LiquidityChangeType::Absolute => "ABSOLUTE",
ChangeType::Delta => "DELTA",
ChangeType::Absolute => "ABSOLUTE",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.