@argonprotocol/mainchain 1.1.0-rc.4 → 1.1.0-rc.5

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.
@@ -1,4 +1,93 @@
1
1
  import { Command } from '@commander-js/extra-typings';
2
+ import { Accountset } from '../index.cjs';
3
+ import { KeyringPair } from '@polkadot/keyring/types';
4
+ import '@polkadot/api-base/types';
5
+ import '@polkadot/types-codec';
6
+ import '@polkadot/types-codec/types';
7
+ import '@polkadot/types/interfaces/runtime';
8
+ import '@polkadot/types/lookup';
9
+ import '@polkadot/types/types';
10
+ import '@polkadot/rpc-core/types';
11
+ import '@polkadot/types';
12
+ import '@polkadot/types/interfaces/author';
13
+ import '@polkadot/types/interfaces/babe';
14
+ import '@polkadot/types/interfaces/beefy';
15
+ import '@polkadot/types/interfaces/chain';
16
+ import '@polkadot/types/interfaces/childstate';
17
+ import '@polkadot/types/interfaces/consensus';
18
+ import '@polkadot/types/interfaces/contracts';
19
+ import '@polkadot/types/interfaces/dev';
20
+ import '@polkadot/types/interfaces/engine';
21
+ import '@polkadot/types/interfaces/eth';
22
+ import '@polkadot/types/interfaces/extrinsics';
23
+ import '@polkadot/types/interfaces/grandpa';
24
+ import '@polkadot/types/interfaces/mmr';
25
+ import '@polkadot/types/interfaces/offchain';
26
+ import '@polkadot/types/interfaces/payment';
27
+ import '@polkadot/types/interfaces/rpc';
28
+ import '@polkadot/types/interfaces/state';
29
+ import '@polkadot/types/interfaces/system';
30
+ import '@polkadot/types/interfaces/blockbuilder';
31
+ import '@polkadot/types/interfaces/genesisBuilder';
32
+ import '@polkadot/types/interfaces/metadata';
33
+ import '@polkadot/types/interfaces/txqueue';
34
+ import '@polkadot/types/interfaces/assetConversion';
35
+ import '@polkadot/types/interfaces/assets';
36
+ import '@polkadot/types/interfaces/attestations';
37
+ import '@polkadot/types/interfaces/aura';
38
+ import '@polkadot/types/interfaces/authorship';
39
+ import '@polkadot/types/interfaces/balances';
40
+ import '@polkadot/types/interfaces/benchmark';
41
+ import '@polkadot/types/interfaces/bridges';
42
+ import '@polkadot/types/interfaces/claims';
43
+ import '@polkadot/types/interfaces/collective';
44
+ import '@polkadot/types/interfaces/contractsAbi';
45
+ import '@polkadot/types/interfaces/crowdloan';
46
+ import '@polkadot/types/interfaces/cumulus';
47
+ import '@polkadot/types/interfaces/democracy';
48
+ import '@polkadot/types/interfaces/dryRunApi';
49
+ import '@polkadot/types/interfaces/elections';
50
+ import '@polkadot/types/interfaces/evm';
51
+ import '@polkadot/types/interfaces/fungibles';
52
+ import '@polkadot/types/interfaces/genericAsset';
53
+ import '@polkadot/types/interfaces/gilt';
54
+ import '@polkadot/types/interfaces/identity';
55
+ import '@polkadot/types/interfaces/imOnline';
56
+ import '@polkadot/types/interfaces/lottery';
57
+ import '@polkadot/types/interfaces/mixnet';
58
+ import '@polkadot/types/interfaces/nfts';
59
+ import '@polkadot/types/interfaces/nompools';
60
+ import '@polkadot/types/interfaces/offences';
61
+ import '@polkadot/types/interfaces/parachains';
62
+ import '@polkadot/types/interfaces/poll';
63
+ import '@polkadot/types/interfaces/proxy';
64
+ import '@polkadot/types/interfaces/purchase';
65
+ import '@polkadot/types/interfaces/recovery';
66
+ import '@polkadot/types/interfaces/scaleInfo';
67
+ import '@polkadot/types/interfaces/scheduler';
68
+ import '@polkadot/types/interfaces/session';
69
+ import '@polkadot/types/interfaces/society';
70
+ import '@polkadot/types/interfaces/staking';
71
+ import '@polkadot/types/interfaces/statement';
72
+ import '@polkadot/types/interfaces/support';
73
+ import '@polkadot/types/interfaces/treasury';
74
+ import '@polkadot/types/interfaces/txpayment';
75
+ import '@polkadot/types/interfaces/uniques';
76
+ import '@polkadot/types/interfaces/utility';
77
+ import '@polkadot/types/interfaces/vesting';
78
+ import '@polkadot/types/interfaces/xcm';
79
+ import '@polkadot/types/interfaces/xcmPaymentApi';
80
+ import '@polkadot/types/interfaces/xcmRuntimeApi';
81
+ import '@polkadot/api';
82
+ import '@polkadot/util-crypto';
83
+ import '@polkadot/types/types/registry';
84
+ import '@polkadot/util-crypto/types';
85
+ import '@polkadot/types/types/extrinsic';
86
+ import '@polkadot/api/promise/types';
87
+ import '@polkadot/api/types';
88
+ import 'nanoevents';
89
+ import '@polkadot/types/interfaces';
90
+ import 'bignumber.js';
2
91
 
