Origin

Git Source

Inherits: StateHub, OriginEvents, InterfaceOrigin

Origin contract is used for sending messages to remote chains. It is done by inserting the message hashes into the Origin Merkle, which makes it possible to prove that message was sent using the Merkle proof against the Origin Merkle Root. This essentially compresses the list of messages into a single 32-byte value that needs to be stored on the destination chain. Origin is responsible for the following:

  • Formatting the sent message payloads, and inserting their hashes into the Origin Merkle Tree.
  • Keeping track of its own historical states (see parent contract StateHub).
  • Enforcing minimum tip values for sent base messages based on the provided execution requests.
  • Distributing the collected tips upon request from a local AgentManager contract.

State Variables

gasOracle

address public immutable gasOracle;

Functions

onlyRemoteDestination

modifier onlyRemoteDestination(uint32 destination);

constructor

constructor(uint32 synapseDomain_, address agentManager_, address inbox_, address gasOracle_)
    AgentSecured("0.0.3", synapseDomain_, agentManager_, inbox_);

initialize

Initializes Origin contract:

  • msg.sender is set as contract owner
  • State of "empty merkle tree" is saved
function initialize() external initializer;

sendBaseMessage

Send a message to the recipient located on destination domain.

*Recipient has to conform to IMessageRecipient interface, otherwise message won't be delivered. Will revert if any of these is true:

  • destination is equal to contract's local domain
  • content length is greater than MAX_CONTENT_BYTES
  • msg.value is lower than value of minimum tips for the given message*
function sendBaseMessage(
    uint32 destination,
    bytes32 recipient,
    uint32 optimisticPeriod,
    uint256 paddedRequest,
    bytes memory content
) external payable onlyRemoteDestination(destination) returns (uint32 messageNonce, bytes32 messageHash);

Parameters

NameTypeDescription
destinationuint32Domain of destination chain
recipientbytes32Address of recipient on destination chain as bytes32
optimisticPerioduint32Optimistic period for message execution on destination chain
paddedRequestuint256Padded encoded message execution request on destination chain
contentbytesRaw bytes content of message

Returns

NameTypeDescription
messageNonceuint32Nonce of the sent message
messageHashbytes32Hash of the sent message

sendManagerMessage

Send a manager message to the destination domain.

This could only be called by AgentManager, which takes care of encoding the calldata payload. Note: (msgOrigin, proofMaturity) security args will be added to payload on the destination chain so that the AgentManager could verify where the Manager Message came from and how mature is the proof. Note: function is not payable, as no tips are required for sending a manager message. Will revert if destination is equal to contract's local domain.

function sendManagerMessage(uint32 destination, uint32 optimisticPeriod, bytes memory payload)
    external
    onlyAgentManager
    onlyRemoteDestination(destination)
    returns (uint32 messageNonce, bytes32 messageHash);

Parameters

NameTypeDescription
destinationuint32Domain of destination chain
optimisticPerioduint32Optimistic period for message execution on destination chain
payloadbytesPayload for calling AgentManager on destination chain (with extra security args)

withdrawTips

Withdraws locked base message tips to the recipient.

Could only be called by a local AgentManager.

function withdrawTips(address recipient, uint256 amount) external onlyAgentManager;

Parameters

NameTypeDescription
recipientaddressAddress to withdraw tips to
amountuint256Tips value to withdraw

getMinimumTipsValue

Returns the minimum tips value for sending a message to a given destination.

Using at least tipsValue as msg.value for sendBaseMessage() will guarantee that the message will be accepted.

function getMinimumTipsValue(uint32 destination, uint256 paddedRequest, uint256 contentLength)
    external
    view
    returns (uint256 tipsValue);

Parameters

NameTypeDescription
destinationuint32Domain of destination chain
paddedRequestuint256Padded encoded message execution request on destination chain
contentLengthuint256The length of the message content

Returns

NameTypeDescription
tipsValueuint256Minimum tips value for a message to be accepted

_sendMessage

Sends the given message to the specified destination. Message hash is inserted into the Origin Merkle Tree, which will enable message execution on destination chain.

function _sendMessage(uint32 destination, uint32 optimisticPeriod, MessageFlag flag, bytes memory body)
    internal
    returns (uint32 messageNonce, bytes32 messageHash);

_getMinimumTips

Returns the minimum tips for sending a message to the given destination with the given request and content.

function _getMinimumTips(uint32 destination, uint256 paddedRequest, uint256 contentLength)
    internal
    view
    returns (Tips);

_fetchGasData

Gets the current gas data from the gas oracle to be saved as part of the Origin State.

function _fetchGasData() internal view override returns (GasData);