Skip to content

Commit 98ae012

Browse files
committed
circuit breaking based on supply on look-back time (not max in the period)
1 parent 21060f8 commit 98ae012

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ contract UFragmentsPolicy is Ownable {
236236
/**
237237
* @notice Sets the parameters which control rebase circuit breaker.
238238
* @param epochLookback_ The number of rebase epochs to look back.
239-
* @param tolerableDeclinePercentage_ The maximum supply decline percentage which is allowed
239+
* @param tolerableDeclinePercentage_ The supply decline percentage which is allowed
240240
* within the defined look back period.
241241
*/
242242
function setRebaseCircuitBreakerParameters(
@@ -377,19 +377,15 @@ contract UFragmentsPolicy is Ownable {
377377

378378
// When supply is decreasing:
379379
// We limit the supply delta, based on recent supply history.
380-
if (rebasePercentage < 0) {
381-
int256 maxSupply = currentSupply;
382-
for (
383-
uint256 e = ((epoch > epochLookback) ? (epoch - epochLookback) : 0);
384-
e < epoch;
385-
e++
386-
) {
387-
int256 epochSupply = supplyHistory[e].toInt256Safe();
388-
if (epochSupply > maxSupply) {
389-
maxSupply = epochSupply;
390-
}
380+
if (rebasePercentage < 0 && epoch > epochLookback) {
381+
int256 allowedMin = supplyHistory[epoch - epochLookback]
382+
.toInt256Safe()
383+
.mul(ONE.sub(tolerableDeclinePercentage))
384+
.div(ONE);
385+
if (allowedMin > currentSupply) {
386+
// NOTE: Allowed minimum supply can only be at most the current supply.
387+
allowedMin = currentSupply;
391388
}
392-
int256 allowedMin = maxSupply.mul(ONE.sub(tolerableDeclinePercentage)).div(ONE);
393389
if (newSupply < allowedMin) {
394390
newSupply = allowedMin;
395391
}

test/unit/UFragmentsPolicy.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1409,7 +1409,21 @@ describe('UFragmentsPolicy', function () {
14091409
expect(
14101410
(await parseRebaseEvent(uFragmentsPolicy.rebase()))
14111411
.requestedSupplyAdjustment,
1412-
).to.eq(-49)
1412+
).to.eq(-51)
1413+
1414+
await mockExternalData(INITIAL_RATE_50P_LESS, INITIAL_TARGET_RATE)
1415+
await increaseTime(60)
1416+
expect(
1417+
(await parseRebaseEvent(uFragmentsPolicy.rebase()))
1418+
.requestedSupplyAdjustment,
1419+
).to.eq(-48)
1420+
1421+
await mockExternalData(INITIAL_RATE_50P_LESS, INITIAL_TARGET_RATE)
1422+
await increaseTime(60)
1423+
expect(
1424+
(await parseRebaseEvent(uFragmentsPolicy.rebase()))
1425+
.requestedSupplyAdjustment,
1426+
).to.eq(-46)
14131427

14141428
await mockExternalData(INITIAL_RATE_50P_LESS, INITIAL_TARGET_RATE)
14151429
await increaseTime(60)

0 commit comments

Comments
 (0)