@ledgerhq/live-cli 24.10.2 → 24.10.3-nightly.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cli.js +33 -63
- package/lib/cli.js.map +1 -1
- package/lib/commands/blockchain/bot.js +7 -7
- package/lib/commands/blockchain/bot.js.map +1 -1
- package/lib/commands/blockchain/botPortfolio.js +22 -26
- package/lib/commands/blockchain/botPortfolio.js.map +1 -1
- package/lib/commands/blockchain/botTransfer.js +219 -392
- package/lib/commands/blockchain/botTransfer.js.map +1 -1
- package/lib/commands/blockchain/broadcast.js +11 -42
- package/lib/commands/blockchain/broadcast.js.map +1 -1
- package/lib/commands/blockchain/confirmOp.js +12 -52
- package/lib/commands/blockchain/confirmOp.js.map +1 -1
- package/lib/commands/blockchain/derivation.js +31 -33
- package/lib/commands/blockchain/derivation.js.map +1 -1
- package/lib/commands/blockchain/estimateMaxSpendable.js +27 -56
- package/lib/commands/blockchain/estimateMaxSpendable.js.map +1 -1
- package/lib/commands/blockchain/generateTestScanAccounts.js +29 -37
- package/lib/commands/blockchain/generateTestScanAccounts.js.map +1 -1
- package/lib/commands/blockchain/generateTestTransaction.js +70 -96
- package/lib/commands/blockchain/generateTestTransaction.js.map +1 -1
- package/lib/commands/blockchain/getAddress.js +20 -24
- package/lib/commands/blockchain/getAddress.js.map +1 -1
- package/lib/commands/blockchain/getTransactionStatus.js +31 -69
- package/lib/commands/blockchain/getTransactionStatus.js.map +1 -1
- package/lib/commands/blockchain/receive.js +14 -42
- package/lib/commands/blockchain/receive.js.map +1 -1
- package/lib/commands/blockchain/satstack.js +30 -33
- package/lib/commands/blockchain/satstack.js.map +1 -1
- package/lib/commands/blockchain/satstackStatus.js +4 -5
- package/lib/commands/blockchain/satstackStatus.js.map +1 -1
- package/lib/commands/blockchain/scanDescriptors.js +8 -14
- package/lib/commands/blockchain/scanDescriptors.js.map +1 -1
- package/lib/commands/blockchain/send.js +61 -90
- package/lib/commands/blockchain/send.js.map +1 -1
- package/lib/commands/blockchain/signMessage.d.ts +1 -1
- package/lib/commands/blockchain/signMessage.js +15 -40
- package/lib/commands/blockchain/signMessage.js.map +1 -1
- package/lib/commands/blockchain/sync.js +27 -120
- package/lib/commands/blockchain/sync.js.map +1 -1
- package/lib/commands/blockchain/testDetectOpCollision.js +15 -48
- package/lib/commands/blockchain/testDetectOpCollision.js.map +1 -1
- package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js +37 -86
- package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js.map +1 -1
- package/lib/commands/device/app.js +42 -76
- package/lib/commands/device/app.js.map +1 -1
- package/lib/commands/device/appUninstallAll.d.ts +1 -1
- package/lib/commands/device/appUninstallAll.js +22 -29
- package/lib/commands/device/appUninstallAll.js.map +1 -1
- package/lib/commands/device/appsCheckAllAppVersions.js +208 -361
- package/lib/commands/device/appsCheckAllAppVersions.js.map +1 -1
- package/lib/commands/device/appsInstallAll.js +15 -24
- package/lib/commands/device/appsInstallAll.js.map +1 -1
- package/lib/commands/device/appsUpdateTestAll.js +69 -80
- package/lib/commands/device/appsUpdateTestAll.js.map +1 -1
- package/lib/commands/device/cleanSpeculos.js +4 -4
- package/lib/commands/device/cleanSpeculos.js.map +1 -1
- package/lib/commands/device/customLockScreenFetch.js +37 -84
- package/lib/commands/device/customLockScreenFetch.js.map +1 -1
- package/lib/commands/device/customLockScreenFetchAndRestore.js +46 -110
- package/lib/commands/device/customLockScreenFetchAndRestore.js.map +1 -1
- package/lib/commands/device/customLockScreenFetchHash.js +5 -7
- package/lib/commands/device/customLockScreenFetchHash.js.map +1 -1
- package/lib/commands/device/customLockScreenLoad.js +25 -72
- package/lib/commands/device/customLockScreenLoad.js.map +1 -1
- package/lib/commands/device/customLockScreenRemove.js +5 -7
- package/lib/commands/device/customLockScreenRemove.js.map +1 -1
- package/lib/commands/device/devDeviceAppsScenario.js +33 -65
- package/lib/commands/device/devDeviceAppsScenario.js.map +1 -1
- package/lib/commands/device/deviceAppVersion.js +5 -8
- package/lib/commands/device/deviceAppVersion.js.map +1 -1
- package/lib/commands/device/deviceInfo.js +5 -8
- package/lib/commands/device/deviceInfo.js.map +1 -1
- package/lib/commands/device/deviceSDKFirmwareUpdate.js +22 -68
- package/lib/commands/device/deviceSDKFirmwareUpdate.js.map +1 -1
- package/lib/commands/device/deviceSDKGetBatteryStatuses.js +7 -8
- package/lib/commands/device/deviceSDKGetBatteryStatuses.js.map +1 -1
- package/lib/commands/device/deviceSDKGetDeviceInfo.js +6 -7
- package/lib/commands/device/deviceSDKGetDeviceInfo.js.map +1 -1
- package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js +8 -9
- package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js.map +1 -1
- package/lib/commands/device/deviceVersion.js +5 -8
- package/lib/commands/device/deviceVersion.js.map +1 -1
- package/lib/commands/device/discoverDevices.js +15 -50
- package/lib/commands/device/discoverDevices.js.map +1 -1
- package/lib/commands/device/firmwareRepair.js +3 -6
- package/lib/commands/device/firmwareRepair.js.map +1 -1
- package/lib/commands/device/firmwareUpdate.js +63 -123
- package/lib/commands/device/firmwareUpdate.js.map +1 -1
- package/lib/commands/device/genuineCheck.js +7 -12
- package/lib/commands/device/genuineCheck.js.map +1 -1
- package/lib/commands/device/getBatteryStatus.js +5 -9
- package/lib/commands/device/getBatteryStatus.js.map +1 -1
- package/lib/commands/device/getDeviceRunningMode.js +7 -10
- package/lib/commands/device/getDeviceRunningMode.js.map +1 -1
- package/lib/commands/device/i18n.js +27 -79
- package/lib/commands/device/i18n.js.map +1 -1
- package/lib/commands/device/listApps.d.ts +1 -1
- package/lib/commands/device/listApps.js +7 -12
- package/lib/commands/device/listApps.js.map +1 -1
- package/lib/commands/device/managerListApps.js +21 -28
- package/lib/commands/device/managerListApps.js.map +1 -1
- package/lib/commands/device/proxy.js +242 -350
- package/lib/commands/device/proxy.js.map +1 -1
- package/lib/commands/device/reinstallConfigurationConsent.js +36 -126
- package/lib/commands/device/reinstallConfigurationConsent.js.map +1 -1
- package/lib/commands/device/repl.js +5 -10
- package/lib/commands/device/repl.js.map +1 -1
- package/lib/commands/device/speculosList.js +12 -58
- package/lib/commands/device/speculosList.js.map +1 -1
- package/lib/commands/live/balanceHistory.js +44 -79
- package/lib/commands/live/balanceHistory.js.map +1 -1
- package/lib/commands/live/countervalues.js +111 -207
- package/lib/commands/live/countervalues.js.map +1 -1
- package/lib/commands/live/envs.js +4 -6
- package/lib/commands/live/envs.js.map +1 -1
- package/lib/commands/live/exportAccounts.js +30 -56
- package/lib/commands/live/exportAccounts.js.map +1 -1
- package/lib/commands/live/ledgerKeyRingProtocol.d.ts +1 -1
- package/lib/commands/live/ledgerKeyRingProtocol.js +63 -103
- package/lib/commands/live/ledgerKeyRingProtocol.js.map +1 -1
- package/lib/commands/live/ledgerSync.js +20 -60
- package/lib/commands/live/ledgerSync.js.map +1 -1
- package/lib/commands/live/liveData.js +34 -60
- package/lib/commands/live/liveData.js.map +1 -1
- package/lib/commands/live/portfolio.js +68 -98
- package/lib/commands/live/portfolio.js.map +1 -1
- package/lib/commands/live/synchronousOnboarding.js +6 -9
- package/lib/commands/live/synchronousOnboarding.js.map +1 -1
- package/lib/commands/live/user.js +4 -4
- package/lib/commands/live/user.js.map +1 -1
- package/lib/commands/live/version.js +2 -4
- package/lib/commands/live/version.js.map +1 -1
- package/lib/commands/ptx/swap.d.ts.map +1 -1
- package/lib/commands/ptx/swap.js +194 -280
- package/lib/commands/ptx/swap.js.map +1 -1
- package/lib/commands-index.d.ts +9 -9
- package/lib/commands-index.js +64 -64
- package/lib/commands-index.js.map +1 -1
- package/lib/live-common-setup-base.js +28 -48
- package/lib/live-common-setup-base.js.map +1 -1
- package/lib/live-common-setup.js +66 -123
- package/lib/live-common-setup.js.map +1 -1
- package/lib/qr.js +6 -10
- package/lib/qr.js.map +1 -1
- package/lib/scan.js +84 -92
- package/lib/scan.js.map +1 -1
- package/lib/signedOperation.js +6 -6
- package/lib/signedOperation.js.map +1 -1
- package/lib/stream.js +57 -68
- package/lib/stream.js.map +1 -1
- package/lib/transaction.js +60 -142
- package/lib/transaction.js.map +1 -1
- package/package.json +7 -7
|
@@ -1,91 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __values = (this && this.__values) || function(o) {
|
|
50
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
51
|
-
if (m) return m.call(o);
|
|
52
|
-
if (o && typeof o.length === "number") return {
|
|
53
|
-
next: function () {
|
|
54
|
-
if (o && i >= o.length) o = void 0;
|
|
55
|
-
return { value: o && o[i++], done: !o };
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
59
|
-
};
|
|
60
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
61
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
62
4
|
};
|
|
63
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
64
6
|
/* eslint-disable no-console */
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
7
|
+
const rxjs_1 = require("rxjs");
|
|
8
|
+
const operators_1 = require("rxjs/operators");
|
|
9
|
+
const index_1 = require("@ledgerhq/live-common/currencies/index");
|
|
10
|
+
const index_2 = require("@ledgerhq/live-common/bridge/index");
|
|
11
|
+
const live_env_1 = require("@ledgerhq/live-env");
|
|
12
|
+
const promise_1 = require("@ledgerhq/live-common/promise");
|
|
13
|
+
const cache_1 = require("@ledgerhq/live-common/bridge/cache");
|
|
14
|
+
const engine_1 = require("@ledgerhq/live-common/bot/engine");
|
|
15
|
+
const specs_1 = __importDefault(require("@ledgerhq/live-common/generated/specs"));
|
|
16
|
+
const speculos_1 = require("@ledgerhq/live-common/load/speculos");
|
|
17
|
+
const index_3 = require("@ledgerhq/live-common/account/index");
|
|
18
|
+
const logic_1 = require("@ledgerhq/live-countervalues/logic");
|
|
19
|
+
const CONCURRENT = parseInt(process.env.CONCURRENCY || "2", 10);
|
|
20
|
+
const ONLY_CURRENCIES = process.env.ONLY_CURRENCIES
|
|
79
21
|
? process.env.ONLY_CURRENCIES.split(",")
|
|
80
|
-
.map(
|
|
22
|
+
.map(c => c.trim())
|
|
81
23
|
.filter(Boolean)
|
|
82
24
|
: null;
|
|
83
25
|
// TODO improve botTransfer by only using "allSpecs" and introduce a "transferMutation" in the specs for all spec to define how to transfer funds out (as well as UNDELEGATING funds)
|
|
84
26
|
function getImplicitDeviceAction(currency, forSubAccount) {
|
|
85
|
-
for (
|
|
86
|
-
|
|
87
|
-
for (
|
|
88
|
-
|
|
27
|
+
for (const k in specs_1.default) {
|
|
28
|
+
const familySpec = specs_1.default[k];
|
|
29
|
+
for (const c in familySpec) {
|
|
30
|
+
const spec = familySpec[c];
|
|
89
31
|
if (spec.currency === currency) {
|
|
90
32
|
if (forSubAccount && spec.genericDeviceActionForSubAccountTransfers) {
|
|
91
33
|
return spec.genericDeviceActionForSubAccountTransfers;
|
|
@@ -95,341 +37,226 @@ function getImplicitDeviceAction(currency, forSubAccount) {
|
|
|
95
37
|
}
|
|
96
38
|
}
|
|
97
39
|
}
|
|
98
|
-
|
|
40
|
+
const split = process.env.FUNDS_SPLIT && parseInt(process.env.FUNDS_SPLIT, 10);
|
|
99
41
|
exports.default = {
|
|
100
42
|
description: "transfer funds from one seed (SEED) to another (SEED_RECIPIENT)",
|
|
101
43
|
args: [],
|
|
102
|
-
job:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
saveData
|
|
44
|
+
job: () => {
|
|
45
|
+
const localCache = {};
|
|
46
|
+
const cache = (0, cache_1.makeBridgeCacheSystem)({
|
|
47
|
+
saveData(c, d) {
|
|
106
48
|
localCache[c.id] = d;
|
|
107
49
|
return Promise.resolve();
|
|
108
50
|
},
|
|
109
|
-
getData
|
|
51
|
+
getData(c) {
|
|
110
52
|
return Promise.resolve(localCache[c.id]);
|
|
111
53
|
},
|
|
112
54
|
});
|
|
113
|
-
function getAllRecipients(currencies) {
|
|
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
|
-
syncConfig: {
|
|
146
|
-
paginationConfig: {},
|
|
147
|
-
},
|
|
148
|
-
})
|
|
149
|
-
.pipe((0, operators_1.filter)(function (e) { return e.type === "discovered"; }), (0, operators_1.first)(), (0, operators_1.timeout)({
|
|
150
|
-
each: (0, live_env_1.getEnv)("BOT_TIMEOUT_SCAN_ACCOUNTS"),
|
|
151
|
-
with: function () { return (0, rxjs_1.throwError)(function () { return new Error("scan account timeout"); }); },
|
|
152
|
-
}), (0, operators_1.map)(function (e) { return e.account.freshAddress; }), (0, operators_1.catchError)(function (err) {
|
|
153
|
-
console.error("couldn't infer address for a " + currency.id + " account", err);
|
|
154
|
-
return (0, rxjs_1.of)(null);
|
|
155
|
-
})))];
|
|
156
|
-
case 3:
|
|
157
|
-
maybeAddress = _a.sent();
|
|
158
|
-
if (maybeAddress) {
|
|
159
|
-
recipientsPerCurrencyId.set(currency.id, maybeAddress);
|
|
160
|
-
}
|
|
161
|
-
return [3 /*break*/, 6];
|
|
162
|
-
case 4:
|
|
163
|
-
e_1 = _a.sent();
|
|
164
|
-
console.error("Something went wrong on sending on " + currency.id, e_1);
|
|
165
|
-
return [3 /*break*/, 6];
|
|
166
|
-
case 5:
|
|
167
|
-
if (device)
|
|
168
|
-
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
169
|
-
return [7 /*endfinally*/];
|
|
170
|
-
case 6: return [2 /*return*/];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}); })];
|
|
174
|
-
case 1:
|
|
175
|
-
_a.sent();
|
|
176
|
-
(0, live_env_1.setEnv)("SEED", prevSeed);
|
|
177
|
-
return [2 /*return*/, recipientsPerCurrencyId];
|
|
55
|
+
async function getAllRecipients(currencies) {
|
|
56
|
+
const prevSeed = (0, live_env_1.getEnv)("SEED");
|
|
57
|
+
const { SEED_RECIPIENT } = process.env;
|
|
58
|
+
if (SEED_RECIPIENT) {
|
|
59
|
+
(0, live_env_1.setEnv)("SEED", SEED_RECIPIENT);
|
|
60
|
+
}
|
|
61
|
+
const recipientsPerCurrencyId = new Map();
|
|
62
|
+
await (0, promise_1.promiseAllBatched)(CONCURRENT, currencies, async (currency) => {
|
|
63
|
+
let device;
|
|
64
|
+
try {
|
|
65
|
+
const r = await (0, speculos_1.createImplicitSpeculos)(`speculos:nanos:${currency.id}`);
|
|
66
|
+
if (!r)
|
|
67
|
+
return;
|
|
68
|
+
device = r.device;
|
|
69
|
+
await cache.prepareCurrency(currency);
|
|
70
|
+
const maybeAddress = await (0, rxjs_1.firstValueFrom)((0, index_2.getCurrencyBridge)(currency)
|
|
71
|
+
.scanAccounts({
|
|
72
|
+
currency,
|
|
73
|
+
deviceId: device.id,
|
|
74
|
+
syncConfig: {
|
|
75
|
+
paginationConfig: {},
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
.pipe((0, operators_1.filter)(e => e.type === "discovered"), (0, operators_1.first)(), (0, operators_1.timeout)({
|
|
79
|
+
each: (0, live_env_1.getEnv)("BOT_TIMEOUT_SCAN_ACCOUNTS"),
|
|
80
|
+
with: () => (0, rxjs_1.throwError)(() => new Error("scan account timeout")),
|
|
81
|
+
}), (0, operators_1.map)(e => e.account.freshAddress), (0, operators_1.catchError)(err => {
|
|
82
|
+
console.error("couldn't infer address for a " + currency.id + " account", err);
|
|
83
|
+
return (0, rxjs_1.of)(null);
|
|
84
|
+
})));
|
|
85
|
+
if (maybeAddress) {
|
|
86
|
+
recipientsPerCurrencyId.set(currency.id, maybeAddress);
|
|
178
87
|
}
|
|
179
|
-
}
|
|
88
|
+
}
|
|
89
|
+
catch (e) {
|
|
90
|
+
console.error("Something went wrong on sending on " + currency.id, e);
|
|
91
|
+
}
|
|
92
|
+
finally {
|
|
93
|
+
if (device)
|
|
94
|
+
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
95
|
+
}
|
|
180
96
|
});
|
|
97
|
+
(0, live_env_1.setEnv)("SEED", prevSeed);
|
|
98
|
+
return recipientsPerCurrencyId;
|
|
181
99
|
}
|
|
182
|
-
function botPortfolio(currencies) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
accounts.push(e.account);
|
|
219
|
-
}
|
|
220
|
-
})))];
|
|
221
|
-
case 2:
|
|
222
|
-
_a.sent();
|
|
223
|
-
return [3 /*break*/, 5];
|
|
224
|
-
case 3:
|
|
225
|
-
e_2 = _a.sent();
|
|
226
|
-
console.error("Something went wrong on portfolio of " + currency.id, e_2);
|
|
227
|
-
return [3 /*break*/, 5];
|
|
228
|
-
case 4:
|
|
229
|
-
if (device)
|
|
230
|
-
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
231
|
-
return [7 /*endfinally*/];
|
|
232
|
-
case 5: return [2 /*return*/];
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
}); })];
|
|
236
|
-
case 1:
|
|
237
|
-
_a.sent();
|
|
238
|
-
return [2 /*return*/, accounts];
|
|
239
|
-
}
|
|
240
|
-
});
|
|
100
|
+
async function botPortfolio(currencies) {
|
|
101
|
+
const accounts = [];
|
|
102
|
+
await (0, promise_1.promiseAllBatched)(CONCURRENT, currencies, async (currency) => {
|
|
103
|
+
let device;
|
|
104
|
+
try {
|
|
105
|
+
const r = await (0, speculos_1.createImplicitSpeculos)(`speculos:nanos:${currency.id}`);
|
|
106
|
+
if (!r)
|
|
107
|
+
return;
|
|
108
|
+
device = r.device;
|
|
109
|
+
await (0, rxjs_1.firstValueFrom)((0, index_2.getCurrencyBridge)(currency)
|
|
110
|
+
.scanAccounts({
|
|
111
|
+
currency,
|
|
112
|
+
deviceId: r.device.id,
|
|
113
|
+
syncConfig: {
|
|
114
|
+
paginationConfig: {},
|
|
115
|
+
},
|
|
116
|
+
})
|
|
117
|
+
.pipe((0, operators_1.timeout)({
|
|
118
|
+
each: (0, live_env_1.getEnv)("BOT_TIMEOUT_SCAN_ACCOUNTS"),
|
|
119
|
+
with: () => (0, rxjs_1.throwError)(() => new Error("scan account timeout")),
|
|
120
|
+
}), (0, operators_1.catchError)(e => {
|
|
121
|
+
console.error("scan accounts failed for " + currency.id, e);
|
|
122
|
+
return (0, rxjs_1.from)([]);
|
|
123
|
+
}), (0, operators_1.tap)(e => {
|
|
124
|
+
if (e.type === "discovered") {
|
|
125
|
+
accounts.push(e.account);
|
|
126
|
+
}
|
|
127
|
+
})));
|
|
128
|
+
}
|
|
129
|
+
catch (e) {
|
|
130
|
+
console.error("Something went wrong on portfolio of " + currency.id, e);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (device)
|
|
134
|
+
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
135
|
+
}
|
|
241
136
|
});
|
|
137
|
+
return accounts;
|
|
242
138
|
}
|
|
243
|
-
|
|
244
|
-
function sendAllFunds(accounts, recipientsPerCurrencyId) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
to: countervalue,
|
|
288
|
-
value: subAccount.balance.toNumber(),
|
|
289
|
-
});
|
|
290
|
-
if (cv && cv > cvUSDThreshold) {
|
|
291
|
-
plannedTransactions.push(accountBridge.updateTransaction(accountBridge.createTransaction(account), __assign(__assign({ recipient: recipient }, (split && split > 1
|
|
292
|
-
? {
|
|
293
|
-
amount: subAccount.balance.div(split).integerValue(),
|
|
294
|
-
}
|
|
295
|
-
: { useAllAmount: true })), { subAccountId: subAccount.id })));
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
plannedTransactions.push(accountBridge.updateTransaction(accountBridge.createTransaction(account), __assign({ recipient: recipient }, (split && split > 1
|
|
299
|
-
? { amount: account.spendableBalance.div(split).integerValue() }
|
|
300
|
-
: { useAllAmount: true }))));
|
|
301
|
-
_d.label = 1;
|
|
302
|
-
case 1:
|
|
303
|
-
_d.trys.push([1, 18, 19, 20]);
|
|
304
|
-
return [4 /*yield*/, (0, speculos_1.createImplicitSpeculos)("speculos:nanos:".concat(currency.id))];
|
|
305
|
-
case 2:
|
|
306
|
-
r = _d.sent();
|
|
307
|
-
if (!r) {
|
|
308
|
-
console.warn("couldn't create a speculos transport for " + currency.id);
|
|
309
|
-
return [2 /*return*/];
|
|
310
|
-
}
|
|
311
|
-
device = r.device;
|
|
312
|
-
_d.label = 3;
|
|
313
|
-
case 3:
|
|
314
|
-
_d.trys.push([3, 15, 16, 17]);
|
|
315
|
-
plannedTransactions_1 = __values(plannedTransactions), plannedTransactions_1_1 = plannedTransactions_1.next();
|
|
316
|
-
_d.label = 4;
|
|
317
|
-
case 4:
|
|
318
|
-
if (!!plannedTransactions_1_1.done) return [3 /*break*/, 14];
|
|
319
|
-
tx = plannedTransactions_1_1.value;
|
|
320
|
-
_d.label = 5;
|
|
321
|
-
case 5:
|
|
322
|
-
_d.trys.push([5, 12, , 13]);
|
|
323
|
-
deviceAction = getImplicitDeviceAction(account.currency, "subAccountId" in tx);
|
|
324
|
-
if (!deviceAction) {
|
|
325
|
-
throw new Error("no spec found for currency " + account.currency.id);
|
|
326
|
-
}
|
|
327
|
-
return [4 /*yield*/, accountBridge.prepareTransaction(account, tx)];
|
|
328
|
-
case 6:
|
|
329
|
-
transaction = _d.sent();
|
|
330
|
-
return [4 /*yield*/, accountBridge.getTransactionStatus(account, transaction)];
|
|
331
|
-
case 7:
|
|
332
|
-
statusCommon = _d.sent();
|
|
333
|
-
if (Object.keys(statusCommon.errors).length !== 0) {
|
|
334
|
-
return [3 /*break*/, 13];
|
|
335
|
-
}
|
|
336
|
-
status = __assign(__assign({}, statusCommon), { family: transaction.family });
|
|
337
|
-
return [4 /*yield*/, (0, rxjs_1.firstValueFrom)(accountBridge
|
|
338
|
-
.signOperation({
|
|
339
|
-
account: account,
|
|
340
|
-
transaction: transaction,
|
|
341
|
-
deviceId: device.id,
|
|
342
|
-
})
|
|
343
|
-
.pipe((0, engine_1.autoSignTransaction)({
|
|
344
|
-
transport: device.transport,
|
|
345
|
-
deviceAction: deviceAction,
|
|
346
|
-
appCandidate: r.appCandidate,
|
|
347
|
-
account: account,
|
|
348
|
-
transaction: transaction,
|
|
349
|
-
status: status,
|
|
350
|
-
disableStrictStepValueValidation: true, // we transfer the funds without validating the field values
|
|
351
|
-
}), (0, operators_1.first)(function (e) { return e.type === "signed"; }), (0, operators_1.map)(function (e) { return e.signedOperation; })))];
|
|
352
|
-
case 8:
|
|
353
|
-
signedOperation = _d.sent();
|
|
354
|
-
if (!(0, live_env_1.getEnv)("DISABLE_TRANSACTION_BROADCAST")) return [3 /*break*/, 9];
|
|
355
|
-
_a = signedOperation.operation;
|
|
356
|
-
return [3 /*break*/, 11];
|
|
357
|
-
case 9: return [4 /*yield*/, accountBridge.broadcast({
|
|
358
|
-
account: account,
|
|
359
|
-
signedOperation: signedOperation,
|
|
360
|
-
})];
|
|
361
|
-
case 10:
|
|
362
|
-
_a = _d.sent();
|
|
363
|
-
_d.label = 11;
|
|
364
|
-
case 11:
|
|
365
|
-
optimisticOperation = _a;
|
|
366
|
-
console.log((0, index_3.formatOperation)(account)(optimisticOperation));
|
|
367
|
-
return [3 /*break*/, 13];
|
|
368
|
-
case 12:
|
|
369
|
-
e_3 = _d.sent();
|
|
370
|
-
console.error("Something went wrong on trying to send from " + account.id, tx, e_3);
|
|
371
|
-
return [3 /*break*/, 13];
|
|
372
|
-
case 13:
|
|
373
|
-
plannedTransactions_1_1 = plannedTransactions_1.next();
|
|
374
|
-
return [3 /*break*/, 4];
|
|
375
|
-
case 14: return [3 /*break*/, 17];
|
|
376
|
-
case 15:
|
|
377
|
-
e_4_1 = _d.sent();
|
|
378
|
-
e_4 = { error: e_4_1 };
|
|
379
|
-
return [3 /*break*/, 17];
|
|
380
|
-
case 16:
|
|
381
|
-
try {
|
|
382
|
-
if (plannedTransactions_1_1 && !plannedTransactions_1_1.done && (_b = plannedTransactions_1.return)) _b.call(plannedTransactions_1);
|
|
383
|
-
}
|
|
384
|
-
finally { if (e_4) throw e_4.error; }
|
|
385
|
-
return [7 /*endfinally*/];
|
|
386
|
-
case 17: return [3 /*break*/, 20];
|
|
387
|
-
case 18:
|
|
388
|
-
e_5 = _d.sent();
|
|
389
|
-
console.error("Something went wrong on account " + account.id, e_5);
|
|
390
|
-
return [3 /*break*/, 20];
|
|
391
|
-
case 19:
|
|
392
|
-
if (device)
|
|
393
|
-
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
394
|
-
return [7 /*endfinally*/];
|
|
395
|
-
case 20: return [2 /*return*/];
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
}); })];
|
|
399
|
-
case 2:
|
|
400
|
-
_a.sent();
|
|
401
|
-
return [2 /*return*/];
|
|
139
|
+
const cvUSDThreshold = 10;
|
|
140
|
+
async function sendAllFunds(accounts, recipientsPerCurrencyId) {
|
|
141
|
+
const countervalue = (0, index_1.getFiatCurrencyByTicker)("USD");
|
|
142
|
+
const countervaluesState = await (0, logic_1.loadCountervalues)(logic_1.initialState, {
|
|
143
|
+
trackingPairs: (0, logic_1.inferTrackingPairForAccounts)(accounts, countervalue),
|
|
144
|
+
autofillGaps: true,
|
|
145
|
+
refreshRate: 60000,
|
|
146
|
+
marketCapBatchingAfterRank: 20,
|
|
147
|
+
});
|
|
148
|
+
await (0, promise_1.promiseAllBatched)(CONCURRENT, accounts, async (account) => {
|
|
149
|
+
const { currency } = account;
|
|
150
|
+
const cv = (0, logic_1.calculate)(countervaluesState, {
|
|
151
|
+
from: currency,
|
|
152
|
+
to: countervalue,
|
|
153
|
+
value: account.balance.toNumber(),
|
|
154
|
+
});
|
|
155
|
+
if (!cv || cv < cvUSDThreshold) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
const recipient = recipientsPerCurrencyId.get(currency.id);
|
|
159
|
+
if (!recipient) {
|
|
160
|
+
console.log("no recipient to empty account " + account.id);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
const accountBridge = (0, index_2.getAccountBridge)(account);
|
|
164
|
+
// TODO in case of cosmos & other funds that can be delegated, we need to also schedule these txs first..
|
|
165
|
+
const plannedTransactions = [];
|
|
166
|
+
// FIXME better value than this arbitrary one: calc countervalues
|
|
167
|
+
account.subAccounts?.forEach(subAccount => {
|
|
168
|
+
const cv = (0, logic_1.calculate)(countervaluesState, {
|
|
169
|
+
from: account.currency,
|
|
170
|
+
to: countervalue,
|
|
171
|
+
value: subAccount.balance.toNumber(),
|
|
172
|
+
});
|
|
173
|
+
if (cv && cv > cvUSDThreshold) {
|
|
174
|
+
plannedTransactions.push(accountBridge.updateTransaction(accountBridge.createTransaction(account), {
|
|
175
|
+
recipient,
|
|
176
|
+
...(split && split > 1
|
|
177
|
+
? {
|
|
178
|
+
amount: subAccount.balance.div(split).integerValue(),
|
|
179
|
+
}
|
|
180
|
+
: { useAllAmount: true }),
|
|
181
|
+
subAccountId: subAccount.id,
|
|
182
|
+
}));
|
|
402
183
|
}
|
|
403
184
|
});
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
185
|
+
plannedTransactions.push(accountBridge.updateTransaction(accountBridge.createTransaction(account), {
|
|
186
|
+
recipient,
|
|
187
|
+
...(split && split > 1
|
|
188
|
+
? { amount: account.spendableBalance.div(split).integerValue() }
|
|
189
|
+
: { useAllAmount: true }),
|
|
190
|
+
}));
|
|
191
|
+
let device;
|
|
192
|
+
try {
|
|
193
|
+
const r = await (0, speculos_1.createImplicitSpeculos)(`speculos:nanos:${currency.id}`);
|
|
194
|
+
if (!r) {
|
|
195
|
+
console.warn("couldn't create a speculos transport for " + currency.id);
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
device = r.device;
|
|
199
|
+
for (const tx of plannedTransactions) {
|
|
200
|
+
try {
|
|
201
|
+
const deviceAction = getImplicitDeviceAction(account.currency, "subAccountId" in tx);
|
|
202
|
+
if (!deviceAction) {
|
|
203
|
+
throw new Error("no spec found for currency " + account.currency.id);
|
|
204
|
+
}
|
|
205
|
+
const transaction = await accountBridge.prepareTransaction(account, tx);
|
|
206
|
+
const statusCommon = await accountBridge.getTransactionStatus(account, transaction);
|
|
207
|
+
if (Object.keys(statusCommon.errors).length !== 0) {
|
|
208
|
+
continue;
|
|
415
209
|
}
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
210
|
+
const status = { ...statusCommon, family: transaction.family };
|
|
211
|
+
const signedOperation = await (0, rxjs_1.firstValueFrom)(accountBridge
|
|
212
|
+
.signOperation({
|
|
213
|
+
account,
|
|
214
|
+
transaction,
|
|
215
|
+
deviceId: device.id,
|
|
216
|
+
})
|
|
217
|
+
.pipe((0, engine_1.autoSignTransaction)({
|
|
218
|
+
transport: device.transport,
|
|
219
|
+
deviceAction,
|
|
220
|
+
appCandidate: r.appCandidate,
|
|
221
|
+
account,
|
|
222
|
+
transaction,
|
|
223
|
+
status,
|
|
224
|
+
disableStrictStepValueValidation: true, // we transfer the funds without validating the field values
|
|
225
|
+
}), (0, operators_1.first)((e) => e.type === "signed"), (0, operators_1.map)(e => e.signedOperation)));
|
|
226
|
+
const optimisticOperation = (0, live_env_1.getEnv)("DISABLE_TRANSACTION_BROADCAST")
|
|
227
|
+
? signedOperation.operation
|
|
228
|
+
: await accountBridge.broadcast({
|
|
229
|
+
account,
|
|
230
|
+
signedOperation,
|
|
231
|
+
});
|
|
232
|
+
console.log((0, index_3.formatOperation)(account)(optimisticOperation));
|
|
233
|
+
}
|
|
234
|
+
catch (e) {
|
|
235
|
+
console.error("Something went wrong on trying to send from " + account.id, tx, e);
|
|
236
|
+
}
|
|
429
237
|
}
|
|
430
|
-
}
|
|
238
|
+
}
|
|
239
|
+
catch (e) {
|
|
240
|
+
console.error("Something went wrong on account " + account.id, e);
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
if (device)
|
|
244
|
+
(0, speculos_1.releaseSpeculosDevice)(device.id);
|
|
245
|
+
}
|
|
431
246
|
});
|
|
432
247
|
}
|
|
248
|
+
async function main() {
|
|
249
|
+
let currencies = (0, index_1.listSupportedCurrencies)();
|
|
250
|
+
if (ONLY_CURRENCIES) {
|
|
251
|
+
currencies = currencies.filter(c => ONLY_CURRENCIES.includes(c.id));
|
|
252
|
+
}
|
|
253
|
+
currencies.sort(() => Math.random() - 0.5);
|
|
254
|
+
const recipientsPerCurrencyId = await getAllRecipients(currencies);
|
|
255
|
+
console.log(Array.from(recipientsPerCurrencyId.keys()).length + " RECIPIENTS FETCHED");
|
|
256
|
+
const accounts = await botPortfolio(currencies);
|
|
257
|
+
console.log(`BOT PORTFOLIO FETCHED ${accounts.length} accounts`);
|
|
258
|
+
await sendAllFunds(accounts, recipientsPerCurrencyId);
|
|
259
|
+
}
|
|
433
260
|
return (0, rxjs_1.from)(main());
|
|
434
261
|
},
|
|
435
262
|
};
|