使用原生 ETH 进行 Uniswap v3 交换
如果我想从 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
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.
在 Uniswap v3 中,您可以原生使用 Ether,而不是将其包装到 WETH。当您将 ETH 输入到
exactInputSingle
或exactOutputSingle
方法中时,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
orexactOutputSingle
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