draft-ERC20Bridgeable.sol 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: MIT
  2. pragma solidity ^0.8.20;
  3. import {ERC20} from "../ERC20.sol";
  4. import {ERC165, IERC165} from "../../../utils/introspection/ERC165.sol";
  5. import {IERC7802} from "../../../interfaces/draft-IERC7802.sol";
  6. /**
  7. * @dev ERC20 extension that implements the standard token interface according to
  8. * https://eips.ethereum.org/EIPS/eip-7802[ERC-7802].
  9. */
  10. abstract contract ERC20Bridgeable is ERC20, ERC165, IERC7802 {
  11. /// @dev Modifier to restrict access to the token bridge.
  12. modifier onlyTokenBridge() {
  13. // Token bridge should never be impersonated using a relayer/forwarder. Using msg.sender is preferable to
  14. // _msgSender() for security reasons.
  15. _checkTokenBridge(msg.sender);
  16. _;
  17. }
  18. /// @inheritdoc ERC165
  19. function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
  20. return interfaceId == type(IERC7802).interfaceId || super.supportsInterface(interfaceId);
  21. }
  22. /**
  23. * @dev See {IERC7802-crosschainMint}. Emits a {IERC7802-CrosschainMint} event.
  24. */
  25. function crosschainMint(address to, uint256 value) public virtual override onlyTokenBridge {
  26. _mint(to, value);
  27. emit CrosschainMint(to, value, _msgSender());
  28. }
  29. /**
  30. * @dev See {IERC7802-crosschainBurn}. Emits a {IERC7802-CrosschainBurn} event.
  31. */
  32. function crosschainBurn(address from, uint256 value) public virtual override onlyTokenBridge {
  33. _burn(from, value);
  34. emit CrosschainBurn(from, value, _msgSender());
  35. }
  36. /**
  37. * @dev Checks if the caller is a trusted token bridge. MUST revert otherwise.
  38. *
  39. * Developers should implement this function using an access control mechanism that allows
  40. * customizing the list of allowed senders. Consider using {AccessControl} or {AccessManaged}.
  41. */
  42. function _checkTokenBridge(address caller) internal virtual;
  43. }