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};
26
27/// Represents a fee collection event in a decentralized exchange (DEX) pool.
28#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
29#[cfg_attr(
30    feature = "python",
31    pyo3::pyclass(module = "nautilus_trader.core.nautilus_pyo3.model")
32)]
33pub struct PoolFeeCollect {
34    /// The blockchain network where the fee collection occurred.
35    pub chain: SharedChain,
36    /// The decentralized exchange where the fee collection was executed.
37    pub dex: SharedDex,
38    /// The instrument ID for this pool's trading pair.
39    pub instrument_id: InstrumentId,
40    /// The blockchain address of the pool smart contract.
41    pub pool_address: Address,
42    /// The blockchain block number where the fee collection occurred.
43    pub block: u64,
44    /// The unique hash identifier of the blockchain transaction containing the fee collection.
45    pub transaction_hash: String,
46    /// The index position of the transaction within the block.
47    pub transaction_index: u32,
48    /// The index position of the fee collection event log within the transaction.
49    pub log_index: u32,
50    /// The blockchain address that owns the liquidity position.
51    pub owner: Address,
52    /// The amount of the first token fees collected.
53    pub amount0: u128,
54    /// The amount of the second token fees collected.
55    pub amount1: u128,
56    /// The lower price tick boundary of the liquidity position.
57    pub tick_lower: i32,
58    /// The upper price tick boundary of the liquidity position.
59    pub tick_upper: i32,
60    /// The timestamp of the fee collection in Unix nanoseconds.
61    pub timestamp: Option<UnixNanos>,
62    /// UNIX timestamp (nanoseconds) when the instance was created.
63    pub ts_init: Option<UnixNanos>,
64}
65
66impl PoolFeeCollect {
67    /// Creates a new [`PoolFeeCollect`] instance with the specified properties.
68    #[must_use]
69    #[allow(clippy::too_many_arguments)]
70    pub const fn new(
71        chain: SharedChain,
72        dex: SharedDex,
73        instrument_id: InstrumentId,
74        pool_address: Address,
75        block: u64,
76        transaction_hash: String,
77        transaction_index: u32,
78        log_index: u32,
79        owner: Address,
80        amount0: u128,
81        amount1: u128,
82        tick_lower: i32,
83        tick_upper: i32,
84        timestamp: Option<UnixNanos>,
85    ) -> Self {
86        Self {
87            chain,
88            dex,
89            instrument_id,
90            pool_address,
91            block,
92            transaction_hash,
93            transaction_index,
94            log_index,
95            owner,
96            amount0,
97            amount1,
98            tick_lower,
99            tick_upper,
100            timestamp,
101            ts_init: timestamp,
102        }
103    }
104
105    /// Returns the instrument ID for this pool's trading pair.
106    #[must_use]
107    pub const fn instrument_id(&self) -> InstrumentId {
108        self.instrument_id
109    }
110}
111
112impl Display for PoolFeeCollect {
113    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
114        write!(
115            f,
116            "PoolFeeCollect({} fees collected: token0={}, token1={}, owner={}, tick_range=[{}, {}], tx={}:{}:{})",
117            self.instrument_id,
118            self.amount0,
119            self.amount1,
120            self.owner,
121            self.tick_lower,
122            self.tick_upper,
123            self.block,
124            self.transaction_index,
125            self.log_index,
126        )
127    }
128}