Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 4 additions & 38 deletions contracts/governance/Governor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

pragma solidity ^0.8.0;

import "../token/ERC721/IERC721Receiver.sol";
import "../token/ERC1155/IERC1155Receiver.sol";
import "../token/ERC721/utils/ERC721Holder.sol";
import "../token/ERC1155/utils/ERC1155Holder.sol";
import "../utils/cryptography/ECDSA.sol";
import "../utils/cryptography/EIP712.sol";
import "../utils/introspection/ERC165.sol";
Expand All @@ -25,7 +25,7 @@ import "./IGovernor.sol";
*
* _Available since v4.3._
*/
abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receiver, IERC1155Receiver {
abstract contract Governor is Context, ERC165, EIP712, IGovernor, ERC721Holder, ERC1155Holder {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is our convention for ordering of interfaces within inheritance lists? I would like to include this in the guidelines doc.

I would always put interfaces first but I think you always put them last. In this case there is an added weirdness though because IGovernor is an abstract contract.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

My main goal was to have the inheritance ordering tests pass. I first I wanted to reorder some things, and I spent ~2h down the rabit hole of fixing ordering when the solution was staring at me from the start.

using DoubleEndedQueue for DoubleEndedQueue.Bytes32Deque;

bytes32 public constant BALLOT_TYPEHASH = keccak256("Ballot(uint256 proposalId,uint8 support)");
Expand Down Expand Up @@ -95,7 +95,7 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165) returns (bool) {
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC165, ERC1155Receiver) returns (bool) {
bytes4 governorCancelId = this.cancel.selector ^ this.proposalProposer.selector;

bytes4 governorParamsId = this.castVoteWithReasonAndParams.selector ^
Expand All @@ -117,7 +117,6 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
interfaceId == governor43Id ||
interfaceId == governor46Id ||
interfaceId == governorCancelId ||
interfaceId == type(IERC1155Receiver).interfaceId ||
super.supportsInterface(interfaceId);
}

Expand Down Expand Up @@ -601,37 +600,4 @@ abstract contract Governor is Context, ERC165, EIP712, IGovernor, IERC721Receive
function _executor() internal view virtual returns (address) {
return address(this);
}

/**
* @dev See {IERC721Receiver-onERC721Received}.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155Received}.
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155BatchReceived}.
*/
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
43 changes: 5 additions & 38 deletions contracts/governance/TimelockController.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
pragma solidity ^0.8.0;

import "../access/AccessControl.sol";
import "../token/ERC721/IERC721Receiver.sol";
import "../token/ERC1155/IERC1155Receiver.sol";
import "../token/ERC721/utils/ERC721Holder.sol";
import "../token/ERC1155/utils/ERC1155Holder.sol";

/**
* @dev Contract module which acts as a timelocked controller. When set as the
Expand All @@ -22,7 +22,7 @@ import "../token/ERC1155/IERC1155Receiver.sol";
*
* _Available since v3.3._
*/
contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver {
contract TimelockController is AccessControl, ERC721Holder, ERC1155Holder {
bytes32 public constant PROPOSER_ROLE = keccak256("PROPOSER_ROLE");
bytes32 public constant EXECUTOR_ROLE = keccak256("EXECUTOR_ROLE");
bytes32 public constant CANCELLER_ROLE = keccak256("CANCELLER_ROLE");
Expand Down Expand Up @@ -122,8 +122,8 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, AccessControl) returns (bool) {
return interfaceId == type(IERC1155Receiver).interfaceId || super.supportsInterface(interfaceId);
function supportsInterface(bytes4 interfaceId) public view virtual override(AccessControl, ERC1155Receiver) returns (bool) {
return super.supportsInterface(interfaceId);
}

/**
Expand Down Expand Up @@ -380,37 +380,4 @@ contract TimelockController is AccessControl, IERC721Receiver, IERC1155Receiver
emit MinDelayChange(_minDelay, newDelay);
_minDelay = newDelay;
}

/**
* @dev See {IERC721Receiver-onERC721Received}.
*/
function onERC721Received(address, address, uint256, bytes memory) public virtual override returns (bytes4) {
return this.onERC721Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155Received}.
*/
function onERC1155Received(
address,
address,
uint256,
uint256,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155Received.selector;
}

/**
* @dev See {IERC1155Receiver-onERC1155BatchReceived}.
*/
function onERC1155BatchReceived(
address,
address,
uint256[] memory,
uint256[] memory,
bytes memory
) public virtual override returns (bytes4) {
return this.onERC1155BatchReceived.selector;
}
}
2 changes: 1 addition & 1 deletion scripts/checks/inheritance-ordering.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ for (const artifact of artifacts) {
const linearized = [];

for (const source in solcOutput.contracts) {
if (source.includes('/mocks/')) {
if (['contracts-exposed', 'contracts/mocks'].some(pattern => source.match(pattern))) {
continue;
}

Expand Down