@ledgerhq/live-cli 24.11.0-nightly.3 → 24.11.1-next.0

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.
Files changed (152) hide show
  1. package/lib/cli.js +33 -63
  2. package/lib/cli.js.map +1 -1
  3. package/lib/commands/blockchain/bot.js +7 -7
  4. package/lib/commands/blockchain/bot.js.map +1 -1
  5. package/lib/commands/blockchain/botPortfolio.js +22 -26
  6. package/lib/commands/blockchain/botPortfolio.js.map +1 -1
  7. package/lib/commands/blockchain/botTransfer.js +219 -392
  8. package/lib/commands/blockchain/botTransfer.js.map +1 -1
  9. package/lib/commands/blockchain/broadcast.js +11 -42
  10. package/lib/commands/blockchain/broadcast.js.map +1 -1
  11. package/lib/commands/blockchain/confirmOp.js +12 -52
  12. package/lib/commands/blockchain/confirmOp.js.map +1 -1
  13. package/lib/commands/blockchain/derivation.js +31 -33
  14. package/lib/commands/blockchain/derivation.js.map +1 -1
  15. package/lib/commands/blockchain/estimateMaxSpendable.js +27 -56
  16. package/lib/commands/blockchain/estimateMaxSpendable.js.map +1 -1
  17. package/lib/commands/blockchain/generateTestScanAccounts.js +29 -37
  18. package/lib/commands/blockchain/generateTestScanAccounts.js.map +1 -1
  19. package/lib/commands/blockchain/generateTestTransaction.js +70 -96
  20. package/lib/commands/blockchain/generateTestTransaction.js.map +1 -1
  21. package/lib/commands/blockchain/getAddress.js +20 -24
  22. package/lib/commands/blockchain/getAddress.js.map +1 -1
  23. package/lib/commands/blockchain/getTransactionStatus.js +31 -69
  24. package/lib/commands/blockchain/getTransactionStatus.js.map +1 -1
  25. package/lib/commands/blockchain/receive.js +14 -42
  26. package/lib/commands/blockchain/receive.js.map +1 -1
  27. package/lib/commands/blockchain/satstack.js +30 -33
  28. package/lib/commands/blockchain/satstack.js.map +1 -1
  29. package/lib/commands/blockchain/satstackStatus.js +4 -5
  30. package/lib/commands/blockchain/satstackStatus.js.map +1 -1
  31. package/lib/commands/blockchain/scanDescriptors.js +8 -14
  32. package/lib/commands/blockchain/scanDescriptors.js.map +1 -1
  33. package/lib/commands/blockchain/send.js +61 -90
  34. package/lib/commands/blockchain/send.js.map +1 -1
  35. package/lib/commands/blockchain/signMessage.d.ts +1 -1
  36. package/lib/commands/blockchain/signMessage.js +15 -40
  37. package/lib/commands/blockchain/signMessage.js.map +1 -1
  38. package/lib/commands/blockchain/sync.js +27 -120
  39. package/lib/commands/blockchain/sync.js.map +1 -1
  40. package/lib/commands/blockchain/testDetectOpCollision.js +15 -48
  41. package/lib/commands/blockchain/testDetectOpCollision.js.map +1 -1
  42. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js +37 -86
  43. package/lib/commands/blockchain/testGetTrustedInputFromTxHash.js.map +1 -1
  44. package/lib/commands/device/app.js +42 -76
  45. package/lib/commands/device/app.js.map +1 -1
  46. package/lib/commands/device/appUninstallAll.d.ts +1 -1
  47. package/lib/commands/device/appUninstallAll.js +22 -29
  48. package/lib/commands/device/appUninstallAll.js.map +1 -1
  49. package/lib/commands/device/appsCheckAllAppVersions.js +208 -361
  50. package/lib/commands/device/appsCheckAllAppVersions.js.map +1 -1
  51. package/lib/commands/device/appsInstallAll.js +15 -24
  52. package/lib/commands/device/appsInstallAll.js.map +1 -1
  53. package/lib/commands/device/appsUpdateTestAll.js +69 -80
  54. package/lib/commands/device/appsUpdateTestAll.js.map +1 -1
  55. package/lib/commands/device/cleanSpeculos.js +4 -4
  56. package/lib/commands/device/cleanSpeculos.js.map +1 -1
  57. package/lib/commands/device/customLockScreenFetch.js +37 -84
  58. package/lib/commands/device/customLockScreenFetch.js.map +1 -1
  59. package/lib/commands/device/customLockScreenFetchAndRestore.js +46 -110
  60. package/lib/commands/device/customLockScreenFetchAndRestore.js.map +1 -1
  61. package/lib/commands/device/customLockScreenFetchHash.js +5 -7
  62. package/lib/commands/device/customLockScreenFetchHash.js.map +1 -1
  63. package/lib/commands/device/customLockScreenLoad.js +25 -72
  64. package/lib/commands/device/customLockScreenLoad.js.map +1 -1
  65. package/lib/commands/device/customLockScreenRemove.js +5 -7
  66. package/lib/commands/device/customLockScreenRemove.js.map +1 -1
  67. package/lib/commands/device/devDeviceAppsScenario.js +33 -65
  68. package/lib/commands/device/devDeviceAppsScenario.js.map +1 -1
  69. package/lib/commands/device/deviceAppVersion.js +5 -8
  70. package/lib/commands/device/deviceAppVersion.js.map +1 -1
  71. package/lib/commands/device/deviceInfo.js +5 -8
  72. package/lib/commands/device/deviceInfo.js.map +1 -1
  73. package/lib/commands/device/deviceSDKFirmwareUpdate.js +22 -68
  74. package/lib/commands/device/deviceSDKFirmwareUpdate.js.map +1 -1
  75. package/lib/commands/device/deviceSDKGetBatteryStatuses.js +7 -8
  76. package/lib/commands/device/deviceSDKGetBatteryStatuses.js.map +1 -1
  77. package/lib/commands/device/deviceSDKGetDeviceInfo.js +6 -7
  78. package/lib/commands/device/deviceSDKGetDeviceInfo.js.map +1 -1
  79. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js +8 -9
  80. package/lib/commands/device/deviceSDKToggleOnboardingEarlyCheck.js.map +1 -1
  81. package/lib/commands/device/deviceVersion.js +5 -8
  82. package/lib/commands/device/deviceVersion.js.map +1 -1
  83. package/lib/commands/device/discoverDevices.js +15 -50
  84. package/lib/commands/device/discoverDevices.js.map +1 -1
  85. package/lib/commands/device/firmwareRepair.js +3 -6
  86. package/lib/commands/device/firmwareRepair.js.map +1 -1
  87. package/lib/commands/device/firmwareUpdate.js +63 -123
  88. package/lib/commands/device/firmwareUpdate.js.map +1 -1
  89. package/lib/commands/device/genuineCheck.js +7 -12
  90. package/lib/commands/device/genuineCheck.js.map +1 -1
  91. package/lib/commands/device/getBatteryStatus.js +5 -9
  92. package/lib/commands/device/getBatteryStatus.js.map +1 -1
  93. package/lib/commands/device/getDeviceRunningMode.js +7 -10
  94. package/lib/commands/device/getDeviceRunningMode.js.map +1 -1
  95. package/lib/commands/device/i18n.js +27 -79
  96. package/lib/commands/device/i18n.js.map +1 -1
  97. package/lib/commands/device/listApps.d.ts +1 -1
  98. package/lib/commands/device/listApps.js +7 -12
  99. package/lib/commands/device/listApps.js.map +1 -1
  100. package/lib/commands/device/managerListApps.js +21 -28
  101. package/lib/commands/device/managerListApps.js.map +1 -1
  102. package/lib/commands/device/proxy.js +242 -350
  103. package/lib/commands/device/proxy.js.map +1 -1
  104. package/lib/commands/device/reinstallConfigurationConsent.js +36 -126
  105. package/lib/commands/device/reinstallConfigurationConsent.js.map +1 -1
  106. package/lib/commands/device/repl.js +5 -10
  107. package/lib/commands/device/repl.js.map +1 -1
  108. package/lib/commands/device/speculosList.js +12 -58
  109. package/lib/commands/device/speculosList.js.map +1 -1
  110. package/lib/commands/live/balanceHistory.js +44 -79
  111. package/lib/commands/live/balanceHistory.js.map +1 -1
  112. package/lib/commands/live/countervalues.js +111 -207
  113. package/lib/commands/live/countervalues.js.map +1 -1
  114. package/lib/commands/live/envs.js +4 -6
  115. package/lib/commands/live/envs.js.map +1 -1
  116. package/lib/commands/live/exportAccounts.js +30 -56
  117. package/lib/commands/live/exportAccounts.js.map +1 -1
  118. package/lib/commands/live/ledgerKeyRingProtocol.d.ts +1 -1
  119. package/lib/commands/live/ledgerKeyRingProtocol.js +63 -103
  120. package/lib/commands/live/ledgerKeyRingProtocol.js.map +1 -1
  121. package/lib/commands/live/ledgerSync.js +20 -60
  122. package/lib/commands/live/ledgerSync.js.map +1 -1
  123. package/lib/commands/live/liveData.js +34 -60
  124. package/lib/commands/live/liveData.js.map +1 -1
  125. package/lib/commands/live/portfolio.js +68 -98
  126. package/lib/commands/live/portfolio.js.map +1 -1
  127. package/lib/commands/live/synchronousOnboarding.js +6 -9
  128. package/lib/commands/live/synchronousOnboarding.js.map +1 -1
  129. package/lib/commands/live/user.js +4 -4
  130. package/lib/commands/live/user.js.map +1 -1
  131. package/lib/commands/live/version.js +2 -4
  132. package/lib/commands/live/version.js.map +1 -1
  133. package/lib/commands/ptx/swap.js +194 -282
  134. package/lib/commands/ptx/swap.js.map +1 -1
  135. package/lib/commands-index.d.ts +9 -9
  136. package/lib/commands-index.js +64 -64
  137. package/lib/commands-index.js.map +1 -1
  138. package/lib/live-common-setup-base.js +26 -48
  139. package/lib/live-common-setup-base.js.map +1 -1
  140. package/lib/live-common-setup.js +66 -123
  141. package/lib/live-common-setup.js.map +1 -1
  142. package/lib/qr.js +6 -10
  143. package/lib/qr.js.map +1 -1
  144. package/lib/scan.js +84 -92
  145. package/lib/scan.js.map +1 -1
  146. package/lib/signedOperation.js +6 -6
  147. package/lib/signedOperation.js.map +1 -1
  148. package/lib/stream.js +57 -68
  149. package/lib/stream.js.map +1 -1
  150. package/lib/transaction.js +60 -142
  151. package/lib/transaction.js.map +1 -1
  152. package/package.json +9 -9
