Skip to content

App facets structs can be optimized#

In ERC721A.sol source code, we can see the following assumption:

 - An owner cannot have more than 2**64 - 1 (max value of uint64) of supply.

So as the max number of tokens per wallet is 2**64,

in DropStorage.sol:

    struct Layout {
        mapping(address => uint256) _mintCount;
        bytes32 _merkleRoot;
        uint256 _dropRevenue;
        // Sales Parameters
        uint256 _maxAmount;
        uint256 _maxPerMint;
        uint256 _maxPerWallet;
        uint256 _price;
        // States
        bool _presaleActive;
        bool _saleActive;
    }

and in EditionStorage.sol:

    struct Edition {
        string tokenURI;
        bytes32 merkleRoot;
        uint256 price;
        uint256 quantity;
        uint256 maxQuantity;
        uint256 maxPerWallet;
        uint256 maxPerMint;
        uint256 nonce;
        address signer;
        bool active;
    }
_maxPerMint and _maxPerWallet, could be uint64.

It would save one slot in each struct which would save gas when accessing the structs.

If the change is made, the functions getting/setting the values should be modified too, for example in EditionFacet.sol:

 function createEdition(
        string memory tokenURI,
        uint256 price,
        uint256 maxQuantity,
        uint256 maxPerWallet,
        uint256 maxPerMint