nautilus_blockchain/events/
burn.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 burn event that occurs when liquidity is removed from a position in a liquidity pool.
25#[derive(Debug, Clone)]
26pub struct BurnEvent {
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 burn 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 owner of the position.
40    pub owner: Address,
41    /// The lower tick boundary of the position.
42    pub tick_lower: i32,
43    /// The upper tick boundary of the position.
44    pub tick_upper: i32,
45    /// The amount of liquidity burned to the position range.
46    pub amount: u128,
47    /// The amount of token0 withdrawn.
48    pub amount0: U256,
49    /// The amount of token1 withdrawn.
50    pub amount1: U256,
51}
52
53impl BurnEvent {
54    /// Creates a new [`BurnEvent`] instance with the specified parameters.
55    #[must_use]
56    #[allow(clippy::too_many_arguments)]
57    pub const fn new(
58        dex: SharedDex,
59        pool_address: Address,
60        block_number: u64,
61        transaction_hash: String,
62        transaction_index: u32,
63        log_index: u32,
64        owner: Address,
65        tick_lower: i32,
66        tick_upper: i32,
67        amount: u128,
68        amount0: U256,
69        amount1: U256,
70    ) -> Self {
71        Self {
72            dex,
73            pool_address,
74            block_number,
75            transaction_hash,
76            transaction_index,
77            log_index,
78            owner,
79            tick_lower,
80            tick_upper,
81            amount,
82            amount0,
83            amount1,
84        }
85    }
86
87    /// Converts a burn event into a `PoolLiquidityUpdate`.
88    #[allow(clippy::too_many_arguments)]
89    #[must_use]
90    pub fn to_pool_liquidity_update(
91        &self,
92        chain: SharedChain,
93        dex: SharedDex,
94        instrument_id: InstrumentId,
95        pool_address: Address,
96        liquidity: Quantity,
97        amount0: Quantity,
98        amount1: Quantity,
99        timestamp: Option<UnixNanos>,
100    ) -> PoolLiquidityUpdate {
101        PoolLiquidityUpdate::new(
102            chain,
103            dex,
104            instrument_id,
105            pool_address,
106            PoolLiquidityUpdateType::Burn,
107            self.block_number,
108            self.transaction_hash.clone(),
109            self.transaction_index,
110            self.log_index,
111            None,
112            self.owner,
113            liquidity,
114            amount0,
115            amount1,
116            self.tick_lower,
117            self.tick_upper,
118            timestamp,
119        )
120    }
121}