LibAMB.sol 1.1 KB

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