-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Collateral TWAP price miscalculation #830
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
You have been unassigned from the bounty @pavlovcik |
Hey, yes |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
No progress was made, I will try to find the root cause and hopefully fix this. |
I think I found a way to implement this correctly.
...
Last available price gives for 100 LUSD collateral about 90.388 3CRV tokens which seems correct when fee is included. I need to think over how to implement a test. likely I will create LUSD Curve MetaPool mock with values, so that forking will not be needed in forge. From balances and time delta we will get VWAP price using two pairs of get_price_cumulative_last and elapsed time. I will describe the calculations in a detail and open a PR tomorrow morning. |
Do you have any updates @gitcoindev? If you would like to release the bounty back to the DevPool, please comment |
I will try to finish by tomorrow EOD, just wrapping up an another PR. |
In the end I am going to implement also chainlink oracle support for any collateral in scope of this ticket which is half baked already on my local set up. |
Yes, there is no need to overengineer the solution, chainlink is fine. As a part of the current issue we were expecting:
|
I will try to finalize this tomorrow till EOD. |
@@ Need to reimplement penalty system @@ |
+ Evaluating results. Please wait... |
@@ Need to reimplement penalty system @@ |
+ Evaluating results. Please wait... |
@@ Need to reimplement penalty system @@ |
+ Evaluating results. Please wait... |
@pavlovcik i thoght we'd nailed the private key bug? |
I'm not sure. To be honest I never felt mastery around the X25519 key related feature so it's possible that I'm making a mistake in the configuration. |
I've just successfully decrypted this private key for the
Yes
This is public key, not private, so it is safe to share it. Naming could've been better.
Yes. The only risk is that if
No. Partners encrypt with
You've already proposed that we need critical env variables rotation mechanism and |
Sorry for clouding the conversation on this with debugging the bot! @rndquu @gitcoindev @molecula451 I have concerns around using Chainlink and censorship resistance. Chainlink is a centralized point of failure for the protocol. Why not use the on chain TWAPs instead? Perhaps we can have a planned upgrade sometime in late 2024 to change the oracle(s)? |
Indeed a well thought chainlink it's a heavily centrilized organization which the only good thing they provide it's infrastructure as a service and well known set of poketing of smart contracts, and use cases in with heavily demanded protocols that are using it, but that's it |
ChainLink is an industry standard but yes, this should not be a single point of failure. When I started working on TWAP I realized the security implications of using just TWAP, and expected some findings from the audit as well. We should think this through. Since the contracts were partially based on Frax I had a look at latest oracles there and their implementation is very good in this matter. https://docs.frax.finance/frax-oracle/frax-oracle-overview The executive summary is as follows: to retrieve frxEth / ETH price they use dual oracles that combine ChainLink and Uniswap V3 TWAP feeds into one feed, provided lowest and highest prices from those two. In their case for frxEth price is bounded to be 0.7 at the lowest (0.7 frxEth = 1 ETH) and 1 at the highest (1 frxEth = 1 ETH). On top of that they have implemented a Frax Oracle contract that uses feeds from above dual oracles for different pairs and different networks. If one of the price providers in dual oracle fails / is stalled or censored, the second price will be used. Perhaps some blogs or articles explain this in more detail. The oracles implementation repository was created around 4 months ago https://github.com/FraxFinance/frax-oracles I think it also might be beneficial to dig into Sherlock past contests to see if they already audited those oracles or some other projects that use them and the findings they had. If no such audits are available we could as well try to find other approaches for oracles from past security audits and try to create an overview of the available most secure solutions. Then pick one and upgrade the current solution. |
We'll gradually move to smth like "take the median price from chainlink, curve, uniswap, other oracle provider". Right now chainlink is the fastest to implement, safest and most reliable solution. |
+ Evaluating results. Please wait... |
+ Evaluating results. Please wait... |
We have the UbiquityPoolFacet contract (which uses LibUbiquityPool library under the hood) which is responsible for minting/redeeming Dollar tokens for collateral.
Example:
Now check this test. It basically simulates the calcMintDollarAmount() method responsible for calculating how much Dollars should be minted/redeemed in exchange for collateral tokens.
The calculation seems to be wrong because when we try to get the collateral price in USD here
ubiquity-dollar/packages/contracts/src/dollar/libraries/LibUbiquityPool.sol
Line 438 in 7a70182
~239561778028138198.47
Dollars which is way too highAs a part of the current issue we should add a new method to the oracle faucet which will be responsible for fetching collateral token prices in USD.
Possible options:
The text was updated successfully, but these errors were encountered: