# 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

```solidity
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

```solidity
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

```solidity
function executeTrade(
    uint256 _amountInWei,
    address _user
) external payable onlyRouter whenNotPaused
```

Generates tickets for the \_user based on \_amountInWei; can only be called by router.

***

```solidity
function batchExecuteTrade(
    BatchTradeParams[] memory trades,
) external payable onlyRouter whenNotPaused
```

Generates tickets for multiple trades.

***

```solidity
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.

{% hint style="info" %}
The need for Operator intervention arises because the raffle contract does not store ticket ownership information
{% endhint %}

***

```solidity
function claim() external whenNotPaused
```

For raffle winners to claim their funds.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://rpslabs.gitbook.io/docs/using-lotto-sdk/for-developers/smart-contracts/rps-raffle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
