Skip to content

Commit 5e14374

Browse files
authored
no-op supply change when oracle inputs are invalid (#290)
1 parent be7c2b4 commit 5e14374

File tree

3 files changed

+52
-16
lines changed

3 files changed

+52
-16
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,14 @@ contract UFragmentsPolicy is Ownable {
125125
epoch = epoch.add(1);
126126

127127
(uint256 targetRate, bool targetRateValid) = getTargetRate();
128-
require(targetRateValid);
129-
130128
(uint256 exchangeRate, bool rateValid) = getExchangeRate();
131-
require(rateValid);
132-
133129
if (exchangeRate > MAX_RATE) {
134130
exchangeRate = MAX_RATE;
135131
}
136132

137-
int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);
133+
int256 supplyDelta = (targetRateValid && rateValid)
134+
? computeSupplyDelta(exchangeRate, targetRate)
135+
: int256(0);
138136
if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
139137
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
140138
}

scripts/deploy.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,6 @@ task('deploy:wampl', 'Deploy wampl contract')
199199
await verify(hre, wampl.address, [args.ampl])
200200
})
201201

202-
203202
task('deploy:oracle', 'Deploy the median oracle contract')
204203
.addParam('expiry', 'The report expiry')
205204
.addParam('delay', 'The report delay')
@@ -213,12 +212,7 @@ task('deploy:oracle', 'Deploy the median oracle contract')
213212

214213
// deploy contract
215214
const oracle = await deployContract(hre, 'MedianOracle', deployer, [])
216-
await oracle.init(
217-
args.expiry,
218-
args.delay,
219-
1,
220-
args.scalar
221-
)
215+
await oracle.init(args.expiry, args.delay, 1, args.scalar)
222216
console.log('Oracle deployed to:', oracle.address)
223217

224218
// wait and verify

test/unit/UFragmentsPolicy.ts

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -866,15 +866,15 @@ describe('UFragmentsPolicy:Rebase', async function () {
866866
})
867867

868868
describe('when the market oracle returns invalid data', function () {
869-
it('should fail', async function () {
869+
it('should NOT fail', async function () {
870870
await mockExternalData(
871871
INITIAL_RATE_30P_MORE,
872872
INITIAL_TARGET_RATE,
873873
1000,
874874
false,
875875
)
876876
await increaseTime(60)
877-
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.be
877+
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.not.be
878878
.reverted
879879
})
880880
})
@@ -908,7 +908,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
908908
})
909909

910910
describe('when the cpi oracle returns invalid data', function () {
911-
it('should fail', async function () {
911+
it('should NOT fail', async function () {
912912
await mockExternalData(
913913
INITIAL_RATE_30P_MORE,
914914
INITIAL_TARGET_RATE,
@@ -917,7 +917,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
917917
false,
918918
)
919919
await increaseTime(60)
920-
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.be
920+
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.not.be
921921
.reverted
922922
})
923923
})
@@ -1204,6 +1204,50 @@ describe('UFragmentsPolicy:Rebase', async function () {
12041204
).to.eq(0)
12051205
})
12061206
})
1207+
1208+
describe('rate is invalid', function () {
1209+
before(async function () {
1210+
await mockExternalData(
1211+
INITIAL_RATE_30P_MORE,
1212+
INITIAL_TARGET_RATE,
1213+
1000,
1214+
false,
1215+
)
1216+
await uFragmentsPolicy.connect(deployer).setDeviationThreshold(0)
1217+
await increaseTime(60)
1218+
})
1219+
1220+
it('should emit Rebase with 0 requestedSupplyAdjustment', async function () {
1221+
expect(
1222+
(
1223+
await parseRebaseEvent(
1224+
uFragmentsPolicy.connect(orchestrator).rebase(),
1225+
)
1226+
).requestedSupplyAdjustment,
1227+
).to.eq(0)
1228+
})
1229+
})
1230+
1231+
describe('target rate is invalid', function () {
1232+
before(async function () {
1233+
await mockExternalData(
1234+
INITIAL_RATE,
1235+
INITIAL_TARGET_RATE_25P_MORE,
1236+
1000,
1237+
true,
1238+
false,
1239+
)
1240+
await uFragmentsPolicy.connect(deployer).setDeviationThreshold(0)
1241+
await increaseTime(60)
1242+
})
1243+
1244+
it('should emit Rebase with 0 requestedSupplyAdjustment', async function () {
1245+
expect(
1246+
(await parseRebaseEvent(uFragmentsPolicy.connect(orchestrator).rebase()))
1247+
.requestedSupplyAdjustment,
1248+
).to.eq(0)
1249+
})
1250+
})
12071251
})
12081252

12091253
describe('UFragmentsPolicy:Rebase', async function () {

0 commit comments

Comments
 (0)