Skip to main content

Claimer

Git Source

Author: G9 Software Inc.

This contract uses a variable rate gradual dutch auction to incentivize prize claims on behalf of others. Fees for each canary tier is set to the respective tier's prize size.

State Variables

prizePool

The Prize Pool that this Claimer is claiming prizes for

PrizePool public immutable prizePool;

maxFeePortionOfPrize

The maximum fee that can be charged as a portion of the prize size. Fixed point 18 number

UD2x18 public immutable maxFeePortionOfPrize;

timeToReachMaxFee

The time in seconds to reach the max auction fee

uint256 public immutable timeToReachMaxFee;

Functions

constructor

Constructs a new Claimer

constructor(PrizePool _prizePool, uint256 _timeToReachMaxFee, UD2x18 _maxFeePortionOfPrize);

Parameters

NameTypeDescription
_prizePoolPrizePoolThe prize pool to claim for
_timeToReachMaxFeeuint256The time it should take to reach the maximum fee
_maxFeePortionOfPrizeUD2x18The maximum fee that can be charged as a portion of the prize size. Fixed point 18 number

claimPrizes

Allows the caller to claim prizes on behalf of others or for themself.

If you are claiming for yourself or don't want to take a fee, set the _feeRecipient and _minFeePerClaim to zero. This will save some gas on fee calculation.

function claimPrizes(
IClaimable _vault,
uint8 _tier,
address[] calldata _winners,
uint32[][] calldata _prizeIndices,
address _feeRecipient,
uint256 _minFeePerClaim
) external returns (uint256 totalFees);

Parameters

NameTypeDescription
_vaultIClaimableThe vault to claim from
_tieruint8The tier to claim for
_winnersaddress[]The array of winners to claim for
_prizeIndicesuint32[][]The array of prize indices to claim for each winner (length should match winners)
_feeRecipientaddressThe address to receive the claim fees
_minFeePerClaimuint256The minimum fee for each claim

Returns

NameTypeDescription
totalFeesuint256The total fees collected across all successful claims

_countClaims

If the claimer hasn't specified both a min fee and a fee recipient, we assume that they don't expect a fee and save them some gas on the calculation.

Computes the number of claims that will be made

function _countClaims(address[] calldata _winners, uint32[][] calldata _prizeIndices) internal pure returns (uint256);

Parameters

NameTypeDescription
_winnersaddress[]The array of winners to claim for
_prizeIndicesuint32[][]The array of prize indices to claim for each winner (length should match winners)

Returns

NameTypeDescription
<none>uint256The number of claims

_claim

Claims prizes for a batch of winners and prize indices

function _claim(
IClaimable _vault,
uint8 _tier,
address[] calldata _winners,
uint32[][] calldata _prizeIndices,
address _feeRecipient,
uint96 _feePerClaim
) internal returns (uint256);

Parameters

NameTypeDescription
_vaultIClaimableThe vault to claim from
_tieruint8The tier to claim for
_winnersaddress[]The array of winners to claim for
_prizeIndicesuint32[][]The array of prize indices to claim for each winner (length should match winners)
_feeRecipientaddressThe address to receive the claim fees
_feePerClaimuint96The fee to charge for each claim

Returns

NameTypeDescription
<none>uint256The number of claims that were successful

computeTotalFees

Computes the total fees for the given number of claims.

function computeTotalFees(uint8 _tier, uint256 _claimCount) external view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier to claim prizes from
_claimCountuint256The number of claims

Returns

NameTypeDescription
<none>uint256The total fees for those claims

computeTotalFees

Computes the total fees for the given number of claims if a number of claims have already been made.

function computeTotalFees(uint8 _tier, uint256 _claimCount, uint256 _claimedCount) public view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier to claim prizes from
_claimCountuint256The number of claims
_claimedCountuint256The number of prizes already claimed

Returns

NameTypeDescription
<none>uint256The total fees for those claims

computeFeePerClaim

Computes the fee per claim for the given tier and number of claims

function computeFeePerClaim(uint8 _tier, uint256 _claimCount) external view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier to claim prizes from
_claimCountuint256The number of claims

Returns

NameTypeDescription
<none>uint256The fee that will be taken per claim

_computeFeePerClaim

Computes the total fees for the given number of claims.

function _computeFeePerClaim(uint8 _tier, uint256 _claimCount, uint256 _claimedCount) internal view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier
_claimCountuint256The number of claims to check
_claimedCountuint256The number of prizes already claimed

Returns

NameTypeDescription
<none>uint256The total fees for the claims

computeMaxFee

Computes the maximum fee that can be charged.

function computeMaxFee(uint8 _tier) public view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier to compute the max fee for

Returns

NameTypeDescription
<none>uint256The maximum fee that can be charged

_computeFeeTarget

Compute the target fee for prize claims

function _computeFeeTarget(uint8 _numberOfTiers) internal view returns (uint256);

Parameters

NameTypeDescription
_numberOfTiersuint8The current number of tiers for the prize pool

Returns

NameTypeDescription
<none>uint256The target fee for prize claims

_computeDecayConstant

Computes the decay constant for the VRGDA.

This is a decay constant that ensures the fee will grow from the target to the max fee within the time frame

function _computeDecayConstant(uint256 _targetFee, uint8 _numberOfTiers) internal view returns (SD59x18);

Parameters

NameTypeDescription
_targetFeeuint256The target fee
_numberOfTiersuint8The current number of tiers for the prize pool

Returns

NameTypeDescription
<none>SD59x18The decay constant

_computeMaxFee

Computes the max fee given the tier

function _computeMaxFee(uint8 _tier) internal view returns (uint256);

Parameters

NameTypeDescription
_tieruint8The tier to compute the max fee for

Returns

NameTypeDescription
<none>uint256The maximum fee that will be charged for a prize claim for the given tier

_computeFeeForNextClaim

Computes the fee for the next claim.

function _computeFeeForNextClaim(
uint256 _targetFee,
SD59x18 _decayConstant,
SD59x18 _perTimeUnit,
uint256 _elapsed,
uint256 _sold,
uint256 _maxFee
) internal pure returns (uint256);

Parameters

NameTypeDescription
_targetFeeuint256The target fee that should be charged
_decayConstantSD59x18The VRGDA decay constant
_perTimeUnitSD59x18The num to be claimed per second
_elapseduint256The number of seconds that have elapsed
_solduint256The number of prizes that were claimed
_maxFeeuint256The maximum fee that can be charged

Returns

NameTypeDescription
<none>uint256The fee to charge for the next claim

Events

ClaimError

Emitted when a claim reverts

event ClaimError(IClaimable indexed vault, uint8 indexed tier, address indexed winner, uint32 prizeIndex, bytes reason);

Parameters

NameTypeDescription
vaultIClaimableThe vault for which the claim failed
tieruint8The tier for which the claim failed
winneraddressThe winner for which the claim failed
prizeIndexuint32The prize index for which the claim failed
reasonbytesThe revert reason