@@ -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
- var rxjs_1 = require("rxjs");
66
- var operators_1 = require("rxjs/operators");
67
- var index_1 = require("@ledgerhq/live-common/currencies/index");
68
- var index_2 = require("@ledgerhq/live-common/bridge/index");
69
- var live_env_1 = require("@ledgerhq/live-env");
70
- var promise_1 = require("@ledgerhq/live-common/promise");
71
- var cache_1 = require("@ledgerhq/live-common/bridge/cache");
72
- var engine_1 = require("@ledgerhq/live-common/bot/engine");
73
- var specs_1 = __importDefault(require("@ledgerhq/live-common/generated/specs"));
74
- var speculos_1 = require("@ledgerhq/live-common/load/speculos");
75
- var index_3 = require("@ledgerhq/live-common/account/index");
76
- var logic_1 = require("@ledgerhq/live-countervalues/logic");
77
- var CONCURRENT = parseInt(process.env.CONCURRENCY || "2", 10);
78
- var ONLY_CURRENCIES = process.env.ONLY_CURRENCIES
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(function (c) { return c.trim(); })
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 (var k in specs_1.default) {
86
- var familySpec = specs_1.default[k];
87
- for (var c in familySpec) {
88
- var spec = familySpec[c];
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
- var split = process.env.FUNDS_SPLIT && parseInt(process.env.FUNDS_SPLIT, 10);
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: function () {
103
- var localCache = {};
104
- var cache = (0, cache_1.makeBridgeCacheSystem)({
105
- saveData: function (c, d) {
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: function (c) {
51
+ getData(c) {
110
52
  return Promise.resolve(localCache[c.id]);
111
53
  },
112
54
  });
113
- function getAllRecipients(currencies) {
114
- return __awaiter(this, void 0, void 0, function () {
115
- var prevSeed, SEED_RECIPIENT, recipientsPerCurrencyId;
116
- var _this = this;
117
- return __generator(this, function (_a) {
118
- switch (_a.label) {
119
- case 0:
120
- prevSeed = (0, live_env_1.getEnv)("SEED");
121
- SEED_RECIPIENT = process.env.SEED_RECIPIENT;
122
- if (SEED_RECIPIENT) {
123
- (0, live_env_1.setEnv)("SEED", SEED_RECIPIENT);
124
- }
125
- recipientsPerCurrencyId = new Map();
126
- return [4 /*yield*/, (0, promise_1.promiseAllBatched)(CONCURRENT, currencies, function (currency) { return __awaiter(_this, void 0, void 0, function () {
127
- var device, r, maybeAddress, e_1;
128
- return __generator(this, function (_a) {
129
- switch (_a.label) {
130
- case 0:
131
- _a.trys.push([0, 4, 5, 6]);
132
- return [4 /*yield*/, (0, speculos_1.createImplicitSpeculos)("speculos:nanos:".concat(currency.id))];
133
- case 1:
134
- r = _a.sent();
135
- if (!r)
136
- return [2 /*return*/];
137
- device = r.device;
138
- return [4 /*yield*/, cache.prepareCurrency(currency)];
139
- case 2:
140
- _a.sent();
141
- return [4 /*yield*/, (0, rxjs_1.firstValueFrom)((0, index_2.getCurrencyBridge)(currency)
142
- .scanAccounts({
143
- currency: currency,
144
- deviceId: device.id,
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
- return __awaiter(this, void 0, void 0, function () {
184
- var accounts;
185
- var _this = this;
186
- return __generator(this, function (_a) {
187
- switch (_a.label) {
188
- case 0:
189
- accounts = [];
190
- return [4 /*yield*/, (0, promise_1.promiseAllBatched)(CONCURRENT, currencies, function (currency) { return __awaiter(_this, void 0, void 0, function () {
191
- var device, r, e_2;
192
- return __generator(this, function (_a) {
193
- switch (_a.label) {
194
- case 0:
195
- _a.trys.push([0, 3, 4, 5]);
196
- return [4 /*yield*/, (0, speculos_1.createImplicitSpeculos)("speculos:nanos:".concat(currency.id))];
197
- case 1:
198
- r = _a.sent();
199
- if (!r)
200
- return [2 /*return*/];
201
- device = r.device;
202
- return [4 /*yield*/, (0, rxjs_1.firstValueFrom)((0, index_2.getCurrencyBridge)(currency)
203
- .scanAccounts({
204
- currency: currency,
205
- deviceId: r.device.id,
206
- syncConfig: {
207
- paginationConfig: {},
208
- },
209
- })
210
- .pipe((0, operators_1.timeout)({
211
- each: (0, live_env_1.getEnv)("BOT_TIMEOUT_SCAN_ACCOUNTS"),
212
- with: function () { return (0, rxjs_1.throwError)(function () { return new Error("scan account timeout"); }); },
213
- }), (0, operators_1.catchError)(function (e) {
214
- console.error("scan accounts failed for " + currency.id, e);
215
- return (0, rxjs_1.from)([]);
216
- }), (0, operators_1.tap)(function (e) {
217
- if (e.type === "discovered") {
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
- var cvUSDThreshold = 10;
244
- function sendAllFunds(accounts, recipientsPerCurrencyId) {
245
- return __awaiter(this, void 0, void 0, function () {
246
- var countervalue, countervaluesState;
247
- var _this = this;
248
- return __generator(this, function (_a) {
249
- switch (_a.label) {
250
- case 0:
251
- countervalue = (0, index_1.getFiatCurrencyByTicker)("USD");
252
- return [4 /*yield*/, (0, logic_1.loadCountervalues)(logic_1.initialState, {
253
- trackingPairs: (0, logic_1.inferTrackingPairForAccounts)(accounts, countervalue),
254
- autofillGaps: true,
255
- refreshRate: 60000,
256
- marketCapBatchingAfterRank: 20,
257
- })];
258
- case 1:
259
- countervaluesState = _a.sent();
260
- return [4 /*yield*/, (0, promise_1.promiseAllBatched)(CONCURRENT, accounts, function (account) { return __awaiter(_this, void 0, void 0, function () {
261
- var currency, cv, recipient, accountBridge, plannedTransactions, device, r, plannedTransactions_1, plannedTransactions_1_1, tx, deviceAction, transaction, statusCommon, status, signedOperation, optimisticOperation, _a, e_3, e_4_1, e_5;
262
- var e_4, _b;
263
- var _c;
264
- return __generator(this, function (_d) {
265
- switch (_d.label) {
266
- case 0:
267
- currency = account.currency;
268
- cv = (0, logic_1.calculate)(countervaluesState, {
269
- from: currency,
270
- to: countervalue,
271
- value: account.balance.toNumber(),
272
- });
273
- if (!cv || cv < cvUSDThreshold) {
274
- return [2 /*return*/];
275
- }
276
- recipient = recipientsPerCurrencyId.get(currency.id);
277
- if (!recipient) {
278
- console.log("no recipient to empty account " + account.id);
279
- return [2 /*return*/];
280
- }
281
- accountBridge = (0, index_2.getAccountBridge)(account);
282
- plannedTransactions = [];
283
- // FIXME better value than this arbitrary one: calc countervalues
284
- (_c = account.subAccounts) === null || _c === void 0 ? void 0 : _c.forEach(function (subAccount) {
285
- var cv = (0, logic_1.calculate)(countervaluesState, {
286
- from: account.currency,
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
- function main() {
407
- return __awaiter(this, void 0, void 0, function () {
408
- var currencies, recipientsPerCurrencyId, accounts;
409
- return __generator(this, function (_a) {
410
- switch (_a.label) {
411
- case 0:
412
- currencies = (0, index_1.listSupportedCurrencies)();
413
- if (ONLY_CURRENCIES) {
414
- currencies = currencies.filter(function (c) { return ONLY_CURRENCIES.includes(c.id); });
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
- currencies.sort(function () { return Math.random() - 0.5; });
417
- return [4 /*yield*/, getAllRecipients(currencies)];
418
- case 1:
419
- recipientsPerCurrencyId = _a.sent();
420
- console.log(Array.from(recipientsPerCurrencyId.keys()).length + " RECIPIENTS FETCHED");
421
- return [4 /*yield*/, botPortfolio(currencies)];
422
- case 2:
423
- accounts = _a.sent();
424
- console.log("BOT PORTFOLIO FETCHED ".concat(accounts.length, " accounts"));
425
- return [4 /*yield*/, sendAllFunds(accounts, recipientsPerCurrencyId)];
426
- case 3:
427
- _a.sent();
428
- return [2 /*return*/];
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
  };