Skip to content

Commit d1ff1f6

Browse files
authored
Merge pull request #130 from ampleforth/naguib-0-rebase
If oracle data is invalid apply 0 supply change instead of reverting transaction.
2 parents 0cc0a5b + 7e065e2 commit d1ff1f6

File tree

2 files changed

+14
-31
lines changed

2 files changed

+14
-31
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,28 +91,29 @@ contract UFragmentsPolicy is Ownable {
9191
uint256 cpi;
9292
bool cpiValid;
9393
(cpi, cpiValid) = cpiOracle.getData();
94-
require(cpiValid);
9594

9695
uint256 targetRate = cpi.mul(10 ** DECIMALS).div(baseCpi);
9796

9897
uint256 exchangeRate;
9998
bool rateValid;
10099
(exchangeRate, rateValid) = marketOracle.getData();
101-
require(rateValid);
102100

103101
if (exchangeRate > MAX_RATE) {
104102
exchangeRate = MAX_RATE;
105103
}
106104

107-
int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);
105+
int256 supplyDelta = 0;
108106

109-
// Apply the Dampening factor.
110-
supplyDelta = supplyDelta.div(rebaseLag.toInt256Safe());
107+
if (cpiValid && rateValid) {
108+
supplyDelta = computeSupplyDelta(exchangeRate, targetRate);
111109

112-
if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
113-
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
114-
}
110+
// Apply the Dampening factor.
111+
supplyDelta = supplyDelta.div(rebaseLag.toInt256Safe());
115112

113+
if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
114+
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
115+
}
116+
}
116117
uint256 supplyAfterRebase = uFrags.rebase(epoch, supplyDelta);
117118
assert(supplyAfterRebase <= MAX_SUPPLY);
118119
emit LogRebase(epoch, exchangeRate, cpi, supplyDelta, lastRebaseTimestampSec);

test/unit/UFragmentsPolicy.js

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -363,20 +363,11 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
363363
before('setup UFragmentsPolicy contract', setupContracts);
364364

365365
describe('when the market oracle returns invalid data', function () {
366-
it('should fail', async function () {
366+
it('supply delta should equal zero', async function () {
367367
await mockExternalData(INITIAL_RATE_30P_MORE, INITIAL_CPI, 1000, false);
368-
expect(
369-
await chain.isEthException(uFragmentsPolicy.rebase())
370-
).to.be.true;
371-
});
372-
});
368+
r = await uFragmentsPolicy.rebase();
369+
r.logs[0].args.requestedSupplyAdjustment.should.be.bignumber.eq(0);
373370

374-
describe('when the market oracle returns valid data', function () {
375-
it('should NOT fail', async function () {
376-
await mockExternalData(INITIAL_RATE_30P_MORE, INITIAL_CPI, 1000, true);
377-
expect(
378-
await chain.isEthException(uFragmentsPolicy.rebase())
379-
).to.be.false;
380371
});
381372
});
382373
});
@@ -387,20 +378,11 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
387378
describe('when the cpi oracle returns invalid data', function () {
388379
it('should fail', async function () {
389380
await mockExternalData(INITIAL_RATE_30P_MORE, INITIAL_CPI, 1000, true, false);
390-
expect(
391-
await chain.isEthException(uFragmentsPolicy.rebase())
392-
).to.be.true;
381+
r = await uFragmentsPolicy.rebase();
382+
r.logs[0].args.requestedSupplyAdjustment.should.be.bignumber.eq(0)
393383
});
394384
});
395385

396-
describe('when the cpi oracle returns valid data', function () {
397-
it('should NOT fail', async function () {
398-
await mockExternalData(INITIAL_RATE_30P_MORE, INITIAL_CPI, 1000, true, true);
399-
expect(
400-
await chain.isEthException(uFragmentsPolicy.rebase())
401-
).to.be.false;
402-
});
403-
});
404386
});
405387

406388
contract('UFragmentsPolicy:Rebase', async function (accounts) {

0 commit comments

Comments
 (0)