Skip to content

Commit

Permalink
feat(smart-contracts): UP token contract (#13875)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemsos committed May 28, 2024
1 parent 0887d2e commit cd3123d
Show file tree
Hide file tree
Showing 12 changed files with 950 additions and 777 deletions.
153 changes: 153 additions & 0 deletions smart-contracts/contracts/tokens/UP/UPGovernor.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.21;

import "@openzeppelin/contracts-upgradeable5/proxy/utils/Initializable.sol";
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/governance/extensions/GovernorVotesQuorumFractionUpgradeable.sol";

/// @custom:security-contact hello@unlock-protocol.com
contract UPGovernor is
Initializable,
GovernorUpgradeable,
GovernorSettingsUpgradeable,
GovernorCountingSimpleUpgradeable,
GovernorVotesUpgradeable,
GovernorVotesQuorumFractionUpgradeable,
GovernorTimelockControlUpgradeable
{
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}

function initialize(
IVotes _token,
TimelockControllerUpgradeable _timelock
) public initializer {
__Governor_init("UnlockProtocolGovernor");
__GovernorSettings_init(6 days, 6 days, 0);
__GovernorCountingSimple_init();
__GovernorVotes_init(_token);
__GovernorVotesQuorumFraction_init(3);
__GovernorTimelockControl_init(_timelock);
}

function quorumDenominator() public pure override returns (uint256) {
return 1000;
}

// The following functions are overrides required by Solidity.

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();
}
}
15 changes: 15 additions & 0 deletions smart-contracts/contracts/tokens/UP/UPTimelock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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,
address admin
) public initializer {
__TimelockController_init(minDelay, proposers, executors, admin);
}
}
70 changes: 70 additions & 0 deletions smart-contracts/contracts/tokens/UP/UPToken.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// 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 UPToken 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());
}

// required to base votes on timestamp instead of blocks
function clock() public view override returns (uint48) {
return uint48(block.timestamp);
}

// solhint-disable-next-line func-name-mixedcase
function CLOCK_MODE() public pure override returns (string memory) {
return "mode=timestamp";
}

// 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);
}
}

0 comments on commit cd3123d

Please sign in to comment.