1inch / spot-price-aggregator

Liquidity-weighted dex price oracle for offchain price discovery
MIT License
261 stars 80 forks source link

Which price does spot-price-aggregator returns, last, ask or else? #93

Closed AlwxDavydov closed 10 months ago

AlwxDavydov commented 10 months ago

I fetch price data of coin AGI (0x818835503F55283cd51A4399f595e295A9338753) using price for requiested tokens(https://portal.1inch.dev/documentation/spot-price/swagger). And 1inch api return this image At the same time on 1inch web price is a bit different image The price of last deal is also different image Moreover, when it comes to pancake, the price of LP tokens is also distinct. Consequently, I find it challenging to determine which price the requested tokens will return. I believe that the difference in the USDT-USD price has a minor impact, as on the Binance Smart Chain (BSC), USDT currently equals 0.9998 USD, and the difference is relatively small at present. It's worth noting that in all my price calculations, I've consistently used the USDT price for AGI, always considering it as 1 USDT. Additionally, it's possible that the quantity of coins for the swap could influence the price, although this is not the case here. Furthermore, this matter has already been addressed in an open ticket.

I also want to mention that I picked AGI cause it only has one pair on defi (on pancake with USDT). Thats why the situation is not clear to me. How can 3 sources receiving the price from the same path have 3 different numbers

zZoMROT commented 10 months ago

When you pull token prices through the 1inch API, the service, using OffchainOracle, initially pegs the price to WETH (or WBNB for your BSC network scenario). Then, this figure is scaled by the price of ETH (or BNB for the BSC network) in US dollars. Given that the prices of ETH and BNB are notoriously volatile and in constant flux, you’re likely to see subtle discrepancies in prices at different moments in time.

The discrepancies in prices that you notice between the API, the 1inch website, and other sources, can arise due to this volatility, and also because different sources acquire and update their pricing data differently. This may include variations in calculation methods, liquidity, and trading volumes across different platforms and liquidity pools. However, since you mentioned that there is only one pool with your token, this does not apply to your situation, but bear this in mind in other instances.

For obtaining the most precise and up-to-the-minute price data that isn’t swayed by fluctuations in the dollar exchange rate, I suggest using the getRate method in OffchainOracle. You can execute this directly in the bscscan explorer or programmatically, but don't use it onchain. This approach enables you to gauge the price of any token relative to another, thereby minimizing potential disparities and incongruities in prices amongst different services and sidestepping inaccuracies in the crypto-to-dollar valuation.

zZoMROT commented 10 months ago

Responding to the main question of the issue: The SpotPriceAggregator returns the weighted price of one token to another at the current moment, taking into account various protocols (which can be viewed in the README of this repository and 1inch docs page) and settings (such as the connectors used, wrappers used, and a threshold filter that allows disregarding pools with low liquidity and incorrect rate).