AccrossBridge
Inherits: BaseBridge, IBridge, IAcrossReceiverV3, ReentrancyGuard
Title: AcrossBridge
Author: Merge Layers Inc.
Bridge integration for Across V3 used by the rebalancer
State Variables
SLIPPAGE_PRECISION
Precision used for slippage calculations
uint256 private constant SLIPPAGE_PRECISION = 1e5
ACROSS_SPOKE_POOL
Across spoke pool address
address public immutable ACROSS_SPOKE_POOL
MAX_SLIPPAGE
Maximum allowed slippage in basis points
uint256 public immutable MAX_SLIPPAGE
REBALANCER
Rebalancer contract address
address public immutable REBALANCER
whitelistedRelayers
Whitelisted relayers per destination chain
mapping(uint32 dstChainId => mapping(address relayer => bool isWhitelisted)) public whitelistedRelayers
Functions
onlySpokePool
Modifier to restrict access to only the spoke pool
modifier onlySpokePool() ;
constructor
Initializes the Across bridge
constructor(address _roles, address _spokePool, address _rebalancer) BaseBridge(_roles);
Parameters
| Name | Type | Description |
|---|---|---|
_roles | address | Address of the roles contract |
_spokePool | address | Address of the Across spoke pool |
_rebalancer | address | Address of the rebalancer contract |
setWhitelistedRelayer
Whitelists or removes a relayer for a destination chain
function setWhitelistedRelayer(uint32 _dstId, address _relayer, bool status) external onlyBridgeConfigurator;
Parameters
| Name | Type | Description |
|---|---|---|
_dstId | uint32 | The destination chain ID |
_relayer | address | The relayer address to update |
status | bool | Whether the relayer is whitelisted |
handleV3AcrossMessage
handles AcrossV3 SpokePool message
function handleV3AcrossMessage(
address tokenSent,
uint256 amount,
address, /* relayer is unused */
bytes calldata message
)
external
onlySpokePool
nonReentrant;
Parameters
| Name | Type | Description |
|---|---|---|
tokenSent | address | the token address received |
amount | uint256 | the token amount |
<none> | address | |
message | bytes | the custom message sent from source |
sendMsg
rebalance through bridge
function sendMsg(
uint256 _extractedAmount,
address _market,
uint32 _dstChainId,
address _token,
bytes calldata _message,
bytes calldata /* _bridgeData */
) external payable onlyRebalancer;
Parameters
| Name | Type | Description |
|---|---|---|
_extractedAmount | uint256 | extracted amount for rebalancing |
_market | address | destination address |
_dstChainId | uint32 | destination chain id |
_token | address | the token to rebalance |
_message | bytes | operation message data |
<none> | bytes |
isRelayerWhitelisted
Returns whether an address is whitelisted as relayer for a destination chain
function isRelayerWhitelisted(uint32 dstChain, address relayer) external view returns (bool);
Parameters
| Name | Type | Description |
|---|---|---|
dstChain | uint32 | The destination chain ID |
relayer | address | The relayer address |
Returns
| Name | Type | Description |
|---|---|---|
<none> | bool | isWhitelisted True if relayer is whitelisted |
getFee
computes fee for bridge operation
function getFee(
uint32,
/* _dstChainId */
bytes calldata,
/* _message */
bytes calldata /* _bridgeData */
)
external
pure
returns (uint256);
Parameters
| Name | Type | Description |
|---|---|---|
<none> | uint32 | |
<none> | bytes | |
<none> | bytes |
Returns
| Name | Type | Description |
|---|---|---|
<none> | uint256 | fee Computed bridge fee |
_depositV3Now
Deposits funds into Across spoke pool for immediate relay
function _depositV3Now(bytes calldata _message, address _token, uint32 _dstChainId, address _market) private;
Parameters
| Name | Type | Description |
|---|---|---|
_message | bytes | Encoded Across message |
_token | address | Token being transferred |
_dstChainId | uint32 | Destination chain ID |
_market | address | Market address encoded in the message |
_decodeMessage
Decodes the Across message payload
function _decodeMessage(bytes calldata _message) private pure returns (DecodedMessage memory messageData);
Parameters
| Name | Type | Description |
|---|---|---|
_message | bytes | Encoded message data |
Returns
| Name | Type | Description |
|---|---|---|
messageData | DecodedMessage | The decoded message struct |
Events
Rebalanced
Emitted when funds are rebalanced to a market
event Rebalanced(address indexed market, uint256 amount);
Parameters
| Name | Type | Description |
|---|---|---|
market | address | The market receiving funds |
amount | uint256 | The amount rebalanced |
WhitelistedRelayerStatusUpdated
Emitted when relayer whitelist status is updated
event WhitelistedRelayerStatusUpdated(
address indexed sender, uint32 indexed dstId, address indexed delegate, bool status
);
Parameters
| Name | Type | Description |
|---|---|---|
sender | address | The caller updating whitelist |
dstId | uint32 | The destination chain ID |
delegate | address | The relayer address |
status | bool | The whitelist status |
Errors
AcrossBridge_TokenMismatch
Error thrown when tokens do not match expected underlying
error AcrossBridge_TokenMismatch();
AcrossBridge_NotAuthorized
Error thrown when caller is not authorized
error AcrossBridge_NotAuthorized();
AcrossBridge_NotImplemented
Error thrown when feature is not implemented
error AcrossBridge_NotImplemented();
AcrossBridge_AddressNotValid
Error thrown when an address is not valid
error AcrossBridge_AddressNotValid();
AcrossBridge_SlippageNotValid
Error thrown when slippage exceeds maximum
error AcrossBridge_SlippageNotValid();
AcrossBridge_RelayerNotValid
Error thrown when relayer is not valid
error AcrossBridge_RelayerNotValid();
AcrossBridge_InvalidReceiver
Error thrown when receiver market is invalid
error AcrossBridge_InvalidReceiver();
AcrossBridge_MaxFeeExceeded
Error thrown when relayer fee exceeds maximum
error AcrossBridge_MaxFeeExceeded();
Structs
DecodedMessage
Decoded Across message payload
struct DecodedMessage {
address outputToken;
uint256 inputAmount;
uint256 outputAmount;
address relayer;
uint32 deadline;
uint32 exclusivityDeadline;
}