Skip to main content

Claimable

Git Source

Inherits: HookManager, IClaimable

Author: G9 Software Inc.

Provides an interface for Claimer contracts to interact with a vault in PoolTogether V5 while allowing each account to set and manage prize hooks that are called when they win.

State Variables

HOOK_GAS

The gas to give to each of the before and after prize claim hooks.

This should be enough gas to mint an NFT if needed.

uint24 public constant HOOK_GAS = 150_000;

HOOK_RETURN_DATA_LIMIT

The number of bytes to limit hook return / revert data.

If this limit is exceeded for beforeClaimPrize return data, the claim will revert.

Revert data for both hooks will also be limited to this size.

128 bytes is enough for beforeClaimPrize to return the _prizeRecipient address as well as 32 bytes of additional _hookData byte string data (32 for offset, 32 for length, 32 for data).

uint16 public constant HOOK_RETURN_DATA_LIMIT = 128;

prizePool

Address of the PrizePool that computes prizes.

PrizePool public immutable prizePool;

claimer

Address of the claimer.

address public claimer;

Functions

onlyClaimer

Requires the caller to be the claimer.

modifier onlyClaimer();

constructor

Claimable constructor

constructor(PrizePool prizePool_, address claimer_);

Parameters

NameTypeDescription
prizePool_PrizePoolThe prize pool to claim prizes from
claimer_addressThe address allowed to claim prizes on behalf of winners

claimPrize

Claim a prize for a winner

Also calls the before and after claim hooks if set by the winner.

Reverts if the return data size of the beforeClaimPrize hook exceeds HOOK_RETURN_DATA_LIMIT.

function claimPrize(address _winner, uint8 _tier, uint32 _prizeIndex, uint96 _reward, address _rewardRecipient)
external
onlyClaimer
returns (uint256);

Parameters

NameTypeDescription
_winneraddressThe winner of the prize
_tieruint8The prize tier
_prizeIndexuint32The prize index
_rewarduint96The reward to allocate to the reward recipient, in prize tokens
_rewardRecipientaddressThe recipient of the reward

Returns

NameTypeDescription
<none>uint256The total prize token amount claimed (zero if already claimed)

_setClaimer

Set claimer address.

Will revert if _claimer is address zero.

function _setClaimer(address _claimer) internal;

Parameters

NameTypeDescription
_claimeraddressAddress of the claimer

_safeHookCall

Uses ExcessivelySafeCall to limit the return data size to a safe limit.

This is used for both hook calls to prevent gas bombs that can be triggered using a large amount of return data or a large revert string.

In the case of an unsuccessful call, the revert reason will be bubbled up if it is within the safe data limit. Otherwise, a ReturnDataOverLimit reason will be thrown.

function _safeHookCall(IPrizeHooks _implementation, bytes memory _calldata)
internal
returns (bytes memory _returnData, uint256 _actualReturnDataSize);

Returns

NameTypeDescription
_returnDatabytesThe safe, size limited return data
_actualReturnDataSizeuint256The actual return data size of the original result

Errors

PrizePoolZeroAddress

Thrown when the Prize Pool is set to the zero address.

error PrizePoolZeroAddress();

ClaimerZeroAddress

Thrown when the Claimer is set to the zero address.

error ClaimerZeroAddress();

ClaimRecipientZeroAddress

Thrown when a prize is claimed for the zero address.

error ClaimRecipientZeroAddress();

CallerNotClaimer

Thrown when the caller is not the prize claimer.

error CallerNotClaimer(address caller, address claimer);

Parameters

NameTypeDescription
calleraddressThe caller address
claimeraddressThe claimer address

ReturnDataOverLimit

Thrown if relevant hook return data is greater than the HOOK_RETURN_DATA_LIMIT.

error ReturnDataOverLimit(uint256 returnDataSize, uint256 hookDataLimit);

Parameters

NameTypeDescription
returnDataSizeuint256The actual size of the return data
hookDataLimituint256The return data size limit for hooks