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::{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 address of the smart contract which emitted the event.
29    pub pool_address: Address,
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 const fn new(
59        dex: SharedDex,
60        pool_address: Address,
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_address,
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        pool_address: Address,
99        timestamp: Option<UnixNanos>,
100    ) -> PoolLiquidityUpdate {
101        PoolLiquidityUpdate::new(
102            chain,
103            dex,
104            instrument_id,
105            pool_address,
106            PoolLiquidityUpdateType::Mint,
107            self.block_number,
108            self.transaction_hash.clone(),
109            self.transaction_index,
110            self.log_index,
111            Some(self.sender),
112            self.owner,
113            self.amount,
114            self.amount0,
115            self.amount1,
116            self.tick_lower,
117            self.tick_upper,
118            timestamp,
119        )
120    }
121}