Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions contracts/UFragmentsPolicy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ contract UFragmentsPolicy is Ownable {
epoch = epoch.add(1);

(uint256 targetRate, bool targetRateValid) = getTargetRate();
require(targetRateValid);

(uint256 exchangeRate, bool rateValid) = getExchangeRate();
require(rateValid);

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

int256 supplyDelta = computeSupplyDelta(exchangeRate, targetRate);
int256 supplyDelta = (targetRateValid && rateValid)
? computeSupplyDelta(exchangeRate, targetRate)
: int256(0);
if (supplyDelta > 0 && uFrags.totalSupply().add(uint256(supplyDelta)) > MAX_SUPPLY) {
supplyDelta = (MAX_SUPPLY.sub(uFrags.totalSupply())).toInt256Safe();
}
Expand Down
8 changes: 1 addition & 7 deletions scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ task('deploy:wampl', 'Deploy wampl contract')
await verify(hre, wampl.address, [args.ampl])
})


task('deploy:oracle', 'Deploy the median oracle contract')
.addParam('expiry', 'The report expiry')
.addParam('delay', 'The report delay')
Expand All @@ -213,12 +212,7 @@ task('deploy:oracle', 'Deploy the median oracle contract')

// deploy contract
const oracle = await deployContract(hre, 'MedianOracle', deployer, [])
await oracle.init(
args.expiry,
args.delay,
1,
args.scalar
)
await oracle.init(args.expiry, args.delay, 1, args.scalar)
console.log('Oracle deployed to:', oracle.address)

// wait and verify
Expand Down
52 changes: 48 additions & 4 deletions test/unit/UFragmentsPolicy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,15 +866,15 @@ describe('UFragmentsPolicy:Rebase', async function () {
})

describe('when the market oracle returns invalid data', function () {
it('should fail', async function () {
it('should NOT fail', async function () {
await mockExternalData(
INITIAL_RATE_30P_MORE,
INITIAL_TARGET_RATE,
1000,
false,
)
await increaseTime(60)
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.be
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.not.be
.reverted
})
})
Expand Down Expand Up @@ -908,7 +908,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
})

describe('when the cpi oracle returns invalid data', function () {
it('should fail', async function () {
it('should NOT fail', async function () {
await mockExternalData(
INITIAL_RATE_30P_MORE,
INITIAL_TARGET_RATE,
Expand All @@ -917,7 +917,7 @@ describe('UFragmentsPolicy:Rebase', async function () {
false,
)
await increaseTime(60)
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.be
await expect(uFragmentsPolicy.connect(orchestrator).rebase()).to.not.be
.reverted
})
})
Expand Down Expand Up @@ -1204,6 +1204,50 @@ describe('UFragmentsPolicy:Rebase', async function () {
).to.eq(0)
})
})

describe('rate is invalid', function () {
before(async function () {
await mockExternalData(
INITIAL_RATE_30P_MORE,
INITIAL_TARGET_RATE,
1000,
false,
)
await uFragmentsPolicy.connect(deployer).setDeviationThreshold(0)
await increaseTime(60)
})

it('should emit Rebase with 0 requestedSupplyAdjustment', async function () {
expect(
(
await parseRebaseEvent(
uFragmentsPolicy.connect(orchestrator).rebase(),
)
).requestedSupplyAdjustment,
).to.eq(0)
})
})

describe('target rate is invalid', function () {
before(async function () {
await mockExternalData(
INITIAL_RATE,
INITIAL_TARGET_RATE_25P_MORE,
1000,
true,
false,
)
await uFragmentsPolicy.connect(deployer).setDeviationThreshold(0)
await increaseTime(60)
})

it('should emit Rebase with 0 requestedSupplyAdjustment', async function () {
expect(
(await parseRebaseEvent(uFragmentsPolicy.connect(orchestrator).rebase()))
.requestedSupplyAdjustment,
).to.eq(0)
})
})
})

describe('UFragmentsPolicy:Rebase', async function () {
Expand Down