|
| 1 | +// SPDX-License-Identifier: BUSL-1.1 |
| 2 | +pragma solidity ^0.8.0; |
| 3 | +import "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol"; |
| 4 | + |
| 5 | +import "./Ovm_SpokePool.sol"; |
| 6 | +import "./external/interfaces/CCTPInterfaces.sol"; |
| 7 | +import { IOpUSDCBridgeAdapter } from "./external/interfaces/IOpUSDCBridgeAdapter.sol"; |
| 8 | + |
| 9 | +/** |
| 10 | + * @notice Cher SpokePool. |
| 11 | + * @custom:security-contact [email protected] |
| 12 | + */ |
| 13 | +contract Cher_SpokePool is Ovm_SpokePool { |
| 14 | + using SafeERC20 for IERC20; |
| 15 | + |
| 16 | + // Address of the custom L2 USDC bridge. |
| 17 | + address private constant USDC_BRIDGE = 0x8be79275FCfD08A931087ECf70Ba8a99aee3AC59; |
| 18 | + |
| 19 | + /// @custom:oz-upgrades-unsafe-allow constructor |
| 20 | + constructor( |
| 21 | + address _wrappedNativeTokenAddress, |
| 22 | + uint32 _depositQuoteTimeBuffer, |
| 23 | + uint32 _fillDeadlineBuffer, |
| 24 | + IERC20 _l2Usdc, |
| 25 | + ITokenMessenger _cctpTokenMessenger |
| 26 | + ) |
| 27 | + Ovm_SpokePool( |
| 28 | + _wrappedNativeTokenAddress, |
| 29 | + _depositQuoteTimeBuffer, |
| 30 | + _fillDeadlineBuffer, |
| 31 | + _l2Usdc, |
| 32 | + _cctpTokenMessenger |
| 33 | + ) |
| 34 | + {} // solhint-disable-line no-empty-blocks |
| 35 | + |
| 36 | + /** |
| 37 | + * @notice Construct the OVM Cher SpokePool. |
| 38 | + * @param _initialDepositId Starting deposit ID. Set to 0 unless this is a re-deployment in order to mitigate |
| 39 | + * relay hash collisions. |
| 40 | + * @param _crossDomainAdmin Cross domain admin to set. Can be changed by admin. |
| 41 | + * @param _withdrawalRecipient Address which receives token withdrawals. Can be changed by admin. For Spoke Pools on L2, this will |
| 42 | + */ |
| 43 | + function initialize( |
| 44 | + uint32 _initialDepositId, |
| 45 | + address _crossDomainAdmin, |
| 46 | + address _withdrawalRecipient |
| 47 | + ) public initializer { |
| 48 | + __OvmSpokePool_init(_initialDepositId, _crossDomainAdmin, _withdrawalRecipient, Lib_PredeployAddresses.OVM_ETH); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * @notice Cher-specific logic to bridge tokens back to the hub pool contract on L1. |
| 53 | + * @param amountToReturn Amount of the token to bridge back. |
| 54 | + * @param l2TokenAddress Address of the l2 Token to bridge back. This token will either be bridged back to the token defined in the mapping `remoteL1Tokens`, |
| 55 | + * or via the canonical mapping defined in the bridge contract retrieved from `tokenBridges`. |
| 56 | + * @dev This implementation deviates slightly from `_bridgeTokensToHubPool` in the `Ovm_SpokePool` contract since |
| 57 | + * this chain uses Circle's bridged (upgradable to native) USDC standard, which uses a custom interface. |
| 58 | + */ |
| 59 | + function _bridgeTokensToHubPool(uint256 amountToReturn, address l2TokenAddress) internal virtual override { |
| 60 | + // Handle custom USDC bridge which doesn't conform to the standard bridge interface. In the future, CCTP may be used to bridge USDC to mainnet, in which |
| 61 | + // case bridging logic is handled by the Ovm_SpokePool code. In the meantime, if CCTP is not enabled, then use the USDC bridge. Once CCTP is activated on |
| 62 | + // Cher, this block of code will be unused. |
| 63 | + if (l2TokenAddress == address(usdcToken) && !_isCCTPEnabled()) { |
| 64 | + usdcToken.safeIncreaseAllowance(USDC_BRIDGE, amountToReturn); |
| 65 | + IOpUSDCBridgeAdapter(USDC_BRIDGE).sendMessage( |
| 66 | + withdrawalRecipient, // _to. Withdraw, over the bridge, to the l1 hub pool contract. |
| 67 | + amountToReturn, // _amount. |
| 68 | + l1Gas // _minGasLimit. Same value used in other OpStack bridges. |
| 69 | + ); |
| 70 | + } else super._bridgeTokensToHubPool(amountToReturn, l2TokenAddress); |
| 71 | + } |
| 72 | +} |
0 commit comments