I am recreating a UNISWAP-like AMM and have encountered problems anytime I want to divide the balances of tokens in my pool. For example: I want to
require() that tokens are deposited in the correct ratio (Total number of token 1/Total number of token 2). If I do this I can encounter 2 problems:
- either the result is 0<x<1 and I get 0 which stops all further calculations
- or the result is rounded down to an integer which is a significant calculation error
I hoped using larger numbers (18 decimals) would solve this problem but it hasn't, I also don't want to use external libraries, other than safeMath. What can I do to solve these problems? Thanks!