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(smart-contracts): UP token contract #13875

Merged
merged 27 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
fddde56
move UDT to its own folder
clemsos May 21, 2024
6f70dae
OZ contracts to v5
clemsos May 21, 2024
6b4af58
UP token draft
clemsos May 21, 2024
bf5ac5f
test for UP token setttings
clemsos May 21, 2024
ab8cb90
add votes to erc20
clemsos May 21, 2024
bcb7286
repurpose UDT votes test
clemsos May 21, 2024
618a91e
gov + timelock
clemsos May 21, 2024
0441590
Merge branch 'master' into up-token
clemsos May 21, 2024
c1883eb
Merge branch 'master' into up-token
julien51 May 21, 2024
7f8110c
fix governor settings tests
clemsos May 22, 2024
13819ff
fix gov quorum event
clemsos May 22, 2024
2a42e60
Update smart-contracts/test/UnlockProtocolToken/governor.js
julien51 May 22, 2024
4465c19
Update smart-contracts/contracts/tokens/UP/UPGovernor.sol
clemsos May 22, 2024
24b6e4c
use seconds instead of blocks
clemsos May 22, 2024
508b7c5
Merge branch 'up-token' of github.com:unlock-protocol/unlock into up-…
clemsos May 22, 2024
d1621d3
specifiy timelock admin in constructor
clemsos May 22, 2024
340b58f
Merge branch 'master' into up-token
clemsos May 23, 2024
796699c
use block timetsmp for revert test
clemsos May 23, 2024
cd71637
fix governor testst
clemsos May 23, 2024
649f09d
`increaseTime` receives seconds instead of hours
clemsos May 23, 2024
80833a2
Merge branch 'master' into up-token
clemsos May 23, 2024
4c7195e
rename files to UPToken
clemsos May 24, 2024
3f79de7
Merge branch 'up-token' of github.com:unlock-protocol/unlock into up-…
clemsos May 24, 2024
b40b440
Merge branch 'master' into up-token
clemsos May 24, 2024
748e787
Merge branch 'master' into up-token
clemsos May 24, 2024
68ebc08
Update governor.js
clemsos May 28, 2024
82ffc30
Merge branch 'master' into up-token
clemsos May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
166 changes: 166 additions & 0 deletions smart-contracts/contracts/tokens/UP/UPGovernor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.21;

import "@openzeppelin/contracts-upgradeable5/governance/GovernorUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/governance/extensions/GovernorSettingsUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/governance/extensions/GovernorCountingSimpleUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/governance/extensions/GovernorVotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/governance/extensions/GovernorTimelockControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/proxy/utils/Initializable.sol";

/// @custom:security-contact hello@unlock-protocol.com
contract UPGovernor is
Initializable,
GovernorUpgradeable,
GovernorSettingsUpgradeable,
GovernorCountingSimpleUpgradeable,
GovernorVotesUpgradeable,
GovernorTimelockControlUpgradeable
{
uint private _quorum;

// add custom event for quorum changes
event QuorumSet(uint oldQuorum, uint newQuorum);

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
IVotes _token,
TimelockControllerUpgradeable _timelock
) public initializer {
__Governor_init("UnlockProtocolGovernor");
__GovernorSettings_init(43200 /* 6 day */, 43200 /* 6 days */, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this in seconds? If so this is not 6 days! please use 6* 24 * 60 * 60 for clarty.

__GovernorCountingSimple_init();
__GovernorVotes_init(_token);
__GovernorTimelockControl_init(_timelock);

// default quorum set to 30k
_quorum = 30000e18;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nouvelle syntax?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quorum should be 3k NOT 30k.

}

// quorum set to 30k
clemsos marked this conversation as resolved.
Show resolved Hide resolved
function quorum(uint256) public view override returns (uint256) {
return _quorum;
}

// helper to change quorum
function setQuorum(uint256 newQuorum) public onlyGovernance {
uint256 oldQuorum = _quorum;
_quorum = newQuorum;
emit QuorumSet(oldQuorum, newQuorum);
}

// The following functions are overrides required by Solidity.
clemsos marked this conversation as resolved.
Show resolved Hide resolved

function votingDelay()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingDelay();
}

function votingPeriod()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.votingPeriod();
}

function state(
uint256 proposalId
)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (ProposalState)
{
return super.state(proposalId);
}

function proposalNeedsQueuing(
uint256 proposalId
)
public
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (bool)
{
return super.proposalNeedsQueuing(proposalId);
}

function proposalThreshold()
public
view
override(GovernorUpgradeable, GovernorSettingsUpgradeable)
returns (uint256)
{
return super.proposalThreshold();
}

function _queueOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
)
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (uint48)
{
return
super._queueOperations(
proposalId,
targets,
values,
calldatas,
descriptionHash
);
}

function _executeOperations(
uint256 proposalId,
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
) internal override(GovernorUpgradeable, GovernorTimelockControlUpgradeable) {
super._executeOperations(
proposalId,
targets,
values,
calldatas,
descriptionHash
);
}

function _cancel(
address[] memory targets,
uint256[] memory values,
bytes[] memory calldatas,
bytes32 descriptionHash
)
internal
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (uint256)
{
return super._cancel(targets, values, calldatas, descriptionHash);
}

function _executor()
internal
view
override(GovernorUpgradeable, GovernorTimelockControlUpgradeable)
returns (address)
{
return super._executor();
}
}
14 changes: 14 additions & 0 deletions smart-contracts/contracts/tokens/UP/UPTimelock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;

import "@openzeppelin/contracts-upgradeable/governance/TimelockControllerUpgradeable.sol";

contract UPTimelock is TimelockControllerUpgradeable {
function initialize(
uint256 minDelay,
address[] memory proposers,
address[] memory executors
) public initializer {
__TimelockController_init(minDelay, proposers, executors, msg.sender);
}
}
60 changes: 60 additions & 0 deletions smart-contracts/contracts/tokens/UP/UnlockProtocolToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.21;

import "@openzeppelin/contracts-upgradeable5/token/ERC20/ERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/token/ERC20/extensions/ERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/token/ERC20/extensions/ERC20VotesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable5/proxy/utils/Initializable.sol";
import {NoncesUpgradeable} from "@openzeppelin/contracts-upgradeable5/utils/NoncesUpgradeable.sol";

/// @custom:security-contact hello@unlock-protocol.com
contract UnlockProtocolToken is
Initializable,
ERC20Upgradeable,
ERC20PermitUpgradeable,
ERC20VotesUpgradeable,
OwnableUpgradeable
{
uint public constant TOTAL_SUPPLY = 1_000_000_000;

/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
address initialOwner,
address preMinter
) public initializer {
__ERC20_init("UnlockProtocolToken", "UP");
__ERC20Permit_init("UnlockProtocolToken");
__ERC20Votes_init();
__Ownable_init(initialOwner);

// premint the supply
_mint(preMinter, TOTAL_SUPPLY * 10 ** decimals());
}

// The following functions are overrides required by Solidity.

function _update(
address from,
address to,
uint256 value
) internal override(ERC20Upgradeable, ERC20VotesUpgradeable) {
super._update(from, to, value);
}

function nonces(
address owner
)
public
view
override(ERC20PermitUpgradeable, NoncesUpgradeable)
returns (uint256)
{
return super.nonces(owner);
}
}