简体   繁体   English

web3.py getAmountOut() 输出 INVALID LIQUIDITY

[英]web3.py getAmountOut() outputs INVALID LIQUIDITY

I'm trying to use the getAmountOut() function from the Uniswap Router-02 which should tell you how much of output token you should receive for a given input token amount.我正在尝试使用 Uniswap Router-02 中的 getAmountOut() function,它应该告诉您对于给定的输入令牌数量,您应该收到多少 output 令牌。

Problem is I am getting the following error:问题是我收到以下错误:

web3.exceptions.ContractLogicError: execution reverted: UniswapV2Library: INSUFFICIENT_LIQUIDITY . web3.exceptions.ContractLogicError: execution reverted: UniswapV2Library: INSUFFICIENT_LIQUIDITY

Now does this function require you to use some ETH because it has to pay gas fees in order to execute or is there an error in my code?现在这个 function 是否需要您使用一些 ETH,因为它必须支付汽油费才能执行,还是我的代码中有错误?

def checkSubTrade(exchange, in_token_address, out_token_address, amount):

# Should be general cross exchange but would have to check if each routers contain the same methods
router_address = w3.toChecksumAddress(router_dict[str(exchange)])
router_abi = abi_dict[str(exchange)]
router_contract = w3.eth.contract(address = router_address, abi = router_abi)
swap_path = [in_token_address, out_token_address]

output = router_contract.functions.getAmountsOut(amount, swap_path).call()

return output

output = checkSubTrade('uniswap', token_dict['WETH'], token_dict['UNI'], 100000000)
print(output())

token_dict , router_dict contain the addresses and abi_dict contains the ABI for the DEX. token_dictrouter_dict包含地址, abi_dict包含 DEX 的 ABI。

i think you need to check two things.我认为你需要检查两件事。

  1. router_address: maybe it is different then you think when you go scope page that chain providing, you can see transaction detail. router_address: 可能和你想象的不一样,当你在链提供的 go scope 页面时,你可以看到交易细节。 and there is from and to, for example this link you might see the to, in swap session to is route_address.并且有 from 和 to,例如这个链接你可能会看到 to,在交换 session 到是 route_address。 so like that, you need to search in scope page to get route_address像这样,您需要在 scope 页面中搜索以获取 route_address
  2. router_abi: i think you using uniswapv2library, but in uniswap2library there is many other abi. router_abi:我认为您使用的是 uniswapv2library,但在 uniswap2library 中还有许多其他 abi。 for example factoryabi.例如 factoryabi。 so you need to check abi is correct or not.所以你需要检查 abi 是否正确。 i highly recommend that you need to get or make solidity file of abi and change abi via web ide我强烈建议您需要获取或制作 abi 的solidity 文件并通过 web ide 更改 abi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM