nautilus_blockchain/events/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 alloy::primitives::Address;
17use nautilus_core::UnixNanos;
18use nautilus_model::{
19 defi::{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 address of the smart contract which emitted the event.
29 pub pool_address: Address,
30 /// The block number when the collect occurred.
31 pub block_number: u64,
32 /// The unique hash identifier of the transaction containing this event.
33 pub transaction_hash: String,
34 /// The position of this transaction within the block.
35 pub transaction_index: u32,
36 /// The position of this event log within the transaction.
37 pub log_index: u32,
38 /// The owner of the position.
39 pub owner: Address,
40 /// The recipient of the collected fees.
41 pub recipient: Address,
42 /// The lower tick boundary of the position.
43 pub tick_lower: i32,
44 /// The upper tick boundary of the position.
45 pub tick_upper: i32,
46 /// The amount of token0 fees collected.
47 pub amount0: u128,
48 /// The amount of token1 fees collected.
49 pub amount1: u128,
50}
51
52impl CollectEvent {
53 /// Creates a new [`CollectEvent`] instance with the specified parameters.
54 #[must_use]
55 #[allow(clippy::too_many_arguments)]
56 pub const fn new(
57 dex: SharedDex,
58 pool_address: Address,
59 block_number: u64,
60 transaction_hash: String,
61 transaction_index: u32,
62 log_index: u32,
63 owner: Address,
64 recipient: Address,
65 tick_lower: i32,
66 tick_upper: i32,
67 amount0: u128,
68 amount1: u128,
69 ) -> Self {
70 Self {
71 dex,
72 pool_address,
73 block_number,
74 transaction_hash,
75 transaction_index,
76 log_index,
77 owner,
78 recipient,
79 tick_lower,
80 tick_upper,
81 amount0,
82 amount1,
83 }
84 }
85
86 /// Converts a collect event into a `PoolFeeCollect`.
87 #[allow(clippy::too_many_arguments)]
88 pub fn to_pool_fee_collect(
89 &self,
90 chain: SharedChain,
91 dex: SharedDex,
92 instrument_id: InstrumentId,
93 pool_address: Address,
94 timestamp: Option<UnixNanos>,
95 ) -> PoolFeeCollect {
96 PoolFeeCollect::new(
97 chain,
98 dex,
99 instrument_id,
100 pool_address,
101 self.block_number,
102 self.transaction_hash.clone(),
103 self.transaction_index,
104 self.log_index,
105 self.owner,
106 self.amount0,
107 self.amount1,
108 self.tick_lower,
109 self.tick_upper,
110 timestamp,
111 )
112 }
113}