1

I'm trying to make some swaps with Uniswap V2 pools, but I've run into some UI bugs using the Uniswap site (its a janky pair with a low volume token involved, the Metamask confirmation window never pops up, and using my Ledger wallet, approving the tokens is for some reason interpreted as sending an NFT, which is not supported, 1Inch exchange gives me a rate expired error as well).

Anyway, I'm now trying to do it manually (either through Etherscan writeContract or through Web3.py) but I'm now running into some issues with that as well. I want to use swapExactTokensForTokens, which takes amountIn, amountOutMin, path, to, and deadline.

Here is an example set of inputs that doesn't work, trying to trade 20 UDSC for WETH (amountOutMin was calculated using an XYK calculator I made):

  • amountIn = 20000000
  • amountOutMin = 16030000000000000
  • path = 0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48, 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2
  • to = my wallet address
  • deadline = UNIX timestamp 20 minutes from now, i.e. something like 1672938243

When I send these variables through a script over Web3.py I get a TRANSFER_FROM_FAILED error. When I try entering them into the Etherscan writeContract form Metamask for some reason calculates:

Amount + gas fee Max amount: 1.25786989ETH

Which is definitely wrong, for this single $20 value swap.

I saw another post (Uniswap transaction fails with TransferHelper: TRANSFER_FROM_FAILED) where someone suggested that you need to approve the token being sold (in this case USDC) and another (How to manually approve a token for swap on Uniswap (direct contract interaction)) which says that you approve via the token's contract, but ERC20 tokens don't seem to have an approved function, so I tried it in the pools contract (with my address and 115792089237316195423570985008687907853269984665640564039457584007913129639935 as the amount) and that went through fine, I think I also tried putting the USDC address as the address in a second transaction as well, I'm losing track of what I've tried at this point, to be honest. I also tried multiplying 6518090524712*0.85 to sort of simulate a 15% slippage tolerance but that didn't work either. The gas fees are also weirdly high on some of these failed transactions.

Any suggestions would be greatly appreciated.

1

1 Answer 1

0

your path is wrong, you need to put first weth contract

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.