Skip to content

Commit 055eb16

Browse files
authored
Set lastRebaseTimestampSec to the offset time instead of the beginning of the start of minRebaseTimeIntervalSec cyclic interval (#134)
* fixed lastRebase time calculation bug * logging block time instead of snapped time
1 parent ab83c34 commit 055eb16

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

contracts/UFragmentsPolicy.sol

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ contract UFragmentsPolicy is Ownable {
9696
require(lastRebaseTimestampSec.add(minRebaseTimeIntervalSec) < now);
9797

9898
// Snap the rebase time to the start of this window.
99-
lastRebaseTimestampSec = now.sub(now.mod(minRebaseTimeIntervalSec));
99+
lastRebaseTimestampSec = now.sub(
100+
now.mod(minRebaseTimeIntervalSec)).add(rebaseWindowOffsetSec);
100101

101102
epoch = epoch.add(1);
102103

@@ -127,7 +128,7 @@ contract UFragmentsPolicy is Ownable {
127128

128129
uint256 supplyAfterRebase = uFrags.rebase(epoch, supplyDelta);
129130
assert(supplyAfterRebase <= MAX_SUPPLY);
130-
emit LogRebase(epoch, exchangeRate, cpi, supplyDelta, lastRebaseTimestampSec);
131+
emit LogRebase(epoch, exchangeRate, cpi, supplyDelta, now);
131132
}
132133

133134
/**

test/unit/UFragmentsPolicy.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -567,22 +567,23 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
567567
});
568568

569569
contract('UFragmentsPolicy:Rebase', async function (accounts) {
570-
let rbTime, rbWindow, minRebaseTimeIntervalSec, now, prevRebaseTime, nextRebaseTime,
571-
timeToWait;
570+
let rbTime, rbWindow, minRebaseTimeIntervalSec, now, prevRebaseTime, nextRebaseWindowOpenTime,
571+
timeToWait, lastRebaseTimestamp;
572572

573573
beforeEach('setup UFragmentsPolicy contract', async function () {
574574
await setupContracts();
575+
await uFragmentsPolicy.setRebaseTimingParameters(86400, 72000, 900);
575576
rbTime = await uFragmentsPolicy.rebaseWindowOffsetSec.call();
576577
rbWindow = await uFragmentsPolicy.rebaseWindowLengthSec.call();
577578
minRebaseTimeIntervalSec = await uFragmentsPolicy.minRebaseTimeIntervalSec.call();
578579
now = new BigNumber(await chain.currentTime());
579580
prevRebaseTime = now.minus(now.mod(minRebaseTimeIntervalSec)).plus(rbTime);
580-
nextRebaseTime = prevRebaseTime.plus(minRebaseTimeIntervalSec);
581+
nextRebaseWindowOpenTime = prevRebaseTime.plus(minRebaseTimeIntervalSec);
581582
});
582583

583584
describe('when its 5s after the rebase window closes', function () {
584585
it('should fail', async function () {
585-
timeToWait = nextRebaseTime.minus(now).plus(rbWindow).plus(5);
586+
timeToWait = nextRebaseWindowOpenTime.minus(now).plus(rbWindow).plus(5);
586587
await chain.waitForSomeTime(timeToWait.toNumber());
587588
await mockExternalData(INITIAL_RATE, INITIAL_CPI, 1000);
588589
expect(await uFragmentsPolicy.inRebaseWindow.call()).to.be.false;
@@ -594,7 +595,7 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
594595

595596
describe('when its 5s before the rebase window opens', function () {
596597
it('should fail', async function () {
597-
timeToWait = nextRebaseTime.minus(now).minus(5);
598+
timeToWait = nextRebaseWindowOpenTime.minus(now).minus(5);
598599
await chain.waitForSomeTime(timeToWait.toNumber());
599600
await mockExternalData(INITIAL_RATE, INITIAL_CPI, 1000);
600601
expect(await uFragmentsPolicy.inRebaseWindow.call()).to.be.false;
@@ -606,25 +607,29 @@ contract('UFragmentsPolicy:Rebase', async function (accounts) {
606607

607608
describe('when its 5s after the rebase window opens', function () {
608609
it('should NOT fail', async function () {
609-
timeToWait = nextRebaseTime.minus(now).plus(5);
610+
timeToWait = nextRebaseWindowOpenTime.minus(now).plus(5);
610611
await chain.waitForSomeTime(timeToWait.toNumber());
611612
await mockExternalData(INITIAL_RATE, INITIAL_CPI, 1000);
612613
expect(await uFragmentsPolicy.inRebaseWindow.call()).to.be.true;
613614
expect(
614615
await chain.isEthException(uFragmentsPolicy.rebase())
615616
).to.be.false;
617+
lastRebaseTimestamp = await uFragmentsPolicy.lastRebaseTimestampSec.call();
618+
expect(lastRebaseTimestamp.eq(nextRebaseWindowOpenTime)).to.be.true;
616619
});
617620
});
618621

619622
describe('when its 5s before the rebase window closes', function () {
620623
it('should NOT fail', async function () {
621-
timeToWait = nextRebaseTime.minus(now).plus(rbWindow).minus(5);
624+
timeToWait = nextRebaseWindowOpenTime.minus(now).plus(rbWindow).minus(5);
622625
await chain.waitForSomeTime(timeToWait.toNumber());
623626
await mockExternalData(INITIAL_RATE, INITIAL_CPI, 1000);
624627
expect(await uFragmentsPolicy.inRebaseWindow.call()).to.be.true;
625628
expect(
626629
await chain.isEthException(uFragmentsPolicy.rebase())
627630
).to.be.false;
631+
lastRebaseTimestamp = await uFragmentsPolicy.lastRebaseTimestampSec.call();
632+
expect(lastRebaseTimestamp.eq(nextRebaseWindowOpenTime)).to.be.true;
628633
});
629634
});
630635
});

0 commit comments

Comments
 (0)