QuoteLibrary

The Quote Library provides efficient price discovery and optimal route calculation for cross-chain token swaps and transfers. It aggregates liquidity from multiple DEXs and cross-chain bridges to find the best execution paths.

Overview

The Quote Library is a core component of the IU2U Protocol that handles:

  • Multi-DEX Price Aggregation: Fetches quotes from multiple decentralized exchanges

  • Cross-Chain Route Optimization: Finds optimal paths for cross-chain swaps

  • Real-time Price Updates: Maintains up-to-date pricing information

  • Slippage Calculation: Estimates price impact and slippage for trades

  • Gas Cost Estimation: Includes transaction costs in route optimization

Smart Contract Interface

Core Functions

getQuote

Get a quote for a token swap without executing the transaction.

function getQuote(
    address tokenIn,
    address tokenOut,
    uint256 amountIn,
    bytes calldata dexData
) external view returns (QuoteResult memory)

Parameters:

  • tokenIn: Address of the input token

  • tokenOut: Address of the output token

  • amountIn: Amount of input tokens

  • dexData: Encoded DEX-specific parameters

Returns:

Usage Example:

getCrossChainQuote

Get a quote for cross-chain token swap including bridge fees and timing.

Parameters:

  • fromChain: Source blockchain name

  • toChain: Destination blockchain name

  • tokenIn: Input token address on source chain

  • tokenOut: Output token address on destination chain

  • amountIn: Amount of input tokens

Returns:

Usage Example:

getMultipleQuotes

Get quotes from multiple DEXs for comparison.

Parameters:

  • tokenIn: Input token address

  • tokenOut: Output token address

  • amountIn: Amount of input tokens

  • dexes: Array of DEX addresses to query

Usage Example:

getBestRoute

Get the optimal route for a token swap considering all available DEXs.

Parameters:

  • tokenIn: Input token address

  • tokenOut: Output token address

  • amountIn: Amount of input tokens

  • maxSlippage: Maximum acceptable slippage in basis points

Returns:

estimateGasCost

Estimate gas costs for a swap route.

getPriceImpact

Calculate price impact for a trade.

Configuration Functions

addDEX

Add a new DEX to the quote aggregation (admin only).

updateDEXStatus

Enable or disable a DEX for quote aggregation.

setMaxSlippage

Set maximum allowed slippage for quotes.

setSupportedTokens

Configure which tokens are supported for quoting.

JavaScript SDK Integration

QuoteLibrary Class

React Hook

Advanced Features

Quote Optimization Strategies

Real-time Price Monitoring

Best Practices

Quote Management

  1. Cache Aggressively: Quote data becomes stale quickly, but short-term caching improves UX

  2. Handle Failures Gracefully: Always have fallback options when quotes fail

  3. Consider Gas Costs: Include gas costs in route optimization

  4. Monitor Price Impact: Large trades should be split to minimize impact

Performance Optimization

  1. Batch Requests: Use multicall when getting multiple quotes

  2. Parallel Processing: Query multiple DEXs simultaneously

  3. Smart Caching: Cache based on token pair and amount ranges

  4. Rate Limiting: Respect API rate limits to avoid being blocked

Integration Patterns

  1. Progressive Enhancement: Start with basic quotes, add advanced features

  2. Error Boundaries: Wrap quote components in error boundaries

  3. Loading States: Always show loading states for better UX

  4. Real-time Updates: Use WebSockets for live price feeds when available

Resources

Last updated