Skip to content

Commit

Permalink
Re-add params in relayer (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujw77 authored Apr 25, 2024
1 parent d4d1ed1 commit c5879dd
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 20 deletions.
38 changes: 25 additions & 13 deletions src/ORMP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ contract ORMP is ReentrancyGuard, Channel {
using ExcessivelySafeCall for address;

event MessageAssigned(
bytes32 indexed msgHash, address indexed oracle, address indexed relayer, uint256 oracleFee, uint256 relayerFee
bytes32 indexed msgHash,
address indexed oracle,
address indexed relayer,
uint256 oracleFee,
uint256 relayerFee,
bytes params
);
event HashImported(address indexed oracle, uint256 chainId, address channel, uint256 msgIndex, bytes32 hash);

Expand All @@ -51,21 +56,22 @@ contract ORMP is ReentrancyGuard, Channel {
/// @param gasLimit Gas limit for destination user application used.
/// @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,
uint256 gasLimit,
bytes calldata encoded,
address refund,
bytes calldata
bytes calldata params
) external payable sendNonReentrant returns (bytes32) {
// user application address.
address ua = msg.sender;
// send message by channel, return the hash of the message as id.
bytes32 msgHash = _send(ua, toChainId, to, gasLimit, encoded);

// handle fee
_handleFee(ua, refund, msgHash, toChainId, gasLimit, encoded);
_handleFee(ua, refund, msgHash, toChainId, gasLimit, encoded, params);

return msgHash;
}
Expand All @@ -89,16 +95,17 @@ contract ORMP is ReentrancyGuard, Channel {
bytes32 msgHash,
uint256 toChainId,
uint256 gasLimit,
bytes calldata encoded
bytes calldata encoded,
bytes calldata params
) internal {
// fetch user application's config.
UC memory uc = getAppConfig(ua);
// handle relayer fee
uint256 relayerFee = _handleRelayer(uc.relayer, toChainId, ua, gasLimit, encoded);
uint256 relayerFee = _handleRelayer(uc.relayer, toChainId, ua, gasLimit, encoded, params);
// handle oracle fee
uint256 oracleFee = _handleOracle(uc.oracle, toChainId, ua);

emit MessageAssigned(msgHash, uc.oracle, uc.relayer, oracleFee, relayerFee);
emit MessageAssigned(msgHash, uc.oracle, uc.relayer, oracleFee, relayerFee, params);

// refund
if (msg.value > relayerFee + oracleFee) {
Expand All @@ -112,22 +119,27 @@ contract ORMP is ReentrancyGuard, Channel {
// @param ua User application contract address which send the message.
/// @param gasLimit Gas limit for destination user application used.
/// @param encoded The calldata which encoded by ABI Encoding.
function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded, bytes calldata)
/// @param params General extensibility for relayer to custom functionality.
function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded, bytes calldata params)
external
view
returns (uint256)
{
UC memory uc = getAppConfig(ua);
uint256 relayerFee = IRelayer(uc.relayer).fee(toChainId, ua, gasLimit, encoded);
uint256 relayerFee = IRelayer(uc.relayer).fee(toChainId, ua, gasLimit, encoded, params);
uint256 oracleFee = IOracle(uc.oracle).fee(toChainId, ua);
return relayerFee + oracleFee;
}

function _handleRelayer(address relayer, uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded)
internal
returns (uint256)
{
uint256 relayerFee = IRelayer(relayer).fee(toChainId, ua, gasLimit, encoded);
function _handleRelayer(
address relayer,
uint256 toChainId,
address ua,
uint256 gasLimit,
bytes calldata encoded,
bytes calldata params
) internal returns (uint256) {
uint256 relayerFee = IRelayer(relayer).fee(toChainId, ua, gasLimit, encoded, params);
_sendValue(relayer, relayerFee);
return relayerFee;
}
Expand Down
12 changes: 7 additions & 5 deletions src/eco/Relayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,13 @@ contract Relayer {
}

// extraGas = gasLimit
function fee(uint256 toChainId, address, /*ua*/ uint256 gasLimit, bytes calldata encoded)
public
view
returns (uint256)
{
function fee(
uint256 toChainId,
address, /*ua*/
uint256 gasLimit,
bytes calldata encoded,
bytes calldata /*params*/
) public view returns (uint256) {
uint256 size = encoded.length;
uint256 extraGas = gasLimit;
DstPrice memory p = priceOf[toChainId];
Expand Down
3 changes: 2 additions & 1 deletion src/interfaces/IRelayer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ interface IRelayer {
/// @param ua The user application which send the message.
/// @param gasLimit Gas limit for destination user application used.
/// @param encoded The calldata which encoded by ABI Encoding.
/// @param params General extensibility for relayer to custom functionality.
/// @return Relayer price in source native gas.
function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded)
function fee(uint256 toChainId, address ua, uint256 gasLimit, bytes calldata encoded, bytes calldata params)
external
view
returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion test/eco/Relayer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ contract RelayerTest is Test {
function test_setPrice() public {
relayer.setDstPrice(1, 10 ** 10, 1);
relayer.setDstConfig(1, 1, 1);
uint256 f = relayer.fee(1, self, 1, hex"00");
uint256 f = relayer.fee(1, self, 1, hex"00", "");
assertEq(f, 3);
}

Expand Down

0 comments on commit c5879dd

Please sign in to comment.