使用原生 ETH 进行 Uniswap v3 交换

发布于 2025-01-10 11:54:11 字数 604 浏览 5 评论 0原文

如果我想从 ETH 兑换代币,地址是什么?

ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: TOKEN_IN_ADDRESS,
                tokenOut: TOKEN_OUT_ADDRESS,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        amountIn = swapRouter.exactOutputSingle(params);

在这种情况下,如果我想使用原生 ETH,TOKEN_IN_ADDRESS 会是什么?

What would be the address if I want to swap tokens from ETH?

ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: TOKEN_IN_ADDRESS,
                tokenOut: TOKEN_OUT_ADDRESS,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        amountIn = swapRouter.exactOutputSingle(params);

In this case, what would be TOKEN_IN_ADDRESS if I want to use native ETH?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

淡莣 2025-01-17 11:54:11

IIRC,你不能,Uniswap V3 明确假设你正在使用 WETH,也不会像 V2 那样执行任何自动包装,你必须包装你自己的 ETH 并提供 WETH 地址作为输入。

IIRC, you cannot, Uniswap V3 explicitly assumes you are using WETH, nor does it perform any automated wrapping like V2 did, you must wrap your own ETH and provide the WETH address as an input.

澜川若宁 2025-01-17 11:54:11

在 Uniswap v3 中,您可以原生使用 Ether,而不是将其包装到 WETH。当您将 ETH 输入到 exactInputSingleexactOutputSingle 方法中时,Uniswap 会自动将 ETH 包装为 WETH,然后将其交换为所需的代币,然后在输出代币中返回结果。

amountOut = swapRouter.exactInputSingle{value: amountIn}(params);

对于主网使用 WETH9 合约:
TOKEN_IN_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

证明:https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/PeripheryPayments.sol#L58

In Uniswap v3, you can use Ether natively instead of wrapping it to WETH. When you input ETH into the exactInputSingle or exactOutputSingle method, Uniswap will automatically wrap the ETH to WETH and then swap it for the desired token, before returning the result in the output token.

amountOut = swapRouter.exactInputSingle{value: amountIn}(params);

For Mainnet use WETH9 contract:
TOKEN_IN_ADDRESS = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2

Proove: https://github.com/Uniswap/v3-periphery/blob/main/contracts/base/PeripheryPayments.sol#L58

惜醉颜 2025-01-17 11:54:11
ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: TOKEN_IN_ADDRESS,
                tokenOut: TOKEN_OUT_ADDRESS,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        amountIn = swapRouter.exactOutputSingle(params, {value: amountIn);
ISwapRouter.ExactOutputSingleParams memory params =
            ISwapRouter.ExactOutputSingleParams({
                tokenIn: TOKEN_IN_ADDRESS,
                tokenOut: TOKEN_OUT_ADDRESS,
                fee: poolFee,
                recipient: msg.sender,
                deadline: block.timestamp,
                amountOut: amountOut,
                amountInMaximum: amountInMaximum,
                sqrtPriceLimitX96: 0
            });

        amountIn = swapRouter.exactOutputSingle(params, {value: amountIn);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文