Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swapper doesn't load full output token list for certain SPL input tokens #3074

Open
wentokay opened this issue Mar 1, 2023 · 3 comments
Open
Assignees

Comments

@wentokay
Copy link
Collaborator

wentokay commented Mar 1, 2023

Not sure if this is expected but if I try to swap MNGO in Backpack I can only pick USDC, on jup.ag I get the full list

mango.mov
jup.mov
@tomlinton
Copy link
Contributor

This is just due to the onlyDirectRoutes parameter in the API request. This was enabled because with it on we could do swaps in a single transaction as it wasn't acceptable from a UI perspective to require up to 3 transaction signings on a Ledger to execute a swap.

Jupiter now do versioned transactions and I believe they can fit everything into a single transaction even with onlyDirectRoutes off, we just have to confirm that and then can remove the parameter from the API request.

@wentokay
Copy link
Collaborator Author

wentokay commented Mar 1, 2023

Got it. Thanks for the explanation!

@wentokay
Copy link
Collaborator Author

wentokay commented Mar 7, 2023

There's a little bit of hidden complexity with this issue

Simply removing ?onlyDirectRoutes=true would work here because jupiter api v4 guarantees a single transaction and asLegacyTransaction guarantees routing that would fit inside a legacy transaction

However...

  • it would mean a 2.4MB JSON download (vs 51KB we currently fetch) to get the routes, which is going to be noticeable on any connection. It does have cache headers on the file which will help but it will probably get reloaded every so often
  • if we then replace all of the integer indices in the file with public key strings, as we are doing at the moment, it would mean we're storing a ~30MB object in recoil which is probably going to cause more sluggishness on slower machines

I think a long term solution would be to move all of the swap logic to the backend so that there's a simple endpoint that can support multiple chains and would be near instant to use. We'd just provide the transaction to be signed by the wallet and broadcast it to the appropriate blockchain. All routing updates could be done asynchronously on a CRON schedule.

I see 3 possible short term solutions, all of them will suffer from the 2.4MB download -

  1. We go ahead and just change the URL, see if it causes significant slowdown for anyone
  2. We change the URL and change the recoil logic so a 2.4MB object is stored in memory vs ~30MB
  3. We store the routes in indexedDB to reduce the memory burden

I'm going to do some testing with (1) now and will try and move to (2) if it is problematic and that solution doesn't take too much time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants