VolumeRatePolicy
The VolumeRatePolicy enforces per-account volume limits within configurable time periods. It tracks cumulative transaction amounts for each account and rejects transactions that would push the account's total volume past the allowed maximum for the current period. When a new period begins, the counter resets automatically.
Configuration
Both values are set when the policy is first deployed and can be updated afterward by the policy owner.
Maximum amount per period
The maximum amount defines the cumulative volume an individual account is allowed to transact within a single time period. Each account is tracked independently โ one account reaching its limit does not affect others.
For example, setting the maximum to 10000 means each account can transact up to 10,000 units per period. If an account has already transacted 8,000 units in the current period, a new transaction of 3,000 units would be rejected because 8000 + 3000 > 10000.
Time period duration
The time period duration (in seconds) defines how long each tracking window lasts. The policy derives the current period from the block timestamp: block.timestamp / timePeriodDuration. When this value changes (a new period starts), each account's cumulative counter resets to zero.
Common values:
3600โ 1 hour86400โ 1 day604800โ 1 week
Runtime behavior
The policy expects exactly two parameters from the extractor:
| Parameter | Type | Description |
|---|---|---|
amount | uint256 | The transaction amount. |
account | address | The account whose cumulative volume is tracked. |
run()โ Derives the current period fromblock.timestamp / timePeriodDuration. If the account's cumulative volume for this period plus the new amount exceeds the maximum, reverts. ReturnsContinueotherwise.postRun()โ Updates the stored volume for the account. If this is a new period, resets the counter to the current amount. If the same period, adds the amount to the existing total.
API reference
Setter functions
setMaxAmount(uint256 maxAmount)โ Updates the maximum volume per period. Reverts if the new value is the same as the current one.setTimePeriodDuration(uint256 timePeriodDuration)โ Updates the time period length in seconds. Must be greater than zero. Reverts if the new value is the same as the current one.
View functions
getMaxAmount()โ Returns the current maximum volume per period.getTimePeriodDuration()โ Returns the current time period duration in seconds.
Use cases
- Rate limiting โ Cap transfer volume per account per hour or per day.
- Regulatory compliance โ Implement time-based transfer limits required by regulations.
- Resource protection โ Prevent single accounts from exhausting capacity within a time window.