regit-web3 1.0.1

Modular Web3 primitives for exact values, chain and provider reads, swap quotes, and transaction preparation
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 Regit

//! Exact values, source attribution, and family-specific Web3 identities.
//!
//! All metadata is supplied explicitly. These types do not read configuration,
//! consult a clock, or contact a network. [`Amount`] retains nonnegative integer
//! base units; [`ExactDecimal`] retains signed decimal values without floating
//! point. Both serialize their exact numeric values as strings.
//!
//! Existing address, chain identity, asset, and native-balance types are EVM
//! specific. Their original exports remain available, together with explicitly
//! qualified exports in [`evm`]. EVM addresses and hashes serialize as lowercase,
//! `0x`-prefixed hexadecimal strings; EVM chain identifiers serialize as decimal
//! strings.

mod amount;
mod arithmetic;
pub mod asset_binding;
#[cfg(feature = "bitcoin")]
pub mod bitcoin;
#[cfg(feature = "bitcoin-cash")]
pub mod bitcoin_cash;
#[cfg(feature = "cardano")]
pub mod cardano;
#[cfg(feature = "coingecko")]
pub mod coingecko;
pub mod collections;
mod decimal;
#[cfg(feature = "defillama")]
pub mod defillama;
#[cfg(feature = "dogecoin")]
pub mod dogecoin;
pub mod evm;
#[cfg(feature = "helius")]
pub mod helius;
mod identity;
#[cfg(any(feature = "litecoin", feature = "dogecoin"))]
pub(crate) mod indexed_utxo;
#[cfg(feature = "jupiter")]
pub mod jupiter;
#[cfg(feature = "lifi")]
pub mod lifi;
#[cfg(feature = "litecoin")]
pub mod litecoin;
pub mod market;
#[cfg(feature = "mempool-space")]
pub mod mempool_space;
mod observation;
#[cfg(feature = "oneinch")]
pub mod oneinch;
#[cfg(feature = "rubic")]
pub mod rubic;
#[cfg(feature = "solana")]
pub mod solana;
#[cfg(feature = "thorchain")]
pub mod thorchain;
#[cfg(feature = "ton")]
pub mod ton;
#[cfg(feature = "uniswap")]
pub mod uniswap;
#[cfg(feature = "xrpl")]
pub mod xrpl;

pub use amount::Amount;
pub use arithmetic::{ArithmeticError, RoundingMode};
pub use decimal::ExactDecimal;
pub use identity::{Address, Asset, AssetId, AssetKind, ChainId, MetadataOrigin, NetworkId};
pub use observation::{
    Balance, BlockContext, BlockHash, BlockSelector, Finality, Observation, ObservationContext,
    Operation, Source, Timestamp,
};
/// The maintained 256-bit unsigned integer used for exact EVM values.
pub use ruint::aliases::U256;

use serde::{Deserialize, Deserializer};

fn deserialize_optional<'de, D, T>(deserializer: D) -> Result<Option<T>, D::Error>
where
    D: Deserializer<'de>,
    T: Deserialize<'de>,
{
    Option::deserialize(deserializer)
}

fn valid_label(value: &str, maximum: usize) -> bool {
    !value.is_empty()
        && value.len() <= maximum
        && value
            .bytes()
            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.' | b'+'))
}