I would like (if possible) to infer a token price from the blockchain using UniSwap data. After reading the following article, I understood that it is feasible:
“The price of a given token on a given exchange can be calculated as the exchange contract's token_balance divided by its ether_balance.”
My first attempt was to check some transaction data, for example this transaction: https://etherscan.io/tx/0x10de93fd474b5c45035ea5d9ef42172ba6026e024cf77275a72c2b291b118a6d
This page explains in a more readable way (for me) the transaction: https://etherscan.io/address/0x2bf5a5ba29e60682fc56b2fcf9ce07bef4f6196f#events
I understand we have:
uint256 tokens_sold 25661215840000000000 uint256 eth_bought 3014603688879169830
So this would mean a ratio of: 25661215840000000000 / 3014603688879169830 = 8.512302 For this token swap NMR / ETH.
This seems close to the current ration between these two tokens (prices from CoinMarketCap this morning): 203.64 / 23.77 = 8.567101
Is this approach correct?
Also, when I look at the same transaction data in BigQuery, I get:
Input = 0x95e3c50b000000000000000000000000000000000000000000000001641ef3d8f7d3c00000000000000000000000000000000000000000000000000029a07940a8276bdd000000000000000000000000000000000000000000000000000000005ecbd296
which I can decompose into:
0x95e3c50b = MethodID
000000000000000000000000000000000000000000000001641ef3d8f7d3c000 = 25661215840000000000 in Decimal This seems fine: I find the same tokens_sold as above.
00000000000000000000000000000000000000000000000029a07940a8276bdd = 2999530670434773981 What is this?
000000000000000000000000000000000000000000000000000000005ecbd296 = 1590416022 What is this?
I am struggling to find the same eth_bought amount as above: 3014603688879169830.
Can someone help?