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

chore: refactor codes #486

Merged
merged 3 commits into from
Feb 4, 2024
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
50 changes: 21 additions & 29 deletions abi/bscgovernor.abi
Original file line number Diff line number Diff line change
Expand Up @@ -566,19 +566,6 @@
],
"stateMutability": "view"
},
{
"type": "function",
"name": "governorProtector",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "hasVoted",
Expand Down Expand Up @@ -644,6 +631,19 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "isPaused",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "lateQuorumVoteExtension",
Expand Down Expand Up @@ -808,19 +808,6 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "paused",
"inputs": [],
"outputs": [
{
"name": "",
"type": "bool",
"internalType": "bool"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "proposalDeadline",
Expand Down Expand Up @@ -1842,12 +1829,12 @@
},
{
"type": "error",
"name": "Empty",
"name": "AlreadyPaused",
"inputs": []
},
{
"type": "error",
"name": "GovernorPaused",
"name": "Empty",
"inputs": []
},
{
Expand All @@ -1871,6 +1858,11 @@
}
]
},
{
"type": "error",
"name": "NotPaused",
"inputs": []
},
{
"type": "error",
"name": "NotWhitelisted",
Expand All @@ -1888,7 +1880,7 @@
},
{
"type": "error",
"name": "OnlyGovernorProtector",
"name": "OnlyProtector",
"inputs": []
},
{
Expand Down
30 changes: 11 additions & 19 deletions abi/stakehub.abi
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@
"outputs": [],
"stateMutability": "nonpayable"
},
{
"type": "function",
"name": "assetProtector",
"inputs": [],
"outputs": [
{
"name": "",
"type": "address",
"internalType": "address"
}
],
"stateMutability": "view"
},
{
"type": "function",
"name": "blackList",
Expand Down Expand Up @@ -1568,6 +1555,11 @@
],
"anonymous": false
},
{
"type": "error",
"name": "AlreadyPaused",
"inputs": []
},
{
"type": "error",
"name": "AlreadySlashed",
Expand Down Expand Up @@ -1661,14 +1653,19 @@
},
{
"type": "error",
"name": "OnlyAssetProtector",
"name": "NotPaused",
"inputs": []
},
{
"type": "error",
"name": "OnlyCoinbase",
"inputs": []
},
{
"type": "error",
"name": "OnlyProtector",
"inputs": []
},
{
"type": "error",
"name": "OnlySelfDelegation",
Expand Down Expand Up @@ -1700,11 +1697,6 @@
"name": "SelfDelegationNotEnough",
"inputs": []
},
{
"type": "error",
"name": "StakeHubPaused",
"inputs": []
},
{
"type": "error",
"name": "TransferFailed",
Expand Down
74 changes: 8 additions & 66 deletions contracts/BC_fusion/BSCGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorVotesQ
import "@openzeppelin/contracts-upgradeable/governance/extensions/GovernorPreventLateQuorumUpgradeable.sol";

import "./System.sol";
import "./extension/Protectable.sol";
import "./lib/Utils.sol";
import "./interface/IGovToken.sol";

contract BSCGovernor is
System,
Initializable,
Protectable,
GovernorUpgradeable,
GovernorSettingsUpgradeable,
GovernorCompatibilityBravoUpgradeable,
Expand Down Expand Up @@ -48,50 +50,18 @@ contract BSCGovernor is
error NotWhitelisted();
// @notice signature: 0x11b6707f
error TotalSupplyNotEnough();
// @notice signature: 0xe96776bf
error GovernorPaused();
// @notice signature: 0x286300de
error OnlyGovernorProtector();
// @notice signature: 0xb1d02c3d
error InBlackList();
// @notice signature: 0x867f3ee5
error OneLiveProposalPerProposer();

/*----------------- events -----------------*/
event Paused();
event Resumed();
event BlackListed(address indexed target);
event UnBlackListed(address indexed target);

/*----------------- storage -----------------*/
// target contract => is whitelisted for governance
mapping(address => bool) public whitelistTargets;

bool public proposeStarted;
bool public paused;

address public governorProtector;
mapping(address => bool) public blackList;

// @notice The latest proposal for each proposer
mapping(address => uint256) public latestProposalIds;

/*----------------- modifier -----------------*/
modifier whenNotPaused() {
if (paused) revert GovernorPaused();
_;
}

modifier onlyGovernorProtector() {
if (msg.sender != governorProtector) revert OnlyGovernorProtector();
_;
}

modifier notInBlackList() {
if (blackList[msg.sender]) revert InBlackList();
_;
}

/*----------------- init -----------------*/
function initialize() external initializer onlyCoinbase onlyZeroGasPrice {
__Governor_init("BSCGovernor");
Expand All @@ -107,40 +77,7 @@ contract BSCGovernor is

// TODO
// Different address will be set depending on the environment
governorProtector = address(0xdEaD);
}

/*----------------- onlyGovernorProtector -----------------*/
/**
* @dev Pause the whole system in emergency
*/
function pause() external onlyGovernorProtector {
paused = true;
emit Paused();
}

/**
* @dev Resume the whole system
*/
function resume() external onlyGovernorProtector {
paused = false;
emit Resumed();
}

/**
* @dev Add an address to the black list
*/
function addToBlackList(address account) external onlyGovernorProtector {
blackList[account] = true;
emit BlackListed(account);
}

/**
* @dev Remove an address from the black list
*/
function removeFromBlackList(address account) external onlyGovernorProtector {
blackList[account] = false;
emit UnBlackListed(account);
__Protectable_init_unchained(address(0xdEaD));
}

/*----------------- external functions -----------------*/
Expand Down Expand Up @@ -258,6 +195,11 @@ contract BSCGovernor is
uint64 newMinPeriodAfterQuorum = value.bytesToUint64(8);
if (newMinPeriodAfterQuorum == 0 || newMinPeriodAfterQuorum > 2 days) revert InvalidValue(key, value);
_setLateQuorumVoteExtension(newMinPeriodAfterQuorum);
} else if (key.compareStrings("governorProtector")) {
if (value.length != 20) revert InvalidValue(key, value);
address newGovernorProtector = value.bytesToAddress(20);
if (newGovernorProtector == address(0)) revert InvalidValue(key, value);
_setProtector(newGovernorProtector);
} else {
revert UnknownParam(key, value);
}
Expand Down
Loading
Loading