feat: add router capabilities for swapping with the sdk #66
Merged
Conversation
bayological
reviewed
Feb 16, 2025
Co-authored-by: Bayological <6872903+bayological@users.noreply.github.com>
baroooo
suggested changes
Feb 17, 2025
| ) | ||
|
|
||
| // Calculate minAmountOut with 5% slippage | ||
| const minAmountOut = amountOut.mul(95).div(100) |
Contributor
There was a problem hiding this comment.
nit: would be nice to make this an optional param
chapati23
reviewed
Feb 17, 2025
chapati23
reviewed
Feb 17, 2025
philbow61
approved these changes
Feb 17, 2025
Co-authored-by: baroooo <baranseltekin@gmail.com>
baroooo
approved these changes
Feb 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR integrates the Mento Router to implement simple routes between assets in the Mento protocol. The tl;dr of the implementation is:
TradablePairinterface the represents a pair that can be traded either directly or through multiple swaps.getTradablePairsto return an array ofTradablePairslimited to 1 or 2 swaps (because one hop is enough to get between any two assets).This as a base worked well, as long as the clients will use
getTradablePairsfor discoverability and then have that instance with the path to pass back into the router.What this doesn't do: Find the best route. In our setup it's redundant. All paths will be through cUSD ultimately. No need to implement a full router logic on our end.
I had to do some additional work because in practice
mento-webdidn't rely ongetTradablePairsfor performance reasons but kept a local index of hardcoded exchange ids and assets to determine possible swaps. Because the performance concerns were real I decided to implement a helper to cache all tradable pairs in the SDK (instead of them living inmento-web). This way we get the performance boost across implementations and consumers of the SDK have the option to query without cache.This means that when new tokens go live we would still need to rebuild the cache here and redeploy
mento-webbut that was the case in the past as well.Other changes
I've also added a script for testing swaps and a script to list tradable pairs to make it easier to test.
Tested
Tests updated to reflect the router situation.
Related issues
N/A
Backwards compatibility
I've made the interface backwards compatible so no major version push required 🎉
Documentation
N/A