mod client;
mod error;
pub mod nft;
pub mod portfolio;
pub mod prices;
pub mod token;
pub mod transfers;
pub mod debug;
pub mod simulation;
pub mod trace;
pub mod accounts;
pub mod bundler;
pub mod gasmanager;
pub mod wallet;
pub mod notify;
pub mod beacon;
pub mod solana;
pub use client::{Client, Config, Network};
pub use error::{Error, Result};
pub use yldfi_common::http::HttpClientConfig;
pub use yldfi_common::{with_retry, with_simple_retry, RetryConfig, RetryError, RetryableError};
#[must_use]
pub fn config_for_network(api_key: impl Into<String>, network: Network) -> Config {
Config::new(api_key, network)
}
#[must_use]
pub fn config_eth_mainnet(api_key: impl Into<String>) -> Config {
Config::new(api_key, Network::EthMainnet)
}
impl Client {
pub fn nft(&self) -> nft::NftApi<'_> {
nft::NftApi::new(self)
}
pub fn prices(&self) -> prices::PricesApi<'_> {
prices::PricesApi::new(self)
}
pub fn portfolio(&self) -> portfolio::PortfolioApi<'_> {
portfolio::PortfolioApi::new(self)
}
pub fn token(&self) -> token::TokenApi<'_> {
token::TokenApi::new(self)
}
pub fn transfers(&self) -> transfers::TransfersApi<'_> {
transfers::TransfersApi::new(self)
}
pub fn debug(&self) -> debug::DebugApi<'_> {
debug::DebugApi::new(self)
}
pub fn trace(&self) -> trace::TraceApi<'_> {
trace::TraceApi::new(self)
}
pub fn simulation(&self) -> simulation::SimulationApi<'_> {
simulation::SimulationApi::new(self)
}
pub fn bundler(&self) -> bundler::BundlerApi<'_> {
bundler::BundlerApi::new(self)
}
pub fn gas_manager(&self) -> gasmanager::GasManagerApi<'_> {
gasmanager::GasManagerApi::new(self)
}
pub fn wallet(&self) -> wallet::WalletApi<'_> {
wallet::WalletApi::new(self)
}
pub fn accounts(&self) -> accounts::AccountsApi<'_> {
accounts::AccountsApi::new(self)
}
pub fn notify(&self) -> notify::NotifyApi<'_> {
notify::NotifyApi::new(self)
}
pub fn beacon(&self) -> beacon::BeaconApi<'_> {
beacon::BeaconApi::new(self)
}
pub fn solana(&self) -> solana::SolanaApi<'_> {
solana::SolanaApi::new(self)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_network_slug() {
assert_eq!(Network::EthMainnet.slug(), "eth-mainnet");
assert_eq!(Network::PolygonMainnet.slug(), "polygon-mainnet");
assert_eq!(Network::ArbitrumMainnet.slug(), "arb-mainnet");
assert_eq!(Network::BaseMainnet.slug(), "base-mainnet");
}
#[test]
fn test_client_urls() {
let client = Client::new("test-key", Network::EthMainnet).unwrap();
assert!(client.rpc_url().contains("eth-mainnet"));
assert!(client.rpc_url().contains("test-key"));
assert!(client.nft_url().contains("nft/v3"));
assert!(client.prices_url().contains("prices/v1"));
assert!(client.data_url().contains("data/v1"));
}
#[test]
fn test_asset_transfers_options() {
let opts = transfers::AssetTransfersOptions::from_address("0x123")
.with_metadata()
.exclude_zero_value()
.with_max_count(100);
assert_eq!(opts.from_address, Some("0x123".to_string()));
assert_eq!(opts.with_metadata, Some(true));
assert_eq!(opts.exclude_zero_value, Some(true));
assert_eq!(opts.max_count, Some("0x64".to_string()));
}
#[test]
fn test_all_apis_accessible() {
let client = Client::new("test-key", Network::EthMainnet).unwrap();
let _ = client.nft();
let _ = client.prices();
let _ = client.portfolio();
let _ = client.token();
let _ = client.transfers();
let _ = client.debug();
let _ = client.trace();
let _ = client.simulation();
let _ = client.bundler();
let _ = client.gas_manager();
let _ = client.wallet();
let _ = client.accounts();
let _ = client.notify();
let _ = client.beacon();
let _ = client.solana();
}
}