NatSpec

Solidity API

DeRafl

This contract is used by DeRafl to hold raffles for any erc721 token

Designed to be as trustless as possible. There are no owner functions. Chainlink VRF is used to determine a winning ticket of a raffle. A refund for a raffle can be initiated 2 days after a raffles expiry date if not already released. LooksRare royaltyFeeRegistry is used to determine royalty rates for collections. Collection royalties are honoured with a max payout of 10%

INTERFACE_ID_ERC721

bytes4 INTERFACE_ID_ERC721

ERC721 interface

MIN_DAYS

uint256 MIN_DAYS

Minimum days a raffle can be active

MAX_DAYS

uint256 MAX_DAYS

Maximum days a raffle can be active

MIN_ETH

uint256 MIN_ETH

Minimum amount of Eth

MAX_ETH

uint256 MAX_ETH

Maximum amount of Eth

MAX_ROYALTY_FEE_PERCENTAGE

uint256 MAX_ROYALTY_FEE_PERCENTAGE

Maximum royalty fee percentage (10%)

DERAFL_FEE_PERCENTAGE

uint256 DERAFL_FEE_PERCENTAGE

DeRafl protocol fee (3%)

uint256 DERAFL_CHAINLINK_FEE

DeRafl Chainlink Fee

TICKET_PRICE

uint256 TICKET_PRICE

Price per ticket

subscriptionId

uint64 subscriptionId

vrfCoordinator

address vrfCoordinator

keyHash

bytes32 keyHash

callbackGasLimit

uint32 callbackGasLimit

requestConfirmations

uint16 requestConfirmations

numWords

uint32 numWords

COORDINATOR

contract VRFCoordinatorV2Interface COORDINATOR

RaffleOpened

event RaffleOpened(uint256 raffleId, address nftAddress, uint256 tokenId, uint256 tickets, uint256 expires)

Emitted when a raffle is created

Parameters

Name
Type
Description

raffleId

uint256

The id of the raffle created

nftAddress

address

The address of the NFT being raffled

tokenId

uint256

The tokenId of the NFT being raffled

tickets

uint256

Maximum amount of tickets to be sold

expires

uint256

The timestamp when the raffle expires

RaffleClosed

event RaffleClosed(uint256 raffleId)

Emitted when a raffle is closed

Parameters

Name
Type
Description

raffleId

uint256

The id of the raffle being closed

RaffleDrawn

event RaffleDrawn(uint256 raffleId, uint256 winningTicket)

Emitted when a raffle is drawn and winning ticket determined

Parameters

Name
Type
Description

raffleId

uint256

The id of the raffle being drawn

winningTicket

uint256

The winning ticket of the raffle being drawn

RaffleReleased

event RaffleReleased(uint256 raffleId, address winner, uint256 royaltiesPaid, uint256 ethPaid)

Emitted when a raffle is released

Parameters

Name
Type
Description

raffleId

uint256

The id of the raffle being released

winner

address

The address of the winning ticket holder

royaltiesPaid

uint256

Collection royalties paid in wei

ethPaid

uint256

Ethereum paid to the raffle owner in wei

RaffleRefunded

event RaffleRefunded(uint256 raffleId)

Emitted when a raffle has been changed to a refunded state

Parameters

Name
Type
Description

raffleId

uint256

The id of the raffle being refunded

TicketPurchased

event TicketPurchased(uint256 raffleId, uint256 batchId, address purchaser, uint256 ticketFrom, uint256 ticketAmount)

Emitted when tickets are purchased

Parameters

Name
Type
Description

raffleId

uint256

The raffle id of the tickets being purchased

batchId

uint256

The batch id of the ticket purchase

purchaser

address

The address of the account making the purchase

ticketFrom

uint256

The first ticket of the ticket batch

ticketAmount

uint256

The amount of tickets being purchased

TicketRefunded

event TicketRefunded(uint256 raffleId, address refundee, uint256 ethAmount)

Emitted when a refund has been placed

Parameters

Name
Type
Description

raffleId

uint256

The raffle id of the raffle being refunded

refundee

address

The account being issued a refund

ethAmount

uint256

The ethereum amount being refunded in wei

RaffleState

enum RaffleState {
  NONE,
  ACTIVE,
  CLOSED,
  REFUNDED,
  PENDING_DRAW,
  DRAWN,
  RELEASED
}

TicketOwner

struct TicketOwner {
  uint256 ticketsOwned;
  bool isRefunded;
}

TicketBatch

struct TicketBatch {
  address owner;
  uint256 startTicket;
  uint256 endTicket;
}

Raffle

struct Raffle {
  uint256 raffleId;
  enum DeRafl.RaffleState raffleState;
  address payable raffleOwner;
  address nftAddress;
  uint256 tokenId;
  uint256 ticketsAvailable;
  uint256 ticketsSold;
  uint256 batchIndex;
  uint256 expiryTimestamp;
  uint256 chainlinkRequestId;
  uint256 winningTicket;
  address winner;
  uint256 royaltyPercentage;
  address royaltyRecipient;
}

royaltyFeeRegistry

contract IRoyaltyFeeRegistry royaltyFeeRegistry

LooksRare royaltyFeeRegistry

raffles

mapping(uint256 => struct DeRafl.Raffle) raffles

mapping of raffleId => raffle

ticketOwners

mapping(uint256 => mapping(address => struct DeRafl.TicketOwner)) ticketOwners

maps a participants TOTAL tickets bought for a raffle

ticketBatches

mapping(uint256 => mapping(uint256 => struct DeRafl.TicketBatch)) ticketBatches

