Skip to content

Commit 1d13ed3

Browse files
authored
Merge pull request #297 from ampleforth/naguib-double-curve
Refactor rebase function parameters. To have two seperate sigmoid rebase function for positive and negative rebase. Each with its configured bound/asymptote and growth factor.
2 parents dda5b9f + 0e7f9d1 commit 1d13ed3

File tree

3 files changed

+232
-127
lines changed

3 files changed

+232
-127
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,13 @@ contract UFragmentsPolicy is Ownable {
9494

9595
// DECIMALS decimal fixed point numbers.
9696
// Used in computation of (Upper-Lower)/(1-(Upper/Lower)/2^(Growth*delta))) + Lower
97-
int256 public rebaseFunctionLowerPercentage;
98-
int256 public rebaseFunctionUpperPercentage;
99-
int256 public rebaseFunctionGrowth;
97+
/// @custom:oz-renamed-from rebaseFunctionLowerPercentage
98+
int256 public rebaseFunctionNegativePercentageLimit;
99+
/// @custom:oz-renamed-from rebaseFunctionUpperPercentage
100+
int256 public rebaseFunctionPositivePercentageLimit;
101+
/// @custom:oz-renamed-from rebaseFunctionGrowth
102+
int256 public rebaseFunctionPositiveGrowth;
103+
int256 public rebaseFunctionNegativeGrowth;
100104

101105
int256 private constant ONE = int256(10**DECIMALS);
102106

@@ -166,25 +170,30 @@ contract UFragmentsPolicy is Ownable {
166170
orchestrator = orchestrator_;
167171
}
168172

169-
function setRebaseFunctionGrowth(int256 rebaseFunctionGrowth_) external onlyOwner {
170-
require(rebaseFunctionGrowth_ >= 0);
171-
rebaseFunctionGrowth = rebaseFunctionGrowth_;
172-
}
173-
174-
function setRebaseFunctionLowerPercentage(int256 rebaseFunctionLowerPercentage_)
173+
function setRebaseFunctionNegativePercentageLimit(int256 rebaseFunctionNegativePercentageLimit_)
175174
external
176175
onlyOwner
177176
{
178-
require(rebaseFunctionLowerPercentage_ <= 0);
179-
rebaseFunctionLowerPercentage = rebaseFunctionLowerPercentage_;
177+
require(rebaseFunctionNegativePercentageLimit_ <= 0);
178+
rebaseFunctionNegativePercentageLimit = rebaseFunctionNegativePercentageLimit_;
180179
}
181180

182-
function setRebaseFunctionUpperPercentage(int256 rebaseFunctionUpperPercentage_)
181+
function setRebaseFunctionPositivePercentageLimit(int256 rebaseFunctionPositivePercentageLimit_)
183182
external
184183
onlyOwner
185184
{
186-
require(rebaseFunctionUpperPercentage_ >= 0);
187-
rebaseFunctionUpperPercentage = rebaseFunctionUpperPercentage_;
185+
require(rebaseFunctionPositivePercentageLimit_ >= 0);
186+
rebaseFunctionPositivePercentageLimit = rebaseFunctionPositivePercentageLimit_;
187+
}
188+
189+
function setRebaseFunctionPositiveGrowth(int256 rebaseFunctionPositiveGrowth_) external onlyOwner {
190+
require(rebaseFunctionPositiveGrowth_ >= 0);
191+
rebaseFunctionPositiveGrowth = rebaseFunctionPositiveGrowth_;
192+
}
193+
194+
function setRebaseFunctionNegativeGrowth(int256 rebaseFunctionNegativeGrowth_) external onlyOwner {
195+
require(rebaseFunctionNegativeGrowth_ >= 0);
196+
rebaseFunctionNegativeGrowth = rebaseFunctionNegativeGrowth_;
188197
}
189198

190199
/**
@@ -246,9 +255,10 @@ contract UFragmentsPolicy is Ownable {
246255
// deviationThreshold = 0.05e18 = 5e16
247256
deviationThreshold = 25 * 10**(DECIMALS - 3);
248257

249-
rebaseFunctionGrowth = int256(45 * (10**DECIMALS));
250-
rebaseFunctionUpperPercentage = int256(5 * (10**(DECIMALS - 2))); // 0.05
251-
rebaseFunctionLowerPercentage = int256((-77) * int256(10**(DECIMALS - 3))); // -0.077
258+
rebaseFunctionPositiveGrowth = int256(45 * (10**DECIMALS)); // Positive growth
259+
rebaseFunctionNegativeGrowth = int256(45 * (10**DECIMALS)); // Negative growth
260+
rebaseFunctionPositivePercentageLimit = int256(5 * (10**(DECIMALS - 2))); // 0.05
261+
rebaseFunctionNegativePercentageLimit = int256((-77) * int256(10**(DECIMALS - 3))); // -0.077
252262

253263
minRebaseTimeIntervalSec = 1 days;
254264
rebaseWindowOffsetSec = 7200; // 2AM UTC
@@ -334,12 +344,25 @@ contract UFragmentsPolicy is Ownable {
334344
}
335345
int256 targetRateSigned = targetRate.toInt256Safe();
336346
int256 normalizedRate = rate.toInt256Safe().mul(ONE).div(targetRateSigned);
337-
int256 rebasePercentage = computeRebasePercentage(
338-
normalizedRate,
339-
rebaseFunctionLowerPercentage,
340-
rebaseFunctionUpperPercentage,
341-
rebaseFunctionGrowth
342-
);
347+
348+
// Determine growth and bounds based on positive or negative rebase
349+
int256 rebasePercentage;
350+
if (normalizedRate >= ONE) {
351+
rebasePercentage = computeRebasePercentage(
352+
normalizedRate,
353+
-rebaseFunctionPositivePercentageLimit,
354+
rebaseFunctionPositivePercentageLimit,
355+
rebaseFunctionPositiveGrowth
356+
);
357+
} else {
358+
rebasePercentage = computeRebasePercentage(
359+
normalizedRate,
360+
rebaseFunctionNegativePercentageLimit,
361+
-rebaseFunctionNegativePercentageLimit,
362+
rebaseFunctionNegativeGrowth
363+
);
364+
}
365+
343366
return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
344367
}
345368

scripts/deploy.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ task('deploy:amplforce:testnet', 'Deploy ampleforth contract suite for testnet')
3333

3434
// Policy
3535
const DEVIATION_TRESHOLD = utils.parseUnits('0.002', 18) // 0.002% (ie) 0.05/24)
36-
const LOWER = utils.parseUnits('-0.005', 18)
37-
const UPPER = utils.parseUnits('0.005', 18)
38-
const GROWTH = utils.parseUnits('3', 18)
36+
const LOWER = utils.parseUnits('-0.005', 18) // rebaseFunctionNegativePercentageLimit
37+
const UPPER = utils.parseUnits('0.005', 18) // rebaseFunctionPositivePercentageLimit
38+
const POSITIVE_GROWTH = utils.parseUnits('31', 18) // rebaseFunctionPositiveGrowth;
39+
const NEGATIVE_GROWTH = utils.parseUnits('41', 18) // rebaseFunctionNegativeGrowth;
3940
const MIN_REBASE_INTERVAL = 1200 // 20 mins
4041
const REBASE_WINDOW_OFFSET = 0
4142
const REBASE_WINDOW_LEN = 2400 // 40 mins
@@ -119,9 +120,10 @@ task('deploy:amplforce:testnet', 'Deploy ampleforth contract suite for testnet')
119120

120121
// configure parameters
121122
await waitFor(policy.setDeviationThreshold(DEVIATION_TRESHOLD))
122-
await waitFor(policy.setRebaseFunctionGrowth(GROWTH))
123-
await waitFor(policy.setRebaseFunctionLowerPercentage(LOWER))
124-
await waitFor(policy.setRebaseFunctionUpperPercentage(UPPER))
123+
await waitFor(policy.setRebaseFunctionPositiveGrowth(POSITIVE_GROWTH))
124+
await waitFor(policy.setRebaseFunctionNegativeGrowth(NEGATIVE_GROWTH))
125+
await waitFor(policy.setRebaseFunctionNegativePercentageLimit(LOWER))
126+
await waitFor(policy.setRebaseFunctionPositivePercentageLimit(UPPER))
125127
await waitFor(
126128
policy.setRebaseTimingParameters(
127129
MIN_REBASE_INTERVAL,

0 commit comments

Comments
 (0)