odos_sdk/
api.rs

1use std::fmt::Display;
2
3use alloy_primitives::{Address, U256};
4use bon::Builder;
5use serde::{Deserialize, Serialize};
6use url::Url;
7
8use crate::{error_code::TraceId, OdosError, Result};
9
10#[cfg(feature = "v2")]
11use {
12    crate::OdosRouterV2::{inputTokenInfo, outputTokenInfo, swapTokenInfo},
13    crate::OdosV2Router::{swapCall, OdosV2RouterCalls},
14    alloy_primitives::Bytes,
15    tracing::debug,
16};
17
18#[cfg(feature = "v3")]
19use {
20    crate::IOdosRouterV3::swapTokenInfo as v3SwapTokenInfo, crate::OdosV3Router::OdosV3RouterCalls,
21};
22
23/// API host tier for the Odos API
24///
25/// Odos provides two API host tiers:
26/// - **Public**: Standard API available to all users at <https://api.odos.xyz>
27/// - **Enterprise**: Premium API with enhanced features at <https://enterprise-api.odos.xyz>
28///
29/// Use in combination with [`ApiVersion`] via the [`Endpoint`] type for complete
30/// endpoint configuration.
31///
32/// # Examples
33///
34/// ```rust
35/// use odos_sdk::{ApiHost, ApiVersion, Endpoint};
36///
37/// // Use directly with Endpoint
38/// let endpoint = Endpoint::new(ApiHost::Public, ApiVersion::V2);
39///
40/// // Or use convenience methods
41/// let endpoint = Endpoint::public_v2();
42/// ```
43#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
44#[serde(rename_all = "lowercase")]
45pub enum ApiHost {
46    /// Public API endpoint <https://docs.odos.xyz/build/api-docs>
47    ///
48    /// Standard API available to all users. Suitable for most use cases.
49    Public,
50    /// Enterprise API endpoint <https://docs.odos.xyz/build/enterprise-api>
51    ///
52    /// Premium API with enhanced features, higher rate limits, and dedicated support.
53    /// Requires an API key obtained through the Odos Enterprise program.
54    Enterprise,
55}
56
57impl ApiHost {
58    /// Get the base URL for the API host
59    ///
60    /// Returns the root URL for the selected host tier without any path segments.
61    ///
62    /// # Examples
63    ///
64    /// ```rust
65    /// use odos_sdk::ApiHost;
66    ///
67    /// let public = ApiHost::Public;
68    /// assert_eq!(public.base_url().as_str(), "https://api.odos.xyz/");
69    ///
70    /// let enterprise = ApiHost::Enterprise;
71    /// assert_eq!(enterprise.base_url().as_str(), "https://enterprise-api.odos.xyz/");
72    /// ```
73    pub fn base_url(&self) -> Url {
74        match self {
75            ApiHost::Public => Url::parse("https://api.odos.xyz/").unwrap(),
76            ApiHost::Enterprise => Url::parse("https://enterprise-api.odos.xyz/").unwrap(),
77        }
78    }
79}
80
81/// Version of the Odos API
82///
83/// Odos provides multiple API versions with different features and response formats:
84/// - **V2**: Stable production version with comprehensive swap routing
85/// - **V3**: Latest version with enhanced features and optimizations
86///
87/// Use in combination with [`ApiHost`] via the [`Endpoint`] type for complete
88/// endpoint configuration.
89///
90/// # Examples
91///
92/// ```rust
93/// use odos_sdk::{ApiHost, ApiVersion, Endpoint};
94///
95/// // Recommended: Use V2 for production
96/// let endpoint = Endpoint::new(ApiHost::Public, ApiVersion::V2);
97///
98/// // Or use V3 for latest features
99/// let endpoint = Endpoint::new(ApiHost::Public, ApiVersion::V3);
100/// ```
101#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
102#[serde(rename_all = "lowercase")]
103pub enum ApiVersion {
104    /// API version 2 - Stable production version
105    ///
106    /// Recommended for most production use cases. Provides comprehensive
107    /// swap routing with extensive DEX coverage.
108    V2,
109    /// API version 3 - Latest version with enhanced features
110    ///
111    /// Includes optimizations and new features. Check the Odos documentation
112    /// for specific enhancements over V2.
113    V3,
114}
115
116impl ApiVersion {
117    /// Get the path segment for this version
118    ///
119    /// Returns the path component to use in API URLs (e.g., "v2", "v3").
120    fn path(&self) -> &'static str {
121        match self {
122            ApiVersion::V2 => "v2",
123            ApiVersion::V3 => "v3",
124        }
125    }
126}
127
128/// Complete API endpoint configuration combining host tier and API version
129///
130/// The `Endpoint` type provides an ergonomic way to configure both the API host
131/// tier (Public/Enterprise) and version (V2/V3) together.
132///
133/// # Examples
134///
135/// ## Using convenience constructors (recommended)
136///
137/// ```rust
138/// use odos_sdk::{ClientConfig, Endpoint};
139///
140/// // Public API V2 (default, recommended for production)
141/// let config = ClientConfig {
142///     endpoint: Endpoint::public_v2(),
143///     ..Default::default()
144/// };
145///
146/// // Enterprise API V3 (latest features)
147/// let config = ClientConfig {
148///     endpoint: Endpoint::enterprise_v3(),
149///     ..Default::default()
150/// };
151/// ```
152///
153/// ## Using explicit construction
154///
155/// ```rust
156/// use odos_sdk::{Endpoint, ApiHost, ApiVersion};
157///
158/// let endpoint = Endpoint::new(ApiHost::Enterprise, ApiVersion::V2);
159/// assert_eq!(endpoint.quote_url().as_str(), "https://enterprise-api.odos.xyz/sor/quote/v2");
160/// ```
161///
162/// ## Migration from old API
163///
164/// ```rust
165/// use odos_sdk::{ClientConfig, Endpoint};
166///
167/// // Old way (still works but deprecated)
168/// // let config = ClientConfig {
169/// //     endpoint: EndpointBase::Public,
170/// //     endpoint_version: EndpointVersion::V2,
171/// //     ..Default::default()
172/// // };
173///
174/// // New way
175/// let config = ClientConfig {
176///     endpoint: Endpoint::public_v2(),
177///     ..Default::default()
178/// };
179/// ```
180#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Deserialize, Serialize)]
181pub struct Endpoint {
182    host: ApiHost,
183    version: ApiVersion,
184}
185
186impl Endpoint {
187    /// Create a new endpoint with specific host and version
188    ///
189    /// # Examples
190    ///
191    /// ```rust
192    /// use odos_sdk::{Endpoint, ApiHost, ApiVersion};
193    ///
194    /// let endpoint = Endpoint::new(ApiHost::Public, ApiVersion::V2);
195    /// ```
196    pub const fn new(host: ApiHost, version: ApiVersion) -> Self {
197        Self { host, version }
198    }
199
200    /// Public API V2 endpoint (default, recommended for production)
201    ///
202    /// This is the recommended configuration for most production use cases.
203    ///
204    /// # Examples
205    ///
206    /// ```rust
207    /// use odos_sdk::Endpoint;
208    ///
209    /// let endpoint = Endpoint::public_v2();
210    /// assert_eq!(endpoint.quote_url().as_str(), "https://api.odos.xyz/sor/quote/v2");
211    /// ```
212    pub const fn public_v2() -> Self {
213        Self::new(ApiHost::Public, ApiVersion::V2)
214    }
215
216    /// Public API V3 endpoint
217    ///
218    /// Use for latest features and optimizations on the public API.
219    ///
220    /// # Examples
221    ///
222    /// ```rust
223    /// use odos_sdk::Endpoint;
224    ///
225    /// let endpoint = Endpoint::public_v3();
226    /// assert_eq!(endpoint.quote_url().as_str(), "https://api.odos.xyz/sor/quote/v3");
227    /// ```
228    pub const fn public_v3() -> Self {
229        Self::new(ApiHost::Public, ApiVersion::V3)
230    }
231
232    /// Enterprise API V2 endpoint
233    ///
234    /// Use for enterprise tier with V2 API. Requires an API key.
235    ///
236    /// # Examples
237    ///
238    /// ```rust
239    /// use odos_sdk::Endpoint;
240    ///
241    /// let endpoint = Endpoint::enterprise_v2();
242    /// assert_eq!(endpoint.quote_url().as_str(), "https://enterprise-api.odos.xyz/sor/quote/v2");
243    /// ```
244    pub const fn enterprise_v2() -> Self {
245        Self::new(ApiHost::Enterprise, ApiVersion::V2)
246    }
247
248    /// Enterprise API V3 endpoint
249    ///
250    /// Use for enterprise tier with latest V3 features. Requires an API key.
251    ///
252    /// # Examples
253    ///
254    /// ```rust
255    /// use odos_sdk::Endpoint;
256    ///
257    /// let endpoint = Endpoint::enterprise_v3();
258    /// assert_eq!(endpoint.quote_url().as_str(), "https://enterprise-api.odos.xyz/sor/quote/v3");
259    /// ```
260    pub const fn enterprise_v3() -> Self {
261        Self::new(ApiHost::Enterprise, ApiVersion::V3)
262    }
263
264    /// Get the quote URL for this endpoint
265    ///
266    /// Constructs the full URL for the quote endpoint by combining the base URL
267    /// with the appropriate version path.
268    ///
269    /// # Examples
270    ///
271    /// ```rust
272    /// use odos_sdk::Endpoint;
273    ///
274    /// let endpoint = Endpoint::public_v2();
275    /// assert_eq!(endpoint.quote_url().as_str(), "https://api.odos.xyz/sor/quote/v2");
276    ///
277    /// let endpoint = Endpoint::enterprise_v3();
278    /// assert_eq!(endpoint.quote_url().as_str(), "https://enterprise-api.odos.xyz/sor/quote/v3");
279    /// ```
280    pub fn quote_url(&self) -> Url {
281        self.host
282            .base_url()
283            .join(&format!("sor/quote/{}", self.version.path()))
284            .unwrap()
285    }
286
287    /// Get the assemble URL for this endpoint
288    ///
289    /// The assemble endpoint is version-independent and constructs transaction data
290    /// from a previously obtained quote path ID.
291    ///
292    /// # Examples
293    ///
294    /// ```rust
295    /// use odos_sdk::Endpoint;
296    ///
297    /// let endpoint = Endpoint::public_v2();
298    /// assert_eq!(endpoint.assemble_url().as_str(), "https://api.odos.xyz/sor/assemble");
299    /// ```
300    pub fn assemble_url(&self) -> Url {
301        self.host.base_url().join("sor/assemble").unwrap()
302    }
303
304    /// Get the API host tier
305    ///
306    /// # Examples
307    ///
308    /// ```rust
309    /// use odos_sdk::{Endpoint, ApiHost};
310    ///
311    /// let endpoint = Endpoint::public_v2();
312    /// assert_eq!(endpoint.host(), ApiHost::Public);
313    /// ```
314    pub const fn host(&self) -> ApiHost {
315        self.host
316    }
317
318    /// Get the API version
319    ///
320    /// # Examples
321    ///
322    /// ```rust
323    /// use odos_sdk::{Endpoint, ApiVersion};
324    ///
325    /// let endpoint = Endpoint::public_v2();
326    /// assert_eq!(endpoint.version(), ApiVersion::V2);
327    /// ```
328    pub const fn version(&self) -> ApiVersion {
329        self.version
330    }
331}
332
333impl Default for Endpoint {
334    /// Returns the default endpoint: Public API V2
335    ///
336    /// This is the recommended configuration for most production use cases.
337    fn default() -> Self {
338        Self::public_v2()
339    }
340}
341
342/// Input token for the Odos quote API
343#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
344#[serde(rename_all = "camelCase")]
345pub struct InputToken {
346    token_address: Address,
347    // Odos API error message: "Input Amount should be positive integer in string form with < 64 digits[0x6]"
348    amount: String,
349}
350
351impl InputToken {
352    pub fn new(token_address: Address, amount: U256) -> Self {
353        Self {
354            token_address,
355            amount: amount.to_string(),
356        }
357    }
358}
359
360impl From<(Address, U256)> for InputToken {
361    fn from((token_address, amount): (Address, U256)) -> Self {
362        Self::new(token_address, amount)
363    }
364}
365
366impl Display for InputToken {
367    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
368        write!(
369            f,
370            "InputToken {{ token_address: {}, amount: {} }}",
371            self.token_address, self.amount
372        )
373    }
374}
375
376/// Output token for the Odos quote API
377#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Deserialize, Serialize)]
378#[serde(rename_all = "camelCase")]
379pub struct OutputToken {
380    token_address: Address,
381    proportion: u32,
382}
383
384impl OutputToken {
385    pub fn new(token_address: Address, proportion: u32) -> Self {
386        Self {
387            token_address,
388            proportion,
389        }
390    }
391}
392
393impl From<(Address, u32)> for OutputToken {
394    fn from((token_address, proportion): (Address, u32)) -> Self {
395        Self::new(token_address, proportion)
396    }
397}
398
399impl Display for OutputToken {
400    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
401        write!(
402            f,
403            "OutputToken {{ token_address: {}, proportion: {} }}",
404            self.token_address, self.proportion
405        )
406    }
407}
408
409/// Request to the Odos quote API: <https://docs.odos.xyz/build/api-docs>
410///
411/// # Using Type-Safe Newtypes
412///
413/// You can use the type-safe [`Slippage`](crate::Slippage), [`Chain`](crate::Chain),
414/// and [`ReferralCode`](crate::ReferralCode) types with their conversion methods:
415///
416/// ```rust
417/// use odos_sdk::{QuoteRequest, Slippage, Chain, ReferralCode};
418/// use alloy_primitives::Address;
419///
420/// let request = QuoteRequest::builder()
421///     .chain_id(Chain::ethereum().id())
422///     .slippage_limit_percent(Slippage::percent(0.5).unwrap().as_percent())
423///     .referral_code(ReferralCode::NONE.code())
424///     // ... other fields
425///     # .input_tokens(vec![])
426///     # .output_tokens(vec![])
427///     # .user_addr(Address::ZERO)
428///     # .compact(false)
429///     # .simple(false)
430///     # .disable_rfqs(false)
431///     .build();
432/// ```
433#[derive(Builder, Clone, Debug, Default, PartialEq, PartialOrd, Deserialize, Serialize)]
434#[serde(rename_all = "camelCase")]
435pub struct QuoteRequest {
436    chain_id: u64,
437    input_tokens: Vec<InputToken>,
438    output_tokens: Vec<OutputToken>,
439    slippage_limit_percent: f64,
440    user_addr: Address,
441    compact: bool,
442    simple: bool,
443    referral_code: u32,
444    disable_rfqs: bool,
445    #[builder(default)]
446    source_blacklist: Vec<String>,
447}
448
449/// Single quote response from the Odos quote API: <https://docs.odos.xyz/build/api-docs>
450#[derive(Clone, Debug, PartialEq, PartialOrd, Deserialize, Serialize)]
451#[serde(rename_all = "camelCase")]
452pub struct SingleQuoteResponse {
453    block_number: u64,
454    data_gas_estimate: u64,
455    gas_estimate: f64,
456    gas_estimate_value: f64,
457    gwei_per_gas: f64,
458    in_amounts: Vec<String>,
459    in_tokens: Vec<Address>,
460    in_values: Vec<f64>,
461    net_out_value: f64,
462    out_amounts: Vec<String>,
463    out_tokens: Vec<Address>,
464    out_values: Vec<f64>,
465    /// Partner fee percentage. Defaults to 0.0 if not present (V3 API compatibility).
466    #[serde(default)]
467    partner_fee_percent: f64,
468    path_id: String,
469    path_viz: Option<String>,
470    percent_diff: f64,
471    price_impact: f64,
472}
473
474impl SingleQuoteResponse {
475    /// Get the data gas estimate of the quote
476    pub fn data_gas_estimate(&self) -> u64 {
477        self.data_gas_estimate
478    }
479
480    /// Get the block number of the quote
481    pub fn get_block_number(&self) -> u64 {
482        self.block_number
483    }
484
485    /// Get the gas estimate of the quote
486    pub fn gas_estimate(&self) -> f64 {
487        self.gas_estimate
488    }
489
490    /// Get the in amounts of the quote
491    pub fn in_amounts_iter(&self) -> impl Iterator<Item = &String> {
492        self.in_amounts.iter()
493    }
494
495    /// Get the in amount of the quote
496    pub fn in_amount_u256(&self) -> Result<U256> {
497        let amount_str = self
498            .in_amounts_iter()
499            .next()
500            .ok_or_else(|| OdosError::missing_data("Missing input amount"))?;
501        let amount: u128 = amount_str
502            .parse()
503            .map_err(|_| OdosError::invalid_input("Invalid input amount format"))?;
504        Ok(U256::from(amount))
505    }
506
507    /// Get the out amount of the quote
508    pub fn out_amount(&self) -> Option<&String> {
509        self.out_amounts.first()
510    }
511
512    /// Get the out amounts of the quote
513    pub fn out_amounts_iter(&self) -> impl Iterator<Item = &String> {
514        self.out_amounts.iter()
515    }
516
517    /// Get the in tokens of the quote
518    pub fn in_tokens_iter(&self) -> impl Iterator<Item = &Address> {
519        self.in_tokens.iter()
520    }
521
522    /// Get the in token of the quote
523    pub fn first_in_token(&self) -> Option<&Address> {
524        self.in_tokens.first()
525    }
526
527    pub fn out_tokens_iter(&self) -> impl Iterator<Item = &Address> {
528        self.out_tokens.iter()
529    }
530
531    /// Get the out token of the quote
532    pub fn first_out_token(&self) -> Option<&Address> {
533        self.out_tokens.first()
534    }
535
536    /// Get the out values of the quote
537    pub fn out_values_iter(&self) -> impl Iterator<Item = &f64> {
538        self.out_values.iter()
539    }
540
541    /// Get the path id of the quote
542    pub fn path_id(&self) -> &str {
543        &self.path_id
544    }
545
546    /// Get the path id as a vector of bytes
547    pub fn path_definition_as_vec_u8(&self) -> Vec<u8> {
548        self.path_id().as_bytes().to_vec()
549    }
550
551    /// Get the swap input token and amount
552    pub fn swap_input_token_and_amount(&self) -> Result<(Address, U256)> {
553        let input_token = *self
554            .in_tokens_iter()
555            .next()
556            .ok_or_else(|| OdosError::missing_data("Missing input token"))?;
557        let input_amount_in_u256 = self.in_amount_u256()?;
558
559        Ok((input_token, input_amount_in_u256))
560    }
561
562    /// Get the price impact of the quote
563    pub fn price_impact(&self) -> f64 {
564        self.price_impact
565    }
566}
567
568/// Error response from the Odos API
569///
570/// When the Odos API returns an error, it includes:
571/// - `detail`: Human-readable error message
572/// - `traceId`: UUID for tracking the error in Odos logs
573/// - `errorCode`: Numeric error code indicating the specific error type
574///
575/// Example error response:
576/// ```json
577/// {
578///   "detail": "Error getting quote, please try again",
579///   "traceId": "10becdc8-a021-4491-8201-a17b657204e0",
580///   "errorCode": 2999
581/// }
582/// ```
583#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
584#[serde(rename_all = "camelCase")]
585pub struct OdosApiErrorResponse {
586    /// Human-readable error message
587    pub detail: String,
588    /// Trace ID for debugging (UUID)
589    pub trace_id: TraceId,
590    /// Numeric error code
591    pub error_code: u16,
592}
593
594/// Swap inputs for the Odos assemble API
595///
596/// Available only when the `v2` feature is enabled.
597#[cfg(feature = "v2")]
598#[derive(Clone, Debug)]
599pub struct SwapInputs {
600    executor: Address,
601    path_definition: Bytes,
602    input_token_info: inputTokenInfo,
603    output_token_info: outputTokenInfo,
604    value_out_min: U256,
605}
606
607#[cfg(feature = "v2")]
608impl TryFrom<OdosV2RouterCalls> for SwapInputs {
609    type Error = OdosError;
610
611    fn try_from(swap: OdosV2RouterCalls) -> std::result::Result<Self, Self::Error> {
612        match swap {
613            OdosV2RouterCalls::swap(call) => {
614                debug!(
615                    swap_type = "V2Router",
616                    input.token = %call.tokenInfo.inputToken,
617                    input.amount_wei = %call.tokenInfo.inputAmount,
618                    output.token = %call.tokenInfo.outputToken,
619                    output.min_wei = %call.tokenInfo.outputMin,
620                    executor = %call.executor,
621                    "Extracting swap inputs from V2 router call"
622                );
623
624                let swapCall {
625                    executor,
626                    pathDefinition,
627                    referralCode,
628                    tokenInfo,
629                } = call;
630
631                let _referral_code = referralCode;
632
633                let swapTokenInfo {
634                    inputToken,
635                    inputAmount,
636                    inputReceiver,
637                    outputMin,
638                    outputQuote,
639                    outputReceiver,
640                    outputToken,
641                } = tokenInfo;
642
643                let _output_quote = outputQuote;
644
645                Ok(Self {
646                    executor,
647                    path_definition: pathDefinition,
648                    input_token_info: inputTokenInfo {
649                        tokenAddress: inputToken,
650                        amountIn: inputAmount,
651                        receiver: inputReceiver,
652                    },
653                    output_token_info: outputTokenInfo {
654                        tokenAddress: outputToken,
655                        relativeValue: U256::from(1),
656                        receiver: outputReceiver,
657                    },
658                    value_out_min: outputMin,
659                })
660            }
661            _ => Err(OdosError::invalid_input("Unexpected OdosV2RouterCalls")),
662        }
663    }
664}
665
666#[cfg(feature = "v3")]
667impl TryFrom<OdosV3RouterCalls> for SwapInputs {
668    type Error = OdosError;
669
670    fn try_from(swap: OdosV3RouterCalls) -> std::result::Result<Self, Self::Error> {
671        match swap {
672            OdosV3RouterCalls::swap(call) => {
673                debug!(
674                    swap_type = "V3Router",
675                    input.token = %call.tokenInfo.inputToken,
676                    input.amount_wei = %call.tokenInfo.inputAmount,
677                    output.token = %call.tokenInfo.outputToken,
678                    output.min_wei = %call.tokenInfo.outputMin,
679                    executor = %call.executor,
680                    "Extracting swap inputs from V3 router call"
681                );
682
683                let v3SwapTokenInfo {
684                    inputToken,
685                    inputAmount,
686                    inputReceiver,
687                    outputMin,
688                    outputQuote,
689                    outputReceiver,
690                    outputToken,
691                } = call.tokenInfo;
692
693                let _output_quote = outputQuote;
694                let _referral_info = call.referralInfo;
695
696                Ok(Self {
697                    executor: call.executor,
698                    path_definition: call.pathDefinition,
699                    input_token_info: inputTokenInfo {
700                        tokenAddress: inputToken,
701                        amountIn: inputAmount,
702                        receiver: inputReceiver,
703                    },
704                    output_token_info: outputTokenInfo {
705                        tokenAddress: outputToken,
706                        relativeValue: U256::from(1),
707                        receiver: outputReceiver,
708                    },
709                    value_out_min: outputMin,
710                })
711            }
712            _ => Err(OdosError::invalid_input("Unexpected OdosV3RouterCalls")),
713        }
714    }
715}
716
717#[cfg(feature = "v2")]
718impl SwapInputs {
719    /// Get the executor of the swap
720    pub fn executor(&self) -> Address {
721        self.executor
722    }
723
724    /// Get the path definition of the swap
725    pub fn path_definition(&self) -> &Bytes {
726        &self.path_definition
727    }
728
729    /// Get the token address of the swap
730    pub fn token_address(&self) -> Address {
731        self.input_token_info.tokenAddress
732    }
733
734    /// Get the amount in of the swap
735    pub fn amount_in(&self) -> U256 {
736        self.input_token_info.amountIn
737    }
738
739    /// Get the receiver of the swap
740    pub fn receiver(&self) -> Address {
741        self.input_token_info.receiver
742    }
743
744    /// Get the relative value of the swap
745    pub fn relative_value(&self) -> U256 {
746        self.output_token_info.relativeValue
747    }
748
749    /// Get the output token address of the swap
750    pub fn output_token_address(&self) -> Address {
751        self.output_token_info.tokenAddress
752    }
753
754    /// Get the value out min of the swap
755    pub fn value_out_min(&self) -> U256 {
756        self.value_out_min
757    }
758}
759
760#[cfg(test)]
761mod tests {
762    use super::*;
763
764    #[test]
765    fn test_api_host_base_url() {
766        assert_eq!(ApiHost::Public.base_url().as_str(), "https://api.odos.xyz/");
767        assert_eq!(
768            ApiHost::Enterprise.base_url().as_str(),
769            "https://enterprise-api.odos.xyz/"
770        );
771    }
772
773    #[test]
774    fn test_api_version_path() {
775        assert_eq!(ApiVersion::V2.path(), "v2");
776        assert_eq!(ApiVersion::V3.path(), "v3");
777    }
778
779    #[test]
780    fn test_endpoint_constructors() {
781        let endpoint = Endpoint::public_v2();
782        assert_eq!(endpoint.host(), ApiHost::Public);
783        assert_eq!(endpoint.version(), ApiVersion::V2);
784
785        let endpoint = Endpoint::public_v3();
786        assert_eq!(endpoint.host(), ApiHost::Public);
787        assert_eq!(endpoint.version(), ApiVersion::V3);
788
789        let endpoint = Endpoint::enterprise_v2();
790        assert_eq!(endpoint.host(), ApiHost::Enterprise);
791        assert_eq!(endpoint.version(), ApiVersion::V2);
792
793        let endpoint = Endpoint::enterprise_v3();
794        assert_eq!(endpoint.host(), ApiHost::Enterprise);
795        assert_eq!(endpoint.version(), ApiVersion::V3);
796
797        let endpoint = Endpoint::new(ApiHost::Public, ApiVersion::V2);
798        assert_eq!(endpoint.host(), ApiHost::Public);
799        assert_eq!(endpoint.version(), ApiVersion::V2);
800    }
801
802    #[test]
803    fn test_endpoint_quote_urls() {
804        assert_eq!(
805            Endpoint::public_v2().quote_url().as_str(),
806            "https://api.odos.xyz/sor/quote/v2"
807        );
808        assert_eq!(
809            Endpoint::public_v3().quote_url().as_str(),
810            "https://api.odos.xyz/sor/quote/v3"
811        );
812        assert_eq!(
813            Endpoint::enterprise_v2().quote_url().as_str(),
814            "https://enterprise-api.odos.xyz/sor/quote/v2"
815        );
816        assert_eq!(
817            Endpoint::enterprise_v3().quote_url().as_str(),
818            "https://enterprise-api.odos.xyz/sor/quote/v3"
819        );
820    }
821
822    #[test]
823    fn test_endpoint_assemble_urls() {
824        assert_eq!(
825            Endpoint::public_v2().assemble_url().as_str(),
826            "https://api.odos.xyz/sor/assemble"
827        );
828        assert_eq!(
829            Endpoint::public_v3().assemble_url().as_str(),
830            "https://api.odos.xyz/sor/assemble"
831        );
832        assert_eq!(
833            Endpoint::enterprise_v2().assemble_url().as_str(),
834            "https://enterprise-api.odos.xyz/sor/assemble"
835        );
836        assert_eq!(
837            Endpoint::enterprise_v3().assemble_url().as_str(),
838            "https://enterprise-api.odos.xyz/sor/assemble"
839        );
840    }
841
842    #[test]
843    fn test_endpoint_default() {
844        let endpoint = Endpoint::default();
845        assert_eq!(endpoint.host(), ApiHost::Public);
846        assert_eq!(endpoint.version(), ApiVersion::V2);
847        assert_eq!(
848            endpoint.quote_url().as_str(),
849            "https://api.odos.xyz/sor/quote/v2"
850        );
851    }
852
853    #[test]
854    fn test_endpoint_equality() {
855        assert_eq!(
856            Endpoint::public_v2(),
857            Endpoint::new(ApiHost::Public, ApiVersion::V2)
858        );
859        assert_eq!(
860            Endpoint::enterprise_v3(),
861            Endpoint::new(ApiHost::Enterprise, ApiVersion::V3)
862        );
863        assert_ne!(Endpoint::public_v2(), Endpoint::public_v3());
864        assert_ne!(Endpoint::public_v2(), Endpoint::enterprise_v2());
865    }
866}