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

Fix ERC20 token approval #2018

Merged
merged 6 commits into from
Aug 3, 2020
Merged

Fix ERC20 token approval #2018

merged 6 commits into from
Aug 3, 2020

Conversation

andrevmatos
Copy link
Contributor

@andrevmatos andrevmatos commented Jul 31, 2020

Fixes #2010
Fixes UDC deposit part of #1908

Short description
This makes 2 important changes:

  • To approve before depositing (both for depositChannel and depositToUDC), if the current allowance is less than required to deposit but different than 0, we must first set it to 0 then set the needed allowance; this is a requirement on secure ERC20 contracts like RDN
  • To avoid the double transactions as above, we now default to approving MaxUint256 (i.e. a very big number), trusting the spender (i.e. TokenNetwork contract and UserDeposit contract, respectively); this way, only an approve per token is needed, and the following deposits can happen without the need to mine approve again
    • If a user isn't confortable with the above, they can either set config.minimumAllowance to a small value, like Zero, which will make it default to the strictly requested deposit amount, and/or, on Metamask's prompt (per approve transaction), simply set the allowance to any desired amount (as long as it's greater than or equal the requested deposit, or else the deposit tx will fail)

Additionally, this also refactor the depositToUDC logic, which was on the public Raiden class, to its own epic, and interact with it through udcDeposit async actions.

Definition of Done

  • Steps to manually test the change have been documented
  • Acceptance criteria are met
  • Change has been manually tested by the reviewer (dApp)

Steps to manually test the change (dApp)

  1. Test the default requested approve is now a very big number
  2. Test editing allowance on Metamask and setting it to a value greater than the requested deposit will succeed (don't forget to also increase a little the gasLimit), but on the next deposit, it'll be required to first approve(0) and then the new value, which still defaults to a very big number

@andrevmatos andrevmatos self-assigned this Jul 31, 2020
@codecov
Copy link

codecov bot commented Jul 31, 2020

Codecov Report

Merging #2018 into master will decrease coverage by 0.01%.
The diff coverage is 97.18%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2018      +/-   ##
==========================================
- Coverage   95.96%   95.94%   -0.02%     
==========================================
  Files         155      155              
  Lines        5896     5922      +26     
  Branches     1057     1121      +64     
==========================================
+ Hits         5658     5682      +24     
- Misses        179      181       +2     
  Partials       59       59              
Flag Coverage Δ
#dapp 93.19% <ø> (ø)
#sdk 97.07% <97.18%> (-0.03%) ⬇️
#sdk_e2e 65.82% <95.77%> (+0.06%) ⬆️
#sdk_unit 86.24% <74.64%> (+0.20%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
raiden-ts/src/channels/utils.ts 96.77% <86.66%> (-2.03%) ⬇️
raiden-ts/src/channels/epics.ts 97.87% <100.00%> (-0.03%) ⬇️
raiden-ts/src/config.ts 100.00% <100.00%> (ø)
raiden-ts/src/epics.ts 96.49% <100.00%> (ø)
raiden-ts/src/helpers.ts 94.92% <100.00%> (+0.15%) ⬆️
raiden-ts/src/raiden.ts 91.46% <100.00%> (-0.19%) ⬇️
raiden-ts/src/services/actions.ts 100.00% <100.00%> (ø)
raiden-ts/src/services/epics.ts 99.70% <100.00%> (+0.02%) ⬆️
raiden-ts/src/utils/actions.ts 96.34% <100.00%> (ø)
raiden-ts/src/utils/types.ts 95.89% <100.00%> (+0.11%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 24fb4c1...1f203eb. Read the comment docs.

Copy link
Contributor

@weilbith weilbith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't looked into much details of the tests. Sorry.
Rest in the comments. Function wise this should be fine. Therefore you get the approval (since this seems to be the convention).

raiden-ts/src/raiden.ts Outdated Show resolved Hide resolved
raiden-ts/src/raiden.ts Show resolved Hide resolved
raiden-ts/src/raiden.ts Outdated Show resolved Hide resolved
raiden-ts/src/raiden.ts Show resolved Hide resolved
raiden-ts/src/services/epics.ts Show resolved Hide resolved
raiden-ts/src/services/epics.ts Show resolved Hide resolved
raiden-ts/src/services/epics.ts Show resolved Hide resolved
raiden-ts/src/services/epics.ts Outdated Show resolved Hide resolved
raiden-ts/src/services/epics.ts Outdated Show resolved Hide resolved
raiden-ts/src/services/epics.ts Show resolved Hide resolved
@andrevmatos andrevmatos merged commit 3b17585 into master Aug 3, 2020
@andrevmatos andrevmatos deleted the fix/rdn_approve branch August 3, 2020 17:30
@weilbith
Copy link
Contributor

weilbith commented Aug 4, 2020

Thanks for your adjustment! 🤗

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

Successfully merging this pull request may close these issues.

Concurrent approvals will fail with RDN
2 participants