chiru-labs / ERC721A

https://ERC721A.org
MIT License
2.5k stars 840 forks source link

Add `ERC721ABatchBurnable` extension #444

Closed jjranalli closed 2 months ago

jjranalli commented 1 year ago

This PR introduces the ERC721ABatchBurnable extension, leveraging the _batchBurn function introduced here and then refactored in #450.

Assumptions

Some assumptions had to be made:

Notes

Vectorized commented 1 year ago

O.O Sort.

Vectorized commented 1 year ago

Oh, possible to add in an approvalCheck parameter to the function?

Similar to _burn(tokenId, approvalCheck).

In case someone has a use case for doing batch transfers internally.

jjranalli commented 1 year ago

Oh, possible to add in an approvalCheck parameter to the function?

Absolutely, on it. Just to confirm, it would result in the following functions:

Vectorized commented 1 year ago

@jjranalli Yes!

jjranalli commented 1 year ago

@Vectorized approvalCheck flag added.

Also fixing some issues with the logic. Will push a new version soon

jjranalli commented 1 year ago

The commit above is an attempt to ensure correctness of nextInitialized for all token IDs, while minimizing gas impact.

Vectorized commented 1 year ago

I think the sort can use insertion sort. Then we can add a comment on passing in sorted tokenIds for best performance. The full intro sort costs several hundred bytes of bytecode.

Thanks so much for the PR.

I’m wondering if we can also do batch burning.

jjranalli commented 1 year ago

Perfect, makes sense! Switched to insertion sort.

I had to bump prettier-plugin-solidity as it was causing an error during lint preventing checks to go through. However that also caused formatting to change across other contracts. Lmk how you want me to handle that

Will take care of tests now

I’m wondering if we can also do batch burning

Absolutely, we can use same concept on burn too. Happy to take care of that as well, maybe in a separate PR

jjranalli commented 1 year ago

@Vectorized Apologies for the long wait! This is now ready for review

Notes

jjranalli commented 1 year ago

I had to bump prettier-plugin-solidity as it was causing an error during lint preventing checks to go through. However that also caused formatting to change across other contracts.

Also restored formatting to how it was. Hopefully checks will go through now.

jjranalli commented 1 year ago

@Vectorized It's done! 🫡 I ended up adding batch burns directly in this PR as it leverages common logic to that written for batch transfers. PR got a bit large but hope that's not an issue

Main changes

Batch transfers

batchBurn

Notes

jjranalli commented 1 year ago

@Vectorized should I make changes to this PR based on #450?

jjranalli commented 1 year ago

@Vectorized Managed to have a look at #450, awesome stuff over there. A few questions while I merge it in here and clean things up:

Also was trying to optimise gas in this commit by resetting _packedOwnerships for sequential IDs, but then realised that without additional ownership checks it would allow burner to burn any token basically. Might be a better way to handle it.

Nlferu commented 3 months ago

Hi @Vectorized

Are there any updates on batchTransferFrom and batchBurn extensions? Any chance those will be included into ERC721A soon?