i have a question about interacting with the Uniswap quoter contract.
I am able to get a quote using quoteExactInputSingle. The method has 1 parameter for the input amount, which works fine when it is an integer like 100
. The contract parameter is a uint
(therefore we must use something equivalent in javascript that can be converted using jsbn/jsbi).
Does anyone know how to get quotes using fractional input amounts instead? E.g. wanting to swap 0.00014 UNI
in javascript:
const amountIn = 0.00014;
await quoterContract.callStatic.quoteExactInputSingle(
token0Address,
token1Address,
poolFee,
amountIn, // The parameter for input amount
0
);
produces:
Error: invalid BigNumber string (argument="value", value="0.00014", code=INVALID_ARGUMENT, version=bignumber/5.7.0)
reason: 'invalid BigNumber string',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: '0.00014'
}
I have tried finding the answer in the uniswap source code:
- front-end, inc. the widgets repo
- AWS router
- their SDK docs
- their guide on making trades
I did notice that the uniswap product multiplies decimal amounts by 20 decimal places (before sending the amount in a http request to their API), which is then converted "back" to a decimal in a smart contract (after they identify the number of decimal places for the input token). This is obviously because the EVM doesn't support fractions, however i can't find an explanation for why the multiplication is done to exactly 20 decimal places.
I do also know about the Token
sdk class, e.g.:
const token = new Token(5, token0Address, 18, 'UNI', 'Uniswap');
However i haven't found a way to use the Token
instance with the quoter contract.