Anish-Agnihotri/MultiRaffle
حول
NFT distribution with (1) randomized, multi-winner raffles and (2) bulk on-chain metadata generation.
الأعمال والماليةالنمو المقاس للنجوم
- خلال 24 ساعة
- -١
- خلال 7 أيام
- -١
- خلال 15 يومًا
- -١
- خلال شهر
- جارٍ جمع السجل
تغيّر صافي النجوم خلال فترات متداخلة، وليس مجموعًا يوميًا. تبقى القياسات المفقودة فارغة. النجوم تقيس الاهتمام لا جودة البرمجيات.
README.md
الأصل
MultiRaffle
About | Implementation | License
About
MultiRaffle is an unaudited, unoptimized NFT distribution reference, implenting a randomized multi-winner raffle and randomized on-chain metadata generation.
It allows operators to quickly deploy an NFT distribution that allows users to purchase refundable raffle tickets, potentially win NFTs, and randomly assign metadata to these NFTs via Chainlink VRF.
Implementation
- Each raffle begins with an
operatorassigning constants includingNFT Name,NFT Symbol,Mint Cost (per NFT),Raffle Start Time,Raffle End Time,Available NFT Supply, andMax Raffle Entries per Address. - Then, for the period that the raffle is active,
userscan enter the raffle and claim up toMax Raffle Entries per Addresstickets. - Once the raffling period is finished, the NFTs can be distributed among winning tickets. If there are fewer purchased tickets than the
Available NFT Supply, no clearing is required. Else, anyone can and must callclearRaffle(either in partial steps socializing gas cost, or all at once) to forward Fisher-Yates shuffle the raffle entries and choose winners.
// Fisher-Yates shuffle across set of raffle tickets
for (uint256 i = shuffledCount; i < shuffledCount + numShuffles; i++) {
// Generate a random index to select from
uint256 randomIndex = i + entropy % (raffleEntries.length - i);
// Collect the value at that random index
address randomTmp = raffleEntries[randomIndex];
// Update the value at the random index to the current value
raffleEntries[randomIndex] = raffleEntries[i];
// Update the current value to the value at the random index
raffleEntries[i] = randomTmp;
}
- Once winning tickets have been determined,
userscan claim either NFTs for their winning tickets or a refund for their losing tickets. - Finally, once
usershave their NFTs, they can choose to reveal metadata. This will randomly reveal the metadata for all NFTs pending metadata.
// Metadata for range of tokenIds (batch applied to startIndex - endIndex)
struct Metadata {
// Starting index (inclusive)
uint256 startIndex;
// Ending index (exclusive)
uint256 endIndex;
// Randomness for range of tokens
uint256 entropy;
}
Build and Test
# Collect repo
git clone https://github.com/anish-agnihotri/MultiRaffle
cd MultiRaffle
# Checkout tests branch to modify contract to mock Chainlink
git checkout -t origin/tests
# Run tests
make
make test
Installing the toolkit
If you do not have DappTools already installed, you'll need to run the commands below:
Install Nix
# User must be in sudoers
curl -L https://nixos.org/nix/install | sh
# Run this or login again to use Nix
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
Install DappTools
curl https://dapp.tools/install | sh
License
Credits
- @gakonst/lootloose for DappTools info + inspiration
- ds-test, OZ, Chainlink for inherited libraries
Disclaimer
These smart contracts are being provided as is. No guarantee, representation or warranty is being made, express or implied, as to the safety or correctness of the user interface or the smart contracts. They have not been audited and as such there can be no assurance they will work as intended, and users may experience delays, failures, errors, omissions, loss of transmitted information or loss of funds. Paradigm is not liable for any of the foregoing. Users should proceed with caution and use at their own risk.
استكشف مشاريع مشابهة ومرتبطة
جارٍ التحميل…