0

I am trying to get the price impact of a trade in uniswap sdk and I noticed that the result from the sdk isn't accurate as what was shown on the uniswap webapp. There is 0.3 difference regardless of which token and input value. Where does the 0.3 come from?

Here is my snippet:


const amountIn = '2';
const TOKEN_ADDRESS = '0x30f271C9E86D2B7d00a6376Cd96A1cFBD5F0b9b3';

// swapTokensForExactToken
const TOKEN = new UNISWAP.Token(UNISWAP.ChainId.MAINNET, TOKEN_ADDRESS, 18)
let pair = await UNISWAP.Fetcher.fetchPairData(UNISWAP.WETH[TOKEN.chainId], TOKEN)
let route = new UNISWAP.Route([pair], UNISWAP.WETH[TOKEN.chainId])
const inputToken = web3.utils.toWei((parseFloat(amountIn) * parseFloat(route.midPrice.raw.toSignificant(6))).toString(), 'ether');
     
let trade = new UNISWAP.Trade(route, new UNISWAP.TokenAmount(TOKEN, inputToken), UNISWAP.TradeType.EXACT_OUTPUT)
    

console.log('impact: ', trade.priceImpact.toFixed()) // 1.10
// Uniswap app value 0.80
0

It is likely that one takes into account the 0.3% liquidity provider fee and the other does not.

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.