Skip to content

Commit

Permalink
Merge pull request #72 from yuichiroaoki/log
Browse files Browse the repository at this point in the history
emit log
  • Loading branch information
yuichiroaoki authored Apr 26, 2022
2 parents 932caa5 + 54b223c commit f6818ef
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 2 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ dist
!.yarn/versions
.pnp.*

yarn.lock
yarn.lock
log
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"console-table-printer": "latest",
"dotenv": "latest",
"ethers": "^5.5.3",
"log4js": "^6.4.6",
"ts-node": "latest",
"typescript": "latest"
},
Expand Down
33 changes: 32 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
renderInterval,
loanAmount,
diffAmount,
explorerURL,
gasLimit,
gasPrice,
} from "./config";
import { flashloan } from "./flashloan";
import { expectAmountOut } from "./expect";
Expand All @@ -17,6 +20,21 @@ import { chalkDifference, chalkPercentage, chalkTime } from "./utils/chalk";
import { flashloanTable, priceTable } from "./consoleUI/table";
import { initPriceTable, renderTables } from "./consoleUI";
import { createRoutes } from "./price/1inch/route";
import * as log4js from "log4js";

log4js.configure({
appenders: {
flashloan: { type: "file", filename: "log/flashloan.log" },
error: { type: "file", filename: "log/error.log" },
},
categories: {
default: { appenders: ["flashloan"], level: "info" },
error: { appenders: ["error"], level: "warn" },
},
});

const logger = log4js.getLogger("flashloan");
const errReport = log4js.getLogger("error");

export const main = async () => {
console.clear();
Expand Down Expand Up @@ -87,6 +105,9 @@ export const main = async () => {
);
} catch (e) {
// skip flashloan when failed to estimate price
errReport.warn(e);
errReport.warn(1, JSON.stringify(firstProtocols));
errReport.warn(2, JSON.stringify(secondProtocols));
return;
}
// check if the expected amount is larger than the loan amount
Expand Down Expand Up @@ -150,9 +171,18 @@ export const main = async () => {
),
timestamp: new Date().toISOString(),
});

