interface icon indicating copy to clipboard operation
interface copied to clipboard

Widget slow to fetch prices

Open phoebenetwork opened this issue 3 years ago • 11 comments

Hello, I have noticed that when the widget is fetching prices within my dapp, it takes about 5x as long to fetch the price through the widget than if I go directly to uniswap.org to get the price (~5 seconds through the widget vs. ~1 second on Uniswap). I tested them side-by-side to make sure my WiFi wasn't causing the slow price quotes within my dapp.

Is the widget generally slower than Uniswap's website, or did I do something wrong in my implementation?

Any advice on how I can optimize the performance?

phoebenetwork avatar Apr 26 '22 23:04 phoebenetwork

hello! yes, very astute observation. Both the swap widget and the app.uniswap.org interface compute the optimal route using the Auto Router. The difference is that the swap widget runs that algorithm locally in the browser whereas app.uniswap.org runs the Auto Router on a hosted backend for faster performance.

The Auto Router is open source so devs are welcome to host it themselves! If you're interested, we can add a parameter in the Swap Widget to pass in a URL to your hosted instance of the Auto Router

willhennessy avatar Apr 26 '22 23:04 willhennessy

Thank you! This is super helpful information. We will go ahead and host it ourselves then to improve the performance.

I noticed another issue with the widget, and maybe there's a similar solution for this one as well. When I am on the Polygon network, the widget fetches the price correctly, but it also returns a 404 error. I was looking at the API calls, and it seems like it makes 2 calls - one to the polygon v3 pool (correct) and one to the polygon v2 pool (error). Unless I am missing something, there is no polygon v2 pool, which is why the 404 error happens. Is there a way to exclude this v2 API call when fetching price on the Polygon network?

This is the bad call: https://cloudflare-ipfs.com/ipns/api.uniswap.org/v1/pools/v2/polygon-mainnet.json

phoebenetwork avatar Apr 27 '22 00:04 phoebenetwork

Cool! Unless you want to fork the widget, you'll need us to add a parameter to pass in your hosted instance URL. When do you plan to launch and what's your project?

re the polygon bug, I've opened issue https://github.com/Uniswap/interface/issues/3782

willhennessy avatar Apr 27 '22 14:04 willhennessy

Hi @willhennessy, thanks for the help. I am trying to implement Auto Router, do I host the provided implementation as a cloud function and pass the endpoint as provider to our UniSwap Widget?

aqilusman45 avatar Apr 27 '22 21:04 aqilusman45

@willpote can provide a few pointers! This is admittedly an area we could document in more detail.

We don’t yet support a parameter to pass the auto router provider into the widget. To help me gauge priority, are you on the same or different team as phoebe?

willhennessy avatar Apr 28 '22 04:04 willhennessy

Hi @willhennessy @willpote thanks for your help with this. @aqilusman45 is on our team as well and will actually be the one who directly handles the cloud implementation of the Auto Router for our dapp.

phoebenetwork avatar Apr 28 '22 14:04 phoebenetwork

This would actually involve deploying the Auto Router API to AWS, then passing in that API endpoint into the widget (as @willhennessy mentioned we don't currently expose this functionality, so we'd need to do some work on our side).

Could you talk a bit more about your use case? Are you using the widget to enable users to swap any token, or would it be primarily be used to buy your community's token? There may be some other options that wouldn't involve you deploying your own API.

willpote avatar Apr 28 '22 15:04 willpote

Hi @willpote we will be using the widget to enable users to swap any token. We are basically trying to create the most user-friendly trading environment for first-time web3/crypto users. We have a fiat on-ramp, a cross-chain portfolio tracker (aggregates balance across networks, regardless of what network is currently selected), and a cross-chain swap (uniswap for eth/polygon and pancakeswap for bsc). Then phase 2 is to layer a social network on top of that investment infrastructure.

Because we're trying to create a hub that truly aggregates everything in one place for web3, and will be onboarding a lot of first time crypto users, we anticipate our users will use the swap widget as their primary dex.

So yes, we'd appreciate any guidance you have on the best approach for our particular use case.

phoebenetwork avatar Apr 28 '22 23:04 phoebenetwork

Hey All, Came across this whilst trying to solve an issue when using the Uniswap Swap widget. Have implemented it and it works fully except for when entering a value in the input field of the input token, it spams error fetching trade even before clicking review swap. Is there anyone who can help/ who has encountered this? Screenshot 2023-06-23 at 11 07 32

rowancowper avatar Jun 23 '23 09:06 rowancowper

To follow up I know the error there says insufficient USDC but the same error occurs even when there is a sufficient amount. Screenshot 2023-06-23 at 11 08 45

rowancowper avatar Jun 23 '23 09:06 rowancowper

+1 "Error fetching trade" issue

BTW: ETH <-> WETH works

thekoenekamp avatar Jun 28 '23 14:06 thekoenekamp