This project contains the smart contracts used for LooksRare's raffle protocol. The main contract Raffle
allows anyone to create a raffle with multiple prizes and winners. The fees must be paid in ETH or ERC-20, while
the prizes can be ERC-721, ERC-1155, ETH or ERC-20.
Each raffle consists of the following states:
-
None
There is no raffle at the provided ID. -
Open
The raffle has been created, prizes have been deposited and is open for entries. -
Drawing
When a raffle's minimum entries has reached before the cutoff time, the smart contract calls Chainlink VRF to draw a random number to determine the winners. Raffle owners also have the option to draw the winners if the minimum entries is not met after the cutoff time. The stateDrawing
represents the intermediary state of waiting for Chainlink VRF's callback. -
RandomnessFulfilled
When Chainlink VRF's callback is complete, the raffle stores the random words and transitions toRandomnessFulfilled
. -
Drawn
The process to store random words and to select the winners are separated into 2 functions as there is a 2.5m callback gas limit from Chainlink. Once the winners are selected via the functionselectWinners
, the raffle is consideredDrawn
. -
Complete
After the raffle creator claims the fees accumulated from selling raffle tickets, the raffle is consideredComplete
. -
Refundable
If the raffle is still in theCreated
state (no prizes were deposited) or is not able to sell out at least the specified minimum entries, then the raffle can be cancelled. The raffle can be transitioned toRefundable
state if there are deposited prizes. The raffle creator can withdraw the prizes and the ticket buyers can withdraw the fees spent (if any). -
Cancelled
A raffle can transition fromRefundable
toCancelled
by having the raffle creator withdrawing the prizes or it can transition fromCreated
toCancelled
directly if the prizes were never deposited. Ticket buyers can still withdraw the fees spent.
The contract owner can set a protocol fee recipient and a protocol fee basis points (up to 25%) per raffle.
Each raffle can have between 1 to 5 pricing options. The rules are as follows:
- The raffle's minimum entries must be divisible by the first pricing option's entries count.
- The first pricing option must not have a price of 0.
- Each pricing option after the first one must have a higher entries count than the previous one.
- Each pricing option after the first one must have a higher total price than the previous one.
- Each pricing option after the first one must not have a higher price per entry than the previous one.
- Each pricing option's entries count must be divisible by the next pricing option's entries count.
- Each raffle's lifespan must between 1 day to 7 days.
- If the fee/prize token is an ERC-20, then it must be allowed by the contract owner (LooksRare's multi-sig).
- There can be up to 200 prizes per raffle. Each ERC-721 prize counts as 1 even if they belong to the same collection. Each ERC-20 / ERC-1155 with the same token ID and multiple winners count as 1.
- The maximum winners per raffle is 200.