1inch / spot-price-aggregator

Liquidity-weighted dex price oracle for offchain price discovery
MIT License
273 stars 79 forks source link

Why, in some cases, a spot price aggregator cannot return the price of a token with high liquidity on a well-known exchange. And another time it may return the price of a token with a liquidity of $200 #141

Closed AlwxDavydov closed 5 months ago

AlwxDavydov commented 5 months ago

For example, if we try to fetch price of WSM (0x62694d43ccb9b64e76e38385d15e325c7712a735), it listed on Uniswap, or EVDC(0x93749e69560efe1ad6661903e47df538492c50a4), listed on pancake we will get this answer.

{
  "0x62694d43ccb9b64e76e38385d15e325c7712a735": "0",
  "0x93749e69560efe1ad6661903e47df538492c50a4": "0"
}

But if we try it with some tokens with very low liquidity, for example BOTAI (0x20b2d9f094b7561a4abbcf8a2b88938b779c986d), liquidity in which does not exceed $200, we have correct answer

{
"0x20b2d9f094b7561a4abbcf8a2b88938b779c986d": "0.00002475886904925149",
}

I also leave curl here for you to check it up

curl -X GET \
      "https://api.1inch.dev/price/v1.1/56/0x93749e69560efe1ad6661903e47df538492c50a4,0x62694d43ccb9b64e76e38385d15e325c7712a735,0x20b2d9f094b7561a4abbcf8a2b88938b779c986d?currency=USD" \
      -H "Authorization: Bearer " \ # put key here
      -H "accept: application/json" \
      -H "content-type: application/json" \
zZoMROT commented 5 months ago

Thank you for your interest in our repository and for bringing up this issue.

Regarding the WSM token, it appears that there are liquidity pools on both UniswapV3 and PancakeV3. For the PancakeV3 pool, the liquidity is zero, which explains why the price is also zero. Moreover, it seems like UniswapV3 is not integrated into the OffchainOracle on BSC network, which is indeed an oversight. We will aim to address this and add support as soon as possible.

As for the EVDC token, our OffchainOracle does return a non-zero value for the getRateToEthWithThreshold method using the parameters (0x93749e69560efe1ad6661903e47df538492c50a4, true, 10). There could be a possibility that this token is on a blacklist so API doesn't return the price - it might be worthwhile to confirm this with our support team. I will also inquire internally about this issue and update this thread if I find out why the API is returning a zero price.

zZoMROT commented 5 months ago

Right now the contract of OffchainOracle returns prices for all tokens you mentioned

Снимок экрана 2024-04-18 в 21 30 52 Снимок экрана 2024-04-18 в 21 31 08 Снимок экрана 2024-04-18 в 21 31 29
AlwxDavydov commented 5 months ago

@zZoMROT Yes, I checked and the WSM coin is now displayed. But I want to understand the logic of why this happens, and not the specific decision for these coins. I'm using 1inch API and for example I still can't get EVDC. Here is a picture of response

Screenshot_73

There are also many more coins that have liquidity but are not displayed in 1inch api. What should I do with them?

zZoMROT commented 5 months ago

There could be several reasons why the API does not return a price for a specific token. Some of these reasons may relate to how the SpotPriceAggregator functions, which necessitates an understanding of its operational mechanics. The SpotPriceAggregator assesses the price of one token against another using available DEXs, both directly and through connectors, if direct liquidity is lacking. You can find a list of supported DEXs and connectors in the README or on the 1inch documentation site for any network. This oracle might not detect the price of a token if it fails to find any liquidity pools (as with the WSM token mentioned in this issue) or if it does not recognize the rules by which the token is wrapped/unwrapped.

Regarding API issues, it's important to note that the software interacting with the SpotPriceAggregator uses various methods to fetch price data. When using the SpotPriceAggregator, it requests the price of a token relative to another token. This process involves several nuances: since there is no USD in crypto, the system may use stable token families (e.g., USD-, EURO-) or native tokens as bases for querying the prices of the requested token. The API might not return a price if the only available pool contains an unpopular token paired with the requested token. There might also be blacklists or other similar restrictions in place, I don't sure about it.

