generated from dgma/sol-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
baf243a
commit b8bdb4d
Showing
4 changed files
with
155 additions
and
8 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
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
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,12 @@ | ||
// SPDX-License-Identifier: GPL-3.0 | ||
|
||
pragma solidity ^0.8.16; | ||
|
||
import {ERC20Permit, ERC20} from "@openzeppelin/contracts/token/ERC20/extensions/ERC20Permit.sol"; | ||
|
||
contract MockERC20 is ERC20Permit { | ||
constructor() ERC20Permit("Random") ERC20("MockERC20", "ME20") { | ||
uint256 amount = 1 * 10 ** 9 * 10 ** 18; | ||
_mint(msg.sender, amount); | ||
} | ||
} |
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,43 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
|
||
contract SigUtils { | ||
bytes32 internal DOMAIN_SEPARATOR; | ||
|
||
constructor(bytes32 _DOMAIN_SEPARATOR) { | ||
DOMAIN_SEPARATOR = _DOMAIN_SEPARATOR; | ||
} | ||
|
||
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 | ||
// deadline)"); | ||
bytes32 public constant PERMIT_TYPEHASH = | ||
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; | ||
|
||
struct Permit { | ||
address owner; | ||
address spender; | ||
uint256 value; | ||
uint256 nonce; | ||
uint256 deadline; | ||
} | ||
|
||
// computes the hash of a permit | ||
function getStructHash(Permit memory _permit) internal pure returns (bytes32) { | ||
return keccak256( | ||
abi.encode( | ||
PERMIT_TYPEHASH, | ||
_permit.owner, | ||
_permit.spender, | ||
_permit.value, | ||
_permit.nonce, | ||
_permit.deadline | ||
) | ||
); | ||
} | ||
|
||
// computes the hash of the fully encoded EIP-712 message for the domain, which can be used to | ||
// recover the signer | ||
function getTypedDataHash(Permit memory _permit) public view returns (bytes32) { | ||
return keccak256(abi.encodePacked("\x19\x01", DOMAIN_SEPARATOR, getStructHash(_permit))); | ||
} | ||
} |