Cyfrin / foundry-defi-stablecoin-cu

241 stars 107 forks source link

Modifying fuzz tests #91

Closed Aaryan-Urunkar closed 2 months ago

Aaryan-Urunkar commented 2 months ago

Our stablecoin is 200% overcollateralized so in the fuzz tests we must see if the (totalSupply *2) and not totalSupply is lesser than or equal to the collateral.

The assert for our invariant shall be as follows:

assert(wethValue + wbtcValue >= (totalSupply*2));

First official PR. I hope it's not trivial / not well formatted.

PatrickAlphaC commented 2 months ago

Thanks! This isn't quite right though...

The invariant of the protocol is that it "must always be over-collateralized". The reason that we make projects have a 200% collateralization ratio is actually not because the protocol must always have over 200% collateral, that is so that there is a large enough buffer to being below 100% collateralized. This way, when prices drop, liquidators can have time to liquidate before the protocol is under 100% collateralized.

If we say our invariant is "the protocol must always be 200% collateralized or more" then we should move our collateralization ratio to 300%+ so that when prices drop, liquidators can have time to liquidate before the protocol is under 200% collateralized.

Good idea though! I'd glad you went for a PR! Keep up the learning!