Skip to content

Commit

Permalink
refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
skosito committed Sep 12, 2024
1 parent b40d43a commit 27e58e7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion v2/contracts/evm/interfaces/IGatewayEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,4 @@ struct MessageContext {

interface Callable {
function onCall(address sender, bytes calldata message) external returns (bytes memory);
}
}
33 changes: 15 additions & 18 deletions v2/contracts/zevm/GatewayZEVM.sol
Original file line number Diff line number Diff line change
Expand Up @@ -255,15 +255,7 @@ contract GatewayZEVM is
nonReentrant
whenNotPaused
{
if (receiver.length == 0) revert ZeroAddress();
if (message.length == 0) revert EmptyMessage();

(address gasZRC20, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit(callOptions.gasLimit);
if (!IZRC20(gasZRC20).transferFrom(msg.sender, FUNGIBLE_MODULE_ADDRESS, gasFee)) {
revert GasFeeTransferFailed();
}

emit Called(msg.sender, zrc20, receiver, message, callOptions, revertOptions);
_call(receiver, zrc20, message, callOptions, revertOptions);
}

function call(
Expand All @@ -276,23 +268,28 @@ contract GatewayZEVM is
external
nonReentrant
whenNotPaused
{
_call(receiver, zrc20, message, CallOptions({ gasLimit: gasLimit, isArbitraryCall: true }), revertOptions);
}

function _call(
bytes memory receiver,
address zrc20,
bytes calldata message,
CallOptions memory callOptions,
RevertOptions memory revertOptions
)
internal
{
if (receiver.length == 0) revert ZeroAddress();
if (message.length == 0) revert EmptyMessage();

(address gasZRC20, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit(gasLimit);
(address gasZRC20, uint256 gasFee) = IZRC20(zrc20).withdrawGasFeeWithGasLimit(callOptions.gasLimit);
if (!IZRC20(gasZRC20).transferFrom(msg.sender, FUNGIBLE_MODULE_ADDRESS, gasFee)) {
revert GasFeeTransferFailed();
}

emit Called(
msg.sender,
zrc20,
receiver,
message,
CallOptions({ gasLimit: gasLimit, isArbitraryCall: true }),
revertOptions
);
emit Called(msg.sender, zrc20, receiver, message, callOptions, revertOptions);
}

/// @notice Deposit foreign coins into ZRC20.
Expand Down

0 comments on commit 27e58e7

Please sign in to comment.