|
| 1 | +#!/usr/bin/env -S node --require ts-node/register |
| 2 | + |
| 3 | +import { providers, Wallet, utils, Contract } from "ethers"; |
| 4 | +import { getContractInterface, predeploys } from "@eth-optimism/contracts"; |
| 5 | +import erc20Abi from "./ERC20.json"; |
| 6 | +import dotenv from "dotenv"; |
| 7 | +dotenv.config(); |
| 8 | + |
| 9 | +function config() { |
| 10 | + if (!process.env.PRIVATE_KEY) throw new Error("Must pass PRIVATE_KEY"); |
| 11 | + if (!process.env.NETWORK) throw new Error("Must pass NETWORK"); |
| 12 | + if (!process.env.NAME) throw new Error("Must pass NAME"); |
| 13 | + if (!process.env.SYMBOL) throw new Error("Must pass SYMBOL"); |
| 14 | + if (!process.env.L1_TOKEN_ADDRESS) throw new Error("Must pass L1_TOKEN_ADDRESS"); |
| 15 | + return { |
| 16 | + privateKey: process.env.PRIVATE_KEY, |
| 17 | + network: process.env.NETWORK, |
| 18 | + name: process.env.NAME, |
| 19 | + symbol: process.env.SYMBOL, |
| 20 | + l1TokenAddress: process.env.L1_TOKEN_ADDRESS, |
| 21 | + }; |
| 22 | +} |
| 23 | + |
| 24 | +(async () => { |
| 25 | + console.log("booting up fam\n"); |
| 26 | + const cfg = config(); |
| 27 | + |
| 28 | + const l2FactoryAddress = |
| 29 | + cfg.network === "kovan" |
| 30 | + ? "0x50EB44e3a68f1963278b4c74c6c343508d31704C" |
| 31 | + : "0x2e985AcD6C8Fa033A4c5209b0140940E24da7C5C"; |
| 32 | + |
| 33 | + const l2Provider = new providers.JsonRpcProvider(`https://${cfg.network}.optimism.io`); |
| 34 | + const wallet = new Wallet(cfg.privateKey).connect(l2Provider); |
| 35 | + const l2TokenFactory = new Contract(l2FactoryAddress, getContractInterface("OVM_L2StandardTokenFactory"), wallet); |
| 36 | + const address = await wallet.getAddress(); |
| 37 | + console.log(`Deploying ${cfg.name} ($${cfg.symbol}) from ${address}...`); |
| 38 | + const tx = await l2TokenFactory.createStandardL2Token(cfg.l1TokenAddress, cfg.name, cfg.symbol); |
| 39 | + const receipt = await tx.wait(); |
| 40 | + const [, tokenCreatedEvent] = receipt.events; |
| 41 | + const l2TokenAddress = tokenCreatedEvent.args._l2Token; |
| 42 | + console.log(`Deployed to ${l2TokenAddress} on Optimistic ${cfg.network}`); |
| 43 | +})().catch((err) => { |
| 44 | + console.log(err); |
| 45 | + process.exit(1); |
| 46 | +}); |
0 commit comments