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

Update contracts to support Solidity 0.8.x #2442

Merged
merged 18 commits into from
Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Use the built-in block.chainid instead of separate a getChainId() fun…
…ction
  • Loading branch information
andrekorol committed Dec 22, 2020
commit e1bb61296d6f2e6865ce2b1e6099c2607b797770
14 changes: 5 additions & 9 deletions contracts/drafts/EIP712.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;
pragma solidity >=0.6.0 <0.9.0;

/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
Expand Down Expand Up @@ -43,13 +43,13 @@ abstract contract EIP712 {
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
constructor(string memory name, string memory version) internal {
bytes32 hashedName = keccak256(bytes(name));
bytes32 hashedVersion = keccak256(bytes(version));
bytes32 typeHash = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
_HASHED_NAME = hashedName;
_HASHED_VERSION = hashedVersion;
_CACHED_CHAIN_ID = _getChainId();
_CACHED_CHAIN_ID = block.chainid;
_CACHED_DOMAIN_SEPARATOR = _buildDomainSeparator(typeHash, hashedName, hashedVersion);
_TYPE_HASH = typeHash;
}
Expand All @@ -58,7 +58,7 @@ abstract contract EIP712 {
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (_getChainId() == _CACHED_CHAIN_ID) {
if (block.chainid == _CACHED_CHAIN_ID) {
return _CACHED_DOMAIN_SEPARATOR;
} else {
return _buildDomainSeparator(_TYPE_HASH, _HASHED_NAME, _HASHED_VERSION);
Expand All @@ -71,7 +71,7 @@ abstract contract EIP712 {
typeHash,
name,
version,
_getChainId(),
block.chainid,
address(this)
)
);
Expand All @@ -95,8 +95,4 @@ abstract contract EIP712 {
function _hashTypedDataV4(bytes32 structHash) internal view returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x01", _domainSeparatorV4(), structHash));
}

function _getChainId() private view returns (uint256 chainId) {
chainId = block.chainid;
}
}
4 changes: 0 additions & 4 deletions contracts/mocks/EIP712External.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,4 @@ contract EIP712External is EIP712 {
address recoveredSigner = ECDSA.recover(digest, signature);
require(recoveredSigner == signer);
}

function getChainId() external view returns (uint256 chainId) {
chainId = block.chainid;
}
}
4 changes: 0 additions & 4 deletions contracts/mocks/ERC20PermitMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,4 @@ contract ERC20PermitMock is ERC20Permit {
) payable ERC20(name, symbol) ERC20Permit(name) {
_mint(initialAccount, initialBalance);
}

function getChainId() external view returns (uint256 chainId) {
chainId = block.chainid;
}
}