🤑
Multiple Winners
The Multiple Winners prize strategy periodically selects a predefined number of winners and awards to them an equal share of the prizes available in the Prize Pool.

Initialization

A Multiple Winners prize strategy is initialized with:
Prize Period Start: the timestamp at which the prize period should start
Prize Period Seconds: the duration of time between prizes
PrizePool Address: the address of the prize pool that implements the pool functionality such as deposit and withdraw
​Ticket: The interface to use to select winners
​Sponsorship: The token that represents sponsorship
​Random Number Generator: used to generate random numbers for winner selection
Number of Winners: the number of winners in a prize period. This can be later changed by the owner calling set number of winners.

Strategy Settings

Set Number of Winners

The number of winners in a prize period can be set by calling:
1
function setNumberOfWinners(uint256 count)
2
external onlyOwner requireAwardNotInProgress
Copied!
  • Requires that the Award process is not in progress
  • count must be greater than 0

View Number of Winners

The number of winners setting can be viewed by calling:
1
function numberOfWinners() external view returns (uint256
Copied!

Set Split External ERC-20 Awards

The SplitExternalErc20Awards flag can be set by calling:
1
function setSplitExternalErc20Awards(bool _splitExternalErc20Awards)
2
external onlyOwner requireAwardNotInProgress
Copied!
This controls how externally added ERC-20's are distributed. Setting to true results in the ERC-20's paid out uniformly (similar to the main prize), while false does not pay out external ERC-20's for that award.

Set Random Number Generation Service

The Random Number Generation Service can be set when the award process has not started by the Prize Pool owner by calling:
1
function setRngService(RNGInterface rngService)
2
external onlyOwner requireAwardNotInProgress
Copied!

Set Random Number Generator Request Timeout

The RNG request timeout parameter can be set (in seconds) when the award process has not started by the Prize Pool owner by calling:
1
function setRngRequestTimeout(uint32 _rngRequestTimeout)
2
external onlyOwner requireAwardNotInProgress {
Copied!

Prize Period Information

View if the Prize Period is Over

To check if the prize period is finished call:
1
function isPrizePeriodOver() external view returns (bool)
Copied!
Returns true if the prize period is over, false otherwise.

View when the Prize Period Finishes

To check the unix time when the prize period ends call:
1
function prizePeriodEndAt() external view returns (uint256)
Copied!

View Estimate of Number of Blocks to Prize Block

To estimate the remaining blocks until the prize given a number of seconds per block call estimateRemainingBlocksToPrize with secondPerBlockMantissa set to 15 seconds for Ethereum mainnet:
1
function estimateRemainingBlocksToPrize(uint256 secondsPerBlockMantissa) public
2
view returns (uint256)
Copied!

View Prize Period Remaining Time (in seconds)

To get the number of seconds remaining until the prize can be awarded call:
1
function prizePeriodRemainingSeconds() external view returns (uint256)
Copied!

View Next Prize Period Start Time

To get the Unix timestamp of when the next prize period will start call calculateNextPrizePeriodStartTime with currentTime set to the current Unix time:
1
function calculateNextPrizePeriodStartTime(uint256 currentTime)
2
external view returns (uint256)
Copied!

Award Process

At the end of the prize period, anyone can begin the award process. This happens in two main stages - startAward and completeAward. startAward triggers the configured Random Number Generator request, which will take some blocks. completeAward can then be called, which selects the winners using the RNG result and pushes the tokens out to the winners.

Start Award

The award process can be started by calling startAward. This function starts the award process by starting the configured random number request. The prize period must have ended. The RNG-Request-Fee is expected to be held within this contract before calling this function.
1
function startAward() external requireCanStartAward
Copied!
Upon completion this function fires the following event:
1
event PrizePoolAwardStarted(
2
address indexed operator,
3
address indexed prizePool,
4
uint32 indexed rngRequestId,
5
uint32 rngLockBlock
6
);
Copied!

Complete Award

The award process can be finished by calling completeAward. The random number must have been requested and now available (is can be checked by calling isRngCompleted()).
1
function completeAward() external requireCanCompleteAward
Copied!
This function fires two events upon completion:
1
event PrizePoolAwarded(
2
address indexed operator,
3
uint256 randomNumber
4
);
Copied!
Since Prize Pools are continuously rolling the next prize period is now open:
1
event PrizePoolOpened(
2
address indexed operator,
3
uint256 indexed prizePeriodStartedAt
4
);
Copied!

Cancel Award

This function can be called by anyone to unlock the tickets if the RNG has timed out:
1
function cancelAward() public
Copied!
This function will fire the event:
1
event PrizePoolAwardCancelled(
2
address indexed operator,
3
address indexed prizePool,
4
uint32 indexed rngRequestId,
5
uint32 rngLockBlock
6
);
Copied!

Listeners

A prize strategy can have both a token listener and a periodic prize strategy listener in order execute code for certain callbacks (event hooks).

Set Token Listener

The token listener can be set by the prize pool owner when the award process is not in progress by calling setTokenListener with the address of the new tokenList :
1
function setTokenListener(TokenListenerInterface _tokenListener)
2
external onlyOwner requireAwardNotInProgress
Copied!

Set Periodic Prize Strategy Listener

The periodic prize strategy listener can be set by the prize pool owner when the award process is not in progress by calling setPeriodicPrizeStrategyListener with the address of the new PeriodicPrizeStrategyListener:
1
function setPeriodicPrizeStrategyListener(PeriodicPrizeStrategyListenerInterface _periodicPrizeStrategyListener)
2
external onlyOwner requireAwardNotInProgress
Copied!
This function will ensure the Listener Interface is implementing using ERC-165 introspection, and upon completion fire the following event:
1
event PeriodicPrizeStrategyListenerSet(
2
PeriodicPrizeStrategyListenerInterface indexed periodicPrizeStrategyListener
3
);
Copied!

External ERC20 and ERC721 Awards

External awards can be added to the pool. This is particularly useful in the case of the stake pool. Although still possible for either the token listener or the owner to manually add or remove ERC-20's and ERC-721's, it is recommended to add a single LootBox per prize period and direct the external awards to this LootBox address.
The pool owner or the token listener can add/remove ERC721's by calling:
1
function addExternalErc721Award(IERC721Upgradeable _externalErc721,
2
uint256[] calldata _tokenIds)
3
external onlyOwnerOrListener requireAwardNotInProgress
Copied!
1
function removeExternalErc721Award(
2
IERC721Upgradeable _externalErc721,
3
IERC721Upgradeable _prevExternalErc721)
4
external onlyOwner requireAwardNotInProgress
Copied!
The pool owner or the token listener can add/remove ERC20's by calling:
1
function addExternalErc20Awards(IERC20Upgradeable[] calldata _externalErc20s)
2
external onlyOwnerOrListener requireAwardNotInProgress
Copied!
1
function removeExternalErc20Award(
2
IERC20Upgradeable _externalErc20,
3
IERC20Upgradeable _prevExternalErc20)
4
external onlyOwner requireAwardNotInProgress
Copied!
Corresponding events are fired for each ERC type added or removed:
1
event ExternalErc721AwardAdded(
2
IERC721Upgradeable indexed externalErc721,
3
uint256[] tokenIds
4
);
5
​
6
event ExternalErc20AwardAdded(
7
IERC20Upgradeable indexed externalErc20
8
);
9
​
10
event ExternalErc721AwardRemoved(
11
IERC721Upgradeable indexed externalErc721Award
12
);
13
​
14
event ExternalErc20AwardRemoved(
15
IERC20Upgradeable indexed externalErc20Award
16
);
Copied!
Last modified 11mo ago