nautilus_blockchain/events/mint.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, U256};
17use nautilus_core::UnixNanos;
18use nautilus_model::{
19 defi::{PoolIdentifier, PoolLiquidityUpdate, PoolLiquidityUpdateType, SharedChain, SharedDex},
20 identifiers::InstrumentId,
21};
22
23/// Represents a mint event that occurs when liquidity is added to a position in a liquidity pool.
24#[derive(Debug, Clone)]
25pub struct MintEvent {
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 mint 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 address that sent the transaction.
39 pub sender: Address,
40 /// The owner of the position.
41 pub owner: 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 liquidity minted.
47 pub amount: u128,
48 /// The amount of token0 deposited.
49 pub amount0: U256,
50 /// The amount of token1 deposited.
51 pub amount1: U256,
52}
53
54impl MintEvent {
55 /// Creates a new [`MintEvent`] instance with the specified parameters.
56 #[must_use]
57 #[allow(clippy::too_many_arguments)]
58 pub fn new(
59 dex: SharedDex,
60 pool_identifier: PoolIdentifier,
61 block_number: u64,
62 transaction_hash: String,
63 transaction_index: u32,
64 log_index: u32,
65 sender: Address,
66 owner: Address,
67 tick_lower: i32,
68 tick_upper: i32,
69 amount: u128,
70 amount0: U256,
71 amount1: U256,
72 ) -> Self {
73 Self {
74 dex,
75 pool_identifier,
76 block_number,
77 transaction_hash,
78 transaction_index,
79 log_index,
80 sender,
81 owner,
82 tick_lower,
83 tick_upper,
84 amount,
85 amount0,
86 amount1,
87 }
88 }
89
90 /// Converts a mint event into a `PoolLiquidityUpdate`.
91 #[allow(clippy::too_many_arguments)]
92 #[must_use]
93 pub fn to_pool_liquidity_update(
94 &self,
95 chain: SharedChain,
96 dex: SharedDex,
97 instrument_id: InstrumentId,
98 timestamp: Option<UnixNanos>,
99 ) -> PoolLiquidityUpdate {
100 PoolLiquidityUpdate::new(
101 chain,
102 dex,
103 instrument_id,
104 self.pool_identifier,
105 PoolLiquidityUpdateType::Mint,
106 self.block_number,
107 self.transaction_hash.clone(),
108 self.transaction_index,
109 self.log_index,
110 Some(self.sender),
111 self.owner,
112 self.amount,
113 self.amount0,
114 self.amount1,
115 self.tick_lower,
116 self.tick_upper,
117 timestamp,
118 )
119 }
120}