Using Ganache fork with .callStatic() (ethers js) doesn't support Uniswap Router #1933
-
I have created a test project for the purpose of this question for testing a simple swap using Uniswap Router. For the sake of this question I created a simple repo, you can install it with If you cloned the repo and tried to run it, you will see that the transaction is executing well, you will receive the recipe as you should! My problem comes when I'm trying to replace the same transaction with const tx = await router.swapExactETHForTokens(
amountOutMin,
[weth.address, floki.address],
addresses.recipient,
deadline,
{
value: amountIn,
gasLimit: 1000000
}
); with: const tx = await router.callStatic.swapExactETHForTokens(
amountOutMin,
[weth.address, floki.address],
addresses.recipient,
deadline,
{
value: amountIn,
gasLimit: 1000000
}
); I'm getting an error: Error: missing revert data in call exception (error={"reason":"processing response error","code":"SERVER_ERROR","body":"{\"id\":46,\"jsonrpc\":\"2.0\",\"error\":{\"message\":\"VM Exception while processing transaction: revert\",\"code\":-32000,\"data\":{\"0x95d2182e8a13b89b535b2b61e5f6b1bc56ef3f9505773d353cb64116d38cdb96\":{\"error\":\"revert\",\"program_counter\":9406,\"return\":\"0x\"},\"stack\":\"c: VM Exception while processing transaction: revert\\n at Function.c.fromResults (C:\\\\Users\\\\USER\\\\Desktop\\\\callStaticTest\\\\node_modules\\\\ganache-cli\\\\build\\\\ganache-core.node.cli.js:4:192416)\\n at C:\\\\Users\\\\USER\\\\Desktop\\\\callStaticTest\\\\node_modules\\\\ganache-cli\\\\build\\\\ganache-core.node.cli.js:42:50402\",\"name\":\"c\"}}}","error":{"code":-32000,"data":{"0x95d2182e8a13b89b535b2b61e5f6b1bc56ef3f9505773d353cb64116d38cdb96":{"error":"revert","program_counter":9406,"return":"0x"},"stack":"c: VM Exception while processing transaction: revert\n at Function.c.fromResults (C:\\Users\\USER\\Desktop\\callStaticTest\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:4:192416)\n at C:\\Users\\USER\\Desktop\\callStaticTest\\node_modules\\ganache-cli\\build\\ganache-core.node.cli.js:42:50402","name":"c"}},"requestBody":"{\"method\":\"eth_call\",\"params\":[{\"gas\":\"0xf4240\",\"value\":\"0x8ac7230489e80000\",\"from\":\"0x33850a0605cc68b139ba15dd68fa4a2623d3e992\",\"to\":\"0x7a250d5630b4cf539739df2c5dacb4c659f2488d\",\"data\":\"0x7ff36ab50000000000000000000000000000000000000000000000000441e05289161917000000000000000000000000000000000000000000000000000000000000008000000000000000000000000033850a0605cc68b139ba15dd68fa4a2623d3e9920000000000000000000000000000000000000000000000000000000061cbc8410000000000000000000000000000000000000000000000000000000000000002000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc200000000000000000000000043f11c02439e2736800433b4594994bd43cd066d\"},\"latest\"],\"id\":46,\"jsonrpc\":\"2.0\"}","requestMethod":"POST","url":"http://localhost:8545"}, data="0x", code=CALL_EXCEPTION, version=providers/5.5.1)
at Logger.makeError (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\logger\src.ts\index.ts:225:28)
at Logger.throwError (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\logger\src.ts\index.ts:237:20)
at checkError (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:34:16)
at JsonRpcProvider.<anonymous> (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\providers\src.ts\json-rpc-provider.ts:562:20)
at step (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:48:23)
at Object.throw (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:29:53)
at rejected (C:\Users\USER\Desktop\callStaticTest\node_modules\@ethersproject\providers\lib\json-rpc-provider.js:21:65)
at processTicksAndRejections (node:internal/process/task_queues:96:5) this is the implementation for the router function I'm trying to interact with: function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
virtual
override
payable
ensure(deadline)
returns (uint[] memory amounts)
{
require(path[0] == WETH, 'UniswapV2Router: INVALID_PATH');
amounts = UniswapV2Library.getAmountsOut(factory, msg.value, path);
require(amounts[amounts.length - 1] >= amountOutMin, 'UniswapV2Router: INSUFFICIENT_OUTPUT_AMOUNT');
IWETH(WETH).deposit{value: amounts[0]}();
assert(IWETH(WETH).transfer(UniswapV2Library.pairFor(factory, path[0], path[1]), amounts[0]));
_swap(amounts, path, to);
} link to source code: I have tried to run this code with a different contract and If I try to call a simple approve on the floki erc20 contract for example, it works! I run it directly with Infura and it works, so it seems like its a problem with ganache-cli fork, Edit: I tried using a local db with Ganache and also using the Ganache provider directly instead of the server, but neither made a change. I am assuming that it triggers an assert somewhere, but not sure why. If you set the amount to 0 you can see that it can trigger the method successfully, as it reverts with a proper error message, but it cannot fully perform the call on it, neither via ethers nor a direct rpc call. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Can you try ganache@7.0.0-beta.2? Release notes and usage: https://github.com/trufflesuite/ganache/releases/tag/ganache%407.0.0-beta.2 |
Beta Was this translation helpful? Give feedback.
Can you try ganache@7.0.0-beta.2? Release notes and usage: https://github.com/trufflesuite/ganache/releases/tag/ganache%407.0.0-beta.2