From 1b287fd71ef30c9f8869cdc4ceeb003149f44b6c Mon Sep 17 00:00:00 2001 From: gemcoder21 <104884878+gemcoder21@users.noreply.github.com> Date: Wed, 13 Nov 2024 20:16:16 +0000 Subject: [PATCH] Add swapper.supported_chains method --- gemstone/src/swapper/mod.rs | 16 +++++++++++++--- gemstone/src/swapper/models.rs | 2 +- gemstone/src/swapper/thorchain/mod.rs | 7 +++---- gemstone/src/swapper/uniswap/mod.rs | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/gemstone/src/swapper/mod.rs b/gemstone/src/swapper/mod.rs index 03db44fe..2cfff028 100644 --- a/gemstone/src/swapper/mod.rs +++ b/gemstone/src/swapper/mod.rs @@ -13,11 +13,12 @@ mod uniswap; use models::*; use primitives::Chain; +use std::collections::HashSet; #[async_trait] pub trait GemSwapProvider: Send + Sync + Debug { fn provider(&self) -> SwapProvider; - async fn supported_chains(&self) -> Result, SwapperError>; + fn supported_chains(&self) -> Vec; async fn fetch_quote(&self, request: &SwapQuoteRequest, provider: Arc) -> Result; async fn fetch_quote_data(&self, quote: &SwapQuote, provider: Arc, data: FetchQuoteData) -> Result; async fn get_transaction_status(&self, chain: Chain, transaction_hash: &str, provider: Arc) -> Result; @@ -39,8 +40,17 @@ impl GemSwapper { } } - fn get_providers(&self) -> Vec { - self.swappers.iter().map(|x| x.provider().name().to_string()).collect() + fn supported_chains(&self) -> Vec { + self.swappers + .iter() + .flat_map(|x| x.supported_chains()) + .collect::>() + .into_iter() + .collect() + } + + fn get_providers(&self) -> Vec { + self.swappers.iter().map(|x| x.provider()).collect() } async fn fetch_quote(&self, request: SwapQuoteRequest) -> Result, SwapperError> { diff --git a/gemstone/src/swapper/models.rs b/gemstone/src/swapper/models.rs index d8833ba7..097f59d1 100644 --- a/gemstone/src/swapper/models.rs +++ b/gemstone/src/swapper/models.rs @@ -69,7 +69,7 @@ pub struct SwapQuoteRequest { pub struct GemSwapOptions { pub slippage_bps: u32, pub fee: Option, - pub preferred_providers: Vec, + pub preferred_providers: Vec, } impl Default for GemSwapOptions { diff --git a/gemstone/src/swapper/thorchain/mod.rs b/gemstone/src/swapper/thorchain/mod.rs index 2b8bfeb7..454fb331 100644 --- a/gemstone/src/swapper/thorchain/mod.rs +++ b/gemstone/src/swapper/thorchain/mod.rs @@ -57,12 +57,11 @@ impl GemSwapProvider for ThorChain { SwapProvider::Thorchain } - async fn supported_chains(&self) -> Result, SwapperError> { - let chains: Vec = Chain::all() + fn supported_chains(&self) -> Vec { + Chain::all() .into_iter() .filter_map(|chain| THORChainName::from_chain(&chain).map(|name| name.chain())) - .collect(); - Ok(chains) + .collect() } async fn fetch_quote(&self, request: &SwapQuoteRequest, provider: Arc) -> Result { diff --git a/gemstone/src/swapper/uniswap/mod.rs b/gemstone/src/swapper/uniswap/mod.rs index d3efde3e..1d0ad0d4 100644 --- a/gemstone/src/swapper/uniswap/mod.rs +++ b/gemstone/src/swapper/uniswap/mod.rs @@ -331,8 +331,8 @@ impl GemSwapProvider for UniswapV3 { SwapProvider::UniswapV3 } - async fn supported_chains(&self) -> Result, SwapperError> { - Ok(Chain::all().iter().filter(|x| self.support_chain(x)).cloned().collect()) + fn supported_chains(&self) -> Vec { + Chain::all().iter().filter(|x| self.support_chain(x)).cloned().collect() } async fn fetch_quote(&self, request: &SwapQuoteRequest, provider: Arc) -> Result {