Skip to content

Commit 55c4c4a

Browse files
feat: Add README
1 parent 111784d commit 55c4c4a

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

README.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<p align="center">
2+
<h1 align="center">MultiRaffle</h1>
3+
</p>
4+
<p align="center">
5+
<b><a href="https://github.com/anish-agnihotri/MultiRaffle#About">About</a></b>
6+
|
7+
<b><a href="https://github.com/anish-agnihotri/MultiRaffle#Implementation">Implementation</a></b>
8+
|
9+
<b><a href="https://github.com/anish-agnihotri/MultiRaffle#License">License</a></b>
10+
</p>
11+
12+
# About
13+
14+
MultiRaffle is an **unaudited, unoptimized** NFT distribution reference, implenting a randomized multi-winner raffle and randomized on-chain metadata generation.
15+
16+
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](https://docs.chain.link/docs/chainlink-vrf/).
17+
18+
# Implementation
19+
20+
1. Each raffle begins with an `operator` assigning constants including `NFT Name`, `NFT Symbol`, `Mint Cost (per NFT)`, `Raffle Start Time`, `Raffle End Time`, `Available NFT Supply`, and `Max Raffle Entries per Address`.
21+
2. Then, for the period that the raffle is active, `users` can enter the raffle and claim up to `Max Raffle Entries per Address` tickets.
22+
3. 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 call `clearRaffle` (either in partial steps socializing gas cost, or all at once) to forward [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle) the raffle entries and choose winners.
23+
24+
```solidity
25+
// Fisher-Yates shuffle across set of raffle tickets
26+
for (uint256 i = shuffledCount; i < shuffledCount + numShuffles; i++) {
27+
// Generate a random index to select from
28+
uint256 randomIndex = i + entropy % (raffleEntries.length - i);
29+
// Collect the value at that random index
30+
address randomTmp = raffleEntries[randomIndex];
31+
// Update the value at the random index to the current value
32+
raffleEntries[randomIndex] = raffleEntries[i];
33+
// Update the current value to the value at the random index
34+
raffleEntries[i] = randomTmp;
35+
}
36+
```
37+
38+
4. Once winning tickets have been determined, `users` can claim either NFTs for their winning tickets or a refund for their losing tickets.
39+
5. Finally, once `users` have their NFTs, they can choose to reveal metadata. This will randomly reveal the metadata for all NFTs pending metadata.
40+
41+
```solidity
42+
// Metadata for range of tokenIds (batch applied to startIndex - endIndex)
43+
struct Metadata {
44+
// Starting index (inclusive)
45+
uint256 startIndex;
46+
// Ending index (exclusive)
47+
uint256 endIndex;
48+
// Randomness for range of tokens
49+
uint256 entropy;
50+
}
51+
```
52+
53+
# Build and Test
54+
55+
```bash
56+
# Collect repo
57+
git clone https://github.com/anish-agnihotri/MultiRaffle
58+
cd MultiRaffle
59+
60+
# Checkout tests branch to modify contract to mock Chainlink
61+
git checkout -t origin/tests
62+
63+
# Run tests
64+
make
65+
make test
66+
```
67+
68+
# Installing the toolkit
69+
70+
If you do not have DappTools already installed, you'll need to run the commands below:
71+
72+
## Install Nix
73+
74+
```bash
75+
# User must be in sudoers
76+
curl -L https://nixos.org/nix/install | sh
77+
78+
# Run this or login again to use Nix
79+
. "$HOME/.nix-profile/etc/profile.d/nix.sh"
80+
```
81+
82+
## Install DappTools
83+
84+
```bash
85+
curl https://dapp.tools/install | sh
86+
```
87+
88+
# License
89+
90+
[GNU Affero GPL v3.0](https://github.com/Anish-Agnihotri/MultiRaffle/blob/master/LICENSE)
91+
92+
# Credits
93+
94+
- [@gakonst/lootloose](https://github.com/gakonst/lootloose) for DappTools info + inspiration
95+
- ds-test, OZ, Chainlink for inherited libraries
96+
97+
# Disclaimer
98+
99+
_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._

0 commit comments

Comments
 (0)