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