Skip to content

Commit

Permalink
apply standardization to hardhat deploy scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
thedarkjester committed Dec 17, 2024
1 parent a358ebd commit d24429c
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 67 deletions.
12 changes: 8 additions & 4 deletions contracts/deploy/01_deploy_PlonkVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
}
const contract = await deployFromFactory(contractName, provider);
const contractAddress = await contract.getAddress();
console.log(`${contractName} deployed at ${contractAddress}`);

process.env.PLONKVERIFIER_ADDRESS = contractAddress;

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(hre.network.name, contractName, contractAddress, deployTx.hash);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

await tryVerifyContract(contractAddress);
};
Expand Down
14 changes: 9 additions & 5 deletions contracts/deploy/02_deploy_Timelock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
);
const contractAddress = await contract.getAddress();

console.log(`${contractName} deployed at ${contractAddress}`);

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(hre.network.name, contractName, contractAddress, deployTx.hash);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

const args = [minDelay, timeLockProposers?.split(","), timelockExecutors?.split(","), adminAddress];

await tryVerifyContractWithConstructorArgs(
Expand Down
8 changes: 6 additions & 2 deletions contracts/deploy/03_deploy_LineaRollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
LINEA_ROLLUP_UNPAUSE_TYPES_ROLES,
OPERATOR_ROLE,
} from "../common/constants";
import { ethers } from "hardhat";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments } = hre;
Expand Down Expand Up @@ -78,10 +79,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const contractAddress = await contract.getAddress();
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Contract deployment transaction receipt not found.";
throw "Deployment transaction not found.";
}

console.log(`${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber}`);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

Expand Down
8 changes: 6 additions & 2 deletions contracts/deploy/03_deploy_LineaRollupV5.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
tryStoreAddress,
tryVerifyContract,
} from "contracts/common/helpers";
import { ethers } from "hardhat";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments } = hre;
Expand Down Expand Up @@ -63,10 +64,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const contractAddress = await contract.getAddress();
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Contract deployment transaction receipt not found.";
throw "Deployment transaction not found.";
}

console.log(`${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber}`);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

Expand Down
9 changes: 7 additions & 2 deletions contracts/deploy/04_deploy_L2MessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
L2_MESSAGE_SERVICE_ROLES,
L2_MESSAGE_SERVICE_UNPAUSE_TYPES_ROLES,
} from "../common/constants";
import { ethers } from "hardhat";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments } = hre;
Expand Down Expand Up @@ -62,9 +63,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const contractAddress = await contract.getAddress();
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Contract deployment transaction receipt not found.";
throw "Deployment transaction not found.";
}
console.log(`${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber}`);

const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

Expand Down
7 changes: 5 additions & 2 deletions contracts/deploy/04_deploy_L2MessageServiceV1Deployed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const contractAddress = await contract.getAddress();
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Contract deployment transaction receipt not found.";
throw "Deployment transaction not found.";
}

console.log(`${contractName} deployed at ${contractAddress}`);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

Expand Down
16 changes: 9 additions & 7 deletions contracts/deploy/05_deploy_BridgedToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const BridgedToken = await ethers.getContractFactory(contractName);

const bridgedToken = (await upgrades.deployBeacon(BridgedToken)) as unknown as BridgedToken;
await bridgedToken.waitForDeployment();

const bridgedTokenAddress = await bridgedToken.getAddress();
process.env.BRIDGED_TOKEN_ADDRESS = bridgedTokenAddress;

// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const deployTx = bridgedToken.deployTransaction;
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
const txReceipt = await bridgedToken.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(network.name, contractName, bridgedTokenAddress, deployTx.hash);
const contractAddress = await bridgedToken.getAddress();
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(network.name, contractName, bridgedTokenAddress, txReceipt.hash);

if (process.env.TOKEN_BRIDGE_L1 === "true") {
console.log(`L1 BridgedToken beacon deployed on ${network.name}, at address:`, bridgedTokenAddress);
Expand Down
14 changes: 10 additions & 4 deletions contracts/deploy/06_deploy_TokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await tokenBridge.waitForDeployment();
const tokenBridgeAddress = await tokenBridge.getAddress();

const deployTx = tokenBridge.deploymentTransaction();
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
const txReceipt = await tokenBridge.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(network.name, contractName, tokenBridgeAddress, deployTx.hash);
const contractAddress = await tokenBridge.getAddress();

console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(network.name, contractName, tokenBridgeAddress, txReceipt.hash);

const proxyAdminAddress = await upgrades.erc1967.getAdminAddress(tokenBridgeAddress);

Expand Down
17 changes: 10 additions & 7 deletions contracts/deploy/07_deploy_LXPToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
console.log(`Deploying new version, NB: ${existingContractAddress} will be overwritten if env SAVE_ADDRESS=true.`);
}
const contract = await deployFromFactory(contractName, provider, adminAddress, await get1559Fees(provider));
const contractAddress = await contract.getAddress();
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

