use std::result::Result as StdResult;
pub mod contract;
pub mod constants;
if_providers! {
mod middleware;
pub use middleware::{Call, Multicall, MulticallContract};
pub mod error;
}
#[repr(u8)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord)]
pub enum MulticallVersion {
Multicall = 1,
Multicall2 = 2,
#[default]
Multicall3 = 3,
}
impl From<MulticallVersion> for u8 {
fn from(v: MulticallVersion) -> Self {
v as u8
}
}
impl TryFrom<u8> for MulticallVersion {
type Error = String;
fn try_from(v: u8) -> StdResult<Self, Self::Error> {
match v {
1 => Ok(MulticallVersion::Multicall),
2 => Ok(MulticallVersion::Multicall2),
3 => Ok(MulticallVersion::Multicall3),
_ => Err(format!("Invalid Multicall version: {v}. Accepted values: 1, 2, 3.")),
}
}
}
impl MulticallVersion {
#[inline]
pub fn is_v1(&self) -> bool {
matches!(self, Self::Multicall)
}
#[inline]
pub fn is_v2(&self) -> bool {
matches!(self, Self::Multicall2)
}
#[inline]
pub fn is_v3(&self) -> bool {
matches!(self, Self::Multicall3)
}
}