Skip to content

Sip 184 merge develop#1642

Closed
leckylao wants to merge 122 commits intodevelopfrom
sip-184-merge-develop
Closed

Sip 184 merge develop#1642
leckylao wants to merge 122 commits intodevelopfrom
sip-184-merge-develop

Conversation

@leckylao
Copy link
Copy Markdown
Contributor

@leckylao leckylao commented Jan 8, 2022

No description provided.

- created libraries folder
- moving SafeDecimalMath into libraries
- adding decimals into SafeDecimalMath
- Adding require check for price;
- Adding setup for test;
- Adding more rounds of price feeds for test;
- Adding dynamic fee in systemSettings in test
- removed fastForward as startTime and Now is not equal
- Rename priceWeight to RoundDecay
- adding cap 100% for max exchangeFeeRate
- Added return for invalid rate
- linking libraries in setup
- disable dynamic fee when price feeds less than 2 rounds
- disable dynamic fee on exchanger spec settle
- move setPriceAggregator out of the updateRates loop
- Fix set price with no volatility on exchangeAtomically
- remove format from cacheRate as it's already been formatted
- Having the rounds rate loop inside the aggregator
- Using roundId 1 for sUSD to be consistent
- Fix interface wrong compiler version warning
- adding --max-old-space-size
@leckylao leckylao changed the base branch from develop to feat/sip-184-dynamic-fees January 8, 2022 13:06
@leckylao leckylao changed the base branch from feat/sip-184-dynamic-fees to develop January 8, 2022 13:06
@codecov
Copy link
Copy Markdown

codecov bot commented Jan 8, 2022

Codecov Report

Merging #1642 (1f500db) into develop (d34061c) will increase coverage by 0.09%.
The diff coverage is 100.00%.

❗ Current head 1f500db differs from pull request most recent head 3118295. Consider uploading reports for the commit 3118295 to get more accurate results
Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1642      +/-   ##
===========================================
+ Coverage    95.58%   95.68%   +0.09%     
===========================================
  Files           82       83       +1     
  Lines         1904     1946      +42     
  Branches       593      610      +17     
===========================================
+ Hits          1820     1862      +42     
  Misses          84       84              
Impacted Files Coverage Δ
contracts/DynamicFee.sol 100.00% <100.00%> (ø)
contracts/ExchangeRates.sol 98.75% <100.00%> (+0.19%) ⬆️
contracts/Exchanger.sol 96.93% <100.00%> (+0.30%) ⬆️
contracts/MixinSystemSettings.sol 100.00% <100.00%> (ø)
contracts/SystemSettings.sol 100.00% <100.00%> (ø)

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 54a9c52...3118295. Read the comment docs.

* Fix CI test
- increase stake behaviour SNX mint
- update setRate to deploy mockAggregator

* Revert "Fix CI test"

This reverts commit 182b34c.

* Revert "Revert "Fix CI test""

This reverts commit 1be5282.
- update setMissingRates to always add all rates
- increase SNXAmount on stake
- increase SNX stake amount
@artdgn
Copy link
Copy Markdown
Contributor

artdgn commented Jan 10, 2022

Should #1563 be closed in favour of this one @leckylao ?

uint rate,
uint time
) internal {
if (rate > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should check if rate != cacheRates[currencyKey][roundId].rate to avoid SSTORE for rewriting same rate

return false;
}

function anyRateIsInvalidAtRound(bytes32[] calldata currencyKeys, uint[] calldata roundIds)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. This seems to be used only in exchanger and always for two rates, does this need to accept arrays, maybe a single rate method can be used twice instead.
  2. This checks for flags and time, but doesn't check for 0 rate. probably needs a test case as well. If method's intent is time only, than should be renamed to anyRateStaleAtRound or smth..
  3. Would be good to add doc comments (and specify what invalid means in this case).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This function is meant the be consistent with function anyRateIsInvalid so the recommendation would likely be apply on both functions therefore would just leave it for now and mark as improvement.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like the array variants are more gas efficient in terms of number of external calls vs. checking each rate separately.

uint[] memory roundIds = new uint[](2);
roundIds[0] = roundIdForSrc;
roundIds[1] = roundIdForDest;
require(!exchangeRates().anyRateIsInvalidAtRound(synthKeys, roundIds), "Src/dest rate invalid or not found");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. As above, can probably check the two rates specificaly instead of creating and iterating on array of 2

  2. Not sure if "or not found" part of message is needed or accurate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Similar that the function is meant the be consistent with function _ensureCanExchange so not necessary changing the legacy function would just leave it for now and mark as improvement.

function _getDynamicFeeForExchange(bytes32 currencyKey) internal view returns (uint dynamicFee) {
// No dynamic fee for sUSD
if (currencyKey == sUSD) return 0;
(uint threshold, uint weightDecay, uint rounds) = getExchangeDynamicFeeData();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: getExchangeDynamicFeeData -> getExchangeDynamicFeeParams or getExchangeDynamicFeeConfig


/// @notice Get exchange max dynamic fee
/// @return max dynamic fee
function getExchangeMaxDynamicFee() internal view returns (uint) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should this be added to getExchangeDynamicFeeData to query for them all together?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's fetching from different functions though, might just leave it for now.

@@ -0,0 +1,124 @@
,,,,,,,
,round,price,ΔP (bp),boost,dynamic_fee (bp),,deviation threshold (bp)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please add the formulas text so that numbers can be recreated / checked / adjusted

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Would be refer back to the xlsx spreadsheet.

function itCanStake({ ctx }) {
describe('staking and claiming', () => {
const SNXAmount = ethers.utils.parseEther('100');
const SNXAmount = ethers.utils.parseEther('100000');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why was this change needed? (in another PR it was changed to 1000 :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

await setSystemSetting({ ctx, settingName: 'rateStalePeriod', newValue: '1000000000' });

// try to add the missing rates
await _setMissingRates({ ctx });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think we should remove the check, instead we should check if the aggregators have enough rates for the dynamic fee, and if they don't add them. This always adds and overwrites aggregators, which makes the integration tests less "integration".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am not too familiar with the aggregator stuff and how to change that. As you added this part would you mind having a new PR on top of this to change it?

aggregator = aggregator.connect(owner);
// set decimals
await (await aggregator.setDecimals(18)).wait();
// deploy an aggregator
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As these are integration tests, this should probably try to add rates if they're missing, and not always. So probably the check needs to be altered and not removed - it should check probably if there are enough rates, and if there aren't - add them.


const { timestamp } = await ctx.provider.getBlock();
// factory for price aggregators contracts
const MockAggregatorFactory = await createMockAggregatorFactory(ctx.users.owner);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

as in the other PR - this method shouldn't deploy and add aggregators, this should be a separate explicit setup step, otherwise this could hide a broken scenario or fork test

@artdgn
Copy link
Copy Markdown
Contributor

artdgn commented Jan 10, 2022

Also, would be nice to see an updated gas usage report.

leckylao and others added 4 commits January 10, 2022 17:51
- _setCacheRate also check non-duplicate entry
- remove duplicate rates in Exchanger.spec.js
@artdgn artdgn mentioned this pull request Jan 11, 2022
11 tasks
@artdgn artdgn changed the base branch from develop to feat/reduce-system-settings-size January 12, 2022 23:45
@artdgn artdgn changed the base branch from feat/reduce-system-settings-size to develop January 12, 2022 23:47
@artdgn artdgn mentioned this pull request Jan 13, 2022
@artdgn
Copy link
Copy Markdown
Contributor

artdgn commented Jan 17, 2022

Work continued in #1649

@artdgn artdgn closed this Jan 17, 2022
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.

2 participants