-
Notifications
You must be signed in to change notification settings - Fork 1
/
my_tdts.js
107 lines (88 loc) · 3.37 KB
/
my_tdts.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
import fs from 'fs';
import ethers from 'ethers';
import TBTCSystem from "@keep-network/tbtc/artifacts/TBTCSystem.json";
import VendingMachine from "@keep-network/tbtc/artifacts/VendingMachine.json";
import TBTCToken from "@keep-network/tbtc/artifacts/TBTCToken.json";
import TBTCDepositToken from "@keep-network/tbtc/artifacts/TBTCDepositToken.json";
import Deposit from "@keep-network/tbtc/artifacts/Deposit.json";
import BondedECDSAKeep from "@keep-network/keep-ecdsa/artifacts/BondedECDSAKeep.json";
import DepositLog from "@keep-network/tbtc/artifacts/DepositLog.json";
if (process.argv.length < 3 || !process.argv[2]) {
console.error('node access.js [password]');
process.exit(1);
}
const states = [
// DOES NOT EXIST YET
"START",
// FUNDING FLOW
"AWAITING_SIGNER_SETUP",
"AWAITING_BTC_FUNDING_PROOF",
// FAILED SETUP
"FAILED_SETUP",
// ACTIVE
"ACTIVE", // includes courtesy call
// REDEMPTION FLOW
"AWAITING_WITHDRAWAL_SIGNATURE",
"AWAITING_WITHDRAWAL_PROOF",
"REDEEMED",
// SIGNER LIQUIDATION FLOW
"COURTESY_CALL",
"FRAUD_LIQUIDATION_IN_PROGRESS",
"LIQUIDATION_IN_PROGRESS",
"LIQUIDATED"
];
async function main() {
let wallet
try {
const j = fs.readFileSync('wallet.json', 'utf8');
const w = await new ethers.Wallet.fromEncryptedJson(j, process.argv[2]);
const ip = new ethers.providers.InfuraProvider('ropsten', process.env.INFURA_API);
wallet = w.connect(ip);
const vendingContract = new ethers.Contract(VendingMachine.networks["3"].address, VendingMachine.abi, wallet);
const tokenContract = new ethers.Contract(TBTCToken.networks["3"].address, TBTCToken.abi, wallet);
const tdtContract = new ethers.Contract(TBTCDepositToken.networks["3"].address, TBTCDepositToken.abi, wallet);
console.log(`I own ${ethers.utils.formatEther((await tokenContract.balanceOf(wallet.address)).toString())} tBTC`);
//console.log(tdtContract);
const transfers = await tdtContract.queryFilter(tdtContract.filters.Transfer(null, wallet.address));
const tokenIDs = transfers.map(t => { return t.args[2].toHexString()});
console.log(tokenIDs);
const activeTDTs = new Array();
for (let tokenID of tokenIDs) {
const d = new ethers.Contract(tokenID, Deposit.abi, wallet);
const depositState = await d.currentState();
console.log(`[${tokenID}] in state ${states[depositState]} @ ${ethers.utils.formatEther((await d.lotSizeTbtc()).toString())} tBTC`);
if (depositState.toNumber() === 1) { // Check if we can dissolve this.
try {
console.log(`try to call notifySignerSetupFailure`);
const tx = await d.notifySignerSetupFailed();
await tx.wait();
console.log(`success`);
} catch (err) {
console.log(`failed to call notifySignerSetupFailed`);
}
} else if (depositState.toNumber() === 5) {
// Check if withdrawal request has timed out.
try {
console.log(`try to call notifySignatureTimeout`);
const tx = await d.notifySignatureTimeout();
await tx.wait();
console.log(`success`);
} catch (err) {
console.log(`failed to call notifySignatureTimeout`);
}
}
const w = await d.withdrawableAmount();
if (w.gt(0)) {
console.log(`we can withdraw: ${ethers.utils.formatEther(w.toString())}`)
const wTx = await d.withdrawFunds();
await wTx.wait();
}
}
} catch(err) {
console.error(`Could not authorize: ${err.message}`)
process.exit(1)
}
}
main().catch(err => {
console.error(err);
})