Skip to content
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

refactor: Deployment script cleanup #561

Merged
merged 19 commits into from
Aug 22, 2024
27 changes: 10 additions & 17 deletions deploy/001_deploy_hubpool.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
import { L1_ADDRESS_MAP } from "./consts";

import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L1_ADDRESS_MAP, WETH, ZERO_ADDRESS } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());

const lpTokenFactory = await deploy("LpTokenFactory", { from: deployer, log: true, skipIfAlreadyDeployed: true });
const { deployer } = await hre.getNamedAccounts();
const chainId = parseInt(await hre.getChainId());
const lpTokenFactory = await hre.deployments.deploy("LpTokenFactory", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
});

await deploy("HubPool", {
await hre.deployments.deploy("HubPool", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
lpTokenFactory.address,
L1_ADDRESS_MAP[chainId].finder,
L1_ADDRESS_MAP[chainId].weth,
"0x0000000000000000000000000000000000000000",
],
args: [lpTokenFactory.address, L1_ADDRESS_MAP[chainId].finder, WETH[chainId], ZERO_ADDRESS],
libraries: { MerkleLib: lpTokenFactory.address },
});
};
Expand Down
18 changes: 7 additions & 11 deletions deploy/002_deploy_optimism_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
import { L1_ADDRESS_MAP } from "./consts";
import { L1_ADDRESS_MAP, USDC, WETH } from "./consts";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());
const { deployer } = await hre.getNamedAccounts();
const chainId = parseInt(await hre.getChainId());

const args = [
L1_ADDRESS_MAP[chainId].weth,
WETH[chainId],
L1_ADDRESS_MAP[chainId].optimismCrossDomainMessenger,
L1_ADDRESS_MAP[chainId].optimismStandardBridge,
L1_ADDRESS_MAP[chainId].usdc,
USDC[chainId],
L1_ADDRESS_MAP[chainId].cctpTokenMessenger,
];
const instance = await deploy("Optimism_Adapter", {
const instance = await hre.deployments.deploy("Optimism_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: false,
args: args,
});
await run("verify:verify", { address: instance.address, constructorArguments: args });
await hre.run("verify:verify", { address: instance.address, constructorArguments: args });
};

module.exports = func;
Expand Down
18 changes: 6 additions & 12 deletions deploy/003_deploy_optimism_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L2_ADDRESS_MAP } from "./consts";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { FILL_DEADLINE_BUFFER, L2_ADDRESS_MAP, QUOTE_TIME_BUFFER, USDC, WETH } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
Expand All @@ -15,17 +15,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
hubPool.address,
];

// Construct this spokepool with a:
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
// * Native USDC address on L2
// * CCTP token messenger address on L2
const constructorArgs = [
pxrl marked this conversation as resolved.
Show resolved Hide resolved
"0x4200000000000000000000000000000000000006",
3600,
21600,
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
WETH[spokeChainId],
QUOTE_TIME_BUFFER,
FILL_DEADLINE_BUFFER,
USDC[spokeChainId],
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Optimism_SpokePool", constructorArgs, initArgs);
Expand Down
18 changes: 7 additions & 11 deletions deploy/004_deploy_arbitrum_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { L1_ADDRESS_MAP } from "./consts";
import { L1_ADDRESS_MAP, USDC } from "./consts";
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());
const { deployer } = await hre.getNamedAccounts();
const chainId = parseInt(await hre.getChainId());

