-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} | ||
|