-
Notifications
You must be signed in to change notification settings - Fork 383
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi!
Code is
def _eth_to_token_swap_output(
self, output_token: AddressLike, qty: int, recipient: Optional[AddressLike]
) -> HexBytes:
"""Convert ETH to tokens given an output amount."""
if self.version == 1:
token_funcs = self.exchange_contract(output_token).functions
eth_qty = self.get_eth_token_output_price(output_token, qty)
tx_params = self._get_tx_params(eth_qty)
func_params: List[Any] = [qty, self._deadline()]
if not recipient:
function = token_funcs.ethToTokenSwapOutput(*func_params)
else:
func_params.append(recipient)
function = token_funcs.ethToTokenTransferOutput(*func_params)
return self._build_and_send_tx(function, tx_params)
else:
if recipient is None:
recipient = self.address
eth_qty = self.get_eth_token_output_price(output_token, qty) #<----------------------------
return self._build_and_send_tx(
self.router.functions.swapETHForExactTokens(
qty,
[self.get_weth_address(), output_token],
recipient,
self._deadline(),
),
self._get_tx_params(eth_qty),
)
It seems for me that highlighted string should be smth like that:
eth_qty = int(
(1 + self.max_slippage)*
self.get_eth_token_output_price(output_token, qty))
Am I right? As written I have no idea how slippage can be taken into account. Thanks in advance!
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working