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 tokentokenOut: Address of the output tokenamountIn: Amount of input tokensdexData: 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 nametoChain: Destination blockchain nametokenIn: Input token address on source chaintokenOut: Output token address on destination chainamountIn: Amount of input tokens
Returns:
Usage Example:
getMultipleQuotes
Get quotes from multiple DEXs for comparison.
Parameters:
tokenIn: Input token addresstokenOut: Output token addressamountIn: Amount of input tokensdexes: 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 addresstokenOut: Output token addressamountIn: Amount of input tokensmaxSlippage: 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
Cache Aggressively: Quote data becomes stale quickly, but short-term caching improves UX
Handle Failures Gracefully: Always have fallback options when quotes fail
Consider Gas Costs: Include gas costs in route optimization
Monitor Price Impact: Large trades should be split to minimize impact
Performance Optimization
Batch Requests: Use multicall when getting multiple quotes
Parallel Processing: Query multiple DEXs simultaneously
Smart Caching: Cache based on token pair and amount ranges
Rate Limiting: Respect API rate limits to avoid being blocked
Integration Patterns
Progressive Enhancement: Start with basic quotes, add advanced features
Error Boundaries: Wrap quote components in error boundaries
Loading States: Always show loading states for better UX
Real-time Updates: Use WebSockets for live price feeds when available
Resources
Last updated

