2023-08-20 13:46:39 +00:00
|
|
|
import { ethers } from "hardhat";
|
|
|
|
import fs from "fs/promises";
|
|
|
|
import dotenv from "dotenv";
|
|
|
|
const env = process.env.NODE_ENV || "local";
|
|
|
|
dotenv.config({ path: `.env.${env}` });
|
|
|
|
|
|
|
|
async function main() {
|
2023-08-20 13:56:05 +00:00
|
|
|
if (!process.env.BRIDGE_ADDRESS) throw "Bridge address not defined";
|
2023-08-20 13:46:39 +00:00
|
|
|
if (!process.env.TOKEN_NAME) throw "Token name not defined";
|
|
|
|
if (!process.env.TOKEN_SYMBOL) throw "Token symbol not defined";
|
|
|
|
|
|
|
|
const L1TokenAddress = (await fs.readFile(`.l1-token-address.${env}`, "utf-8")).trim();
|
|
|
|
|
|
|
|
const L2Token = await ethers.deployContract(
|
|
|
|
"L2Token",
|
|
|
|
[
|
|
|
|
process.env.TOKEN_NAME,
|
|
|
|
process.env.TOKEN_SYMBOL,
|
2023-08-20 13:57:32 +00:00
|
|
|
process.env.BRIDGE_ADDRESS,
|
2023-08-20 13:46:39 +00:00
|
|
|
L1TokenAddress,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
|
|
|
await L2Token.waitForDeployment();
|
|
|
|
const deployedAddress = await L2Token.getAddress();
|
|
|
|
|
|
|
|
console.log(`L2 token deployed to: ${deployedAddress}`);
|
|
|
|
await fs.writeFile(`.l2-token-address.${env}`, deployedAddress);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We recommend this pattern to be able to use async/await everywhere
|
|
|
|
// and properly handle errors.
|
|
|
|
main().catch((error) => {
|
|
|
|
console.error(error);
|
|
|
|
process.exitCode = 1;
|
|
|
|
});
|