Rebalancer

Git Source

Inherits: IRebalancer, HypernativeFirewallProtected, ReentrancyGuard

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 chainId => mapping(uint256 nonce => Msg message)) public logs

whitelistedBridges

Bridge whitelist status

mapping(address bridge => bool whitelisted) public whitelistedBridges

allowedTokensPerBridge

Allowed tokens per bridge

mapping(address bridge => mapping(address token => bool allowed)) public allowedTokensPerBridge

whitelistedDestinations

Destination chain whitelist status

mapping(uint32 dstChainId => bool whitelisted) public whitelistedDestinations

allowedList

Markets allowed for rebalancing

mapping(address market => bool allowed) 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 maxSize)) public maxTransferSizes

minTransferSizes

Per-chain token minimum transfer size

mapping(uint32 dstChainId => mapping(address token => uint256 minSize)) public minTransferSizes

currentTransferSize

Rolling transfer info for size-window enforcement

mapping(uint32 dstChainId => mapping(address token => TransferInfo transferInfo)) public currentTransferSize

whitelistedMarkets

Market whitelist status

mapping(address market => bool whitelisted) 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) ;

Parameters

NameTypeDescription
_rolesaddressRoles contract
_saveAddressaddressAddress to sweep saved assets to
_adminaddressAdmin address

setAllowedTokens

Set allowed tokens for a bridge

function setAllowedTokens(address bridge, address[] calldata tokens, bool status) external onlyFirewallApproved;

Parameters

NameTypeDescription
bridgeaddressBridge address
tokensaddress[]Token list to allow/disallow
statusboolAllowance status

setMarketStatus

Batch whitelist/unwhitelist markets

function setMarketStatus(address[] calldata list, bool status) external onlyFirewallApproved;

Parameters

NameTypeDescription
listaddress[]Market addresses
statusboolWhitelist status

setAllowList

Batch set allow-list status for markets

function setAllowList(address[] calldata list, bool status) external onlyFirewallApproved;

Parameters

NameTypeDescription
listaddress[]Market addresses
statusboolAllow list status

setWhitelistedBridgeStatus

Set whitelist status for a bridge

function setWhitelistedBridgeStatus(address _bridge, bool status_) external onlyFirewallApproved;

Parameters

NameTypeDescription
_bridgeaddressBridge address
status_boolWhitelist status

setWhitelistedDestination

Set whitelist status for a destination chain

function setWhitelistedDestination(uint32 _dstId, bool status_) external onlyFirewallApproved;

Parameters

NameTypeDescription
_dstIduint32Destination chain id
status_boolWhitelist status

saveEth

Sweep native ETH to the configured save address

function saveEth() external onlyFirewallApproved;

saveTokens

Sweep stray tokens to the given market

function saveTokens(address token, address market) external;

Parameters

NameTypeDescription
tokenaddressToken address to sweep
marketaddressMarket to receive tokens

setMinTransferSize

Set minimum transfer size for a destination/token

function setMinTransferSize(uint32 _dstChainId, address _token, uint256 _limit) external onlyFirewallApproved;

Parameters

NameTypeDescription
_dstChainIduint32Destination chain id
_tokenaddressToken address
_limituint256Minimum size

setMaxTransferSize

Set maximum transfer size for a destination/token

function setMaxTransferSize(uint32 _dstChainId, address _token, uint256 _limit) external onlyFirewallApproved;

Parameters

NameTypeDescription
_dstChainIduint32Destination chain id
_tokenaddressToken address
_limituint256Maximum size

sendMsg

Sends a bridge message

function sendMsg(address _bridge, address _market, uint256 _amount, Msg calldata _msg)
    external
    payable
    onlyFirewallApproved
    nonReentrant;

Parameters

NameTypeDescription
_bridgeaddress
_marketaddressThe market to rebalance from address
_amountuint256The amount to rebalance
_msgMsgThe message data

isMarketWhitelisted

Returns if a market is whitelisted

function isMarketWhitelisted(address market) external view returns (bool);

Parameters

NameTypeDescription
marketaddressMarket address

Returns

NameTypeDescription
<none>boolwhitelisted True if whitelisted

isBridgeWhitelisted

Returns if a bridge implementation is whitelisted

function isBridgeWhitelisted(address bridge) external view returns (bool);

Parameters

NameTypeDescription
bridgeaddressBridge address

Returns

NameTypeDescription
<none>boolwhitelisted True if whitelisted

isDestinationWhitelisted

Returns if a destination is whitelisted

function isDestinationWhitelisted(uint32 dstId) external view returns (bool);

Parameters

NameTypeDescription
dstIduint32Destination chain ID

Returns

NameTypeDescription
<none>boolwhitelisted True if whitelisted

firewallRegister

Registers an account with the firewall

function firewallRegister(address _account) public override(HypernativeFirewallProtected);

Parameters

NameTypeDescription
_accountaddressAccount to register

Structs

TransferInfo

struct TransferInfo {
    uint256 size;
    uint256 timestamp;
}