Skip to main content

Crate yldfi_common

Crate yldfi_common 

Source
Expand description

§yldfi-common

Shared utilities for yldfi-rs API clients.

§Modules

  • retry - Retry utilities with exponential backoff
  • eth - Ethereum address and transaction hash validation
  • chains - EVM chain ID and name mappings
  • units - Wei/Gwei/Ether conversion utilities

§Retry Utilities

use yldfi_common::{with_retry, RetryConfig, RetryableError};

// Implement RetryableError for your error type
struct MyError;
impl RetryableError for MyError {
    fn is_retryable(&self) -> bool { true }
}

async fn example() {
    let config = RetryConfig::default();
    let result = with_retry(&config, || async {
        Ok::<_, MyError>("success")
    }).await;
}

§Ethereum Utilities

use yldfi_common::eth::{is_valid_address, normalize_address, is_valid_tx_hash};

assert!(is_valid_address("0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045"));
assert_eq!(
    normalize_address("0xABC123..."),
    None // Invalid length
);

§Chain Mappings

use yldfi_common::chains::Chain;

let chain = Chain::from_id(1);
assert_eq!(chain, Chain::Ethereum);
assert_eq!(chain.name(), "ethereum");
assert_eq!(chain.native_currency(), "ETH");

§Unit Conversions

use yldfi_common::units::{to_wei, from_wei, parse_units, format_units};

// Convert 1.5 ETH to wei
let wei = to_wei("1.5", 18).unwrap();
assert_eq!(wei, "1500000000000000000");

// Convert wei back to ETH
let eth = from_wei("1500000000000000000", 18);
assert_eq!(eth, "1.5");

Re-exports§

pub use retry::with_retry;
pub use retry::with_simple_retry;
pub use retry::RetryConfig;
pub use retry::RetryError;
pub use retry::RetryableError;
pub use http::build_client;
pub use http::build_client_with_proxy;
pub use http::build_default_client;
pub use http::HttpClientConfig;
pub use http::HttpError;
pub use eth::is_valid_address;
pub use eth::is_valid_tx_hash;
pub use eth::normalize_address;
pub use eth::Address;
pub use eth::AddressParseError;
pub use eth::HttpStatusKind;
pub use eth::TxHash;
pub use eth::TxHashParseError;
pub use chains::Chain;
pub use api::extract_retry_after;
pub use api::handle_error_response;
pub use api::ApiConfig;
pub use api::ApiError;
pub use api::ApiResult;
pub use api::BaseClient;
pub use api::ConfigValidationError;
pub use api::NoDomainError;
pub use api::SecretApiKey;
pub use units::Wei;
pub use units::WeiParseError;

Modules§

api
Generic API client infrastructure
chains
Chain ID and name mappings for EVM-compatible networks
eth
Ethereum utilities for address and transaction hash validation
http
HTTP client utilities with proxy support
rate_limit
Client-side rate limiting utilities (SEC-008 fix)
retry
Retry utilities with exponential backoff
units
Wei/Gwei/Ether conversion utilities