From ec21f2dc23ea9f4a452e4c6c4d5548f34355322c Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Fri, 7 Jul 2023 10:33:32 -0500 Subject: [PATCH 1/3] feat: adds command --help --- bin/index.js | 111 +++++++++++++++++++++++++++----------- src/confirm-withdrawal.ts | 15 ++++++ src/create.ts | 10 ++++ src/deposit.ts | 15 ++++++ src/index.ts | 107 +++++++++++++++++++++++------------- src/withdraw.ts | 15 ++++++ 6 files changed, 205 insertions(+), 68 deletions(-) diff --git a/bin/index.js b/bin/index.js index 8e32b311..5d217c6e 100755 --- a/bin/index.js +++ b/bin/index.js @@ -1,5 +1,28 @@ #! /usr/bin/env node "use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + var desc = Object.getOwnPropertyDescriptor(m, k); + if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { + desc = { enumerable: true, get: function() { return m[k]; } }; + } + Object.defineProperty(o, k2, desc); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { @@ -18,47 +41,75 @@ const chalk_1 = __importDefault(require("chalk")); // const figlet = require('figlet'); const figlet_1 = __importDefault(require("figlet")); // import method to create projects -const create_1 = __importDefault(require("./create")); -const deposit_1 = __importDefault(require("./deposit")); -const withdraw_1 = __importDefault(require("./withdraw")); -const help_1 = __importDefault(require("./help")); -const confirm_withdrawal_1 = __importDefault(require("./confirm-withdrawal")); +const create_1 = __importStar(require("./create")); +const deposit_1 = __importStar(require("./deposit")); +const withdraw_1 = __importStar(require("./withdraw")); +const confirm_withdrawal_1 = __importStar(require("./confirm-withdrawal")); const zeek_1 = __importDefault(require("./zeek")); -const availableOptions = ['create', 'deposit', 'withdraw', 'confirm-withdrawal', 'help']; +const help_1 = __importDefault(require("./help")); +const availableOptions = [ + "create", + "deposit", + "withdraw", + "confirm-withdrawal", + "help", +]; // second argument should be the selected option const option = process.argv[2]; const main = () => __awaiter(void 0, void 0, void 0, function* () { + const helpFlag = Boolean(process.argv.filter((arg) => arg === "--help")[0]); if (!availableOptions.includes(option)) { console.log(`Invalid operation. Available operations are: ${availableOptions}`); process.exit(-1); } // Starts CLI - console.log(chalk_1.default.magentaBright(figlet_1.default.textSync(`zkSync ${option}`, { horizontalLayout: 'full' }))); - const zeekFlag = Boolean(process.argv.filter(arg => arg === "--zeek")[0]); + console.log(chalk_1.default.magentaBright(figlet_1.default.textSync(`zkSync ${option}`, { horizontalLayout: "full" }))); + const zeekFlag = Boolean(process.argv.filter((arg) => arg === "--zeek")[0]); const l1RpcUrl = String(process.argv - .filter(arg => arg.startsWith("l1-rpc-url")) - .map(arg => arg.split('=')[1])[0]); + .filter((arg) => arg.startsWith("l1-rpc-url")) + .map((arg) => arg.split("=")[1])[0]); const l2RpcUrl = String(process.argv - .filter(arg => arg.startsWith("l2-rpc-url")) - .map(arg => arg.split('=')[1])[0]); - switch (option) { - case 'create': - // arg 3 is the project name - const projectName = process.argv[3] || '.'; - yield (0, create_1.default)(projectName, zeekFlag); - break; - case 'deposit': - yield (0, deposit_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case 'withdraw': - yield (0, withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case 'confirm-withdrawal': - yield (0, confirm_withdrawal_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "help": - (0, help_1.default)(); - break; + .filter((arg) => arg.startsWith("l2-rpc-url")) + .map((arg) => arg.split("=")[1])[0]); + if (helpFlag) { + switch (option) { + case "create": + (0, create_1.help)(); + break; + case "deposit": + (0, deposit_1.help)(); + break; + case "withdraw": + (0, withdraw_1.help)(); + break; + case "confirm-withdrawal": + (0, confirm_withdrawal_1.help)(); + break; + default: + (0, help_1.default)(); + break; + } + } + else { + switch (option) { + case "create": + // arg 3 is the project name + const projectName = process.argv[3] || "."; + yield (0, create_1.default)(projectName, zeekFlag); + break; + case "deposit": + yield (0, deposit_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "withdraw": + yield (0, withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "confirm-withdrawal": + yield (0, confirm_withdrawal_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "help": + (0, help_1.default)(); + break; + } } if (zeekFlag) { yield (0, zeek_1.default)(); diff --git a/src/confirm-withdrawal.ts b/src/confirm-withdrawal.ts index 1053d618..83e3eab3 100644 --- a/src/confirm-withdrawal.ts +++ b/src/confirm-withdrawal.ts @@ -4,6 +4,21 @@ import chalk from 'chalk'; import inquirer, { Answers, QuestionCollection } from 'inquirer'; import { track } from './analytics'; +// Used for `zksync-cli confirm-withdrawal --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli confirm-withdrawal --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Confirms the withdrawal of funds from zkSync to L1. The command will ask for the network, the zkSync transaction address, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { track("confirm-withdrawal", {zeek, network: "goerli"}); diff --git a/src/create.ts b/src/create.ts index c2c3e490..430cc89b 100644 --- a/src/create.ts +++ b/src/create.ts @@ -17,6 +17,16 @@ const runCommand = (command: string) => { return true; }; +// Used for `zksync-cli create --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli create \n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Creates a new Hardhat project in the provided folder. If no folder is specified, it will create the project in the current folder, provided it's empty.\n` + ); +} + export default async function (projectName: string, zeek?: boolean) { track("create", {zeek, network: "goerli"}) diff --git a/src/deposit.ts b/src/deposit.ts index 89200524..04d04026 100644 --- a/src/deposit.ts +++ b/src/deposit.ts @@ -5,6 +5,21 @@ import chalk from "chalk"; import inquirer, { Answers, QuestionCollection } from "inquirer"; import { track } from "./analytics"; +// Used for `zksync-cli deposit --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli deposit --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Deposits funds from L1 to L2. The command will ask for the network, the recipient's address, the amount in ETH, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { track("deposit", {zeek, network: "goerli"}); diff --git a/src/index.ts b/src/index.ts index 9b146c6a..cc5f4e8f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,25 +1,32 @@ #! /usr/bin/env node -import chalk from 'chalk'; +import chalk from "chalk"; // @ts-ignore // const figlet = require('figlet'); -import figlet from 'figlet'; +import figlet from "figlet"; // import method to create projects -import create from './create'; -import deposit from './deposit'; -import withdraw from './withdraw'; -import help from './help'; -import confirmWithdrawal from './confirm-withdrawal'; -import zeek from './zeek'; +import create, { help as createHelp } from "./create"; +import deposit, { help as depositHelp } from "./deposit"; +import withdraw, { help as withdrawHelp } from "./withdraw"; +import confirmWithdrawal, { help as confirmWithdrawalHelp } from "./confirm-withdrawal"; +import zeek from "./zeek"; +import help from "./help"; -const availableOptions: string[] = ['create', 'deposit', 'withdraw', 'confirm-withdrawal', 'help']; +const availableOptions: string[] = [ + "create", + "deposit", + "withdraw", + "confirm-withdrawal", + "help", +]; // second argument should be the selected option const option: string = process.argv[2]; -const main = async() => { +const main = async () => { + const helpFlag = Boolean(process.argv.filter((arg) => arg === "--help")[0]); if (!availableOptions.includes(option)) { console.log( `Invalid operation. Available operations are: ${availableOptions}` @@ -31,43 +38,67 @@ const main = async() => { console.log( chalk.magentaBright( - figlet.textSync(`zkSync ${option}`, { horizontalLayout: 'full' }) + figlet.textSync(`zkSync ${option}`, { horizontalLayout: "full" }) ) ); - const zeekFlag = Boolean(process.argv.filter(arg => arg === "--zeek")[0]); - const l1RpcUrl = String(process.argv - .filter(arg => arg.startsWith("l1-rpc-url")) - .map(arg => arg.split('=')[1])[0]); - const l2RpcUrl = String(process.argv - .filter(arg => arg.startsWith("l2-rpc-url")) - .map(arg => arg.split('=')[1])[0]); + const zeekFlag = Boolean(process.argv.filter((arg) => arg === "--zeek")[0]); + const l1RpcUrl = String( + process.argv + .filter((arg) => arg.startsWith("l1-rpc-url")) + .map((arg) => arg.split("=")[1])[0] + ); + const l2RpcUrl = String( + process.argv + .filter((arg) => arg.startsWith("l2-rpc-url")) + .map((arg) => arg.split("=")[1])[0] + ); - switch (option) { - case 'create': - // arg 3 is the project name - const projectName = process.argv[3] || '.'; - await create(projectName, zeekFlag); - break; - case 'deposit': - await deposit(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case 'withdraw': - await withdraw(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case 'confirm-withdrawal': - await confirmWithdrawal(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "help": - help(); - break; + if (helpFlag) { + switch (option) { + case "create": + createHelp(); + break; + case "deposit": + depositHelp(); + break; + case "withdraw": + withdrawHelp(); + break; + case "confirm-withdrawal": + confirmWithdrawalHelp(); + break; + default: + help(); + break; + } + } else { + switch (option) { + case "create": + // arg 3 is the project name + const projectName = process.argv[3] || "."; + await create(projectName, zeekFlag); + break; + case "deposit": + await deposit(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "withdraw": + await withdraw(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "confirm-withdrawal": + await confirmWithdrawal(zeekFlag, l1RpcUrl, l2RpcUrl); + break; + case "help": + help(); + break; + } } - if(zeekFlag) { + if (zeekFlag) { await zeek(); } process.exit(0); -} +}; main(); diff --git a/src/withdraw.ts b/src/withdraw.ts index 8eb62b1a..e32d9738 100644 --- a/src/withdraw.ts +++ b/src/withdraw.ts @@ -4,6 +4,21 @@ import chalk from 'chalk'; import inquirer, { Answers, QuestionCollection } from 'inquirer'; import { track } from './analytics'; +// Used for `zksync-cli withdraw --help` +export const help = () => { + console.log(chalk.bold("Usage:")); + console.log("zksync-cli withdraw --l1-rpc-url= --l2-rpc-url=\n"); + console.log(chalk.bold(`Description:`)); + console.log( + `Withdraws funds from L2 to L1. The command will ask for the network, the recipient's address, the amount in ETH, and the sender's private key.\n` + ); + console.log(chalk.bold(`Options:`)); + console.log(chalk.greenBright(`--l1-rpc-url=`)); + console.log(`The URL of the L1 RPC provider.\n`); + console.log(chalk.greenBright(`--l2-rpc-url=`)); + console.log(`The URL of the L2 RPC provider.\n`); +} + export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { track("withdraw", {zeek, network: "goerli"}) From 65489d325f48c484005f1c3a47a92284d4207e56 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 27 Jul 2023 12:00:43 -0500 Subject: [PATCH 2/3] Update src/index.ts Co-authored-by: Nicolas Villanueva --- src/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.ts b/src/index.ts index c0a018ff..2e097b50 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,7 +26,7 @@ const availableOptions: string[] = [ const option: string = process.argv[2]; const main = async () => { - const helpFlag = Boolean(process.argv.filter((arg) => arg === "--help")[0]); + const helpFlag = Boolean(process.argv.filter((arg) => ["--help", "-h"].includes(arg))[0]); if (!availableOptions.includes(option)) { console.log( `Invalid operation. Available operations are: ${availableOptions}` From d071d626627c522c4c850418e376575cfa3f6dd6 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 27 Jul 2023 12:06:32 -0500 Subject: [PATCH 3/3] chore: make requested changes --- .gitignore | 1 + bin/index.js | 119 ------------------------------------------------ src/deposit.ts | 2 - src/withdraw.ts | 2 - 4 files changed, 1 insertion(+), 123 deletions(-) delete mode 100755 bin/index.js diff --git a/.gitignore b/.gitignore index ac32d116..5e974217 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ artifacts bin bin/ +bin/*.js \ No newline at end of file diff --git a/bin/index.js b/bin/index.js deleted file mode 100755 index 237d3726..00000000 --- a/bin/index.js +++ /dev/null @@ -1,119 +0,0 @@ -#! /usr/bin/env node -"use strict"; -var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - var desc = Object.getOwnPropertyDescriptor(m, k); - if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { - desc = { enumerable: true, get: function() { return m[k]; } }; - } - Object.defineProperty(o, k2, desc); -}) : (function(o, m, k, k2) { - if (k2 === undefined) k2 = k; - o[k2] = m[k]; -})); -var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { - Object.defineProperty(o, "default", { enumerable: true, value: v }); -}) : function(o, v) { - o["default"] = v; -}); -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); - __setModuleDefault(result, mod); - return result; -}; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const chalk_1 = __importDefault(require("chalk")); -// @ts-ignore -// const figlet = require('figlet'); -const figlet_1 = __importDefault(require("figlet")); -// import method to create projects -const create_1 = __importStar(require("./create")); -const deposit_1 = __importStar(require("./deposit")); -const withdraw_1 = __importStar(require("./withdraw")); -const confirm_withdraw_1 = __importStar(require("./confirm-withdraw")); -const zeek_1 = __importDefault(require("./zeek")); -const help_1 = __importDefault(require("./help")); -const availableOptions = [ - "create", - "deposit", - "withdraw", - "confirm-withdraw", - "help", -]; -// second argument should be the selected option -const option = process.argv[2]; -const main = () => __awaiter(void 0, void 0, void 0, function* () { - const helpFlag = Boolean(process.argv.filter((arg) => arg === "--help")[0]); - if (!availableOptions.includes(option)) { - console.log(`Invalid operation. Available operations are: ${availableOptions}`); - process.exit(-1); - } - // Starts CLI - console.log(chalk_1.default.magentaBright(figlet_1.default.textSync(`zkSync ${option}`, { horizontalLayout: "full" }))); - const zeekFlag = Boolean(process.argv.filter((arg) => arg === "--zeek")[0]); - const l1RpcUrl = String(process.argv - .filter((arg) => arg.startsWith("l1-rpc-url")) - .map((arg) => arg.split("=")[1])[0]); - const l2RpcUrl = String(process.argv - .filter((arg) => arg.startsWith("l2-rpc-url")) - .map((arg) => arg.split("=")[1])[0]); - if (helpFlag) { - switch (option) { - case "create": - (0, create_1.help)(); - break; - case "deposit": - (0, deposit_1.help)(); - break; - case "withdraw": - (0, withdraw_1.help)(); - break; - case "confirm-withdraw": - (0, confirm_withdraw_1.help)(); - break; - default: - (0, help_1.default)(); - break; - } - } - else { - switch (option) { - case "create": - // arg 3 is the project name - const projectName = process.argv[3] || "."; - yield (0, create_1.default)(projectName, zeekFlag); - break; - case "deposit": - yield (0, deposit_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "withdraw": - yield (0, withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "confirm-withdraw": - yield (0, confirm_withdraw_1.default)(zeekFlag, l1RpcUrl, l2RpcUrl); - break; - case "help": - (0, help_1.default)(); - break; - } - } - if (zeekFlag) { - yield (0, zeek_1.default)(); - } - process.exit(0); -}); -main(); diff --git a/src/deposit.ts b/src/deposit.ts index b6eb83c2..fe68e4fa 100644 --- a/src/deposit.ts +++ b/src/deposit.ts @@ -22,8 +22,6 @@ export const help = () => { export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { - track("deposit", {zeek, network: "goerli"}); - console.log(chalk.magentaBright("Deposit funds from L1 to zkSync")); const questions: QuestionCollection = [ diff --git a/src/withdraw.ts b/src/withdraw.ts index ff14fed0..f96307a0 100644 --- a/src/withdraw.ts +++ b/src/withdraw.ts @@ -21,8 +21,6 @@ export const help = () => { export default async function (zeek?: boolean, l1RpcUrl?: string, l2RpcUrl?: string) { - track("withdraw", {zeek, network: "goerli"}) - console.log(chalk.magentaBright('Withdraw funds from zkSync to Goerli')); const questions: QuestionCollection = [