Trait StellarDexServiceTrait

Source
pub trait StellarDexServiceTrait: Send + Sync {
    // Required methods
    fn supported_asset_types(&self) -> HashSet<AssetType>;
    fn get_token_to_xlm_quote<'life0, 'life1, 'async_trait>(
        &'life0 self,
        asset_id: &'life1 str,
        amount: u64,
        slippage: f32,
        asset_decimals: Option<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<StellarQuoteResponse, StellarDexServiceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn get_xlm_to_token_quote<'life0, 'life1, 'async_trait>(
        &'life0 self,
        asset_id: &'life1 str,
        amount: u64,
        slippage: f32,
        asset_decimals: Option<u8>,
    ) -> Pin<Box<dyn Future<Output = Result<StellarQuoteResponse, StellarDexServiceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn prepare_swap_transaction<'life0, 'async_trait>(
        &'life0 self,
        params: SwapTransactionParams,
    ) -> Pin<Box<dyn Future<Output = Result<(String, StellarQuoteResponse), StellarDexServiceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn execute_swap<'life0, 'async_trait>(
        &'life0 self,
        params: SwapTransactionParams,
    ) -> Pin<Box<dyn Future<Output = Result<SwapExecutionResult, StellarDexServiceError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;

    // Provided method
    fn can_handle_asset(&self, asset_id: &str) -> bool { ... }
}
Expand description

Trait for Stellar DEX services

Required Methods§

Source

fn supported_asset_types(&self) -> HashSet<AssetType>

Returns the asset types this DEX service can handle

§Returns

A set of supported asset types (Native, Classic, Contract, or combinations)

Source

fn get_token_to_xlm_quote<'life0, 'life1, 'async_trait>( &'life0 self, asset_id: &'life1 str, amount: u64, slippage: f32, asset_decimals: Option<u8>, ) -> Pin<Box<dyn Future<Output = Result<StellarQuoteResponse, StellarDexServiceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a quote for converting a token to XLM

§Arguments
  • asset_id - Asset identifier (e.g., “native” for XLM, or “USDC:GA5Z…” for credit assets)
  • amount - Amount in stroops to convert
  • slippage - Slippage percentage (e.g., 1.0 for 1%)
  • asset_decimals - Number of decimal places for the asset (defaults to 7 if None)
§Returns

A quote response with conversion details

Source

fn get_xlm_to_token_quote<'life0, 'life1, 'async_trait>( &'life0 self, asset_id: &'life1 str, amount: u64, slippage: f32, asset_decimals: Option<u8>, ) -> Pin<Box<dyn Future<Output = Result<StellarQuoteResponse, StellarDexServiceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Get a quote for converting XLM to a token

§Arguments
  • asset_id - Target asset identifier
  • amount - Amount in stroops of XLM to convert
  • slippage - Slippage percentage
  • asset_decimals - Number of decimal places for the asset (defaults to 7 if None)
§Returns

A quote response with conversion details

Source

fn prepare_swap_transaction<'life0, 'async_trait>( &'life0 self, params: SwapTransactionParams, ) -> Pin<Box<dyn Future<Output = Result<(String, StellarQuoteResponse), StellarDexServiceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Prepare a swap transaction (get quote and build XDR) without executing it

This method creates an unsigned transaction XDR for a swap operation. The transaction can then be queued for background processing.

§Arguments
  • params - Swap transaction parameters including source account, assets, amounts, sequence number, and network passphrase
§Returns

A tuple containing:

  • String - Unsigned transaction XDR (base64 encoded)
  • StellarQuoteResponse - Quote information including destination amount
Source

fn execute_swap<'life0, 'async_trait>( &'life0 self, params: SwapTransactionParams, ) -> Pin<Box<dyn Future<Output = Result<SwapExecutionResult, StellarDexServiceError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Execute a swap transaction

This method creates, signs, and submits a Stellar transaction with a path payment operation based on the quote from get_token_to_xlm_quote or get_xlm_to_token_quote.

§Arguments
  • params - Swap transaction parameters including source account, assets, amounts, sequence number, and network passphrase
§Returns

A SwapExecutionResult containing the transaction hash and destination amount received

Provided Methods§

Source

fn can_handle_asset(&self, asset_id: &str) -> bool

Checks if this service can handle a specific asset

§Arguments
  • asset_id - Asset identifier (e.g., “native”, “USDC:GA5Z…”, “C…”)
§Returns

True if this service can process swaps for this asset

Implementors§

Source§

impl<P, S> StellarDexServiceTrait for OrderBookService<P, S>
where P: StellarProviderTrait + Send + Sync + 'static, S: StellarSignTrait + Signer + Send + Sync + 'static,

Source§

impl<P, S> StellarDexServiceTrait for StellarDexService<P, S>
where P: StellarProviderTrait + Send + Sync + 'static, S: StellarSignTrait + Signer + Send + Sync + 'static,