Skip to main content

ICCIPRateLimiter

Git Source

Title: ICCIPRateLimiter

The token bucket types, events and errors of the Chainlink CCIP RateLimiter library.

The struct layouts are identical to RateLimiter.TokenBucket and RateLimiter.Config of Chainlink CCIP 1.6.0, so functions declared with these types encode to the same ABI and the same selectors as the token pool functions that use the Chainlink types. Every amount is expressed in the smallest unit of the pool token.

Events​

TokensConsumed​

Emitted when tokens are consumed from an enabled bucket.

event TokensConsumed(uint256 tokens);

Parameters

NameTypeDescription
tokensuint256The number of tokens consumed.

ConfigChanged​

Emitted when a bucket configuration is written.

event ConfigChanged(Config config);

Parameters

NameTypeDescription
configConfigThe configuration written.

Errors​

BucketOverfilled​

Thrown when a bucket holds more tokens than its capacity.

error BucketOverfilled();

TokenMaxCapacityExceeded​

Thrown when a request exceeds the capacity of the bucket.

error TokenMaxCapacityExceeded(uint256 capacity, uint256 requested, address tokenAddress);

Parameters

NameTypeDescription
capacityuint256The capacity of the bucket.
requesteduint256The number of tokens requested.
tokenAddressaddressThe token of the bucket.

TokenRateLimitReached​

Thrown when a request exceeds the tokens currently in the bucket.

error TokenRateLimitReached(uint256 minWaitInSeconds, uint256 available, address tokenAddress);

Parameters

NameTypeDescription
minWaitInSecondsuint256The number of seconds until the bucket holds enough tokens.
availableuint256The number of tokens currently in the bucket.
tokenAddressaddressThe token of the bucket.

InvalidRateLimitRate​

Thrown when an enabled configuration has a zero rate or a rate that is not below its capacity.

error InvalidRateLimitRate(Config rateLimiterConfig);

Parameters

NameTypeDescription
rateLimiterConfigConfigThe rejected configuration.

DisabledNonZeroRateLimit​

Thrown when a disabled configuration has a non-zero capacity or rate.

error DisabledNonZeroRateLimit(Config config);

Parameters

NameTypeDescription
configConfigThe rejected configuration.

Structs​

TokenBucket​

The live state of a token bucket.

struct TokenBucket {
uint128 tokens;
uint32 lastUpdated;
bool isEnabled;
uint128 capacity;
uint128 rate;
}

Properties

NameTypeDescription
tokensuint128The current number of tokens in the bucket.
lastUpdateduint32The timestamp of the last refill, in seconds.
isEnabledboolWhether the rate limiting is enabled.
capacityuint128The maximum number of tokens that the bucket can hold.
rateuint128The number of tokens per second that the bucket is refilled with.

Config​

The configuration of a token bucket.

An enabled configuration requires 0 < rate < capacity. A disabled configuration requires capacity == 0 and rate == 0 and imposes no limit at all.

struct Config {
bool isEnabled;
uint128 capacity;
uint128 rate;
}

Properties

NameTypeDescription
isEnabledboolWhether the rate limiting is enabled.
capacityuint128The maximum number of tokens that the bucket can hold.
rateuint128The number of tokens per second that the bucket is refilled with.