Skip to content

Commit

Permalink
added exchange rate and cpi getters on policy
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Oct 9, 2024
1 parent 929b239 commit fe4a8c6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
24 changes: 16 additions & 8 deletions contracts/UFragmentsPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -124,22 +124,17 @@ contract UFragmentsPolicy is Ownable {

epoch = epoch.add(1);

uint256 targetRate;
bool targetRateValid;
(targetRate, targetRateValid) = cpiOracle.getData();
(uint256 targetRate, bool targetRateValid) = getTargetRate();
require(targetRateValid);

uint256 exchangeRate;
bool rateValid;
(exchangeRate, rateValid) = marketOracle.getData();
(uint256 exchangeRate, bool rateValid) = getExchangeRate();
require(rateValid);

if (exchangeRate > MAX_RATE) {
exchangeRate = MAX_RATE;
}

int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);

if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
}
Expand Down Expand Up @@ -267,6 +262,20 @@ contract UFragmentsPolicy is Ownable {
uFrags = uFrags_;
}

/**
* @return The current price target and validity from the cpi oracle.
*/
function getTargetRate() public returns (uint256, bool) {
return cpiOracle.getData();
}

/**
* @return The current exchange rate and validity from the market oracle.
*/
function getExchangeRate() public returns (uint256, bool) {
return marketOracle.getData();
}

/**
* @return If the latest block timestamp is within the rebase time window it, returns true.
* Otherwise, returns false.
Expand Down Expand Up @@ -333,7 +342,6 @@ contract UFragmentsPolicy is Ownable {
rebaseFunctionUpperPercentage,
rebaseFunctionGrowth
);

return uFrags.totalSupply().toInt256Safe().mul(rebasePercentage).div(ONE);
}

Expand Down
8 changes: 4 additions & 4 deletions test/unit/UFragmentsPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ const INITIAL_TARGET_RATE_25P_LESS = imul(INITIAL_TARGET_RATE, '0.75', 1)
const INITIAL_RATE = ethers.utils.parseUnits('1.05', 18)
const INITIAL_RATE_30P_MORE = imul(INITIAL_RATE, '1.3', 1)
const INITIAL_RATE_30P_LESS = imul(INITIAL_RATE, '0.7', 1)
const INITIAL_RATE_5P_MORE = imul(INITIAL_RATE, '1.05', 1)
const INITIAL_RATE_5P_LESS = imul(INITIAL_RATE, '0.95', 1)
const INITIAL_RATE_2P_MORE = imul(INITIAL_RATE, '1.02', 1)
const INITIAL_RATE_2P_LESS = imul(INITIAL_RATE, '0.98', 1)
const INITIAL_RATE_60P_MORE = imul(INITIAL_RATE, '1.6', 1)
const INITIAL_RATE_50P_LESS = imul(INITIAL_RATE, '0.5', 1)
const INITIAL_RATE_2X = INITIAL_RATE.mul(2)
Expand Down Expand Up @@ -702,7 +702,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
await increaseTime(60)

await mockExternalData(
INITIAL_RATE_5P_MORE.sub(2),
INITIAL_RATE_2P_MORE.sub(2),
INITIAL_TARGET_RATE,
1000,
)
Expand All @@ -716,7 +716,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
await increaseTime(60)

await mockExternalData(
INITIAL_RATE_5P_LESS.add(2),
INITIAL_RATE_2P_LESS.add(2),
INITIAL_TARGET_RATE,
1000,
)
Expand Down

0 comments on commit fe4a8c6

Please sign in to comment.