nautilus_model/defi/data/
collect.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2025 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use std::fmt::Display;
17
18use alloy_primitives::Address;
19use nautilus_core::UnixNanos;
20use serde::{Deserialize, Serialize};
21
22use crate::{
23    defi::{SharedChain, SharedDex},
24    identifiers::InstrumentId,
25    types::Quantity,
26};
27
28/// Represents a fee collection event in a decentralized exchange (DEX) pool.
29#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
30#[cfg_attr(
31    feature = "python",
32    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
33)]
34pub struct PoolFeeCollect {
35    /// The blockchain network where the fee collection occurred.
36    pub chain: SharedChain,
37    /// The decentralized exchange where the fee collection was executed.
38    pub dex: SharedDex,
39    /// The DEX liquidity pool instrument ID.
40    pub instrument_id: InstrumentId,
41    /// The blockchain address of the pool smart contract.
42    pub pool_address: Address,
43    /// The blockchain block number where the fee collection occurred.
44    pub block: u64,
45    /// The unique hash identifier of the blockchain transaction containing the fee collection.
46    pub transaction_hash: String,
47    /// The index position of the transaction within the block.
48    pub transaction_index: u32,
49    /// The index position of the fee collection event log within the transaction.
50    pub log_index: u32,
51    /// The blockchain address that owns the liquidity position.
52    pub owner: Address,
53    /// The amount of the first token fees collected.
54    pub fee0: Quantity,
55    /// The amount of the second token fees collected.
56    pub fee1: Quantity,
57    /// The lower price tick boundary of the liquidity position.
58    pub tick_lower: i32,
59    /// The upper price tick boundary of the liquidity position.
60    pub tick_upper: i32,
61    /// The timestamp of the fee collection in Unix nanoseconds.
62    pub timestamp: Option<UnixNanos>,
63    /// UNIX timestamp (nanoseconds) when the instance was created.
64    pub ts_init: Option<UnixNanos>,
65}
66
67impl PoolFeeCollect {
68    /// Creates a new [`PoolFeeCollect`] instance with the specified properties.
69    #[must_use]
70    #[allow(clippy::too_many_arguments)]
71    pub const fn new(
72        chain: SharedChain,
73        dex: SharedDex,
74        instrument_id: InstrumentId,
75        pool_address: Address,
76        block: u64,
77        transaction_hash: String,
78        transaction_index: u32,
79        log_index: u32,
80        owner: Address,
81        fee0: Quantity,
82        fee1: Quantity,
83        tick_lower: i32,
84        tick_upper: i32,
85        timestamp: Option<UnixNanos>,
86    ) -> Self {
87        Self {
88            chain,
89            dex,
90            instrument_id,
91            pool_address,
92            block,
93            transaction_hash,
94            transaction_index,
95            log_index,
96            owner,
97            fee0,
98            fee1,
99            tick_lower,
100            tick_upper,
101            timestamp,
102            ts_init: timestamp,
103        }
104    }
105}
106
107impl Display for PoolFeeCollect {
108    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109        write!(
110            f,
111            "PoolFeeCollect({}:{} {} fees collected: token0={}, token1={}, owner={}, tick_range=[{}, {}], tx={}:{}:{})",
112            self.chain.name,
113            self.dex.name,
114            self.instrument_id,
115            self.fee0,
116            self.fee1,
117            self.owner,
118            self.tick_lower,
119            self.tick_upper,
120            self.block,
121            self.transaction_index,
122            self.log_index,
123        )
124    }
125}