我正试图从我的学习升级一个闪存贷款文件,我没有时间检查池的存在。这是密码。
// 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有相同的地址所以我被困在这里了。
发布于 2022-08-01 19:38:28
似乎经过5个小时的思考,我找到了一个答案:
if (_tokenBorrow == address(WETH)) {
address pair = IUniswapV2Factory(UNISWAP_FACTORY).getPair(
address(WETH),
_token2
);现在我得到Uniswap:锁定错误。但是看起来,uniswap只需要一个现有的一对就可以开始交换了。如果我给他这对的地址就行了。
https://ethereum.stackexchange.com/questions/132811
复制相似问题