Gemstone Raffles
Raffles are the primary mechanism for NFT Distribution, and can also have cash prizes.
Ruby.Exchange uses raffles to distribute gemstone NFTs at random to users who participate.
NFTs are allocated at random via a simple raffle process controlled by a smart contract. Each raffle runs for a specified period of time, with a set number of tickets, and a set ticket price. A raffle has at most one NFT as its prize, and so the number of tickets issued effectively determines the odds of winning.
The smart contract uses the BLS signature included in every SKALE block as a random number generator. Because this is a threshold signature, it represents a trustworthy and decentralized source of randomness that cannot be front-run by an attacker, whether a user or a rogue network validator.
The raffle framework is designed to be flexible, allowing cash prizes (RUBY, USDC, etc) to be paid out to winners, as well as an NFT prize. Where multiple NFTs of the same type and value are to be distributed (for example, a series of 10 gemstones that reduce trading fees), the required number of raffles is simply held consecutively, with the next one starting when the previous one has been won.

Raffle Mechanics

Each raffle is initialized with a configurable number of tickets. Users can buy one or more tickets. Ticket numbers are randomly generated, or selected manually by the user from available remaining tickets, rather than being issued sequentially by the contract.
At the end of the raffle, a specified number of tickets are drawn in order (first, second, third place, etc).
If a user holds a ticket with the same number as one drawn for a prize, they win the prize allocated to that place. If a winning ticket number has not been bought by any user, the ticket is not redrawn and the prize for that place instead goes to the treasury.
There are two types of prize for every raffle:
  • A percentage of the "pot", or the total value of all tickets purchased for the raffle.
  • An NFT (optional).
First place wins a percentage of the pot and the NFT, while the remaining places win only percentages of the pot.
Because a percentage of the entry fees for each raffle can be burned, gem distribution can be net deflationary for the platform, and is never inflationary.

Raffle Configuration

The following variables can be configured for each raffle:
  • The currency used to purchase tickets. The default currency is RUBY.
  • The price of each ticket in the purchase currency.
  • The address and id of the NFT to award for first prize. This can be disabled (i.e. there is no NFT prize) by setting it to zero.
  • The percentage of the pot that will go to each prize place (maximum ten prizes).
  • The percentage of the pot to be burned.
  • The percentage of the pot that will go to the treasury, or another specified address. This address also receives any prizes for which a ticket has not been purchased.
  • The total number of tickets to be generated.
  • The duration of the raffle in seconds. The raffle will end after this time, regardless of whether all tickets have been sold.

Example Raffle

A raffle is initialized with:
  • 1,000 tickets
  • Tickets are priced in RUBY tokens
  • The purchase price for a ticket is 1 [RUBY]
  • A gemstone NFT is specified for the prize
  • Four prizes are specified for first, second, third, and fourth places: 35%, 25%, 15%, and 10% of the pot respectively (total 85%)
  • 5% of the pot is to be burned
  • 10% of the pot goes to the treasury address
  • The raffle will last for 24 hours
The raffle begins and users purchase 780 tickets for a total of 780 RUBY. The raffle ends after 24 hours with the remaining tickets sold.
Four ticket numbers are drawn: 201, 438, 778, and 955.
  • Ticket 201 has been purchased and the holder receives the first prize of 35% of the pot, or 273 RUBY, and the NFT prize.
  • No one has purchased ticket 438, so the second prize (25% of the pot or 195 RUBY) goes to the treasury address.
  • Ticket 778 has been purchased and the holder receives the third prize of 15% of the pot, or 117 RUBY.
  • Ticket 955 has been purchased and the holder receives the fourth prize of 10% of the pot, or 78 RUBY.
  • 5% of the pot, or 39 RUBY, is burned.
  • 10% of the pot, or 78 RUBY, is sent to the treasury address, in addition to the 195 RUBY from second prize.
Any prize (including NFTs) can be claimed by the winner indefinitely. There is no deadline.