Repository navigation
Expand file tree
/
Copy pathwithdraw_fees.js
More file actions
81 lines (66 loc) · 3.05 KB
/
Copy pathwithdraw_fees.js
File metadata and controls
81 lines (66 loc) · 3.05 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
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
"use strict";
const fs = require("fs");
const { ethers } = require("ethers");
const desktopApp = require("ocore/desktop_app.js");
const args = process.argv.slice(2);
const exportAssistantJson = require('./evm/build/contracts/ExportAssistant.json');
const importAssistantJson = require('./evm/build/contracts/ImportAssistant.json');
process.on('unhandledRejection', up => {
console.error('unhandledRejection event', up, up.stack);
throw up;
});
async function withdrawFromEvmAssistant(network, assistant_address) {
const { getProvider } = require("./evm/provider.js");
const mnemonic = JSON.parse(fs.readFileSync(desktopApp.getAppDataDir() + '/keys.json')).mnemonic_phrase;
const provider = getProvider(network);
const wallet = ethers.Wallet.fromMnemonic(mnemonic).connect(provider);
console.log(`my address on ${network}: ${wallet.address}`);
// try ExportAssistant ABI first; if withdrawManagementFee reverts, it might be an ImportAssistant — both share the same interface for these two methods
const contract = new ethers.Contract(assistant_address, exportAssistantJson.abi, wallet);
console.log(`withdrawing management fee from ${assistant_address} on ${network}...`);
const tx1 = await contract.withdrawManagementFee();
console.log(`management fee withdrawal tx: ${tx1.hash}`);
await tx1.wait();
console.log(`management fee withdrawal mined`);
console.log(`withdrawing success fee from ${assistant_address} on ${network}...`);
const tx2 = await contract.withdrawSuccessFee();
console.log(`success fee withdrawal tx: ${tx2.hash}`);
await tx2.wait();
console.log(`success fee withdrawal mined`);
}
async function withdrawFromObyteAssistant(assistant_address) {
const headlessWallet = require('headless-obyte');
const operator = require('aabot/operator.js');
const dag = require('aabot/dag.js');
const network = require('ocore/network.js');
const db_import = require('./db_import.js');
const light_wallet = require("ocore/light_wallet.js");
await headlessWallet.waitTillReady();
await db_import.initDB();
await operator.start();
await network.start();
await light_wallet.waitUntilFirstHistoryReceived();
await network.waitTillSyncIdle();
console.log(`withdrawing management fee from ${assistant_address} on Obyte...`);
const unit1 = await dag.sendAARequest(assistant_address, { withdraw_management_fee: 1 });
console.log(`management fee withdrawal unit: ${unit1}`);
console.log(`withdrawing success fee from ${assistant_address} on Obyte...`);
const unit2 = await dag.sendAARequest(assistant_address, { withdraw_success_fee: 1 });
console.log(`success fee withdrawal unit: ${unit2}`);
}
async function start() {
const network = args[0];
const assistant_address = args[1];
if (!network || !assistant_address) {
console.error('Usage: node withdraw_fees.js <network> <assistant_address>');
console.error(' network: Obyte | Ethereum | BSC | Polygon | Kava');
process.exit(1);
}
if (network === 'Obyte') {
await withdrawFromObyteAssistant(assistant_address);
} else {
await withdrawFromEvmAssistant(network, assistant_address);
}
process.exit(0);
}
start();