// This address receives gas refunds on the L2 after messages are relayed. Currently
// set to the Risk Labs relayer address. The deployer should change this if necessary.
Expand All @@ -18,22 +14,22 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L1_ADDRESS_MAP[chainId].l1ArbitrumInbox,
L1_ADDRESS_MAP[chainId].l1ERC20GatewayRouter,
l2RefundAddress,
L1_ADDRESS_MAP[chainId].usdc,
USDC[chainId],
L1_ADDRESS_MAP[chainId].cctpTokenMessenger,
];
const instance = await deploy("Arbitrum_Adapter", {
const instance = await hre.deployments.deploy("Arbitrum_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: false,
args: [
L1_ADDRESS_MAP[chainId].l1ArbitrumInbox,
L1_ADDRESS_MAP[chainId].l1ERC20GatewayRouter,
l2RefundAddress,
L1_ADDRESS_MAP[chainId].usdc,
USDC[chainId],
L1_ADDRESS_MAP[chainId].cctpTokenMessenger,
],
});
await run("verify:verify", { address: instance.address, constructorArguments: args });
await hre.run("verify:verify", { address: instance.address, constructorArguments: args });
};

module.exports = func;
Expand Down
18 changes: 6 additions & 12 deletions deploy/005_deploy_arbitrum_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeployFunction } from "hardhat-deploy/types";
import { L2_ADDRESS_MAP } from "./consts";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { FILL_DEADLINE_BUFFER, L2_ADDRESS_MAP, QUOTE_TIME_BUFFER, USDC, WETH } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
Expand All @@ -16,17 +16,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
hubPool.address,
];