renderTables(p, pp);
logger.info("flashloan executed", tx.hash);
logger.info(`Explorer URL: ${explorerURL}/tx/${tx.hash}`);
} catch (e) {
errReport.error(e);
errReport.error({
gasLimit,
gasPrice,
loanAmount,
baseToken,
tradingToken,
});
} finally {
isFlashLoaning = false;
}
Expand All @@ -173,5 +203,6 @@ export const main = async () => {

main().catch((error) => {
console.error(error);
errReport.error(error);
process.exit(1);
});
89 changes: 89 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2219,6 +2219,13 @@ axios@latest:
languageName: node
linkType: hard

"date-format@npm:^4.0.9":
version: 4.0.9
resolution: "date-format@npm:4.0.9"
checksum: c9cdc5123a9b99de5b7d6bc35197bf6bc01581c795b1cd4e24d72e29d7a535d3a6cbd6f993d90b1ff6d5d51d51a9c969730a8fb8cc8977eee3430c5320e2418a
languageName: node
linkType: hard

"debug@npm:4, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1, debug@npm:^4.3.2":
version: 4.3.3
resolution: "debug@npm:4.3.3"
Expand All @@ -2240,6 +2247,18 @@ axios@latest:
languageName: node
linkType: hard

"debug@npm:^4.3.4":
version: 4.3.4
resolution: "debug@npm:4.3.4"
dependencies:
ms: 2.1.2
peerDependenciesMeta:
supports-color:
optional: true
checksum: 3dbad3f94ea64f34431a9cbf0bafb61853eda57bff2880036153438f50fb5a84f27683ba0d8e5426bf41a8c6ff03879488120cf5b3a761e77953169c0600a708
languageName: node
linkType: hard

"decimal.js-light@npm:^2.5.0":
version: 2.5.1
resolution: "decimal.js-light@npm:2.5.1"
Expand Down Expand Up @@ -2645,6 +2664,13 @@ dotenv@latest:
languageName: node
linkType: hard

"flatted@npm:^3.2.5":
version: 3.2.5
resolution: "flatted@npm:3.2.5"
checksum: 3c436e9695ccca29620b4be5671dd72e5dd0a7500e0856611b7ca9bd8169f177f408c3b9abfa78dfe1493ee2d873e2c119080a8a9bee4e1a186a9e60ca6c89f1
languageName: node
linkType: hard

"follow-redirects@npm:^1.14.4":
version: 1.14.6
resolution: "follow-redirects@npm:1.14.6"
Expand Down Expand Up @@ -2673,6 +2699,17 @@ dotenv@latest:
languageName: node
linkType: hard

"fs-extra@npm:^10.1.0":
version: 10.1.0
resolution: "fs-extra@npm:10.1.0"
dependencies:
graceful-fs: ^4.2.0
jsonfile: ^6.0.1
universalify: ^2.0.0
checksum: dc94ab37096f813cc3ca12f0f1b5ad6744dfed9ed21e953d72530d103cea193c2f81584a39e9dee1bea36de5ee66805678c0dddc048e8af1427ac19c00fffc50
languageName: node
linkType: hard

"fs-minipass@npm:^2.0.0":
version: 2.1.0
resolution: "fs-minipass@npm:2.1.0"
Expand Down Expand Up @@ -2843,6 +2880,13 @@ dotenv@latest:
languageName: node
linkType: hard

"graceful-fs@npm:^4.1.6, graceful-fs@npm:^4.2.0":
version: 4.2.10
resolution: "graceful-fs@npm:4.2.10"
checksum: 3f109d70ae123951905d85032ebeae3c2a5a7a997430df00ea30df0e3a6c60cf6689b109654d6fdacd28810a053348c4d14642da1d075049e6be1ba5216218da
languageName: node
linkType: hard

"hardhat-watcher@npm:^2.1.1":
version: 2.1.1
resolution: "hardhat-watcher@npm:2.1.1"
Expand Down Expand Up @@ -3889,6 +3933,19 @@ jest@latest:
languageName: node
linkType: hard

"jsonfile@npm:^6.0.1":
version: 6.1.0
resolution: "jsonfile@npm:6.1.0"
dependencies:
graceful-fs: ^4.1.6
universalify: ^2.0.0
dependenciesMeta:
graceful-fs:
optional: true
checksum: 7af3b8e1ac8fe7f1eccc6263c6ca14e1966fcbc74b618d3c78a0a2075579487547b94f72b7a1114e844a1e15bb00d440e5d1720bfc4612d790a6f285d5ea8354
languageName: node
linkType: hard

"keyv@npm:^3.0.0":
version: 3.1.0
resolution: "keyv@npm:3.1.0"
Expand Down Expand Up @@ -4018,6 +4075,19 @@ lint-staged@latest:
languageName: node
linkType: hard

"log4js@npm:^6.4.6":
version: 6.4.6
resolution: "log4js@npm:6.4.6"
dependencies:
date-format: ^4.0.9
debug: ^4.3.4
flatted: ^3.2.5
rfdc: ^1.3.0
streamroller: ^3.0.8
checksum: 22ce9738db32e19efffb9c7ec222ab151622afd45c1634bdc94487b1fb9be9de3ef45835eea3a728e52442d273d38eafa1b728f149aad1e76aac3b373dda09cf
languageName: node
linkType: hard

"lowercase-keys@npm:^1.0.0, lowercase-keys@npm:^1.0.1":
version: 1.0.1
resolution: "lowercase-keys@npm:1.0.1"
Expand Down Expand Up @@ -5026,6 +5096,7 @@ resolve@^1.20.0:
husky: latest
jest: latest
lint-staged: latest
log4js: ^6.4.6
nodemon: latest
pinst: latest
prettier: latest
Expand Down Expand Up @@ -5091,6 +5162,17 @@ resolve@^1.20.0:
languageName: node
linkType: hard

"streamroller@npm:^3.0.8":
version: 3.0.8
resolution: "streamroller@npm:3.0.8"
dependencies:
date-format: ^4.0.9
debug: ^4.3.4
fs-extra: ^10.1.0
checksum: 34dce4add3aec6efde41ac2dac1b9d3393e109628c49d56adb0093b8ef636ed907765113f5683ea64271f983fbfe775a7cf382d681dc3797d546d0065d7a3d27
languageName: node
linkType: hard

"string-argv@npm:^0.3.1":
version: 0.3.1
resolution: "string-argv@npm:0.3.1"
Expand Down Expand Up @@ -5537,6 +5619,13 @@ typescript@latest:
languageName: node
linkType: hard

"universalify@npm:^2.0.0":
version: 2.0.0
resolution: "universalify@npm:2.0.0"
checksum: 2406a4edf4a8830aa6813278bab1f953a8e40f2f63a37873ffa9a3bc8f9745d06cc8e88f3572cb899b7e509013f7f6fcc3e37e8a6d914167a5381d8440518c44
languageName: node
linkType: hard

"update-notifier@npm:^5.1.0":
version: 5.1.0
resolution: "update-notifier@npm:5.1.0"
Expand Down

0 comments on commit f6818ef

Please sign in to comment.