Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add refund address in send #65

Merged
merged 1 commit into from
Oct 31, 2023
Merged
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
7 changes: 4 additions & 3 deletions src/ORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ contract ORMP is ReentrancyGuard, Channel {
/// @param toChainId The Message destination chain id.
/// @param to User application contract address which receive the message.
/// @param encoded The calldata which encoded by ABI Encoding.
/// @param refund Return extra fee to refund address.
/// @param params General extensibility for relayer to custom functionality.
function send(uint256 toChainId, address to, bytes calldata encoded, bytes calldata params)
function send(uint256 toChainId, address to, bytes calldata encoded, address refund, bytes calldata params)
external
payable
sendNonReentrant
Expand All @@ -58,8 +59,8 @@ contract ORMP is ReentrancyGuard, Channel {

//refund
if (msg.value > relayerFee + oracleFee) {
uint256 refund = msg.value - (relayerFee + oracleFee);
(bool success,) = ua.call{value: refund}("");
uint256 refundFee = msg.value - (relayerFee + oracleFee);
(bool success,) = refund.call{value: refundFee}("");
require(success, "!refund");
}

Expand Down
5 changes: 3 additions & 2 deletions src/interfaces/IORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ interface IORMP {
/// @param toChainId The Message destination chain id.
/// @param to User application contract address which receive the message.
/// @param encoded The calldata which encoded by ABI Encoding.
/// @param refund Return extra fee to refund address.
/// @param params General extensibility for relayer to custom functionality.
/// @return Return the hash of the message as message id.
function send(uint256 toChainId, address to, bytes calldata encoded, bytes calldata params)
function send(uint256 toChainId, address to, bytes calldata encoded, address refund, bytes calldata params)
external
payable
returns (bytes32);
Expand All @@ -37,7 +38,7 @@ interface IORMP {
// @param to User application contract address which receive the message.
jiguantong marked this conversation as resolved.
Show resolved Hide resolved
/// @param encoded The calldata which encoded by ABI Encoding.
/// @param params General extensibility for relayer to custom functionality.
function fee(uint256 toChainId, address, /*to*/ bytes calldata encoded, bytes calldata params)
function fee(uint256 toChainId, address to, bytes calldata encoded, bytes calldata params)
external
view
returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion test/ORMP.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract ORMPTest is Test, Verifier {

function perform_send() public {
uint256 f = ormp.fee(2, self, "", "");
ormp.send{value: f}(2, self, "", "");
ormp.send{value: f}(2, self, "", self, "");
proof = Proof({blockNumber: block.number, messageIndex: ormp.messageCount() - 1, messageProof: ormp.prove()});
vm.chainId(2);
}
Expand Down
2 changes: 1 addition & 1 deletion test/bench/ORMP.b.sol
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ contract ORMPBenchmarkTest is Test {
function perform_send(uint256 fromChainId, uint256 toChainId, bytes calldata encoded) public {
vm.createSelectFork(fromChainId.toChainName());
uint256 f = ormp.fee(toChainId, self, encoded, abi.encode(uint256(0)));
ormp.send{value: f}(toChainId, self, encoded, abi.encode(uint256(0)));
ormp.send{value: f}(toChainId, self, encoded, self, abi.encode(uint256(0)));
}
}
Loading