// Construct this spokepool with a:
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
// * Native USDC address on L2
// * CCTP token messenger address on L2
const constructorArgs = [
L2_ADDRESS_MAP[spokeChainId].l2Weth,
3600,
21600,
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
WETH[spokeChainId],
QUOTE_TIME_BUFFER,
FILL_DEADLINE_BUFFER,
USDC[spokeChainId],
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Arbitrum_SpokePool", constructorArgs, initArgs);
Expand Down
7 changes: 2 additions & 5 deletions deploy/006_deploy_ethereum_adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@ import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await hre.getNamedAccounts();

const { deployer } = await getNamedAccounts();

await deploy("Ethereum_Adapter", {
await hre.deployments.deploy("Ethereum_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
Expand Down
8 changes: 2 additions & 6 deletions deploy/007_deploy_ethereum_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { L1_ADDRESS_MAP } from "./consts";
import { FILL_DEADLINE_BUFFER, QUOTE_TIME_BUFFER, WETH } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
Expand All @@ -11,11 +11,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// with deprecated spoke pool.
const initArgs = [1_000_000, hubPool.address];

// Construct this spokepool with a:
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
const constructorArgs = [L1_ADDRESS_MAP[spokeChainId].weth, 3600, 21600];
const constructorArgs = [WETH[spokeChainId], QUOTE_TIME_BUFFER, FILL_DEADLINE_BUFFER];
await deployNewProxy("Ethereum_SpokePool", constructorArgs, initArgs);

// Transfer ownership to hub pool.
Expand Down
24 changes: 11 additions & 13 deletions deploy/008_deploy_polygon_token_bridger_mainnet.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import { DeployFunction } from "hardhat-deploy/types";
import { L1_ADDRESS_MAP, POLYGON_CHAIN_IDS } from "./consts";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L1_ADDRESS_MAP, POLYGON_CHAIN_IDS, WETH, WMATIC } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());
const { deployments } = hre;
const { deployer } = await hre.getNamedAccounts();
const hubChainId = parseInt(await hre.getChainId());
const spokeChainId = POLYGON_CHAIN_IDS[hubChainId];
const hubPool = await deployments.get("HubPool");

await deploy("PolygonTokenBridger", {
await deployments.deploy("PolygonTokenBridger", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
hubPool.address,
L1_ADDRESS_MAP[chainId].polygonRegistry,
L1_ADDRESS_MAP[chainId].weth,
L1_ADDRESS_MAP[chainId].l2WrappedMatic,
chainId,
POLYGON_CHAIN_IDS[chainId],
L1_ADDRESS_MAP[hubChainId].polygonRegistry,
WETH[hubChainId],
WMATIC[spokeChainId],
hubChainId,
spokeChainId,
],
deterministicDeployment: "0x1234", // Salt for the create2 call.
});
Expand Down
23 changes: 11 additions & 12 deletions deploy/009_deploy_polygon_adapter.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import { DeployFunction } from "hardhat-deploy/types";
import { L1_ADDRESS_MAP } from "./consts";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { TOKEN_SYMBOLS_MAP } from "../utils";
import { L1_ADDRESS_MAP, USDC, WETH } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();
const MATIC = TOKEN_SYMBOLS_MAP.MATIC.addresses;

const chainId = parseInt(await getChainId());
const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployer } = await hre.getNamedAccounts();
const chainId = parseInt(await hre.getChainId());

const args = [
L1_ADDRESS_MAP[chainId].polygonRootChainManager,
L1_ADDRESS_MAP[chainId].polygonFxRoot,
L1_ADDRESS_MAP[chainId].polygonDepositManager,
L1_ADDRESS_MAP[chainId].polygonERC20Predicate,
L1_ADDRESS_MAP[chainId].matic,
L1_ADDRESS_MAP[chainId].weth,
L1_ADDRESS_MAP[chainId].usdc,
MATIC[chainId],
WETH[chainId],
USDC[chainId],
L1_ADDRESS_MAP[chainId].cctpTokenMessenger,
];
const instance = await deploy("Polygon_Adapter", {
const instance = await hre.deployments.deploy("Polygon_Adapter", {
from: deployer,
log: true,
skipIfAlreadyDeployed: false,
args,
});
await run("verify:verify", { address: instance.address, constructorArguments: args });
await hre.run("verify:verify", { address: instance.address, constructorArguments: args });
};

module.exports = func;
Expand Down
24 changes: 10 additions & 14 deletions deploy/010_deploy_polygon_token_bridger_polygon.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import { DeployFunction } from "hardhat-deploy/types";
import { L1_ADDRESS_MAP } from "./consts";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { L1_ADDRESS_MAP, WETH, WMATIC } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts, getChainId } = hre;
const { deploy } = deployments;

const { deployer } = await getNamedAccounts();

const chainId = parseInt(await getChainId());
const l1ChainId = parseInt(await hre.companionNetworks.l1.getChainId());
const { deployer } = await hre.getNamedAccounts();
const spokeChainId = parseInt(await hre.getChainId());
const hubChainId = parseInt(await hre.companionNetworks.l1.getChainId());
const l1HubPool = await hre.companionNetworks.l1.deployments.get("HubPool");

await deploy("PolygonTokenBridger", {
await hre.deployments.deploy("PolygonTokenBridger", {
from: deployer,
log: true,
skipIfAlreadyDeployed: true,
args: [
l1HubPool.address,
L1_ADDRESS_MAP[l1ChainId].polygonRegistry,
L1_ADDRESS_MAP[l1ChainId].weth,
L1_ADDRESS_MAP[l1ChainId].l2WrappedMatic,
l1ChainId,
chainId,
L1_ADDRESS_MAP[hubChainId].polygonRegistry,
WETH[hubChainId],
WMATIC[spokeChainId],
hubChainId,
spokeChainId,
],
deterministicDeployment: "0x1234", // Salt for the create2 call.
});
Expand Down
18 changes: 6 additions & 12 deletions deploy/011_deploy_polygon_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DeployFunction } from "hardhat-deploy/types";
import { L2_ADDRESS_MAP } from "./consts";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { FILL_DEADLINE_BUFFER, L2_ADDRESS_MAP, QUOTE_TIME_BUFFER, USDC, WMATIC } from "./consts";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
Expand All @@ -19,17 +19,11 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L2_ADDRESS_MAP[spokeChainId].fxChild,
];

// Construct this spokepool with a:
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
// * Native USDC address on L2
// * CCTP token messenger address on L2
const constructorArgs = [
L2_ADDRESS_MAP[spokeChainId].wMatic,
3600,
21600,
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
WMATIC[spokeChainId],
QUOTE_TIME_BUFFER,
FILL_DEADLINE_BUFFER,
USDC[spokeChainId],
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Polygon_SpokePool", constructorArgs, initArgs);
Expand Down
Loading
Loading