1use alloy_primitives::{Address, U256};
2
3use arb_primitives::{multigas::MultiGas, tx_types::ArbTxType};
4
5#[derive(Debug, Clone)]
7pub struct StartTxContext {
8 pub sender: Address,
9 pub to: Option<Address>,
10 pub nonce: u64,
11 pub gas_limit: u64,
12 pub gas_price: U256,
13 pub value: U256,
14 pub data: Vec<u8>,
15 pub tx_type: ArbTxType,
16 pub is_gas_estimation: bool,
17}
18
19#[derive(Debug, Clone)]
21pub struct GasChargingContext {
22 pub sender: Address,
23 pub poster_address: Address,
24 pub gas_limit: u64,
25 pub intrinsic_gas: u64,
26 pub gas_price: U256,
27 pub base_fee: U256,
28 pub tx_type: ArbTxType,
29 pub poster_cost: U256,
32 pub calldata_units: u64,
34}
35
36#[derive(Debug, Clone, Default)]
38pub struct GasChargingResult {
39 pub poster_cost: U256,
40 pub poster_gas: u64,
41 pub compute_hold_gas: u64,
42 pub calldata_units: u64,
44 pub multi_gas: MultiGas,
46}
47
48#[derive(Debug, Clone)]
50pub struct EndTxContext {
51 pub sender: Address,
52 pub gas_left: u64,
53 pub gas_used: u64,
54 pub gas_price: U256,
55 pub base_fee: U256,
56 pub tx_type: ArbTxType,
57 pub success: bool,
58 pub refund_to: Address,
59}
60
61pub trait ArbOsHooks {
67 type Error: core::fmt::Debug;
68
69 fn start_tx(&mut self, ctx: &StartTxContext) -> Result<(), Self::Error>;
72
73 fn gas_charging(&mut self, ctx: &GasChargingContext) -> Result<GasChargingResult, Self::Error>;
76
77 fn end_tx(&mut self, ctx: &EndTxContext) -> Result<(), Self::Error>;
80
81 fn nonrefundable_gas(&self) -> u64;
83
84 fn held_gas(&self) -> u64;
86
87 fn scheduled_txs(&mut self) -> Vec<Vec<u8>>;
89
90 fn drop_tip(&self) -> bool;
92
93 fn gas_price_op(&self, gas_price: U256, base_fee: U256) -> U256;
95
96 fn msg_is_non_mutating(&self) -> bool;
98
99 fn is_calldata_pricing_increase_enabled(&self) -> bool;
101}
102
103pub struct NoopArbOsHooks;
105
106impl ArbOsHooks for NoopArbOsHooks {
107 type Error = ();
108
109 fn start_tx(&mut self, _ctx: &StartTxContext) -> Result<(), ()> {
110 Ok(())
111 }
112
113 fn gas_charging(&mut self, _ctx: &GasChargingContext) -> Result<GasChargingResult, ()> {
114 Ok(GasChargingResult::default())
115 }
116
117 fn end_tx(&mut self, _ctx: &EndTxContext) -> Result<(), ()> {
118 Ok(())
119 }
120
121 fn nonrefundable_gas(&self) -> u64 {
122 0
123 }
124
125 fn held_gas(&self) -> u64 {
126 0
127 }
128
129 fn scheduled_txs(&mut self) -> Vec<Vec<u8>> {
130 vec![]
131 }
132
133 fn drop_tip(&self) -> bool {
134 false
135 }
136
137 fn gas_price_op(&self, gas_price: U256, _base_fee: U256) -> U256 {
138 gas_price
139 }
140
141 fn msg_is_non_mutating(&self) -> bool {
142 false
143 }
144
145 fn is_calldata_pricing_increase_enabled(&self) -> bool {
146 true
147 }
148}