-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.ts
69 lines (61 loc) · 1.93 KB
/
helpers.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import path from "path";
import fs from "fs";
import { formatEther } from "ethers/lib/utils";
import { VaultStatus } from "./types";
import {
getCollateralRatio,
getETHPrice,
getOSQTHPrice,
getTotalValueUSDC,
} from "./utils";
export const clearLines = (n: number) => {
for (let i = 0; i < n; i++) {
//first clear the current line, then clear the previous line
const y = i === 0 ? null : -1;
process.stdout.moveCursor(0, y);
process.stdout.clearLine(1);
}
process.stdout.cursorTo(0);
};
export const displayVaultStatus = async (
currentVaultStatus: VaultStatus,
blockNumber: number,
startTime: number,
blockToStart: number,
blockToFinish: number
) => {
const totalValueUSDC = await getTotalValueUSDC(
currentVaultStatus.shortAmount,
currentVaultStatus.collateralAmount,
blockNumber
);
const collateralRatio = await getCollateralRatio(
currentVaultStatus.shortAmount,
currentVaultStatus.collateralAmount,
blockNumber
);
const currentETHPrice = await getETHPrice(blockNumber);
const currentOSQTHPrice = await getOSQTHPrice(blockNumber);
const currentTime = Date.now();
const msPassed = currentTime - startTime;
const msLeft =
((blockToFinish - blockNumber) * msPassed) / (blockNumber - blockToStart);
const minLeft = msLeft / 1000 / 60;
process.stdout.write(`block number: ${blockNumber}\n`);
process.stdout.write(
`total value: ${formatEther(totalValueUSDC.toString())}\n`
);
process.stdout.write(`collateral ratio: ${collateralRatio}\n`);
process.stdout.write(`current ETH price: ${currentETHPrice}\n`);
process.stdout.write(`current OSQTH price: ${currentOSQTHPrice}\n`);
process.stdout.write(`ETA min left: ${minLeft}`);
clearLines(6);
};
export function ensureDirectoryExistence(filePath: string) {
var dirname = path.dirname(filePath);
if (fs.existsSync(dirname)) {
return true;
}
ensureDirectoryExistence(dirname);
fs.mkdirSync(dirname);
}