Skip to content

feat: make_trade add optional route param #239

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion uniswap/uniswap.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ def _get_token_token_input_price(
logger.warning(f"No route specified, assuming route: {route}")

if self.version == 2:
# BL: This is where route param gets called
price: int = self.router.functions.getAmountsOut(qty, route).call()[-1]
elif self.version == 3:
if route:
Expand Down Expand Up @@ -401,6 +402,7 @@ def make_trade(
fee: int = None,
slippage: float = None,
fee_on_transfer: bool = False,
route: Optional[List[AddressLike]] = None,
Copy link
Member

@ErikBjare ErikBjare Jul 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might lead to unexpected behavior if route is specified but not respected (such as in the eth_to_token and token_to_eth cases).

) -> HexBytes:
"""Make a trade by defining the qty of the input token."""
if fee is None:
Expand Down Expand Up @@ -431,6 +433,7 @@ def make_trade(
fee,
slippage,
fee_on_transfer,
route=route
)

@check_approval
Expand Down Expand Up @@ -652,6 +655,7 @@ def _token_to_token_swap_input(
fee: int,
slippage: float,
fee_on_transfer: bool = False,
route: Optional[List[AddressLike]] = None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern as above, needs to be respected in all cases, or raise an exception if it can't.

) -> HexBytes:
"""Convert tokens to tokens given an input amount."""
# Balance check
Expand Down Expand Up @@ -690,7 +694,7 @@ def _token_to_token_swap_input(
min_tokens_bought = int(
(1 - slippage)
* self._get_token_token_input_price(
input_token, output_token, qty, fee=fee
input_token, output_token, qty, fee=fee, route=route
)
)
if fee_on_transfer:
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy