WRAP / UNWRAP with v4 swap #98
-
Hello, thank you for this repo; I am using it for uniswap v4 swaps. however, I want to to do swap to buy ETH on uniswap v4 and would like to add a wrap_eth to get WETH as output. I am struggling with that; is that possible with the current version? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
Hello Alex Yes, it's possible, though it's absolutely not elegant in the current version ... from uniswap_universal_router_decoder import (
FunctionRecipient,
RouterCodec,
V4Constants,
)
from uniswap_universal_router_decoder._enums import _RouterConstant # ugly and not necessary, but maybe clearer ...
trx_params = (
codec.
encode.
chain().
v4_swap().
swap_exact_in_single(
pool_key=eth_wbtc_pool_key,
zero_for_one=False,
amount_in=wbtc_amount,
amount_out_min=Wei(0),
).
settle_all(wbtc_address, wbtc_amount).
# All 3 below lines should work:
# take(eth_address, "0x0000000000000000000000000000000000000002", V4Constants.OPEN_DELTA.value).
# take(eth_address, ur_address, V4Constants.OPEN_DELTA.value).
take(eth_address, _RouterConstant.ADDRESS_THIS.value, V4Constants.OPEN_DELTA.value).
build_v4_swap().
# The 2 below lines should work:
wrap_eth(FunctionRecipient.SENDER, _RouterConstant.ROUTER_BALANCE.value).
# wrap_eth(FunctionRecipient.SENDER, Wei(2**255)).
build_transaction(account.address)
) |
Beta Was this translation helpful? Give feedback.
-
thank you so much; could you also give an example for the other way; swap WETH to WBTC? Regards |
Beta Was this translation helpful? Give feedback.
-
good |
Beta Was this translation helpful? Give feedback.
-
That's a good question. |
Beta Was this translation helpful? Give feedback.
Hello Alex
Yes, it's possible, though it's absolutely not elegant in the current version ...
Here is an example where I sell some WBTC for ETH, and then get them as WETH: