LibArbitrumL2.sol 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.6.0) (crosschain/arbitrum/LibArbitrumL2.sol)
  3. pragma solidity ^0.8.4;
  4. import {IArbSys as ArbitrumL2_Bridge} from "../../vendor/arbitrum/IArbSys.sol";
  5. import "../errors.sol";
  6. /**
  7. * @dev Primitives for cross-chain aware contracts for
  8. * [Arbitrum](https://arbitrum.io/).
  9. *
  10. * This version should only be used on L2 to process cross-chain messages
  11. * originating from L1. For the other side, use {LibArbitrumL1}.
  12. */
  13. library LibArbitrumL2 {
  14. /**
  15. * @dev Returns whether the current function call is the result of a
  16. * cross-chain message relayed by `arbsys`.
  17. */
  18. address public constant ARBSYS = 0x0000000000000000000000000000000000000064;
  19. function isCrossChain(address arbsys) internal view returns (bool) {
  20. return ArbitrumL2_Bridge(arbsys).isTopLevelCall();
  21. }
  22. /**
  23. * @dev Returns the address of the sender that triggered the current
  24. * cross-chain message through `arbsys`.
  25. *
  26. * NOTE: {isCrossChain} should be checked before trying to recover the
  27. * sender, as it will revert with `NotCrossChainCall` if the current
  28. * function call is not the result of a cross-chain message.
  29. */
  30. function crossChainSender(address arbsys) internal view returns (address) {
  31. if (!isCrossChain(arbsys)) revert NotCrossChainCall();
  32. return
  33. ArbitrumL2_Bridge(arbsys).wasMyCallersAddressAliased()
  34. ? ArbitrumL2_Bridge(arbsys).myCallersAddressWithoutAliasing()
  35. : msg.sender;
  36. }
  37. }