You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
API that are used to get token prices are not returning accurate prices. The prices are determined by considering the ether balance and token balance (eth_balance / token_balance) of token exchange contract.
For example :
Dai/Sai Uniswapcontract: 0x09cabEC1eAd1c0Ba254B09efb3EE13841712bE14 has 90 eth and 17520 DAI. The price is returned by calculating 90/17520 which is incorrect. Can you please look into this or correct me if i am wrong. Thanks.
Looks like Uniswap uses WETH (wraped ETH) instead of ETH, Does it have to do anything with the above issue? WETH amount should be fetched from the token exchange contract instead of ETH for price calculation in get_eth_token_input_price and other related functions. I am not an expert on this like you are, just posting my thoughts here. Thanks.
This library always assumes the routing token1 -> (w)eth -> token2 for token -> token transactions (on Uniswap v2) and gets the prices directly from the contract (we're not computing prices ourselves here, just asking the contract for the price given a route).
Edit: I now realize the contract you're referring to is Uniswap v1. It's currently at 63.02 ETH and 12349 SAI, which becomes 0.005103247226496073 ETH/SAI, which seems to be correct when checking Coingecko for reference (0.00509591 ETH/SAI). I don't know how Uniswap v1 treats ETH vs WETH, and I'm not sure exactly what you are asking or how the price is incorrect.
Just tested uniswap.get_token_eth_input_price(sai, 1*10**18) / 10**18 which returns something similar (0.005087772161388855), so not sure what you think is wrong here. Closing.
It's a common mistake to make, see for example this issue: #41
Edit: Your wbtc_rate (and others) is also incorrect. If you want the price of 1 WBTC denominated in ETH, you should use: wbtc_rate = uniswap_wrapper.get_eth_token_input_price(wbtc, 10 ** 8) (8 decimals as defined by the WBTC ERC20 contract)
correcting the decimal following contract definition,
this give me:
wbtc_rate = 0
usdc_rate = 0
i tried to increase again the decimal selection and change my conversion func, this seems to give correct result :
Activity
msujithk commentedon Aug 5, 2020
Looks like Uniswap uses WETH (wraped ETH) instead of ETH, Does it have to do anything with the above issue? WETH amount should be fetched from the token exchange contract instead of ETH for price calculation in get_eth_token_input_price and other related functions. I am not an expert on this like you are, just posting my thoughts here. Thanks.
ErikBjare commentedon Sep 25, 2020
This library always assumes the routing
token1 -> (w)eth -> token2fortoken -> tokentransactions (on Uniswap v2) and gets the prices directly from the contract (we're not computing prices ourselves here, just asking the contract for the price given a route).Edit: I now realize the contract you're referring to is Uniswap v1. It's currently at
63.02 ETHand12349 SAI, which becomes0.005103247226496073 ETH/SAI, which seems to be correct when checking Coingecko for reference (0.00509591 ETH/SAI). I don't know how Uniswap v1 treats ETH vs WETH, and I'm not sure exactly what you are asking or how the price is incorrect.ErikBjare commentedon Sep 25, 2020
Just tested
uniswap.get_token_eth_input_price(sai, 1*10**18) / 10**18which returns something similar (0.005087772161388855), so not sure what you think is wrong here. Closing.tryiou commentedon Dec 20, 2020
Hey there, thanks for sharing this work with us, bumping this thread as i get similar problem it seems :
this give me:
1 BAT = 0.23610407627217966 USDT
1 aBLOCK = 18154844558.9239 USDT
1 WETH = 643.893084 USDT
1 USDC = 997933195691.8488 USDT
1 WBTC = 232699612651547.88 USDT
1 UNI = 3.822174314993634 USDT
1 DAI = 3.71318337592881 USDT
BAT, WETH and UNI look correct, aBLOCK,USDC,WBTC look like problem with digits, and DAI seems out, using wrapper with version 2 and infura provider
ErikBjare commentedon Dec 20, 2020
@tryiou That's because your
conversionfunction makes an incorrect assumption about the number of decimals. As an example, WBTC has 8, not 18 (https://etherscan.io/token/0x2260fac5e5542a773aa44fbcfedf7c193bc2c599).It's a common mistake to make, see for example this issue: #41
Edit: Your
wbtc_rate(and others) is also incorrect. If you want the price of 1 WBTC denominated in ETH, you should use:wbtc_rate = uniswap_wrapper.get_eth_token_input_price(wbtc, 10 ** 8)(8 decimals as defined by the WBTC ERC20 contract)tryiou commentedon Dec 20, 2020
thanks for your answer, i'll study this more in depth 👍
tryiou commentedon Dec 20, 2020
testing few more
correcting the decimal following contract definition,
this give me:
wbtc_rate = 0
usdc_rate = 0
i tried to increase again the decimal selection and change my conversion func, this seems to give correct result :
wbtc_rate = 2712959
1 wbtc = 23918.122868793816 USDT
ErikBjare commentedon Dec 21, 2020
Ah, yeah I was wrong about the
get_eth_token_input_priceargument. It should indeed be 10**18.Happy to see you figured it 👍