Skip to content

PSM#261

Merged
Joeysantoro merged 40 commits intofeat/v2/basefrom
feat/v2/psm
Nov 14, 2021
Merged

PSM#261
Joeysantoro merged 40 commits intofeat/v2/basefrom
feat/v2/psm

Conversation

@ElliotFriedman
Copy link
Contributor

@ElliotFriedman ElliotFriedman commented Oct 21, 2021

The PegStabilityModule is a contract that combines the ReserveStabilizer and the BondingCurve contract into a single smart contract. All excess reserves will be sent to the Balancer pool to earn yield.

There are two different PSM's, one is for DAI and is called the PriceBoundPSM, and the other is for ETH. The DAI PriceBoundPSM has a feature that stops all swapping when the the price of DAI is above $1.02 or below $0.98. This feature protects FEI from a worst case scenario where DAI loses its peg. When the DAI price is above $1.02 or below $0.98, buying and selling will be paused until the price returns to the acceptable range.

The ETH PSM allows users to buy and sell FEI denominated in ETH. This module has no oracle safety feature.

Both contracts can have minting and redeeming paused by guardian or governor.

Done

  • PSM
  • PriceBoundPSM
  • PriceBoundPSM Unit Tests
  • Eth Router

@ElliotFriedman ElliotFriedman changed the base branch from develop to feat/v2/base October 21, 2021 23:20
@ElliotFriedman ElliotFriedman changed the base branch from feat/v2/base to develop October 21, 2021 23:21
@ElliotFriedman ElliotFriedman changed the title PSM [WIP] PSM Oct 21, 2021
@ElliotFriedman ElliotFriedman changed the base branch from develop to feat/v2/base October 21, 2021 23:23
Comment on lines +47 to +48
function setExchangeRateScaledBase(uint256 usdPerEth) public {
price = Decimal.D256({ value: usdPerEth });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier to have this function take in two unscaled parameters and use a ratio maybe? Nbd

Copy link
Contributor

@Joeysantoro Joeysantoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a bunch of comments. I don't think this PR should include any other contracts mentioned in the TODO. I haven't reviewed unit tests yet

Copy link
Contributor

@Joeysantoro Joeysantoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks really good! Left a few more organizational comments

Copy link
Contributor

@xklob xklob left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments; also, I don't see any admin role-assignment happening, unless I missed something?

Copy link
Contributor

@Joeysantoro Joeysantoro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed one of the tests, assume the same comments apply to the ERC20 one.

Will review that one on my last pass. Last comment is the tests should look for events and event args more

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matter of style, do you think duplicating the logic in the test is sufficient, or is it better to supply an exact amount so that we aren't missing the situation where both logics are incorrect?

I find it helpful to be explicit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add tests where I calculate things out by hand before I run them and just use those constants in the tests.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a test for after changing fee as well

Comment on lines 331 to 336
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is confusing me, shouldn't end - start be equal to the surplus not the threshold? Also assert that the PSM holds exactly threshold at the end.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, start - end should equal the threshold as everything greater than the threshold got subtracted.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check it does nothing when below threshold

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this an ERC20 error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there is no approval done before redeem is called. This test isn't named well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can governance change the max?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove the governor's ability to do this. I added this on the off chance that we want to change the max fee in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to leave it in. Fine either way though.

@xklob xklob changed the title [WIP] PSM PSM Nov 10, 2021
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove .only


/// @notice helper function to determine if price is within a valid range
function _validPrice(Decimal.D256 memory price) internal view returns (bool valid) {
valid = price.greaterThan(Decimal.ratio(floor, Constants.BASIS_POINTS_GRANULARITY))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use GTE & LTE here, instead of just GE & LE?

@Joeysantoro Joeysantoro merged commit efa5e4f into feat/v2/base Nov 14, 2021
@Joeysantoro Joeysantoro deleted the feat/v2/psm branch November 14, 2021 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments