Skip to content

Instantly share code, notes, and snippets.

@m-bo-one
Created May 25, 2022 10:15
Show Gist options
  • Save m-bo-one/fa47c542d3273dc127c02eec1c7d1bf4 to your computer and use it in GitHub Desktop.
Save m-bo-one/fa47c542d3273dc127c02eec1c7d1bf4 to your computer and use it in GitHub Desktop.
multichain
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.10;
interface CallProxy{
function anyCall(
address _to,
bytes calldata _data,
address _fallback,
uint256 _toChainID,
uint256 _flags
) external payable;
function calcSrcFees(
string calldata _appID,
uint256 _toChainID,
uint256 _dataLength
) external view returns (uint256);
// function appIdentifier(address _addr) external view returns (string memory);
}
contract AnycallReceiverV6 {
event NewMsg(string msg);
function anyExecute(bytes calldata _data) external returns (bool success, bytes memory result) {
(string memory _msg) = abi.decode(_data, (string));
success = true;
result = '';
emit NewMsg(_msg);
}
}
contract AnycallSenderV6 {
address public immutable anycallContract;
bool public immutable isFeePayer;
event NewMsg(string msg);
constructor(address _anycallContract, bool _isFeePayer) {
anycallContract = _anycallContract;
isFeePayer = _isFeePayer;
}
function calcFees(uint256 _chainId, string calldata _msg) public view returns (uint256) {
return CallProxy(anycallContract).calcSrcFees(
"",
_chainId,
abi.encode(_msg).length
);
}
function anyMessage(address _receiver, uint256 _chainId, string calldata _msg) external payable {
require(msg.value >= calcFees(_chainId, _msg), "AnycallSenderV6: Wrong fees amount");
CallProxy(anycallContract).anyCall{value: msg.value}(
_receiver,
// sending the encoded bytes of the string msg and decode on the destination chain
abi.encode(_msg),
// 0x as fallback address because we don't have a fallback function
address(0),
// chainid of polygon
_chainId,
// Using 0 flag to pay fee on destination chain, on source 2
isFeePayer ? 2 : 0
);
emit NewMsg(_msg);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment