This repository has been archived by the owner on Oct 26, 2022. It is now read-only.
generated from sushiswap/hardhat-foundation
-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
pragma solidity 0.8.10; | ||
|
||
abstract contract Domain { | ||
/*////////////////////////////////////////////////////////////// | ||
DOMAIN STORAGE/LOGIC | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
uint256 internal immutable INITIAL_CHAIN_ID; | ||
|
||
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR; | ||
|
||
mapping(address => uint256) public nonces; | ||
|
||
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) { | ||
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator(); | ||
} | ||
|
||
function computeDomainSeparator() internal view virtual returns (bytes32) { | ||
return | ||
keccak256( | ||
abi.encode( | ||
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"), | ||
keccak256(bytes("Domain")), | ||
keccak256("1"), | ||
block.chainid, | ||
address(this) | ||
) | ||
); | ||
} | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
CONSTRUCTOR | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
constructor() { | ||
INITIAL_CHAIN_ID = block.chainid; | ||
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator(); | ||
} | ||
} |