-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Remove the draft prefix to ERC20Permit #3793
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts v4.4.1 (interfaces/IERC2612.sol) | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "../token/ERC20/extensions/IERC20Permit.sol"; | ||
|
|
||
| interface IERC2612 is IERC20Permit {} |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,8 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts v4.4.1 (interfaces/draft-IERC2612.sol) | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "../token/ERC20/extensions/draft-IERC20Permit.sol"; | ||
| // IERC2612 was marked as draft due to the EIP-2612 dependency. | ||
| // EIP-2612 is Final as of 2022-11-01. This file is deprecated. | ||
|
|
||
| interface IERC2612 is IERC20Permit {} | ||
| import "./IERC2612.sol"; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/extensions/ERC20Permit.sol) | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./IERC20Permit.sol"; | ||
| import "../ERC20.sol"; | ||
| import "../../../utils/cryptography/ECDSA.sol"; | ||
| import "../../../utils/cryptography/EIP712.sol"; | ||
| import "../../../utils/Counters.sol"; | ||
|
|
||
| /** | ||
| * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in | ||
| * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. | ||
| * | ||
| * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by | ||
| * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't | ||
| * need to send a transaction, and thus is not required to hold Ether at all. | ||
| * | ||
| * _Available since v3.4._ | ||
| */ | ||
| abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { | ||
| using Counters for Counters.Counter; | ||
|
|
||
| mapping(address => Counters.Counter) private _nonces; | ||
|
|
||
| // solhint-disable-next-line var-name-mixedcase | ||
| bytes32 private constant _PERMIT_TYPEHASH = | ||
| keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); | ||
| /** | ||
| * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. | ||
| * However, to ensure consistency with the upgradeable transpiler, we will continue | ||
| * to reserve a slot. | ||
| * @custom:oz-renamed-from _PERMIT_TYPEHASH | ||
| */ | ||
| // solhint-disable-next-line var-name-mixedcase | ||
| bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; | ||
|
|
||
| /** | ||
| * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. | ||
| * | ||
| * It's a good idea to use the same `name` that is defined as the ERC20 token name. | ||
| */ | ||
| constructor(string memory name) EIP712(name, "1") {} | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-permit}. | ||
| */ | ||
| function permit( | ||
| address owner, | ||
| address spender, | ||
| uint256 value, | ||
| uint256 deadline, | ||
| uint8 v, | ||
| bytes32 r, | ||
| bytes32 s | ||
| ) public virtual override { | ||
| require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); | ||
|
|
||
| bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); | ||
|
|
||
| bytes32 hash = _hashTypedDataV4(structHash); | ||
|
|
||
| address signer = ECDSA.recover(hash, v, r, s); | ||
| require(signer == owner, "ERC20Permit: invalid signature"); | ||
|
|
||
| _approve(owner, spender, value); | ||
| } | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-nonces}. | ||
| */ | ||
| function nonces(address owner) public view virtual override returns (uint256) { | ||
| return _nonces[owner].current(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. | ||
| */ | ||
| // solhint-disable-next-line func-name-mixedcase | ||
| function DOMAIN_SEPARATOR() external view override returns (bytes32) { | ||
| return _domainSeparatorV4(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev "Consume a nonce": return the current value and increment. | ||
| * | ||
| * _Available since v4.1._ | ||
| */ | ||
| function _useNonce(address owner) internal virtual returns (uint256 current) { | ||
| Counters.Counter storage nonce = _nonces[owner]; | ||
| current = nonce.current(); | ||
| nonce.increment(); | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,60 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Permit.sol) | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| /** | ||
| * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in | ||
| * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. | ||
| * | ||
| * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by | ||
| * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't | ||
| * need to send a transaction, and thus is not required to hold Ether at all. | ||
| */ | ||
| interface IERC20Permit { | ||
| /** | ||
| * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, | ||
| * given ``owner``'s signed approval. | ||
| * | ||
| * IMPORTANT: The same issues {IERC20-approve} has related to transaction | ||
| * ordering also apply here. | ||
| * | ||
| * Emits an {Approval} event. | ||
| * | ||
| * Requirements: | ||
| * | ||
| * - `spender` cannot be the zero address. | ||
| * - `deadline` must be a timestamp in the future. | ||
| * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` | ||
| * over the EIP712-formatted function arguments. | ||
| * - the signature must use ``owner``'s current nonce (see {nonces}). | ||
| * | ||
| * For more information on the signature format, see the | ||
| * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP | ||
| * section]. | ||
| */ | ||
| function permit( | ||
| address owner, | ||
| address spender, | ||
| uint256 value, | ||
| uint256 deadline, | ||
| uint8 v, | ||
| bytes32 r, | ||
| bytes32 s | ||
| ) external; | ||
|
|
||
| /** | ||
| * @dev Returns the current nonce for `owner`. This value must be | ||
| * included whenever a signature is generated for {permit}. | ||
| * | ||
| * Every successful call to {permit} increases ``owner``'s nonce by one. This | ||
| * prevents a signature from being used multiple times. | ||
| */ | ||
| function nonces(address owner) external view returns (uint256); | ||
|
|
||
| /** | ||
| * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. | ||
| */ | ||
| // solhint-disable-next-line func-name-mixedcase | ||
| function DOMAIN_SEPARATOR() external view returns (bytes32); | ||
| } |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,95 +1,8 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC20/extensions/draft-ERC20Permit.sol) | ||
|
|
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./draft-IERC20Permit.sol"; | ||
| import "../ERC20.sol"; | ||
| import "../../../utils/cryptography/ECDSA.sol"; | ||
| import "../../../utils/cryptography/EIP712.sol"; | ||
| import "../../../utils/Counters.sol"; | ||
| // IERC20Permit was marked as draft due to the EIP-2612 dependency. | ||
Amxx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // EIP-2612 is Final as of 2022-11-01. This file is deprecated. | ||
|
|
||
| /** | ||
| * @dev Implementation of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in | ||
| * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. | ||
| * | ||
| * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by | ||
| * presenting a message signed by the account. By not relying on `{IERC20-approve}`, the token holder account doesn't | ||
| * need to send a transaction, and thus is not required to hold Ether at all. | ||
| * | ||
| * _Available since v3.4._ | ||
| */ | ||
| abstract contract ERC20Permit is ERC20, IERC20Permit, EIP712 { | ||
| using Counters for Counters.Counter; | ||
|
|
||
| mapping(address => Counters.Counter) private _nonces; | ||
|
|
||
| // solhint-disable-next-line var-name-mixedcase | ||
| bytes32 private constant _PERMIT_TYPEHASH = | ||
| keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); | ||
| /** | ||
| * @dev In previous versions `_PERMIT_TYPEHASH` was declared as `immutable`. | ||
| * However, to ensure consistency with the upgradeable transpiler, we will continue | ||
| * to reserve a slot. | ||
| * @custom:oz-renamed-from _PERMIT_TYPEHASH | ||
| */ | ||
| // solhint-disable-next-line var-name-mixedcase | ||
| bytes32 private _PERMIT_TYPEHASH_DEPRECATED_SLOT; | ||
|
|
||
| /** | ||
| * @dev Initializes the {EIP712} domain separator using the `name` parameter, and setting `version` to `"1"`. | ||
| * | ||
| * It's a good idea to use the same `name` that is defined as the ERC20 token name. | ||
| */ | ||
| constructor(string memory name) EIP712(name, "1") {} | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-permit}. | ||
| */ | ||
| function permit( | ||
| address owner, | ||
| address spender, | ||
| uint256 value, | ||
| uint256 deadline, | ||
| uint8 v, | ||
| bytes32 r, | ||
| bytes32 s | ||
| ) public virtual override { | ||
| require(block.timestamp <= deadline, "ERC20Permit: expired deadline"); | ||
|
|
||
| bytes32 structHash = keccak256(abi.encode(_PERMIT_TYPEHASH, owner, spender, value, _useNonce(owner), deadline)); | ||
|
|
||
| bytes32 hash = _hashTypedDataV4(structHash); | ||
|
|
||
| address signer = ECDSA.recover(hash, v, r, s); | ||
| require(signer == owner, "ERC20Permit: invalid signature"); | ||
|
|
||
| _approve(owner, spender, value); | ||
| } | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-nonces}. | ||
| */ | ||
| function nonces(address owner) public view virtual override returns (uint256) { | ||
| return _nonces[owner].current(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev See {IERC20Permit-DOMAIN_SEPARATOR}. | ||
| */ | ||
| // solhint-disable-next-line func-name-mixedcase | ||
| function DOMAIN_SEPARATOR() external view override returns (bytes32) { | ||
| return _domainSeparatorV4(); | ||
| } | ||
|
|
||
| /** | ||
| * @dev "Consume a nonce": return the current value and increment. | ||
| * | ||
| * _Available since v4.1._ | ||
| */ | ||
| function _useNonce(address owner) internal virtual returns (uint256 current) { | ||
| Counters.Counter storage nonce = _nonces[owner]; | ||
| current = nonce.current(); | ||
| nonce.increment(); | ||
| } | ||
| } | ||
| import "./ERC20Permit.sol"; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.