Skip to content

Commit 8305b09

Browse files
committed
Refactor rebase function parameters to separate positive and negative growth
1 parent fd13c8b commit 8305b09

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ contract UFragmentsPolicy is Ownable {
9696
// Used in computation of (Upper-Lower)/(1-(Upper/Lower)/2^(Growth*delta))) + Lower
9797
int256 public rebaseFunctionLowerPercentage;
9898
int256 public rebaseFunctionUpperPercentage;
99-
int256 public rebaseFunctionGrowth;
99+
int256 public rebaseFunctionPositiveGrowth;
100+
int256 public rebaseFunctionNegativeGrowth;
100101

101102
int256 private constant ONE = int256(10**DECIMALS);
102103

@@ -166,10 +167,6 @@ contract UFragmentsPolicy is Ownable {
166167
orchestrator = orchestrator_;
167168
}
168169

169-
function setRebaseFunctionGrowth(int256 rebaseFunctionGrowth_) external onlyOwner {
170-
require(rebaseFunctionGrowth_ >= 0);
171-
rebaseFunctionGrowth = rebaseFunctionGrowth_;
172-
}
173170

174171
function setRebaseFunctionLowerPercentage(int256 rebaseFunctionLowerPercentage_)
175172
external
@@ -187,6 +184,16 @@ contract UFragmentsPolicy is Ownable {
187184
rebaseFunctionUpperPercentage = rebaseFunctionUpperPercentage_;
188185
}
189186

187+
function setRebaseFunctionPositiveGrowth(int256 rebaseFunctionPositiveGrowth_) external onlyOwner {
188+
require(rebaseFunctionPositiveGrowth_ >= 0);
189+
rebaseFunctionPositiveGrowth = rebaseFunctionPositiveGrowth_;
190+
}
191+
192+
function setRebaseFunctionNegativeGrowth(int256 rebaseFunctionNegativeGrowth_) external onlyOwner {
193+
require(rebaseFunctionNegativeGrowth_ >= 0);
194+
rebaseFunctionNegativeGrowth = rebaseFunctionNegativeGrowth_;
195+
}
196+
190197
/**
191198
* @notice Sets the deviation threshold fraction. If the exchange rate given by the market
192199
* oracle is within this fractional distance from the targetRate, then no supply
@@ -246,7 +253,8 @@ contract UFragmentsPolicy is Ownable {
246253
// deviationThreshold = 0.05e18 = 5e16
247254
deviationThreshold = 25 * 10**(DECIMALS - 3);
248255

249-
rebaseFunctionGrowth = int256(45 * (10**DECIMALS));
256+
rebaseFunctionPositiveGrowth = int256(45 * (10**DECIMALS)); // Positive growth
257+
rebaseFunctionNegativeGrowth = int256(45 * (10**DECIMALS)); // Negative growth
250258
rebaseFunctionUpperPercentage = int256(5 * (10**(DECIMALS - 2))); // 0.05
251259
rebaseFunctionLowerPercentage = int256((-77) * int256(10**(DECIMALS - 3))); // -0.77
252260

@@ -334,12 +342,19 @@ contract UFragmentsPolicy is Ownable {
334342
}
335343
int256 targetRateSigned = targetRate.toInt256Safe();
336344
int256 normalizedRate = rate.toInt256Safe().mul(ONE).div(targetRateSigned);
337-
int256 rebasePercentage = computeRebasePercentage(
338-
normalizedRate,
339-
rebaseFunctionLowerPercentage,
340-
rebaseFunctionUpperPercentage,
341-
rebaseFunctionGrowth
342-
);
345+
346+
// 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);
343358
return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
344359
}
345360

0 commit comments

Comments
 (0)