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: locking l2 upgrade #542

Merged
merged 17 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 10 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
127 changes: 121 additions & 6 deletions contracts/governance/locking/LockingBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@ import "./libs/LibBrokenLine.sol";
abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
using LibBrokenLine for LibBrokenLine.BrokenLine;
/**
* @dev Duration of a week in blocks on the CELO blockchain assuming 5 seconds per block
* @dev Duration of a week in blocks on the CELO blockchain before the L2 transition (5 seconds per block)
*/
uint32 public constant WEEK = 120_960;

/**
* @dev Duration of a week in blocks on the CELO blockchain after the L2 transition (1 seconds per block)
*/
uint32 public constant L2_WEEK = 604_800;

/**
* @dev Maximum allowable cliff period for token locks in weeks
*/
Expand Down Expand Up @@ -84,6 +90,31 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
* @dev Total supply line of veMento
*/
LibBrokenLine.BrokenLine public totalSupplyLine;

// ***************
// New variables for L2 transition upgrade (3 slots)
// ***************
/**
* @dev L2 transtion block number
baroooo marked this conversation as resolved.
Show resolved Hide resolved
*/
uint256 public l2Block;
baroooo marked this conversation as resolved.
Show resolved Hide resolved
/**
* @dev L2 starting point week number
*/
int256 public l2StartingPointWeek;
/**
* @dev Shift amount used after L2 transition to move the start of the epoch to 00-00 UTC Wednesday (approx)
*/
uint32 public l2Shift;
/**
* @dev Address of the Mento Labs multisig
*/
address public mentoLabsMultisig;
/**
* @dev Flag to pause locking and governance
*/
bool public paused;

/**
* @dev Emitted when create Lock with parameters (account, delegate, amount, slopePeriod, cliff)
*/
Expand Down Expand Up @@ -125,6 +156,26 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
* @dev set newMinSlopePeriod
*/
event SetMinSlopePeriod(uint256 indexed newMinSlopePeriod);
/**
* @dev set new Mento Labs multisig address
*/
event SetMentoLabsMultisig(address indexed mentoLabsMultisig);
/**
* @dev set new L2 transition block number
*/
event SetL2TransitionBlock(uint256 indexed l2Block);
/**
* @dev set new L2 shift amount
*/
event SetL2Shift(uint32 indexed l2Shift);
/**
* @dev set new L2 starting point week number
*/
event SetL2StartingPointWeek(int256 indexed l2StartingPointWeek);
/**
* @dev set new paused flag
*/
event SetPaused(bool indexed paused);

/**
* @dev Initializes the contract with token, starting point week, and minimum cliff and slope periods.
Expand All @@ -149,6 +200,11 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
minSlopePeriod = _minSlopePeriod;
}

modifier onlyMentoLabs() {
require(msg.sender == mentoLabsMultisig, "caller is not MentoLabs multisig");
_;
}

/**
* @notice Adds a new locking line for an account, initializing the lock with specified parameters.
* @param account Address for which tokens are being locked.
Expand Down Expand Up @@ -256,20 +312,29 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {

/**
* @notice Calculates the week number for a given blocknumber
* @dev It takes L2 transition into account to calculate the week number consistently
* @param ts block number
* @return week number the block number belongs to
*/
function roundTimestamp(uint32 ts) public view returns (uint32) {
baroooo marked this conversation as resolved.
Show resolved Hide resolved
require(!paused, "locking is paused");

if (ts < getEpochShift()) {
return 0;
}
uint32 shifted = ts - (getEpochShift());
return shifted / WEEK - uint32(startingPointWeek);

if (l2Block == 0 || ts < l2Block) {
uint32 shifted = ts - getEpochShift();
baroooo marked this conversation as resolved.
Show resolved Hide resolved
return shifted / WEEK - uint32(startingPointWeek);
} else {
uint32 shifted = ts - l2Shift;
return uint32(uint256(int256(uint256(shifted / L2_WEEK)) - l2StartingPointWeek));
}
}

/**
* @notice method returns the amount of blocks to shift locking epoch to.
* we move it to 00-00 UTC Wednesday (approx) by shifting 89964 blocks (CELO)
* @notice method returns the amount of blocks to shift locking epoch on L1 CELO.
* we move it to 00-00 UTC Wednesday (approx) by shifting 89964 blocks
*/
function getEpochShift() internal view virtual returns (uint32) {
return 89964;
Expand Down Expand Up @@ -351,6 +416,56 @@ abstract contract LockingBase is OwnableUpgradeable, IVotesUpgradeable {
uint32 time = roundTimestamp(blockNumber);
updateTotalSupplyLine(time);
}
/**
* @notice Sets the Mento Labs multisig address
* @param mentoLabsMultisig_ address of the Mento Labs multisig
*
*/
function setMentoLabsMultisig(address mentoLabsMultisig_) external onlyOwner {
mentoLabsMultisig = mentoLabsMultisig_;
emit SetMentoLabsMultisig(mentoLabsMultisig_);
}
baroooo marked this conversation as resolved.
Show resolved Hide resolved
/**
* @notice Sets the L2 transition block number and pauses locking and governance
* @param l2Block_ block number of the L2 transition
*
baroooo marked this conversation as resolved.
Show resolved Hide resolved
*/
baroooo marked this conversation as resolved.
Show resolved Hide resolved
function setL2TransitionBlock(uint256 l2Block_) external onlyMentoLabs {
l2Block = l2Block_;
paused = true;

emit SetL2TransitionBlock(l2Block_);
}

/**
* @notice Sets the L2 shift amount
* @param l2Shift_ shift amount that will be used after L2 transition
*/
function setL2Shift(uint32 l2Shift_) external onlyMentoLabs {
l2Shift = l2Shift_;

emit SetL2Shift(l2Shift_);
}

/**
* @notice Sets the L2 starting point week number
* @param l2StartingPointWeek_ starting point week number that will be used after L2 transition
*/
function setL2StartingPointWeek(int256 l2StartingPointWeek_) external onlyMentoLabs {
l2StartingPointWeek = l2StartingPointWeek_;

emit SetL2StartingPointWeek(l2StartingPointWeek_);
}

/**
* @notice Sets the paused flag
* @param paused_ flag to pause locking and governance
*/
function setPaused(bool paused_) external onlyMentoLabs {
paused = paused_;

emit SetPaused(paused_);
}

uint256[50] private __gap;
uint256[47] private __gap;
}
3 changes: 3 additions & 0 deletions test/fork/ForkTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import { BancorExchangeProviderForkTest } from "./BancorExchangeProviderForkTest
import { GoodDollarTradingLimitsForkTest } from "./GoodDollar/TradingLimitsForkTest.sol";
import { GoodDollarSwapForkTest } from "./GoodDollar/SwapForkTest.sol";
import { GoodDollarExpansionForkTest } from "./GoodDollar/ExpansionForkTest.sol";
import { LockingUpgradeForkTest } from "./upgrades/LockingUpgradeForkTest.sol";

contract Alfajores_ChainForkTest is ChainForkTest(ALFAJORES_ID, 1, uints(16)) {}

Expand Down Expand Up @@ -120,3 +121,5 @@ contract Celo_GoodDollarTradingLimitsForkTest is GoodDollarTradingLimitsForkTest
contract Celo_GoodDollarSwapForkTest is GoodDollarSwapForkTest(CELO_ID) {}

contract Celo_GoodDollarExpansionForkTest is GoodDollarExpansionForkTest(CELO_ID) {}

contract Celo_LockingUpgradeForkTest is LockingUpgradeForkTest(CELO_ID) {}
Loading
Loading