L2 Relayer
The Relayer contract acts as a middleman, receiving messages from the Broadcaster and relaying them to the according Agent (ownership, parameter, or emergency).
Relayer.vy
The source code for the Relayer.vy contract slightly differ depending on the chain its deployed to.
-
ArbitrumRelayer.vyfor Arbitrum -
OptimismRelayer.vyfor Optimism and Optimistic Rollups -
XYZRelayer.vyfor all other chains
A comprehensive list of all deployed contracts is available here .
The Relayer receives the broadcasted message and forwards the message to the appropriate agent. The Agents are then responsible for executing the calldata of the message.
Upgradability of Agents
A Relayer's agent addresses cannot be altered. Once chosen, there is no way back. In the case of any issues, a new Relayer contract has to be deployed.
Relaying Messages¶
The actual structure of the relay function may vary slightly depending on the chain-specific Relayer used. However, the general concept remains consistent:
A message is broadcast through the Broadcaster contract from Ethereum to the L2, where the Relayer relays the message and executes it via the corresponding Agent.
relay¶
Relayer.relay(_agent: Agent, _messages: DynArray[Message, MAX_MESSAGES]):
Function to receive a message from the Broadcaster and relay the message to the according agent. This function is automatically called by the MESSENGER contract of the according chain. There is no need to manually call this function, which would actually revert as it is a guarded function.
| Input | Type | Description |
|---|---|---|
_agent | address | Token to transfer |
_messages | address | Destination of the asset |
Source code
@external
def relay(_agent: Agent, _messages: DynArray[Message, MAX_MESSAGES]):
"""
@notice Receive messages for an agent and relay them.
@param _agent The agent to relay messages to.
@param _messages The sequence of messages to relay.
"""
assert IArbSys(ARBSYS).wasMyCallersAddressAliased()
assert IArbSys(ARBSYS).myCallersAddressWithoutAliasing() == self
IAgent(self.agent[_agent]).execute(_messages)
@external
def relay(_agent: Agent, _messages: DynArray[Message, MAX_MESSAGES]):
"""
@notice Receive messages for an agent and relay them.
@param _agent The agent to relay messages to.
@param _messages The sequence of messages to relay.
"""
assert msg.sender == MESSENGER
assert IMessenger(MESSENGER).xDomainMessageSender() == self
IAgent(self.agent[_agent]).execute(_messages)
@external
def relay(_agent: Agent, _messages: DynArray[Message, MAX_MESSAGES]):
"""
@notice Receive messages for an agent and relay them.
@param _agent The agent to relay messages to.
@param _messages The sequence of messages to relay.
"""
assert msg.sender == self.messenger
IAgent(self.agent[_agent]).execute(_messages)
Agents¶
The contract contains the addresses of the Agents that are responsible for executing the messages.
OWNERSHIP_AGENT¶
Relayer.OWNERSHIP_AGENT() -> address: view
Getter for the ownership agent.
Returns: ownership agent (address).
PARAMETER_AGENT¶
Relayer.PARAMETER_AGENT() -> address: view
Getter for the parameter agent.
Returns: parameter agent (address).
EMERGENCY_AGENT¶
Relayer.EMERGENCY_AGENT() -> address: view
Getter for the emergency agent.
Returns: emergency agent (address).