Rebalancer
Inherits: IRebalancer, HypernativeFirewallProtected
Title: Cross-chain rebalancer
Author: Malda Protocol
Manages bridge interactions and transfer size limits for cross-chain rebalancing.
State Variables
roles
Roles contract used for access control.
IRoles public roles
nonce
Incremental nonce used for logging messages.
uint256 public nonce
logs
Sent messages indexed by destination chain and nonce.
mapping(uint32 dstChainId => mapping(uint256 msgNonce => Msg message)) public logs
whitelistedBridges
Bridge whitelist status.
mapping(address bridge => bool status) public whitelistedBridges
allowedTokensPerBridge
Allowed tokens per bridge.
mapping(address bridge => mapping(address token => bool status)) public allowedTokensPerBridge
whitelistedDestinations
Destination chain whitelist status.
mapping(uint32 dstChainId => bool status) public whitelistedDestinations
allowedList
Markets allowed for rebalancing.
mapping(address market => bool status) public allowedList
admin
Admin address with elevated permissions.
address public admin
saveAddress
Address used to sweep saved assets.
address public saveAddress
maxTransferSizes
Per-chain token maximum transfer size.
mapping(uint32 dstChainId => mapping(address token => uint256 limit)) public maxTransferSizes
minTransferSizes
Per-chain token minimum transfer size.
mapping(uint32 dstChainId => mapping(address token => uint256 limit)) public minTransferSizes
currentTransferSize
Rolling transfer info for size-window enforcement.
mapping(uint32 dstChainId => mapping(address token => TransferInfo info)) public currentTransferSize
whitelistedMarkets
Market whitelist status.
mapping(address market => bool status) public whitelistedMarkets
transferTimeWindow
Duration of the rolling transfer size window.
uint256 public transferTimeWindow
Functions
constructor
Initializes the Rebalancer.
constructor(address _roles, address _saveAddress, address _admin, bytes memory initData) ;
Parameters
| Name | Type | Description |
|---|---|---|
_roles | address | Roles contract. |
_saveAddress | address | Address to sweep saved assets to. |
_admin | address | Admin address. |
initData | bytes | Optional initialization data (InitInfo ABI-encoded). |
initFirewall
Initialize firewall.
function initFirewall(address _firewall) external;
Parameters
| Name | Type | Description |
|---|---|---|
_firewall | address | Firewall address. |
setAdmin
Set admin.
function setAdmin(address _account) external;
Parameters
| Name | Type | Description |
|---|---|---|
_account | address | Admin address. |
setSaveAddress
Set save address.
function setSaveAddress(address _save) external;
Parameters
| Name | Type | Description |
|---|---|---|
_save | address | Save address. |
setAllowedTokens
Set allowed tokens for a bridge.
function setAllowedTokens(address bridge, address[] calldata tokens, bool status)
external
onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
bridge | address | Bridge address. |
tokens | address[] | Token list to allow/disallow. |
status | bool | Allowance status. |
setMarketStatus
Batch whitelist/unwhitelist markets.
function setMarketStatus(address[] calldata list, bool status) external onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
list | address[] | Market addresses. |
status | bool | Whitelist status. |
setAllowList
Batch set allow-list status for markets.
function setAllowList(address[] calldata list, bool status) external onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
list | address[] | Market addresses. |
status | bool | Allow list status. |
setWhitelistedBridgeStatus
Set whitelist status for a bridge.
function setWhitelistedBridgeStatus(address _bridge, bool _status) external onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
_bridge | address | Bridge address. |
_status | bool | Whitelist status. |
setWhitelistedDestination
Set whitelist status for a destination chain.
function setWhitelistedDestination(uint32 _dstId, bool _status) external onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
_dstId | uint32 | Destination chain id. |
_status | bool | Whitelist status. |
saveEth
Sweep native ETH to the configured save address.
function saveEth() external onlyFirewallApprovedAllowEOA;
saveTokens
Sweep stray tokens to the given market.
function saveTokens(address token, address market) external;
Parameters
| Name | Type | Description |
|---|---|---|
token | address | Token address to sweep. |
market | address | Market to receive tokens. |
setMinTransferSize
Sets the minimum transfer size for a given destination and token.
function setMinTransferSize(uint32 _dstChainId, address _token, uint256 _limit)
external
onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
_dstChainId | uint32 | Destination chain id. |
_token | address | Token address. |
_limit | uint256 | Minimum transfer size. |
setMaxTransferSize
Sets the maximum transfer size for a given destination and token.
function setMaxTransferSize(uint32 _dstChainId, address _token, uint256 _limit)
external
onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
_dstChainId | uint32 | Destination chain id. |
_token | address | Token address. |
_limit | uint256 | Maximum transfer size. |
sendMsg
Sends a bridge message.
function sendMsg(address _bridge, address _market, uint256 _amount, Msg calldata _msg)
external
payable
onlyFirewallApprovedAllowEOA;
Parameters
| Name | Type | Description |
|---|---|---|
_bridge | address | |
_market | address | The market to rebalance from address. |
_amount | uint256 | The amount to rebalance. |
_msg | Msg | The message data. |
isMarketWhitelisted
Returns if a market is whitelisted.
function isMarketWhitelisted(address market) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
market | address | Market address. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | whitelisted True if whitelisted. |
isBridgeWhitelisted
Returns if a bridge implementation is whitelisted.
function isBridgeWhitelisted(address bridge) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
bridge | address | Bridge address. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | whitelisted True if whitelisted. |
isDestinationWhitelisted
Returns if a destination is whitelisted.
function isDestinationWhitelisted(uint32 dstId) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
dstId | uint32 | Destination chain ID. |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | whitelisted True if whitelisted. |
firewallRegister
Registers an account with the firewall.
function firewallRegister(address _account) public override(HypernativeFirewallProtected);
Parameters
| Name | Type | Description |
|---|---|---|
_account | address | Account to register. |
_initFromData
Initializes the Rebalancer from initialization data.
function _initFromData(bytes memory initData) internal;
Parameters
| Name | Type | Description |
|---|---|---|
initData | bytes | Initialization data. |
_initMarkets
Initializes the markets.
function _initMarkets(address[] memory markets) internal;
Parameters
| Name | Type | Description |
|---|---|---|
markets | address[] | Markets to initialize. |
_initBridges
Initializes the bridges.
function _initBridges(address[] memory bridges) internal;
Parameters
| Name | Type | Description |
|---|---|---|
bridges | address[] | Bridges to initialize. |
_initDestinations
Initializes the destinations.
function _initDestinations(uint32[] memory destinations) internal;
Parameters
| Name | Type | Description |
|---|---|---|
destinations | uint32[] | Destinations to initialize. |
_initBridgeTokens
Initializes the bridge tokens.
function _initBridgeTokens(BridgeTokens[] memory bridgeTokens) internal;
Parameters
| Name | Type | Description |
|---|---|---|
bridgeTokens | BridgeTokens[] | Bridge tokens to initialize. |
_sendMsgPreChecks
Checks the pre-conditions for sending a message.
function _sendMsgPreChecks(address _bridge, address _market, uint256 _amount, Msg calldata _msg) internal;
Parameters
| Name | Type | Description |
|---|---|---|
_bridge | address | Bridge address. |
_market | address | Market address. |
_amount | uint256 | Amount to send. |
_msg | Msg | Message data. |
_updateTransferWindowAndCheckMax
Updates the transfer window and checks the maximum transfer size.
function _updateTransferWindowAndCheckMax(uint256 amount, uint32 dstChainId, address token) internal;
Parameters
| Name | Type | Description |
|---|---|---|
amount | uint256 | Amount to send. |
dstChainId | uint32 | Destination chain id. |
token | address | Token address. |
_setMarketStatus
Sets the market status.
function _setMarketStatus(address[] memory list, bool status) internal;
Parameters
| Name | Type | Description |
|---|---|---|
list | address[] | Market addresses. |
status | bool | Market status. |
_setAllowList
Sets the allow list.
function _setAllowList(address[] memory list, bool status) internal;
Parameters
| Name | Type | Description |
|---|---|---|
list | address[] | Market addresses. |
status | bool | Allow list status. |
_setWhitelistedBridgeStatus
Sets the whitelisted bridge status.
function _setWhitelistedBridgeStatus(address _bridge, bool _status) internal;
Parameters
| Name | Type | Description |
|---|---|---|
_bridge | address | Bridge address. |
_status | bool | Whitelisted bridge status. |
_setWhitelistedDestination
Sets the whitelisted destination.
function _setWhitelistedDestination(uint32 _dstId, bool _status) internal;
Parameters
| Name | Type | Description |
|---|---|---|
_dstId | uint32 | Destination chain id. |
_status | bool | Whitelisted destination status. |
_setAllowedTokens
Sets the allowed tokens.
function _setAllowedTokens(address bridge, address[] memory tokens, bool status) internal;
Parameters
| Name | Type | Description |
|---|---|---|
bridge | address | Bridge address. |
tokens | address[] | Token addresses. |
status | bool | Allowed tokens status. |
Structs
TransferInfo
struct TransferInfo {
uint256 size;
uint256 timestamp;
}
InitInfo
struct InitInfo {
BridgeTokens[] bridgeTokens;
address[] markets;
address[] bridges;
uint32[] destinations;
}
BridgeTokens
struct BridgeTokens {
address bridge;
address[] tokens;
}