Skip to content

Commit

Permalink
Merge pull request #38 from marcelooblan2016/hotfix/rpc_update_polygon
Browse files Browse the repository at this point in the history
rpc update & fixes
  • Loading branch information
marcelooblan2016 authored Jan 5, 2022
2 parents 1642ea2 + 44de92e commit 76c12eb
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ SELL_PROFIT=
# CHECKPOINT #
##############
# Stop Trading At Date: Optional
# Format: MMMM-Do-YYYY h:mm:ss a
# Format: YYYY-MM-DD HH:mm (2022-01-05 09:30) (military time)
CHECKPOINT_DATE=
75 changes: 40 additions & 35 deletions dist/Metamask/metaMask.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,43 +51,48 @@ class Metamask {
*/
build() {
return __awaiter(this, void 0, void 0, function* () {
let args = process.argv.slice(2);
let validArguments = {};
if (args.length >= 1) {
args = args.forEach(function (argument) {
var _a;
let splittedArgument = argument.replace("--", "").split("=");
validArguments[splittedArgument[0]] = ((_a = splittedArgument[1]) !== null && _a !== void 0 ? _a : null);
});
}
// check if fresh start
let envValues = config_1.default.envValues();
if (typeof envValues['PROCESS_ID'] == 'undefined') {
logger_1.default.write({ content: "Fresh start, it may take at least a minute." });
try {
let args = process.argv.slice(2);
let validArguments = {};
if (args.length >= 1) {
args = args.forEach(function (argument) {
var _a;
let splittedArgument = argument.replace("--", "").split("=");
validArguments[splittedArgument[0]] = ((_a = splittedArgument[1]) !== null && _a !== void 0 ? _a : null);
});
}
// check if fresh start
let envValues = config_1.default.envValues();
if (typeof envValues['PROCESS_ID'] == 'undefined') {
logger_1.default.write({ content: "Fresh start, it may take at least a minute." });
}
// log process id
config_1.default.update({ key: "PROCESS_ID", value: process.pid });
// launch browser
logger_1.default.write({ content: "Launching browser..." });
this.browser = yield dappeteer.launch(puppeteer_1.default, { metamaskVersion: constants_1.default.metamask_version, args: ['--no-sandbox'] });
logger_1.default.write({ content: "Setup metamask..." });
this.metamask = yield dappeteer.setupMetamask(this.browser);
this.page = this.metamask.page;
// import private key
let privateKey = typeof validArguments['pkey'] != 'undefined' ? validArguments['pkey'] : (constants_1.default.private_key != '' ? constants_1.default.private_key : null);
if (privateKey == null) {
logger_1.default.write({ content: "Private key required, exiting..." });
process.exit(0);
}
yield this.metamask.importPK(privateKey);
// add new networks
yield this.addNewNetworks();
// switch to preferred network
logger_1.default.write({ content: `Switch network: ${constants_1.default.network_preferred}` });
// await this.switchNetwork(C.network_preferred);
yield this.page.waitForTimeout(2000);
// load tokens
yield this.loadTokenContracts();
}
// log process id
config_1.default.update({ key: "PROCESS_ID", value: process.pid });
// launch browser
logger_1.default.write({ content: "Launching browser..." });
this.browser = yield dappeteer.launch(puppeteer_1.default, { metamaskVersion: constants_1.default.metamask_version, args: ['--no-sandbox'] });
logger_1.default.write({ content: "Setup metamask..." });
this.metamask = yield dappeteer.setupMetamask(this.browser);
this.page = this.metamask.page;
// import private key
let privateKey = typeof validArguments['pkey'] != 'undefined' ? validArguments['pkey'] : (constants_1.default.private_key != '' ? constants_1.default.private_key : null);
if (privateKey == null) {
logger_1.default.write({ content: "Private key required, exiting..." });
process.exit(0);
catch (error) {
console.log(error);
}
yield this.metamask.importPK(privateKey);
// add new networks
yield this.addNewNetworks();
// switch to preferred network
logger_1.default.write({ content: `Switch network: ${constants_1.default.network_preferred}` });
// await this.switchNetwork(C.network_preferred);
yield this.page.waitForTimeout(2000);
// load tokens
yield this.loadTokenContracts();
});
}
/*
Expand Down
4 changes: 2 additions & 2 deletions dist/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ module.exports = {
"slug": "matic-mainnet",
"name": "Matic Mainnet",
"new": true,
"rpc_url": "https://rpc-mainnet.maticvigil.com",
"rpc_url": "https://polygon-rpc.com",
"chain_id": 137,
"currency_symbol": "MATIC",
"block_explorer_url": "https://explorer.matic.network"
"block_explorer_url": "https://polygonscan.com/"
}
],
trading: {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": "1.0.50",
"version": "1.0.52",
"main": "./dist/index.js",
"repository": {
"type": "git",
Expand Down
76 changes: 40 additions & 36 deletions src/Metamask/metaMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,43 +26,47 @@ class Metamask implements MetamaskInterface {
*/
public async build (): Promise<void>
{
let args: any = process.argv.slice(2);
let validArguments: any = {};
if (args.length >= 1) {
args = args.forEach( function (argument: string) {
let splittedArgument = argument.replace("--", "").split("=");
validArguments[splittedArgument[0]] = (splittedArgument[1] ?? null);
});
}
// check if fresh start
let envValues = config.envValues();
if (typeof envValues['PROCESS_ID'] == 'undefined') {
logger.write({content: "Fresh start, it may take at least a minute."});
}
// log process id
config.update({key: "PROCESS_ID", value: process.pid});
// launch browser
logger.write({content: "Launching browser..."});
this.browser = await dappeteer.launch(puppeteer, {metamaskVersion: C.metamask_version, args: ['--no-sandbox']});

logger.write({content: "Setup metamask..."});
this.metamask = await dappeteer.setupMetamask(this.browser);
this.page = this.metamask.page;
// import private key
let privateKey: string = typeof validArguments['pkey'] != 'undefined' ? validArguments['pkey'] : (C.private_key != '' ? C.private_key : null);
if (privateKey == null) {
logger.write({content: "Private key required, exiting..."});
process.exit(0);
try {
let args: any = process.argv.slice(2);
let validArguments: any = {};
if (args.length >= 1) {
args = args.forEach( function (argument: string) {
let splittedArgument = argument.replace("--", "").split("=");
validArguments[splittedArgument[0]] = (splittedArgument[1] ?? null);
});
}
// check if fresh start
let envValues = config.envValues();
if (typeof envValues['PROCESS_ID'] == 'undefined') {
logger.write({content: "Fresh start, it may take at least a minute."});
}
// log process id
config.update({key: "PROCESS_ID", value: process.pid});
// launch browser
logger.write({content: "Launching browser..."});
this.browser = await dappeteer.launch(puppeteer, {metamaskVersion: C.metamask_version, args: ['--no-sandbox']});

logger.write({content: "Setup metamask..."});
this.metamask = await dappeteer.setupMetamask(this.browser);
this.page = this.metamask.page;
// import private key
let privateKey: string = typeof validArguments['pkey'] != 'undefined' ? validArguments['pkey'] : (C.private_key != '' ? C.private_key : null);
if (privateKey == null) {
logger.write({content: "Private key required, exiting..."});
process.exit(0);
}
await this.metamask.importPK(privateKey);
// add new networks
await this.addNewNetworks();
// switch to preferred network
logger.write({content: `Switch network: ${C.network_preferred}`});
// await this.switchNetwork(C.network_preferred);
await this.page!.waitForTimeout(2000);
// load tokens
await this.loadTokenContracts();
} catch (error) {
console.log(error);
}
await this.metamask.importPK(privateKey);
// add new networks
await this.addNewNetworks();
// switch to preferred network
logger.write({content: `Switch network: ${C.network_preferred}`});
// await this.switchNetwork(C.network_preferred);
await this.page!.waitForTimeout(2000);
// load tokens
await this.loadTokenContracts();
}
/*
* Import tokens with contracts
Expand Down
4 changes: 2 additions & 2 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ module.exports = {
"slug": "matic-mainnet",
"name": "Matic Mainnet",
"new": true,
"rpc_url": "https://rpc-mainnet.maticvigil.com",
"rpc_url": "https://polygon-rpc.com",
"chain_id": 137,
"currency_symbol": "MATIC",
"block_explorer_url": "https://explorer.matic.network"
"block_explorer_url": "https://polygonscan.com/"
}
],
trading: {
Expand Down

0 comments on commit 76c12eb

Please sign in to comment.