Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Massive USDT Approval costs #133

Open
laraschke opened this issue Aug 26, 2022 · 3 comments
Open

Massive USDT Approval costs #133

laraschke opened this issue Aug 26, 2022 · 3 comments

Comments

@laraschke
Copy link

Hey everyone,

i integrated the paraswap api into my dapp. Everything is looking good and running fine. I can approve and exchange various ERC20 tokens on Ethereum as well as Polygon with "normal" expected gas costs.

I am facing an unexpected problem by approving the paraswap api for USDT access. The fees for an approval transaction is 300 - 1000 times higher than for other tokens.

The function call looks like this:

await paraswap.approveToken("100", <senderAddress>, "0xdAC17F958D2ee523a2206206994597C13D831ec7");

To find the root of the problem i tried to fire the approve transaction separately on Etherscan. Weirdly, approving any random address has expectable gas cost except of the paraswap transferrer contract. By calling the approve function on USDT contract with paraswap contract as spender (0x216B4B4Ba9F3e719726886d34a177484278Bfcae) the gas costs are just exploding.

Hopefully anybody can help me out.

@mwamedacen
Copy link
Member

mwamedacen commented Aug 27, 2022

Hi there, the problem you're experiencing is due to USDT that is not fully compliant with ERC20.

Here's a sneak peek of USDT's contract code (hint: solution in the comment):
Screenshot 2022-08-27 at 23 06 17

Alternatively here is a popular article: https://forum.openzeppelin.com/t/can-not-call-the-function-approve-of-the-usdt-contract/2130

In a nutshell, if you approved a certain address to spend a certain amount X in the past and spender didn't consume all the allowance (< X), you have to first reset allowance by calling approve(0) then you can call approve(Y).

@laraschke
Copy link
Author

Hi @mwamedacen,
thanks for the quick reply.

You are totally right on this one. The address of the paraswap transferrer contract has already been approved with an amount X, which led to the high gas consumption on approving USDT.

On checking my dapp why the approving call is made while the contract is already approved I found the root of this problem.

The API call for getting token allowance is not working for me on the Ethereum Mainchain. On polygon everything is running fine and i get correct allowance values for several different tokens. On Ethereum I get a "Not found" response. I finally did a workaround by getting the transferrer address and checking it by myself with a direct contract call for the token allowance, but the getAllowance function is not working for me on Ethereum. Maybe you can proof this issue.

paraswap.setWeb3Provider(web3.library);
  const allowanceRes: any = await paraswap.getAllowance(
    web3.account,
    from.address
  );

Is always returning "not found" on Ethereum with different tokens.

{message: 'Not Found'}

@nmaddp1995
Copy link

Hi @laraschke, What did you use to connect wallet.
I'm using wagmi to connect then I can't pass the right web3Provider to swap so that I can't call the function paraswap.approveToken

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants