0

Hi I have a mint function I am working on where there are 3 users groups ie A, B, C. The total supply is split in 2, with 2 user groups sharing the same amount of supply. I am looking for a way to keep track of the total minted by group A, to use that variable in my group B logic.

Here is my code stripped down to illustrate what I mean -

        uint256 public maxSupply = 2000;

        if(groupA == true) {
            maxSupply = 1000; 
            uint256 totalMinted = ?; // NEED TO KEEP TRACK ON HOW MANY WERE MINTED

         uint256 ownerTokenCount = addressMintedBalance[msg.sender];
         require(ownerTokenCount + _mintAmount <= perAddressLimit, "max per address exceeded");
        }
        if(groupB == true) {
            maxSupply = 1000 - totalMinted; // GET REMAINING SUPPLY TOTAL
        } 
        if(groupC == true) {
         maxSupply = 1000;
        }

With ownerTokenCount I can track the amount minted for the user, but I would need to track the total minted using the group A function. Any ideas that wouldn't require a lot of gas?

2 Answers 2

0

if you want a very low gas solution, assuming that you already have a way to know when an user belongs to each group and how the limit per group seems to be a small number you can try to use bitwise operations to store how much each group have minted and write it to a single variable, assigning a limited number of bytes to each value, that way you can read and write with a little less gas if you need the three values at once

1
  • Sorry but I only need the amount minted by group A to subtract from the reserved supply for group A and B.
    – 730wavy
    Feb 15, 2022 at 22:53
0

For my solution I ended up using counters with some custom logic in my functions -

import "@openzeppelin/contracts/utils/Counters.sol";
...
using Counters for Counters.Counter;
...
Counters.Counter private supply;
...
supply.increment();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.