Skip to content
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

Collateralization Memoizer #157

Merged
merged 5 commits into from
Sep 11, 2021

Conversation

eswak
Copy link
Contributor

@eswak eswak commented Sep 7, 2021

This PR adds a new contract to cache calls to the CollateralizationOracle

contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved
contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved
contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved
contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved
contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved
}

// @notice returns true if the cached values are outdated.
function isOutdated() external override view returns (bool outdated) {
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 this function should use early returning liberally to simplify the logic

Copy link
Contributor

Choose a reason for hiding this comment

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

This method should split in two, isOutdated returning the time condition only and a second called isExceededDeviationThreshold

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 did not use early returns, since the function is intended to be called offchain only, I kept the code as simple as possible without too much branching

contracts/oracle/CollateralizationMemoizer.sol Outdated Show resolved Hide resolved

require(_validityStatus, "CollateralizationMemoizer: CollateralizationOracle reading is invalid");

Decimal.D256 memory _thresholdLow = Decimal.from(10_000 - deviationThresholdBasisPoints).div(10_000);
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think a helper method would be cleaner but this looks fine so I won't die on that hill

int256 protocolEquity,
bool validityStatus
) {
bool fetchedValidityStatus;
Copy link
Contributor

Choose a reason for hiding this comment

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

this fetchedValidityStatus isn't used

Copy link
Contributor Author

@eswak eswak Sep 10, 2021

Choose a reason for hiding this comment

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

resolved in 491fff8, it was a bug

Decimal.D256 memory _thresholdLow = Decimal.from(10_000 - deviationThresholdBasisPoints).div(10_000);
Decimal.D256 memory _thresholdHigh = Decimal.from(10_000 + deviationThresholdBasisPoints).div(10_000);

obsolete = paused();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refactor the obsolete logic to use a helper method or at least be more transparent?
Parsing this isn't easy.

Copy link
Contributor

Choose a reason for hiding this comment

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

Will merge as is and add a refactor in another PR

@Joeysantoro Joeysantoro merged commit a98a5d1 into fei-protocol:feat/v2 Sep 11, 2021
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