odos_sdk/
lib.rs

1//! # Odos SDK
2//!
3//! A production-ready Rust SDK for the Odos protocol - a decentralized exchange aggregator
4//! that provides optimal routing for token swaps across multiple EVM chains.
5//!
6//! ## Features
7//!
8//! - **Multi-chain Support**: 16+ EVM chains including Ethereum, Arbitrum, Optimism, Polygon, Base, etc.
9//! - **Type-safe**: Leverages Rust's type system with Alloy primitives for addresses, chain IDs, and amounts
10//! - **Production-ready**: Built-in retry logic, circuit breakers, timeouts, and error handling
11//! - **Builder Pattern**: Ergonomic API using the `bon` crate for request building
12//! - **Comprehensive Error Handling**: Detailed error types for different failure scenarios
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use odos_sdk::*;
18//! use alloy_primitives::{Address, U256};
19//! use std::str::FromStr;
20//!
21//! # async fn example() -> Result<()> {
22//! // Create a client
23//! let client = OdosSorV2::new()?;
24//!
25//! // Build a quote request
26//! let quote_request = QuoteRequest::builder()
27//!     .chain_id(1) // Ethereum mainnet
28//!     .input_tokens(vec![(
29//!         Address::from_str("0xA0b86a33E6441d35a6b083d5b02a8e3F6CE21a2E")?, // WETH
30//!         U256::from(1000000000000000000u64) // 1 ETH
31//!     ).into()])
32//!     .output_tokens(vec![(
33//!         Address::from_str("0xA0b86a33E6441d35a6b083d5b02a8e3F6CE21a2E")?, // USDC
34//!         1
35//!     ).into()])
36//!     .slippage_limit_percent(1.0)
37//!     .user_addr("0x742d35Cc6634C0532925a3b8D35f3e7a5edD29c0".to_string())
38//!     .compact(false)
39//!     .simple(false)
40//!     .referral_code(0)
41//!     .disable_rfqs(false)
42//!     .build();
43//!
44//! // Get a quote
45//! let quote = client.get_swap_quote(&quote_request).await?;
46//!
47//! // Build transaction data
48//! let swap_context = SwapContext::builder()
49//!     .chain(alloy_chains::NamedChain::Mainnet)
50//!     .router_address(alloy_chains::NamedChain::Mainnet.v2_router_address()?)
51//!     .signer_address(Address::from_str("0x742d35Cc6634C0532925a3b8D35f3e7a5edD29c0")?)
52//!     .output_recipient(Address::from_str("0x742d35Cc6634C0532925a3b8D35f3e7a5edD29c0")?)
53//!     .token_address(Address::from_str("0xA0b86a33E6441d35a6b083d5b02a8e3F6CE21a2E")?)
54//!     .token_amount(U256::from(1000000000000000000u64))
55//!     .path_id(quote.path_id().to_string())
56//!     .build();
57//!
58//! let transaction = client.build_base_transaction(&swap_context).await?;
59//! # Ok(())
60//! # }
61//! ```
62//!
63//! ## Configuration
64//!
65//! The SDK supports extensive configuration for production use:
66//!
67//! ```rust,no_run
68//! use odos_sdk::*;
69//! use std::time::Duration;
70//!
71//! # fn example() -> Result<()> {
72//! let config = ClientConfig {
73//!     timeout: Duration::from_secs(30),
74//!     connect_timeout: Duration::from_secs(10),
75//!     max_retries: 3,
76//!     initial_retry_delay: Duration::from_millis(100),
77//!     max_retry_delay: Duration::from_secs(5),
78//!     max_connections: 20,
79//!     pool_idle_timeout: Duration::from_secs(90),
80//! };
81//!
82//! let client = OdosSorV2::with_config(config)?;
83//! # Ok(())
84//! # }
85//! ```
86//!
87//! ## Error Handling
88//!
89//! The SDK provides comprehensive error types for different failure scenarios:
90//!
91//! ```rust,no_run
92//! use odos_sdk::*;
93//!
94//! # async fn example() {
95//! # let client = OdosSorV2::new().unwrap();
96//! # let quote_request = QuoteRequest::builder().chain_id(1).input_tokens(vec![]).output_tokens(vec![]).slippage_limit_percent(1.0).user_addr("test".to_string()).compact(false).simple(false).referral_code(0).disable_rfqs(false).build();
97//! match client.get_swap_quote(&quote_request).await {
98//!     Ok(quote) => {
99//!         // Handle successful quote
100//!         println!("Got quote with path ID: {}", quote.path_id());
101//!     }
102//!     Err(OdosError::Api { status, message }) => {
103//!         // Handle API errors
104//!         eprintln!("API error {}: {}", status, message);
105//!     }
106//!     Err(OdosError::Timeout(msg)) => {
107//!         // Handle timeout errors (retryable)
108//!         eprintln!("Request timed out: {}", msg);
109//!     }
110//!     Err(OdosError::RateLimit(msg)) => {
111//!         // Handle rate limiting (retryable)
112//!         eprintln!("Rate limited: {}", msg);
113//!     }
114//!     Err(err) => {
115//!         // Handle other errors
116//!         eprintln!("Error: {}", err);
117//!     }
118//! }
119//! # }
120//! ```
121
122mod api;
123mod assemble;
124mod chain;
125mod client;
126mod contract;
127mod error;
128#[cfg(test)]
129mod integration_tests;
130mod limit_order_v2;
131mod sor;
132mod swap;
133mod transfer;
134mod v2_router;
135mod v3_router;
136
137pub use api::*;
138pub use assemble::*;
139pub use chain::*;
140pub use client::*;
141pub use contract::*;
142pub use error::*;
143pub use limit_order_v2::*;
144pub use sor::*;
145pub use swap::*;
146pub use transfer::*;
147pub use v2_router::*;
148pub use v3_router::*;