RPS Raffle
RPS Raffle is the core smart contract powering our customizable raffle systems. It handles ticket generation, fund management, and raffle logistics, offering a range of configurable parameters for a tailor-made user experience.
Roles
Operator
This backend account is crucial for managing the raffle mechanics. It is responsible for executing the raffle process once the winning tickets have been randomly selected. Importantly, the Operator is needed for this task because the raffle contract does not maintain information regarding ticket ownership.
Router
Represents the RPSRouter contract.
Owner
Holds ultimate control over raffle parameters, such as pot limits, ticket costs, and prize distributions.
State variables
uint256 public potLimit // raffle fund size threshold
uint256 public currentPotSize // current raffle fund volume
uint256 public raffleTicketCost // ticket cost in ether
uint128 private claimWindow // claim period in seconds
uint16 public numberOfWinners
uint16 public tradeFeeInBps; // raffle fee in bps (100 = 1%, 10000 = 100%)
uint32 public lastRaffleTicketId
uint16 public currentPotId
uint16 public protocolFeeInBps // integrated protocol fee as a percentage of funds that go to the raffle; controlled by the raffle owner
Mappings
mapping(address => Prize) public claimablePrizes
mapping(uint256 => RequestStatus) public chainlinkRequests
mapping(uint16 => uint32[]) public winningTicketIds
mapping(uint16 => uint128) public prizeAmounts
mapping(address => uint256) public pendingAmounts // βpartial ticketβ amounts for each user
External functions
function executeTrade(
uint256 _amountInWei,
address _user
) external payable onlyRouter whenNotPaused
Generates tickets for the _user based on _amountInWei; can only be called by router.
function batchExecuteTrade(
BatchTradeParams[] memory trades,
) external payable onlyRouter whenNotPaused
Generates tickets for multiple trades.
function executeRaffle(
address[] calldata _winners
) external onlyOperator
This function represents the final stage of the raffle process and is exclusively invoked by the Operator account. It performs two critical tasks:
Winner Assignment: It sets the addresses of the winning participants based on their associated ticket IDs.
Fund Release: Upon this assignment, the raffle funds are unlocked, enabling winners to claim their prizes.
function claim() external whenNotPaused
For raffle winners to claim their funds.
Last updated