From cb8accd3547391c7e9793c1dd566d75984ca0298 Mon Sep 17 00:00:00 2001 From: Martin Beckmann Date: Fri, 3 Nov 2023 16:55:18 +0100 Subject: [PATCH] Migrate to 1Inch dev portal (#2029) # Description 1Inch requested all integrations to move to their new 1Inch dev portal (similar to what 0x did not too long ago). # Changes This basically just needs 3 changes: 1. change base URL 2. add some prefix path in the url (in our case all APIs belong to the `/swap` group) 3. add the `Authorization: Bearer API_KEY` header to all requests (happens in https://github.com/cowprotocol/infrastructure/pull/828) ## How to test Did a manual test running all the ignored `oneinch_api` tests which do actual requests to the API (note that this needed a slight modification to the code adding the `Authorization` header. Screenshot 2023-10-31 at 19 52 47 --- crates/shared/src/arguments.rs | 2 +- crates/shared/src/oneinch_api.rs | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/crates/shared/src/arguments.rs b/crates/shared/src/arguments.rs index 4549a3b77e..9dc63df69e 100644 --- a/crates/shared/src/arguments.rs +++ b/crates/shared/src/arguments.rs @@ -269,7 +269,7 @@ pub struct Arguments { pub disabled_one_inch_protocols: Vec, /// The 1Inch REST API URL to use. - #[structopt(long, env, default_value = "https://api.1inch.io/")] + #[structopt(long, env, default_value = "https://api.1inch.dev/")] pub one_inch_url: Url, /// Which address should receive the rewards for referring trades to 1Inch. diff --git a/crates/shared/src/oneinch_api.rs b/crates/shared/src/oneinch_api.rs index 9453ce43ab..6bcd85665a 100644 --- a/crates/shared/src/oneinch_api.rs +++ b/crates/shared/src/oneinch_api.rs @@ -96,7 +96,7 @@ fn addr2str(addr: H160) -> String { impl SellOrderQuoteQuery { fn into_url(self, base_url: &Url, chain_id: u64) -> Url { - let endpoint = format!("v5.0/{chain_id}/quote"); + let endpoint = format!("/swap/v5.0/{chain_id}/quote"); let mut url = crate::url::join(base_url, &endpoint); url.query_pairs_mut() @@ -246,7 +246,7 @@ impl Display for Slippage { impl SwapQuery { /// Encodes the swap query as fn into_url(self, base_url: &Url, chain_id: u64) -> Url { - let endpoint = format!("v5.0/{chain_id}/swap"); + let endpoint = format!("/swap/v5.0/{chain_id}/swap"); let mut url = crate::url::join(base_url, &endpoint); url.query_pairs_mut() .append_pair("fromTokenAddress", &addr2str(self.quote.from_token_address)) @@ -502,7 +502,7 @@ pub struct OneInchClientImpl { } impl OneInchClientImpl { - pub const DEFAULT_URL: &'static str = "https://api.1inch.io/"; + pub const DEFAULT_URL: &'static str = "https://api.1inch.dev/"; // 1: mainnet, 100: gnosis chain pub const SUPPORTED_CHAINS: &'static [u64] = &[1, 100]; @@ -570,13 +570,13 @@ impl OneInchClient for OneInchClientImpl { } async fn get_spender(&self) -> Result { - let endpoint = format!("v5.0/{}/approve/spender", self.chain_id); + let endpoint = format!("/swap/v5.0/{}/approve/spender", self.chain_id); let url = crate::url::join(&self.base_url, &endpoint); logged_query(&self.client, url, None).await } async fn get_liquidity_sources(&self) -> Result { - let endpoint = format!("v5.0/{}/liquidity-sources", self.chain_id); + let endpoint = format!("/swap/v5.0/{}/liquidity-sources", self.chain_id); let url = crate::url::join(&self.base_url, &endpoint); logged_query(&self.client, url, None).await } @@ -750,7 +750,7 @@ mod tests { #[test] fn swap_query_serialization() { - let base_url = Url::parse("https://api.1inch.io/").unwrap(); + let base_url = Url::parse("https://api.1inch.dev/").unwrap(); let url = SwapQuery { from_address: addr!("00000000219ab540356cBB839Cbe05303d7705Fa"), slippage: Slippage::percentage(0.5).unwrap(), @@ -777,7 +777,7 @@ mod tests { assert_eq!( url.as_str(), - "https://api.1inch.io/v5.0/1/swap\ + "https://api.1inch.dev/swap/v5.0/1/swap\ ?fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\ &toTokenAddress=0x111111111117dc0aa78b770fa6a738034120c302\ &amount=1000000000000000000\ @@ -788,7 +788,7 @@ mod tests { #[test] fn swap_query_serialization_options_parameters() { - let base_url = Url::parse("https://api.1inch.io/").unwrap(); + let base_url = Url::parse("https://api.1inch.dev/").unwrap(); let url = SwapQuery { from_address: addr!("00000000219ab540356cBB839Cbe05303d7705Fa"), slippage: Slippage::percentage(0.5).unwrap(), @@ -818,7 +818,7 @@ mod tests { assert_eq!( url.as_str(), - "https://api.1inch.io/v5.0/1/swap\ + "https://api.1inch.dev/swap/v5.0/1/swap\ ?fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\ &toTokenAddress=0x111111111117dc0aa78b770fa6a738034120c302\ &amount=1000000000000000000\ @@ -1055,7 +1055,7 @@ mod tests { #[test] fn sell_order_quote_query_serialization() { - let base_url = Url::parse("https://api.1inch.io/").unwrap(); + let base_url = Url::parse("https://api.1inch.dev/").unwrap(); let url = SellOrderQuoteQuery { from_token_address: addr!("EeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), to_token_address: addr!("111111111117dc0aa78b770fa6a738034120c302"), @@ -1074,7 +1074,7 @@ mod tests { assert_eq!( url.as_str(), - "https://api.1inch.io/v5.0/1/quote\ + "https://api.1inch.dev/swap/v5.0/1/quote\ ?fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\ &toTokenAddress=0x111111111117dc0aa78b770fa6a738034120c302\ &amount=1000000000000000000" @@ -1083,7 +1083,7 @@ mod tests { #[test] fn sell_order_quote_query_serialization_optional_parameters() { - let base_url = Url::parse("https://api.1inch.io/").unwrap(); + let base_url = Url::parse("https://api.1inch.dev/").unwrap(); let url = SellOrderQuoteQuery { from_token_address: addr!("EeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"), to_token_address: addr!("111111111117dc0aa78b770fa6a738034120c302"), @@ -1105,7 +1105,7 @@ mod tests { assert_eq!( url.as_str(), - "https://api.1inch.io/v5.0/1/quote\ + "https://api.1inch.dev/swap/v5.0/1/quote\ ?fromTokenAddress=0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee\ &toTokenAddress=0x111111111117dc0aa78b770fa6a738034120c302\ &amount=1000000000000000000\