Anish-Agnihotri / MultiRaffle

NFT distribution with (1) randomized, multi-winner raffles and (2) bulk on-chain metadata generation.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting a refund when claiming tickets

tzumby opened this issue · comments

commented

Hey @Anish-Agnihotri, thanks for providing this sample contract. Both this and the article are really good resources!

I'm looking at the refund mechanism and wondering if it wouldn't be easier to just compare the number of winningTickets
with the entriesPerAddress(address) and just send the MINT_COST * (entriesPerAddress - winningTickets) as a refund ?

The advantage here is that we don't need to keep track of the losing tickets as well (which would have swapped indices because of the shuffling.

        // Refund losing tickets

        uint256 entriesPerAddress = entriesPerAddress[msg.sender];

        if (winningTickets != entriesPerAddress) {
            // Payout value equal to number of bought tickets - paid for winning tickets
            (bool sent, ) = payable(msg.sender).call{
                value: (entriesPerAddress - winningTickets) * MINT_COST
            }("");
            require(sent, "Unsuccessful in refund");
        }

        // Emit claim event
        emit RaffleClaimed(msg.sender, winningTickets, entriesPerAddress - winningTickets);