AccrossBridge

Git Source

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

NameTypeDescription
_rolesaddressAddress of the roles contract
_spokePooladdressAddress of the Across spoke pool
_rebalanceraddressAddress 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

NameTypeDescription
_dstIduint32The destination chain ID
_relayeraddressThe relayer address to update
statusboolWhether 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

NameTypeDescription
tokenSentaddressthe token address received
amountuint256the token amount
<none>address
messagebytesthe 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

NameTypeDescription
_extractedAmountuint256extracted amount for rebalancing
_marketaddressdestination address
_dstChainIduint32destination chain id
_tokenaddressthe token to rebalance
_messagebytesoperation 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

NameTypeDescription
dstChainuint32The destination chain ID
relayeraddressThe relayer address

Returns

NameTypeDescription
<none>boolisWhitelisted 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

NameTypeDescription
<none>uint32
<none>bytes
<none>bytes

Returns

NameTypeDescription
<none>uint256fee 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

NameTypeDescription
_messagebytesEncoded Across message
_tokenaddressToken being transferred
_dstChainIduint32Destination chain ID
_marketaddressMarket address encoded in the message

_decodeMessage

Decodes the Across message payload

function _decodeMessage(bytes calldata _message) private pure returns (DecodedMessage memory messageData);

Parameters

NameTypeDescription
_messagebytesEncoded message data

Returns

NameTypeDescription
messageDataDecodedMessageThe decoded message struct

Events

Rebalanced

Emitted when funds are rebalanced to a market

event Rebalanced(address indexed market, uint256 amount);

Parameters

NameTypeDescription
marketaddressThe market receiving funds
amountuint256The amount rebalanced

WhitelistedRelayerStatusUpdated

Emitted when relayer whitelist status is updated

event WhitelistedRelayerStatusUpdated(
    address indexed sender, uint32 indexed dstId, address indexed delegate, bool status
);

Parameters

NameTypeDescription
senderaddressThe caller updating whitelist
dstIduint32The destination chain ID
delegateaddressThe relayer address
statusboolThe 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;
}