LibArbitrumL2.sol 1.4 KB

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