From f92989606f4c3b0e9767d4bf42b29a1d67bfbdde Mon Sep 17 00:00:00 2001 From: Praveen Ravichandran Date: Sat, 19 Feb 2022 15:17:49 -0500 Subject: [PATCH] Convert cli params to env vars --- package-lock.json | 226 +-------------------------------------------- package.json | 3 +- src/utils/flags.ts | 48 ++++------ 3 files changed, 20 insertions(+), 257 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4b7c760..ae06fb6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,8 +13,7 @@ "bignumber.js": "^9.0.2", "puppeteer": "^13.3.2", "redis": "^4.0.2", - "web3": "^1.7.0", - "yargs": "^17.3.1" + "web3": "^1.7.0" }, "devDependencies": { "@types/node": "^17.0.10", @@ -555,26 +554,6 @@ "url": "https://github.com/sponsors/epoberezkin" } }, - "node_modules/ansi-regex": { - "version": "5.0.1", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, - "node_modules/ansi-styles": { - "version": "4.3.0", - "license": "MIT", - "dependencies": { - "color-convert": "^2.0.1" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/chalk/ansi-styles?sponsor=1" - } - }, "node_modules/array-flatten": { "version": "1.1.1", "license": "MIT" @@ -960,15 +939,6 @@ "version": "1.1.0", "license": "MIT" }, - "node_modules/cliui": { - "version": "7.0.4", - "license": "ISC", - "dependencies": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, "node_modules/clone-response": { "version": "1.0.2", "license": "MIT", @@ -983,20 +953,6 @@ "node": ">=0.10.0" } }, - "node_modules/color-convert": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "color-name": "~1.1.4" - }, - "engines": { - "node": ">=7.0.0" - } - }, - "node_modules/color-name": { - "version": "1.1.4", - "license": "MIT" - }, "node_modules/combined-stream": { "version": "1.0.8", "license": "MIT", @@ -1269,10 +1225,6 @@ "minimalistic-crypto-utils": "^1.0.1" } }, - "node_modules/emoji-regex": { - "version": "8.0.0", - "license": "MIT" - }, "node_modules/encodeurl": { "version": "1.0.2", "license": "MIT", @@ -1360,13 +1312,6 @@ "ext": "^1.1.2" } }, - "node_modules/escalade": { - "version": "3.1.1", - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/escape-html": { "version": "1.0.3", "license": "MIT" @@ -1740,13 +1685,6 @@ "node": ">= 4" } }, - "node_modules/get-caller-file": { - "version": "2.0.5", - "license": "ISC", - "engines": { - "node": "6.* || 8.* || >= 10.*" - } - }, "node_modules/get-intrinsic": { "version": "1.1.1", "license": "MIT", @@ -2148,13 +2086,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-fullwidth-code-point": { - "version": "3.0.0", - "license": "MIT", - "engines": { - "node": ">=8" - } - }, "node_modules/is-function": { "version": "1.0.2", "license": "MIT" @@ -3138,13 +3069,6 @@ "node": ">=0.6" } }, - "node_modules/require-directory": { - "version": "2.1.1", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/responselike": { "version": "1.0.2", "license": "MIT", @@ -3382,18 +3306,6 @@ "safe-buffer": "~5.2.0" } }, - "node_modules/string-width": { - "version": "4.2.3", - "license": "MIT", - "dependencies": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/string.prototype.trimend": { "version": "1.0.4", "license": "MIT", @@ -3416,16 +3328,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/strip-ansi": { - "version": "6.0.1", - "license": "MIT", - "dependencies": { - "ansi-regex": "^5.0.1" - }, - "engines": { - "node": ">=8" - } - }, "node_modules/strip-hex-prefix": { "version": "1.0.0", "license": "MIT", @@ -4164,21 +4066,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/wrap-ansi": { - "version": "7.0.0", - "license": "MIT", - "dependencies": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/chalk/wrap-ansi?sponsor=1" - } - }, "node_modules/wrappy": { "version": "1.0.2", "license": "ISC" @@ -4240,13 +4127,6 @@ "node": ">=0.4" } }, - "node_modules/y18n": { - "version": "5.0.8", - "license": "ISC", - "engines": { - "node": ">=10" - } - }, "node_modules/yaeti": { "version": "0.0.6", "license": "MIT", @@ -4258,29 +4138,6 @@ "version": "3.1.1", "license": "ISC" }, - "node_modules/yargs": { - "version": "17.3.1", - "license": "MIT", - "dependencies": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.0.0" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/yargs-parser": { - "version": "21.0.0", - "license": "ISC", - "engines": { - "node": ">=12" - } - }, "node_modules/yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", @@ -4583,15 +4440,6 @@ "uri-js": "^4.2.2" } }, - "ansi-regex": { - "version": "5.0.1" - }, - "ansi-styles": { - "version": "4.3.0", - "requires": { - "color-convert": "^2.0.1" - } - }, "array-flatten": { "version": "1.1.1" }, @@ -4866,14 +4714,6 @@ "class-is": { "version": "1.1.0" }, - "cliui": { - "version": "7.0.4", - "requires": { - "string-width": "^4.2.0", - "strip-ansi": "^6.0.0", - "wrap-ansi": "^7.0.0" - } - }, "clone-response": { "version": "1.0.2", "requires": { @@ -4883,15 +4723,6 @@ "cluster-key-slot": { "version": "1.1.0" }, - "color-convert": { - "version": "2.0.1", - "requires": { - "color-name": "~1.1.4" - } - }, - "color-name": { - "version": "1.1.4" - }, "combined-stream": { "version": "1.0.8", "requires": { @@ -5092,9 +4923,6 @@ "minimalistic-crypto-utils": "^1.0.1" } }, - "emoji-regex": { - "version": "8.0.0" - }, "encodeurl": { "version": "1.0.2" }, @@ -5160,9 +4988,6 @@ "ext": "^1.1.2" } }, - "escalade": { - "version": "3.1.1" - }, "escape-html": { "version": "1.0.3" }, @@ -5436,9 +5261,6 @@ "generic-pool": { "version": "3.8.2" }, - "get-caller-file": { - "version": "2.0.5" - }, "get-intrinsic": { "version": "1.1.1", "requires": { @@ -5679,9 +5501,6 @@ "has-tostringtag": "^1.0.0" } }, - "is-fullwidth-code-point": { - "version": "3.0.0" - }, "is-function": { "version": "1.0.2" }, @@ -6291,9 +6110,6 @@ } } }, - "require-directory": { - "version": "2.1.1" - }, "responselike": { "version": "1.0.2", "requires": { @@ -6443,14 +6259,6 @@ "safe-buffer": "~5.2.0" } }, - "string-width": { - "version": "4.2.3", - "requires": { - "emoji-regex": "^8.0.0", - "is-fullwidth-code-point": "^3.0.0", - "strip-ansi": "^6.0.1" - } - }, "string.prototype.trimend": { "version": "1.0.4", "requires": { @@ -6465,12 +6273,6 @@ "define-properties": "^1.1.3" } }, - "strip-ansi": { - "version": "6.0.1", - "requires": { - "ansi-regex": "^5.0.1" - } - }, "strip-hex-prefix": { "version": "1.0.0", "requires": { @@ -6986,14 +6788,6 @@ "is-typed-array": "^1.1.7" } }, - "wrap-ansi": { - "version": "7.0.0", - "requires": { - "ansi-styles": "^4.0.0", - "string-width": "^4.1.0", - "strip-ansi": "^6.0.0" - } - }, "wrappy": { "version": "1.0.2" }, @@ -7046,30 +6840,12 @@ "xtend": { "version": "4.0.2" }, - "y18n": { - "version": "5.0.8" - }, "yaeti": { "version": "0.0.6" }, "yallist": { "version": "3.1.1" }, - "yargs": { - "version": "17.3.1", - "requires": { - "cliui": "^7.0.2", - "escalade": "^3.1.1", - "get-caller-file": "^2.0.5", - "require-directory": "^2.1.1", - "string-width": "^4.2.3", - "y18n": "^5.0.5", - "yargs-parser": "^21.0.0" - } - }, - "yargs-parser": { - "version": "21.0.0" - }, "yauzl": { "version": "2.10.0", "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz", diff --git a/package.json b/package.json index 451e501..7d0f901 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,7 @@ "bignumber.js": "^9.0.2", "puppeteer": "^13.3.2", "redis": "^4.0.2", - "web3": "^1.7.0", - "yargs": "^17.3.1" + "web3": "^1.7.0" }, "devDependencies": { "@types/node": "^17.0.10", diff --git a/src/utils/flags.ts b/src/utils/flags.ts index 253c277..49542b0 100644 --- a/src/utils/flags.ts +++ b/src/utils/flags.ts @@ -1,30 +1,18 @@ -import yargs from "yargs/yargs"; - -/** - * Args is a map of all the command line arguments received - */ -export const Args: any = yargs(process.argv.slice(2)).options({ - publicKey: { type: "string", demandOption: true }, - privateKey: { type: "string", demandOption: true }, - mode: { type: "string", default: "MANUAL", demandOption: true }, - chatId: { type: "string", demandOption: false }, - chartInterval: { type: "string", default: "1h", demandOption: true }, - stableToken: { type: "string", default: "USDC", demandOption: true }, - targetToken: { type: "string", default: "WMATIC", demandOption: true }, - stableTokenTickerKraken: { - type: "string", - default: "USDCUSD", - demandOption: true, - }, - targetTokenTickerKraken: { - type: "string", - default: "MATICUSD", - demandOption: true, - }, - botToken: { type: "string", demandOption: true }, - password: { type: "string", default: "kryptonite", demandOption: true }, - redisAddress: { type: "string", demandOption: true }, - chainId: { type: "number", default: 137, demandOption: true }, - minProfitPercent: { type: "number", default: 1, demandOption: true }, - slippagePercent: { type: "number", default: 1, demandOption: true }, -}).argv; +let ENV: any = process.env; +export const Args = { + publicKey: ENV.PUBLIC_KEY || "", + privateKey: ENV.PRIVATE_KEY || "", + mode: ENV.MODE || "MANUAL", + chatId: ENV.CHAT_ID || "", + chartInterval: ENV.CHART_INTERVAL || "1h", + stableToken: ENV.STABLE_TOKEN || "USDC", + targetToken: ENV.TARGET_TOKEN || "WMATIC", + stableTokenTickerKraken: ENV.STABLE_TOKEN_TICKER_KRAKEN || "USDCUSD", + targetTokenTickerKraken: ENV.TARGET_TOKEN_TICKER_KRAKEN || "MATICUSD", + botToken: ENV.BOT_TOKEN || "", + password: ENV.PASSWORD || "kryptonite", + redisAddress: ENV.REDIS_ADDRESS || "", + chainId: Number(ENV.CHAIN_ID || 137), + minProfitPercent: Number(ENV.MIN_PROFIT_PERCENT || 1), + slippagePercent: Number(ENV.SLIPPAGE_PERCENT || 1), +};