For minting, burning of synths and swaps, the fee and output amounts are calculated separately via calcSwapOutput and calcSwapFee. To avoid rounding errors and duplicate calculations, it would be best to combine both of these functions and return both outputs at once.
For example, if we take x = 60000, X = 73500, Y = 50321, the actual swap fee should be 10164.57 and output 12451.6. However, calcSwapOutput and calcSwapFee returns 10164 and 12451, leaving 1 wei unaccounted for. This can be avoided by combining the calculations as suggested below. The fee and actual output will be 10164 and 12452 instead.
Functions that have to call calcSwapOutput within the contract (eg. calcSwapValueInBaseWithPool) should call this function as well, for calculation consistency.
In addition, calculations for both calcSwapOutput and calcSwapFee will phantom overflow if the input values become too large. (Eg. x = 2^128, Y=2^128). This can be avoided by the suggested implementation below using the FullMath library.
The FullMath library is included (and made compatible with sol 0.8+) on the issue page for convenience.
