-
Notifications
You must be signed in to change notification settings - Fork 1
/
maintainer.js
137 lines (122 loc) · 4.4 KB
/
maintainer.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
const Web3 = require("web3");
var fs = require("fs");
var dir = "./data";
if (!fs.existsSync(dir)) {
console.log("data folder does not exists. Run collector script first");
}
const { operator, url } = require("./scriptConfig.js");
const depositAddress = "0xCffDCB12b74bE900e2020B9D96D256F1fEA96342";
const depositFactoryAddress = "0x87EFFeF56C7fF13E2463b5d4dCE81bE2340FAf8b";
const keepFactoryAddress = "0xA7d9E842EFB252389d613dA88EDa3731512e40bD";
const feeRebateTokenAddress = "0xaf3fFF06b75f99352d8C2a3C4beF1339a2f94789";
const TDTAddress = "0x10B66Bd1e3b5a936B7f8Dbc5976004311037Cdf0";
const vendingMachineAddress = "0x526c08E5532A9308b3fb33b7968eF78a5005d2AC";
const { setupLoader } = require("@openzeppelin/contract-loader");
const states = [
"START",
"AWAITING_SIGNER_SETUP",
"AWAITING_BTC_FUNDING_PROOF",
"FAILED_SETUP",
"ACTIVE",
"AWAITING_WITHDRAWAL_SIGNATURE",
"AWAITING_WITHDRAWAL_PROOF",
"REDEEMED",
"COURTESY_CALL",
"FRAUD_LIQUIDATION_IN_PROGRESS",
"LIQUIDATION_IN_PROGRESS",
"LIQUIDATED",
];
function time() {
return new Date().toUTCString() + ":";
}
async function getRecents() {
let nodeData = require("./data/nodeData");
const web3 = new Web3(url);
const loader = setupLoader({ provider: web3 }).web3;
const depositFactory = loader.fromArtifact(
"DepositFactory",
depositFactoryAddress
);
const ecdsaFactory = loader.fromArtifact(
"BondedECDSAKeepFactory",
keepFactoryAddress
);
const frt = loader.fromArtifact("FeeRebateToken", feeRebateTokenAddress);
const tdt = loader.fromArtifact("TBTCDepositToken", TDTAddress);
let END_BLOCK = await web3.eth.getBlockNumber();
let read = fs.readFileSync("data/blockUpdated.txt");
let START_BLOCK = Number(read);
if (START_BLOCK == 0) {
START_BLOCK = END_BLOCK - 999;
}
let log =`Gathering data from block range:${START_BLOCK} - ${END_BLOCK}\n`
fs.appendFileSync("data/logs.txt", `${time()} ${log}`);
fs.writeFileSync("data/blockUpdated.txt", END_BLOCK);
let events = await ecdsaFactory.getPastEvents("BondedECDSAKeepCreated", {
fromBlock: START_BLOCK,
toBlock: END_BLOCK, // You can also specify 'latest'
});
let ecdsaSelected = false;
let keepAddress;
let blockNum;
let transactionIndex;
let txHash;
let cloneAddress;
let TDTOwner;
let FRTExists;
let TDTredeemable = false;
let state;
let lotSize;
for (let i = 0; i < events.length; i++) {
let vls = events[i].returnValues["1"];
for (let q = 0; q < vls.length; q++) {
if (vls[q] == operator) {
txHash = events[i].transactionHash;
blockNum = events[i].blockNumber;
keepAddress = events[i].returnValues["keepAddress"];
events = await depositFactory.getPastEvents("DepositCloneCreated", {
fromBlock: blockNum,
toBlock: blockNum, // You can also specify 'latest'
});
for (let i = 0; i < events.length; i++) {
if (events[i].transactionHash == txHash) {
cloneAddress = events[i].returnValues["0"];
}
}
const deposit = loader.fromArtifact("Deposit", cloneAddress);
lotSize = await deposit.methods.lotSizeSatoshis().call();
state = await deposit.methods.currentState().call();
collateralizationRate = await deposit.methods.collateralizationPercentage().call()
FRTExists = await frt.methods.exists(cloneAddress).call();
if (FRTExists) {
TDTOwner = await tdt.methods.ownerOf(cloneAddress).call();
if (TDTOwner == vendingMachineAddress) {
TDTredeemable = true;
}
}
if (FRTExists && !TDTredeemable) {
}
let KeepData = {
keepAddress: keepAddress,
blockNum: blockNum,
cloneAddress: cloneAddress,
lotSize: lotSize,
state: states[state],
FRTExists: FRTExists,
redeemable: TDTredeemable,
TDTOwner: TDTOwner,
collateralizationRate: collateralizationRate,
};
var count = Object.keys(nodeData).length;
nodeData[count.toString()] = KeepData;
let logData = JSON.stringify(KeepData);
fs.appendFileSync("data/logs.txt", time() + " found " + logData);
let data = JSON.stringify(nodeData);
fs.writeFileSync("data/nodeData.json", data);
}
}
}
log =`end log for ${START_BLOCK} - ${END_BLOCK}\n`
fs.appendFileSync("data/logs.txt", `${log}`);
}
getRecents();