Origin
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 domaincontent
length is greater thanMAX_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
Name | Type | Description |
---|---|---|
destination | uint32 | Domain of destination chain |
recipient | bytes32 | Address of recipient on destination chain as bytes32 |
optimisticPeriod | uint32 | Optimistic period for message execution on destination chain |
paddedRequest | uint256 | Padded encoded message execution request on destination chain |
content | bytes | Raw bytes content of message |
Returns
Name | Type | Description |
---|---|---|
messageNonce | uint32 | Nonce of the sent message |
messageHash | bytes32 | Hash 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
Name | Type | Description |
---|---|---|
destination | uint32 | Domain of destination chain |
optimisticPeriod | uint32 | Optimistic period for message execution on destination chain |
payload | bytes | Payload 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
Name | Type | Description |
---|---|---|
recipient | address | Address to withdraw tips to |
amount | uint256 | Tips 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
Name | Type | Description |
---|---|---|
destination | uint32 | Domain of destination chain |
paddedRequest | uint256 | Padded encoded message execution request on destination chain |
contentLength | uint256 | The length of the message content |
Returns
Name | Type | Description |
---|---|---|
tipsValue | uint256 | Minimum 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);