Skip to main content

RateLimiter

You can use this control numeric limits over a period using timestamp.

RATE_LIMIT_SETTER_ROLE

bytes32 RATE_LIMIT_SETTER_ROLE

USED_RATE_LIMIT_RESETTER_ROLE

bytes32 USED_RATE_LIMIT_RESETTER_ROLE

periodInSeconds

uint256 periodInSeconds

limitInWei

uint256 limitInWei

currentPeriodEnd

uint256 currentPeriodEnd

The time at which the current period ends at.

Public for ease of consumption.

currentPeriodAmountInWei

uint256 currentPeriodAmountInWei

Amounts already withdrawn this period.

Public for ease of consumption.

__RateLimiter_init

function __RateLimiter_init(uint256 _periodInSeconds, uint256 _limitInWei) internal

Initialises the limits and period for the rate limiter.

Parameters

NameTypeDescription
_periodInSecondsuint256The length of the period in seconds.
_limitInWeiuint256The limit allowed in the period in Wei.

_addUsedAmount

function _addUsedAmount(uint256 _usedAmount) internal

Increments the amount used in the period.

_The amount determining logic is external to this (e.g. fees are included when calling here). Ignores the calculation if usedAmount is zero. Reverts if the limit is breached.

Parameters

NameTypeDescription
_usedAmountuint256The amount used to be added.

resetRateLimitAmount

function resetRateLimitAmount(uint256 _amount) external

Resets the rate limit amount.

If the used amount is higher, it is set to the limit to avoid confusion/issues. Only the RATE_LIMIT_SETTER_ROLE is allowed to execute this function. Emits the LimitAmountChanged event. usedLimitAmountToSet will use the default value of zero if period has expired.

Parameters

NameTypeDescription
_amountuint256The amount to reset the limit to.

resetAmountUsedInPeriod

function resetAmountUsedInPeriod() external

Resets the amount used to zero.

Only the USED_RATE_LIMIT_RESETTER_ROLE is allowed to execute this function. Emits the AmountUsedInPeriodReset event.