mirror of
https://github.com/luxfi/sudoamm.git
synced 2026-07-25 16:17:09 +00:00
Remove last NFT first when using idSet to save gas
This commit is contained in:
@@ -32,10 +32,14 @@ abstract contract LSSVMPairMissingEnumerable is LSSVMPair {
|
||||
) internal override {
|
||||
// Send NFTs to recipient
|
||||
// We're missing enumerable, so we also update the pair's own ID set
|
||||
// NOTE: We start from last index to first index to save on gas
|
||||
uint256 lastIndex = idSet.length() - 1;
|
||||
for (uint256 i = 0; i < numNFTs; i++) {
|
||||
uint256 nftId = idSet.at(0);
|
||||
_nft.safeTransferFrom(address(this), nftRecipient, nftId);
|
||||
idSet.remove(nftId);
|
||||
unchecked {
|
||||
uint256 nftId = idSet.at(lastIndex--);
|
||||
_nft.safeTransferFrom(address(this), nftRecipient, nftId);
|
||||
idSet.remove(nftId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user