Skip to content

Commit fe4a8c6

Browse files
committed
added exchange rate and cpi getters on policy
1 parent 929b239 commit fe4a8c6

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,17 @@ contract UFragmentsPolicy is Ownable {
124124

125125
epoch = epoch.add(1);
126126

127-
uint256 targetRate;
128-
bool targetRateValid;
129-
(targetRate, targetRateValid) = cpiOracle.getData();
127+
(uint256 targetRate, bool targetRateValid) = getTargetRate();
130128
require(targetRateValid);
131129

132-
uint256 exchangeRate;
133-
bool rateValid;
134-
(exchangeRate, rateValid) = marketOracle.getData();
130+
(uint256 exchangeRate, bool rateValid) = getExchangeRate();
135131
require(rateValid);
136132

137133
if (exchangeRate > MAX_RATE) {
138134
exchangeRate = MAX_RATE;
139135
}
140136

141137
int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);
142-
143138
if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
144139
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
145140
}
@@ -267,6 +262,20 @@ contract UFragmentsPolicy is Ownable {
267262
uFrags = uFrags_;
268263
}
269264

265+
/**
266+
* @return The current price target and validity from the cpi oracle.
267+
*/
268+
function getTargetRate() public returns (uint256, bool) {
269+
return cpiOracle.getData();
270+
}
271+
272+
/**
273+
* @return The current exchange rate and validity from the market oracle.
274+
*/
275+
function getExchangeRate() public returns (uint256, bool) {
276+
return marketOracle.getData();
277+
}
278+
270279
/**
271280
* @return If the latest block timestamp is within the rebase time window it, returns true.
272281
* Otherwise, returns false.
@@ -333,7 +342,6 @@ contract UFragmentsPolicy is Ownable {
333342
rebaseFunctionUpperPercentage,
334343
rebaseFunctionGrowth
335344
);
336-
337345
return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
338346
}
339347

test/unit/UFragmentsPolicy.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ const INITIAL_TARGET_RATE_25P_LESS = imul(INITIAL_TARGET_RATE, '0.75', 1)
2020
const INITIAL_RATE = ethers.utils.parseUnits('1.05', 18)
2121
const INITIAL_RATE_30P_MORE = imul(INITIAL_RATE, '1.3', 1)
2222
const INITIAL_RATE_30P_LESS = imul(INITIAL_RATE, '0.7', 1)
23-
const INITIAL_RATE_5P_MORE = imul(INITIAL_RATE, '1.05', 1)
24-
const INITIAL_RATE_5P_LESS = imul(INITIAL_RATE, '0.95', 1)
23+
const INITIAL_RATE_2P_MORE = imul(INITIAL_RATE, '1.02', 1)
24+
const INITIAL_RATE_2P_LESS = imul(INITIAL_RATE, '0.98', 1)
2525
const INITIAL_RATE_60P_MORE = imul(INITIAL_RATE, '1.6', 1)
2626
const INITIAL_RATE_50P_LESS = imul(INITIAL_RATE, '0.5', 1)
2727
const INITIAL_RATE_2X = INITIAL_RATE.mul(2)
@@ -702,7 +702,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
702702
await increaseTime(60)
703703

704704
await mockExternalData(
705-
INITIAL_RATE_5P_MORE.sub(2),
705+
INITIAL_RATE_2P_MORE.sub(2),
706706
INITIAL_TARGET_RATE,
707707
1000,
708708
)
@@ -716,7 +716,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
716716
await increaseTime(60)
717717

718718
await mockExternalData(
719-
INITIAL_RATE_5P_LESS.add(2),
719+
INITIAL_RATE_2P_LESS.add(2),
720720
INITIAL_TARGET_RATE,
721721
1000,
722722
)

0 commit comments

Comments
 (0)