首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uniswap V2闪存。池不存在

Uniswap V2闪存。池不存在
EN

Ethereum用户
提问于 2022-08-01 16:10:55
回答 1查看 169关注 0票数 0

我正试图从我的学习升级一个闪存贷款文件,我没有时间检查池的存在。这是密码。

代码语言:javascript
复制
// Get the Factory Pair address for combined tokens
        address pair = IUniswapV2Factory(UNISWAP_FACTORY).getPair(
            _tokenBorrow,
            WETH
        );

        // Return error if combination does not exist
        require(pair != address(0), "Pool does not exist");

        // Figure out which token (0 or 1) has the amount and assign
        address token0 = IUniswapV2Pair(pair).token0();
        address token1 = IUniswapV2Pair(pair).token1();
        uint256 amount0Out = _tokenBorrow == token0 ? _amount : 0;
        uint256 amount1Out = _tokenBorrow == token1 ? _amount : 0;

        // Passing data as bytes so that the 'swap' function knows it is a flashloan
        bytes memory data = abi.encode(_tokenBorrow, _amount, msg.sender);

        // Execute the initial swap to get the loan
        IUniswapV2Pair(pair).swap(amount0Out, amount1Out, address(this), data)

在我的学习文件中,我们总是借用USDC,所以对USDC/Weth存在和pair != address(0),但是当借来的硬币是WETH时,我收到一个错误:VM Exception while processing transaction: reverted with reason string 'Pool does not exist',因为我理解这种情况,我们需要检查这个tokenBorrow/WETH对的存在,以确保我们可以借用一个令牌。但我该拿WETH怎么办?也许我该去看看WETH/ETH的对子?但ETH和WETH有相同的地址所以我被困在这里了。

EN

回答 1

Ethereum用户

发布于 2022-08-01 19:38:28

似乎经过5个小时的思考,我找到了一个答案:

代码语言:javascript
复制
if (_tokenBorrow == address(WETH)) {
        address pair = IUniswapV2Factory(UNISWAP_FACTORY).getPair(
        address(WETH),
        _token2
    );

现在我得到Uniswap:锁定错误。但是看起来,uniswap只需要一个现有的一对就可以开始交换了。如果我给他这对的地址就行了。

票数 0
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/132811

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档