Skip to content

Commit

Permalink
adapt provider trait change
Browse files Browse the repository at this point in the history
  • Loading branch information
0xh3rman committed Nov 16, 2024
1 parent 7cfd5b1 commit c9d886c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
4 changes: 4 additions & 0 deletions gemstone/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ list:
build:
cargo build

lint:
@cargo clippy --version
cargo clippy -- -D warnings

test:
cargo test

Expand Down
4 changes: 3 additions & 1 deletion gemstone/src/swapper/models.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::permit2_data::Permit2Data;
use crate::config::swap_config::SwapReferralFees;
use crate::network::{jsonrpc::JsonRpcError, AlienError};
use primitives::{AssetId, ChainType};
use primitives::AssetId;
use std::fmt::Debug;

static DEFAULT_SLIPPAGE_BPS: u32 = 300;
Expand Down Expand Up @@ -50,12 +50,14 @@ pub enum GemSwapMode {
pub enum SwapProvider {
UniswapV3,
Thorchain,
Orca,
}
impl SwapProvider {
pub fn name(&self) -> &str {
match self {
Self::UniswapV3 => "Uniswap v3",
Self::Thorchain => "THORChain",
Self::Orca => "Orca Whirlpool",
}
}
}
Expand Down
1 change: 0 additions & 1 deletion gemstone/src/swapper/orca/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ mod provider;
mod whirlpool;
pub use provider::*;

const ORCA_NAME: &str = "Orca";
const WHIRLPOOL_PROGRAM: &str = "whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc";
const WHIRLPOOL_CONFIG: &str = "2LecshUwdy9xi7meFgHtFJQNSKk4KdTrcpvaB56dP2NQ";
const FEE_TIER_DISCRIMINATOR: &str = "AR8t9QRDQXa";
20 changes: 12 additions & 8 deletions gemstone/src/swapper/orca/provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::fee_tiers::get_fee_tiers;
use super::whirlpool::{get_tick_array_address, get_whirlpool_address};
use super::{models::*, FEE_TIER_DISCRIMINATOR, ORCA_NAME, WHIRLPOOL_CONFIG, WHIRLPOOL_PROGRAM};
use super::{models::*, FEE_TIER_DISCRIMINATOR, WHIRLPOOL_CONFIG, WHIRLPOOL_PROGRAM};
use crate::network::JsonRpcResult;
use crate::{
network::{jsonrpc::jsonrpc_call, AlienProvider},
Expand Down Expand Up @@ -38,12 +38,12 @@ impl Default for Orca {

#[async_trait]
impl GemSwapProvider for Orca {
fn name(&self) -> &'static str {
ORCA_NAME
fn provider(&self) -> SwapProvider {
SwapProvider::Orca
}

async fn supported_chains(&self) -> Result<Vec<Chain>, SwapperError> {
Ok(vec![Chain::Solana])
fn supported_chains(&self) -> Vec<Chain> {
vec![Chain::Solana]
}

async fn fetch_quote(&self, request: &SwapQuoteRequest, provider: Arc<dyn AlienProvider>) -> Result<SwapQuote, SwapperError> {
Expand Down Expand Up @@ -84,11 +84,10 @@ impl GemSwapProvider for Orca {
})?;

Ok(SwapQuote {
chain_type: request.from_asset.chain.chain_type(),
from_value: request.value.clone(),
to_value: quote.token_est_out.to_string(),
provider: SwapProviderData {
name: self.name().into(),
data: SwapProviderData {
provider: self.provider(),
routes: vec![SwapRoute {
route_type: "whirlpool".into(),
input: from_asset.to_string(),
Expand All @@ -105,6 +104,11 @@ impl GemSwapProvider for Orca {
async fn fetch_quote_data(&self, _quote: &SwapQuote, _provider: Arc<dyn AlienProvider>, _data: FetchQuoteData) -> Result<SwapQuoteData, SwapperError> {
todo!()
}

async fn get_transaction_status(&self, _chain: Chain, _transaction_hash: &str, _provider: Arc<dyn AlienProvider>) -> Result<bool, SwapperError> {
// TODO: the transaction status from the RPC
Ok(true)
}
}

impl Orca {
Expand Down
3 changes: 1 addition & 2 deletions gemstone/src/swapper/uniswap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,7 @@ impl GemSwapProvider for UniswapV3 {
}

async fn get_transaction_status(&self, _chain: Chain, _transaction_hash: &str, _provider: Arc<dyn AlienProvider>) -> Result<bool, SwapperError> {
// Implement the logic to get the transaction status here
// For now, we will return Ok(true) as a placeholder
// TODO: the transaction status from the RPC
Ok(true)
}
}
Expand Down

0 comments on commit c9d886c

Please sign in to comment.