Setting specific token spend limits to mitigate risk when using dApps?

EthereumEthereum
$1,343.46
0.29%
20D Ago
self.ethereum
I've been searching for the answer to this for over a year and... crickets.. I feel like I'm asking a forbidden question. Trying again: (Skip to the bottom for the TL;DR version if you wish) Scenario- You wish to swap 500 USDC for ETH via, let's say, UniSwap using your Metamask wallet. (Any DEX or dapp works the same though) Before you can swap you must approve UniSwap to "spend" your USDC in order to receive that value in ETH. By default, one can simply click "Approve" , wait for confirmation, then swap. However, you have just approved UniSwap to spend an UNLIMITED amount of your USDC. If you had 50,000 USDC UniSwap (or a bad actor or contract bug etc) can spend all 50k of your USDC, forever, until you revoke the permission. This is a convenience of sorts so you don't have to keep spending gas every time you visit again for a swap. Ok. Got it. But if you wish, you can "EDIT PERMISSION" and select custom and input 500 USDC specifically, overriding the default "Unlimited". This puts a cap on how much UniSwap can spend in the future. It reduces risk (before you decide to revoke the permission altogether) such that if something happens down the line, and you happen to have 50k USDC in your wallet, it can still only spend 500 USDC at a time. Great! As long as the unit of value is a whole number. But how can one carry out the above process when the amount you wish to approve is a fraction (aka a decimal) less than 1 (or in between whole numbers)? Decimal points aren't accepted in the custom field and I'm guessing this has to do with the uint256 base numbering of the Ethereum language. How to properly convert? Example: You wish to swap 0.123 WBTC for Xx ETH. You have 1 whole WBTC in your wallet but you do not wish to approve the dapp unlimited spend of all your BTC. So you head over to custom, and try to input 0.123 - no bueno! It must be a whole number. I'm assuming a conversion must take place going from WBTC to GWEI or something like that. I simply cannot find any info on how to correctly do this. TL;Dr summary: How do I tell Metamask I only wish to allow a DEX or dapp permission to spend a fractional amount of a token instead of giving the DEX unlimited spend authorization? Example: How to specify 0.123 WBTC max allowance (when I have let's say 1 WBTC in wallet) for a swap to USDC when MM only accepts whole numbers/integers/uint256? Advise? Thx Cheers