Skip to content

Commit

Permalink
refactor(forwarders): remove call from ForwaderNativePermissioned
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Feb 22, 2024
1 parent a1584b8 commit 4513e63
Show file tree
Hide file tree
Showing 3 changed files with 564 additions and 53 deletions.
26 changes: 1 addition & 25 deletions contracts/forwarder/ForwarderNativePermissioned.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ error InvalidCallParams(address[] targets, bytes[] data, address caller);
error InvalidOriginAddress(address originAddress);
error InvalidCaller(address caller, address expected);

contract ForwarderNativePermissioned is IForwarder, IERC777Recipient, Context, Ownable {
contract ForwarderNativePermissioned is IERC777Recipient, Context, Ownable {
using SafeERC20 for IERC20;

address public immutable token;
Expand All @@ -37,14 +37,6 @@ contract ForwarderNativePermissioned is IForwarder, IERC777Recipient, Context, O
vault = _vault; // set it to 0 on an host chain
}

modifier onlySelf() {
address msgSender = _msgSender();
if (address(this) != msgSender) {
revert InvalidCaller(msgSender, address(this));
}
_;
}

function tokensReceived(
address /*_operator*/,
address _from,
Expand Down Expand Up @@ -83,22 +75,6 @@ contract ForwarderNativePermissioned is IForwarder, IERC777Recipient, Context, O
}
}

/// @inheritdoc IForwarder
function call(uint256 amount, address to, bytes calldata data, bytes4 chainId) external onlySelf() {
_call(token, amount, to, data, chainId);
}

function call(address _token, uint256 amount, address to, bytes calldata data, bytes4 chainId) external onlySelf() {
_call(_token, amount, to, data, chainId);
}

function _call(address _token, uint256 amount, address to, bytes calldata data, bytes4 chainId) internal {
bytes memory effectiveUserData = abi.encode(data, address(this));
uint256 effectiveAmount = amount == 0 ? 1 : amount;
IERC20(_token).safeApprove(vault, effectiveAmount);
IErc20Vault(vault).pegIn(effectiveAmount, _token, Helpers.addressToAsciiString(to), effectiveUserData, chainId);
}

function whitelistOriginAddress(address originAddress) external onlyOwner {
_whitelistedOriginAddresses[originAddress] = true;
}
Expand Down
Loading

0 comments on commit 4513e63

Please sign in to comment.