Skip to content

Commit b874710

Browse files
authored
Initializing base cpi (#119)
1 parent c943ff2 commit b874710

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,15 @@ contract UFragmentsPolicy is Ownable {
7373
// MAX_SUPPLY = MAX_INT256 / MAX_RATE
7474
uint256 private constant MAX_SUPPLY = ~(uint256(1) << 255) / MAX_RATE;
7575

76-
// CPI-U value July 10th 1983 100, DECIMALS Fixed point number
77-
uint256 private constant BASE_CPI = 100 * (10**DECIMALS);
76+
// CPI value at the time of launch, DECIMALS Fixed point number
77+
uint256 private baseCpi;
7878

7979
/**
8080
* @notice Anyone can call this function to initiate a new rebase operation, provided more than
8181
* the minimum time period has elapsed.
8282
* @dev The supply adjustment equals (_totalSupply * DeviationFromTargetRate) / rebaseLag
8383
* Where DeviationFromTargetRate is (MarketOracleRate - targetRate) / targetRate
84-
* and targetRate is CpiOracleRate / BASE_CPI
84+
* and targetRate is CpiOracleRate / baseCpi
8585
*/
8686
function rebase() external {
8787
// This comparison also ensures there is no reentrancy.
@@ -94,7 +94,7 @@ contract UFragmentsPolicy is Ownable {
9494
(cpi, cpiValid) = cpiOracle.getData();
9595
require(cpiValid);
9696

97-
uint256 targetRate = cpi.mul(10 ** DECIMALS).div(BASE_CPI);
97+
uint256 targetRate = cpi.mul(10 ** DECIMALS).div(baseCpi);
9898

9999
uint256 exchangeRate;
100100
bool rateValid;
@@ -188,7 +188,7 @@ contract UFragmentsPolicy is Ownable {
188188
* It is called at the time of contract creation to invoke parent class initializers and
189189
* initialize the contract's state variables.
190190
*/
191-
function initialize(address owner, UFragments uFrags_)
191+
function initialize(address owner, UFragments uFrags_, uint256 baseCpi_)
192192
public
193193
initializer
194194
{
@@ -203,6 +203,7 @@ contract UFragmentsPolicy is Ownable {
203203
epoch = 0;
204204

205205
uFrags = uFrags_;
206+
baseCpi = baseCpi_;
206207
}
207208

208209
/**

test/unit/UFragmentsPolicy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async function setupContracts () {
3939
mockCpiOracle = await MockOracle.new('CpiOracle');
4040
uFragmentsPolicy = await UFragmentsPolicy.new();
4141
await uFragmentsPolicy.sendTransaction({
42-
data: encodeCall('initialize', ['address', 'address'], [deployer, mockUFragments.address]),
42+
data: encodeCall('initialize', ['address', 'address', 'uint256'], [deployer, mockUFragments.address, BASE_CPI.toString()]),
4343
from: deployer
4444
});
4545
await uFragmentsPolicy.setMarketOracle(mockMarketOracle.address);

0 commit comments

Comments
 (0)