console.log(`${contractName} deployed at ${contractAddress}`);
const contractAddress = await contract.getAddress();

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
}
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, deployTx.hash);
await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

const args = [adminAddress];

Expand Down
19 changes: 11 additions & 8 deletions contracts/deploy/07_deploy_SurgeXPToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,22 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
transferAddresses,
await get1559Fees(provider),
);
const contractAddress = await contract.getAddress();

console.log(`${contractName} deployed at ${contractAddress}`);

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(hre.network.name, contractName, contractAddress, deployTx.hash);
const contractAddress = await contract.getAddress();

const args = [adminAddress, minterAddress, transferAddresses];
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

const args = [adminAddress, minterAddress, transferAddresses];
await tryVerifyContractWithConstructorArgs(contractAddress, "contracts/token/LineaSurgeXP.sol:LineaSurgeXP", args);
};
export default func;
Expand Down
19 changes: 10 additions & 9 deletions contracts/deploy/08_deploy_CustomBridgedToken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,20 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
},
);

await customBridgedToken.waitForDeployment();
const customBridgedTokenAddress = await customBridgedToken.getAddress();

const deployTx = customBridgedToken.deploymentTransaction();
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
const txReceipt = await customBridgedToken.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(network.name, contractName, customBridgedTokenAddress, deployTx.hash);
const contractAddress = await customBridgedToken.getAddress();

console.log(`CustomBridgedToken deployed on ${network.name}, at address:`, customBridgedTokenAddress);
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryVerifyContract(customBridgedTokenAddress);
await tryStoreAddress(network.name, contractName, contractAddress, txReceipt.hash);
await tryVerifyContract(contractAddress);
};

export default func;
func.tags = ["CustomBridgedToken"];
13 changes: 8 additions & 5 deletions contracts/deploy/09_deploy_TestEIP4844.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const func: DeployFunction = async function () {
const contract = await deployFromFactory(contractName, provider, await get1559Fees(provider));
const contractAddress = await contract.getAddress();

console.log(`${contractName} deployed at ${contractAddress}`);

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
throw "Contract deployment transaction receipt not found.";
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);
};
export default func;
func.tags = ["TestEIP4844"];
6 changes: 5 additions & 1 deletion contracts/deploy/10_deploy_RecoverFunds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { deployUpgradableFromFactory } from "../scripts/hardhat/utils";
import { tryVerifyContract, getDeployedContractAddress, tryStoreAddress, getRequiredEnvVar } from "../common/helpers";
import { ethers } from "hardhat";

const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments } = hre;
Expand Down Expand Up @@ -36,7 +37,10 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
throw "Contract deployment transaction receipt not found.";
}

console.log(`${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber}`);
const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

await tryStoreAddress(hre.network.name, contractName, contractAddress, txReceipt.hash);

Expand Down
13 changes: 8 additions & 5 deletions contracts/deploy/11_deploy_TestERC20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
await contract.waitForDeployment();
const contractAddress = await contract.getAddress();

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

await tryStoreAddress(network.name, contractName, contractAddress, deployTx.hash);
await tryStoreAddress(network.name, contractName, contractAddress, txReceipt.hash);

const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

const chainId = (await ethers.provider.getNetwork()).chainId;
console.log(`${contractName} deployed on ${network.name}, chainId=${chainId}, at address: ${contractAddress}`);
await tryVerifyContract(contractAddress);
};

Expand Down
11 changes: 7 additions & 4 deletions contracts/deploy/12_deploy_CallForwardingProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ const func: DeployFunction = async function () {
const contract = await deployFromFactory(contractName, provider, targetAddress);
const contractAddress = await contract.getAddress();

console.log(`${contractName} deployed at ${contractAddress}`);

const deployTx = contract.deploymentTransaction();
if (!deployTx) {
const txReceipt = await contract.deploymentTransaction()?.wait();
if (!txReceipt) {
throw "Deployment transaction not found.";
}

const chainId = (await ethers.provider!.getNetwork()).chainId;
console.log(
`contract=${contractName} deployed: address=${contractAddress} blockNumber=${txReceipt.blockNumber} chainId=${chainId}`,
);

const args = [targetAddress];

await tryVerifyContractWithConstructorArgs(
Expand Down

0 comments on commit d24429c

Please sign in to comment.