The event within IERC2309.sol is useful for batch minting of consecutive tokenIds. However, I need something that can handle non-sequential tokenIds so that it can be extended outside of minting. For example, when Alice transfers tokenIds 2,3,6,10,12 to Bob using a batch transfer function, I'd like to be able to emit a single event summarizing that transfer, i.e:
event ConsecutiveTransferBatch(
uint256[] indexed tokenIds,
address indexed fromAddress,
address indexed toAddress
);
Does something like this exist?
I did a quick test in Remix with the following code:
// SPDX-License-Identifier: MIT
pragma solidity >=0.8;
contract A {
// Copied from IERC721.sol
event Transfer(
address indexed from,
address indexed to,
uint256 indexed tokenId
);
// Modified from IERC2309.sol, and made to look more like Transfer(...)
event ConsecutiveTransferBatch(
address indexed from,
address indexed to,
uint256[] indexed tokenIds
);
function transfer(uint256[] calldata tokenIds)
public {
uint256 _batchSize = tokenIds.length;
for (uint256 i; i<_batchSize;) {
emit Transfer(address(0), address(0), tokenIds[i]);
unchecked {++i;}
}
}
function transferConsecutive(uint256[] calldata tokenIds)
public {
// Including the loop to get a more accurate cost difference
uint256 _batchSize = tokenIds.length;
for (uint256 i; i<_batchSize;) {
unchecked {++i;}
}
emit ConsecutiveTransferBatch(address(0), address(0), tokenIds);
}
}
Results for the execution gas costs are as follows:
BatchSize | Transfer | ConsecutiveTransferBatch
1 | 2496 | 2578
2 | 4534 | 2633
5 | 10648 | 2798
10 | 20838 | 3073
So it's obvious the improvement could be extended to non-sequential transfers. I'm just not sure if anything like this exists somewhere? And if not, where is the best place to go about suggesting an update/improvement to the existing IERC2309 to handle non-sequential transfers?