-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
55 lines (51 loc) · 1.53 KB
/
utils.js
File metadata and controls
55 lines (51 loc) · 1.53 KB
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
const { rewardRatios, APIKey } = require("./constants");
const ethers = require("ethers");
const axios = require("axios");
const express = require("express");
const path = require("path");
var bcrypt = require("bcrypt");
const calcRewardRatio = (min, max, month) => {
return rewardRatios[`_${min}to${max}`][`_${month}`] * 100;
};
const monthtoSecond = (month) => {
return month * 2629746;
};
const getGasPriceApi = async () => {
let maxFeePerGas = 40000000000n; // fallback to 40 gwei
let maxPriorityFeePerGas = 40000000000n; // fallback to 40 gwei
try {
const { data } = await axios({
method: "get",
url: `https://api.polygonscan.com/api?module=gastracker&action=gasoracle&apikey=${APIKey}`,
});
maxFeePerGas = ethers.parseUnits(
Math.ceil(data.result.FastGasPrice) + "",
"gwei"
);
maxPriorityFeePerGas = ethers.parseUnits(
Math.ceil(data.result.ProposeGasPrice) + "",
"gwei"
);
} catch (e) {
return e.message;
}
return { maxFeePerGas, maxPriorityFeePerGas };
};
const serveStaticFiles = (app, routes) => {
app.use(express.static(path.join(__dirname, "/public")));
for (let route of routes) {
app.use(route, express.static(path.join(__dirname, "/public")));
}
};
const validatePassword = async (password, dbPassword) => {
var hash = dbPassword.replace(/^\$2y(.+)$/i, "$2a$1");
const result = await bcrypt.compare(password, hash);
return result;
};
module.exports = {
calcRewardRatio,
monthtoSecond,
getGasPriceApi,
serveStaticFiles,
validatePassword,
};