I'm calling UNISWAP SDK to price a trade on pair like USDC, PAX and getting significantly worse results than the UX:
const sourceToken = new Token(ChainId.MAINNET, source_token_address, source_token_decimals);
const sourceAmount = new TokenAmount(sourceToken, source_amount);
output_amount = await uniswap_token_pair.getOutputAmount(sourceAmount);
const final_output_val = web3.utils.toBN(output_amount[0].raw.toString());
console.log(UNISWAP output ${pair_name} raw= ${output_amount[0].raw.toString()} num=${bn_to_number(final_output_val, target_token_decimals)});
return final_output_val;
I'm assuming that it's because the WebSite chooses a multi-hop route USDC=>ETH=>PAX. How do I do this in the SDK without having to myself explictily craft the route -- i.e I basically want it to figure out the best route from me just like the web site does? I can't see a param anywhere to have the SDK do a multihop.?
multicallwith all the LPs of existing tokens. My idea is they maintain a database of all pairs, and then use the multicall contract to get every price of every LP for said token. – bru53001 Jul 02 '21 at 18:18