use alloy::primitives::Address;
use alloy::providers::MULTICALL3_ADDRESS;
fn get_custom_multicall_address(chain_id: u64) -> Option<Address> {
match chain_id {
50 => Some(
"0x0c9A8dB3B6C58bC02b8473167b0062b543F3ED7f"
.parse()
.unwrap(),
),
_ => None,
}
}
pub fn resolve_multicall_address(chain_id: u64, override_address: Option<Address>) -> Address {
override_address
.or_else(|| get_custom_multicall_address(chain_id))
.unwrap_or(MULTICALL3_ADDRESS)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_override_takes_priority() {
let custom: Address = "0x0000000000000000000000000000000000000001"
.parse()
.unwrap();
assert_eq!(resolve_multicall_address(1, Some(custom)), custom);
}
#[test]
fn test_falls_back_to_multicall3() {
assert_eq!(resolve_multicall_address(1, None), MULTICALL3_ADDRESS);
}
}