nautilus_model/defi/data/collect.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 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::{PoolIdentifier, 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.model", from_py_object)
32)]
33#[cfg_attr(
34 feature = "python",
35 pyo3_stub_gen::derive::gen_stub_pyclass(module = "nautilus_trader.model")
36)]
37pub struct PoolFeeCollect {
38 /// The blockchain network where the fee collection occurred.
39 pub chain: SharedChain,
40 /// The decentralized exchange where the fee collection was executed.
41 pub dex: SharedDex,
42 /// The instrument ID for this pool's trading pair.
43 pub instrument_id: InstrumentId,
44 /// The unique identifier for this pool (could be an address or other protocol-specific hex string).
45 pub pool_identifier: PoolIdentifier,
46 /// The blockchain block number where the fee collection occurred.
47 pub block: u64,
48 /// The hash of the block observed when this collection was ingested.
49 #[serde(default, skip_serializing_if = "Option::is_none")]
50 pub block_hash: Option<String>,
51 /// The unique hash identifier of the blockchain transaction containing the fee collection.
52 pub transaction_hash: String,
53 /// The index position of the transaction within the block.
54 pub transaction_index: u32,
55 /// The index position of the fee collection event log within the transaction.
56 pub log_index: u32,
57 /// The blockchain address that owns the liquidity position.
58 pub owner: Address,
59 /// The amount of the first token fees collected.
60 pub amount0: u128,
61 /// The amount of the second token fees collected.
62 pub amount1: u128,
63 /// The lower price tick boundary of the liquidity position.
64 pub tick_lower: i32,
65 /// The upper price tick boundary of the liquidity position.
66 pub tick_upper: i32,
67 /// UNIX timestamp (nanoseconds) when the fee collection event occurred.
68 pub ts_event: UnixNanos,
69 /// UNIX timestamp (nanoseconds) when the instance was created.
70 pub ts_init: UnixNanos,
71}
72
73impl PoolFeeCollect {
74 /// Creates a new [`PoolFeeCollect`] instance with the specified properties.
75 #[must_use]
76 #[expect(clippy::too_many_arguments)]
77 pub const fn new(
78 chain: SharedChain,
79 dex: SharedDex,
80 instrument_id: InstrumentId,
81 pool_identifier: PoolIdentifier,
82 block: u64,
83 transaction_hash: String,
84 transaction_index: u32,
85 log_index: u32,
86 owner: Address,
87 amount0: u128,
88 amount1: u128,
89 tick_lower: i32,
90 tick_upper: i32,
91 ts_event: UnixNanos,
92 ts_init: UnixNanos,
93 ) -> Self {
94 Self {
95 chain,
96 dex,
97 instrument_id,
98 pool_identifier,
99 block,
100 block_hash: None,
101 transaction_hash,
102 transaction_index,
103 log_index,
104 owner,
105 amount0,
106 amount1,
107 tick_lower,
108 tick_upper,
109 ts_event,
110 ts_init,
111 }
112 }
113}
114
115impl Display for PoolFeeCollect {
116 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
117 write!(
118 f,
119 "PoolFeeCollect({} fees collected: token0={}, token1={}, owner={}, tick_range=[{}, {}], tx={}:{}:{})",
120 self.instrument_id,
121 self.amount0,
122 self.amount1,
123 self.owner,
124 self.tick_lower,
125 self.tick_upper,
126 self.block,
127 self.transaction_index,
128 self.log_index,
129 )
130 }
131}