nautilus_blockchain/events/fee_protocol_update.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 nautilus_core::UnixNanos;
17use nautilus_model::{
18 defi::{PoolIdentifier, SharedChain, SharedDex, data::PoolFeeProtocolUpdate},
19 identifiers::InstrumentId,
20};
21
22/// Represents a `SetFeeProtocol` event that changes a pool's protocol-fee configuration.
23///
24/// Only the new per-token denominators are retained; the previous values carried by the event are
25/// not needed to rebuild pool state.
26#[derive(Debug, Clone)]
27pub struct FeeProtocolUpdateEvent {
28 /// The decentralized exchange where the event happened.
29 pub dex: SharedDex,
30 /// The unique identifier for the pool.
31 pub pool_identifier: PoolIdentifier,
32 /// The block number in which this event was included.
33 pub block_number: u64,
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 new protocol-fee denominator for token0.
41 pub fee_protocol0_new: u8,
42 /// The new protocol-fee denominator for token1.
43 pub fee_protocol1_new: u8,
44}
45
46impl FeeProtocolUpdateEvent {
47 /// Creates a new [`FeeProtocolUpdateEvent`] instance with the specified parameters.
48 #[must_use]
49 #[expect(clippy::too_many_arguments)]
50 pub fn new(
51 dex: SharedDex,
52 pool_identifier: PoolIdentifier,
53 block_number: u64,
54 transaction_hash: String,
55 transaction_index: u32,
56 log_index: u32,
57 fee_protocol0_new: u8,
58 fee_protocol1_new: u8,
59 ) -> Self {
60 Self {
61 dex,
62 pool_identifier,
63 block_number,
64 transaction_hash,
65 transaction_index,
66 log_index,
67 fee_protocol0_new,
68 fee_protocol1_new,
69 }
70 }
71
72 /// Converts a fee-protocol update event into a `PoolFeeProtocolUpdate`.
73 #[must_use]
74 pub fn to_pool_fee_protocol_update(
75 &self,
76 chain: SharedChain,
77 instrument_id: InstrumentId,
78 timestamp: UnixNanos,
79 ) -> PoolFeeProtocolUpdate {
80 PoolFeeProtocolUpdate::new(
81 chain,
82 self.dex.clone(),
83 instrument_id,
84 self.pool_identifier,
85 self.block_number,
86 self.transaction_hash.clone(),
87 self.transaction_index,
88 self.log_index,
89 self.fee_protocol0_new,
90 self.fee_protocol1_new,
91 timestamp, // ts_event
92 timestamp, // ts_init (same block timestamp)
93 )
94 }
95}