Skip to content

Commit

Permalink
only allow gateway as caller in GoFastCaller
Browse files Browse the repository at this point in the history
  • Loading branch information
thal0x committed Nov 6, 2024
1 parent f9ccbef commit f12611f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
3 changes: 2 additions & 1 deletion solidity/src/FastTransferGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {OrderEncoder} from "./libraries/OrderEncoder.sol";

import {IPermit2} from "./interfaces/IPermit2.sol";
import {IMailbox} from "./interfaces/hyperlane/IMailbox.sol";
import {GoFastCaller} from "./GoFastMulticall.sol";
import {GoFastCaller} from "./GoFastCaller.sol";

// Structure that contains the order details required to settle or refund an order

struct SettlementDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,28 @@ pragma solidity ^0.8.13;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";

contract GoFastCaller {
contract GoFastCaller is Ownable {
using SafeERC20 for IERC20;

address public gateway;

constructor(address _owner) Ownable(_owner) {}

function setGateway(address _gateway) external onlyOwner {
gateway = _gateway;
}

modifier onlyGateway() {
require(gateway != address(0), "GoFastCaller: gateway not set");
require(msg.sender == gateway, "GoFastCaller: sender not gateway");
_;
}

function execute(address _target, address _token, uint256 _amount, bytes memory _data)
external
onlyGateway
returns (bool, bytes memory)
{
IERC20(_token).forceApprove(_target, _amount);
Expand Down
6 changes: 4 additions & 2 deletions solidity/test/ERC7683.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {IPermit2} from "../src/interfaces/IPermit2.sol";
import {OnchainCrossChainOrder, GaslessCrossChainOrder} from "../src/erc7683/ERC7683.sol";
import {GoFastERC7683, OrderData} from "../src/GoFastERC7683.sol";
import {OrderEncoder} from "../src/libraries/OrderEncoder.sol";
import {GoFastCaller} from "../src/GoFastMulticall.sol";
import {GoFastCaller} from "../src/GoFastCaller.sol";

interface IUniswapV2Router02 {
function swapExactTokensForTokens(
Expand Down Expand Up @@ -56,7 +56,7 @@ contract ERC7683Test is Test {
solver = address(2);
mailbox = address(0x979Ca5202784112f4738403dBec5D0F3B9daabB9);

GoFastCaller goFastCaller = new GoFastCaller();
GoFastCaller goFastCaller = new GoFastCaller(address(this));

FastTransferGateway gatewayImpl = new FastTransferGateway();
ERC1967Proxy gatewayProxy = new ERC1967Proxy(
Expand All @@ -74,6 +74,8 @@ contract ERC7683Test is Test {
);
gateway = FastTransferGateway(address(gatewayProxy));

goFastCaller.setGateway(address(gateway));

GoFastERC7683 goFastERC7683Impl = new GoFastERC7683();
ERC1967Proxy goFastERC7683Proxy = new ERC1967Proxy(
address(goFastERC7683Impl),
Expand Down
6 changes: 4 additions & 2 deletions solidity/test/FastTransferGateway.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {TypeCasts} from "../src/libraries/TypeCasts.sol";
import {OrderEncoder} from "../src/libraries/OrderEncoder.sol";
import {IPermit2} from "../src/interfaces/IPermit2.sol";
import {IMailbox} from "../src/interfaces/hyperlane/IMailbox.sol";
import {GoFastCaller} from "../src/GoFastMulticall.sol";
import {GoFastCaller} from "../src/GoFastCaller.sol";

interface IUniswapV2Router02 {
function swapExactTokensForTokens(
Expand Down Expand Up @@ -55,7 +55,7 @@ contract FastTransferGatewayTest is Test {
solver = address(2);
mailbox = address(0x979Ca5202784112f4738403dBec5D0F3B9daabB9);

GoFastCaller _goFastCaller = new GoFastCaller();
GoFastCaller _goFastCaller = new GoFastCaller(address(this));
goFastCaller = address(_goFastCaller);
FastTransferGateway gatewayImpl = new FastTransferGateway();
ERC1967Proxy gatewayProxy = new ERC1967Proxy(
Expand All @@ -72,6 +72,8 @@ contract FastTransferGatewayTest is Test {
)
);
gateway = FastTransferGateway(address(gatewayProxy));

_goFastCaller.setGateway(address(gateway));
}

function test_submitAndSettle() public {
Expand Down

0 comments on commit f12611f

Please sign in to comment.