Skip to content

Sip 75 keeper isynths phase one #669

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

Merged
merged 39 commits into from
Aug 22, 2020
Merged

Conversation

jjgonecrypto
Copy link
Contributor

@jjgonecrypto jjgonecrypto commented Aug 17, 2020

Considerations

  • Rename ExchangeRates canFreezeRate() to isInverseRateAtBounds() which is more accurate
  • It could be better to return the inverse pricing struct, if any, in the ExchangeRates helper view

Ancillary Tasks

  • Update of SIP-75 with minor specification changes (to IExchangeRates)
  • Removal of all centralized oracle code (coming in a separate PR)
  • Add view to allow reverse lookup of address aggregator to bytes32 (see 2) below).

Notes

  1. ExchangeRates.RatesUpdated no longer has inverse rate emitted but rather the companion long rate (to align it with AnswerUpdated). This event will be removed altogether in a separate PR
  2. This change will require co-ordination with synthetix-subgraph to ensure that AnswerUpdated events on long synths cause a RateUpdate to the inverse (will require a reverse lookup on ExchangeRates - something like currenciesUsingAggregator(address aggregator) external view returns (bytes32[] currencies) to determine if a given aggregator update impacts an inverse

jjgonecrypto and others added 30 commits August 10, 2020 14:31
…etixio/synthetix into sip-76-warning-flags-invalid-rates
@codecov
Copy link

codecov bot commented Aug 19, 2020

Codecov Report

Merging #669 into develop will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop     #669   +/-   ##
========================================
  Coverage    99.52%   99.52%           
========================================
  Files           51       51           
  Lines         3165     3191   +26     
  Branches       422      428    +6     
========================================
+ Hits          3150     3176   +26     
  Misses          15       15           
Impacted Files Coverage Δ
contracts/BinaryOptionMarketManager.sol 100.00% <100.00%> (ø)
contracts/ExchangeRates.sol 98.78% <100.00%> (+0.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15ae9b2...d1ce697. Read the comment docs.

@jjgonecrypto jjgonecrypto marked this pull request as ready for review August 19, 2020 05:45

_setRate(currencyKey, freezeAtUpperLimit ? upperLimit : lowerLimit, now);
inversePricing[currencyKey].frozenAtUpperLimit = freezeAtUpperLimit;
Copy link
Contributor

@jacko125 jacko125 Aug 20, 2020

Choose a reason for hiding this comment

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

Is the intention here to reset both frozenAtUpperLimit and frozenAtLowerLimit to either false / true regardless during the resetting process? Ie, if frozenAtUpperLimit || frozenAtLowerLimit was true, we want them to be false after.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When setInversePricing is called, it can be frozen upper, lower, or not at all. Keep in mind this function is used both a) when repricing a synth and b) populating a new ExchangeRates to replicate the state in an older one, hence the need, on occasion, to be able to set an inverse as frozen directly.

for (uint i = 0; i < aggregatorKeys.length; i++) {
bytes32 currencyKey = aggregatorKeys[i];
if (address(aggregators[currencyKey]) == aggregator) {
currencies[count++] = currencyKey;
Copy link
Contributor

Choose a reason for hiding this comment

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

@justinjmoses Is it going to be possible to have multiple currencies / prices based off the same aggregator address?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, so for example ETHUSD will support both sETH and iETH

Copy link
Contributor

@jacko125 jacko125 left a comment

Choose a reason for hiding this comment

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

Some points where gas efficiency can be improved for getting rates.

@jjgonecrypto
Copy link
Contributor Author

RFAL

Copy link
Contributor

@eternauta1337 eternauta1337 left a comment

Choose a reason for hiding this comment

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

Looks good. Only left minor comments.


uint rate = _getRate(currencyKey);

if (rate == inverse.upperLimit || rate == inverse.lowerLimit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

By this code, I'm assuming that _getRate(...) returns a value bounded within the price limits. Even if that's the case, to improve readability and have a cero cost sanity check, use <= and >= instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted. I will adjust.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually then it will think 0 is a valid lowerLimit and it should not be. 0 will be returned for an inverse that has no underlying rate, and in which case it should not be frozen. I will add that condition as well

@@ -1031,18 +1033,19 @@ const deploy = async ({
) {
if (oldExrates.options.address !== addressOf(exchangeRates)) {
const freezeAtUpperLimit = +w3utils.fromWei(currentRateForCurrency) === upperLimit;
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider that Number.MAX_SAFE_INTEGER + 1 === Number.MAX_SAFE_INTEGER + 2 and MAX_SAFE_INTEGER = 9007199254740991, so might be a good idea to use big numbers here.

@jjgonecrypto jjgonecrypto merged commit bf8829e into develop Aug 22, 2020
@jjgonecrypto jjgonecrypto deleted the sip-75-keeper-isynths-phase-one branch August 22, 2020 00:53
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.

4 participants