3
92
  declare function accountCli(): Command<[], {}, {}>;
4
93
 
@@ -10,6 +99,16 @@ declare function liquidityCli(): Command<[], {}, {}>;
10
99
 
11
100
  declare function bitcoinCli(): Command<[], {}, {}>;
12
101
 
102
+ declare function keyringFromFile(opts: {
103
+ filePath: string;
104
+ passphrase?: string;
105
+ }): Promise<KeyringPair>;
106
+ declare function saveKeyringPair(opts: {
107
+ filePath: string;
108
+ passphrase?: string;
109
+ cryptoType?: 'sr25519' | 'ed25519';
110
+ }): Promise<KeyringPair>;
111
+
13
112
  declare function globalOptions(program: Command): IGlobalOptions;
14
113
  declare function buildCli(): Command<[], {
15
114
  env?: string | undefined;
@@ -19,8 +118,9 @@ declare function buildCli(): Command<[], {
19
118
  accountPassphrase?: string | undefined;
20
119
  subaccounts?: number[] | undefined;
21
120
  }, {}>;
121
+ declare function accountsetFromCli(program: Command, proxyForAddress?: string): Promise<Accountset>;
22
122
  type IGlobalOptions = ReturnType<ReturnType<typeof buildCli>['opts']>;
23
123
  declare function addGlobalArgs(program: ReturnType<typeof buildCli>): void;
24
124
  declare function applyEnv(program: ReturnType<typeof buildCli>): string | undefined;
25
125
 
26
- export { type IGlobalOptions, accountCli, addGlobalArgs, applyEnv, bitcoinCli, buildCli, globalOptions, liquidityCli, miningCli, vaultCli };
126
+ export { type IGlobalOptions, accountCli, accountsetFromCli, addGlobalArgs, applyEnv, bitcoinCli, buildCli, globalOptions, keyringFromFile, liquidityCli, miningCli, saveKeyringPair, vaultCli };
@@ -1,4 +1,93 @@
1
1
  import { Command } from '@commander-js/extra-typings';
2
+ import { Accountset } from '../index.js';
3
+ import { KeyringPair } from '@polkadot/keyring/types';
4
+ import '@polkadot/api-base/types';
5
+ import '@polkadot/types-codec';
6
+ import '@polkadot/types-codec/types';
7
+ import '@polkadot/types/interfaces/runtime';
8
+ import '@polkadot/types/lookup';
9
+ import '@polkadot/types/types';
10
+ import '@polkadot/rpc-core/types';
11
+ import '@polkadot/types';
12
+ import '@polkadot/types/interfaces/author';
13
+ import '@polkadot/types/interfaces/babe';
14
+ import '@polkadot/types/interfaces/beefy';
15
+ import '@polkadot/types/interfaces/chain';
16
+ import '@polkadot/types/interfaces/childstate';
17
+ import '@polkadot/types/interfaces/consensus';
18
+ import '@polkadot/types/interfaces/contracts';
19
+ import '@polkadot/types/interfaces/dev';
20
+ import '@polkadot/types/interfaces/engine';
21
+ import '@polkadot/types/interfaces/eth';
22
+ import '@polkadot/types/interfaces/extrinsics';
23
+ import '@polkadot/types/interfaces/grandpa';
24
+ import '@polkadot/types/interfaces/mmr';
25
+ import '@polkadot/types/interfaces/offchain';
26
+ import '@polkadot/types/interfaces/payment';
27
+ import '@polkadot/types/interfaces/rpc';
28
+ import '@polkadot/types/interfaces/state';
29
+ import '@polkadot/types/interfaces/system';
30
+ import '@polkadot/types/interfaces/blockbuilder';
31
+ import '@polkadot/types/interfaces/genesisBuilder';
32
+ import '@polkadot/types/interfaces/metadata';
33
+ import '@polkadot/types/interfaces/txqueue';
34
+ import '@polkadot/types/interfaces/assetConversion';
35
+ import '@polkadot/types/interfaces/assets';
36
+ import '@polkadot/types/interfaces/attestations';
37
+ import '@polkadot/types/interfaces/aura';
38
+ import '@polkadot/types/interfaces/authorship';
39
+ import '@polkadot/types/interfaces/balances';
40
+ import '@polkadot/types/interfaces/benchmark';
41
+ import '@polkadot/types/interfaces/bridges';
42
+ import '@polkadot/types/interfaces/claims';
43
+ import '@polkadot/types/interfaces/collective';
44
+ import '@polkadot/types/interfaces/contractsAbi';
45
+ import '@polkadot/types/interfaces/crowdloan';
46
+ import '@polkadot/types/interfaces/cumulus';
47
+ import '@polkadot/types/interfaces/democracy';
48
+ import '@polkadot/types/interfaces/dryRunApi';
49
+ import '@polkadot/types/interfaces/elections';
50
+ import '@polkadot/types/interfaces/evm';
51
+ import '@polkadot/types/interfaces/fungibles';
52
+ import '@polkadot/types/interfaces/genericAsset';
53
+ import '@polkadot/types/interfaces/gilt';
54
+ import '@polkadot/types/interfaces/identity';
55
+ import '@polkadot/types/interfaces/imOnline';
56
+ import '@polkadot/types/interfaces/lottery';
57
+ import '@polkadot/types/interfaces/mixnet';
58
+ import '@polkadot/types/interfaces/nfts';
59
+ import '@polkadot/types/interfaces/nompools';
60
+ import '@polkadot/types/interfaces/offences';
61
+ import '@polkadot/types/interfaces/parachains';
62
+ import '@polkadot/types/interfaces/poll';
63
+ import '@polkadot/types/interfaces/proxy';
64
+ import '@polkadot/types/interfaces/purchase';
65
+ import '@polkadot/types/interfaces/recovery';
66
+ import '@polkadot/types/interfaces/scaleInfo';
67
+ import '@polkadot/types/interfaces/scheduler';
68
+ import '@polkadot/types/interfaces/session';
69
+ import '@polkadot/types/interfaces/society';
70
+ import '@polkadot/types/interfaces/staking';
71
+ import '@polkadot/types/interfaces/statement';
72
+ import '@polkadot/types/interfaces/support';
73
+ import '@polkadot/types/interfaces/treasury';
74
+ import '@polkadot/types/interfaces/txpayment';
75
+ import '@polkadot/types/interfaces/uniques';
76
+ import '@polkadot/types/interfaces/utility';
77
+ import '@polkadot/types/interfaces/vesting';
78
+ import '@polkadot/types/interfaces/xcm';
79
+ import '@polkadot/types/interfaces/xcmPaymentApi';
80
+ import '@polkadot/types/interfaces/xcmRuntimeApi';
81
+ import '@polkadot/api';
82
+ import '@polkadot/util-crypto';
83
+ import '@polkadot/types/types/registry';
84
+ import '@polkadot/util-crypto/types';
85
+ import '@polkadot/types/types/extrinsic';
86
+ import '@polkadot/api/promise/types';
87
+ import '@polkadot/api/types';
88
+ import 'nanoevents';
89
+ import '@polkadot/types/interfaces';
90
+ import 'bignumber.js';
2
91
 
3
92
  declare function accountCli(): Command<[], {}, {}>;
4
93
 
@@ -10,6 +99,16 @@ declare function liquidityCli(): Command<[], {}, {}>;
10
99
 
11
100
  declare function bitcoinCli(): Command<[], {}, {}>;
12
101
 
102
+ declare function keyringFromFile(opts: {
103
+ filePath: string;
104
+ passphrase?: string;
105
+ }): Promise<KeyringPair>;
106
+ declare function saveKeyringPair(opts: {
107
+ filePath: string;
108
+ passphrase?: string;
109
+ cryptoType?: 'sr25519' | 'ed25519';
110
+ }): Promise<KeyringPair>;
111
+
13
112
  declare function globalOptions(program: Command): IGlobalOptions;
14
113
  declare function buildCli(): Command<[], {
15
114
  env?: string | undefined;
@@ -19,8 +118,9 @@ declare function buildCli(): Command<[], {
19
118
  accountPassphrase?: string | undefined;
20
119
  subaccounts?: number[] | undefined;
21
120
  }, {}>;
121
+ declare function accountsetFromCli(program: Command, proxyForAddress?: string): Promise<Accountset>;
22
122
  type IGlobalOptions = ReturnType<ReturnType<typeof buildCli>['opts']>;
23
123
  declare function addGlobalArgs(program: ReturnType<typeof buildCli>): void;
24
124
  declare function applyEnv(program: ReturnType<typeof buildCli>): string | undefined;
25
125
 
26
- export { type IGlobalOptions, accountCli, addGlobalArgs, applyEnv, bitcoinCli, buildCli, globalOptions, liquidityCli, miningCli, vaultCli };
126
+ export { type IGlobalOptions, accountCli, accountsetFromCli, addGlobalArgs, applyEnv, bitcoinCli, buildCli, globalOptions, keyringFromFile, liquidityCli, miningCli, saveKeyringPair, vaultCli };
package/lib/clis/index.js CHANGED
@@ -54,8 +54,6 @@ __export(index_exports, {
54
54
  getClient: () => getClient,
55
55
  getTickFromHeader: () => getTickFromHeader,
56
56
  gettersToObject: () => gettersToObject,
57
- keyringFromCli: () => keyringFromCli,
58
- keyringFromFile: () => keyringFromFile,
59
57
  keyringFromSuri: () => keyringFromSuri,
60
58
  mnemonicGenerate: () => mnemonicGenerate,
61
59
  waitForLoad: () => waitForLoad
@@ -436,11 +434,8 @@ var AccountRegistry = class _AccountRegistry {
436
434
  // src/Accountset.ts
437
435
  import * as process2 from "node:process";
438
436
 
439
- // src/AccountMiners.ts
440
- import EventEmitter2 from "node:events";
441
-
442
437
  // src/BlockWatch.ts
443
- import EventEmitter from "node:events";
438
+ import { createNanoEvents } from "nanoevents";
444
439
  function getTickFromHeader(client, header) {
445
440
  for (const x of header.digest.logs) {
446
441
  if (x.isPreRuntime) {
@@ -470,7 +465,7 @@ var BlockWatch = class {
470
465
  this.options.shouldLog ??= true;
471
466
  this.options.finalizedBlocks ??= false;
472
467
  }
473
- events = new EventEmitter();
468
+ events = createNanoEvents();
474
469
  obligationsById = {};
475
470
  obligationIdByUtxoId = {};
476
471
  unsubscribe;
@@ -661,6 +656,7 @@ var MiningRotations = class {
661
656
  };
662
657
 
663
658
  // src/AccountMiners.ts
659
+ import { createNanoEvents as createNanoEvents2 } from "nanoevents";
664
660
  var AccountMiners = class _AccountMiners {
665
661
  constructor(accountset, registeredMiners, options = { shouldLog: false }) {
666
662
  this.accountset = accountset;
@@ -673,7 +669,7 @@ var AccountMiners = class _AccountMiners {
673
669
  };
674
670
  }
675
671
  }
676
- events = new EventEmitter2();
672
+ events = createNanoEvents2();
677
673
  miningRotations;
678
674
  trackedAccountsByAddress = {};
679
675
  async watch() {
@@ -788,7 +784,7 @@ var AccountMiners = class _AccountMiners {
788
784
  };
789
785
 
790
786
  // src/Accountset.ts
791
- var Accountset = class _Accountset {
787
+ var Accountset = class {
792
788
  txSubmitterPair;
793
789
  isProxy = false;
794
790
  seedAddress;
@@ -1171,24 +1167,6 @@ var Accountset = class _Accountset {
1171
1167
  await accountMiners.watch();
1172
1168
  return accountMiners;
1173
1169
  }
1174
- static async fromCli(program, proxyForAddress) {
1175
- const parentOptions = program.parent?.optsWithGlobals();
1176
- const keypair = await keyringFromCli(parentOptions);
1177
- const client = getClient(parentOptions.mainchainUrl);
1178
- if (proxyForAddress) {
1179
- return new _Accountset({
1180
- client,
1181
- isProxy: true,
1182
- seedAddress: proxyForAddress,
1183
- txSubmitter: keypair
1184
- });
1185
- } else {
1186
- return new _Accountset({
1187
- seedAccount: keypair,
1188
- client
1189
- });
1190
- }
1191
- }
1192
1170
  };
1193
1171
  function getDefaultSubaccountRange() {
1194
1172
  try {
@@ -1400,8 +1378,8 @@ var Vault = class {
1400
1378
  };
1401
1379
 
1402
1380
  // src/VaultMonitor.ts
1403
- import { EventEmitter as EventEmitter3 } from "node:events";
1404
1381
  import { printTable as printTable2 } from "console-table-printer";
1382
+ import { createNanoEvents as createNanoEvents3 } from "nanoevents";
1405
1383
  var VaultMonitor = class {
1406
1384
  constructor(accountset, alerts = {}, options = {}) {
1407
1385
  this.accountset = accountset;
@@ -1431,7 +1409,7 @@ var VaultMonitor = class {
1431
1409
  this.printBids(header.hash);
1432
1410
  });
1433
1411
  }
1434
- events = new EventEmitter3();
1412
+ events = createNanoEvents3();
1435
1413
  vaultsById = {};
1436
1414
  blockWatch;
1437
1415
  mainchain;
@@ -2309,47 +2287,13 @@ var BitcoinLocks = class _BitcoinLocks {
2309
2287
  };
2310
2288
 
2311
2289
  // src/keyringUtils.ts
2312
- import { promises } from "node:fs";
2313
- import * as os from "node:os";
2314
- var { readFile, writeFile } = promises;
2315
- async function keyringFromCli(opts) {
2316
- if (opts.accountSuri) {
2317
- return keyringFromSuri(opts.accountSuri);
2318
- }
2319
- if (opts.accountFilePath) {
2320
- return keyringFromFile({
2321
- filePath: opts.accountFilePath,
2322
- passphrase: opts.accountPassphrase
2323
- });
2324
- }
2325
- throw new Error(
2326
- "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
2327
- );
2328
- }
2329
2290
  function keyringFromSuri(suri, cryptoType = "sr25519") {
2330
2291
  return new Keyring({ type: cryptoType }).createFromUri(suri);
2331
2292
  }
2332
- async function keyringFromFile(opts) {
2333
- if (!opts.filePath) {
2334
- throw new Error(
2335
- "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
2336
- );
2337
- }
2338
- const path = opts.filePath.replace("~", os.homedir());
2339
- const json = JSON.parse(await readFile(path, "utf-8"));
2340
- const mainAccount = new Keyring().createFromJson(json);
2341
- mainAccount.decodePkcs8(opts.passphrase);
2342
- return mainAccount;
2343
- }
2344
- async function createKeyringPair(opts) {
2345
- const { filePath, passphrase, cryptoType } = opts;
2293
+ function createKeyringPair(opts) {
2294
+ const { cryptoType } = opts;
2346
2295
  const seed = mnemonicGenerate();
2347
- const keyring = keyringFromSuri(seed, cryptoType);
2348
- if (filePath) {
2349
- const json = keyring.toJson(passphrase);
2350
- await writeFile(filePath, JSON.stringify(json, null, 2));
2351
- }
2352
- return keyring;
2296
+ return keyringFromSuri(seed, cryptoType);
2353
2297
  }
2354
2298
 
2355
2299
  // src/index.ts
@@ -2380,7 +2324,7 @@ function accountCli() {
2380
2324
  "Manage subaccounts from a single keypair"
2381
2325
  );
2382
2326
  program.command("watch").description("Watch for blocks closed by subaccounts").action(async () => {
2383
- const accountset = await Accountset.fromCli(program);
2327
+ const accountset = await accountsetFromCli(program);
2384
2328
  const accountMiners = await accountset.watchBlocks();
2385
2329
  accountMiners.events.on("mined", (_block, mined) => {
2386
2330
  console.log("Your accounts authored a block", mined);
@@ -2391,7 +2335,7 @@ function accountCli() {
2391
2335
  });
2392
2336
  program.command("list", { isDefault: true }).description("Show subaccounts").option("--addresses", "Just show a list of ids").action(async ({ addresses }) => {
2393
2337
  const { subaccounts } = globalOptions(program);
2394
- const accountset = await Accountset.fromCli(program);
2338
+ const accountset = await accountsetFromCli(program);
2395
2339
  if (addresses) {
2396
2340
  const addresses2 = accountset.addresses;
2397
2341
  console.log(addresses2.join(","));
@@ -2422,7 +2366,7 @@ function accountCli() {
2422
2366
  "Register the keys to a url (normally this is localhost)"
2423
2367
  ).action(async ({ registerKeysTo, path }) => {
2424
2368
  const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program);
2425
- const accountset = await Accountset.fromCli(program);
2369
+ const accountset = await accountsetFromCli(program);
2426
2370
  process3.env.KEYS_MNEMONIC ||= mnemonicGenerate();
2427
2371
  if (registerKeysTo) {
2428
2372
  await accountset.registerKeys(registerKeysTo);
@@ -2463,7 +2407,7 @@ function accountCli() {
2463
2407
  "--print-only",
2464
2408
  "Output as curl commands instead of direct registration"
2465
2409
  ).action(async (nodeRpcUrl, { printOnly }) => {
2466
- const accountset = await Accountset.fromCli(program);
2410
+ const accountset = await accountsetFromCli(program);
2467
2411
  if (printOnly) {
2468
2412
  const { gran, seal } = accountset.keys();
2469
2413
  const commands = [];
@@ -2497,7 +2441,7 @@ function accountCli() {
2497
2441
  "Restrict this operation to a subset of the subaccounts (eg, 0-10)",
2498
2442
  parseSubaccountRange
2499
2443
  ).action(async ({ subaccounts }) => {
2500
- const accountset = await Accountset.fromCli(program);
2444
+ const accountset = await accountsetFromCli(program);
2501
2445
  const result = await accountset.consolidate(subaccounts);
2502
2446
  printTable3(result);
2503
2447
  process3.exit(0);
@@ -2516,7 +2460,7 @@ function vaultCli() {
2516
2460
  "Monitor vaults and manage securitization"
2517
2461
  );
2518
2462
  program.command("list", { isDefault: true }).description("Show current state of vaults").action(async () => {
2519
- const accountset = await Accountset.fromCli(program);
2463
+ const accountset = await accountsetFromCli(program);
2520
2464
  const vaults = new VaultMonitor(accountset, void 0, {
2521
2465
  vaultOnlyWatchMode: true
2522
2466
  });
@@ -2532,7 +2476,7 @@ function vaultCli() {
2532
2476
  "The tip to include with the transaction",
2533
2477
  parseFloat
2534
2478
  ).action(async ({ tip, argons, vaultId, ratio }) => {
2535
- const accountset = await Accountset.fromCli(program);
2479
+ const accountset = await accountsetFromCli(program);
2536
2480
  const client = await accountset.client;
2537
2481
  const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
2538
2482
  const microgons = BigInt(argons * 1e6);
@@ -2593,7 +2537,7 @@ function vaultCli() {
2593
2537
  "Bitcoin pubkey must be 66 characters (add 0x in front optionally)"
2594
2538
  );
2595
2539
  }
2596
- const accountset = await Accountset.fromCli(program);
2540
+ const accountset = await accountsetFromCli(program);
2597
2541
  const client = await accountset.client;
2598
2542
  const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
2599
2543
  const microgons = BigInt(argons * 1e6);
@@ -2676,7 +2620,7 @@ function miningCli() {
2676
2620
  "Watch mining seats or setup bidding"
2677
2621
  );
2678
2622
  program.command("list", { isDefault: true }).description("Monitor all miners").action(async () => {
2679
- const accountset = await Accountset.fromCli(program);
2623
+ const accountset = await accountsetFromCli(program);
2680
2624
  const bids = new MiningBids(accountset.client);
2681
2625
  const api = await accountset.client;
2682
2626
  let lastMiners = {};
@@ -2772,7 +2716,7 @@ function miningCli() {
2772
2716
  bidIncrement,
2773
2717
  proxyForAddress
2774
2718
  }) => {
2775
- const accountset = await Accountset.fromCli(program, proxyForAddress);
2719
+ const accountset = await accountsetFromCli(program, proxyForAddress);
2776
2720
  let cohortBidder;
2777
2721
  const miningBids = new MiningBids(accountset.client, false);
2778
2722
  const maxCohortSize = await miningBids.maxCohortSize();
@@ -2859,7 +2803,7 @@ function miningCli() {
2859
2803
  ).action(async ({ outfile, proxyPassphrase, feeArgons }) => {
2860
2804
  const { mainchainUrl } = globalOptions(program);
2861
2805
  const client = await getClient(mainchainUrl);
2862
- const keyringPair = await createKeyringPair({
2806
+ const keyringPair = await saveKeyringPair({
2863
2807
  filePath: outfile,
2864
2808
  passphrase: proxyPassphrase
2865
2809
  });
@@ -2873,7 +2817,7 @@ function miningCli() {
2873
2817
  ]);
2874
2818
  let keypair;
2875
2819
  try {
2876
- const accountset = await Accountset.fromCli(program);
2820
+ const accountset = await accountsetFromCli(program);
2877
2821
  keypair = accountset.txSubmitterPair;
2878
2822
  } catch (e) {
2879
2823
  const polkadotLink = `https://polkadot.js.org/apps/?rpc=${mainchainUrl}#/extrinsics/decode/${tx.toHex()}`;
@@ -2901,7 +2845,7 @@ function liquidityCli() {
2901
2845
  "Monitor or bond to liquidity pools"
2902
2846
  );
2903
2847
  program.command("list", { isDefault: true }).description("Show or watch the vault bid pool rewards").action(async () => {
2904
- const accountset = await Accountset.fromCli(program);
2848
+ const accountset = await accountsetFromCli(program);
2905
2849
  const bidPool = new BidPool(
2906
2850
  accountset.client,
2907
2851
  accountset.txSubmitterPair
@@ -2917,7 +2861,7 @@ function liquidityCli() {
2917
2861
  "The tip to include with the transaction",
2918
2862
  parseFloat
2919
2863
  ).action(async ({ tip, argons, vaultId }) => {
2920
- const accountset = await Accountset.fromCli(program);
2864
+ const accountset = await accountsetFromCli(program);
2921
2865
  const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
2922
2866
  const microgons = BigInt(argons * 1e6);
2923
2867
  const bidPool = new BidPool(
@@ -2945,7 +2889,7 @@ function liquidityCli() {
2945
2889
  parseFloat
2946
2890
  ).action(async ({ maxArgons, minPctSharing, tip }) => {
2947
2891
  const maxAmountPerSlot = BigInt(maxArgons * 1e6);
2948
- const accountset = await Accountset.fromCli(program);
2892
+ const accountset = await accountsetFromCli(program);
2949
2893
  const vaults = new VaultMonitor(
2950
2894
  accountset,
2951
2895
  {
@@ -2994,7 +2938,7 @@ function bitcoinCli() {
2994
2938
  "Alert when bitcoin space exceeds this amount",
2995
2939
  parseFloat
2996
2940
  ).description("Watch for bitcoin space available").action(async ({ argons }) => {
2997
- const accountset = await Accountset.fromCli(program);
2941
+ const accountset = await accountsetFromCli(program);
2998
2942
  const bot = new VaultMonitor(accountset, {
2999
2943
  bitcoinSpaceAvailable: argons ? BigInt(argons * 1e6) : 1n
3000
2944
  });
@@ -3026,7 +2970,7 @@ function bitcoinCli() {
3026
2970
  0
3027
2971
  ).action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {
3028
2972
  const amountToLock = BigInt(argons * 1e6);
3029
- const accountset = await Accountset.fromCli(program);
2973
+ const accountset = await accountsetFromCli(program);
3030
2974
  await BitcoinLocks.waitForSpace(accountset, {
3031
2975
  argonAmount: amountToLock,
3032
2976
  bitcoinXpub,
@@ -3044,6 +2988,32 @@ function bitcoinCli() {
3044
2988
  return program;
3045
2989
  }
3046
2990
 
2991
+ // src/clis/keyringStore.ts
2992
+ import { promises } from "node:fs";
2993
+ import * as os from "node:os";
2994
+ var { readFile, writeFile } = promises;
2995
+ async function keyringFromFile(opts) {
2996
+ if (!opts.filePath) {
2997
+ throw new Error(
2998
+ "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
2999
+ );
3000
+ }
3001
+ const path = opts.filePath.replace("~", os.homedir());
3002
+ const json = JSON.parse(await readFile(path, "utf-8"));
3003
+ const mainAccount = new Keyring().createFromJson(json);
3004
+ mainAccount.decodePkcs8(opts.passphrase);
3005
+ return mainAccount;
3006
+ }
3007
+ async function saveKeyringPair(opts) {
3008
+ const { filePath, passphrase, cryptoType } = opts;
3009
+ const keyring = createKeyringPair({ cryptoType });
3010
+ if (filePath) {
3011
+ const json = keyring.toJson(passphrase);
3012
+ await writeFile(filePath, JSON.stringify(json, null, 2));
3013
+ }
3014
+ return keyring;
3015
+ }
3016
+
3047
3017
  // src/clis/index.ts
3048
3018
  function globalOptions(program) {
3049
3019
  return program.optsWithGlobals();
@@ -3073,6 +3043,38 @@ function buildCli() {
3073
3043
  ).env("SUBACCOUNT_RANGE").argParser(parseSubaccountRange)
3074
3044
  ).addCommand(accountCli()).addCommand(vaultCli()).addCommand(miningCli()).addCommand(liquidityCli()).addCommand(bitcoinCli());
3075
3045
  }
3046
+ async function accountsetFromCli(program, proxyForAddress) {
3047
+ const opts = program.parent?.optsWithGlobals();
3048
+ let keypair;
3049
+ if (opts.accountSuri) {
3050
+ keypair = keyringFromSuri(opts.accountSuri);
3051
+ }
3052
+ if (opts.accountFilePath) {
3053
+ keypair = await keyringFromFile({
3054
+ filePath: opts.accountFilePath,
3055
+ passphrase: opts.accountPassphrase
3056
+ });
3057
+ }
3058
+ if (!keypair) {
3059
+ throw new Error(
3060
+ "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
3061
+ );
3062
+ }
3063
+ const client = getClient(opts.mainchainUrl);
3064
+ if (proxyForAddress) {
3065
+ return new Accountset({
3066
+ client,
3067
+ isProxy: true,
3068
+ seedAddress: proxyForAddress,
3069
+ txSubmitter: keypair
3070
+ });
3071
+ } else {
3072
+ return new Accountset({
3073
+ seedAccount: keypair,
3074
+ client
3075
+ });
3076
+ }
3077
+ }
3076
3078
  function addGlobalArgs(program) {
3077
3079
  for (const command of program.commands) {
3078
3080
  command.configureHelp({
@@ -3102,13 +3104,16 @@ function applyEnv(program) {
3102
3104
  }
3103
3105
  export {
3104
3106
  accountCli,
3107
+ accountsetFromCli,
3105
3108
  addGlobalArgs,
3106
3109
  applyEnv,
3107
3110
  bitcoinCli,
3108
3111
  buildCli,
3109
3112
  globalOptions,
3113
+ keyringFromFile,
3110
3114
  liquidityCli,
3111
3115
  miningCli,
3116
+ saveKeyringPair,
3112
3117
  vaultCli
3113
3118
  };
3114
3119
  //# sourceMappingURL=index.js.map