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

improve(deploy): Improve SpokePool deployment UX #577

Merged
merged 4 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deploy/003_deploy_optimism_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Optimism_SpokePool", constructorArgs, initArgs, spokeChainId === 10);
await deployNewProxy("Optimism_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["OptimismSpokePool", "optimism"];
2 changes: 1 addition & 1 deletion deploy/005_deploy_arbitrum_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Arbitrum_SpokePool", constructorArgs, initArgs, spokeChainId === 42161);
await deployNewProxy("Arbitrum_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["ArbitrumSpokePool", "arbitrum"];
14 changes: 6 additions & 8 deletions deploy/007_deploy_ethereum_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { DeployFunction } from "hardhat-deploy/types";
import { deployNewProxy } from "../utils/utils.hre";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { L1_ADDRESS_MAP } from "./consts";
import { HardhatRuntimeEnvironment } from "hardhat/types";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getChainId } = hre;
const chainId = await getChainId();
const hubPool = await deployments.get("HubPool");
console.log(`Using chain ${chainId} HubPool @ ${hubPool.address}`);
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
console.log(`Using HubPool @ ${hubPool.address}`);

// Initialize deposit counter to very high number of deposits to avoid duplicate deposit ID's
// with deprecated spoke pool.
Expand All @@ -17,8 +15,8 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// * A WETH address of the WETH address
// * A depositQuoteTimeBuffer of 1 hour
// * A fillDeadlineBuffer of 6 hours
const constructorArgs = [L1_ADDRESS_MAP[chainId].weth, 3600, 21600];
await deployNewProxy("Ethereum_SpokePool", constructorArgs, initArgs, chainId === "1");
const constructorArgs = [L1_ADDRESS_MAP[spokeChainId].weth, 3600, 21600];
await deployNewProxy("Ethereum_SpokePool", constructorArgs, initArgs);

// Transfer ownership to hub pool.
};
Expand Down
2 changes: 1 addition & 1 deletion deploy/011_deploy_polygon_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Polygon_SpokePool", constructorArgs, initArgs, spokeChainId === 137);
await deployNewProxy("Polygon_SpokePool", constructorArgs, initArgs);
};

module.exports = func;
Expand Down
6 changes: 4 additions & 2 deletions deploy/016_deploy_zksync_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// * A fillDeadlineBuffer of 6 hours
const constructorArgs = [L2_ADDRESS_MAP[spokeChainId].l2Weth, 3600, 21600];

let newAddress;
let newAddress: string;
// On production, we'll rarely want to deploy a new proxy contract so we'll default to deploying a new implementation
// contract.
if (spokeChainId === 324) {
// If SKIP_PROXY is defined, only deploy an implementation contract.
pxrl marked this conversation as resolved.
Show resolved Hide resolved
const implementationOnly = process.env.SKIP_PROXY !== undefined;
if (implementationOnly) {
pxrl marked this conversation as resolved.
Show resolved Hide resolved
const _deployment = await deployer.deploy(artifact, constructorArgs);
newAddress = _deployment.address;
console.log(`New ${contractName} implementation deployed @ ${newAddress}`);
Expand Down
2 changes: 1 addition & 1 deletion deploy/025_deploy_base_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
L2_ADDRESS_MAP[spokeChainId].l2Usdc,
L2_ADDRESS_MAP[spokeChainId].cctpTokenMessenger,
];
await deployNewProxy("Base_SpokePool", constructorArgs, initArgs, spokeChainId === 8453);
await deployNewProxy("Base_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["BaseSpokePool", "base"];
2 changes: 1 addition & 1 deletion deploy/029_deploy_linea_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
];
const constructorArgs = [L2_ADDRESS_MAP[chainId].l2Weth, 3600, 21600];

await deployNewProxy("Linea_SpokePool", constructorArgs, initArgs, chainId === 59144);
await deployNewProxy("Linea_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["LineaSpokePool", "linea"];
2 changes: 1 addition & 1 deletion deploy/036_deploy_blast_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
"0x8bA929bE3462a809AFB3Bf9e100Ee110D2CFE531",
L1_ADDRESS_MAP[hubChainId].blastDaiRetriever, // Address of mainnet retriever contract to facilitate USDB finalizations.
];
await deployNewProxy("Blast_SpokePool", constructorArgs, initArgs, spokeChainId === 81457);
await deployNewProxy("Blast_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["BlastSpokePool", "blast"];
5 changes: 2 additions & 3 deletions deploy/039_deploy_mode_spokepool.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
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 { ZERO_ADDRESS } from "@uma/common";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
const { hubPool } = await getSpokePoolDeploymentInfo(hre);

const initArgs = [
1,
Expand All @@ -29,7 +28,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// the cctpTokenMessenger to the zero address.
ZERO_ADDRESS,
];
await deployNewProxy("Mode_SpokePool", constructorArgs, initArgs, spokeChainId === 34443);
await deployNewProxy("Mode_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["ModeSpokePool", "mode"];
4 changes: 2 additions & 2 deletions deploy/043_deploy_lisk_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZERO_ADDRESS } from "@uma/common";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);
const { hubPool } = await getSpokePoolDeploymentInfo(hre);

const initArgs = [
1,
Expand All @@ -28,7 +28,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// the cctpTokenMessenger to the zero address.
ZERO_ADDRESS,
];
await deployNewProxy("Lisk_SpokePool", constructorArgs, initArgs, spokeChainId === 1135);
await deployNewProxy("Lisk_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["LiskSpokePool", "lisk"];
7 changes: 2 additions & 5 deletions deploy/047_deploy_redstone_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZERO_ADDRESS } from "@uma/common";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { CHAIN_IDs } from "../utils";
import { WETH } from "./consts";

const { REDSTONE } = CHAIN_IDs;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);

