kabu_types_events/
state_update_event.rs1#![allow(clippy::type_complexity)]
2
3use alloy_consensus::Header;
4use alloy_primitives::TxHash;
5use kabu_types_blockchain::GethStateUpdateVec;
6use kabu_types_market::PoolWrapper;
7use kabu_types_market::SwapDirection;
8use reth_ethereum_primitives::EthPrimitives;
9use reth_node_types::NodePrimitives;
10use revm::DatabaseRef;
11use std::collections::BTreeMap;
12
13#[derive(Clone)]
14pub struct StateUpdateEvent<DB, N: NodePrimitives = EthPrimitives> {
15 pub next_block_number: u64,
16 pub next_block_timestamp: u64,
17 pub next_base_fee: u64,
18 market_state: DB,
19 state_update: GethStateUpdateVec,
20 state_required: Option<GethStateUpdateVec>,
21 directions: BTreeMap<PoolWrapper, Vec<SwapDirection>>,
22 pub stuffing_txs_hashes: Vec<TxHash>,
23 pub stuffing_txs: Vec<N::SignedTx>,
24 pub origin: String,
25 pub tips_pct: u32,
26}
27
28#[allow(clippy::too_many_arguments)]
29impl<DB: DatabaseRef, N: NodePrimitives> StateUpdateEvent<DB, N> {
30 pub fn new(
31 next_block: u64,
32 next_block_timestamp: u64,
33 next_base_fee: u64,
34 market_state: DB,
35 state_update: GethStateUpdateVec,
36 state_required: Option<GethStateUpdateVec>,
37 directions: BTreeMap<PoolWrapper, Vec<SwapDirection>>,
38 stuffing_txs_hashes: Vec<TxHash>,
39 stuffing_txs: Vec<N::SignedTx>,
40 origin: String,
41 tips_pct: u32,
42 ) -> StateUpdateEvent<DB, N> {
43 StateUpdateEvent {
44 next_block_number: next_block,
45 next_block_timestamp,
46 next_base_fee,
47 state_update,
48 state_required,
49 market_state,
50 directions,
51 stuffing_txs_hashes,
52 stuffing_txs,
53 origin,
54 tips_pct,
55 }
56 }
57 pub fn directions(&self) -> &BTreeMap<PoolWrapper, Vec<SwapDirection>> {
58 &self.directions
59 }
60
61 pub fn market_state(&self) -> &DB {
62 &self.market_state
63 }
64
65 pub fn state_update(&self) -> &GethStateUpdateVec {
66 &self.state_update
67 }
68
69 pub fn state_required(&self) -> &Option<GethStateUpdateVec> {
70 &self.state_required
71 }
72
73 pub fn stuffing_len(&self) -> usize {
74 self.stuffing_txs_hashes.len()
75 }
76
77 pub fn stuffing_txs_hashes(&self) -> &Vec<TxHash> {
78 &self.stuffing_txs_hashes
79 }
80 pub fn stuffing_txs(&self) -> &Vec<N::SignedTx> {
81 &self.stuffing_txs
82 }
83
84 pub fn stuffing_tx_hash(&self) -> TxHash {
85 self.stuffing_txs_hashes.first().cloned().unwrap_or_default()
86 }
87}
88
89impl<DB: DatabaseRef, N: NodePrimitives> StateUpdateEvent<DB, N> {
90 pub fn next_header(&self) -> Header {
91 Header { number: self.next_block_number, timestamp: self.next_block_timestamp, ..Default::default() }
92 }
93}