use alloy::primitives::{Address, I256, U160};
use nautilus_core::UnixNanos;
use nautilus_model::{
defi::{PoolSwap, SharedChain, SharedDex},
enums::OrderSide,
identifiers::InstrumentId,
types::{Price, Quantity},
};
#[derive(Debug, Clone)]
pub struct SwapEvent {
pub dex: SharedDex,
pub pool_address: Address,
pub block_number: u64,
pub transaction_hash: String,
pub transaction_index: u32,
pub log_index: u32,
pub sender: Address,
pub receiver: Address,
pub amount0: I256,
pub amount1: I256,
pub sqrt_price_x96: U160,
pub liquidity: u128,
pub tick: i32,
}
impl SwapEvent {
#[must_use]
#[allow(clippy::too_many_arguments)]
pub const fn new(
dex: SharedDex,
pool_address: Address,
block_number: u64,
transaction_hash: String,
transaction_index: u32,
log_index: u32,
sender: Address,
receiver: Address,
amount0: I256,
amount1: I256,
sqrt_price_x96: U160,
liquidity: u128,
tick: i32,
) -> Self {
Self {
dex,
pool_address,
block_number,
transaction_hash,
transaction_index,
log_index,
sender,
receiver,
amount0,
amount1,
sqrt_price_x96,
liquidity,
tick,
}
}
#[allow(clippy::too_many_arguments)]
#[must_use]
pub fn to_pool_swap(
&self,
chain: SharedChain,
instrument_id: InstrumentId,
pool_address: Address,
normalized_side: Option<OrderSide>,
normalized_quantity: Option<Quantity>,
normalized_price: Option<Price>,
timestamp: Option<UnixNanos>,
) -> PoolSwap {
PoolSwap::new(
chain,
self.dex.clone(),
instrument_id,
pool_address,
self.block_number,
self.transaction_hash.clone(),
self.transaction_index,
self.log_index,
timestamp,
self.sender,
self.receiver,
self.amount0,
self.amount1,
self.sqrt_price_x96,
self.liquidity,
self.tick,
normalized_side,
normalized_quantity,
normalized_price,
)
}
}