enzymefinance / protocol

Enzyme Protocol Implementation
https://enzyme.finance
GNU General Public License v3.0
374 stars 155 forks source link

Price of aUSDT, aDai, aUSDC, etc. fluctuates in calculating vault value #1046

Closed mocolicious closed 3 years ago

mocolicious commented 3 years ago

The price of stablecoins is being tracked based on market value on certain exchanges it looks like instead of using the stable price. This is important because when depositing on the platform 1USDC, 1 USDT, 1 Dai will always give you an equivalent amount of aUSDC, aUSDT, aDai.

SeanJCasey commented 3 years ago

Hey @mocolicious . I'm not clear on if you're reporting an issue in the protocol or with the display of data via the app, so let me briefly explain the way pricing works in the protocol:

If we're purely talking about the prices in the protocol, all stablecoins use Chainlink price feeds. e.g., 1 unit of USDC is worth whatever Chainlink's USDC/ETH price feed reports that it is worth, which is then translated via whatever other price feeds are necessary to get the desired output, e.g., via DAI/ETH if you want to get the rate of USDC to DAI.

In the case of aTokens, each aToken is actually pegged 1:1 with its underlying in our system also, so 1 aUSDC = 1 USDC = whatever Chainlink USDC/ETH says it's worth.

Are you reporting an issue with that paradigm, or maybe the way that those values are interpreted and displayed in our frontend / subgraph?

mocolicious commented 3 years ago

perhaps just a display issue, but the way it appears it shows price, value and daily change of the tokens and then allocation. This morning I was seeing aDai and aUSDT showing about 94cents and its usually around 97-99cents. I'm unsure if it factors into the share price or not but if it does it seems like a major flaw because it could allow people to exploit arbitrage in the fluctuation.

Just checking the price against the chainlink prices it doesn't seem to explain the large discrepancy in price so I'm not sure what's the error. https://data.chain.link/xdai/mainnet/stablecoins/usdc-usd shows little more than a 1/2 cent deviation throughout the day. I'm assuming whatever the issue is its probably having to do with current market volatility.

SeanJCasey commented 3 years ago

The frontend UI/subgraph don't make on-chain calls to fetch prices, so it's likely limited to the display-side, but I'm going to drop this thread in our internal chat to have somebody on the frontend team confirm.

mocolicious commented 3 years ago

awesome! Thanks for looking into this. You're the man @SeanJCasey!

iherger commented 3 years ago

When we are displaying the price of e.g. aUSDC in the frontend, we are using some approximations. These approximations are necessary for performance reasons for the app (i.e. we don't make on-chain calls for asset prices when as user uses the app, but we are loading the prices from our subgraph), and they are also partially required by the subgraph (i.e. prices of derivative assets like aTokens are not continuously updated, but they may have a lag of up to an hour).

Additionally, in order to accommodate prices for all tokens, we always convert through ETH (most tokens only have an ETH based Chainlink price feed). That means, that for display purposes, we are always going TokenX -> ETH -> USD (even if there is a direct Chainlink price feed TokenX -> USD, like in the case of USDC). This can lead to small deviations as well.

All of this, and the yesterday's market volatility, explain the deviations that you saw.

SeanJCasey commented 3 years ago

Hope that's all clear, marking this issue as closed.