Skip to content

Commit 21060f8

Browse files
committed
code review comments
1 parent 4fb7a0e commit 21060f8

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -378,18 +378,21 @@ contract UFragmentsPolicy is Ownable {
378378
// When supply is decreasing:
379379
// We limit the supply delta, based on recent supply history.
380380
if (rebasePercentage < 0) {
381-
int256 maxSupplyInHistory = currentSupply;
382-
for (uint8 i = 1; i < epochLookback && epoch > i; i++) {
383-
int256 epochSupply = supplyHistory[epoch - i].toInt256Safe();
384-
if (epochSupply > maxSupplyInHistory) {
385-
maxSupplyInHistory = epochSupply;
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;
386390
}
387391
}
388-
int256 allowedSupplyMinimum = maxSupplyInHistory
389-
.mul(ONE.sub(tolerableDeclinePercentage))
390-
.div(ONE);
391-
newSupply = (newSupply > allowedSupplyMinimum) ? newSupply : allowedSupplyMinimum;
392-
require(newSupply <= currentSupply);
392+
int256 allowedMin = maxSupply.mul(ONE.sub(tolerableDeclinePercentage)).div(ONE);
393+
if (newSupply < allowedMin) {
394+
newSupply = allowedMin;
395+
}
393396
}
394397

395398
return newSupply.sub(currentSupply);

0 commit comments

Comments
 (0)