Skip to content

Commit

Permalink
feat: submit message script
Browse files Browse the repository at this point in the history
  • Loading branch information
reednaa committed Jun 5, 2024
1 parent fc4bcb3 commit b464270
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
50 changes: 50 additions & 0 deletions script/SimpleApplication.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import { ICrossChainReceiver } from "../src/interfaces/ICrossChainReceiver.sol";
import { IIncentivizedMessageEscrow } from "../src/interfaces/IIncentivizedMessageEscrow.sol";

/**
* @title Example application contract
*/
contract SimpleApplication is ICrossChainReceiver {

event Event(bytes message);

IIncentivizedMessageEscrow immutable MESSAGE_ESCROW;

constructor(address messageEscrow_) {
MESSAGE_ESCROW = IIncentivizedMessageEscrow(messageEscrow_);
}

function submitMessage(
bytes32 destinationIdentifier,
bytes calldata destinationAddress,
bytes calldata message,
IIncentivizedMessageEscrow.IncentiveDescription calldata incentive,
uint64 deadline
) external payable returns(uint256 gasRefund, bytes32 messageIdentifier) {
(gasRefund, messageIdentifier) = MESSAGE_ESCROW.submitMessage{value: msg.value}(
destinationIdentifier,
destinationAddress,
message,
incentive,
deadline
);
}

function setRemoteImplementation(bytes32 destinationIdentifier, bytes calldata implementation) external {
MESSAGE_ESCROW.setRemoteImplementation(destinationIdentifier, implementation);
}

function receiveAck(bytes32 /* destinationIdentifier */, bytes32 /* messageIdentifier */, bytes calldata acknowledgement) external {
emit Event(acknowledgement);
}

function receiveMessage(bytes32 /* sourceIdentifierbytes */, bytes32 /* messageIdentifier */, bytes calldata /* fromApplication */, bytes calldata message) external returns(bytes calldata acknowledgement) {
emit Event(message);
return message;
}

receive() external payable {}
}
45 changes: 45 additions & 0 deletions script/SubmitMessage.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";

import { BaseMultiChainDeployer} from "./BaseMultiChainDeployer.s.sol";

// Import all the Apps for deployment here.
import { IMessageEscrowStructs } from "../src/interfaces/IMessageEscrowStructs.sol";
import { IIncentivizedMessageEscrow } from "../src/interfaces/IIncentivizedMessageEscrow.sol";

import { SimpleApplication } from "./SimpleApplication.sol";

contract SubmitMessage is BaseMultiChainDeployer {
function submitMessage(address app, bytes32 destinationIdentifier, bytes memory destinationAddress, string memory message, address refundGasTo) external broadcast {
IMessageEscrowStructs.IncentiveDescription memory incentive = IMessageEscrowStructs.IncentiveDescription({
maxGasDelivery: 200000,
maxGasAck: 200000,
refundGasTo: refundGasTo,
priceOfDeliveryGas: 1 gwei,
priceOfAckGas: 1 gwei,
targetDelta: 0
});

uint256 incentiveValue = 200000 * 1 gwei * 2;

SimpleApplication(payable(app)).submitMessage{value: 2807712706467 + incentiveValue}(
destinationIdentifier,
destinationAddress,
abi.encodePacked(message),
incentive,
0
);
}

function setRemoteImplementation(address app, bytes32 destinationIdentifier, bytes calldata implementation) broadcast external {
SimpleApplication(payable(app)).setRemoteImplementation(destinationIdentifier, implementation);
}

function deploySimpleApplication(string[] memory chains, address escrow) iter_chains_string(chains) broadcast external returns(address app) {
app = address(new SimpleApplication{salt: bytes32(0)}(escrow));
}
}

0 comments on commit b464270

Please sign in to comment.