Skip to content

Commit 2cb4317

Browse files
committed
Addressing code review comments
1 parent ced07b3 commit 2cb4317

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -344,17 +344,24 @@ contract UFragmentsPolicy is Ownable {
344344
int256 normalizedRate = rate.toInt256Safe().mul(ONE).div(targetRateSigned);
345345

346346
// Determine growth and bounds based on positive or negative rebase
347-
int256 growth = normalizedRate >= ONE
348-
? rebaseFunctionPositiveGrowth
349-
: rebaseFunctionNegativeGrowth;
350-
int256 lower = normalizedRate >= ONE
351-
? -rebaseFunctionUpperPercentage
352-
: rebaseFunctionLowerPercentage;
353-
int256 upper = normalizedRate >= ONE
354-
? rebaseFunctionUpperPercentage
355-
: -rebaseFunctionLowerPercentage;
356-
357-
int256 rebasePercentage = computeRebasePercentage(normalizedRate, lower, upper, growth);
347+
int256 rebasePercentage;
348+
349+
if (normalizedRate >= ONE) {
350+
rebasePercentage = computeRebasePercentage(normalizedRate, -rebaseFunctionUpperPercentage, rebaseFunctionUpperPercentage, rebaseFunctionPositiveGrowth);
351+
} else {
352+
rebasePercentage = computeRebasePercentage(normalizedRate, rebaseFunctionLowerPercentage, -rebaseFunctionLowerPercentage, rebaseFunctionNegativeGrowth);
353+
}
354+
// int256 growth = normalizedRate >= ONE
355+
// ? rebaseFunctionPositiveGrowth
356+
// : rebaseFunctionNegativeGrowth;
357+
// int256 lower = normalizedRate >= ONE
358+
// ? -rebaseFunctionUpperPercentage
359+
// : rebaseFunctionLowerPercentage;
360+
// int256 upper = normalizedRate >= ONE
361+
// ? rebaseFunctionUpperPercentage
362+
// : -rebaseFunctionLowerPercentage;
363+
364+
// int256 rebasePercentage = computeRebasePercentage(normalizedRate, lower, upper, growth);
358365
return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
359366
}
360367

test/unit/UFragmentsPolicy.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,15 +1036,18 @@ describe('UFragmentsPolicy:Rebase', async function () {
10361036
)
10371037
await uFragmentsPolicy
10381038
.connect(deployer)
1039-
.setRebaseFunctionPositiveGrowth('50' + '000000000000000000') // Positive growth
1039+
.setRebaseFunctionPositiveGrowth('25' + '000000000000000000') // Positive growth
1040+
await uFragmentsPolicy
1041+
.connect(deployer)
1042+
.setRebaseFunctionUpperPercentage('10' + '0000000000000000')
10401043
await increaseTime(60)
10411044
})
10421045

10431046
it('should compute positive rebase percentage correctly', async function () {
10441047
const rebaseEvent = await parseRebaseEvent(
10451048
uFragmentsPolicy.connect(orchestrator).rebase(),
10461049
)
1047-
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(0)
1050+
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(98)
10481051
})
10491052
})
10501053

@@ -1065,7 +1068,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
10651068
const rebaseEvent = await parseRebaseEvent(
10661069
uFragmentsPolicy.connect(orchestrator).rebase(),
10671070
)
1068-
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(0)
1071+
expect(rebaseEvent.requestedSupplyAdjustment).to.eq(-76);
10691072
})
10701073
})
10711074

0 commit comments

Comments
 (0)