Pretty dumb question here, possibly easy to answer, I'm trying to calculate 3% fee for uniswap:
With general approach 15 ether + 15 ether * 0.03 = 1504500... which is not enough from what I see.
But in sample I see the div approach is used 15 ether / .997 = and result will be bigger then previous one.
Can someone explain is div approach is general for solidity contracts?

Oct 5, 2023, 1:42 PM
floating numbers cannot be used in solidity, you can *1eth at the start and /1eth at the end to raise precision (final number should be the same
Oct 5, 2023, 2:03 PM
yes, that's correct, but both approaches to calculate 3% fee will give different results, and looks like second one is correct and first one is not(uniswap will throw an error)
it's not even about solidity calculation itself frankly speaking
Oct 5, 2023, 2:09 PM
you can bootstrap a simple example on remix.ethereum.org
a simple contract with one function to do what you want to do
try to make it and send the screen here + what is your goal
Oct 5, 2023, 2:11 PM
Because its 0.3%, not 3%
997/1000 = 99.7% = 0.3% fee
Oct 5, 2023, 3:03 PM
here is an example
and during work with uniswap I get an error because first value wasn't enough
so that's the question, is it common to use second way?
my mistake in description, but overall in the code i didn't make it
Oct 5, 2023, 3:10 PM
Ah ok
Hmm so first you're doing
15 eth + 15 eth * 3 / 1000

And on second its
(15 eth / 997) * 1000
Both are obviously different...
Oct 5, 2023, 3:19 PM
yes, that's the trick, overall in real life with low precission both works fine, but with 18 zeros they are pretty different
Oct 5, 2023, 3:36 PM

© 2024 Draquery.com All rights reserved.