pub mod hook_handler;
pub mod hook_handler_creator;
use alloy::primitives::U256;
use tycho_common::Bytes;
use crate::protocol::errors::InvalidSnapshotError;
pub const START_TIMESTAMP_ATTRIBUTE: &str = "alpha_start_timestamp";
pub fn decode_start_timestamp(raw: &Bytes) -> Result<u64, InvalidSnapshotError> {
let trimmed = raw
.iter()
.position(|byte| *byte != 0)
.map_or_else(|| &raw[raw.len()..], |first| &raw[first..]);
if trimmed.len() > 32 {
return Err(InvalidSnapshotError::ValueError(format!(
"{START_TIMESTAMP_ATTRIBUTE} is {} bytes (0x{}), wider than the uint256 it encodes",
raw.len(),
hex::encode(raw)
)));
}
Ok(u64::try_from(U256::from_be_slice(trimmed)).unwrap_or(u64::MAX))
}