use df_hyperliquid_core::client::evm::BadAmount;
use crate::client::{Call, Fees, Read};
use crate::utils::{Address, Dec, hype};
use crate::{U256, nitro};
const BASE_FEE_TIMES: u64 = 2;
#[must_use]
pub fn fees(base: U256) -> Fees {
Fees { max_priority_fee: U256::ZERO, max_fee: base.saturating_mul(U256::from_u64(BASE_FEE_TIMES)) }
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Estimate {
pub gas: u64,
pub gas_for_l1: u64,
pub base_fee: U256,
pub l1_base_fee: U256,
}
impl Estimate {
#[must_use]
pub const fn gas_for_l2(&self) -> u64 {
self.gas.saturating_sub(self.gas_for_l1)
}
#[must_use]
pub fn cost(&self) -> U256 {
self.base_fee.saturating_mul(U256::from_u64(self.gas))
}
#[must_use]
pub fn cost_for_l1(&self) -> U256 {
self.base_fee.saturating_mul(U256::from_u64(self.gas_for_l1))
}
pub fn hype(&self) -> Result<Dec, BadAmount> {
hype(self.cost())
}
}
#[must_use]
pub fn components(from: Option<Address>, call: &Call) -> Read<Estimate> {
nitro::node::gas_estimate_components(from, call)
}
pub fn most_spent(gas: u64, fees: Fees, value: U256) -> Result<Dec, BadAmount> {
let gas = fees.max_fee.checked_mul(U256::from_u64(gas)).ok_or(BadAmount::TooLarge)?;
hype(gas.checked_add(value).ok_or(BadAmount::TooLarge)?)
}
#[cfg(test)]
#[path = "tests/gas.rs"]
mod tests;