Skip to content

Commit

Permalink
feat: remove token receive support
Browse files Browse the repository at this point in the history
reduction of 1.5% (total 9.6%) of GovernorContract deploy cost
#11
  • Loading branch information
DuBento committed Jul 30, 2023
1 parent 3d6d60b commit 3329306
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 117 deletions.
116 changes: 1 addition & 115 deletions blockchain/contracts/DAO/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

pragma solidity ^0.8.19;

import "../../OpenZeppelin/token/ERC721/IERC721Receiver.sol";
import "../../OpenZeppelin/token/ERC1155/IERC1155Receiver.sol";
import "../../OpenZeppelin/utils/introspection/ERC165.sol";
import "../../OpenZeppelin/utils/math/SafeCast.sol";
import "../../OpenZeppelin/utils/Address.sol";
import "./extensions/GovernorExecutor.sol";
Expand All @@ -22,13 +19,7 @@ import "./IGovernor.sol";
*
* Modified version of governance contracts from OpenZeppelin v4.9.1
*/
abstract contract Governor is
GovernorExecutor,
ERC165,
IGovernor,
IERC721Receiver,
IERC1155Receiver
{
abstract contract Governor is GovernorExecutor, IGovernor {
struct ProposalCore {
uint64 voteStart;
address proposer;
Expand Down Expand Up @@ -81,35 +72,6 @@ abstract contract Governor is
}
}

/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165, ERC165) returns (bool) {
bytes4 governorCancelId = this.cancel.selector ^
this.proposalProposer.selector;

// The original interface id in v4.3.
bytes4 governor43Id = type(IGovernor).interfaceId ^
type(IERC6372).interfaceId ^
governorCancelId;

// An updated interface id in v4.6, with params added.
bytes4 governor46Id = type(IGovernor).interfaceId ^
type(IERC6372).interfaceId ^
governorCancelId;

// For the updated interface id in v4.9, we use governorCancelId directly.

return
interfaceId == governor43Id ||
interfaceId == governor46Id ||
interfaceId == governorCancelId ||
interfaceId == type(IERC1155Receiver).interfaceId ||
super.supportsInterface(interfaceId);
}

/**
* @dev See {IGovernor-name}.
*/
Expand Down Expand Up @@ -480,56 +442,6 @@ abstract contract Governor is
Address.verifyCallResult(success, returndata);
}

/**
* @dev See {IERC721Receiver-onERC721Received}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC721Received(
address,
address,
uint256,
bytes memory
) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC721Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155Received}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC1155Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155BatchReceived}.
* Receiving tokens is disabled if the governance executor is other than the governor itself (eg. when using with a timelock).
*/
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual returns (bytes4) {
if (_executor() != address(this)) {
revert GovernorDisabledDeposit();
}
return this.onERC1155BatchReceived.selector;
}

/**
* @dev Encodes a `ProposalState` into a `bytes32` representation where each bit enabled corresponds to
* the underlying position in the `ProposalState` enum. For example:
Expand All @@ -547,30 +459,4 @@ abstract contract Governor is
) internal pure returns (bytes32) {
return bytes32(1 << uint8(proposalState));
}

/**
* @dev Try to parse a character from a string as a hex value. Returns `(true, value)` if the char is in
* `[0-9a-fA-F]` and `(false, 0)` otherwise. Value is guaranteed to be in the range `0 <= value < 16`
*/
function _tryHexToUint(bytes1 char) private pure returns (bool, uint8) {
uint8 c = uint8(char);
unchecked {
// Case 0-9
if (47 < c && c < 58) {
return (true, c - 48);
}
// Case A-F
else if (64 < c && c < 71) {
return (true, c - 55);
}
// Case a-f
else if (96 < c && c < 103) {
return (true, c - 87);
}
// Else: not a hex char
else {
return (false, 0);
}
}
}
}
3 changes: 1 addition & 2 deletions blockchain/contracts/DAO/governance/IGovernor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@

pragma solidity ^0.8.19;

import "../../OpenZeppelin/interfaces/IERC165.sol";
import "../../OpenZeppelin/interfaces/IERC6372.sol";

/**
* @dev Interface of the {Governor} core.
*
* _Available since v4.3._
*/
abstract contract IGovernor is IERC165, IERC6372 {
abstract contract IGovernor is IERC6372 {
enum ProposalState {
Active,
Canceled,
Expand Down

0 comments on commit 3329306

Please sign in to comment.