@@ -255,23 +255,6 @@ export class SwapManager {
255255
256256 throw new Error (" Transaction timeout - please check status manually" );
257257 }
258-
259- async getAvailableRoutes(params : {
260- originChainId? : number ;
261- originTokenAddress? : string ;
262- destinationChainId? : number ;
263- destinationTokenAddress? : string ;
264- limit? : number ;
265- }) {
266- try {
267- return await Bridge .routes ({
268- ... params ,
269- client: this .client ,
270- });
271- } catch (error ) {
272- throw new Error (` Failed to get routes: ${error .message } ` );
273- }
274- }
275258}
276259```
277260
@@ -319,92 +302,6 @@ async function swapEthToMatic(amount: string, userAccount: Account) {
319302}
320303```
321304
322- ### Advanced Price Comparison
323-
324- Compare prices across multiple routes to find the best deal:
325-
326- ``` typescript
327- interface RouteComparison {
328- route: any ;
329- quote: SwapQuote ;
330- priceImpact: number ;
331- gasEstimate: bigint ;
332- }
333-
334- export class PriceComparator {
335- private swapManager: SwapManager ;
336-
337- constructor (swapManager : SwapManager ) {
338- this .swapManager = swapManager ;
339- }
340-
341- async compareRoutes(
342- fromToken : { chainId: number ; address: string },
343- amount : bigint ,
344- userAddress : string
345- ): Promise <RouteComparison []> {
346- // Get available routes
347- const routes = await this .swapManager .getAvailableRoutes ({
348- originChainId: fromToken .chainId ,
349- originTokenAddress: fromToken .address ,
350- limit: 10 ,
351- });
352-
353- // Get quotes for each route
354- const comparisons: RouteComparison [] = [];
355-
356- for (const route of routes ) {
357- try {
358- const quote = await this .swapManager .getQuote ({
359- fromChainId: route .originToken .chainId ,
360- fromTokenAddress: route .originToken .address ,
361- toChainId: route .destinationToken .chainId ,
362- toTokenAddress: route .destinationToken .address ,
363- amount ,
364- userAddress ,
365- client: this .swapManager .client ,
366- });
367-
368- const priceImpact = this .calculatePriceImpact (quote , amount );
369- const gasEstimate = this .estimateGasCosts (quote );
370-
371- comparisons .push ({
372- route ,
373- quote ,
374- priceImpact ,
375- gasEstimate ,
376- });
377- } catch (error ) {
378- console .warn (` Failed to get quote for route ${route .originToken .symbol } -> ${route .destinationToken .symbol }: ` , error );
379- }
380- }
381-
382- // Sort by best output amount
383- return comparisons .sort ((a , b ) =>
384- Number (b .quote .destinationAmount ) - Number (a .quote .destinationAmount )
385- );
386- }
387-
388- private calculatePriceImpact(quote : SwapQuote , inputAmount : bigint ): number {
389- // Simplified price impact calculation
390- const ratio = Number (quote .destinationAmount ) / Number (quote .originAmount );
391- return Math .abs (1 - ratio ) * 100 ; // Percentage
392- }
393-
394- private estimateGasCosts(quote : SwapQuote ): bigint {
395- // Sum up gas estimates from all transactions
396- return quote .steps .reduce ((total , step ) => {
397- return total + step .transactions .reduce ((stepTotal : bigint , tx : any ) => {
398- return stepTotal + (tx .gasLimit || 200000n ); // Default estimate
399- }, 0n );
400- }, 0n );
401- }
402- }
403- ```
404-
405- <Callout variant = " info" >
406- ** Gas Optimization Tip:** For frequently traded pairs, consider caching route data to reduce API calls and improve UI responsiveness.
407- </Callout >
408305
409306</TabsContent >
410307</Tabs >
@@ -415,20 +312,16 @@ export class PriceComparator {
415312- ** Cross-chain swaps** - Exchange tokens across 50+ supported chains
416313- ** Real-time quotes** - Get up-to-date pricing and execution estimates
417314- ** Route optimization** - Find the best path for any token pair
418- - ** Price comparison** - Compare multiple routes to maximize output
419315- ** Status tracking** - Monitor cross-chain transaction progress
420316
421317
422-
423318## Going Further
424319
425320- [ Send a Payment] ( /payments/send ) - Learn about peer-to-peer transfers
426- - [ Get Routes] ( /payments/routes ) - Explore route discovery APIs
427- - [ Token Prices] ( /payments/tokens ) - Access real-time token pricing
321+ - [ Token Prices] ( /bridge/tokens ) - Access real-time token pricing
428322- [ Webhooks] ( /payments/webhooks ) - Get notified when swaps complete
429323
430324## API Reference
431325
432326- [ Bridge.Buy.prepare] ( /references/typescript/v5/buy/prepare )
433- - [ Bridge.routes] ( /references/typescript/v5/routes )
434327- [ Bridge.status] ( /references/typescript/v5/status )
0 commit comments