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
Support trading on custom routes in v2 #379
base: master
Are you sure you want to change the base?
Conversation
080fe6c
to
ed2abce
Compare
@@ -730,10 +740,12 @@ def _token_to_token_swap_input( | |||
function = token_funcs.tokenToTokenTransferInput(*func_params) | |||
return self._build_and_send_tx(function) | |||
elif self.version == 2: | |||
if not route: | |||
route = [input_token, self.get_weth_address(), output_token] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WETH in the middle is an assumption, it doesn't have to be like this. Imagine swapping stable for stable. Probably the most correct approach is just [input_token, output token]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't really say if it's correct or not as i'm not terribly familiar with this stuff but I didn't want to make any breaking changes
@@ -971,7 +984,7 @@ def _token_to_token_swap_output( | |||
|
|||
# Balance check | |||
input_balance = self.get_token_balance(input_token) | |||
cost = self._get_token_token_output_price(input_token, output_token, qty, fee) | |||
cost = self._get_token_token_output_price(input_token, output_token, qty, fee, route) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_get_token_token_output_price() needs a fix for route=None
case as well
uniswap/uniswap.py
Outdated
@@ -499,6 +505,9 @@ def make_trade_output( | |||
if input_token == output_token: | |||
raise ValueError | |||
|
|||
if route and (input_token == ETH_ADDRESS or output_token == ETH_ADDRESS): | |||
raise ValueError | |||
|
|||
if input_token == ETH_ADDRESS: | |||
balance = self.get_eth_balance() | |||
need = self._get_eth_token_output_price(output_token, qty, fee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom route support should be added here (and similar methods) too imo
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #379 +/- ##
===========================================
- Coverage 84.20% 61.40% -22.80%
===========================================
Files 11 11
Lines 1057 1065 +8
===========================================
- Hits 890 654 -236
- Misses 167 411 +244 ☔ View full report in Codecov by Sentry. |
Please take a look at recent test results, there are some issues. Just assuming, it could be worth making the |
No description provided.