If the SpotPriceAggregator returns the price of a token you are interested in, but the API does not, the best way of action is to seek assistance from support or to post your query on the developer forum.

AlwxDavydov commented 5 months ago

@zZoMROT I have encountered many times that the spot-price-aggregator cannot return the price of the token, but if you check the swap function for 1inch, the price will be displayed. What is the problem in this case and how can it be solved? For example this token - 0x6ded0f2c886568fb4bb6f04f179093d3d167c9d7

With aggregator:

Untitled

With 1inch: U1ntitled

I found this confusing. Cause this token has liquidity and can be swapped with 1inch. But not displayed with aggregator.

zZoMROT commented 5 months ago

The key difference lies in the fact that these are two distinct services: one for determining token prices and another for finding the best swap paths. The path-finding service is specifically designed to identify the best possible trade for a user by exploring various sources of liquidity. On the other hand, the price determining service operates somewhat differently, and I can only speak for the part that interacts with the SpotPriceAggregator – this part follows a completely different architecture with a simpler algorithm.

The price service queries the contract for the prices of the target token against specific tokens (such as ETH, BNB, USDT, USDC, etc., actually it's depends on service settings) through the SpotPriceAggregator. It then analyzes the data received and displays the result based on these inquiries. It’s important to note that the data obtained from the SpotPriceAggregator directly depends on the particular token against which the target token’s price is being searched and the settings of the main SpotPriceAggregator contract (like the connectors, wrappers, and supported DEXs used). As a result, some tokens may have liquidity but their prices might not be displayed on the website. It's why some tokens with their liquidity could be losed when their liquidity in pools with unpopular tokens or with unsupported DEXs.

Meanwhile, the algorithm that calculates the swap paths is much more complex and operates differently. Therefore, when it finds a trade route, the website can show how many tokens the user will receive as a result of the exchange. However, the independent price determining service might not display the token price in dollars at the same time due to the reasons mentioned above.

zZoMROT commented 5 months ago

For instance, regarding the DFL token you mentioned, there is liquidity available in the PancakeSwapV2 pool with the BSC-USD token. This DEX is supported, and the BSC-USD token acts as a connector, so everything should work fine. Indeed, it does work with the SpotPriceAggregator, as the contract returns a non-zero price. I'm not sure why the API and website are showing a zero value. I suspect it might be related to the issue you've raised here.

Снимок экрана 2024-04-22 в 20 35 33
AlwxDavydov commented 5 months ago

@zZoMROT Then is there any way to inform the developers about this error and fix it. Because there are many large tokens that are not displayed in the aggregator, for an unknown reason (they have a well-known token in the pair and a popular exchange).

zZoMROT commented 5 months ago

I've already reported this issue to the developers, and they were supposed to fix it. I checked the tokens mentioned here, and both the website and API now return their prices correctly. If you're still experiencing issues with other tokens, please let support know which ones.

AlwxDavydov commented 5 months ago

@zZoMROT Yes, I checked it now and literally 2 hours ago everything started working much better. Thanks you. I'll let you know if I come across any tokens with errors. Now I noticed error only with this - 0x0dcee5f694e492f0dd842a7fbe5bed4c6e4665a6. But this error is code 400, so I think it is temporary problem, not sure.

zZoMROT commented 5 months ago

Yes, I checked it now and I see that for some reason the website and API don't recognize the token at this address on the BSC network with error:

{"error":"Bad Request","description":"Bad tokens","statusCode":400,"meta":[{"type":"address","value":"0x0dcee5f694e492f0dd842a7fbe5bed4c6e4665a6"}]}

I recommend reaching out to the support team with this issue. They should be able to provide more specific and faster assistance than simply waiting for a potential fix.