Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Issue with erc20 token approvals #97

Closed
paouvrard opened this issue Feb 17, 2021 · 2 comments
Closed

Issue with erc20 token approvals #97

paouvrard opened this issue Feb 17, 2021 · 2 comments

Comments

@paouvrard
Copy link
Member

Currently for locking a token, it's allowance needs to be set so that the lock contract can pull the tokens.
This allowance is currently set by calling erc20Contract.methods.approve().
If a user initiates two eth -> near transfers, then the allowance will not have been increased by the 2nd transfer (because approve only sets approval and simply overrides the previous approval) and the erc20Contract.methods.lock() will fail.

Possible solutions:

  • Increase the allowance instead of setting it. But some erc20 tokens implement increaseAllowance() and others increaseApproval().
  • Prevent the user from initiating a transfer while the previous one is not locked.
  • Give the maximum allowance to the lock contract.
@alexauroradev
Copy link

Great finding @paouvrard!

I think we should solve it with the second option, though it creates a limitation to the user behaviour.

There're two reasons for doing that:

  1. A user may be confused with approving a X tokens transfer and then immediately approving a X+Y tokens transfer. From the point of view of many users this might seem like a contract tries to get the access to the additional funds. There's no simple way how to solve it without displaying lots of info on how allowances are working.
  2. Normally a user should not a second transfer while the first one is in the execution. The main reason for multiple transfers is the reduction of losses due to an error (contract execution, copying the addresses, etc.). But this implies that a user should wait until the first transfer is finished, then he would start the second one.

However, let's consider adding the maximum allowance option in the future, because this option helps to decrease the cost of a Ethereum->NEAR transfer by >50% (see approve tx and locking tx).

@paouvrard
Copy link
Member Author

Fixed here: aurora-is-near/rainbow-bridge-client#3
image

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

No branches or pull requests

2 participants