|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | + |
| 4 | +import "./interfaces/AdapterInterface.sol"; |
| 5 | +import "../external/interfaces/WETH9Interface.sol"; |
| 6 | + |
| 7 | +// @dev Use local modified CrossDomainEnabled contract instead of one exported by eth-optimism because we need |
| 8 | +// this contract's state variables to be `immutable` because of the delegateCall call. |
| 9 | +import "./CrossDomainEnabled.sol"; |
| 10 | +import "@eth-optimism/contracts/L1/messaging/IL1StandardBridge.sol"; |
| 11 | + |
| 12 | +import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; |
| 13 | +import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; |
| 14 | + |
| 15 | +import "../libraries/CircleCCTPAdapter.sol"; |
| 16 | +import "../external/interfaces/CCTPInterfaces.sol"; |
| 17 | + |
| 18 | +/** |
| 19 | + * @notice Contract containing logic to send messages from L1 to World Chain. This is a clone of the Base/Mode adapter |
| 20 | + * @dev Public functions calling external contracts do not guard against reentrancy because they are expected to be |
| 21 | + * called via delegatecall, which will execute this contract's logic within the context of the originating contract. |
| 22 | + * For example, the HubPool will delegatecall these functions, therefore its only necessary that the HubPool's methods |
| 23 | + * that call this contract's logic guard against reentrancy. |
| 24 | + * @custom:security-contact [email protected] |
| 25 | + */ |
| 26 | + |
| 27 | +// solhint-disable-next-line contract-name-camelcase |
| 28 | +contract WorldChain_Adapter is CrossDomainEnabled, AdapterInterface, CircleCCTPAdapter { |
| 29 | + using SafeERC20 for IERC20; |
| 30 | + uint32 public constant L2_GAS_LIMIT = 200_000; |
| 31 | + |
| 32 | + WETH9Interface public immutable L1_WETH; |
| 33 | + |
| 34 | + IL1StandardBridge public immutable L1_STANDARD_BRIDGE; |
| 35 | + |
| 36 | + /** |
| 37 | + * @notice Constructs new Adapter. |
| 38 | + * @param _l1Weth WETH address on L1. |
| 39 | + * @param _crossDomainMessenger XDomainMessenger World Chain system contract. |
| 40 | + * @param _l1StandardBridge Standard bridge contract. |
| 41 | + * @param _l1Usdc USDC address on L1. |
| 42 | + */ |
| 43 | + constructor( |
| 44 | + WETH9Interface _l1Weth, |
| 45 | + address _crossDomainMessenger, |
| 46 | + IL1StandardBridge _l1StandardBridge, |
| 47 | + IERC20 _l1Usdc |
| 48 | + ) |
| 49 | + CrossDomainEnabled(_crossDomainMessenger) |
| 50 | + CircleCCTPAdapter( |
| 51 | + _l1Usdc, |
| 52 | + // Hardcode cctp messenger to 0x0 to disable CCTP bridging. |
| 53 | + ITokenMessenger(address(0)), |
| 54 | + CircleDomainIds.UNINTIALIZED |
| 55 | + ) |
| 56 | + { |
| 57 | + L1_WETH = _l1Weth; |
| 58 | + L1_STANDARD_BRIDGE = _l1StandardBridge; |
| 59 | + } |
| 60 | + |
| 61 | + /** |
| 62 | + * @notice Send cross-chain message to target on World Chain. |
| 63 | + * @param target Contract on World Chain that will receive message. |
| 64 | + * @param message Data to send to target. |
| 65 | + */ |
| 66 | + function relayMessage(address target, bytes calldata message) external payable override { |
| 67 | + sendCrossDomainMessage(target, L2_GAS_LIMIT, message); |
| 68 | + emit MessageRelayed(target, message); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * @notice Bridge tokens to World Chain. |
| 73 | + * @param l1Token L1 token to deposit. |
| 74 | + * @param l2Token L2 token to receive. |
| 75 | + * @param amount Amount of L1 tokens to deposit and L2 tokens to receive. |
| 76 | + * @param to Bridge recipient. |
| 77 | + */ |
| 78 | + function relayTokens( |
| 79 | + address l1Token, |
| 80 | + address l2Token, |
| 81 | + uint256 amount, |
| 82 | + address to |
| 83 | + ) external payable override { |
| 84 | + // If the l1Token is weth then unwrap it to ETH then send the ETH to the standard bridge. |
| 85 | + if (l1Token == address(L1_WETH)) { |
| 86 | + L1_WETH.withdraw(amount); |
| 87 | + L1_STANDARD_BRIDGE.depositETHTo{ value: amount }(to, L2_GAS_LIMIT, ""); |
| 88 | + } |
| 89 | + // Check if this token is USDC, which requires a custom bridge via CCTP. |
| 90 | + else if (_isCCTPEnabled() && l1Token == address(usdcToken)) { |
| 91 | + _transferUsdc(to, amount); |
| 92 | + } else { |
| 93 | + IL1StandardBridge _l1StandardBridge = L1_STANDARD_BRIDGE; |
| 94 | + |
| 95 | + IERC20(l1Token).safeIncreaseAllowance(address(_l1StandardBridge), amount); |
| 96 | + _l1StandardBridge.depositERC20To(l1Token, l2Token, to, amount, L2_GAS_LIMIT, ""); |
| 97 | + } |
| 98 | + emit TokensRelayed(l1Token, l2Token, amount, to); |
| 99 | + } |
| 100 | +} |
0 commit comments