Skip to main content

PrizeDistributor

The PrizeDistributor contract holds Tickets (captured interest) and distributes tickets to users with winning draw claims. PrizeDistributor uses an external IDrawCalculator to validate a users draw claim, before awarding payouts. To prevent users from reclaiming prizes, a payout history for each draw claim is mapped to user accounts. Reclaiming a draw can occur if an "optimal" prize was not included in previous claim pick indices and the new claims updated payout is greater then the previous prize distributor claim payout.

Functions

constructor

  function constructor(
address _owner,
contract IERC20 _token,
contract IDrawCalculator _drawCalculator
) public

Initialize PrizeDistributor smart contract.

Parameters:

NameTypeDescription
_owneraddressOwner address
_tokencontract IERC20Token address
_drawCalculatorcontract IDrawCalculatorDrawCalculator address

claim

  function claim(
address user,
uint32[] drawIds,
bytes data
) external returns (uint256)

Claim prize payout(s) by submitting valud drawId(s) and winning pick indice(s). The user address is used as the "seed" phrase to generate random numbers.

The claim function is public and any wallet may execute claim on behalf of another user. Prizes are always paid out to the designated user account and not the caller (msg.sender). Claiming prizes is not limited to a single transaction. Reclaiming can be executed subsequentially if an "optimal" prize was not included in previous claim pick indices. The payout difference for the new claim is calculated during the award process and transfered to user.

Parameters:

NameTypeDescription
useraddressAddress of user to claim awards for. Does NOT need to be msg.sender
drawIdsuint32[]Draw IDs from global DrawBuffer reference
databytesThe data to pass to the draw calculator

Return Values:

TypeDescription
uint256Total claim payout. May include calcuations from multiple draws.

withdrawERC20

  function withdrawERC20(
contract IERC20 token,
address to,
uint256 amount
) external returns (bool)

Transfer ERC20 tokens out of contract to recipient address.

Only callable by contract owner.

Parameters:

NameTypeDescription
tokencontract IERC20ERC20 token to transfer.
toaddressRecipient of the tokens.
amountuint256Amount of tokens to transfer.

Return Values:

TypeDescription
booltrue if operation is successful.

getDrawCalculator

  function getDrawCalculator(
) external returns (contract IDrawCalculator)

Read global DrawCalculator address.

getDrawPayoutBalanceOf

  function getDrawPayoutBalanceOf(
address user,
uint32 drawId
) external returns (uint256)

Get the amount that a user has already been paid out for a draw

Parameters:

NameTypeDescription
useraddressUser address
drawIduint32Draw ID

getToken

  function getToken(
) external returns (contract IERC20)

Read global Ticket address.

setDrawCalculator

  function setDrawCalculator(
contract IDrawCalculator newCalculator
) external returns (contract IDrawCalculator)

Sets DrawCalculator reference contract.

Parameters:

NameTypeDescription
newCalculatorcontract IDrawCalculatorDrawCalculator address

Return Values:

TypeDescription
contract IDrawCalculatorNew DrawCalculator address

owner

  function owner(
) public returns (address)

Returns the address of the current owner.

pendingOwner

  function pendingOwner(
) external returns (address)

Gets current _pendingOwner.

Return Values:

TypeDescription
addressCurrent _pendingOwner address.

renounceOwnership

  function renounceOwnership(
) external

Renounce ownership of the contract.

Leaves the contract without owner. It will not be possible to call onlyOwner functions anymore. Can only be called by the current owner. NOTE: Renouncing ownership will leave the contract without an owner, thereby removing any functionality that is only available to the owner.

transferOwnership

  function transferOwnership(
address _newOwner
) external

Allows current owner to set the _pendingOwner address.

Parameters:

NameTypeDescription
_newOwneraddressAddress to transfer ownership to.

claimOwnership

  function claimOwnership(
) external

Allows the _pendingOwner address to finalize the transfer.

This function is only callable by the _pendingOwner.

Events

OwnershipOffered

  event OwnershipOffered(
address pendingOwner
)

Emitted when _pendingOwner has been changed.

Parameters:

NameTypeDescription
pendingOwneraddressnew _pendingOwner address.

OwnershipTransferred

  event OwnershipTransferred(
address previousOwner,
address newOwner
)

Emitted when _owner has been changed.

Parameters:

NameTypeDescription
previousOwneraddressprevious _owner address.
newOwneraddressnew _owner address.

ClaimedDraw

  event ClaimedDraw(
address user,
uint32 drawId,
uint256 payout
)

Emit when user has claimed token from the PrizeDistributor.

Parameters:

NameTypeDescription
useraddressUser address receiving draw claim payouts
drawIduint32Draw id that was paid out
payoutuint256Payout for draw

DrawCalculatorSet

  event DrawCalculatorSet(
contract IDrawCalculator calculator
)

Emit when DrawCalculator is set.

Parameters:

NameTypeDescription
calculatorcontract IDrawCalculatorDrawCalculator address

TokenSet

  event TokenSet(
contract IERC20 token
)

Emit when Token is set.

Parameters:

NameTypeDescription
tokencontract IERC20Token address

ERC20Withdrawn

  event ERC20Withdrawn(
contract IERC20 token,
address to,
uint256 amount
)

Emit when ERC20 tokens are withdrawn.

Parameters:

NameTypeDescription
tokencontract IERC20ERC20 token transferred.
toaddressAddress that received funds.
amountuint256Amount of tokens transferred.