nautilus_blockchain/events/burn.rs
1// -------------------------------------------------------------------------------------------------
2// Copyright (C) 2015-2026 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, B256, U256};
17use nautilus_core::UnixNanos;
18use nautilus_model::{
19 defi::{PoolIdentifier, 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 unique identifier for the pool.
29 pub pool_identifier: PoolIdentifier,
30 /// The block number when the burn occurred.
31 pub block_number: u64,
32 /// The hash of the block containing this event, when the source log reported it.
33 pub block_hash: Option<B256>,
34 /// The unique hash identifier of the transaction containing this event.
35 pub transaction_hash: String,
36 /// The position of this transaction within the block.
37 pub transaction_index: u32,
38 /// The position of this event log within the transaction.
39 pub log_index: u32,
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 burned to the position range.
47 pub amount: u128,
48 /// The amount of token0 withdrawn.
49 pub amount0: U256,
50 /// The amount of token1 withdrawn.
51 pub amount1: U256,
52}
53
54impl BurnEvent {
55 /// Creates a new [`BurnEvent`] instance with the specified parameters.
56 #[must_use]
57 #[expect(clippy::too_many_arguments)]
58 pub fn new(
59 dex: SharedDex,
60 pool_identifier: PoolIdentifier,
61 block_number: u64,
62 block_hash: Option<B256>,
63 transaction_hash: String,
64 transaction_index: u32,
65 log_index: u32,
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 block_hash,
78 transaction_hash,
79 transaction_index,
80 log_index,
81 owner,
82 tick_lower,
83 tick_upper,
84 amount,
85 amount0,
86 amount1,
87 }
88 }
89
90 /// Converts a burn event into a `PoolLiquidityUpdate`.
91 #[must_use]
92 pub fn to_pool_liquidity_update(
93 &self,
94 chain: SharedChain,
95 dex: SharedDex,
96 instrument_id: InstrumentId,
97 pool_identifier: PoolIdentifier,
98 timestamp: UnixNanos,
99 ) -> PoolLiquidityUpdate {
100 PoolLiquidityUpdate::new(
101 chain,
102 dex,
103 instrument_id,
104 pool_identifier,
105 PoolLiquidityUpdateType::Burn,
106 self.block_number,
107 self.transaction_hash.clone(),
108 self.transaction_index,
109 self.log_index,
110 None,
111 self.owner,
112 self.amount,
113 self.amount0,
114 self.amount1,
115 self.tick_lower,
116 self.tick_upper,
117 timestamp, // ts_event
118 timestamp, // ts_init (same block timestamp)
119 )
120 }
121}