Expand All @@ -32,7 +29,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// the cctpTokenMessenger to the zero address.
ZERO_ADDRESS,
];
await deployNewProxy("Redstone_SpokePool", constructorArgs, initArgs, spokeChainId === REDSTONE);
await deployNewProxy("Redstone_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["spokepool", "redstone"];
func.tags = ["RedstoneSpokePool", "redstone"];
7 changes: 2 additions & 5 deletions deploy/049_deploy_zora_spokepool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@ import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { ZERO_ADDRESS } from "@uma/common";
import { deployNewProxy, getSpokePoolDeploymentInfo } from "../utils/utils.hre";
import { CHAIN_IDs } from "../utils";
import { WETH } from "./consts";

const { ZORA } = CHAIN_IDs;

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { hubPool, spokeChainId } = await getSpokePoolDeploymentInfo(hre);

Expand All @@ -32,7 +29,7 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
// the cctpTokenMessenger to the zero address.
ZERO_ADDRESS,
];
await deployNewProxy("Zora_SpokePool", constructorArgs, initArgs, spokeChainId === ZORA);
await deployNewProxy("Zora_SpokePool", constructorArgs, initArgs);
};
module.exports = func;
func.tags = ["spokepool", "zora"];
func.tags = ["ZoraSpokePool", "zora"];
1 change: 0 additions & 1 deletion deployments/deployments.json
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 7489978 }
},
"7777777": {
"SpokePool": { "address": "0x09aea4b2242abC8bb4BB78D537A67a245A7bEC64", "blockNumber": 18119425 },
"SpokePoolVerifier": { "address": "0xB4A8d45647445EA9FC3E1058096142390683dBC2", "blockNumber": 18120222 },
"MulticallHandler": { "address": "0x924a9f036260DdD5808007E1AA95f08eD08aA569", "blockNumber": 18119854 }
},
Expand Down
10 changes: 6 additions & 4 deletions src/DeploymentUtils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import * as deployments_ from "../deployments/deployments.json";

interface DeploymentExport {
[chainId: string]: { [contractName: string]: { address: string; blockNumber: number } };
}
const deployments: DeploymentExport = deployments_ as any;

// Returns the deployed address of any contract on any network.
export function getDeployedAddress(contractName: string, networkId: number): string {
try {
return deployments[networkId.toString()][contractName].address;
} catch (_) {
export function getDeployedAddress(contractName: string, networkId: number, throwOnError = true): string | undefined {
const address = deployments[networkId.toString()]?.[contractName]?.address;
if (!address && throwOnError) {
throw new Error(`Contract ${contractName} not found on ${networkId} in deployments.json`);
}

return address;
}

// Returns the deployment block number of any contract on any network.
Expand Down
11 changes: 9 additions & 2 deletions utils/utils.hre.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import hre from "hardhat";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { Deployment, DeploymentSubmission } from "hardhat-deploy/types";
import { getContractFactory } from "./utils";
import { CHAIN_IDs } from "@across-protocol/constants";
import { getDeployedAddress } from "../src/DeploymentUtils";
import { getContractFactory, toBN } from "./utils";

type unsafeAllowTypes = (
| "delegatecall"
Expand All @@ -15,6 +16,7 @@ type unsafeAllowTypes = (
| "enum-definition"
| "missing-public-upgradeto"
)[];

/**
* @description Resolve the HubPool deployment, as well as the HubPool and SpokePool chain IDs for a new deployment.
* @dev This function relies on having companionNetworks defined in the HardhatUserConfig.
Expand All @@ -40,7 +42,7 @@ export async function deployNewProxy(
name: string,
constructorArgs: FnArgs[],
initArgs: FnArgs[],
implementationOnly = false
implementationOnly?: boolean
): Promise<void> {
const { deployments, run, upgrades, getChainId } = hre;
let chainId = Number(await getChainId());
Expand All @@ -50,7 +52,12 @@ export async function deployNewProxy(
if ([CHAIN_IDs.BLAST, CHAIN_IDs.BLAST_SEPOLIA].includes(chainId)) {
unsafeAllowArgs.push("state-variable-immutable");
}

// If a SpokePool can be found in deployments/deployments.json, then only deploy an implementation contract.
const proxy = getDeployedAddress("SpokePool", chainId, false);
implementationOnly ??= proxy !== undefined;
if (implementationOnly) {
console.log(`${name} deployment already detected @ ${proxy}, deploying new implementation.`);
instance = (await upgrades.deployImplementation(await getContractFactory(name, {}), {
constructorArgs,
kind: "uups",
Expand Down
Loading