From b464270aee692acf5468d9a1b2eb6a47049a5d7d Mon Sep 17 00:00:00 2001 From: Alexander Date: Wed, 5 Jun 2024 18:01:01 +0200 Subject: [PATCH] feat: submit message script --- script/SimpleApplication.sol | 50 ++++++++++++++++++++++++++++++++++++ script/SubmitMessage.s.sol | 45 ++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) create mode 100644 script/SimpleApplication.sol create mode 100644 script/SubmitMessage.s.sol diff --git a/script/SimpleApplication.sol b/script/SimpleApplication.sol new file mode 100644 index 0000000..b86bc43 --- /dev/null +++ b/script/SimpleApplication.sol @@ -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 {} +} diff --git a/script/SubmitMessage.s.sol b/script/SubmitMessage.s.sol new file mode 100644 index 0000000..8b1698b --- /dev/null +++ b/script/SubmitMessage.s.sol @@ -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)); + } +} +