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    types::Quantity,
22};
23
24/// Represents a mint event that occurs when liquidity is added to a position in a liquidity pool.
25#[derive(Debug, Clone)]
26pub struct MintEvent {
27    /// The decentralized exchange where the event happened.
28    pub dex: SharedDex,
29    /// The address of the smart contract which emitted the event.
30    pub pool_address: Address,
31    /// The block number when the mint occurred.
32    pub block_number: u64,
33    /// The unique hash identifier of the transaction containing this event.
34    pub transaction_hash: String,
35    /// The position of this transaction within the block.
36    pub transaction_index: u32,
37    /// The position of this event log within the transaction.
38    pub log_index: u32,
39    /// The address that sent the transaction.
40    pub sender: Address,
41    /// The owner of the position.
42    pub owner: Address,
43    /// The lower tick boundary of the position.
44    pub tick_lower: i32,
45    /// The upper tick boundary of the position.
46    pub tick_upper: i32,
47    /// The amount of liquidity minted.
48    pub amount: u128,
49    /// The amount of token0 deposited.
50    pub amount0: U256,
51    /// The amount of token1 deposited.
52    pub amount1: U256,
53}
54
55impl MintEvent {
56    /// Creates a new [`MintEvent`] instance with the specified parameters.
57    #[must_use]
58    #[allow(clippy::too_many_arguments)]
59    pub const fn new(
60        dex: SharedDex,
61        pool_address: Address,
62        block_number: u64,
63        transaction_hash: String,
64        transaction_index: u32,
65        log_index: u32,
66        sender: Address,
67        owner: Address,
68        tick_lower: i32,
69        tick_upper: i32,
70        amount: u128,
71        amount0: U256,
72        amount1: U256,
73    ) -> Self {
74        Self {
75            dex,
76            pool_address,
77            block_number,
78            transaction_hash,
79            transaction_index,
80            log_index,
81            sender,
82            owner,
83            tick_lower,
84            tick_upper,
85            amount,
86            amount0,
87            amount1,
88        }
89    }
90
91    /// Converts a mint event into a `PoolLiquidityUpdate`.
92    #[allow(clippy::too_many_arguments)]
93    #[must_use]
94    pub fn to_pool_liquidity_update(
95        &self,
96        chain: SharedChain,
97        dex: SharedDex,
98        instrument_id: InstrumentId,
99        pool_address: Address,
100        liquidity: Quantity,
101        amount0: Quantity,
102        amount1: Quantity,
103        timestamp: Option<UnixNanos>,
104    ) -> PoolLiquidityUpdate {
105        PoolLiquidityUpdate::new(
106            chain,
107            dex,
108            instrument_id,
109            pool_address,
110            PoolLiquidityUpdateType::Mint,
111            self.block_number,
112            self.transaction_hash.clone(),
113            self.transaction_index,
114            self.log_index,
115            Some(self.sender),
116            self.owner,
117            liquidity,
118            amount0,
119            amount1,
120            self.tick_lower,
121            self.tick_upper,
122            timestamp,
123        )
124    }
125}