umbra-protocol icon indicating copy to clipboard operation
umbra-protocol copied to clipboard

Send native token max without dust

Open davidlaprade opened this issue 3 years ago • 4 comments

Fixes #378

umbra-send-max-improvements

davidlaprade avatar Sep 11 '22 17:09 davidlaprade

Deploy Preview for jolly-shaw-20fe62 ready!

Name Link
Latest commit 1e088d3690e501294c0937a0766fe8f4f6df49d1
Latest deploy log https://app.netlify.com/sites/jolly-shaw-20fe62/deploys/64136c83e501a900088de284
Deploy Preview https://deploy-preview-390--jolly-shaw-20fe62.netlify.app
Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

netlify[bot] avatar Sep 11 '22 17:09 netlify[bot]

Test failure does not appear to be related to this PR. It's also failing on master

image

davidlaprade avatar Sep 12 '22 14:09 davidlaprade

Mainnet max estimate seems a bit high. Not enough eth left to pay for market gas price. image

garyghayrat avatar Sep 12 '22 19:09 garyghayrat

Mainnet max estimate seems a bit high

Interesting. I'm really glad you checked on mainnet! I actually hadn't. (I needed to republish my keys and I was too lazy/cheap to do it before now. 😅) But since I fixed my mainnet setup, I'm actually seeing the opposite -- estimates are too low:

image

What fee estimate are you seeing in metamask on mainnet @garyghayrat? This is what I'm currently seeing (on 9/12/22 ~3:45pm ET):

image

I added some logging and it seems like our mainnet estimates are actually consistently 20% too low, even with the 10% scale factor applied. I'm not sure why that is.

Metamask's estimated gas limit is ~64k for a mainnet sendETH:

image

And ours is 70671 -- exactly 10% higher than metamask's (as expected, given the scale factor). So the issue seems to be with gas prices.

Sure enough, the MM max gas fee is ~11% higher than what we're getting from our provider. And based on https://www.blocknative.com/gas-estimator theirs is correct. I'll need to look into this

davidlaprade avatar Sep 12 '22 20:09 davidlaprade

@apbendi I was just able to reproduce the error on Arbitrum

image

I ultimately got it to work (send tx here) by bumping the native send gas limit but tbh I'm not sure why it was a problem to begin with. The gas used by the tx (372,580) was well under the original estimate (461,905). It seems that this might be an issue with metamask? Unclear. But I bumped the scale factor estimateNativeSendGasLimit for arbitrum by an additional 5% (10% total) and that seemed to fix the issue.

I was also able to reproduce on optimism. Optimism fees are just weird, so there was a real fix needed here. I have to get more OETH before I can test that the fix works though.

I wasn't able to reproduce the issue on mainnet. I was able to drain an account without issue. Could you re-confirm you have this problem?

davidlaprade avatar Nov 18 '22 20:11 davidlaprade

Hey @davidlaprade, I gave this another look and tested out both Arbitrum and Mainnet. The "allowance" errors on Arbitrum are gone, however now both networks show this message in MetaMask:

Screen Shot 2022-11-21 at 9 31 28 PM

This is the error I see when MetaMask is on "Market", which is the default. If I switch it to "Low", I'm able to confirm the transaction. So it seems maybe the price estimate for gas is just a bit lower than what MetaMask ends up using. Is there a way we can bump it up?

apbendi avatar Nov 22 '22 02:11 apbendi

LCOV of commit 367cf01 during CI #349

Summary coverage rate:
  lines......: 81.4% (506 of 622 lines)
  functions..: 72.5% (79 of 109 functions)
  branches...: 77.8% (260 of 334 branches)

Files changed coverage rate:
                                                       |Lines       |Functions  |Branches    
  Filename                                             |Rate     Num|Rate    Num|Rate     Num
  ===========================================================================================
  umbra-js/src/utils/utils.ts                          |86.9%    160|80.0%    15|72.3%    101

github-actions[bot] avatar Jan 04 '23 20:01 github-actions[bot]

@apbendi I just rebased on top of master and retried max sends on mainnet and arbitrum, per:

I gave this another look and tested out both Arbitrum and Mainnet. The "allowance" errors on Arbitrum are gone, however now both networks show this message in MetaMask

I didn't get any errors. Native token max sends worked without issue on both networks for me.

This is the error I see when MetaMask is on "Market", which is the default. If I switch it to "Low", I'm able to confirm the transaction

This comment makes me wonder what your MetaMask settings are. I can't even see Market vs Low options unless I switch on an experimental feature (see screenshot). But actually even with this feature switched on I still had an arbitrum max send work without issue.

At this point I think it'd be helpful to hop on a call so I can see what you're seeing.

image

davidlaprade avatar Jan 04 '23 20:01 davidlaprade

Alright @apbendi @mds1, I think I finally figured out the remaining issues we were having. I just rebased on master (again) and I think this is ready for re-review.

I have now tested:

  • native token max sends (all 4 supported networks)
  • native token partial sends (all 4 supported networks)
  • ERC20 token max sends (polygon)
  • ERC20 token partial sends (polygon)
  • receive native token (all 4 supported networks)
  • receive ERC20 (polygon)
  • native token max sends on the release preview (all L2s)

Everything worked!

cc @garyghayrat as there is one new string to translate

davidlaprade avatar Mar 10 '23 22:03 davidlaprade

Coverage after merging send-native-token-max-without-dust-#378 into master will be

86.13%
Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
contracts-periphery/src
   UmbraBatchSend.sol93.55%100%75%94.74%85
   UniswapWithdrawHook.sol77.78%100%50%80%44
umbra-js/src
   ethers.ts74.58%100%58.33%100%
   types.ts50%100%0%100%
umbra-js/src/classes
   KeyPair.ts98.65%96.49%100%100%31–32
   RandomNumber.ts100%100%100%100%
   StealthKeyRegistry.ts100%100%100%100%
   TxHistoryProvider.ts85.71%86.67%66.67%87.50%11, 26, 46, 50, 8
   Umbra.ts79.77%74.19%76%83.66%134–135, 211–212, 212–213, 222–223, 241, 287–290, 352, 360, 360–362, 364, 366, 386, 386, 386–387, 392–393, 396, 399, 415, 432–433, 481, 515, 532, 545–546, 556–557, 580–581, 657, 660, 660, 660, 663, 670, 670, 677, 681, 681, 681–682, 695, 699, 702–703, 709–711, 718, 718, 718–721
umbra-js/src/utils
   cns.ts50%33.33%50%55%33–36, 40, 40, 40, 40, 40–41, 44–46
   constants.ts100%100%100%100%
   ens.ts38.89%25%33.33%44%26–27, 35, 56–57, 57, 57–58, 63–64, 66, 70, 70, 70, 70, 70–71, 75–77
   utils.ts80.58%72.03%81.25%86.29%102, 120–121, 168, 221, 235–236, 236, 236, 259, 261–262, 271, 271, 271–272, 274, 277, 286–287, 331, 331, 331, 351, 380, 382, 387, 399, 399–400, 405, 407–408, 419–423, 429, 431, 473–474, 474, 474–476, 476, 476, 576, 58, 581, 59, 84, 92, 94–96
umbra-js/test
   testPrivateKeys.ts100%100%100%100%
   utils.ts100%100%100%100%

github-actions[bot] avatar Mar 10 '23 22:03 github-actions[bot]