Flow Limit in Interchain Token Service
Overview
A FlowLimit
ensures the stability and security of interchain operations by setting constraints on the volume of tokens that can be transferred within a specified time frame. This prevents system abuse and overload, which is crucial in Interchain transfers, and can be used to prevent transfers of a token on a chain that is undergoing an emergency situation. Flow limits are managed by the FlowLimit
contract.
The FlowLimit
contract is used by the token manager contract. These token managers, use the FlowLimit
functionalities to set cross-chain transfer volume going in and out of a given blockchain.
This guide provides a comprehensive understanding of how the FlowLimit
contract operates within the context of Interchain token transfers.
Core Aspects
The following are core aspects of the FlowLimit
contract.
Flow Limit Management
- Uses a flow limit, or a ceiling on the net token flow (difference between flow in and out) within a defined
EPOCH_TIME
(currently set to 6 hours) to manage the number of tokens entering and leaving a blockchain - Ensures that the amount of tokens transferred in or out does not exceed the predefined limits within each epoch
- Role-based functions in the contract, such as
setFlowLimit
, allow authorized users to manage and adjust the flow limits, adapting to varying network conditions and requirements - Uses custom errors such as
FlowLimitExceeded
to handle cases where a transfer exceeds the permitted flow limit
Dynamic Slot Allocation
- Uses efficient low-level assembly for peak performance
- Dynamically calculates storage slots for flow amounts based on the current epoch, optimizing storage use
Public View Functions
The FlowLimit
contract contains the following public functions.
flowLimit()
Returns the current flow limit value.
flowOutAmount()
Returns the current total amount of tokens that have flowed out in the current epoch.
flowInAmount()
Returns the current total amount of tokens that have flowed in the current epoch.
Internal Management Functions
The FlowLimit
contract contains the following internal functions.
_setFlowLimit(uint256, bytes32)
Sets the flow limit for a specific token.
_addFlowOut(uint256)
Adds to the flow out amount, ensuring it does not exceed the flow limit.
_addFlowIn(uint256)
Adds to the flow in amount, also ensuring adherence to the flow limit.
Setting and Overriding Flow Limits in ITS
There are several options for setting and overriding flow limits in the Interchain Token Service.
Fully managed flow limits
If you want Axelar to manage the flow limits for the token and not deal with it yourself:
- Deploy the token with the
minter
address set toaddress(0)
Partially managed flow limits
If you want to manage the flow limits together with Axelar:
- Deploy the token with the
minter
address set to your Deployer account or a multi-sig wallet If you want to manage the flow limits alone: - Deploy the token with the
minter
address set to your Deployer account - Call
tokenManager.removeFlowLimiter(itsAddress)
to remove flow limit management by Axelar
Unmanaged flow limits
If you don’t want anyone to manage flow limits:
- Deploy the token with the
minter
address set to your Deployer account - Call
tokenManager.removeFlowLimiter(itsAddress)
to remove flow limit management by Axelar - Call
tokenManager.removeFlowLimiter(minter)
to remove flow limit management by the minter - Call
tokenManager.transferOperatorship(address(0))
to remove operatorship
The following is an example of how to set a flow limit using the setFlowLimits
method. You might want to increase the limit to the max before removing access granted to yourself.