Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
6c2c814
created DynamicFee library
leckylao Oct 11, 2021
c853490
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Oct 13, 2021
aaf12e5
moving Math into libraries
leckylao Oct 13, 2021
b707cbc
fixing import Math path;
leckylao Oct 13, 2021
6e9a995
adding implementation for DynamicFee
leckylao Oct 13, 2021
82e71a5
Adding Natspec
leckylao Oct 13, 2021
82808cf
Adding test for DynamicFee
leckylao Oct 14, 2021
89116c3
Adding more tests for DynamicFee
leckylao Oct 14, 2021
278b3d7
Try to fix CI Cov by moving test file
leckylao Oct 14, 2021
bb26601
revert libraries folder and move to new PR
leckylao Oct 14, 2021
f4f4218
revert libraries path
leckylao Oct 14, 2021
980bc20
fixed test with data from Afif
leckylao Oct 18, 2021
723c6e6
feat(Exchanger): Adding dynamic fee into exchange fee
leckylao Oct 21, 2021
c5c856d
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Oct 21, 2021
8b1d491
fix(test): updateRates for rounds
leckylao Oct 22, 2021
ff48fb9
fix(test): Adding dynamic fee to 0 for sUSD
leckylao Oct 25, 2021
849583a
Fixing more tests and adding in more descriptions
leckylao Oct 25, 2021
5cd88ec
fix test by adding rounds for price feeds
leckylao Oct 26, 2021
89b78c6
fixed FeePool test
leckylao Oct 27, 2021
c56aa8b
fixing ExchangerWithVirtualSynth link in setup.js
leckylao Oct 27, 2021
5302a44
fixing setup library linking
leckylao Oct 27, 2021
8aa8c5e
fixing setup in test
leckylao Oct 27, 2021
c2f1ba2
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Oct 29, 2021
34b92af
fixing exhcnager test
leckylao Nov 3, 2021
29ac65c
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Nov 3, 2021
76451fe
use iBTC as destinationCurrency as it got rate.
leckylao Nov 3, 2021
a999fe3
Merge branch 'feat/sip-184-dynamic-fees' of github.com:Synthetixio/sy…
leckylao Nov 3, 2021
f30f8e3
move cap max exchange fee into exchange
leckylao Nov 8, 2021
5a30543
fixing exchanger.spec.js
leckylao Nov 8, 2021
c636a28
fixed ExchangerWithVirtualSynth linking in test
leckylao Nov 8, 2021
1566902
fixing baseSynthetix by reducing the price change
leckylao Nov 9, 2021
574c0ff
setting DYNAMIC_FEE_ROUNDS to 0 for L1 to disable dynamicFee
leckylao Nov 9, 2021
88afd1c
fix debtCache test
leckylao Nov 9, 2021
6cc96fc
Adding exchangeDynamicFeeRate into ExchangeState
leckylao Nov 11, 2021
d762939
remove duplicated uint definition.
leckylao Nov 11, 2021
3f2b1ae
Revert "Adding exchangeDynamicFeeRate into ExchangeState"
leckylao Nov 11, 2021
63b4944
add missing declaration
leckylao Nov 11, 2021
d0fe84f
Adding lastExchangeDynamicFeeRate and lastExchangeRoundId;
leckylao Nov 14, 2021
0a577c3
Add lastExchangeDynamicFeeRate
leckylao Nov 15, 2021
8fb9c3a
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Nov 16, 2021
e4438e0
Using cache to improve performance
leckylao Nov 16, 2021
0667767
fixing ExchangerWithFeeRecAlternatives test
leckylao Nov 17, 2021
9362687
get rate before ensure so that feed can be cached
leckylao Nov 17, 2021
8df051c
Code refactor and fix slither code comment
leckylao Nov 18, 2021
9bf1894
move _suspendIfRateInvalid to check right after rate
leckylao Nov 18, 2021
7c0f2b8
fixed ExchangerWithFeeRecAlternatives test
leckylao Nov 19, 2021
f6511d6
fixing exchangeRates, exchanger.spec test
leckylao Nov 21, 2021
b7bc872
fixing exchangeAtomically test
leckylao Nov 22, 2021
0f859f6
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Nov 23, 2021
c01beb5
Updating releases.jon
leckylao Nov 23, 2021
95bedc8
adding more tests scenarios
leckylao Nov 23, 2021
e7bec66
rename method _getRateAndUpdatedTimeAtRound to be consistent
leckylao Nov 23, 2021
c704152
Redundant expression "updateThreshold" inExchangeRatesWithDexPricing
leckylao Nov 23, 2021
9684551
remove duplicated import
leckylao Nov 23, 2021
eabd924
Adding DynamicFee into releases
leckylao Nov 24, 2021
6cd657c
Adding DynamicFee deploy true into local config
leckylao Nov 25, 2021
eb3bea7
Add missing readTarget in configure-system-settings.js
leckylao Nov 25, 2021
72329bc
fixing configure-system-settings to only change if non-default
leckylao Nov 25, 2021
ac1c91d
Add missing external functions into SystemSettings
leckylao Nov 25, 2021
fc3eb7e
Adding tests for systemSettings
leckylao Nov 26, 2021
b253635
fix PR comment
leckylao Nov 28, 2021
a148f36
Rollback DynamicFee formula to the previous iteration
leckylao Nov 28, 2021
026efc3
Disable dynamic on itPricesSpikeDeviation settlement test
leckylao Nov 28, 2021
0934b69
moving timestamp inside updateRates in test
leckylao Nov 28, 2021
a53300e
Adding sourceCurrencyKey into total dynamic fee
leckylao Nov 29, 2021
d98b391
Rollback _getRateAndUpdatedTime as cache not help
leckylao Nov 29, 2021
dac4d0a
fixing CollateralShort test
leckylao Nov 30, 2021
9b9cc5a
fixed PurgableSynth test
leckylao Nov 30, 2021
0b1d612
Fixed ExchangeRates.js test
leckylao Nov 30, 2021
3831c9b
Fixing Exchanger.spec.js test
leckylao Nov 30, 2021
d94240d
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Nov 30, 2021
dc1d46f
Fixes Synth.js test;
leckylao Nov 30, 2021
ab612a0
Merge branch 'feat/sip-184-dynamic-fees' of github.com:Synthetixio/sy…
leckylao Nov 30, 2021
cd70265
Fix(DebtCache test):
leckylao Nov 30, 2021
7dc75c1
Fix(job-fork-tests):
leckylao Nov 30, 2021
178be91
Fix(audit):
leckylao Nov 30, 2021
b8f3a82
Merge ratesAndUpdatedTimeForCurrencyLastNRounds
leckylao Dec 1, 2021
a18babb
Fix(ExchangerWithFeeRecAlternatives.unit.js): Adding default max dyna…
leckylao Dec 2, 2021
0237bd4
Rename DYNAMIC_FEE_ROUNDS to prepend EXCHANGE to be consistent
leckylao Dec 2, 2021
e1ec184
Fix(SystemSettings.js): Add missing max dynamic fee
leckylao Dec 2, 2021
9c1c92c
Fixing publish test
leckylao Dec 4, 2021
364ad77
Fix publish test
leckylao Dec 4, 2021
93f0b67
Chainging EXCHANGE_DYNAMIC_FEE_ROUNDS on mainnet to 1 so it won't be …
leckylao Dec 4, 2021
269db85
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Dec 5, 2021
ef24431
Remove disable exchange fee in atomicExchange test
leckylao Dec 5, 2021
3427ffd
Adding test cases for exchange with dynamic fee
leckylao Dec 5, 2021
59e3e7f
Rename effectiveValueAndRatesAtRound to mutativeEffectiveValueAndRate…
leckylao Dec 6, 2021
d0ccd74
Revert SafeDecimalMath.sol changes
leckylao Dec 6, 2021
77eed96
Revert "Revert SafeDecimalMath.sol changes"
leckylao Dec 6, 2021
f75031a
Adding SafeDecimalMath for releases
leckylao Dec 6, 2021
0a10dbc
Revert "Adding SafeDecimalMath for releases"
leckylao Dec 6, 2021
6d04ba1
Revert "Revert "Revert SafeDecimalMath.sol changes""
leckylao Dec 6, 2021
671f019
Fix TestableDynamicFee to use SafeDecimalMath.unit
leckylao Dec 6, 2021
6b6c1e8
Fixing Mark's comment:
leckylao Dec 9, 2021
dcb9890
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Dec 9, 2021
c458daf
Adding hardhat node config allowUnlimitedContractSize to false
leckylao Dec 9, 2021
eeacf31
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Dec 9, 2021
18c006e
Fixing comments
leckylao Dec 9, 2021
e905aca
Fix(ExchangerWithFeeRecAlternatives):
leckylao Dec 9, 2021
fe81a82
Adding comment for setExchangeDynamicFeeRounds with minimum 2 rounds
leckylao Dec 11, 2021
5b0cda8
Merge branch 'develop' into feat/sip-184-dynamic-fees
leckylao Dec 25, 2021
955b5b1
fix ExchangeRates test
leckylao Dec 25, 2021
feb03f0
fixing ExchangerWithFeeRecAlternatives.unit.js
leckylao Dec 26, 2021
35a4a7b
Fix RewardsIntegrationTests.js
leckylao Jan 2, 2022
d904b7a
Fix Exchanger.spec.js
leckylao Jan 4, 2022
1d1ef57
Fix Exchanger.spec.js
leckylao Jan 4, 2022
b599187
Fix test/publish
leckylao Jan 6, 2022
d41d216
Using roundId 1 as last round to be consistent
leckylao Jan 6, 2022
2b4bd73
Fix integration test
leckylao Jan 6, 2022
732e2cb
Fix ExchangeRates.js
leckylao Jan 6, 2022
ab1b89c
Try to fix CI unit test
leckylao Jan 6, 2022
9d381d2
Merge branch 'develop' into sip-184-merge-develop
leckylao Jan 8, 2022
d5635a7
Fix CI test (#1644)
leckylao Jan 9, 2022
5b71a8d
Fix integration test
leckylao Jan 9, 2022
4223d85
Fix stake.behavior.js
leckylao Jan 9, 2022
e558ac9
Fix stake integration test
leckylao Jan 9, 2022
60fed58
Fix 184 comments
leckylao Jan 10, 2022
7c1d7c4
Revert "Fix stake integration test"
leckylao Jan 10, 2022
2cca728
Change stake.behavior.js SNXAmount back to 1000
leckylao Jan 11, 2022
e628cd0
Merge branch 'develop' into sip-184-merge-develop
artdgn Jan 11, 2022
1f500db
Merge branch 'develop' into sip-184-merge-develop
artdgn Jan 12, 2022
3118295
Merge branch 'develop' into sip-184-merge-develop
artdgn Jan 13, 2022
9312ecd
fix fee cap, rename methods, pass config struct
artdgn Jan 13, 2022
8b92538
fix linking libs after merge, minor caching change
artdgn Jan 13, 2022
23f7ab9
rename dynamic fee test file
artdgn Jan 13, 2022
68b7de1
cap total fee amount to 100%
artdgn Jan 13, 2022
d80a0c0
more efficient dynamic fee calculation
artdgn Jan 13, 2022
c4445f1
remove dynamic fee lib, move into exchanger
artdgn Jan 13, 2022
3d3efd4
remove caching as it doesn't help with dynamic fee
artdgn Jan 13, 2022
cfc7948
Merge branch 'develop' into sip-184-handover-changes
artdgn Jan 14, 2022
ef4b2d3
add spreadheet filename & formulas
artdgn Jan 14, 2022
5032677
Merge branch 'sip-184-handover-changes' of https://github.com/Synthet…
artdgn Jan 14, 2022
eb058c0
Merge branch 'develop' into sip-184-handover-changes
artdgn Jan 17, 2022
b5be09c
fix shadowing and adjust bnclose precision
artdgn Jan 17, 2022
d2631e2
fix aggregators setup in integration tests
artdgn Jan 17, 2022
f422bfe
remove caching again (how did it slip back?)
artdgn Jan 17, 2022
cfd2e5a
fix integration tests setup
artdgn Jan 17, 2022
f2d8580
fix flxeible storage mock tests
artdgn Jan 17, 2022
13b3832
remove unused method
artdgn Jan 17, 2022
36481a1
rename susd constant
artdgn Jan 17, 2022
db48525
remove return variable declarations in new methods
artdgn Jan 17, 2022
ac868c2
update optimistm ops tool commit hash
artdgn Jan 18, 2022
db1462e
address review comments
artdgn Jan 18, 2022
2934641
update optimism core utils package
artdgn Jan 18, 2022
547c765
fix tests timeouts
artdgn Jan 18, 2022
419b519
add missing exchanger tests
artdgn Jan 18, 2022
e19345c
set mainnet rounds to 0 instead of 1
artdgn Jan 18, 2022
79a055c
add short circuit for rounds 0 or 1
artdgn Jan 18, 2022
67f44f5
revert test publish change
artdgn Jan 18, 2022
ba3126b
Revert "update optimism core utils package"
artdgn Jan 19, 2022
44c5ea5
Revert "update optimistm ops tool commit hash"
artdgn Jan 19, 2022
5e04927
Merge branch 'develop' into sip-184-handover-changes
artdgn Jan 19, 2022
6edd50f
add dynamic fee view
artdgn Jan 20, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 72 additions & 23 deletions contracts/ExchangeRates.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,33 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {
return _getCurrentRoundId(currencyKey);
}

function effectiveValueAtRound(
function effectiveValueAndRatesAtRound(
bytes32 sourceCurrencyKey,
uint sourceAmount,
bytes32 destinationCurrencyKey,
uint roundIdForSrc,
uint roundIdForDest
) external view returns (uint value) {
)
external
view
returns (
uint value,
uint sourceRate,
uint destinationRate
)
{
(sourceRate, ) = _getRateAndTimestampAtRound(sourceCurrencyKey, roundIdForSrc);
// If there's no change in the currency, then just return the amount they gave us
if (sourceCurrencyKey == destinationCurrencyKey) return sourceAmount;

(uint srcRate, ) = _getRateAndTimestampAtRound(sourceCurrencyKey, roundIdForSrc);
(uint destRate, ) = _getRateAndTimestampAtRound(destinationCurrencyKey, roundIdForDest);
if (destRate == 0) {
// prevent divide-by 0 error (this can happen when roundIDs jump epochs due
// to aggregator upgrades)
return 0;
if (sourceCurrencyKey == destinationCurrencyKey) {
value = sourceAmount;
} else {
(destinationRate, ) = _getRateAndTimestampAtRound(destinationCurrencyKey, roundIdForDest);
// prevent divide-by 0 error (this happens if the dest is not a valid rate)
if (destinationRate > 0) {
// Calculate the effective value by going from source -> USD -> destination
value = sourceAmount.multiplyDecimalRound(sourceRate).divideDecimalRound(destinationRate);
}
}
// Calculate the effective value by going from source -> USD -> destination
value = sourceAmount.multiplyDecimalRound(srcRate).divideDecimalRound(destRate);
}

function rateAndTimestampAtRound(bytes32 currencyKey, uint roundId) external view returns (uint rate, uint time) {
Expand Down Expand Up @@ -202,15 +210,20 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {
return _getRateAndUpdatedTime(currencyKey).rate;
}

function ratesAndUpdatedTimeForCurrencyLastNRounds(bytes32 currencyKey, uint numRounds)
external
view
returns (uint[] memory rates, uint[] memory times)
{
/// @notice getting N rounds of rates for a currency at a specific round
/// @param currencyKey the currency key
/// @param numRounds the number of rounds to get
/// @param roundId the round id
/// @return a list of rates and a list of times
function ratesAndUpdatedTimeForCurrencyLastNRounds(
bytes32 currencyKey,
uint numRounds,
uint roundId
) external view returns (uint[] memory rates, uint[] memory times) {
rates = new uint[](numRounds);
times = new uint[](numRounds);

uint roundId = _getCurrentRoundId(currencyKey);
roundId = roundId > 0 ? roundId : _getCurrentRoundId(currencyKey);
for (uint i = 0; i < numRounds; i++) {
// fetch the rate and treat is as current, so inverse limits if frozen will always be applied
// regardless of current rate
Expand Down Expand Up @@ -299,6 +312,27 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {
return false;
}

function anyRateIsInvalidAtRound(bytes32[] calldata currencyKeys, uint[] calldata roundIds)
external
view
returns (bool)
{
// Loop through each key and check whether the data point is stale.

require(roundIds.length == currencyKeys.length, "roundIds must be the same length as currencyKeys");

uint256 _rateStalePeriod = getRateStalePeriod();
bool[] memory flagList = getFlagsForRates(currencyKeys);

for (uint i = 0; i < currencyKeys.length; i++) {
if (flagList[i] || _rateIsStaleAtRound(currencyKeys[i], roundIds[i], _rateStalePeriod)) {
return true;
}
}

return false;
}

function synthTooVolatileForAtomicExchange(bytes32) external view returns (bool) {
_notImplemented();
}
Expand Down Expand Up @@ -379,7 +413,7 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {

function _getCurrentRoundId(bytes32 currencyKey) internal view returns (uint) {
if (currencyKey == sUSD) {
return 0; // no roundIds for sUSD
return 0;
}
AggregatorV2V3Interface aggregator = aggregators[currencyKey];
if (aggregator != AggregatorV2V3Interface(0)) {
Expand All @@ -395,7 +429,6 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {
return (SafeDecimalMath.unit(), 0);
} else {
AggregatorV2V3Interface aggregator = aggregators[currencyKey];

if (aggregator != AggregatorV2V3Interface(0)) {
// this view from the aggregator is the most gas efficient but it can throw when there's no data,
// so let's call it low-level to suppress any reverts
Expand Down Expand Up @@ -450,18 +483,34 @@ contract ExchangeRates is Owned, MixinSystemSettings, IExchangeRates {

function _rateIsStale(bytes32 currencyKey, uint _rateStalePeriod) internal view returns (bool) {
// sUSD is a special case and is never stale (check before an SLOAD of getRateAndUpdatedTime)
if (currencyKey == sUSD) return false;

if (currencyKey == sUSD) {
return false;
}
return _rateIsStaleWithTime(_rateStalePeriod, _getUpdatedTime(currencyKey));
}

function _rateIsStaleAtRound(
bytes32 currencyKey,
uint roundId,
uint _rateStalePeriod
) internal view returns (bool) {
// sUSD is a special case and is never stale (check before an SLOAD of getRateAndUpdatedTime)
if (currencyKey == sUSD) {
return false;
}
(, uint time) = _getRateAndTimestampAtRound(currencyKey, roundId);
return _rateIsStaleWithTime(_rateStalePeriod, time);
}

function _rateIsStaleWithTime(uint _rateStalePeriod, uint _time) internal view returns (bool) {
return _time.add(_rateStalePeriod) < now;
}

function _rateIsFlagged(bytes32 currencyKey, FlagsInterface flags) internal view returns (bool) {
// sUSD is a special case and is never invalid
if (currencyKey == sUSD) return false;
if (currencyKey == sUSD) {
return false;
}
address aggregator = address(aggregators[currencyKey]);
// when no aggregator or when the flags haven't been setup
if (aggregator == address(0) || flags == FlagsInterface(0)) {
Expand Down
Loading