LibAMB.sol 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. // SPDX-License-Identifier: MIT
  2. // OpenZeppelin Contracts (last updated v4.7.0) (crosschain/amb/LibAMB.sol)
  3. pragma solidity ^0.8.4;
  4. import {IAMB as AMB_Bridge} from "../../vendor/amb/IAMB.sol";
  5. import "../errors.sol";
  6. /**
  7. * @dev Primitives for cross-chain aware contracts using the
  8. * https://docs.tokenbridge.net/amb-bridge/about-amb-bridge[AMB]
  9. * family of bridges.
  10. */
  11. library LibAMB {
  12. /**
  13. * @dev Returns whether the current function call is the result of a
  14. * cross-chain message relayed by `bridge`.
  15. */
  16. function isCrossChain(address bridge) internal view returns (bool) {
  17. return msg.sender == bridge;
  18. }
  19. /**
  20. * @dev Returns the address of the sender that triggered the current
  21. * cross-chain message through `bridge`.
  22. *
  23. * NOTE: {isCrossChain} should be checked before trying to recover the
  24. * sender, as it will revert with `NotCrossChainCall` if the current
  25. * function call is not the result of a cross-chain message.
  26. */
  27. function crossChainSender(address bridge) internal view returns (address) {
  28. if (!isCrossChain(bridge)) revert NotCrossChainCall();
  29. return AMB_Bridge(bridge).messageSender();
  30. }
  31. }