My bad, this contract is indeed a V3 contract which implements function exactInputSingle
.
Your naming choice (SWAP_ROUTER_02
) has confused me.
I'll have another look to see what could go wrong inside your contract function or inside the V3 contract function which your function calls...
Please conduct the following investigation process:
Change your contract function to this:
function swapExactOutputSingle(uint256 amountIn, uint test) external returns (uint256 amountOut) {
TransferHelper.safeTransferFrom(DAI, msg.sender, address(this), amountIn);
require(test != 111, "safeTransferFrom did not revert");
TransferHelper.safeApprove(DAI, address(swapRouter02), amountIn);
require(test != 222, "safeApprove did not revert");
IV3SwapRouter.ExactInputSingleParams memory params = IV3SwapRouter.ExactInputSingleParams({
tokenIn: DAI,
tokenOut: WETH9,
fee: 3000,
recipient: address(this),
amountIn: amountIn,
amountOutMinimum: 0,
sqrtPriceLimitX96: 0
});
amountOut = swapRouter02.exactInputSingle(params);
require(test != 333, "exactInputSingle did not revert");
}
Redeploy the new contract
Approve the new contract to transfer tokens from your wallet
Execute the new contract function with input test = 111
and check the revert message
Execute the new contract function with input test = 222
and check the revert message
Execute the new contract function with input test = 333
and check the revert message
The above process should indicate the point at which your contract function reverts.
Please post the results in order to allow for further investigation.
Martina
November 16, 2023, 7:57am
23
Thanks, mate,I will redeploy it and post the result.
Martina
November 16, 2023, 8:17am
24
Mate,when I am trying to call the function,it throws this error,
Yes, the transaction is meant to revert with a message. You need to obtain that message somehow, and I suppose that by sending the transaction, you will be able to observe that message on goerli/basescan.
Martina
November 16, 2023, 8:23am
26
That's just one transaction, with the input test = 333
.
You still "owe me" two additional transactions, with test = 111
and test = 222
.
And there's an additional problem - basescan doesn't display the revert message.
My guess - this is because you haven't verified your contract source code, so please do that .
Martina
November 16, 2023, 8:37am
29
Good job!
So we see safeTransferFrom did not revert
and safeApprove did not revert
.
But we don't see exactInputSingle did not revert
, which means that the line:
amountOut = swapRouter02.exactInputSingle(params);
Has reverted the transaction before the line:
require(test != 333, "exactInputSingle did not revert");
was executed (i.e., before this line "had the chance" to revert the transaction).
Martina
November 16, 2023, 8:44am
31
So what is the next step to solve that error, @barakman .
This is the Router contract which you are interacting with.
It implements a function which returns the address of a Factory contract:
This is the Factory contract.
It implements a function which returns the address of a Pool contract corresponding to a given pair of tokens and a given fee:
As you can see, there is currently no Pool contract corresponding to your pair of tokens and your fee.
Martina
November 16, 2023, 10:46am
33
But,when i am trying to swap these token in Pancakeswap,i am able to swap it
.Here is the txnHash:https://goerli.basescan.org/tx/0x99694e2d2208eeaadcdef262827b0347a5aa84775a79dadecabd6cf95b5af916
This pancakeswap router doesn't use the same factory as the uniswap router that your contract interacts with:
Martina
November 16, 2023, 1:03pm
35
Then,How to create a pair Mate,Because i created a LP pair using pancakeswap.
Martina
November 16, 2023, 1:14pm
37
Thanks mate,I will create and try it,and let you know mate
1 Like
I'm pretty sure that in order to execute a swap on this new pool, you'll need to transfer some liquidity to that pool after you create it. But I'm not very familiar with UniV3, so I might be wrong here.
Martina
November 16, 2023, 1:22pm
39
ok mate,No probelm,I will check how to add liquidity to that pool
1 Like