-
Notifications
You must be signed in to change notification settings - Fork 8
/
start.js
186 lines (164 loc) · 4.51 KB
/
start.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
require("dotenv").config();
const readlineModule = require("readline");
const args = require("minimist")(process.argv.slice(2));
const Write = require("./lib/write");
const Web3 = require("./lib/web3");
const Harvest = require("./lib/harvest");
const Score = require("./lib/score");
const { connection, keypair } = Web3;
const harvestInstructions = new Harvest({ connection, keypair });
const scoreInstructions = new Score();
const minimumIntervalTime = 600000;
const maximumIntervalTime = 6000000;
let intervalTime = 0;
let nowSec;
let runningProcess;
let autoClaimProcess;
async function start(isFirst = false) {
if (isFirst) {
Write.printLogo();
try {
await scoreInstructions.getStarAtlasNftInformation();
} catch (err) {
console.error(err);
}
if (!!scoreInstructions.autoBuyFleet) {
Write.printLine({
text: ` Auto buy enabled for ${scoreInstructions.autoBuyFleet.name}.`,
color: Write.colors.fgYellow,
});
}
}
nowSec = new Date().getTime() / 1000;
Write.printLine([
{ text: " Fetching latest flight data...", color: Write.colors.fgYellow },
]);
try {
await scoreInstructions.refreshStakingFleet();
} catch (err) {
console.error(err);
}
try {
await scoreInstructions.refreshInventory();
} catch (err) {
console.error(err);
}
Write.printAvailableSupply(scoreInstructions.inventory);
try {
await scoreInstructions.showFleet();
} catch (err) {
console.error(err);
}
try {
const claimStakeInventory = await harvestInstructions.harvestAll();
if (claimStakeInventory.length) {
Write.printClaimStakesInformation(claimStakeInventory);
} else {
Write.printLine({
text: ` ${"-".repeat(63)}`,
});
}
} catch (err) {
console.error(err);
}
try {
await scoreInstructions.refillFleet();
} catch (err) {
console.error(err);
}
Write.printDailyChurn(
scoreInstructions.dailyUsage,
harvestInstructions.dailyGeneration,
);
await scoreInstructions.processAutoBuy(scoreInstructions.autoBuyFleet);
intervalTime =
args.interval && args.interval > minimumIntervalTime
? args.interval < maximumIntervalTime
? args.interval
: maximumIntervalTime
: minimumIntervalTime;
Write.printRefreshInformation(intervalTime);
}
const exitProcess = async () => {
Write.printLine({
text: "\n Button 'q' pressed",
color: Write.colors.fgYellow,
});
Write.printLine({
text: "Stopping STAR ATLAS AUTOMATION.",
color: Write.colors.fgYellow,
});
clearInterval(runningProcess);
clearInterval(autoClaimProcess);
process.exit(0);
};
readlineModule.emitKeypressEvents(process.stdin);
if (process.stdin.isTTY) {
process.stdin.setRawMode(true);
}
process.stdin.on("keypress", (character) => {
if (character?.toString() === "q") {
return exitProcess();
}
if (character?.toString() === "b") {
if (!!scoreInstructions.autoBuyFleet) {
Write.printLine({
text: "Starting auto buy process.",
color: Write.colors.fgYellow,
});
return scoreInstructions
.processAutoBuy(scoreInstructions.autoBuyFleet)
.then(() => {
Write.printLine({
text: "Auto buy process finished.",
color: Write.colors.fgYellow,
});
});
} else {
Write.printLine({
text: "Auto buy not enabled.",
color: Write.colors.fgRed,
});
}
}
if (character?.toString() === "c") {
Write.printLine({
text: "Starting claim ATLAS process.",
color: Write.colors.fgYellow,
});
return scoreInstructions.claimAtlas().then(() => {
Write.printLine({
text: "Claim ATLAS process finished.",
color: Write.colors.fgYellow,
});
});
}
if (character?.toString() === "i") {
return Write.printAvailableSupply(scoreInstructions.inventory, true);
}
return false;
});
const startInterval = async () => {
if (args.noRunningProcess !== "true") {
clearInterval(runningProcess);
runningProcess = setInterval(start, intervalTime);
} else {
process.exit(0);
}
};
start(true)
.then(() => {
startInterval();
if (process.env.AUTO_CLAIM) {
clearInterval(autoClaimProcess);
autoClaimProcess = setInterval(
async () => {
clearInterval(runningProcess);
await scoreInstructions.claimAtlas(true);
runningProcess = setInterval(start, intervalTime);
},
Number(process.env.AUTO_CLAIM) * 60000,
);
}
})
.catch((err) => console.error(err));