Crate usdshe

Crate usdshe 

Source
Expand description

§usdshe

usdshe is a utility crate for conveniently accessing USDC (USD Coin) contract addresses on various blockchain networks.

It provides a simple trait, Usdc, which can be implemented for different chain identifiers to retrieve the respective USDC contract address. Currently, an implementation for alloy_chains::NamedChain is provided.

§Examples

use usdshe::{Usdc, UsdcError};
use alloy_chains::NamedChain;
use alloy_primitives::Address;
use std::str::FromStr;

// Get Mainnet USDC address
match NamedChain::Mainnet.usdc_address() {
    Ok(address) => {
        assert_eq!(
            address,
            Address::from_str("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48").unwrap()
        );
        println!("Mainnet USDC Address: {}", address);
    }
    Err(e) => eprintln!("Error fetching Mainnet USDC: {}", e),
}

// Attempt to get USDC address for an unsupported chain
// Assuming Kovan is not in the supported list for this example.
// Replace with a NamedChain variant that is genuinely not in your match statement
// if Kovan (or another example) gets added.
// For instance, if `NamedChain::Gnosis` is unsupported:
let some_unsupported_chain = NamedChain::Gnosis; // Example
match some_unsupported_chain.usdc_address() {
    Ok(address) => panic!("Should not find address for {:?}", some_unsupported_chain),
    Err(UsdcError::UnsupportedChain(chain)) => {
        assert_eq!(chain, some_unsupported_chain);
        eprintln!("Correctly failed for unsupported chain: {:?}", chain);
    }
    Err(e) => panic!("Unexpected error: {}", e),
}

Enums§

UsdcError
Represents errors that can occur when retrieving a USDC address.

Constants§

ARBITRUM_SEPOLIA_USDC
https://sepolia.arbiscan.io/address/0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d
ARBITRUM_USDC
https://arbiscan.io/address/0xaf88d065e77c8cc2239327c5edb3a432268e5831
AVALANCHE_USDC
https://debank.com/token/avax/0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e/overview
BASE_SEPOLIA_USDC
https://base-sepolia.blockscout.com/address/0x036CbD53842c5426634e7929541eC2318f3dCF7e
BASE_USDC
https://basescan.org/address/0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
BERACHAIN_USDC
https://berascan.com/address/0x549943e04f40284185054145c6E4e9568C1D3241
BSC_USDC
https://bscscan.com/address/0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d
ETHEREUM_SEPOLIA_USDC
https://sepolia.etherscan.io/address/0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238
ETHEREUM_USDC
FANTOM_USDC
https://www.oklink.com/fantom/token/0x04068da6c83afcfa0e13ba15a6696662335d5b75
FRAXTAL_USDC
<0xDcc0F2D8F90FDe85b10aC1c8Ab57dc0AE946A543>
LINEA_USDC
MANTLE_USDC
http://mantlescan.xyz/token/0x09bc4e0d864854c6afb6eb9a9cdf58ac190d0df9
MODE_USDC
https://explorer.mode.network/token/0xd988097fb8612cc24eeC14542bC03424c656005f
OPTIMISM_USDC
POLYGON_USDC
SCROLL_USDC
https://scrollscan.com/address/0x06efdbff2a14a7c8e15944d1f4a48f9f95f663a4
SONIC_USDC
UNICHAIN_USDC
USDC on Unichain: https://uniscan.xyz/address/0x078d782b760474a361dda0af3839290b0ef57ad6
ZKSYNC_USDC

Traits§

Usdc
A trait for types that can provide a USDC contract address.