Skip to main content

RafflFactory

Git Source Inherits: AutomationCompatibleInterface, VRFConsumerBaseV2Plus, FactoryFeeManager Author: JA (@ubinatus) Raffl is a decentralized platform built on the Ethereum blockchain, allowing users to create and participate in raffles/lotteries with complete transparency, security, and fairness. The RafflFactory contract can be used to create raffle contracts, leveraging Chainlink VRF and Chainlink Automations.

State Variables

keyHash

Max gas to bump to

callbackGasLimit

Callback gas limit for the Chainlink VRF

requestConfirmations

Number of requests confirmations for the Chainlink VRF

subscriptionId

Chainlink subscription ID

implementation

The address that will be used as a delegate call target for Raffls.

_salt

It will be used as the salt for create2

_raffles

Maps the created Raffls addresses

_requestIds

Maps the VRF requestId to the Raffls address

_activeRaffles

Stores the active raffles, which upkeep is pending to be performed

Functions

constructor

*Creates a Raffl factory contract. Requirements:
  • implementationAddress has to be a contract.
  • feeCollectorAddress can’t be address 0x0.
  • poolFeePercentage must be within 0 and maxFee range.
  • vrfCoordinator can’t be address 0x0.*
Parameters
NameTypeDescription
implementationAddressaddressAddress of Raffl contract implementation.
feeCollectorAddressaddressAddress of feeCollector.
creationFeeValueuint64Value for creationFee that will be charged on new Raffls deployed.
poolFeePercentageuint64Value for poolFeePercentage that will be charged from the Raffls pool on success draw.
vrfCoordinatoraddressVRF Coordinator address
_keyHashbytes32The gas lane to use, which specifies the maximum gas price to bump to
_subscriptionIduint256The subscription ID that this contract uses for funding VRF requests

nextSalt

Increments the salt one step.

createRaffle

Creates new Raffl contracts. Requirements:
  • underlyingTokenAddress cannot be the zero address.
  • timestamps must be given in ascending order.
  • percentages must be given in ascending order and the last one must always be 1 eth, where 1 eth equals to 100%.
Parameters
NameTypeDescription
entryTokenaddressThe address of the ERC-20 token as entry. If address zero, entry is the network token
entryPriceuint256The value of each entry for the raffle.
minEntriesuint256The minimum number of entries to consider make the draw.
deadlineuint256The block timestamp until the raffle will receive entries and that will perform the draw if criteria is met.
prizesIRaffl.Prize[]The prizes that will be held by this contract.
tokenGatesIRaffl.TokenGate[]The token gating that will be imposed to users.
extraRecipientIRaffl.ExtraRecipientThe extra recipient that will share the rewards (optional).

activeRaffles

Exposes the ActiveRaffles

handleSubscription

Sets the Chainlink VRF subscription settings
Parameters
NameTypeDescription
_subscriptionIduint64The subscription ID that this contract uses for funding VRF requests
_keyHashbytes32The gas lane to use, which specifies the maximum gas price to bump to
_callbackGasLimituint32Callback gas limit for the Chainlink VRF
_requestConfirmationsuint16Number of requests confirmations for the Chainlink VRF

checkUpkeep

Method called by the Chainlink Automation Nodes to check if performUpkeep must be done. Performs the computation to the array of _activeRaffles. This opens the possibility of having several checkUpkeeps done at the same time.
Parameters
NameTypeDescription
checkDatabytesEncoded binary data which contains the lower bound and upper bound of the _activeRaffles array on which to perform the computation
Returns
NameTypeDescription
upkeepNeededboolWhether the upkeep must be performed or not
performDatabytesEncoded binary data which contains the raffle address and index of the _activeRaffles

performUpkeep

Permissionless write method usually called by the Chainlink Automation Nodes. Either starts the draw for a raffle or cancels the raffle if criteria is not met.
Parameters
NameTypeDescription
performDatabytesEncoded binary data which contains the raffle address and index of the _activeRaffles

fulfillRandomWords

Method called by the Chainlink VRF Coordinator
Parameters
NameTypeDescription
requestIduint256Id of the VRF request
randomWordsuint256[]Provably fair and verifiable array of random words

_burnActiveRaffle

Helper function to remove a raffle from the _activeRaffles array Move the last element to the deleted stop and removes the last element
Parameters
NameTypeDescription
iuint256Element index to remove

setFeeCollector

FUNCTIONS *Set address of fee collector. Requirements:
  • msg.sender has to be the owner of the factory.
  • newFeeCollector can’t be address 0x0.*
Parameters
NameTypeDescription
newFeeCollectoraddressAddress of feeCollector.

Events

RaffleCreated

Parameters
NameTypeDescription
raffleaddressAddress of the created raffle

Structs

ActiveRaffle

raffle the address of the raffle deadline is the timestamp that marks the start time to perform the upkeep effect.