Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Shift locking week #320

Merged
merged 2 commits into from
Dec 7, 2023
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
4 changes: 2 additions & 2 deletions contracts/governance/locking/LockingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,10 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {

/**
* @notice method returns the amount of blocks to shift locking epoch to.
* we move it to 00-00 UTC Friday by shifting 3564 blocks (approx) (CELO)
* we move it to 00-00 UTC Wednesday (approx) by shifting 89964 blocks (CELO)
*/
function getEpochShift() internal view virtual returns (uint32) {
return 3564;
return 89964;
}

function verifyLockOwner(uint256 id) internal view returns (address account) {
Expand Down
21 changes: 14 additions & 7 deletions test/governance/Locking/locking.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -240,20 +240,27 @@ contract Lock_Locking_Test is Locking_Test {

function test_getWeek_shouldReturnCorrectWeekNo() public {
uint32 dayInBlocks = weekInBlocks / 7;
uint32 currentBlock = 21664044; // (Sep-29-2023 11:59:59 AM +UTC) Friday

uint32 currentBlock = 21664044; // (Sep-29-2023 11:59:59 AM +UTC) Friday
lockingContract.setBlock(currentBlock);
lockingContract.setEpochShift(3564);

// without shifting, it is week #179 with 12_204 blocks reminder
assertEq(lockingContract.getWeek(), 179);
assertEq(lockingContract.blockTillNextPeriod(), 112320); // 6.5 days in blocks CELO

_incrementBlock(5 * dayInBlocks);
assertEq(lockingContract.getWeek(), 179);
lockingContract.setEpochShift(89_964);

// since we shift more than remainder(89_964 > 12_204), we are now in the previous week, #178
assertEq(lockingContract.getWeek(), 178);

// FRI 12:00 -> WED 00:00 = 4.5 days
assertEq(lockingContract.blockTillNextPeriod(), (9 * dayInBlocks) / 2);

_incrementBlock(3 * dayInBlocks);
assertEq(lockingContract.getWeek(), 178);
_incrementBlock(dayInBlocks);
assertEq(lockingContract.getWeek(), 179);
assertEq(lockingContract.getWeek(), 178);
_incrementBlock(dayInBlocks);
assertEq(lockingContract.getWeek(), 180);
assertEq(lockingContract.getWeek(), 179);
}

function test_getAvailableForWithdraw_shouldReturnCorrectAmount() public {
Expand Down
Loading