5

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.?

3
  • 1
    I have no idea about this myself, but tracing the HTTP requests made in the UI, it calls a contract called multicall with 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 2, 2021 at 18:18
  • @bru53001 do you have an address for the multicall Contract ? Jul 3, 2021 at 13:26
  • You can find it here.
    – bru53001
    Jul 3, 2021 at 16:07

1 Answer 1

5
Trade.bestTradeExactIn(
    pairs: Pair[],
    amountIn: TokenAmount,
    tokenOut: Token,
    { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {}): Trade[]

Given a list of pairs, a fixed amount in, and token amount out, this method returns the best maxNumResults trades that swap an input token amount to an output token, making at most maxHops hops. The returned trades are sorted by output amount, in decreasing order, and all share the given input amount.

ref: https://docs.uniswap.org/sdk/2.0.0/reference/trade#besttradeexactin

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.