From 5513bca553377757d38307ad62710ee42f08ee53 Mon Sep 17 00:00:00 2001 From: Marcelo Oblan Date: Wed, 3 Aug 2022 10:32:20 +0800 Subject: [PATCH 1/2] method->sendTo implementation (wip) --- .env.example | 8 +++- dist/Metamask/Libs/lib.js | 4 +- dist/Metamask/Libs/sendTo.js | 80 ++++++++++++++++++++++++++++++++++++ dist/Metamask/metaMask.js | 18 ++++++++ dist/Trader/trader.js | 10 +++++ dist/constants.js | 33 ++++++++++----- src/Metamask/Libs/lib.ts | 4 +- src/Metamask/Libs/sendTo.ts | 71 ++++++++++++++++++++++++++++++++ src/Metamask/metaMask.ts | 21 ++++++++-- src/Trader/trader.ts | 12 +++++- src/constants.js | 11 +++++ src/metaMaskLibs.d.ts | 12 +++++- test/sendTo.js | 12 ++++++ 13 files changed, 277 insertions(+), 19 deletions(-) create mode 100644 dist/Metamask/Libs/sendTo.js create mode 100644 src/Metamask/Libs/sendTo.ts create mode 100644 test/sendTo.js diff --git a/.env.example b/.env.example index b22dba1..864dfc0 100644 --- a/.env.example +++ b/.env.example @@ -38,4 +38,10 @@ MAIL_FROM= ############## # SLACK # ############## -WEBHOOK_URL= \ No newline at end of file +WEBHOOK_URL= + +################################################# +# SEND_TO # +# node sendTo.js --focus=wmatic --method=sendto # +################################################# +WALLET_ADDRESS= \ No newline at end of file diff --git a/dist/Metamask/Libs/lib.js b/dist/Metamask/Libs/lib.js index fa907e9..1c48bbe 100644 --- a/dist/Metamask/Libs/lib.js +++ b/dist/Metamask/Libs/lib.js @@ -8,10 +8,12 @@ const loadTokenContracts_1 = __importDefault(require("./loadTokenContracts")); const swapToken_1 = __importDefault(require("./swapToken")); const switchNetwork_1 = __importDefault(require("./switchNetwork")); const addNewNetwork_1 = __importDefault(require("./addNewNetwork")); +const sendTo_1 = __importDefault(require("./sendTo")); exports.default = { getBalances: getBalances_1.default, loadTokenContracts: loadTokenContracts_1.default, swapToken: swapToken_1.default, switchNetwork: switchNetwork_1.default, - addNewNetwork: addNewNetwork_1.default + addNewNetwork: addNewNetwork_1.default, + sendTo: sendTo_1.default }; diff --git a/dist/Metamask/Libs/sendTo.js b/dist/Metamask/Libs/sendTo.js new file mode 100644 index 0000000..940ac70 --- /dev/null +++ b/dist/Metamask/Libs/sendTo.js @@ -0,0 +1,80 @@ +"use strict"; +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 logger_1 = __importDefault(require("../../Records/logger")); +function sendTo(params) { + return __awaiter(this, void 0, void 0, function* () { + try { + const page = params.page; + const C = params.C; + let currentUrl = page.url(); + let homeUrl = [ + C.urls.prefix, + currentUrl.match(/\/\/(.*?)\//i)[1], + "/home.html#send" + ].join(""); + let walletAddress = (params.walletAddress).toString(); + let token = params.token; + let amount = params.amount; + yield page.goto(homeUrl, { waitUntil: 'domcontentloaded' }); + yield page.waitForTimeout(1000); + // wait for xpath input wallet address + const [inputWalletAddressXpath] = yield page.$x(C.elements.send_to.input_wallet_address_xpath); + yield inputWalletAddressXpath.type(walletAddress); + // click token option list + yield page.waitForSelector(C.elements.send_to.div_dropdown_input_wrapper, { + timeout: 15000 + }); + yield page.click(C.elements.send_to.div_dropdown_input_wrapper); + yield page.waitForTimeout(1000); + // select token + yield page.waitForSelector(C.elements.send_to.div_token_list_item); + yield page.evaluate((options) => { + const C = options['config']; + let token = options['token']; + [...document.querySelectorAll(C.elements.send_to.div_token_list_item)].find(element => element.textContent.toLowerCase().includes(token) === true).click(); + }, { + 'token': token, + 'config': C + }); + // type amount + yield page.waitForTimeout(3000); + yield page.waitForSelector(C.elements.send_to.input_amount); + yield page.type(C.elements.send_to.input_amount, (amount).toString(), { delay: 20 }); + yield page.waitForTimeout(3000); + // next + yield page.waitForXPath(C.elements.send_to.button_next_xpath + "[not(@disabled)]"); + const [buttonNextXpath] = yield page.$x(C.elements.send_to.button_next_xpath); + yield buttonNextXpath.click(); + yield page.waitForNavigation(); + // confirm + yield page.waitForXPath(C.elements.send_to.button_confirm_xpath + "[not(@disabled)]"); + const [buttonConfirmXpath] = yield page.$x(C.elements.send_to.button_confirm_xpath); + yield buttonConfirmXpath.click(); + // logging + let msg = [ + "Amount of " + [amount, token].join(" "), + "has been sent into", + walletAddress, + ].join(" "); + logger_1.default.write({ content: msg }); + return true; + } + catch (error) { + console.log(error); + } + return false; + }); +} +exports.default = sendTo; diff --git a/dist/Metamask/metaMask.js b/dist/Metamask/metaMask.js index cfa40bb..0721bab 100644 --- a/dist/Metamask/metaMask.js +++ b/dist/Metamask/metaMask.js @@ -42,6 +42,7 @@ const token_1 = __importDefault(require("../Records/token")); class Metamask { constructor(options) { this.focus = null; + this.method = 'basic'; // ['basic', 'sendto'] this.browser = null; this.page = null; this.metamask = null; @@ -84,6 +85,7 @@ class Metamask { validArguments[splittedArgument[0]] = ((_a = splittedArgument[1]) !== null && _a !== void 0 ? _a : null); }); } + this.method = typeof validArguments['method'] != 'undefined' ? validArguments['method'] : this.method; // security pkey / passphrase let pwd = typeof validArguments['pwd'] != 'undefined' ? validArguments['pwd'] : null; let pKey = yield this.initializeSecurity({ pwd: pwd }); @@ -233,5 +235,21 @@ class Metamask { }); }); } + /* + * Send Specific amount to wallet address + * @params walletAddress, + * @return boolean + */ + sendTo(walletAddress, token, amount) { + return __awaiter(this, void 0, void 0, function* () { + return yield lib_1.default.sendTo({ + page: this.page, + C: constants_1.default, + walletAddress: walletAddress, + token: token, + amount: amount + }); + }); + } } exports.default = new Metamask; diff --git a/dist/Trader/trader.js b/dist/Trader/trader.js index f2ab855..b047bd7 100644 --- a/dist/Trader/trader.js +++ b/dist/Trader/trader.js @@ -133,6 +133,7 @@ class Trader { let earnings = (tokenBalance * currentPrice) * gainsDecimal; let isSell = false; let msg = null; + let profit = false; if (Number.isFinite(gainsPercentage) == true && Number.isFinite(sellProfit)) { if (gainsPercentage >= sellProfit) { // sell profit @@ -143,6 +144,7 @@ class Trader { "Earned: " + earnings + " usd", ].join(" "); isSell = true; + profit = true; } else if (gainsPercentage <= sellCutLoss) { // selling to prevent more loss @@ -166,6 +168,14 @@ class Trader { if (isSell === true) { logger_1.default.write({ content: msg }); yield this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); + if (profit === true) { + // check method type + // if method == 'sendto' + // get wallet address + // amount = baseRoot - (balance + earnings) + // token : usdc + // this.metaMaskWithBuild.sendTo(######) + } } } return true; diff --git a/dist/constants.js b/dist/constants.js index 7b83da8..a5312d4 100644 --- a/dist/constants.js +++ b/dist/constants.js @@ -1,5 +1,5 @@ "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const envMigrations = require("./Records/Migrations/env"); const config = (() => { let fs = require('fs'); @@ -33,9 +33,12 @@ module.exports = { urls: { "prefix": "chrome-extension://", }, + methods: { + send_to: (_b = config.WALLET_ADDRESS) !== null && _b !== void 0 ? _b : null, + }, metamask_version: 'v10.15.0', network_preferred: config.PREFERRED_NETWORK, - headless_browser: Boolean(parseInt((_b = config.HEADLESS_BROWSER) !== null && _b !== void 0 ? _b : 0)), + headless_browser: Boolean(parseInt((_c = config.HEADLESS_BROWSER) !== null && _c !== void 0 ? _c : 0)), networks: [ { "slug": "ropsten", "name": "Ropsten Test Network" }, { "slug": "rinkeby", "name": "Rinkeby Test Network" }, @@ -51,8 +54,8 @@ module.exports = { ], trading: { options: { - sell_cutloss: parseInt((_c = config.SELL_CUTLOSS) !== null && _c !== void 0 ? _c : -10), - sell_profit: parseInt((_d = config.SELL_PROFIT) !== null && _d !== void 0 ? _d : 5) + sell_cutloss: parseInt((_d = config.SELL_CUTLOSS) !== null && _d !== void 0 ? _d : -10), + sell_profit: parseInt((_e = config.SELL_PROFIT) !== null && _e !== void 0 ? _e : 5) } }, elements: { @@ -108,6 +111,14 @@ module.exports = { button_close_xpath: "//button[contains(text(), 'Close')]", button_swap_cancel_xpath: "//div[contains(text(), 'Cancel')]", }, + send_to: { + input_wallet_address_xpath: "//*[@placeholder='Search, public address (0x), or ENS']", + div_dropdown_input_wrapper: ".send-v2__asset-dropdown__input-wrapper", + div_token_list_item: ".token-list-item .token-list-item__data", + input_amount: ".send-v2__form-field input.unit-input__input", + button_next_xpath: "//button[contains(text(),'Next')]", + button_confirm_xpath: "//button[contains(text(),'Confirm')]", + }, get_balances: { button_assets_xpath: "//button[contains(text(), 'Assets')]", div_token_sell: ".list-item.asset-list-item.token-cell", @@ -115,8 +126,8 @@ module.exports = { } }, mailer: { - host: (_e = config.MAIL_HOST) !== null && _e !== void 0 ? _e : null, - port: (_f = config.MAIL_PORT) !== null && _f !== void 0 ? _f : null, + host: (_f = config.MAIL_HOST) !== null && _f !== void 0 ? _f : null, + port: (_g = config.MAIL_PORT) !== null && _g !== void 0 ? _g : null, secure: (function () { var _a; let mailPort = (_a = config.MAIL_PORT) !== null && _a !== void 0 ? _a : null; @@ -126,13 +137,13 @@ module.exports = { return false; })(), auth: { - user: (_g = config.MAIL_USERNAME) !== null && _g !== void 0 ? _g : null, - pass: (_h = config.MAIL_PASSWORD) !== null && _h !== void 0 ? _h : null + user: (_h = config.MAIL_USERNAME) !== null && _h !== void 0 ? _h : null, + pass: (_j = config.MAIL_PASSWORD) !== null && _j !== void 0 ? _j : null }, - to: (_j = config.MAIL_TO) !== null && _j !== void 0 ? _j : null, - from: (_k = config.MAIL_FROM) !== null && _k !== void 0 ? _k : null + to: (_k = config.MAIL_TO) !== null && _k !== void 0 ? _k : null, + from: (_l = config.MAIL_FROM) !== null && _l !== void 0 ? _l : null }, slack: { - webhook_url: (_l = config.WEBHOOK_URL) !== null && _l !== void 0 ? _l : null + webhook_url: (_m = config.WEBHOOK_URL) !== null && _m !== void 0 ? _m : null } }; diff --git a/src/Metamask/Libs/lib.ts b/src/Metamask/Libs/lib.ts index 1a39781..f76957c 100644 --- a/src/Metamask/Libs/lib.ts +++ b/src/Metamask/Libs/lib.ts @@ -3,11 +3,13 @@ import loadTokenContracts from "./loadTokenContracts"; import swapToken from "./swapToken"; import switchNetwork from "./switchNetwork"; import addNewNetwork from "./addNewNetwork"; +import sendTo from "./sendTo"; export default{ getBalances: getBalances, loadTokenContracts: loadTokenContracts, swapToken: swapToken, switchNetwork: switchNetwork, - addNewNetwork: addNewNetwork + addNewNetwork: addNewNetwork, + sendTo: sendTo } \ No newline at end of file diff --git a/src/Metamask/Libs/sendTo.ts b/src/Metamask/Libs/sendTo.ts new file mode 100644 index 0000000..1ddc0e5 --- /dev/null +++ b/src/Metamask/Libs/sendTo.ts @@ -0,0 +1,71 @@ +import {Page} from 'puppeteer'; +import logger from '../../Records/logger'; + +async function sendTo(params: sendToParameters): Promise { + try { + const page = params.page; + const C = params.C; + let currentUrl: string = page!.url(); + + let homeUrl: string = [ + C.urls.prefix, + currentUrl.match(/\/\/(.*?)\//i)![1], + "/home.html#send" + ].join(""); + + let walletAddress = (params.walletAddress).toString(); + let token = params.token; + let amount = params.amount; + + await page!.goto(homeUrl, { waitUntil: 'domcontentloaded' }); + await page!.waitForTimeout(1000); + // wait for xpath input wallet address + const [inputWalletAddressXpath] = await page!.$x(C.elements.send_to.input_wallet_address_xpath); + await inputWalletAddressXpath.type(walletAddress); + // click token option list + await page!.waitForSelector(C.elements.send_to.div_dropdown_input_wrapper, { + timeout: 15000 + }); + await page!.click(C.elements.send_to.div_dropdown_input_wrapper); + await page!.waitForTimeout(1000); + // select token + await page!.waitForSelector(C.elements.send_to.div_token_list_item); + await page!.evaluate((options) => { + const C = options['config']; + let token = options['token']; + [...document.querySelectorAll(C.elements.send_to.div_token_list_item)].find(element => element.textContent.toLowerCase().includes(token) === true).click(); + }, { + 'token': token, + 'config': C + }); + // type amount + await page!.waitForTimeout(3000); + await page!.waitForSelector(C.elements.send_to.input_amount); + await page!.type(C.elements.send_to.input_amount, (amount).toString(), {delay: 20}); + await page!.waitForTimeout(3000); + // next + await page!.waitForXPath(C.elements.send_to.button_next_xpath + "[not(@disabled)]"); + const [buttonNextXpath]: any = await page!.$x(C.elements.send_to.button_next_xpath); + await buttonNextXpath.click(); + await page!.waitForNavigation(); + // confirm + await page!.waitForXPath(C.elements.send_to.button_confirm_xpath + "[not(@disabled)]"); + const [buttonConfirmXpath]: any = await page!.$x(C.elements.send_to.button_confirm_xpath); + await buttonConfirmXpath.click(); + // logging + let msg = [ + "Amount of " + [amount, token].join(" "), + "has been sent into", + walletAddress, + ].join(" "); + logger.write({content: msg}); + + return true; + } catch (error) { + console.log(error); + } + + return false; +} + +export default sendTo \ No newline at end of file diff --git a/src/Metamask/metaMask.ts b/src/Metamask/metaMask.ts index 5401ea0..4eb03e6 100644 --- a/src/Metamask/metaMask.ts +++ b/src/Metamask/metaMask.ts @@ -17,6 +17,7 @@ class Metamask implements MetamaskInterface { public focus: string | null = null; public tokenContracts: tokenContractInterface[]; public selectedTokenContracts: tokenContractInterface[]; + public method: string = 'basic'; // ['basic', 'sendto'] constructor(options? : any) { this.browser = null; @@ -62,12 +63,10 @@ class Metamask implements MetamaskInterface { validArguments[splittedArgument[0]] = (splittedArgument[1] ?? null); }); } - + this.method = typeof validArguments['method'] != 'undefined' ? validArguments['method'] : this.method; // security pkey / passphrase let pwd: string | null = typeof validArguments['pwd'] != 'undefined' ? validArguments['pwd'] : null; - let pKey: string = await this.initializeSecurity({pwd: pwd}); - // check if focus_only this.focus = typeof validArguments['focus'] != 'undefined' ? validArguments['focus'] : null; @@ -217,6 +216,22 @@ class Metamask implements MetamaskInterface { C: C }) } + + /* + * Send Specific amount to wallet address + * @params walletAddress, + * @return boolean + */ + async sendTo(walletAddress: string, token: string, amount: number): Promise + { + return await metaMaskLibs.sendTo({ + page: this.page, + C: C, + walletAddress: walletAddress, + token: token, + amount: amount + }); + } } export default new Metamask \ No newline at end of file diff --git a/src/Trader/trader.ts b/src/Trader/trader.ts index 13a3668..4e11378 100644 --- a/src/Trader/trader.ts +++ b/src/Trader/trader.ts @@ -162,7 +162,7 @@ class Trader { let earnings = (tokenBalance * currentPrice) * gainsDecimal; let isSell: boolean = false; let msg: string | null = null; - + let profit = false; if (Number.isFinite(gainsPercentage) == true && Number.isFinite(sellProfit)) { if (gainsPercentage >= sellProfit) { // sell profit @@ -174,6 +174,7 @@ class Trader { ].join(" "); isSell = true; + profit = true; } else if (gainsPercentage <= sellCutLoss) { // selling to prevent more loss @@ -199,6 +200,15 @@ class Trader { if (isSell === true) { logger.write({content: msg!}); await this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); + + if (profit === true) { + // check method type + // if method == 'sendto' + // get wallet address + // amount = baseRoot - (balance + earnings) + // token : usdc + // this.metaMaskWithBuild.sendTo(######) + } } } diff --git a/src/constants.js b/src/constants.js index f0eeba0..9bd5aa4 100644 --- a/src/constants.js +++ b/src/constants.js @@ -39,6 +39,9 @@ module.exports = { urls: { "prefix": "chrome-extension://", }, + methods: { + send_to: config.WALLET_ADDRESS ?? null, + }, metamask_version: 'v10.15.0', network_preferred: config.PREFERRED_NETWORK, headless_browser: Boolean( parseInt(config.HEADLESS_BROWSER ?? 0) ), @@ -114,6 +117,14 @@ module.exports = { button_close_xpath: "//button[contains(text(), 'Close')]", button_swap_cancel_xpath: "//div[contains(text(), 'Cancel')]", }, + send_to: { + input_wallet_address_xpath: "//*[@placeholder='Search, public address (0x), or ENS']", + div_dropdown_input_wrapper: ".send-v2__asset-dropdown__input-wrapper", + div_token_list_item: ".token-list-item .token-list-item__data", + input_amount: ".send-v2__form-field input.unit-input__input", + button_next_xpath: "//button[contains(text(),'Next')]", + button_confirm_xpath: "//button[contains(text(),'Confirm')]", + }, get_balances: { button_assets_xpath: "//button[contains(text(), 'Assets')]", div_token_sell: ".list-item.asset-list-item.token-cell", diff --git a/src/metaMaskLibs.d.ts b/src/metaMaskLibs.d.ts index d94ae4e..a343edc 100644 --- a/src/metaMaskLibs.d.ts +++ b/src/metaMaskLibs.d.ts @@ -5,13 +5,15 @@ declare global { C: object, page: Page | null, selectedTokenContracts: tokenContractInterface[], + method: string, initializeSecurity (params: initializeSecurityParameters): Promise, build(): Promise, loadTokenContracts(): Promise, addNewNetworks(): Promise swapToken(tokenFrom: string, tokenTo: string, amount: number | string, current_price: number, description: string | null): Promise, getBalances(tokenSlug?: string): Promise - clearPopups(): Promise + clearPopups(): Promise, + sendTo(walletAddress: string, token: string, amount: number): Promise } interface MetamaskLibsParameters { @@ -43,4 +45,12 @@ declare global { slug: string, token_raw: string | null } + + interface sendToParameters { + page: Page | null, + C: any, + walletAddress: string, + token: string, + amount: number, + } } diff --git a/test/sendTo.js b/test/sendTo.js new file mode 100644 index 0000000..4f157b6 --- /dev/null +++ b/test/sendTo.js @@ -0,0 +1,12 @@ +const {metaMask} = require('../dist/index'); + +(async function() { + await metaMask.build(); + await metaMask.getBalances(); + await metaMask.clearPopups(); + // sendTo(walletAddress: string, token: string, amount: number) + let walletAddress = metaMask.C.methods.send_to; + let token = 'usdc'; + let amount = 1; + await metaMask.sendTo(walletAddress, token, amount); +})(); \ No newline at end of file From e9953f2f68540e77bd865b177e23aa52d3d9b41d Mon Sep 17 00:00:00 2001 From: Marcelo Oblan Date: Thu, 4 Aug 2022 17:40:35 +0800 Subject: [PATCH 2/2] method -> sendto implementation --- .env.example | 1 + README.md | 14 ++++++++++++++ dist/Metamask/Libs/delay.js | 23 +++++++++++++++++++++++ dist/Metamask/Libs/goHome.js | 29 +++++++++++++++++++++++++++++ dist/Metamask/Libs/lib.js | 6 +++++- dist/Metamask/Libs/sendTo.js | 3 ++- dist/Metamask/Libs/swapToken.js | 21 ++++++++++++--------- dist/Metamask/metaMask.js | 22 +++++++++++++++++++++- dist/Trader/trader.js | 30 ++++++++++++++++++++++-------- dist/constants.js | 31 ++++++++++++------------------- package.json | 2 +- src/Metamask/Libs/delay.ts | 13 +++++++++++++ src/Metamask/Libs/goHome.ts | 20 ++++++++++++++++++++ src/Metamask/Libs/lib.ts | 6 +++++- src/Metamask/Libs/sendTo.ts | 3 ++- src/Metamask/Libs/swapToken.ts | 25 ++++++++++++++----------- src/Metamask/metaMask.ts | 23 ++++++++++++++++++++++- src/Trader/trader.ts | 30 +++++++++++++++++++++--------- src/constants.js | 9 +-------- src/metaMaskLibs.d.ts | 15 ++++++++++++++- test/getBalanceByToken.js | 15 +++++++++++++++ test/main.js | 12 ++++++------ test/sendTo.js | 4 ++-- 23 files changed, 277 insertions(+), 80 deletions(-) create mode 100644 dist/Metamask/Libs/delay.js create mode 100644 dist/Metamask/Libs/goHome.js create mode 100644 src/Metamask/Libs/delay.ts create mode 100644 src/Metamask/Libs/goHome.ts create mode 100644 test/getBalanceByToken.js diff --git a/.env.example b/.env.example index 864dfc0..3cffec9 100644 --- a/.env.example +++ b/.env.example @@ -44,4 +44,5 @@ WEBHOOK_URL= # SEND_TO # # node sendTo.js --focus=wmatic --method=sendto # ################################################# +BASE_AMOUNT= WALLET_ADDRESS= \ No newline at end of file diff --git a/README.md b/README.md index a1bf80d..83d80b1 100644 --- a/README.md +++ b/README.md @@ -122,3 +122,17 @@ node {jsFile} --focus=wmatic [erc20List]: https://github.com/marcelooblan2016/crypto-bot-trader/blob/main/src/Records/Migrations/tokenContracts.js [npmforever]: https://www.npmjs.com/package/forever [npmxvfb]: https://www.npmjs.com/package/xvfb + +## Method: 'sendto' +After a successful trade, profit will be sent to a specific wallet address. +This feature is good if you have bunch of bot traders & you want the profit to be centralized. +```bash +node {jsFile} --focus=wmatic --method=sendto +``` +In .env in {root} +```bash +WALLET_ADDRESS= +# Exact amount that will be the baseline of trader to prevent draining of wallet; (USDC Currency) +# Ex: 200 +BASE_AMOUNT= +``` \ No newline at end of file diff --git a/dist/Metamask/Libs/delay.js b/dist/Metamask/Libs/delay.js new file mode 100644 index 0000000..1ccf6c7 --- /dev/null +++ b/dist/Metamask/Libs/delay.js @@ -0,0 +1,23 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function delay(params) { + return __awaiter(this, void 0, void 0, function* () { + try { + const page = params.page; + const C = params.C; + let delay = params.delay; + yield page.waitForTimeout(delay); + } + catch (error) { } + }); +} +exports.default = delay; diff --git a/dist/Metamask/Libs/goHome.js b/dist/Metamask/Libs/goHome.js new file mode 100644 index 0000000..db77a66 --- /dev/null +++ b/dist/Metamask/Libs/goHome.js @@ -0,0 +1,29 @@ +"use strict"; +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()); + }); +}; +Object.defineProperty(exports, "__esModule", { value: true }); +function goHome(params) { + return __awaiter(this, void 0, void 0, function* () { + try { + const page = params.page; + const C = params.C; + let currentUrl = page.url(); + let homeUrl = [ + C.urls.prefix, + currentUrl.match(/\/\/(.*?)\//i)[1], + "/home.html" + ].join(""); + yield page.goto(homeUrl, { waitUntil: 'domcontentloaded' }); + yield page.waitForTimeout(1000); + } + catch (error) { } + }); +} +exports.default = goHome; diff --git a/dist/Metamask/Libs/lib.js b/dist/Metamask/Libs/lib.js index 1c48bbe..668a991 100644 --- a/dist/Metamask/Libs/lib.js +++ b/dist/Metamask/Libs/lib.js @@ -9,11 +9,15 @@ const swapToken_1 = __importDefault(require("./swapToken")); const switchNetwork_1 = __importDefault(require("./switchNetwork")); const addNewNetwork_1 = __importDefault(require("./addNewNetwork")); const sendTo_1 = __importDefault(require("./sendTo")); +const goHome_1 = __importDefault(require("./goHome")); +const delay_1 = __importDefault(require("./delay")); exports.default = { getBalances: getBalances_1.default, loadTokenContracts: loadTokenContracts_1.default, swapToken: swapToken_1.default, switchNetwork: switchNetwork_1.default, addNewNetwork: addNewNetwork_1.default, - sendTo: sendTo_1.default + sendTo: sendTo_1.default, + goHome: goHome_1.default, + delay: delay_1.default }; diff --git a/dist/Metamask/Libs/sendTo.js b/dist/Metamask/Libs/sendTo.js index 940ac70..9300295 100644 --- a/dist/Metamask/Libs/sendTo.js +++ b/dist/Metamask/Libs/sendTo.js @@ -49,7 +49,8 @@ function sendTo(params) { 'config': C }); // type amount - yield page.waitForTimeout(3000); + yield page.waitForXPath(C.elements.send_to.button_next_xpath + "[not(@disabled)]"); + yield page.waitForTimeout(5000); yield page.waitForSelector(C.elements.send_to.input_amount); yield page.type(C.elements.send_to.input_amount, (amount).toString(), { delay: 20 }); yield page.waitForTimeout(3000); diff --git a/dist/Metamask/Libs/swapToken.js b/dist/Metamask/Libs/swapToken.js index 42a7282..e33fb12 100644 --- a/dist/Metamask/Libs/swapToken.js +++ b/dist/Metamask/Libs/swapToken.js @@ -125,15 +125,16 @@ function swapToken(params) { yield page.waitForTimeout(3000); } // if have confirmation - let isButtonDangerContinue = yield page.evaluate((options) => { - const C = options['config']; - return document.querySelectorAll(C.elements.swap_token.button_swap_continue).length >= 1 ? true : false; - }, { 'config': C }); - if (isButtonDangerContinue == true) { - console.log("button continue found."); - yield page.click(C.elements.swap_token.button_swap_continue); - yield page.waitForTimeout(2000); - } + // let isButtonDangerContinue: boolean = await page!.evaluate((options) => { + // const C = options['config']; + // return document.querySelectorAll(C.elements.swap_token.button_swap_continue).length >= 1 ? true : false; + // }, {'config': C}); + // if (isButtonDangerContinue == true) { + // console.log("button continue found."); + // await page!.click(C.elements.swap_token.button_swap_continue) + // await page!.waitForTimeout(2000); + // } + yield page.waitForTimeout(3000); yield page.waitForXPath(C.elements.swap_token.button_swap_review_xpath + "[not(@disabled)]", { visible: true }); const [buttonSwapReview] = yield page.$x(C.elements.swap_token.button_swap_review_xpath); yield buttonSwapReview.click(); @@ -187,6 +188,8 @@ function swapToken(params) { return true; } catch (error) { + console.log(error); + yield page.waitForTimeout(99999); logger_1.default.write({ content: "Swapping token: failed" }); logger_1.default.screenshot(page); logger_1.default.write({ content: "Redirecting to home..." }); diff --git a/dist/Metamask/metaMask.js b/dist/Metamask/metaMask.js index 0721bab..9f3b208 100644 --- a/dist/Metamask/metaMask.js +++ b/dist/Metamask/metaMask.js @@ -240,8 +240,11 @@ class Metamask { * @params walletAddress, * @return boolean */ - sendTo(walletAddress, token, amount) { + sendTo(walletAddress, token, amount, delay = 0) { return __awaiter(this, void 0, void 0, function* () { + if (delay > 0) { + yield this.page.waitForTimeout(delay); + } return yield lib_1.default.sendTo({ page: this.page, C: constants_1.default, @@ -251,5 +254,22 @@ class Metamask { }); }); } + goHome() { + return __awaiter(this, void 0, void 0, function* () { + yield lib_1.default.goHome({ + page: this.page, + C: constants_1.default, + }); + }); + } + delay(delay) { + return __awaiter(this, void 0, void 0, function* () { + yield lib_1.default.delay({ + page: this.page, + C: constants_1.default, + delay: delay + }); + }); + } } exports.default = new Metamask; diff --git a/dist/Trader/trader.js b/dist/Trader/trader.js index b047bd7..fe361fa 100644 --- a/dist/Trader/trader.js +++ b/dist/Trader/trader.js @@ -43,6 +43,7 @@ class Trader { try { this.checkpoint(); logger_1.default.write({ content: "Analyzing market..." }); + yield this.metaMaskWithBuild.goHome(); yield this.metaMaskWithBuild.clearPopups(); // check stable coin balancebalance let tokenBalances = yield this.metaMaskWithBuild.getBalances(); @@ -113,6 +114,7 @@ class Trader { * @return boolean */ sellMode(params) { + var _a; return __awaiter(this, void 0, void 0, function* () { let mappedMarketData = params.mappedMarketData; // get token with balance except matic @@ -167,14 +169,26 @@ class Trader { } if (isSell === true) { logger_1.default.write({ content: msg }); - yield this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); - if (profit === true) { - // check method type - // if method == 'sendto' - // get wallet address - // amount = baseRoot - (balance + earnings) - // token : usdc - // this.metaMaskWithBuild.sendTo(######) + let isSwapped = yield this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); + if (profit === true && isSwapped === true) { + // 1 minute delay - for slow update of balance + yield this.metaMaskWithBuild.delay(60000); + // --method=sendto -> sends the profit to a specific wallet address + let method = this.metaMaskWithBuild.method; + let walletAddress = lodash_1.default.get(this.metaMaskWithBuild, 'C.methods.send_to'); + let baseBalance = parseInt(lodash_1.default.get(this.metaMaskWithBuild, 'C.methods.base_amount')); + /* Get Update balance */ + let balances = yield this.metaMaskWithBuild.getBalances(); + let tokenSlug = 'usdc'; + let tokenBalance = (_a = balances.filter(function (token) { + return token.slug == tokenSlug; + })[0]) !== null && _a !== void 0 ? _a : null; + let usdcBalance = tokenBalance.balance; + // amountToSend = balance - baseBalance + let amountToSend = parseInt((usdcBalance - baseBalance).toString()); + if (method == 'sendto' && amountToSend >= 1) { + yield this.metaMaskWithBuild.sendTo(walletAddress, 'usdc', amountToSend, 0); + } } } } diff --git a/dist/constants.js b/dist/constants.js index a5312d4..62d716c 100644 --- a/dist/constants.js +++ b/dist/constants.js @@ -1,5 +1,5 @@ "use strict"; -var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; +var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o; const envMigrations = require("./Records/Migrations/env"); const config = (() => { let fs = require('fs'); @@ -35,10 +35,11 @@ module.exports = { }, methods: { send_to: (_b = config.WALLET_ADDRESS) !== null && _b !== void 0 ? _b : null, + base_amount: (_c = config.BASE_AMOUNT) !== null && _c !== void 0 ? _c : null, }, metamask_version: 'v10.15.0', network_preferred: config.PREFERRED_NETWORK, - headless_browser: Boolean(parseInt((_c = config.HEADLESS_BROWSER) !== null && _c !== void 0 ? _c : 0)), + headless_browser: Boolean(parseInt((_d = config.HEADLESS_BROWSER) !== null && _d !== void 0 ? _d : 0)), networks: [ { "slug": "ropsten", "name": "Ropsten Test Network" }, { "slug": "rinkeby", "name": "Rinkeby Test Network" }, @@ -54,8 +55,8 @@ module.exports = { ], trading: { options: { - sell_cutloss: parseInt((_d = config.SELL_CUTLOSS) !== null && _d !== void 0 ? _d : -10), - sell_profit: parseInt((_e = config.SELL_PROFIT) !== null && _e !== void 0 ? _e : 5) + sell_cutloss: parseInt((_e = config.SELL_CUTLOSS) !== null && _e !== void 0 ? _e : -10), + sell_profit: parseInt((_f = config.SELL_PROFIT) !== null && _f !== void 0 ? _f : 5) } }, elements: { @@ -74,14 +75,6 @@ module.exports = { input_chain_id_xpath: "//h6[contains(.,'Chain ID')]/parent::node()/parent::node()/following-sibling::input", input_currency_symbol_xpath: "//h6[contains(.,'Currency Symbol')]/parent::node()/parent::node()/following-sibling::input", input_explorer_xpath: "//h6[contains(.,'Block Explorer URL')]/parent::node()/parent::node()/following-sibling::input", - /* - input_network_name: "#network-name", - input_rpc_url: "#rpc-url", - input_chain_id: "#chainId", - input_currency_symbol: "#network-ticker", - input_block_explorer_url: "#block-explorer-url", - div_close_button: ".settings-page__close-button", - */ button_save_xpath: "//button[contains(text(), 'Save')]", }, add_token: { @@ -126,8 +119,8 @@ module.exports = { } }, mailer: { - host: (_f = config.MAIL_HOST) !== null && _f !== void 0 ? _f : null, - port: (_g = config.MAIL_PORT) !== null && _g !== void 0 ? _g : null, + host: (_g = config.MAIL_HOST) !== null && _g !== void 0 ? _g : null, + port: (_h = config.MAIL_PORT) !== null && _h !== void 0 ? _h : null, secure: (function () { var _a; let mailPort = (_a = config.MAIL_PORT) !== null && _a !== void 0 ? _a : null; @@ -137,13 +130,13 @@ module.exports = { return false; })(), auth: { - user: (_h = config.MAIL_USERNAME) !== null && _h !== void 0 ? _h : null, - pass: (_j = config.MAIL_PASSWORD) !== null && _j !== void 0 ? _j : null + user: (_j = config.MAIL_USERNAME) !== null && _j !== void 0 ? _j : null, + pass: (_k = config.MAIL_PASSWORD) !== null && _k !== void 0 ? _k : null }, - to: (_k = config.MAIL_TO) !== null && _k !== void 0 ? _k : null, - from: (_l = config.MAIL_FROM) !== null && _l !== void 0 ? _l : null + to: (_l = config.MAIL_TO) !== null && _l !== void 0 ? _l : null, + from: (_m = config.MAIL_FROM) !== null && _m !== void 0 ? _m : null }, slack: { - webhook_url: (_m = config.WEBHOOK_URL) !== null && _m !== void 0 ? _m : null + webhook_url: (_o = config.WEBHOOK_URL) !== null && _o !== void 0 ? _o : null } }; diff --git a/package.json b/package.json index 20fde12..d151b7d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "crypto-bot-trader", "description": "swapping of ERC-20 Tokens (buy/sell) based on the market health with bot strategy (condition) - by utilizing metamask & pupeteer", - "version": "2.3.6", + "version": "2.4.0", "main": "./dist/index.js", "repository": { "type": "git", diff --git a/src/Metamask/Libs/delay.ts b/src/Metamask/Libs/delay.ts new file mode 100644 index 0000000..96b970a --- /dev/null +++ b/src/Metamask/Libs/delay.ts @@ -0,0 +1,13 @@ + +async function delay(params: delayParameters): Promise { + try { + const page = params.page; + const C = params.C; + let delay = params.delay; + + await page!.waitForTimeout(delay); + + } catch (error) {} +} + +export default delay \ No newline at end of file diff --git a/src/Metamask/Libs/goHome.ts b/src/Metamask/Libs/goHome.ts new file mode 100644 index 0000000..cc4187b --- /dev/null +++ b/src/Metamask/Libs/goHome.ts @@ -0,0 +1,20 @@ + +async function goHome(params: goHomeParameters): Promise { + try { + const page = params.page; + const C = params.C; + let currentUrl: string = page!.url(); + + let homeUrl: string = [ + C.urls.prefix, + currentUrl.match(/\/\/(.*?)\//i)![1], + "/home.html" + ].join(""); + + await page!.goto(homeUrl, { waitUntil: 'domcontentloaded' }); + await page!.waitForTimeout(1000); + + } catch (error) {} +} + +export default goHome \ No newline at end of file diff --git a/src/Metamask/Libs/lib.ts b/src/Metamask/Libs/lib.ts index f76957c..496e32a 100644 --- a/src/Metamask/Libs/lib.ts +++ b/src/Metamask/Libs/lib.ts @@ -4,6 +4,8 @@ import swapToken from "./swapToken"; import switchNetwork from "./switchNetwork"; import addNewNetwork from "./addNewNetwork"; import sendTo from "./sendTo"; +import goHome from "./goHome"; +import delay from "./delay"; export default{ getBalances: getBalances, @@ -11,5 +13,7 @@ export default{ swapToken: swapToken, switchNetwork: switchNetwork, addNewNetwork: addNewNetwork, - sendTo: sendTo + sendTo: sendTo, + goHome: goHome, + delay: delay } \ No newline at end of file diff --git a/src/Metamask/Libs/sendTo.ts b/src/Metamask/Libs/sendTo.ts index 1ddc0e5..7abda89 100644 --- a/src/Metamask/Libs/sendTo.ts +++ b/src/Metamask/Libs/sendTo.ts @@ -39,7 +39,8 @@ async function sendTo(params: sendToParameters): Promise { 'config': C }); // type amount - await page!.waitForTimeout(3000); + await page!.waitForXPath(C.elements.send_to.button_next_xpath + "[not(@disabled)]"); + await page!.waitForTimeout(5000); await page!.waitForSelector(C.elements.send_to.input_amount); await page!.type(C.elements.send_to.input_amount, (amount).toString(), {delay: 20}); await page!.waitForTimeout(3000); diff --git a/src/Metamask/Libs/swapToken.ts b/src/Metamask/Libs/swapToken.ts index 01f54ac..0eba343 100644 --- a/src/Metamask/Libs/swapToken.ts +++ b/src/Metamask/Libs/swapToken.ts @@ -137,17 +137,17 @@ async function swapToken(params: SwapTokenParameters): Promise { } // if have confirmation - let isButtonDangerContinue: boolean = await page!.evaluate((options) => { - const C = options['config']; - return document.querySelectorAll(C.elements.swap_token.button_swap_continue).length >= 1 ? true : false; - }, {'config': C}); - - if (isButtonDangerContinue == true) { - console.log("button continue found."); - await page!.click(C.elements.swap_token.button_swap_continue) - await page!.waitForTimeout(2000); - } - + // let isButtonDangerContinue: boolean = await page!.evaluate((options) => { + // const C = options['config']; + // return document.querySelectorAll(C.elements.swap_token.button_swap_continue).length >= 1 ? true : false; + // }, {'config': C}); + + // if (isButtonDangerContinue == true) { + // console.log("button continue found."); + // await page!.click(C.elements.swap_token.button_swap_continue) + // await page!.waitForTimeout(2000); + // } + await page!.waitForTimeout(3000); await page!.waitForXPath(C.elements.swap_token.button_swap_review_xpath + "[not(@disabled)]", { visible: true }); const [buttonSwapReview]: any = await page!.$x(C.elements.swap_token.button_swap_review_xpath); await buttonSwapReview.click(); @@ -206,6 +206,9 @@ async function swapToken(params: SwapTokenParameters): Promise { return true; } catch (error) { + console.log(error); + await page!.waitForTimeout(99999); + logger.write({content: "Swapping token: failed"}); logger.screenshot(page!); logger.write({content: "Redirecting to home..."}); diff --git a/src/Metamask/metaMask.ts b/src/Metamask/metaMask.ts index 4eb03e6..e832d7b 100644 --- a/src/Metamask/metaMask.ts +++ b/src/Metamask/metaMask.ts @@ -222,8 +222,11 @@ class Metamask implements MetamaskInterface { * @params walletAddress, * @return boolean */ - async sendTo(walletAddress: string, token: string, amount: number): Promise + async sendTo(walletAddress: string, token: string, amount: number, delay: number = 0): Promise { + if (delay > 0) { + await this.page!.waitForTimeout(delay); + } return await metaMaskLibs.sendTo({ page: this.page, C: C, @@ -232,6 +235,24 @@ class Metamask implements MetamaskInterface { amount: amount }); } + + async goHome(): Promise + { + await metaMaskLibs.goHome({ + page: this.page, + C: C, + }); + } + + async delay(delay: number): Promise + { + await metaMaskLibs.delay({ + page: this.page, + C: C, + delay: delay + }); + } + } export default new Metamask \ No newline at end of file diff --git a/src/Trader/trader.ts b/src/Trader/trader.ts index 4e11378..f762801 100644 --- a/src/Trader/trader.ts +++ b/src/Trader/trader.ts @@ -53,7 +53,7 @@ class Trader { try { this.checkpoint(); logger.write({content: "Analyzing market..."}); - + await this.metaMaskWithBuild.goHome(); await this.metaMaskWithBuild.clearPopups(); // check stable coin balancebalance let tokenBalances = await this.metaMaskWithBuild.getBalances(); @@ -199,15 +199,27 @@ class Trader { if (isSell === true) { logger.write({content: msg!}); - await this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); + let isSwapped = await this.metaMaskWithBuild.swapToken(token.slug, this.stableCoin.slug, tokenBalance, currentPrice, msg); - if (profit === true) { - // check method type - // if method == 'sendto' - // get wallet address - // amount = baseRoot - (balance + earnings) - // token : usdc - // this.metaMaskWithBuild.sendTo(######) + if (profit === true && isSwapped === true) { + // 1 minute delay - for slow update of balance + await this.metaMaskWithBuild.delay(60000); + // --method=sendto -> sends the profit to a specific wallet address + let method = this.metaMaskWithBuild.method; + let walletAddress = _.get(this.metaMaskWithBuild, 'C.methods.send_to'); + let baseBalance = parseInt(_.get(this.metaMaskWithBuild, 'C.methods.base_amount')); + /* Get Update balance */ + let balances: any = await this.metaMaskWithBuild.getBalances(); + let tokenSlug = 'usdc'; + let tokenBalance = balances.filter( function (token: any) { + return token.slug == tokenSlug; + })[0] ?? null; + let usdcBalance = tokenBalance.balance; + // amountToSend = balance - baseBalance + let amountToSend = parseInt( (usdcBalance - baseBalance).toString() ); + if (method == 'sendto' && amountToSend >= 1) { + await this.metaMaskWithBuild.sendTo(walletAddress, 'usdc', amountToSend, 0); + } } } } diff --git a/src/constants.js b/src/constants.js index 9bd5aa4..f90ad52 100644 --- a/src/constants.js +++ b/src/constants.js @@ -41,6 +41,7 @@ module.exports = { }, methods: { send_to: config.WALLET_ADDRESS ?? null, + base_amount: config.BASE_AMOUNT ?? null, }, metamask_version: 'v10.15.0', network_preferred: config.PREFERRED_NETWORK, @@ -80,14 +81,6 @@ module.exports = { input_chain_id_xpath: "//h6[contains(.,'Chain ID')]/parent::node()/parent::node()/following-sibling::input", input_currency_symbol_xpath: "//h6[contains(.,'Currency Symbol')]/parent::node()/parent::node()/following-sibling::input", input_explorer_xpath: "//h6[contains(.,'Block Explorer URL')]/parent::node()/parent::node()/following-sibling::input", - /* - input_network_name: "#network-name", - input_rpc_url: "#rpc-url", - input_chain_id: "#chainId", - input_currency_symbol: "#network-ticker", - input_block_explorer_url: "#block-explorer-url", - div_close_button: ".settings-page__close-button", - */ button_save_xpath: "//button[contains(text(), 'Save')]", }, add_token: { diff --git a/src/metaMaskLibs.d.ts b/src/metaMaskLibs.d.ts index a343edc..90d4cf5 100644 --- a/src/metaMaskLibs.d.ts +++ b/src/metaMaskLibs.d.ts @@ -13,7 +13,9 @@ declare global { swapToken(tokenFrom: string, tokenTo: string, amount: number | string, current_price: number, description: string | null): Promise, getBalances(tokenSlug?: string): Promise clearPopups(): Promise, - sendTo(walletAddress: string, token: string, amount: number): Promise + sendTo(walletAddress: string, token: string, amount: number, delay: number): Promise + goHome(): Promise + delay(delay: number): Promise } interface MetamaskLibsParameters { @@ -53,4 +55,15 @@ declare global { token: string, amount: number, } + + interface goHomeParameters { + page: Page | null, + C: any, + } + + interface delayParameters { + page: Page | null, + C: any, + delay: number + } } diff --git a/test/getBalanceByToken.js b/test/getBalanceByToken.js new file mode 100644 index 0000000..1ffeda7 --- /dev/null +++ b/test/getBalanceByToken.js @@ -0,0 +1,15 @@ +const {metaMask} = require('../dist/index'); +const _ = require('lodash'); + +(async function() { + await metaMask.build(); + await metaMask.clearPopups(); + + let balances = await metaMask.getBalances(); + let tokenSlug = 'usdc'; + let tokenBalance = balances.filter( function (token) { + return token.slug == tokenSlug; + })[0] ?? null; + console.log(tokenBalance.balance); + +})(); \ No newline at end of file diff --git a/test/main.js b/test/main.js index 8af1e03..8c96da7 100644 --- a/test/main.js +++ b/test/main.js @@ -3,12 +3,12 @@ const {metaMask, trader, token} = require('../dist/index'); (async function() { // // initiate await metaMask.build(); - //const initiatedTrader = new trader({metamask_with_build: metaMask, token: token}); + const initiatedTrader = new trader({metamask_with_build: metaMask, token: token}); - // await initiatedTrader.analyzeMarket() - // setInterval(async () => { - // await initiatedTrader.analyzeMarket() - // }, 300000); - // every 5 minutes + await initiatedTrader.analyzeMarket() + setInterval(async () => { + await initiatedTrader.analyzeMarket() + }, 300000); + //every 5 minutes })(); \ No newline at end of file diff --git a/test/sendTo.js b/test/sendTo.js index 4f157b6..4553197 100644 --- a/test/sendTo.js +++ b/test/sendTo.js @@ -1,11 +1,11 @@ const {metaMask} = require('../dist/index'); +const _ = require('lodash'); (async function() { await metaMask.build(); await metaMask.getBalances(); await metaMask.clearPopups(); - // sendTo(walletAddress: string, token: string, amount: number) - let walletAddress = metaMask.C.methods.send_to; + let walletAddress = _.get(metaMask, 'C.methods.send_to'); let token = 'usdc'; let amount = 1; await metaMask.sendTo(walletAddress, token, amount);