-
Notifications
You must be signed in to change notification settings - Fork 506
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
ERC721Permit - PermitForAll #271
Merged
Merged
Changes from 11 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bd1afc1
initial impl
saucepoint d2e9425
hashing tests
saucepoint 5d22b1d
setApprovalForAll override tests
saucepoint 0f675cb
reorganize ERC721Permit file
saucepoint e005016
separate out tests for permit and permitForAll
saucepoint 5cdaba4
tests for permitForAll
saucepoint 3a54c91
regenerate gas
saucepoint c90e0e9
regenerate gas
saucepoint 4ccc9b7
add to interface
saucepoint 25f2e3a
merge in main; regenerate gas
saucepoint 3a254d0
pr feedback
saucepoint c9e8c06
rename variable
saucepoint 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
2 changes: 1 addition & 1 deletion
2
.forge-snapshots/PositionManager_multicall_initialize_mint.snap
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 |
---|---|---|
@@ -1 +1 @@ | ||
416622 | ||
416667 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
79445 | ||
79484 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
62333 | ||
62372 |
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 |
---|---|---|
@@ -1 +1 @@ | ||
45221 | ||
45260 |
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 |
---|---|---|
|
@@ -17,23 +17,61 @@ abstract contract ERC721Permit_v4 is ERC721, IERC721Permit_v4, EIP712_v4, Unorde | |
/// @notice Computes the nameHash and versionHash | ||
constructor(string memory name_, string memory symbol_) ERC721(name_, symbol_) EIP712_v4(name_) {} | ||
|
||
modifier checkSignatureDeadline(uint256 deadline) { | ||
if (block.timestamp > deadline) revert SignatureDeadlineExpired(); | ||
_; | ||
} | ||
|
||
/// @inheritdoc IERC721Permit_v4 | ||
function permit(address spender, uint256 tokenId, uint256 deadline, uint256 nonce, bytes calldata signature) | ||
external | ||
payable | ||
checkSignatureDeadline(deadline) | ||
{ | ||
if (block.timestamp > deadline) revert DeadlineExpired(); | ||
|
||
address owner = ownerOf(tokenId); | ||
if (spender == owner) revert NoSelfPermit(); | ||
_checkNoSelfPermit(owner, spender); | ||
|
||
bytes32 hash = ERC721PermitHashLibrary.hash(spender, tokenId, nonce, deadline); | ||
signature.verify(_hashTypedData(hash), owner); | ||
bytes32 digest = ERC721PermitHashLibrary.hashPermit(spender, tokenId, nonce, deadline); | ||
signature.verify(_hashTypedData(digest), owner); | ||
|
||
_useUnorderedNonce(owner, nonce); | ||
_approve(owner, spender, tokenId); | ||
} | ||
|
||
/// @inheritdoc IERC721Permit_v4 | ||
function permitForAll( | ||
address owner, | ||
address operator, | ||
bool approved, | ||
uint256 deadline, | ||
uint256 nonce, | ||
bytes calldata signature | ||
) external payable checkSignatureDeadline(deadline) { | ||
_checkNoSelfPermit(owner, operator); | ||
|
||
bytes32 hash = ERC721PermitHashLibrary.hashPermitForAll(operator, approved, nonce, deadline); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do u wanna use digest here too? |
||
signature.verify(_hashTypedData(hash), owner); | ||
|
||
_useUnorderedNonce(owner, nonce); | ||
_approveForAll(owner, operator, approved); | ||
} | ||
|
||
/// @notice Enable or disable approval for a third party ("operator") to manage | ||
/// all of `msg.sender`'s assets | ||
/// @dev Emits the ApprovalForAll event. The contract MUST allow | ||
/// multiple operators per owner. | ||
/// @dev Override Solmate's ERC721 setApprovalForAll so setApprovalForAll() and permit() share the _approveForAll method | ||
/// @param operator Address to add to the set of authorized operators | ||
/// @param approved True if the operator is approved, false to revoke approval | ||
function setApprovalForAll(address operator, bool approved) public override { | ||
_approveForAll(msg.sender, operator, approved); | ||
} | ||
|
||
function _approveForAll(address owner, address operator, bool approved) internal { | ||
isApprovedForAll[owner][operator] = approved; | ||
emit ApprovalForAll(owner, operator, approved); | ||
} | ||
|
||
/// @notice Change or reaffirm the approved address for an NFT | ||
/// @dev override Solmate's ERC721 approve so approve() and permit() share the _approve method | ||
/// The zero address indicates there is no approved address | ||
|
@@ -58,4 +96,8 @@ abstract contract ERC721Permit_v4 is ERC721, IERC721Permit_v4, EIP712_v4, Unorde | |
return spender == ownerOf(tokenId) || getApproved[tokenId] == spender | ||
|| isApprovedForAll[ownerOf(tokenId)][spender]; | ||
} | ||
|
||
function _checkNoSelfPermit(address owner, address permitted) internal pure { | ||
if (owner == permitted) revert NoSelfPermit(); | ||
} | ||
} |
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the variable name
hash
highlights as a keyword for me 🤔