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