Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions contracts/src/HyperlaneMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ pragma solidity ^0.8.9;
// Uncomment this line to use console.log
// import "hardhat/console.sol";

import "./IMailbox.sol";
import "./interfaces/IMailbox.sol";

contract HyperlaneMessageReceiver {
IMailbox inbox;
bytes32 public lastSender;
string public lastMessage;

event ReceivedMessage(uint32 origin, bytes32 sender, bytes message);


constructor(address _inbox) {
inbox = IMailbox(_inbox);
}
Expand All @@ -22,8 +22,8 @@ contract HyperlaneMessageReceiver {
bytes32 _sender,
bytes calldata _message
) external {
lastSender = _sender;
lastMessage = string(_message);
emit ReceivedMessage(_origin, _sender, _message);
lastSender = _sender;
lastMessage = string(_message);
emit ReceivedMessage(_origin, _sender, _message);
}
}
}
103 changes: 83 additions & 20 deletions contracts/src/HyperlaneMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,103 @@ pragma solidity ^0.8.9;
// Uncomment this line to use console.log
// import "hardhat/console.sol";

import "./IMailbox.sol";
import "./IInterchainGasPaymaster.sol";
import "./interfaces/IMailbox.sol";
import "./interfaces/IInterchainGasPaymaster.sol";

contract HyperlaneMessageSender {
IMailbox outbox;

IInterchainGasPaymaster igp;
event SentMessage(uint32 destinationDomain, bytes32 recipient, string message);

constructor(address _outbox,address _gasPayer) {
// Events
event SentMessage(
uint32 destinationDomain,
bytes32 recipient,
string message
);

// Errors
error InsufficientGas();
error DiffrentLengthArrays();

constructor(address _outbox, address _gasPayer) {
outbox = IMailbox(_outbox);
igp = IInterchainGasPaymaster(_gasPayer);
}

function getGasValue(uint32 _destinationDomain,
uint256 _gasAmount ) public view returns(uint256){
function getQuote(
uint32 _destinationDomain,
uint256 _gasAmount
) public view returns (uint256) {
return igp.quoteGasPayment(_destinationDomain, _gasAmount);
}



function sendString(
function getQuoteForMultipleChains(
uint32[] calldata _destinationDomain,
uint256[] calldata _gasAmount
) public view returns (uint256) {
if (_destinationDomain.length != _gasAmount.length) {
revert DiffrentLengthArrays();
}

uint256 total = 0;
for (uint256 i = 0; i < _destinationDomain.length; i++) {
total += igp.quoteGasPayment(_destinationDomain[i], _gasAmount[i]);
}
return total;
}

function dispatch(
uint32 _destinationDomain,
uint256 _gasAmount,
bytes32 _recipient,
string calldata _message,
uint256 _gasAmount
string calldata _message
) external payable {
bytes32 messageId = outbox.dispatch(_destinationDomain, _recipient, bytes(_message));
igp.payForGas{ value: msg.value }(
messageId, // The ID of the message that was just dispatched
_destinationDomain, // The destination domain of the message
_gasAmount, // 100k gas to use in the recipient's handle function
msg.sender // refunds go to msg.sender, who paid the msg.value
);
emit SentMessage(_destinationDomain, _recipient, _message);
bytes32 messageId = outbox.dispatch(
_destinationDomain,
_recipient,
bytes(_message)
);
igp.payForGas{value: msg.value}(
messageId, // The ID of the message that was just dispatched
_destinationDomain, // The destination domain of the message
_gasAmount, // 100k gas to use in the recipient's handle function
msg.sender // refunds go to msg.sender, who paid the msg.value
);
emit SentMessage(_destinationDomain, _recipient, _message);
}

function dispatchForMultipleChains(
uint32[] calldata _destinationDomain,
uint256[] calldata _gasAmount,
bytes32 _recipient,
string calldata _message
) external payable {
if (_destinationDomain.length != _gasAmount.length) {
revert DiffrentLengthArrays();
}

uint256 total = 0;
for (uint256 i = 0; i < _destinationDomain.length; i++) {
total += igp.quoteGasPayment(_destinationDomain[i], _gasAmount[i]);
}

if (total > msg.value) {
revert InsufficientGas();
}

for (uint256 i = 0; i < _destinationDomain.length; i++) {
bytes32 messageId = outbox.dispatch(
_destinationDomain[i],
_recipient,
bytes(_message)
);
igp.payForGas{value: _gasAmount[i]}(
messageId, // The ID of the message that was just dispatched
_destinationDomain[i], // The destination domain of the message
_gasAmount[i], // 100k gas to use in the recipient's handle function
msg.sender // refunds go to msg.sender, who paid the msg.value
);
emit SentMessage(_destinationDomain[i], _recipient, _message);
}
}
}
File renamed without changes.