chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.51k stars 842 forks source link

create an internal _approve function allowing extensions and EIPs to do approvals without check #426

Closed dievardump closed 2 years ago

dievardump commented 2 years ago

The current implementation of ERC721A have _tokenApprovals private and has all the approval management code in the public facing approve function.

This sadly means that there is no way, for a contract extending ERC721A, to internally do approvals without the ownership or isApprovedForAll check.

There are however some EIPs meant to improve ERC721 and tokens management that are in need of being able to approve internally without those checks.

An example is EIP-4494 that introduces Permits to ERC721, allowing to give approvals to accounts by only signing a message instead of having it done on-chain. Very similar to EIP-2612 for ERC20. This EIP could totally change the way we work with marketplaces today, as we would be able to simply sign messages in order to sale items, instead of granting approvalForAll to contracts.

However, EIP-4494 requires the ability to set the approval internally, or at least to bypass the ownership/approvalForAll check, which is right now not possible with the current implementation.

Even if not to accommodate other EIPs and extensions, there can be a lot of reasons for children contracts to be able to do that, similar to the reasons for contracts to be able to burn items internally without that check.

So, as it was already done with the _burn() function, this pull request internalize the content of the _approve function with a version that has a 3rd parameter, to indicate if the ownership & isApprovalForAll needs to be checked or not before setting the approval.

dievardump commented 2 years ago

Sorry, didn't see I was on main, redoing.