maps ticketBatches purchased for a raffle

chainlinkRequestIdMap

mapping(uint256 => uint256) chainlinkRequestIdMap

maps raffleId to a chainlink VRF request

raffleNonce

uint256 raffleNonce

incremented raffleId

deraflFeeCollector

address payable deraflFeeCollector

address to collect protocol fee

constructor

constructor(uint64 _subscriptionId, address _vrfCoordinator, address royaltyFeeRegistryAddress, address feeCollector) public

getRaffle

function getRaffle(uint256 raffleId) external view returns (struct DeRafl.Raffle rafl)

DeRafl Returns information about a particular raffle

Returns the Raffle struct of the specified Id

Parameters

Name
Type
Description

raffleId

uint256

a parameter just like in doxygen (must be followed by parameter name)

Return Values

Name
Type
Description

rafl

struct DeRafl.Raffle

the Raffle struct at the specified raffleId

getUserInfo

function getUserInfo(uint256 raffleId, address ticketOwner) external view returns (struct DeRafl.TicketOwner)

DeRafl Returns an accounts particiaption for a raffle

TicketOwner contains the total amount of tickets bought for a raffle (sum of all ticket batches) and the refund status of a participant in the raffle

Parameters

Name
Type
Description

raffleId

uint256

The raffle Id of the raffle being queried

ticketOwner

address

The address of the participant being queried

Return Values

Name
Type
Description

[0]

struct DeRafl.TicketOwner

TicketOwner

getBatchInfo

function getBatchInfo(uint256 raffleId, uint256 batchId) external view returns (struct DeRafl.TicketBatch)

DeRafl Information about a specific TicketBatch for a raffle

Finds the TicketBatch for a specific raffle via the ticketBatches mapping

Parameters

Name
Type
Description

raffleId

uint256

The raffle Id of the TicketBatch being queried

batchId

uint256

The batchId for the TicketBatch being queried

Return Values

Name
Type
Description

[0]

struct DeRafl.TicketBatch

TicketBatch

createRaffle

function createRaffle(address nftAddress, uint256 tokenId, uint256 daysActive, uint256 ethInput) external

DeRafl Creates a new raffle

Creates a new raffle and adds it to the raffles mapping

Parameters

Name
Type
Description

nftAddress

address

The address of the NFT being raffled

tokenId

uint256

The token id of the NFT being raffled

daysActive

uint256

How many days until the raffle expires

ethInput

uint256

The maximum amount of Eth to be raised for the raffle

buyTickets

function buyTickets(uint256 raffleId, uint256 ticketAmount) external payable

DeRafl Purchase tickets for a raffle

Allows a user to purchase a ticket batch for a raffle. Validates the raffle state. Refunds extra Eth if overpayed, or if tickets remaining < tickets intended to purchase. Creates a new ticketBatch and adds to ticketBatches mapping. Increments ticketOwner in ticketOwners mapping. Update state of Raffle with specified raffleId. Emit TicketsPurchased event.

Parameters

Name
Type
Description

raffleId

uint256

The address of the NFT being raffled

ticketAmount

uint256

The amount of tickets to purchase

drawRaffle

function drawRaffle(uint256 raffleId) external

DeRafl starts the drawing process for a raffle

Sends a request to chainlink VRF for a random number used to draw a winner. Validates raffleState is closed (sold out), or raffle is expired. Stores the chainlinkRequestId in chainlinkRequestIdMap against the raffleId. emits raffle closed event.

Parameters

Name
Type
Description

raffleId

uint256

The raffleId of the raffle being drawn

release

function release(uint256 raffleId, uint256 batchId) external

Completes a raffle, releases prize and accumulated Eth to relevant stake holders

Validates that the batch referenced includes the winning ticket Validates raffle state is drawn

Parameters

Name
Type
Description

raffleId

uint256

The raffle Id of the raffle being released

batchId

uint256

The batch Id of the batch including the winning ticket

refundRaffle

function refundRaffle(uint256 raffleId) external

Changes a raffles state to REFUNDED, allowing participants to be issued refunds. A raffle can be refunded 2 days after it has expired, and is not in a RELEASED state

Parameters

Name
Type
Description

raffleId

uint256

The raffle id of the raffle being refunded

refundTickets

function refundTickets(uint256 raffleId) external

Issues a refund to an individual participant for all tickets purchased (sum of all ticket batches)

Parameters

Name
Type
Description

raffleId

uint256

The raffle id of the raffle being refunded

claimRefundedNft

function claimRefundedNft(uint256 raffleId) external

Returns the NFT of a refunded raffle to the raffle owner

Parameters

Name
Type
Description

raffleId

uint256

The raffle id of the raffle

getRoyaltyInfo

function getRoyaltyInfo(address nftAddress) public view returns (address, uint256)

Gets the royalty fee percentage of an nft. Returns a maximum of 10%

Parameters

Name
Type
Description

nftAddress

address

The address of the token being queried

requestRandomNumber

function requestRandomNumber() internal returns (uint256)

Requests a random number from chainlink VRF

Return Values

Name
Type
Description

[0]

uint256

chainlinkRequestId of the request

fulfillRandomWords

function fulfillRandomWords(uint256 requestId, uint256[] randomWords) internal

DeRafl Callable by chainlink VRF to receive a random number

Generates a winning ticket number between 0 - tickets sold for a raffle

Parameters

Name
Type
Description

requestId

uint256

The chainlinkRequestId which maps to raffle id

randomWords

uint256[]

random words sent by chainlink

onERC721Received

function onERC721Received(address, address, uint256, bytes) external pure returns (bytes4)

Last updated