use std::fmt::Display;
use alloy_primitives::{Address, U256};
use nautilus_core::UnixNanos;
use serde::{Deserialize, Serialize};
use crate::{
defi::{PoolIdentifier, SharedChain, SharedDex},
identifiers::InstrumentId,
};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[cfg_attr(
feature = "python",
pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model", from_py_object)
)]
#[cfg_attr(
feature = "python",
pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.model")
)]
pub struct PoolFlash {
pub chain: SharedChain,
pub dex: SharedDex,
pub instrument_id: InstrumentId,
pub pool_identifier: PoolIdentifier,
pub block: u64,
pub transaction_hash: String,
pub transaction_index: u32,
pub log_index: u32,
pub ts_event: Option<UnixNanos>,
pub sender: Address,
pub recipient: Address,
pub amount0: U256,
pub amount1: U256,
pub paid0: U256,
pub paid1: U256,
}
impl PoolFlash {
#[must_use]
#[allow(clippy::too_many_arguments)]
pub fn new(
chain: SharedChain,
dex: SharedDex,
instrument_id: InstrumentId,
pool_identifier: PoolIdentifier,
block_number: u64,
transaction_hash: String,
transaction_index: u32,
log_index: u32,
ts_event: Option<UnixNanos>,
sender: Address,
recipient: Address,
amount0: U256,
amount1: U256,
paid0: U256,
paid1: U256,
) -> Self {
Self {
chain,
dex,
instrument_id,
pool_identifier,
block: block_number,
transaction_hash,
transaction_index,
log_index,
ts_event,
sender,
recipient,
amount0,
amount1,
paid0,
paid1,
}
}
}
impl Display for PoolFlash {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"PoolFlash(instrument={}, recipient={}, amount0={}, amount1={}, paid0={}, paid1={})",
self.instrument_id, self.recipient, self.amount0, self.amount1, self.paid0, self.paid1,
)
}
}