use std::sync::LazyLock;
use r402::chain::NetworkInfo;
use crate::chain::{Eip155ChainReference, Eip155TokenDeployment, TokenDeploymentEip712};
macro_rules! evm_networks {
($( $name:literal, $ref:literal );* $(;)?) => {
&[ $( NetworkInfo { name: $name, namespace: "eip155", reference: $ref }, )* ]
};
}
macro_rules! evm_token_deployment {
($chain_id:expr, $addr:literal, $dec:literal, eip712: $name:literal / $ver:literal) => {
Eip155TokenDeployment {
chain_reference: Eip155ChainReference::new($chain_id),
address: alloy_primitives::address!($addr),
decimals: $dec,
eip712: Some(TokenDeploymentEip712 {
name: $name.into(),
version: $ver.into(),
}),
}
};
($chain_id:expr, $addr:literal, $dec:literal) => {
Eip155TokenDeployment {
chain_reference: Eip155ChainReference::new($chain_id),
address: alloy_primitives::address!($addr),
decimals: $dec,
eip712: None,
}
};
}
macro_rules! token_accessors {
(
token: $token:ident, lookup: $lookup_fn:ident;
$( $(#[doc = $doc:literal])* $method:ident => $chain_id:expr, $label:literal; )*
) => {
$(
$(#[doc = $doc])*
#[must_use]
pub fn $method() -> &'static Eip155TokenDeployment {
$lookup_fn(Eip155ChainReference::new($chain_id))
.expect(concat!("built-in ", stringify!($token), " deployment for ", $label, " missing"))
}
)*
};
}
pub static EVM_NETWORKS: &[NetworkInfo] = evm_networks![
"ethereum", "1";
"ethereum-sepolia", "11155111";
"base", "8453";
"base-sepolia", "84532";
"arbitrum", "42161";
"arbitrum-sepolia", "421614";
"optimism", "10";
"optimism-sepolia", "11155420";
"polygon", "137";
"polygon-amoy", "80002";
"avalanche", "43114";
"avalanche-fuji", "43113";
"celo", "42220";
"celo-sepolia", "11142220";
"sei", "1329";
"sei-testnet", "1328";
"sonic", "146";
"sonic-blaze", "57054";
"unichain", "130";
"unichain-sepolia", "1301";
"world-chain", "480";
"world-chain-sepolia","4801";
"zksync", "324";
"zksync-sepolia", "300";
"linea", "59144";
"linea-sepolia", "59141";
"ink", "57073";
"ink-sepolia", "763373";
"hyperevm", "999";
"hyperevm-testnet", "998";
"monad", "143";
"monad-testnet", "10143";
"plume", "98866";
"plume-testnet", "98867";
"codex", "81224";
"codex-testnet", "812242";
"xdc", "50";
"xdc-apothem", "51";
"xrpl-evm", "1440000";
"peaq", "3338";
"iotex", "4689";
"megaeth", "4326";
];
static USDC_DEPLOYMENTS: LazyLock<Vec<Eip155TokenDeployment>> = LazyLock::new(|| {
vec![
evm_token_deployment!(1, "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(11_155_111, "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238", 6, eip712: "USDC" / "2"),
evm_token_deployment!(8453, "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(84532, "0x036CbD53842c5426634e7929541eC2318f3dCF7e", 6, eip712: "USDC" / "2"),
evm_token_deployment!(42161, "0xaf88d065e77c8cC2239327C5EDb3A432268e5831", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(421_614, "0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d", 6, eip712: "USDC" / "2"),
evm_token_deployment!(10, "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(11_155_420, "0x5fd84259d66Cd46123540766Be93DFE6D43130D7", 6, eip712: "USDC" / "2"),
evm_token_deployment!(137, "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359", 6, eip712: "USDC" / "2"),
evm_token_deployment!(80002, "0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582", 6, eip712: "USDC" / "2"),
evm_token_deployment!(43114, "0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(43113, "0x5425890298aed601595a70AB815c96711a31Bc65", 6, eip712: "USD Coin" / "2"),
evm_token_deployment!(42220, "0xcebA9300f2b948710d2653dD7B07f33A8B32118C", 6, eip712: "USDC" / "2"),
evm_token_deployment!(11_142_220, "0x01C5C0122039549AD1493B8220cABEdD739BC44E", 6, eip712: "USDC" / "2"),
evm_token_deployment!(1329, "0xe15fC38F6D8c56aF07bbCBe3BAf5708A2Bf42392", 6, eip712: "USDC" / "2"),
evm_token_deployment!(1328, "0x4fCF1784B31630811181f670Aea7A7bEF803eaED", 6, eip712: "USDC" / "2"),
evm_token_deployment!(146, "0x29219dd400f2Bf60E5a23d13Be72B486D4038894", 6, eip712: "USDC" / "2"),
evm_token_deployment!(57054, "0xA4879Fed32Ecbef99399e5cbC247E533421C4eC6", 6, eip712: "USDC" / "2"),
evm_token_deployment!(130, "0x078D782b760474a361dDA0AF3839290b0EF57AD6", 6, eip712: "USDC" / "2"),
evm_token_deployment!(1301, "0x31d0220469e10c4E71834a79b1f276d740d3768F", 6, eip712: "USDC" / "2"),
evm_token_deployment!(480, "0x79A02482A880bCe3F13E09da970dC34dB4cD24D1", 6, eip712: "USDC" / "2"),
evm_token_deployment!(4801, "0x66145f38cBAC35Ca6F1Dfb4914dF98F1614aeA88", 6, eip712: "USDC" / "2"),
evm_token_deployment!(324, "0x1d17CBcF0D6D143135aE902365D2E5e2A16538D4", 6, eip712: "USDC" / "2"),
evm_token_deployment!(300, "0xAe045DE5638162fa134807Cb558E15A3F5A7F853", 6, eip712: "USDC" / "2"),
evm_token_deployment!(59144, "0x176211869cA2b568f2A7D4EE941E073a821EE1ff", 6, eip712: "USDC" / "2"),
evm_token_deployment!(59141, "0xFEce4462D57bD51A6A552365A011b95f0E16d9B7", 6, eip712: "USDC" / "2"),
evm_token_deployment!(57073, "0x2D270e6886d130D724215A266106e6832161EAEd", 6, eip712: "USDC" / "2"),
evm_token_deployment!(763_373, "0xFabab97dCE620294D2B0b0e46C68964e326300Ac", 6, eip712: "USDC" / "2"),
evm_token_deployment!(999, "0xb88339CB7199b77E23DB6E890353E22632Ba630f", 6, eip712: "USDC" / "2"),
evm_token_deployment!(998, "0x2B3370eE501B4a559b57D449569354196457D8Ab", 6, eip712: "USDC" / "2"),
evm_token_deployment!(143, "0x754704Bc059F8C67012fEd69BC8A327a5aafb603", 6, eip712: "USDC" / "2"),
evm_token_deployment!(10143, "0x534b2f3A21130d7a60830c2Df862319e593943A3", 6, eip712: "USDC" / "2"),
evm_token_deployment!(98866, "0x222365EF19F7947e5484218551B56bb3965Aa7aF", 6, eip712: "USDC" / "2"),
evm_token_deployment!(98867, "0xcB5f30e335672893c7eb944B374c196392C19D18", 6, eip712: "USDC" / "2"),
evm_token_deployment!(81224, "0xd996633a415985DBd7D6D12f4A4343E31f5037cf", 6, eip712: "USDC" / "2"),
evm_token_deployment!(812_242, "0x6d7f141b6819C2c9CC2f818e6ad549E7Ca090F8f", 6, eip712: "USDC" / "2"),
evm_token_deployment!(50, "0xfA2958CB79b0491CC627c1557F441eF849Ca8eb1", 6, eip712: "USDC" / "2"),
evm_token_deployment!(51, "0xb5AB69F7bBada22B28e79C8FFAECe55eF1c771D4", 6, eip712: "USDC" / "2"),
evm_token_deployment!(1_440_000, "0xDaF4556169c4F3f2231d8ab7BC8772Ddb7D4c84C", 6),
evm_token_deployment!(3338, "0xbbA60da06c2c5424f03f7434542280FCAd453d10", 6, eip712: "USDC" / "2"),
evm_token_deployment!(4689, "0xcdf79194c6c285077a58da47641d4dbe51f63542", 6, eip712: "Bridged USDC" / "2"),
]
});
static USDM_DEPLOYMENTS: LazyLock<Vec<Eip155TokenDeployment>> = LazyLock::new(|| {
vec![
evm_token_deployment!(4326, "0xFAfDdbb3FC7688494971a79cc65DCa3EF82079E7", 18, eip712: "MegaUSD" / "1"),
]
});
#[must_use]
pub fn usdc_evm_deployments() -> &'static [Eip155TokenDeployment] {
&USDC_DEPLOYMENTS
}
#[must_use]
pub fn usdc_evm_deployment(chain: Eip155ChainReference) -> Option<&'static Eip155TokenDeployment> {
USDC_DEPLOYMENTS.iter().find(|d| d.chain_reference == chain)
}
#[must_use]
pub fn usdm_evm_deployments() -> &'static [Eip155TokenDeployment] {
&USDM_DEPLOYMENTS
}
#[must_use]
pub fn usdm_evm_deployment(chain: Eip155ChainReference) -> Option<&'static Eip155TokenDeployment> {
USDM_DEPLOYMENTS.iter().find(|d| d.chain_reference == chain)
}
#[derive(Debug, Clone, Copy)]
#[allow(
clippy::upper_case_acronyms,
reason = "USDC is a well-known token ticker"
)]
pub struct USDC;
#[allow(
clippy::doc_markdown,
clippy::missing_panics_doc,
clippy::expect_used,
reason = "static deployment lookups are infallible for built-in data"
)]
impl USDC {
#[must_use]
pub fn on(chain: Eip155ChainReference) -> Option<&'static Eip155TokenDeployment> {
usdc_evm_deployment(chain)
}
#[must_use]
pub fn all() -> &'static [Eip155TokenDeployment] {
usdc_evm_deployments()
}
token_accessors! {
token: USDC, lookup: usdc_evm_deployment;
ethereum => 1, "Ethereum";
ethereum_sepolia => 11_155_111, "Ethereum Sepolia";
base => 8453, "Base";
base_sepolia => 84532, "Base Sepolia";
arbitrum => 42161, "Arbitrum";
arbitrum_sepolia => 421_614, "Arbitrum Sepolia";
optimism => 10, "Optimism";
optimism_sepolia => 11_155_420, "OP Sepolia";
polygon => 137, "Polygon";
polygon_amoy => 80002, "Polygon Amoy";
avalanche => 43114, "Avalanche";
avalanche_fuji => 43113, "Avalanche Fuji";
celo => 42220, "Celo";
celo_sepolia => 11_142_220, "Celo Sepolia";
sonic => 146, "Sonic";
sonic_blaze => 57054, "Sonic Blaze";
unichain => 130, "Unichain";
unichain_sepolia => 1301, "Unichain Sepolia";
world_chain => 480, "World Chain";
world_chain_sepolia => 4801, "World Chain Sepolia";
zksync => 324, "ZKsync";
zksync_sepolia => 300, "ZKsync Sepolia";
linea => 59144, "Linea";
linea_sepolia => 59141, "Linea Sepolia";
ink => 57073, "Ink";
ink_sepolia => 763_373, "Ink Sepolia";
sei => 1329, "Sei";
sei_testnet => 1328, "Sei testnet";
hyperevm => 999, "HyperEVM";
hyperevm_testnet => 998, "HyperEVM testnet";
monad => 143, "Monad";
monad_testnet => 10143, "Monad testnet";
plume => 98866, "Plume";
plume_testnet => 98867, "Plume testnet";
codex => 81224, "Codex";
codex_testnet => 812_242, "Codex testnet";
xdc => 50, "XDC";
xdc_apothem => 51, "XDC Apothem";
}
}
#[derive(Debug, Clone, Copy)]
#[allow(
clippy::upper_case_acronyms,
reason = "USDM is a well-known token ticker"
)]
pub struct USDM;
#[allow(
clippy::doc_markdown,
clippy::missing_panics_doc,
clippy::expect_used,
reason = "static deployment lookups are infallible for built-in data"
)]
impl USDM {
#[must_use]
pub fn on(chain: Eip155ChainReference) -> Option<&'static Eip155TokenDeployment> {
usdm_evm_deployment(chain)
}
#[must_use]
pub fn all() -> &'static [Eip155TokenDeployment] {
usdm_evm_deployments()
}
token_accessors! {
token: USDM, lookup: usdm_evm_deployment;
megaeth => 4326, "MegaETH";
}
}