// SPDX-License-Identifier: Apache-2.0 pragma solidity >=0.8.0; import {TokenRouter} from "./libs/TokenRouter.sol"; import {TokenMessage} from "./libs/TokenMessage.sol"; import {MailboxClient} from "../client/MailboxClient.sol"; import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; /** * @title Hyperlane ERC20 Token Collateral that wraps an existing ERC20 with remote transfer functionality. * @author Abacus Works */ contract HypERC20Collateral is TokenRouter { using SafeERC20 for IERC20; IERC20 public immutable wrappedToken; /** * @notice Constructor * @param erc20 Address of the token to keep as collateral */ constructor(address erc20, address _mailbox) TokenRouter(_mailbox) { wrappedToken = IERC20(erc20); } function balanceOf(address _account) external view override returns (uint256) { return wrappedToken.balanceOf(_account); } /** * @dev Transfers `_amount` of `wrappedToken` from `msg.sender` to this contract. * @inheritdoc TokenRouter */ function _transferFromSender(uint256 _amount) internal override returns (bytes memory) { wrappedToken.safeTransferFrom(msg.sender, address(this), _amount); return bytes(""); // no metadata } /** * @dev Transfers `_amount` of `wrappedToken` from this contract to `_recipient`. * @inheritdoc TokenRouter */ function _transferTo( address _recipient, uint256 _amount, bytes calldata // no metadata ) internal virtual override { wrappedToken.safeTransfer(_recipient, _amount); } }