curve-contract icon indicating copy to clipboard operation
curve-contract copied to clipboard

Add a Custom Curve Pool Implementation Handling RAI

Open stefanionescu opened this issue 3 years ago • 4 comments

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.

stefanionescu avatar Oct 20 '21 16:10 stefanionescu

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...

michwill avatar Nov 02 '21 11:11 michwill

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

michwill avatar Nov 02 '21 11:11 michwill

Ok, more stable is:

virtual_price_2 = virtual_price / sqrt(redemption_price)

who would have thought huh?

michwill avatar Nov 02 '21 15:11 michwill

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.

stefanionescu avatar Nov 17 '21 02:11 stefanionescu