-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add base deployments #339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| pragma solidity ^0.8.0; | ||
| import "@eth-optimism/contracts/libraries/constants/Lib_PredeployAddresses.sol"; | ||
|
|
||
| import "./Ovm_SpokePool.sol"; | ||
|
|
||
| /** | ||
| * @notice Base Spoke pool. | ||
| */ | ||
| contract Base_SpokePool is Ovm_SpokePool { | ||
| /** | ||
| * @notice Construct the OVM Base SpokePool. | ||
| * @param _initialDepositId Starting deposit ID. Set to 0 unless this is a re-deployment in order to mitigate | ||
| * relay hash collisions. | ||
| * @param _crossDomainAdmin Cross domain admin to set. Can be changed by admin. | ||
| * @param _hubPool Hub pool address to set. Can be changed by admin. | ||
| */ | ||
| function initialize( | ||
| uint32 _initialDepositId, | ||
| address _crossDomainAdmin, | ||
| address _hubPool | ||
| ) public initializer { | ||
| __OvmSpokePool_init( | ||
| _initialDepositId, | ||
| _crossDomainAdmin, | ||
| _hubPool, | ||
| Lib_PredeployAddresses.OVM_ETH, | ||
| 0x4200000000000000000000000000000000000006 | ||
| ); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an exact copy of the Boba_Adapter. Only the name has been changed. |
||
| pragma solidity ^0.8.0; | ||
|
|
||
| import "./interfaces/AdapterInterface.sol"; | ||
| import "../external/interfaces/WETH9Interface.sol"; | ||
|
|
||
| // @dev Use local modified CrossDomainEnabled contract instead of one exported by eth-optimism because we need | ||
| // this contract's state variables to be `immutable` because of the delegateCall call. | ||
| import "./CrossDomainEnabled.sol"; | ||
| import "@eth-optimism/contracts/L1/messaging/IL1StandardBridge.sol"; | ||
|
|
||
| import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; | ||
| import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; | ||
|
|
||
| /** | ||
| * @notice Contract containing logic to send messages from L1 to Base. This is a modified version of the Optimism adapter | ||
| * that excludes the custom bridging logic. | ||
| * @dev Public functions calling external contracts do not guard against reentrancy because they are expected to be | ||
| * called via delegatecall, which will execute this contract's logic within the context of the originating contract. | ||
| * For example, the HubPool will delegatecall these functions, therefore its only necessary that the HubPool's methods | ||
| * that call this contract's logic guard against reentrancy. | ||
| */ | ||
|
|
||
| // solhint-disable-next-line contract-name-camelcase | ||
| contract Base_Adapter is CrossDomainEnabled, AdapterInterface { | ||
| using SafeERC20 for IERC20; | ||
| uint32 public immutable l2GasLimit = 2_000_000; | ||
|
|
||
| WETH9Interface public immutable l1Weth; | ||
|
|
||
| IL1StandardBridge public immutable l1StandardBridge; | ||
|
|
||
| /** | ||
| * @notice Constructs new Adapter. | ||
| * @param _l1Weth WETH address on L1. | ||
| * @param _crossDomainMessenger XDomainMessenger Base system contract. | ||
| * @param _l1StandardBridge Standard bridge contract. | ||
| */ | ||
| constructor( | ||
| WETH9Interface _l1Weth, | ||
| address _crossDomainMessenger, | ||
| IL1StandardBridge _l1StandardBridge | ||
| ) CrossDomainEnabled(_crossDomainMessenger) { | ||
| l1Weth = _l1Weth; | ||
| l1StandardBridge = _l1StandardBridge; | ||
| } | ||
|
|
||
| /** | ||
| * @notice Send cross-chain message to target on Base. | ||
| * @param target Contract on Base that will receive message. | ||
| * @param message Data to send to target. | ||
| */ | ||
| function relayMessage(address target, bytes calldata message) external payable override { | ||
| sendCrossDomainMessage(target, uint32(l2GasLimit), message); | ||
| emit MessageRelayed(target, message); | ||
| } | ||
|
|
||
| /** | ||
| * @notice Bridge tokens to Base. | ||
| * @param l1Token L1 token to deposit. | ||
| * @param l2Token L2 token to receive. | ||
| * @param amount Amount of L1 tokens to deposit and L2 tokens to receive. | ||
| * @param to Bridge recipient. | ||
| */ | ||
| function relayTokens( | ||
| address l1Token, | ||
| address l2Token, | ||
| uint256 amount, | ||
| address to | ||
| ) external payable override { | ||
| // If the l1Token is weth then unwrap it to ETH then send the ETH to the standard bridge. | ||
| if (l1Token == address(l1Weth)) { | ||
| l1Weth.withdraw(amount); | ||
| l1StandardBridge.depositETHTo{ value: amount }(to, l2GasLimit, ""); | ||
| } else { | ||
| IL1StandardBridge _l1StandardBridge = l1StandardBridge; | ||
|
|
||
| IERC20(l1Token).safeIncreaseAllowance(address(_l1StandardBridge), amount); | ||
| _l1StandardBridge.depositERC20To(l1Token, l2Token, to, amount, l2GasLimit, ""); | ||
| } | ||
| emit TokensRelayed(l1Token, l2Token, amount, to); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { ethers } from "ethers"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a lightly modified version of the Optimism adapter deployment script. |
||
| import { L1_ADDRESS_MAP } from "./consts"; | ||
| import { DeployFunction } from "hardhat-deploy/types"; | ||
| import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
|
||
| const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
| const { deployments, getNamedAccounts, getChainId, network } = hre; | ||
| const { deploy } = deployments; | ||
|
|
||
| const { deployer } = await getNamedAccounts(); | ||
|
|
||
| const chainId = parseInt(await getChainId()); | ||
|
|
||
| await deploy("Base_Adapter", { | ||
| from: deployer, | ||
| log: true, | ||
| skipIfAlreadyDeployed: true, | ||
| args: [ | ||
| L1_ADDRESS_MAP[chainId].weth, | ||
| L1_ADDRESS_MAP[chainId].baseCrossDomainMessenger, | ||
| L1_ADDRESS_MAP[chainId].baseStandardBridge, | ||
| ], | ||
| }); | ||
| }; | ||
|
|
||
| module.exports = func; | ||
| func.dependencies = ["HubPool"]; | ||
| func.tags = ["BaseAdapter", "mainnet"]; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { deployNewProxy } from "../utils/utils.hre"; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lightly modified Optimism spoke pool deployment script. |
||
| import { DeployFunction } from "hardhat-deploy/types"; | ||
| import { HardhatRuntimeEnvironment } from "hardhat/types"; | ||
|
|
||
| const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) { | ||
| const hubPool = await hre.companionNetworks.l1.deployments.get("HubPool"); | ||
| const chainId = await hre.getChainId(); | ||
| console.log(`Using L1 (chainId ${chainId}) hub pool @ ${hubPool.address}`); | ||
|
|
||
| // Initialize deposit counter to very high number of deposits to avoid duplicate deposit ID's | ||
| // with deprecated spoke pool. | ||
| // Set hub pool as cross domain admin since it delegatecalls the Adapter logic. | ||
| const constructorArgs = [1_000_000, hubPool.address, hubPool.address]; | ||
| await deployNewProxy("Base_SpokePool", constructorArgs); | ||
| }; | ||
| module.exports = func; | ||
| func.tags = ["BaseSpokePool", "base"]; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 84531 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an exact copy of Optimism_SpokePool.sol, only the name has been changed.