nautilus_blockchain/events/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 alloy::primitives::{Address, B256};
17use nautilus_core::UnixNanos;
18use nautilus_model::{
19 defi::{PoolIdentifier, SharedChain, SharedDex, data::PoolFeeCollect},
20 identifiers::InstrumentId,
21};
22
23/// Represents a collect event that occurs when fees are collected from a position in a liquidity pool.
24#[derive(Debug, Clone)]
25pub struct CollectEvent {
26 /// The decentralized exchange where the event happened.
27 pub dex: SharedDex,
28 /// The unique identifier for the pool.
29 pub pool_identifier: PoolIdentifier,
30 /// The block number when the collect occurred.
31 pub block_number: u64,
32 /// The hash of the block containing this event, when the source log reported it.
33 pub block_hash: Option<B256>,
34 /// The unique hash identifier of the transaction containing this event.
35 pub transaction_hash: String,
36 /// The position of this transaction within the block.
37 pub transaction_index: u32,
38 /// The position of this event log within the transaction.
39 pub log_index: u32,
40 /// The owner of the position.
41 pub owner: Address,
42 /// The recipient of the collected fees.
43 pub recipient: Address,
44 /// The lower tick boundary of the position.
45 pub tick_lower: i32,
46 /// The upper tick boundary of the position.
47 pub tick_upper: i32,
48 /// The amount of token0 fees collected.
49 pub amount0: u128,
50 /// The amount of token1 fees collected.
51 pub amount1: u128,
52}
53
54impl CollectEvent {
55 /// Creates a new [`CollectEvent`] instance with the specified parameters.
56 #[must_use]
57 #[expect(clippy::too_many_arguments)]
58 pub fn new(
59 dex: SharedDex,
60 pool_identifier: PoolIdentifier,
61 block_number: u64,
62 block_hash: Option<B256>,
63 transaction_hash: String,
64 transaction_index: u32,
65 log_index: u32,
66 owner: Address,
67 recipient: Address,
68 tick_lower: i32,
69 tick_upper: i32,
70 amount0: u128,
71 amount1: u128,
72 ) -> Self {
73 Self {
74 dex,
75 pool_identifier,
76 block_number,
77 block_hash,
78 transaction_hash,
79 transaction_index,
80 log_index,
81 owner,
82 recipient,
83 tick_lower,
84 tick_upper,
85 amount0,
86 amount1,
87 }
88 }
89
90 /// Converts a collect event into a `PoolFeeCollect`.
91 pub fn to_pool_fee_collect(
92 &self,
93 chain: SharedChain,
94 dex: SharedDex,
95 instrument_id: InstrumentId,
96 timestamp: UnixNanos,
97 ) -> PoolFeeCollect {
98 PoolFeeCollect::new(
99 chain,
100 dex,
101 instrument_id,
102 self.pool_identifier,
103 self.block_number,
104 self.transaction_hash.clone(),
105 self.transaction_index,
106 self.log_index,
107 self.owner,
108 self.amount0,
109 self.amount1,
110 self.tick_lower,
111 self.tick_upper,
112 timestamp, // ts_event
113 timestamp, // ts_init (same block timestamp)
114 )
115 }
116}