Uniswap / Uniswap/interface

Unable to buy token when entering exactEth amounts (bestCallOption bug)

Open
#2,137 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug p2
Dominant language
TypeScript
Stars
5.5k
Forks
5.4k
PR merge metrics
No merged PRs in 30d

Description

Description

I'm working on a fee on transfer ERC20 token that automatically stakes when bought from an exchange. These buys work properly when an exact token amount is entered, but not when an exact eth amount is entered.

Interestingly, direct calls on the contract for swapExactETHForTokens work, but swapExactETHForTokensSupportingFeeOnTransferTokens do not.

It appears the interface understands that there are two potential swap functions to call for this exactEth purchase, but breaks down when attempting to choose the best call. This happens in this block of code:

let bestCallOption: SuccessfulCall | SwapCallEstimate | undefined = estimatedCalls.find(
  (el, ix, list): el is SuccessfulCall => {
    return 'gasEstimate' in el && (ix === list.length - 1 || 'gasEstimate' in list[ix + 1])
  }
)

estimatedCalls looks something like this (pseudo-code): [swapExactETHForTokens, swapExactETHForTokensSupportingFeeOnTransferTokens]

so when bestCallOption is calculated, it sees that estimatedCalls[0] has estimatedGas but does not select it since estimatedCalls[1] does not have estimatedGas. I don't see a reason for this to be the case, so am labelling this as a bug. Is anybody able to provide more detail? I'm assuming this logic check was previously necessary, but isn't any longer. If this is a bug, the following change fixes it:

let bestCallOption: SuccessfulCall | SwapCallEstimate | undefined = estimatedCalls.find(
  (el): el is SuccessfulCall => 'gasEstimate' in el
)

I'll create a PR with this change.

Steps to Reproduce

Attempt to swap ETH for 0xc56749ad5a55d74f455986604afa23f938689c0b (AUTO) on Rinkeby Uniswap v2

  • entering an exact AUTO amount succeeds
  • entering an exact ETH amount fails

Appreciate any help on this - thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the bestCallOption selection in the TypeScript interface code and reproduce the exact-ETH swap failure with the AUTO token on Rinkeby. Compare the two candidate swap calls and confirm that the successful estimate is selected; done means exact-token and exact-ETH purchases both work, including fee-on-transfer tokens.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
blockchain, frontend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.