curve-contract
curve-contract copied to clipboard
Add a Custom Curve Pool Implementation Handling RAI
What I did
Related issue: N/A
This PR adds a new type of Curve pool meant to handle stablecoins with a floating target price such as RAI.
How I did it
All changes and test descriptions can be found here.
How to verify it
You can verify the Quantstamp audit for this pool which can be seen here. Please note QSP#2 that mentions the pool does not update and fetch RAI's redemption price prior to every action because it would be expensive to do so. This means we have to mention this tradeoff to the community.
One more significant thing. Virtual price here is not an invariant and it involves price of RAI going up or down. It will show crazy high positive or crazy high negative apy which is no good. So describing what can be done...
Can make another kind of virtual_price
(virtual_price_2
?) which can (similarly to virtual pool prices) defined as:
balances: uint256[2] = self.balances
xp: uint256[2] = self._xp()
virtual_price_2 = 2 * sqrt(balances[0] * xp[1]) / token_amount
Needs to use sqrt (which can use either decimal
data type which sucks, or be implemented from scratch which we do in crypto contracts).
virtual_price_2 will be close to something between the price of LP token in USD and in RAI which makes sense. And that will behave really smoother than the traditional virtual price.
And still, that stays somewhat an experiment
Ok, more stable is:
virtual_price_2 = virtual_price / sqrt(redemption_price)
who would have thought huh?
We did some improvements to the RAI pool code here (as advised by Michael):
https://github.com/reflexer-labs/curve-contract/pull/5#issuecomment-962275232
These also need a final thumbs up so we can merge here as well.