Files
linea-monorepo/contracts/docs/api/messageService/lib/RateLimiter.mdx
kyzooghost ea79b2d2be [Feat] Automate smart contract docgen and PR branch creation into Linea docs repo (#446)
* did poc for autogenerated *.mdx into docs.linea.build

* changed sparseMerkleProof

* first draft of contracts-docgen

* fix typos

* try different github token

* cleanup

* created create-docs-website-pr-branch

* cleanup for doc website repo scripts

* created first docs-repo pr using create-docs-website-pr-branch.sh

* improve comments

* added bash script segment to change filename to lowercase

* fix *.mdx headers to make more docusarus friendly

* update scripts for updated docs pr

* added comments to updateSidebar.js

* fix scripts after local test

* added installation checks

* Update contracts/docs/scripts/create-docs-website-pr-branch.sh

Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com>
Signed-off-by: kyzooghost <73516204+kyzooghost@users.noreply.github.com>

---------

Signed-off-by: kyzooghost <73516204+kyzooghost@users.noreply.github.com>
Co-authored-by: The Dark Jester <thedarkjester@users.noreply.github.com>
2024-12-20 20:45:36 +11:00

112 lines
2.2 KiB
Plaintext

# `RateLimiter`
You can use this control numeric limits over a period using timestamp.
### RATE_LIMIT_SETTER_ROLE
```solidity
bytes32 RATE_LIMIT_SETTER_ROLE
```
### USED_RATE_LIMIT_RESETTER_ROLE
```solidity
bytes32 USED_RATE_LIMIT_RESETTER_ROLE
```
### periodInSeconds
```solidity
uint256 periodInSeconds
```
### limitInWei
```solidity
uint256 limitInWei
```
### currentPeriodEnd
```solidity
uint256 currentPeriodEnd
```
The time at which the current period ends at.
_Public for ease of consumption._
### currentPeriodAmountInWei
```solidity
uint256 currentPeriodAmountInWei
```
Amounts already withdrawn this period.
_Public for ease of consumption._
### __RateLimiter_init
```solidity
function __RateLimiter_init(uint256 _periodInSeconds, uint256 _limitInWei) internal
```
Initialises the limits and period for the rate limiter.
#### Parameters
| Name | Type | Description |
| ---- | ---- | ----------- |
| _periodInSeconds | uint256 | The length of the period in seconds. |
| _limitInWei | uint256 | The limit allowed in the period in Wei. |
### _addUsedAmount
```solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| _usedAmount | uint256 | The amount used to be added. |
### resetRateLimitAmount
```solidity
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
| Name | Type | Description |
| ---- | ---- | ----------- |
| _amount | uint256 | The amount to reset the limit to. |
### resetAmountUsedInPeriod
```solidity
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._