@argonprotocol/mainchain 1.3.4 → 1.3.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.
@@ -16,7 +16,7 @@ import {
16
16
  keyringFromSuri,
17
17
  mnemonicGenerate,
18
18
  parseSubaccountRange
19
- } from "./chunk-P3OMJABP.js";
19
+ } from "./chunk-GZ2TLGCG.js";
20
20
 
21
21
  // src/clis/index.ts
22
22
  import { Command as Command6, Option } from "@commander-js/extra-typings";
@@ -740,4 +740,4 @@ export {
740
740
  addGlobalArgs,
741
741
  applyEnv
742
742
  };
743
- //# sourceMappingURL=chunk-QVXW4O7X.js.map
743
+ //# sourceMappingURL=chunk-2J7IEVVC.js.map
@@ -16,7 +16,7 @@
16
16
 
17
17
 
18
18
 
19
- var _chunkW5SOPU7Icjs = require('./chunk-W5SOPU7I.cjs');
19
+ var _chunkP5WWWRSUcjs = require('./chunk-P5WWWRSU.cjs');
20
20
 
21
21
  // src/clis/index.ts
22
22
  var _extratypings = require('@commander-js/extra-typings');
@@ -70,12 +70,12 @@ function accountCli() {
70
70
  ).option("--register-keys-to <url>", "Register the keys to a url (normally this is localhost)").action(async ({ registerKeysTo, path }) => {
71
71
  const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program);
72
72
  const accountset = await accountsetFromCli(program);
73
- process2.env.KEYS_MNEMONIC ||= _chunkW5SOPU7Icjs.mnemonicGenerate.call(void 0, );
73
+ process2.env.KEYS_MNEMONIC ||= _chunkP5WWWRSUcjs.mnemonicGenerate.call(void 0, );
74
74
  if (registerKeysTo) {
75
75
  await accountset.registerKeys(registerKeysTo);
76
76
  console.log("Keys registered to", registerKeysTo);
77
77
  }
78
- const envData = _chunkW5SOPU7Icjs.filterUndefined.call(void 0, {
78
+ const envData = _chunkP5WWWRSUcjs.filterUndefined.call(void 0, {
79
79
  ACCOUNT_JSON_PATH: accountFilePath,
80
80
  ACCOUNT_SURI: accountSuri,
81
81
  ACCOUNT_PASSPHRASE: accountPassphrase,
@@ -95,7 +95,7 @@ function accountCli() {
95
95
  });
96
96
  program.command("new-key-seed").description("Create a new mnemonic for runtime keys").action(async () => {
97
97
  await _utilcrypto.cryptoWaitReady.call(void 0, );
98
- const mnemonic = _chunkW5SOPU7Icjs.mnemonicGenerate.call(void 0, );
98
+ const mnemonic = _chunkP5WWWRSUcjs.mnemonicGenerate.call(void 0, );
99
99
  console.log("New mnemonic (add this to your .env as KEYS_MNEMONIC):", mnemonic);
100
100
  process2.exit(0);
101
101
  });
@@ -136,7 +136,7 @@ function accountCli() {
136
136
  program.command("consolidate").description("Consolidate all argons into parent account").option(
137
137
  "-s, --subaccounts <range>",
138
138
  "Restrict this operation to a subset of the subaccounts (eg, 0-10)",
139
- _chunkW5SOPU7Icjs.parseSubaccountRange
139
+ _chunkP5WWWRSUcjs.parseSubaccountRange
140
140
  ).action(async ({ subaccounts }) => {
141
141
  const accountset = await accountsetFromCli(program);
142
142
  const result = await accountset.consolidate(subaccounts);
@@ -157,7 +157,7 @@ function vaultCli() {
157
157
  const program = new (0, _extratypings.Command)("vaults").description("Monitor vaults and manage securitization");
158
158
  program.command("list", { isDefault: true }).description("Show current state of vaults").action(async () => {
159
159
  const accountset = await accountsetFromCli(program);
160
- const vaults = new (0, _chunkW5SOPU7Icjs.VaultMonitor)(accountset, void 0, {
160
+ const vaults = new (0, _chunkP5WWWRSUcjs.VaultMonitor)(accountset, void 0, {
161
161
  vaultOnlyWatchMode: true
162
162
  });
163
163
  await vaults.monitor(true);
@@ -170,8 +170,8 @@ function vaultCli() {
170
170
  ).option("--ratio <ratio>", "The new securitization ratio", parseFloat).option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ tip, argons, vaultId, ratio }) => {
171
171
  const accountset = await accountsetFromCli(program);
172
172
  const client = await accountset.client;
173
- const resolvedTip = tip ? BigInt(tip * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : 0n;
174
- const microgons = BigInt(argons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON);
173
+ const resolvedTip = tip ? BigInt(tip * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : 0n;
174
+ const microgons = BigInt(argons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON);
175
175
  const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();
176
176
  if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {
177
177
  console.error("Vault does not belong to this account");
@@ -184,7 +184,7 @@ function vaultCli() {
184
184
  microgons,
185
185
  ratio !== void 0 ? BigNumber(ratio).times(BigNumber(2).pow(64)).toFixed(0) : rawVault.securitizationRatio.toBigInt()
186
186
  );
187
- const submit = new (0, _chunkW5SOPU7Icjs.TxSubmitter)(client, tx, accountset.txSubmitterPair);
187
+ const submit = new (0, _chunkP5WWWRSUcjs.TxSubmitter)(client, tx, accountset.txSubmitterPair);
188
188
  const canAfford = await submit.canAfford({
189
189
  tip: resolvedTip,
190
190
  unavailableBalance: additionalFunds
@@ -216,9 +216,9 @@ function vaultCli() {
216
216
  }
217
217
  const accountset = await accountsetFromCli(program);
218
218
  const client = await accountset.client;
219
- const resolvedTip = tip ? BigInt(tip * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : 0n;
220
- const microgons = BigInt(argons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON);
221
- const bitcoinLocks = new (0, _chunkW5SOPU7Icjs.BitcoinLocks)(Promise.resolve(client));
219
+ const resolvedTip = tip ? BigInt(tip * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : 0n;
220
+ const microgons = BigInt(argons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON);
221
+ const bitcoinLocks = new (0, _chunkP5WWWRSUcjs.BitcoinLocks)(Promise.resolve(client));
222
222
  const existentialDeposit = client.consts.balances.existentialDeposit.toBigInt();
223
223
  const tickDuration = (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();
224
224
  const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();
@@ -232,7 +232,7 @@ function vaultCli() {
232
232
  rawVault.securitizationRatio.toBigInt()
233
233
  );
234
234
  const vaultTxFee = (await vaultModifyTx.paymentInfo(accountset.txSubmitterPair)).partialFee.toBigInt();
235
- const vault = new (0, _chunkW5SOPU7Icjs.Vault)(vaultId, rawVault, tickDuration);
235
+ const vault = new (0, _chunkP5WWWRSUcjs.Vault)(vaultId, rawVault, tickDuration);
236
236
  const argonsNeeded = microgons - vault.securitization;
237
237
  const argonsAvailable = microgons - vault.availableBitcoinSpace();
238
238
  const account = await client.query.system.account(accountset.seedAddress);
@@ -271,7 +271,7 @@ function vaultCli() {
271
271
  btcFee,
272
272
  resolvedTip
273
273
  });
274
- const txSubmitter = new (0, _chunkW5SOPU7Icjs.TxSubmitter)(
274
+ const txSubmitter = new (0, _chunkP5WWWRSUcjs.TxSubmitter)(
275
275
  client,
276
276
  client.tx.utility.batchAll([vaultModifyTx, lockTx]),
277
277
  accountset.txSubmitterPair
@@ -295,7 +295,7 @@ function miningCli() {
295
295
  const program = new (0, _extratypings.Command)("mining").description("Watch mining seats or setup bidding");
296
296
  program.command("list", { isDefault: true }).description("Monitor all miners").action(async () => {
297
297
  const accountset = await accountsetFromCli(program);
298
- const bids = new (0, _chunkW5SOPU7Icjs.MiningBids)(accountset.client);
298
+ const bids = new (0, _chunkP5WWWRSUcjs.MiningBids)(accountset.client);
299
299
  const api = await accountset.client;
300
300
  let lastMiners = {};
301
301
  function print(blockNumber) {
@@ -311,7 +311,7 @@ function miningCli() {
311
311
  _consoletableprinter.printTable.call(void 0,
312
312
  toPrint.map((x) => ({
313
313
  ...x,
314
- bid: x.bid ? _chunkW5SOPU7Icjs.formatArgons.call(void 0, x.bid) : "-",
314
+ bid: x.bid ? _chunkP5WWWRSUcjs.formatArgons.call(void 0, x.bid) : "-",
315
315
  isLastDay: x.isLastDay ? "Y" : "",
316
316
  miner: x.miner
317
317
  }))
@@ -391,7 +391,7 @@ function miningCli() {
391
391
  }) => {
392
392
  const accountset = await accountsetFromCli(program, proxyForAddress);
393
393
  let cohortBidder;
394
- const miningBids = new (0, _chunkW5SOPU7Icjs.MiningBids)(accountset.client, false);
394
+ const miningBids = new (0, _chunkP5WWWRSUcjs.MiningBids)(accountset.client, false);
395
395
  const maxCohortSize = await miningBids.maxCohortSize();
396
396
  const stopBidder = async (unsubscribe2) => {
397
397
  if (cohortBidder) {
@@ -418,7 +418,7 @@ function miningCli() {
418
418
  const balance = await accountset.balance();
419
419
  const feeWiggleRoom = BigInt(25e3);
420
420
  const amountAvailable = balance - feeWiggleRoom;
421
- let maxBidAmount = maxBid ? BigInt(maxBid * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : void 0;
421
+ let maxBidAmount = maxBid ? BigInt(maxBid * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : void 0;
422
422
  let maxBalanceToUse = amountAvailable;
423
423
  if (maxBalance !== void 0) {
424
424
  if (maxBalance.endsWith("%")) {
@@ -429,7 +429,7 @@ function miningCli() {
429
429
  }
430
430
  maxBalanceToUse = amountToBid;
431
431
  } else {
432
- maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON));
432
+ maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON));
433
433
  }
434
434
  maxBidAmount ??= maxBalanceToUse / BigInt(seatsToWin);
435
435
  }
@@ -444,10 +444,10 @@ function miningCli() {
444
444
  if (cohortBidder && _optionalChain([cohortBidder, 'optionalAccess', _3 => _3.cohortStartingFrameId]) !== cohortStartingFrameId) {
445
445
  await stopBidder(unsubscribe);
446
446
  }
447
- cohortBidder = new (0, _chunkW5SOPU7Icjs.CohortBidder)(accountset, cohortStartingFrameId, subaccountRange, {
447
+ cohortBidder = new (0, _chunkP5WWWRSUcjs.CohortBidder)(accountset, cohortStartingFrameId, subaccountRange, {
448
448
  maxBid: maxBidAmount,
449
- minBid: BigInt((_nullishCoalesce(minBid, () => ( 0))) * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON),
450
- bidIncrement: BigInt(Math.floor(bidIncrement * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON)),
449
+ minBid: BigInt((_nullishCoalesce(minBid, () => ( 0))) * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON),
450
+ bidIncrement: BigInt(Math.floor(bidIncrement * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON)),
451
451
  maxBudget: maxBalanceToUse,
452
452
  bidDelay
453
453
  });
@@ -465,7 +465,7 @@ function miningCli() {
465
465
  parseFloat
466
466
  ).option("--proxy-passphrase <passphrase>", "The passphrase for your proxy account").action(async ({ outfile, proxyPassphrase, feeArgons }) => {
467
467
  const { mainchainUrl } = globalOptions(program);
468
- const client = await _chunkW5SOPU7Icjs.getClient.call(void 0, mainchainUrl);
468
+ const client = await _chunkP5WWWRSUcjs.getClient.call(void 0, mainchainUrl);
469
469
  const keyringPair = await saveKeyringPair({
470
470
  filePath: outfile,
471
471
  passphrase: proxyPassphrase
@@ -474,7 +474,7 @@ function miningCli() {
474
474
  console.log(`\u2705 Created proxy account at "${outfile}" with address ${address}`);
475
475
  const tx = client.tx.utility.batchAll([
476
476
  client.tx.proxy.addProxy(address, "MiningBid", 0),
477
- client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON))
477
+ client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON))
478
478
  ]);
479
479
  let keypair;
480
480
  try {
@@ -486,7 +486,7 @@ function miningCli() {
486
486
  process.exit(0);
487
487
  }
488
488
  try {
489
- await new (0, _chunkW5SOPU7Icjs.TxSubmitter)(client, tx, keypair).submit({
489
+ await new (0, _chunkP5WWWRSUcjs.TxSubmitter)(client, tx, keypair).submit({
490
490
  waitForBlock: true
491
491
  });
492
492
  console.log("Mining bid proxy added and funded.");
@@ -505,14 +505,14 @@ function liquidityCli() {
505
505
  const program = new (0, _extratypings.Command)("liquidity-pools").description("Monitor or bond to liquidity pools");
506
506
  program.command("list", { isDefault: true }).description("Show or watch the vault bid pool rewards").action(async () => {
507
507
  const accountset = await accountsetFromCli(program);
508
- const bidPool = new (0, _chunkW5SOPU7Icjs.BidPool)(accountset.client, accountset.txSubmitterPair);
508
+ const bidPool = new (0, _chunkP5WWWRSUcjs.BidPool)(accountset.client, accountset.txSubmitterPair);
509
509
  await bidPool.watch();
510
510
  });
511
511
  program.command("bond").description("Bond argons to a liquidity pool").requiredOption("-v, --vault-id <id>", "The vault id to use", parseInt).requiredOption("-a, --argons <amount>", "The number of argons to set the vault to", parseFloat).option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ tip, argons, vaultId }) => {
512
512
  const accountset = await accountsetFromCli(program);
513
- const resolvedTip = tip ? BigInt(tip * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : 0n;
514
- const microgons = BigInt(argons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON);
515
- const bidPool = new (0, _chunkW5SOPU7Icjs.BidPool)(accountset.client, accountset.txSubmitterPair);
513
+ const resolvedTip = tip ? BigInt(tip * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : 0n;
514
+ const microgons = BigInt(argons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON);
515
+ const bidPool = new (0, _chunkP5WWWRSUcjs.BidPool)(accountset.client, accountset.txSubmitterPair);
516
516
  await bidPool.bondArgons(vaultId, microgons, { tip: resolvedTip });
517
517
  console.log("Bonded argons to liquidity pool bond");
518
518
  process.exit();
@@ -523,17 +523,17 @@ function liquidityCli() {
523
523
  parseInt,
524
524
  30
525
525
  ).option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ maxArgons, minPctSharing, tip }) => {
526
- const maxAmountPerSlot = BigInt(maxArgons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON);
526
+ const maxAmountPerSlot = BigInt(maxArgons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON);
527
527
  const accountset = await accountsetFromCli(program);
528
- const vaults = new (0, _chunkW5SOPU7Icjs.VaultMonitor)(
528
+ const vaults = new (0, _chunkP5WWWRSUcjs.VaultMonitor)(
529
529
  accountset,
530
530
  {
531
531
  liquidityPoolSpaceAvailable: 1000000n
532
532
  },
533
533
  { shouldLog: false }
534
534
  );
535
- const bidPool = new (0, _chunkW5SOPU7Icjs.BidPool)(accountset.client, accountset.txSubmitterPair);
536
- const resolvedTip = tip ? BigInt(tip * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : 0n;
535
+ const bidPool = new (0, _chunkP5WWWRSUcjs.BidPool)(accountset.client, accountset.txSubmitterPair);
536
+ const resolvedTip = tip ? BigInt(tip * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : 0n;
537
537
  console.log("Waiting for liquidity pool space...");
538
538
  vaults.events.on("liquidity-pool-space-above", async (vaultId, amount) => {
539
539
  const vault = vaults.vaultsById[vaultId];
@@ -550,7 +550,7 @@ function liquidityCli() {
550
550
  await bidPool.bondArgons(vaultId, amountToAdd, { tip: resolvedTip });
551
551
  console.log("Bonding argons to vault liquidity pool", {
552
552
  vaultId,
553
- amount: _chunkW5SOPU7Icjs.formatArgons.call(void 0, amountToAdd)
553
+ amount: _chunkP5WWWRSUcjs.formatArgons.call(void 0, amountToAdd)
554
554
  });
555
555
  });
556
556
  await vaults.monitor();
@@ -568,15 +568,15 @@ function bitcoinCli() {
568
568
  parseFloat
569
569
  ).description("Watch for bitcoin space available").action(async ({ argons }) => {
570
570
  const accountset = await accountsetFromCli(program);
571
- const bot = new (0, _chunkW5SOPU7Icjs.VaultMonitor)(accountset, {
572
- bitcoinSpaceAvailable: argons ? BigInt(argons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : 1n
571
+ const bot = new (0, _chunkP5WWWRSUcjs.VaultMonitor)(accountset, {
572
+ bitcoinSpaceAvailable: argons ? BigInt(argons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : 1n
573
573
  });
574
574
  bot.events.on("bitcoin-space-above", async (vaultId, amount) => {
575
575
  const vault = bot.vaultsById[vaultId];
576
576
  const fee = vault.calculateBitcoinFee(amount);
577
577
  const ratio = 100n * fee / amount;
578
578
  console.log(
579
- `Vault ${vaultId} has ${_chunkW5SOPU7Icjs.formatArgons.call(void 0, amount)} argons available for bitcoin. Fee ratio is ${ratio}%`
579
+ `Vault ${vaultId} has ${_chunkP5WWWRSUcjs.formatArgons.call(void 0, amount)} argons available for bitcoin. Fee ratio is ${ratio}%`
580
580
  );
581
581
  });
582
582
  await bot.monitor();
@@ -586,18 +586,18 @@ function bitcoinCli() {
586
586
  "Bitcoin argons needed. NOTE: your account must have enough to cover fees + tip after this amount.",
587
587
  parseFloat
588
588
  ).requiredOption("--bitcoin-xpub <xpub>", "The xpub key to use for bitcoin locking").option("--max-lock-fee <argons>", "The max lock fee you're willing to pay", parseFloat).option("--tip <amount>", "The tip to include with the transaction", parseFloat, 0).action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {
589
- const amountToLock = BigInt(argons * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON);
589
+ const amountToLock = BigInt(argons * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON);
590
590
  const accountset = await accountsetFromCli(program);
591
- await _chunkW5SOPU7Icjs.BitcoinLocks.waitForSpace(accountset, {
591
+ await _chunkP5WWWRSUcjs.BitcoinLocks.waitForSpace(accountset, {
592
592
  argonAmount: amountToLock,
593
593
  bitcoinXpub,
594
- maxLockFee: maxLockFee !== void 0 ? BigInt(maxLockFee * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON) : void 0,
595
- tip: BigInt(tip * _chunkW5SOPU7Icjs.MICROGONS_PER_ARGON)
594
+ maxLockFee: maxLockFee !== void 0 ? BigInt(maxLockFee * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON) : void 0,
595
+ tip: BigInt(tip * _chunkP5WWWRSUcjs.MICROGONS_PER_ARGON)
596
596
  }).then(({ vaultId, satoshis, txFee, securityFee }) => {
597
597
  console.log(
598
- `Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${_chunkW5SOPU7Icjs.formatArgons.call(void 0,
598
+ `Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${_chunkP5WWWRSUcjs.formatArgons.call(void 0,
599
599
  txFee
600
- )}, Lock fee=${_chunkW5SOPU7Icjs.formatArgons.call(void 0, securityFee)}.`
600
+ )}, Lock fee=${_chunkP5WWWRSUcjs.formatArgons.call(void 0, securityFee)}.`
601
601
  );
602
602
  process.exit(0);
603
603
  });
@@ -622,13 +622,13 @@ async function keyringFromFile(opts) {
622
622
  const passphrasePath = opts.passphraseFile.replace("~", os.homedir());
623
623
  passphrase = await readFile(passphrasePath, "utf-8");
624
624
  }
625
- const mainAccount = new (0, _chunkW5SOPU7Icjs.Keyring)().createFromJson(json);
625
+ const mainAccount = new (0, _chunkP5WWWRSUcjs.Keyring)().createFromJson(json);
626
626
  mainAccount.decodePkcs8(passphrase);
627
627
  return mainAccount;
628
628
  }
629
629
  async function saveKeyringPair(opts) {
630
630
  const { filePath, passphrase, cryptoType } = opts;
631
- const keyring = _chunkW5SOPU7Icjs.createKeyringPair.call(void 0, { cryptoType });
631
+ const keyring = _chunkP5WWWRSUcjs.createKeyringPair.call(void 0, { cryptoType });
632
632
  if (filePath) {
633
633
  const json = keyring.toJson(passphrase);
634
634
  await writeFile(filePath, JSON.stringify(json, null, 2));
@@ -662,14 +662,14 @@ function buildCli() {
662
662
  new (0, _extratypings.Option)(
663
663
  "-s, --subaccounts <range>",
664
664
  "Restrict this operation to a subset of the subaccounts (eg, 0-10)"
665
- ).env("SUBACCOUNT_RANGE").argParser(_chunkW5SOPU7Icjs.parseSubaccountRange)
665
+ ).env("SUBACCOUNT_RANGE").argParser(_chunkP5WWWRSUcjs.parseSubaccountRange)
666
666
  ).addCommand(accountCli()).addCommand(vaultCli()).addCommand(miningCli()).addCommand(liquidityCli()).addCommand(bitcoinCli());
667
667
  }
668
668
  async function accountsetFromCli(program, proxyForAddress) {
669
669
  const opts = _optionalChain([program, 'access', _4 => _4.parent, 'optionalAccess', _5 => _5.optsWithGlobals, 'call', _6 => _6()]);
670
670
  let keypair;
671
671
  if (opts.accountSuri) {
672
- keypair = _chunkW5SOPU7Icjs.keyringFromSuri.call(void 0, opts.accountSuri);
672
+ keypair = _chunkP5WWWRSUcjs.keyringFromSuri.call(void 0, opts.accountSuri);
673
673
  }
674
674
  if (opts.accountFilePath) {
675
675
  keypair = await keyringFromFile({
@@ -683,16 +683,16 @@ async function accountsetFromCli(program, proxyForAddress) {
683
683
  "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
684
684
  );
685
685
  }
686
- const client = _chunkW5SOPU7Icjs.getClient.call(void 0, opts.mainchainUrl);
686
+ const client = _chunkP5WWWRSUcjs.getClient.call(void 0, opts.mainchainUrl);
687
687
  if (proxyForAddress) {
688
- return new (0, _chunkW5SOPU7Icjs.Accountset)({
688
+ return new (0, _chunkP5WWWRSUcjs.Accountset)({
689
689
  client,
690
690
  isProxy: true,
691
691
  seedAddress: proxyForAddress,
692
692
  txSubmitter: keypair
693
693
  });
694
694
  } else {
695
- return new (0, _chunkW5SOPU7Icjs.Accountset)({
695
+ return new (0, _chunkP5WWWRSUcjs.Accountset)({
696
696
  seedAccount: keypair,
697
697
  client
698
698
  });
@@ -740,4 +740,4 @@ function applyEnv(program) {
740
740
 
741
741
 
742
742
  exports.accountCli = accountCli; exports.vaultCli = vaultCli; exports.miningCli = miningCli; exports.liquidityCli = liquidityCli; exports.bitcoinCli = bitcoinCli; exports.keyringFromFile = keyringFromFile; exports.saveKeyringPair = saveKeyringPair; exports.globalOptions = globalOptions; exports.buildCli = buildCli; exports.accountsetFromCli = accountsetFromCli; exports.addGlobalArgs = addGlobalArgs; exports.applyEnv = applyEnv;
743
- //# sourceMappingURL=chunk-LB6BAURC.cjs.map
743
+ //# sourceMappingURL=chunk-BP7Y2NWQ.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/mainchain/mainchain/client/nodejs/lib/chunk-LB6BAURC.cjs","../src/clis/index.ts","../src/clis/accountCli.ts","../src/clis/vaultCli.ts","../src/clis/miningCli.ts","../src/clis/liquidityCli.ts","../src/clis/bitcoinCli.ts","../src/clis/keyringStore.ts"],"names":["addresses","Command","printTable","unsubscribe","env"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACpBA,2DAAgC;ADsBhC;AACA;AEvBA;AAEA,4DAA2B;AAC3B,mDAAgC;AAChC,wBAA8B;AAG9B,oFAAyB;AAGV,SAAR,UAAA,CAAA,EAA8B;AACnC,EAAA,MAAM,QAAA,EAAU,IAAI,0BAAA,CAAQ,UAAU,CAAA,CAAE,WAAA,CAAY,0CAA0C,CAAA;AAE9F,EAAA,OAAA,CACG,OAAA,CAAQ,OAAO,CAAA,CACf,WAAA,CAAY,wCAAwC,CAAA,CACpD,MAAA,CAAO,MAAA,CAAA,EAAA,GAAY;AAClB,IAAA,MAAM,WAAA,EAAa,MAAM,iBAAA,CAAkB,OAAO,CAAA;AAClD,IAAA,MAAM,cAAA,EAAgB,MAAM,UAAA,CAAW,WAAA,CAAY,CAAA;AAEnD,IAAA,aAAA,CAAc,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAA,EAAA,GAAU;AAClD,MAAA,OAAA,CAAQ,GAAA,CAAI,gCAAA,EAAkC,KAAK,CAAA;AAAA,IACrD,CAAC,CAAA;AACD,IAAA,aAAA,CAAc,MAAA,CAAO,EAAA,CAAG,QAAA,EAAU,CAAC,MAAA,EAAQ,MAAA,EAAA,GAAW;AACpD,MAAA,OAAA,CAAQ,GAAA,CAAI,6BAAA,EAA+B,MAAM,CAAA;AAAA,I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K,IAAA;AAGG,EAAA;AAKhB;AAEsB;AAIP,EAAA;AAET,EAAA;AACK,EAAA;AACG,IAAA;AACZ,EAAA;AACS,EAAA;AACS,IAAA;AACC,MAAA;AACH,MAAA;AACI,MAAA;AACjB,IAAA;AACH,EAAA;AACc,EAAA;AACF,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEe,EAAA;AACX,EAAA;AACS,IAAA;AACT,MAAA;AACS,MAAA;AACI,MAAA;AACA,MAAA;AACd,IAAA;AACI,EAAA;AACM,IAAA;AACI,MAAA;AACb,MAAA;AACD,IAAA;AACH,EAAA;AACF;AAIgB;AACH,EAAA;AACD,IAAA;AACN,MAAA;AACD,IAAA;AACU,IAAA;AACF,MAAA;AACL,QAAA;AACD,MAAA;AACH,IAAA;AACF,EAAA;AACF;AAEyB;AACf,EAAA;AACI,EAAA;AACH,EAAA;AACS,IAAA;AACJ,IAAA;AACI,IAAA;AAEF,MAAA;AACG,QAAA;AACD,QAAA;AACd,MAAA;AACF,IAAA;AACF,EAAA;AACOG,EAAAA;AACT;AD8kBsB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/mainchain/mainchain/client/nodejs/lib/chunk-LB6BAURC.cjs","sourcesContent":[null,"import { Command, Option } from '@commander-js/extra-typings';\nimport accountCli from './accountCli';\nimport { configDotenv } from 'dotenv';\nimport Path from 'node:path';\nimport vaultCli from './vaultCli';\nimport miningCli from './miningCli';\nimport liquidityCli from './liquidityCli';\nimport bitcoinCli from './bitcoinCli';\nimport { Accountset, parseSubaccountRange } from '../Accountset';\nimport { getClient, keyringFromSuri, KeyringPair } from '../index';\nimport { keyringFromFile, saveKeyringPair } from './keyringStore';\n\nexport {\n accountCli,\n vaultCli,\n miningCli,\n liquidityCli,\n bitcoinCli,\n keyringFromFile,\n saveKeyringPair,\n};\n\nexport function globalOptions(program: Command) {\n return program.optsWithGlobals() as IGlobalOptions;\n}\n\nexport function buildCli() {\n return new Command('Argon CLI')\n .option('-e, --env <path>', 'The path to the account .env file to load')\n .addOption(\n new Option('-u, --mainchain-url <url>', 'The mainchain URL to connect to')\n .default('wss://rpc.argon.network')\n .env('MAINCHAIN_URL'),\n )\n .addOption(\n new Option(\n '--account-file-path <jsonPath>',\n 'The path to your json seed file from polkadotjs',\n ).env('ACCOUNT_JSON_PATH'),\n )\n .addOption(\n new Option('--account-suri <secretUri>', 'A secret uri (suri) to use for the account').env(\n 'ACCOUNT_SURI',\n ),\n )\n .addOption(\n new Option('--account-passphrase <password>', 'The password for your seed file').env(\n 'ACCOUNT_PASSPHRASE',\n ),\n )\n .addOption(\n new Option('--account-passphrase-file <path>', 'The path to a password for your seed file'),\n )\n .addOption(\n new Option(\n '-s, --subaccounts <range>',\n 'Restrict this operation to a subset of the subaccounts (eg, 0-10)',\n )\n .env('SUBACCOUNT_RANGE')\n .argParser(parseSubaccountRange),\n )\n .addCommand(accountCli())\n .addCommand(vaultCli())\n .addCommand(miningCli())\n .addCommand(liquidityCli())\n .addCommand(bitcoinCli());\n}\n\nexport async function accountsetFromCli(\n program: Command,\n proxyForAddress?: string,\n): Promise<Accountset> {\n const opts = program.parent?.optsWithGlobals() as unknown as IGlobalOptions;\n\n let keypair: KeyringPair | undefined;\n if (opts.accountSuri) {\n keypair = keyringFromSuri(opts.accountSuri!);\n }\n if (opts.accountFilePath) {\n keypair = await keyringFromFile({\n filePath: opts.accountFilePath,\n passphrase: opts.accountPassphrase,\n passphraseFile: opts.accountPassphraseFile,\n });\n }\n if (!keypair) {\n throw new Error(\n 'No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)',\n );\n }\n\n const client = getClient(opts.mainchainUrl);\n if (proxyForAddress) {\n return new Accountset({\n client,\n isProxy: true,\n seedAddress: proxyForAddress,\n txSubmitter: keypair,\n });\n } else {\n return new Accountset({\n seedAccount: keypair,\n client,\n });\n }\n}\n\nexport type IGlobalOptions = ReturnType<ReturnType<typeof buildCli>['opts']>;\n\nexport function addGlobalArgs(program: ReturnType<typeof buildCli>) {\n for (const command of program.commands) {\n command.configureHelp({\n showGlobalOptions: true,\n });\n for (const nested of command.commands) {\n nested.configureHelp({\n showGlobalOptions: true,\n });\n }\n }\n}\n\nexport function applyEnv(program: ReturnType<typeof buildCli>): string | undefined {\n program.parseOptions(process.argv);\n const { env } = program.optsWithGlobals();\n if (env) {\n const envPath = Path.resolve(process.cwd(), env);\n const res = configDotenv({ path: envPath });\n if (res.parsed?.ACCOUNT_JSON_PATH) {\n // ensure path is relative to the env file if provided that way\n process.env.ACCOUNT_JSON_PATH = Path.resolve(\n Path.dirname(envPath),\n process.env.ACCOUNT_JSON_PATH!,\n );\n }\n }\n return env;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { filterUndefined, mnemonicGenerate } from '../index';\nimport { printTable } from 'console-table-printer';\nimport { cryptoWaitReady } from '@polkadot/util-crypto';\nimport { writeFileSync } from 'node:fs';\nimport { parseSubaccountRange } from '../Accountset';\nimport Env from '../env';\nimport * as process from 'node:process';\nimport { accountsetFromCli, globalOptions } from './index';\n\nexport default function accountCli() {\n const program = new Command('accounts').description('Manage subaccounts from a single keypair');\n\n program\n .command('watch')\n .description('Watch for blocks closed by subaccounts')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const accountMiners = await accountset.watchBlocks();\n\n accountMiners.events.on('mined', (_block, mined) => {\n console.log('Your accounts authored a block', mined);\n });\n accountMiners.events.on('minted', (_block, minted) => {\n console.log('Your accounts minted argons', minted);\n });\n });\n\n program\n .command('list', { isDefault: true })\n .description('Show subaccounts')\n .option('--addresses', 'Just show a list of ids')\n .action(async ({ addresses }) => {\n const { subaccounts } = globalOptions(program);\n const accountset = await accountsetFromCli(program);\n\n if (addresses) {\n const addresses = accountset.addresses;\n console.log(addresses.join(','));\n process.exit(0);\n }\n const [argonots, argons, seats, bids] = await Promise.all([\n accountset.totalArgonotsAt(),\n accountset.totalArgonsAt(),\n accountset.miningSeats(),\n accountset.bids(),\n ]);\n const accountSubset = subaccounts ? accountset.getAccountsInRange(subaccounts) : undefined;\n const status = accountset.status({\n argons,\n argonots,\n accountSubset,\n seats,\n bids,\n });\n printTable(status);\n process.exit(0);\n });\n\n program\n .command('create')\n .description('Create an account \"env\" file and optionally register keys')\n .requiredOption(\n '--path <path>',\n 'The path to an env file to create (convention is .env.<name>)',\n )\n .option('--register-keys-to <url>', 'Register the keys to a url (normally this is localhost)')\n .action(async ({ registerKeysTo, path }) => {\n const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program);\n const accountset = await accountsetFromCli(program);\n process.env.KEYS_MNEMONIC ||= mnemonicGenerate();\n if (registerKeysTo) {\n await accountset.registerKeys(registerKeysTo);\n console.log('Keys registered to', registerKeysTo);\n }\n const envData = filterUndefined<Env>({\n ACCOUNT_JSON_PATH: accountFilePath,\n ACCOUNT_SURI: accountSuri,\n ACCOUNT_PASSPHRASE: accountPassphrase,\n KEYS_MNEMONIC: process.env.KEYS_MNEMONIC,\n SUBACCOUNT_RANGE: '0-49',\n });\n let envfile = '';\n for (const [key, value] of Object.entries(envData)) {\n if (key) {\n const line = `${key}=${String(value)}`;\n envfile += line + '\\n';\n }\n }\n writeFileSync(path, envfile);\n console.log('Created env file at', path);\n process.exit();\n });\n\n program\n .command('new-key-seed')\n .description('Create a new mnemonic for runtime keys')\n .action(async () => {\n await cryptoWaitReady();\n const mnemonic = mnemonicGenerate();\n console.log('New mnemonic (add this to your .env as KEYS_MNEMONIC):', mnemonic);\n process.exit(0);\n });\n\n program\n .command('register-keys')\n .description('Create an insert-keys script with curl')\n .argument(\n '[node-rpc-url]',\n 'The url to your node host (should be installed on machine via localhost)',\n 'http://localhost:9944',\n )\n .option('--print-only', 'Output as curl commands instead of direct registration')\n .action(async (nodeRpcUrl, { printOnly }) => {\n const accountset = await accountsetFromCli(program);\n if (printOnly) {\n const { gran, seal } = accountset.keys();\n const commands: string[] = [];\n const data = [\n {\n jsonrpc: '2.0',\n id: 0,\n method: 'author_insertKey',\n params: ['gran', gran.privateKey, gran.publicKey],\n },\n {\n jsonrpc: '2.0',\n id: 1,\n method: 'author_insertKey',\n params: ['seal', seal.privateKey, seal.publicKey],\n },\n ];\n for (const key of data) {\n commands.push(\n `curl -X POST -H \"Content-Type: application/json\" -d '${JSON.stringify(key)}' ${nodeRpcUrl}`,\n );\n }\n\n console.log(commands.join(' && '));\n } else {\n await accountset.registerKeys(nodeRpcUrl);\n }\n process.exit();\n });\n\n program\n .command('consolidate')\n .description('Consolidate all argons into parent account')\n .option(\n '-s, --subaccounts <range>',\n 'Restrict this operation to a subset of the subaccounts (eg, 0-10)',\n parseSubaccountRange,\n )\n .action(async ({ subaccounts }) => {\n const accountset = await accountsetFromCli(program);\n const result = await accountset.consolidate(subaccounts);\n printTable(result);\n process.exit(0);\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { TxSubmitter } from '../TxSubmitter';\nimport { Vault } from '../Vault';\nimport { BitcoinLocks } from '../BitcoinLocks';\nimport { accountsetFromCli } from './index';\nimport { MICROGONS_PER_ARGON } from '../utils';\nimport { hexToU8a } from '@polkadot/util';\n\nexport default function vaultCli() {\n const program = new Command('vaults').description('Monitor vaults and manage securitization');\n\n program\n .command('list', { isDefault: true })\n .description('Show current state of vaults')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const vaults = new VaultMonitor(accountset, undefined, {\n vaultOnlyWatchMode: true,\n });\n await vaults.monitor(true);\n process.exit(0);\n });\n\n program\n .command('modify-securitization')\n .description('Change the vault securitization ratio')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption(\n '-a, --argons <amount>',\n 'The number of argons to set as securitization',\n parseFloat,\n )\n .option('--ratio <ratio>', 'The new securitization ratio', parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId, ratio }) => {\n const accountset = await accountsetFromCli(program);\n const client = await accountset.client;\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n\n const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();\n if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {\n console.error('Vault does not belong to this account');\n process.exit(1);\n }\n const existingFunds = rawVault.securitization.toBigInt();\n const additionalFunds = microgons > existingFunds ? microgons - existingFunds : 0n;\n const tx = client.tx.vaults.modifyFunding(\n vaultId,\n microgons,\n ratio !== undefined\n ? BigNumber(ratio).times(BigNumber(2).pow(64)).toFixed(0)\n : rawVault.securitizationRatio.toBigInt(),\n );\n const submit = new TxSubmitter(client, tx, accountset.txSubmitterPair);\n const canAfford = await submit.canAfford({\n tip: resolvedTip,\n unavailableBalance: additionalFunds,\n });\n if (!canAfford.canAfford) {\n console.warn('Insufficient balance to modify vault securitization', {\n ...canAfford,\n addedSecuritization: additionalFunds,\n });\n process.exit(1);\n }\n try {\n const result = await submit.submit({ tip: resolvedTip });\n await result.inBlockPromise;\n console.log('Vault securitization modified');\n process.exit();\n } catch (error) {\n console.error('Error modifying vault securitization', error);\n process.exit(1);\n }\n });\n\n program\n .command('make-bitcoin-space')\n .description('Make bitcoin space in a vault and lock it immediately in the same tx.')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption('-a, --argons <amount>', 'The number of argons to add', parseFloat)\n .requiredOption('--bitcoin-pubkey <pubkey>', 'The pubkey to use for the bitcoin lock')\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId, bitcoinPubkey }) => {\n let pubkey = bitcoinPubkey;\n if (!bitcoinPubkey.startsWith('0x')) {\n pubkey = `0x${bitcoinPubkey}`;\n }\n if (pubkey.length !== 68) {\n throw new Error('Bitcoin pubkey must be 66 characters (add 0x in front optionally)');\n }\n const accountset = await accountsetFromCli(program);\n const client = await accountset.client;\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n const bitcoinLocks = new BitcoinLocks(Promise.resolve(client));\n const existentialDeposit = client.consts.balances.existentialDeposit.toBigInt();\n const tickDuration = (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();\n\n const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();\n if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {\n console.error('Vault does not belong to this account');\n process.exit(1);\n }\n const vaultModifyTx = client.tx.vaults.modifyFunding(\n vaultId,\n microgons,\n rawVault.securitizationRatio.toBigInt(),\n );\n const vaultTxFee = (\n await vaultModifyTx.paymentInfo(accountset.txSubmitterPair)\n ).partialFee.toBigInt();\n const vault = new Vault(vaultId, rawVault, tickDuration);\n\n const argonsNeeded = microgons - vault.securitization;\n const argonsAvailable = microgons - vault.availableBitcoinSpace();\n\n const account = await client.query.system.account(accountset.seedAddress);\n const freeBalance = account.data.free.toBigInt();\n let satoshis = await bitcoinLocks.requiredSatoshisForArgonLiquidity(argonsAvailable);\n satoshis -= 20n; // keep some wiggle room since price can change\n const {\n tx: lockTx,\n securityFee: btcFee,\n txFee,\n } = await bitcoinLocks.createInitializeLockTx({\n vault,\n argonKeyring: accountset.txSubmitterPair,\n satoshis,\n ownerBitcoinPubkey: hexToU8a(pubkey),\n tip: resolvedTip,\n reducedBalanceBy: argonsNeeded + vaultTxFee + resolvedTip,\n });\n if (\n argonsNeeded + txFee + vaultTxFee + resolvedTip + btcFee + existentialDeposit >\n freeBalance\n ) {\n console.warn('Insufficient balance to add bitcoin space and use bitcoins', {\n freeBalance,\n txFee,\n vaultTxFee,\n btcFee,\n argonsAvailable,\n vaultMicrogons: microgons,\n existentialDeposit,\n neededBalanceAboveED: argonsNeeded + txFee + resolvedTip + btcFee + vaultTxFee,\n });\n process.exit(1);\n }\n console.log('Adding bitcoin space and locking bitcoins...', {\n newArgonsAvailable: argonsAvailable,\n txFee,\n vaultTxFee,\n btcFee,\n resolvedTip,\n });\n\n const txSubmitter = new TxSubmitter(\n client,\n client.tx.utility.batchAll([vaultModifyTx, lockTx]),\n accountset.txSubmitterPair,\n );\n const result = await txSubmitter.submit({ tip: resolvedTip });\n try {\n await result.inBlockPromise;\n console.log('Bitcoin space done');\n } catch (error) {\n console.error('Error using bitcoin space', error);\n process.exit(1);\n }\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { getClient, type KeyringPair, MICROGONS_PER_ARGON } from '../index';\nimport { printTable } from 'console-table-printer';\nimport { MiningBids } from '../MiningBids';\nimport { formatArgons } from '../utils';\nimport { TxSubmitter } from '../TxSubmitter';\nimport { accountsetFromCli, globalOptions, saveKeyringPair } from './index';\nimport { CohortBidder } from '../CohortBidder';\n\nexport default function miningCli() {\n const program = new Command('mining').description('Watch mining seats or setup bidding');\n\n program\n .command('list', { isDefault: true })\n .description('Monitor all miners')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const bids = new MiningBids(accountset.client);\n const api = await accountset.client;\n let lastMiners: {\n [frameId: string]: {\n miner: string;\n bid?: bigint;\n isLastDay?: boolean;\n };\n } = {};\n\n function print(blockNumber: number) {\n console.clear();\n const toPrint = Object.entries(lastMiners).map(([seat, miner]) => ({\n seat,\n ...miner,\n }));\n if (!toPrint.length) {\n console.log('No active miners');\n } else {\n console.log(`Miners at block ${blockNumber}`);\n printTable(\n toPrint.map(x => ({\n ...x,\n bid: x.bid ? formatArgons(x.bid) : '-',\n isLastDay: x.isLastDay ? 'Y' : '',\n miner: x.miner,\n })),\n );\n }\n if (!bids.nextCohort.length) {\n console.log('-------------------------------------\\nNo bids for next cohort');\n } else {\n bids.print();\n }\n }\n\n const { unsubscribe } = await bids.watch(accountset.namedAccounts, undefined, print);\n console.log('Watching miners...');\n const minMiners = api.consts.miningSlot.minCohortSize.toNumber();\n\n const unsub = await api.query.miningSlot.nextFrameId(async nextFrameId => {\n const frames = new Array(nextFrameId.toNumber())\n .fill(0)\n .map((_, i) => nextFrameId.toNumber() - i)\n .sort();\n const unseenFrames = new Set(frames);\n const entries = await api.query.miningSlot.minersByCohort.entries();\n const block = await api.query.system.number();\n\n const sortedEntries = entries.sort((a, b) => {\n const aIndex = a[0].args[0].toNumber();\n const bIndex = b[0].args[0].toNumber();\n return aIndex - bIndex;\n });\n\n for (const [rawFrameId, miners] of sortedEntries) {\n const frameId = rawFrameId.args[0].toNumber();\n unseenFrames.delete(frameId);\n let i = 0;\n for (const miner of miners) {\n const address = miner.accountId.toHuman();\n const startingFrameId = miner.startingFrameId.toNumber();\n lastMiners[`${frameId}-${i}`] = {\n miner: accountset.namedAccounts.get(address) ?? address,\n bid: miner.bid.toBigInt(),\n isLastDay: nextFrameId.toNumber() - startingFrameId === 10,\n };\n i++;\n }\n while (i < minMiners) {\n lastMiners[`${frameId}-${i}`] = {\n miner: 'none',\n };\n i++;\n }\n }\n for (const frameId of unseenFrames) {\n for (let i = 0; i < minMiners; i++) {\n lastMiners[`${frameId}-${i}`] = {\n miner: 'none',\n };\n }\n }\n print(block.toNumber());\n });\n process.on('SIGINT', () => {\n unsubscribe();\n unsub();\n process.exit(0);\n });\n });\n\n program\n .command('bid')\n .description('Submit mining bids within a range of parameters')\n .option('--min-bid <amount>', 'The minimum bid amount to use', parseFloat)\n .option('--max-bid <amount>', 'The maximum bid amount to use', parseFloat)\n .option('--max-seats <n>', 'The maximum number of seats to bid on for the slot', parseInt)\n .option(\n '--max-balance <argons>',\n \"Use a maximum amount of the user's balance for the slot. If this ends in a percent, it will be a percent of the funds\",\n )\n .option('--bid-increment <argons>', 'The bid increment', parseFloat, 0.01)\n .option('--bid-delay <ticks>', 'Delay between bids in ticks', parseInt, 0)\n .option('--run-continuous', 'Keep running and rebid every day')\n .option(\n '--proxy-for-address <address>',\n 'The seed account to proxy for (eg: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty)',\n )\n .action(\n async ({\n maxSeats,\n runContinuous,\n maxBid,\n minBid,\n maxBalance,\n bidDelay,\n bidIncrement,\n proxyForAddress,\n }) => {\n const accountset = await accountsetFromCli(program, proxyForAddress);\n\n let cohortBidder: CohortBidder | undefined;\n const miningBids = new MiningBids(accountset.client, false);\n const maxCohortSize = await miningBids.maxCohortSize();\n\n const stopBidder = async (unsubscribe: () => void) => {\n if (cohortBidder) {\n const stats = await cohortBidder.stop();\n console.log('Final bidding result', {\n cohortStartingFrameId: cohortBidder.cohortStartingFrameId,\n ...stats,\n });\n cohortBidder = undefined;\n if (!runContinuous) {\n unsubscribe();\n process.exit();\n }\n }\n };\n const { unsubscribe } = await miningBids.onCohortChange({\n async onBiddingEnd(cohortStartingFrameId) {\n if (cohortBidder?.cohortStartingFrameId === cohortStartingFrameId) {\n await stopBidder(unsubscribe);\n }\n },\n async onBiddingStart(cohortStartingFrameId) {\n const seatsToWin = maxSeats ?? maxCohortSize;\n const balance = await accountset.balance();\n const feeWiggleRoom = BigInt(25e3);\n const amountAvailable = balance - feeWiggleRoom;\n let maxBidAmount = maxBid ? BigInt(maxBid * MICROGONS_PER_ARGON) : undefined;\n let maxBalanceToUse = amountAvailable;\n if (maxBalance !== undefined) {\n if (maxBalance!.endsWith('%')) {\n let maxBalancePercent = parseInt(maxBalance);\n let amountToBid = (amountAvailable * BigInt(maxBalancePercent)) / 100n;\n if (amountToBid > balance) {\n amountToBid = balance;\n }\n maxBalanceToUse = amountToBid;\n } else {\n maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * MICROGONS_PER_ARGON));\n }\n\n maxBidAmount ??= maxBalanceToUse / BigInt(seatsToWin);\n }\n if (maxBalanceToUse > amountAvailable) {\n maxBalanceToUse = amountAvailable;\n }\n if (!maxBidAmount) {\n console.error('No max bid amount set');\n process.exit(1);\n }\n const subaccountRange = await accountset.getAvailableMinerAccounts(seatsToWin);\n\n if (cohortBidder && cohortBidder?.cohortStartingFrameId !== cohortStartingFrameId) {\n await stopBidder(unsubscribe);\n }\n cohortBidder = new CohortBidder(accountset, cohortStartingFrameId, subaccountRange, {\n maxBid: maxBidAmount,\n minBid: BigInt((minBid ?? 0) * MICROGONS_PER_ARGON),\n bidIncrement: BigInt(Math.floor(bidIncrement * MICROGONS_PER_ARGON)),\n maxBudget: maxBalanceToUse,\n bidDelay,\n });\n await cohortBidder.start();\n },\n });\n },\n );\n\n program\n .command('create-bid-proxy')\n .description('Create a mining-bid proxy account for your main account')\n .requiredOption(\n '--outfile <path>',\n 'The file to use to store the proxy account json (eg: proxy.json)',\n )\n .requiredOption(\n '--fee-argons <argons>',\n 'How many argons should be sent to the proxy account for fees (proxies must pay fees)',\n parseFloat,\n )\n .option('--proxy-passphrase <passphrase>', 'The passphrase for your proxy account')\n .action(async ({ outfile, proxyPassphrase, feeArgons }) => {\n const { mainchainUrl } = globalOptions(program);\n const client = await getClient(mainchainUrl);\n\n const keyringPair = await saveKeyringPair({\n filePath: outfile,\n passphrase: proxyPassphrase,\n });\n const address = keyringPair.address;\n console.log(`✅ Created proxy account at \"${outfile}\" with address ${address}`);\n const tx = client.tx.utility.batchAll([\n client.tx.proxy.addProxy(address, 'MiningBid', 0),\n client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * MICROGONS_PER_ARGON)),\n ]);\n let keypair: KeyringPair;\n try {\n const accountset = await accountsetFromCli(program);\n keypair = accountset.txSubmitterPair;\n } catch (e) {\n const polkadotLink = `https://polkadot.js.org/apps/?rpc=${mainchainUrl}#/extrinsics/decode/${tx.toHex()}`;\n console.log(`Complete the registration at this link:`, polkadotLink);\n process.exit(0);\n }\n try {\n await new TxSubmitter(client, tx, keypair).submit({\n waitForBlock: true,\n });\n\n console.log('Mining bid proxy added and funded.');\n process.exit();\n } catch (error) {\n console.error('Error adding mining proxy', error);\n process.exit(1);\n }\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { BidPool } from '../BidPool';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { formatArgons, MICROGONS_PER_ARGON } from '../utils';\nimport { accountsetFromCli } from './index';\n\nexport default function liquidityCli() {\n const program = new Command('liquidity-pools').description('Monitor or bond to liquidity pools');\n program\n .command('list', { isDefault: true })\n .description('Show or watch the vault bid pool rewards')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n await bidPool.watch();\n });\n\n program\n .command('bond')\n .description('Bond argons to a liquidity pool')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption('-a, --argons <amount>', 'The number of argons to set the vault to', parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId }) => {\n const accountset = await accountsetFromCli(program);\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n await bidPool.bondArgons(vaultId, microgons, { tip: resolvedTip });\n console.log('Bonded argons to liquidity pool bond');\n process.exit();\n });\n\n program\n .command('wait-for-space')\n .description('Add bonded argons to a liquidity pool when the market rate is favorable')\n .requiredOption('--max-argons <amount>', 'Max daily argons to use per slot', parseFloat)\n .option(\n '--min-pct-sharing <percent>',\n 'The minimum profit sharing percent to allow',\n parseInt,\n 30,\n )\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ maxArgons, minPctSharing, tip }) => {\n const maxAmountPerSlot = BigInt(maxArgons * MICROGONS_PER_ARGON);\n\n const accountset = await accountsetFromCli(program);\n const vaults = new VaultMonitor(\n accountset,\n {\n liquidityPoolSpaceAvailable: 1_000_000n,\n },\n { shouldLog: false },\n );\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n console.log('Waiting for liquidity pool space...');\n\n vaults.events.on('liquidity-pool-space-above', async (vaultId, amount) => {\n const vault = vaults.vaultsById[vaultId];\n if (vault.terms.liquidityPoolProfitSharing.times(100).toNumber() < minPctSharing) {\n console.info(\n `Skipping vault ${vaultId} due to lower profit sharing than ${minPctSharing}%`,\n );\n return;\n }\n let amountToAdd = amount;\n if (amountToAdd > maxAmountPerSlot) {\n amountToAdd = maxAmountPerSlot;\n }\n await bidPool.bondArgons(vaultId, amountToAdd, { tip: resolvedTip });\n console.log('Bonding argons to vault liquidity pool', {\n vaultId,\n amount: formatArgons(amountToAdd),\n });\n });\n await vaults.monitor();\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { BitcoinLocks } from '../BitcoinLocks';\nimport { formatArgons, MICROGONS_PER_ARGON } from '../utils';\nimport { accountsetFromCli } from './index';\n\nexport default function bitcoinCli() {\n const program = new Command('bitcoin').description('Wait for bitcoin space');\n\n program\n .command('watch')\n .requiredOption(\n '-a, --argons <argons>',\n 'Alert when bitcoin space exceeds this amount',\n parseFloat,\n )\n .description('Watch for bitcoin space available')\n .action(async ({ argons }) => {\n const accountset = await accountsetFromCli(program);\n const bot = new VaultMonitor(accountset, {\n bitcoinSpaceAvailable: argons ? BigInt(argons * MICROGONS_PER_ARGON) : 1n,\n });\n bot.events.on('bitcoin-space-above', async (vaultId, amount) => {\n const vault = bot.vaultsById[vaultId];\n const fee = vault.calculateBitcoinFee(amount);\n const ratio = (100n * fee) / amount;\n console.log(\n `Vault ${vaultId} has ${formatArgons(amount)} argons available for bitcoin. Fee ratio is ${ratio}%`,\n );\n });\n await bot.monitor();\n });\n\n program\n .command('wait-for-space')\n .description('Lock bitcoin when available at a given rate')\n .requiredOption(\n '-a, --argons <amount>',\n 'Bitcoin argons needed. NOTE: your account must have enough to cover fees + tip after this amount.',\n parseFloat,\n )\n .requiredOption('--bitcoin-xpub <xpub>', 'The xpub key to use for bitcoin locking')\n .option('--max-lock-fee <argons>', \"The max lock fee you're willing to pay\", parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat, 0.0)\n .action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {\n const amountToLock = BigInt(argons * MICROGONS_PER_ARGON);\n\n const accountset = await accountsetFromCli(program);\n await BitcoinLocks.waitForSpace(accountset, {\n argonAmount: amountToLock,\n bitcoinXpub,\n maxLockFee: maxLockFee !== undefined ? BigInt(maxLockFee * MICROGONS_PER_ARGON) : undefined,\n tip: BigInt(tip * MICROGONS_PER_ARGON),\n }).then(({ vaultId, satoshis, txFee, securityFee }) => {\n console.log(\n `Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${formatArgons(\n txFee,\n )}, Lock fee=${formatArgons(securityFee)}.`,\n );\n process.exit(0);\n });\n });\n\n return program;\n}\n","import { createKeyringPair, Keyring, KeyringPair } from '../index';\nimport { promises } from 'node:fs';\nimport * as os from 'node:os';\n\nconst { readFile, writeFile } = promises;\n\nexport async function keyringFromFile(opts: {\n filePath: string;\n passphrase?: string;\n passphraseFile?: string;\n}): Promise<KeyringPair> {\n if (!opts.filePath) {\n throw new Error(\n 'No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)',\n );\n }\n const path = opts.filePath.replace('~', os.homedir());\n const json = JSON.parse(await readFile(path, 'utf-8'));\n let passphrase = opts.passphrase;\n if (opts.passphraseFile) {\n const passphrasePath = opts.passphraseFile.replace('~', os.homedir());\n passphrase = await readFile(passphrasePath, 'utf-8');\n }\n const mainAccount = new Keyring().createFromJson(json);\n mainAccount.decodePkcs8(passphrase);\n return mainAccount;\n}\n\nexport async function saveKeyringPair(opts: {\n filePath: string;\n passphrase?: string;\n cryptoType?: 'sr25519' | 'ed25519';\n}): Promise<KeyringPair> {\n const { filePath, passphrase, cryptoType } = opts;\n const keyring = createKeyringPair({ cryptoType });\n if (filePath) {\n const json = keyring.toJson(passphrase);\n await writeFile(filePath, JSON.stringify(json, null, 2));\n }\n return keyring;\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/mainchain/mainchain/client/nodejs/lib/chunk-BP7Y2NWQ.cjs","../src/clis/index.ts","../src/clis/accountCli.ts","../src/clis/vaultCli.ts","../src/clis/miningCli.ts","../src/clis/liquidityCli.ts","../src/clis/bitcoinCli.ts","../src/clis/keyringStore.ts"],"names":["addresses","Command","printTable","unsubscribe","env"],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACpBA,2DAAgC;ADsBhC;AACA;AEvBA;AAEA,4DAA2B;AAC3B,mDAAgC;AAChC,wBAA8B;AAG9B,oFAAyB;AAGV,SAAR,UAAA,CAAA,EAA8B;AACnC,EAAA,MAAM,QAAA,EAAU,IAAI,0BAAA,CAAQ,UAAU,CAAA,CAAE,WAAA,CAAY,0CAA0C,CAAA;AAE9F,EAAA,OAAA,CACG,OAAA,CAAQ,OAAO,CAAA,CACf,WAAA,CAAY,wCAAwC,CAAA,CACpD,MAAA,CAAO,MAAA,CAAA,EAAA,GAAY;AAClB,IAAA,MAAM,WAAA,EAAa,MAAM,iBAAA,CAAkB,OAAO,CAAA;AAClD,IAAA,MAAM,cAAA,EAAgB,MAAM,UAAA,CAAW,WAAA,CAAY,CAAA;AAEnD,IAAA,aAAA,CAAc,MAAA,CAAO,EAAA,CAAG,OAAA,EAAS,CAAC,MAAA,EAAQ,KAAA,EAAA,GAAU;AAClD,MAAA,OAAA,CAAQ,GAAA,CAAI,gCAAA,EAAkC,KAAK,CAAA;AAAA,IACrD,CAAC,CAAA;AACD,IAAA,aAAA,CAAc,MAAA,CAAO,EAAA,CAAG,QAAA,EAAU,CAAC,MAAA,EAAQ,MAAA,EAAA,GAAW;AACpD,MAAA,OAAA,CAAQ,GAAA,CAAI,6BAAA,EAA+B,MAAM,CAAA;AAAA,IACnD,CAAC,CAAA;AAAA,EACH,CAAC,CAAA;AAEH,EAAA,OAAA,CACG,OAAA,CAAQ,MAAA,EAAQ,EAAE,SAAA,EAAW,KAAK,CAAC,CAAA,CACnC,WAAA,CAAY,kBAAkB,CAA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A;AACH,EAAA;AACc,EAAA;AACF,IAAA;AACR,MAAA;AACF,IAAA;AACF,EAAA;AAEe,EAAA;AACX,EAAA;AACS,IAAA;AACT,MAAA;AACS,MAAA;AACI,MAAA;AACA,MAAA;AACd,IAAA;AACI,EAAA;AACM,IAAA;AACI,MAAA;AACb,MAAA;AACD,IAAA;AACH,EAAA;AACF;AAIgB;AACH,EAAA;AACD,IAAA;AACN,MAAA;AACD,IAAA;AACU,IAAA;AACF,MAAA;AACL,QAAA;AACD,MAAA;AACH,IAAA;AACF,EAAA;AACF;AAEyB;AACf,EAAA;AACI,EAAA;AACH,EAAA;AACS,IAAA;AACJ,IAAA;AACI,IAAA;AAEF,MAAA;AACG,QAAA;AACD,QAAA;AACd,MAAA;AACF,IAAA;AACF,EAAA;AACOG,EAAAA;AACT;AD8kBsB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/mainchain/mainchain/client/nodejs/lib/chunk-BP7Y2NWQ.cjs","sourcesContent":[null,"import { Command, Option } from '@commander-js/extra-typings';\nimport accountCli from './accountCli';\nimport { configDotenv } from 'dotenv';\nimport Path from 'node:path';\nimport vaultCli from './vaultCli';\nimport miningCli from './miningCli';\nimport liquidityCli from './liquidityCli';\nimport bitcoinCli from './bitcoinCli';\nimport { Accountset, parseSubaccountRange } from '../Accountset';\nimport { getClient, keyringFromSuri, KeyringPair } from '../index';\nimport { keyringFromFile, saveKeyringPair } from './keyringStore';\n\nexport {\n accountCli,\n vaultCli,\n miningCli,\n liquidityCli,\n bitcoinCli,\n keyringFromFile,\n saveKeyringPair,\n};\n\nexport function globalOptions(program: Command) {\n return program.optsWithGlobals() as IGlobalOptions;\n}\n\nexport function buildCli() {\n return new Command('Argon CLI')\n .option('-e, --env <path>', 'The path to the account .env file to load')\n .addOption(\n new Option('-u, --mainchain-url <url>', 'The mainchain URL to connect to')\n .default('wss://rpc.argon.network')\n .env('MAINCHAIN_URL'),\n )\n .addOption(\n new Option(\n '--account-file-path <jsonPath>',\n 'The path to your json seed file from polkadotjs',\n ).env('ACCOUNT_JSON_PATH'),\n )\n .addOption(\n new Option('--account-suri <secretUri>', 'A secret uri (suri) to use for the account').env(\n 'ACCOUNT_SURI',\n ),\n )\n .addOption(\n new Option('--account-passphrase <password>', 'The password for your seed file').env(\n 'ACCOUNT_PASSPHRASE',\n ),\n )\n .addOption(\n new Option('--account-passphrase-file <path>', 'The path to a password for your seed file'),\n )\n .addOption(\n new Option(\n '-s, --subaccounts <range>',\n 'Restrict this operation to a subset of the subaccounts (eg, 0-10)',\n )\n .env('SUBACCOUNT_RANGE')\n .argParser(parseSubaccountRange),\n )\n .addCommand(accountCli())\n .addCommand(vaultCli())\n .addCommand(miningCli())\n .addCommand(liquidityCli())\n .addCommand(bitcoinCli());\n}\n\nexport async function accountsetFromCli(\n program: Command,\n proxyForAddress?: string,\n): Promise<Accountset> {\n const opts = program.parent?.optsWithGlobals() as unknown as IGlobalOptions;\n\n let keypair: KeyringPair | undefined;\n if (opts.accountSuri) {\n keypair = keyringFromSuri(opts.accountSuri!);\n }\n if (opts.accountFilePath) {\n keypair = await keyringFromFile({\n filePath: opts.accountFilePath,\n passphrase: opts.accountPassphrase,\n passphraseFile: opts.accountPassphraseFile,\n });\n }\n if (!keypair) {\n throw new Error(\n 'No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)',\n );\n }\n\n const client = getClient(opts.mainchainUrl);\n if (proxyForAddress) {\n return new Accountset({\n client,\n isProxy: true,\n seedAddress: proxyForAddress,\n txSubmitter: keypair,\n });\n } else {\n return new Accountset({\n seedAccount: keypair,\n client,\n });\n }\n}\n\nexport type IGlobalOptions = ReturnType<ReturnType<typeof buildCli>['opts']>;\n\nexport function addGlobalArgs(program: ReturnType<typeof buildCli>) {\n for (const command of program.commands) {\n command.configureHelp({\n showGlobalOptions: true,\n });\n for (const nested of command.commands) {\n nested.configureHelp({\n showGlobalOptions: true,\n });\n }\n }\n}\n\nexport function applyEnv(program: ReturnType<typeof buildCli>): string | undefined {\n program.parseOptions(process.argv);\n const { env } = program.optsWithGlobals();\n if (env) {\n const envPath = Path.resolve(process.cwd(), env);\n const res = configDotenv({ path: envPath });\n if (res.parsed?.ACCOUNT_JSON_PATH) {\n // ensure path is relative to the env file if provided that way\n process.env.ACCOUNT_JSON_PATH = Path.resolve(\n Path.dirname(envPath),\n process.env.ACCOUNT_JSON_PATH!,\n );\n }\n }\n return env;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { filterUndefined, mnemonicGenerate } from '../index';\nimport { printTable } from 'console-table-printer';\nimport { cryptoWaitReady } from '@polkadot/util-crypto';\nimport { writeFileSync } from 'node:fs';\nimport { parseSubaccountRange } from '../Accountset';\nimport Env from '../env';\nimport * as process from 'node:process';\nimport { accountsetFromCli, globalOptions } from './index';\n\nexport default function accountCli() {\n const program = new Command('accounts').description('Manage subaccounts from a single keypair');\n\n program\n .command('watch')\n .description('Watch for blocks closed by subaccounts')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const accountMiners = await accountset.watchBlocks();\n\n accountMiners.events.on('mined', (_block, mined) => {\n console.log('Your accounts authored a block', mined);\n });\n accountMiners.events.on('minted', (_block, minted) => {\n console.log('Your accounts minted argons', minted);\n });\n });\n\n program\n .command('list', { isDefault: true })\n .description('Show subaccounts')\n .option('--addresses', 'Just show a list of ids')\n .action(async ({ addresses }) => {\n const { subaccounts } = globalOptions(program);\n const accountset = await accountsetFromCli(program);\n\n if (addresses) {\n const addresses = accountset.addresses;\n console.log(addresses.join(','));\n process.exit(0);\n }\n const [argonots, argons, seats, bids] = await Promise.all([\n accountset.totalArgonotsAt(),\n accountset.totalArgonsAt(),\n accountset.miningSeats(),\n accountset.bids(),\n ]);\n const accountSubset = subaccounts ? accountset.getAccountsInRange(subaccounts) : undefined;\n const status = accountset.status({\n argons,\n argonots,\n accountSubset,\n seats,\n bids,\n });\n printTable(status);\n process.exit(0);\n });\n\n program\n .command('create')\n .description('Create an account \"env\" file and optionally register keys')\n .requiredOption(\n '--path <path>',\n 'The path to an env file to create (convention is .env.<name>)',\n )\n .option('--register-keys-to <url>', 'Register the keys to a url (normally this is localhost)')\n .action(async ({ registerKeysTo, path }) => {\n const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program);\n const accountset = await accountsetFromCli(program);\n process.env.KEYS_MNEMONIC ||= mnemonicGenerate();\n if (registerKeysTo) {\n await accountset.registerKeys(registerKeysTo);\n console.log('Keys registered to', registerKeysTo);\n }\n const envData = filterUndefined<Env>({\n ACCOUNT_JSON_PATH: accountFilePath,\n ACCOUNT_SURI: accountSuri,\n ACCOUNT_PASSPHRASE: accountPassphrase,\n KEYS_MNEMONIC: process.env.KEYS_MNEMONIC,\n SUBACCOUNT_RANGE: '0-49',\n });\n let envfile = '';\n for (const [key, value] of Object.entries(envData)) {\n if (key) {\n const line = `${key}=${String(value)}`;\n envfile += line + '\\n';\n }\n }\n writeFileSync(path, envfile);\n console.log('Created env file at', path);\n process.exit();\n });\n\n program\n .command('new-key-seed')\n .description('Create a new mnemonic for runtime keys')\n .action(async () => {\n await cryptoWaitReady();\n const mnemonic = mnemonicGenerate();\n console.log('New mnemonic (add this to your .env as KEYS_MNEMONIC):', mnemonic);\n process.exit(0);\n });\n\n program\n .command('register-keys')\n .description('Create an insert-keys script with curl')\n .argument(\n '[node-rpc-url]',\n 'The url to your node host (should be installed on machine via localhost)',\n 'http://localhost:9944',\n )\n .option('--print-only', 'Output as curl commands instead of direct registration')\n .action(async (nodeRpcUrl, { printOnly }) => {\n const accountset = await accountsetFromCli(program);\n if (printOnly) {\n const { gran, seal } = accountset.keys();\n const commands: string[] = [];\n const data = [\n {\n jsonrpc: '2.0',\n id: 0,\n method: 'author_insertKey',\n params: ['gran', gran.privateKey, gran.publicKey],\n },\n {\n jsonrpc: '2.0',\n id: 1,\n method: 'author_insertKey',\n params: ['seal', seal.privateKey, seal.publicKey],\n },\n ];\n for (const key of data) {\n commands.push(\n `curl -X POST -H \"Content-Type: application/json\" -d '${JSON.stringify(key)}' ${nodeRpcUrl}`,\n );\n }\n\n console.log(commands.join(' && '));\n } else {\n await accountset.registerKeys(nodeRpcUrl);\n }\n process.exit();\n });\n\n program\n .command('consolidate')\n .description('Consolidate all argons into parent account')\n .option(\n '-s, --subaccounts <range>',\n 'Restrict this operation to a subset of the subaccounts (eg, 0-10)',\n parseSubaccountRange,\n )\n .action(async ({ subaccounts }) => {\n const accountset = await accountsetFromCli(program);\n const result = await accountset.consolidate(subaccounts);\n printTable(result);\n process.exit(0);\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { TxSubmitter } from '../TxSubmitter';\nimport { Vault } from '../Vault';\nimport { BitcoinLocks } from '../BitcoinLocks';\nimport { accountsetFromCli } from './index';\nimport { MICROGONS_PER_ARGON } from '../utils';\nimport { hexToU8a } from '@polkadot/util';\n\nexport default function vaultCli() {\n const program = new Command('vaults').description('Monitor vaults and manage securitization');\n\n program\n .command('list', { isDefault: true })\n .description('Show current state of vaults')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const vaults = new VaultMonitor(accountset, undefined, {\n vaultOnlyWatchMode: true,\n });\n await vaults.monitor(true);\n process.exit(0);\n });\n\n program\n .command('modify-securitization')\n .description('Change the vault securitization ratio')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption(\n '-a, --argons <amount>',\n 'The number of argons to set as securitization',\n parseFloat,\n )\n .option('--ratio <ratio>', 'The new securitization ratio', parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId, ratio }) => {\n const accountset = await accountsetFromCli(program);\n const client = await accountset.client;\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n\n const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();\n if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {\n console.error('Vault does not belong to this account');\n process.exit(1);\n }\n const existingFunds = rawVault.securitization.toBigInt();\n const additionalFunds = microgons > existingFunds ? microgons - existingFunds : 0n;\n const tx = client.tx.vaults.modifyFunding(\n vaultId,\n microgons,\n ratio !== undefined\n ? BigNumber(ratio).times(BigNumber(2).pow(64)).toFixed(0)\n : rawVault.securitizationRatio.toBigInt(),\n );\n const submit = new TxSubmitter(client, tx, accountset.txSubmitterPair);\n const canAfford = await submit.canAfford({\n tip: resolvedTip,\n unavailableBalance: additionalFunds,\n });\n if (!canAfford.canAfford) {\n console.warn('Insufficient balance to modify vault securitization', {\n ...canAfford,\n addedSecuritization: additionalFunds,\n });\n process.exit(1);\n }\n try {\n const result = await submit.submit({ tip: resolvedTip });\n await result.inBlockPromise;\n console.log('Vault securitization modified');\n process.exit();\n } catch (error) {\n console.error('Error modifying vault securitization', error);\n process.exit(1);\n }\n });\n\n program\n .command('make-bitcoin-space')\n .description('Make bitcoin space in a vault and lock it immediately in the same tx.')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption('-a, --argons <amount>', 'The number of argons to add', parseFloat)\n .requiredOption('--bitcoin-pubkey <pubkey>', 'The pubkey to use for the bitcoin lock')\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId, bitcoinPubkey }) => {\n let pubkey = bitcoinPubkey;\n if (!bitcoinPubkey.startsWith('0x')) {\n pubkey = `0x${bitcoinPubkey}`;\n }\n if (pubkey.length !== 68) {\n throw new Error('Bitcoin pubkey must be 66 characters (add 0x in front optionally)');\n }\n const accountset = await accountsetFromCli(program);\n const client = await accountset.client;\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n const bitcoinLocks = new BitcoinLocks(Promise.resolve(client));\n const existentialDeposit = client.consts.balances.existentialDeposit.toBigInt();\n const tickDuration = (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();\n\n const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();\n if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {\n console.error('Vault does not belong to this account');\n process.exit(1);\n }\n const vaultModifyTx = client.tx.vaults.modifyFunding(\n vaultId,\n microgons,\n rawVault.securitizationRatio.toBigInt(),\n );\n const vaultTxFee = (\n await vaultModifyTx.paymentInfo(accountset.txSubmitterPair)\n ).partialFee.toBigInt();\n const vault = new Vault(vaultId, rawVault, tickDuration);\n\n const argonsNeeded = microgons - vault.securitization;\n const argonsAvailable = microgons - vault.availableBitcoinSpace();\n\n const account = await client.query.system.account(accountset.seedAddress);\n const freeBalance = account.data.free.toBigInt();\n let satoshis = await bitcoinLocks.requiredSatoshisForArgonLiquidity(argonsAvailable);\n satoshis -= 20n; // keep some wiggle room since price can change\n const {\n tx: lockTx,\n securityFee: btcFee,\n txFee,\n } = await bitcoinLocks.createInitializeLockTx({\n vault,\n argonKeyring: accountset.txSubmitterPair,\n satoshis,\n ownerBitcoinPubkey: hexToU8a(pubkey),\n tip: resolvedTip,\n reducedBalanceBy: argonsNeeded + vaultTxFee + resolvedTip,\n });\n if (\n argonsNeeded + txFee + vaultTxFee + resolvedTip + btcFee + existentialDeposit >\n freeBalance\n ) {\n console.warn('Insufficient balance to add bitcoin space and use bitcoins', {\n freeBalance,\n txFee,\n vaultTxFee,\n btcFee,\n argonsAvailable,\n vaultMicrogons: microgons,\n existentialDeposit,\n neededBalanceAboveED: argonsNeeded + txFee + resolvedTip + btcFee + vaultTxFee,\n });\n process.exit(1);\n }\n console.log('Adding bitcoin space and locking bitcoins...', {\n newArgonsAvailable: argonsAvailable,\n txFee,\n vaultTxFee,\n btcFee,\n resolvedTip,\n });\n\n const txSubmitter = new TxSubmitter(\n client,\n client.tx.utility.batchAll([vaultModifyTx, lockTx]),\n accountset.txSubmitterPair,\n );\n const result = await txSubmitter.submit({ tip: resolvedTip });\n try {\n await result.inBlockPromise;\n console.log('Bitcoin space done');\n } catch (error) {\n console.error('Error using bitcoin space', error);\n process.exit(1);\n }\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { getClient, type KeyringPair, MICROGONS_PER_ARGON } from '../index';\nimport { printTable } from 'console-table-printer';\nimport { MiningBids } from '../MiningBids';\nimport { formatArgons } from '../utils';\nimport { TxSubmitter } from '../TxSubmitter';\nimport { accountsetFromCli, globalOptions, saveKeyringPair } from './index';\nimport { CohortBidder } from '../CohortBidder';\n\nexport default function miningCli() {\n const program = new Command('mining').description('Watch mining seats or setup bidding');\n\n program\n .command('list', { isDefault: true })\n .description('Monitor all miners')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const bids = new MiningBids(accountset.client);\n const api = await accountset.client;\n let lastMiners: {\n [frameId: string]: {\n miner: string;\n bid?: bigint;\n isLastDay?: boolean;\n };\n } = {};\n\n function print(blockNumber: number) {\n console.clear();\n const toPrint = Object.entries(lastMiners).map(([seat, miner]) => ({\n seat,\n ...miner,\n }));\n if (!toPrint.length) {\n console.log('No active miners');\n } else {\n console.log(`Miners at block ${blockNumber}`);\n printTable(\n toPrint.map(x => ({\n ...x,\n bid: x.bid ? formatArgons(x.bid) : '-',\n isLastDay: x.isLastDay ? 'Y' : '',\n miner: x.miner,\n })),\n );\n }\n if (!bids.nextCohort.length) {\n console.log('-------------------------------------\\nNo bids for next cohort');\n } else {\n bids.print();\n }\n }\n\n const { unsubscribe } = await bids.watch(accountset.namedAccounts, undefined, print);\n console.log('Watching miners...');\n const minMiners = api.consts.miningSlot.minCohortSize.toNumber();\n\n const unsub = await api.query.miningSlot.nextFrameId(async nextFrameId => {\n const frames = new Array(nextFrameId.toNumber())\n .fill(0)\n .map((_, i) => nextFrameId.toNumber() - i)\n .sort();\n const unseenFrames = new Set(frames);\n const entries = await api.query.miningSlot.minersByCohort.entries();\n const block = await api.query.system.number();\n\n const sortedEntries = entries.sort((a, b) => {\n const aIndex = a[0].args[0].toNumber();\n const bIndex = b[0].args[0].toNumber();\n return aIndex - bIndex;\n });\n\n for (const [rawFrameId, miners] of sortedEntries) {\n const frameId = rawFrameId.args[0].toNumber();\n unseenFrames.delete(frameId);\n let i = 0;\n for (const miner of miners) {\n const address = miner.accountId.toHuman();\n const startingFrameId = miner.startingFrameId.toNumber();\n lastMiners[`${frameId}-${i}`] = {\n miner: accountset.namedAccounts.get(address) ?? address,\n bid: miner.bid.toBigInt(),\n isLastDay: nextFrameId.toNumber() - startingFrameId === 10,\n };\n i++;\n }\n while (i < minMiners) {\n lastMiners[`${frameId}-${i}`] = {\n miner: 'none',\n };\n i++;\n }\n }\n for (const frameId of unseenFrames) {\n for (let i = 0; i < minMiners; i++) {\n lastMiners[`${frameId}-${i}`] = {\n miner: 'none',\n };\n }\n }\n print(block.toNumber());\n });\n process.on('SIGINT', () => {\n unsubscribe();\n unsub();\n process.exit(0);\n });\n });\n\n program\n .command('bid')\n .description('Submit mining bids within a range of parameters')\n .option('--min-bid <amount>', 'The minimum bid amount to use', parseFloat)\n .option('--max-bid <amount>', 'The maximum bid amount to use', parseFloat)\n .option('--max-seats <n>', 'The maximum number of seats to bid on for the slot', parseInt)\n .option(\n '--max-balance <argons>',\n \"Use a maximum amount of the user's balance for the slot. If this ends in a percent, it will be a percent of the funds\",\n )\n .option('--bid-increment <argons>', 'The bid increment', parseFloat, 0.01)\n .option('--bid-delay <ticks>', 'Delay between bids in ticks', parseInt, 0)\n .option('--run-continuous', 'Keep running and rebid every day')\n .option(\n '--proxy-for-address <address>',\n 'The seed account to proxy for (eg: 5FHneW46xGXgs5mUiveU4sbTyGBzmstUspZC92UhjJM694ty)',\n )\n .action(\n async ({\n maxSeats,\n runContinuous,\n maxBid,\n minBid,\n maxBalance,\n bidDelay,\n bidIncrement,\n proxyForAddress,\n }) => {\n const accountset = await accountsetFromCli(program, proxyForAddress);\n\n let cohortBidder: CohortBidder | undefined;\n const miningBids = new MiningBids(accountset.client, false);\n const maxCohortSize = await miningBids.maxCohortSize();\n\n const stopBidder = async (unsubscribe: () => void) => {\n if (cohortBidder) {\n const stats = await cohortBidder.stop();\n console.log('Final bidding result', {\n cohortStartingFrameId: cohortBidder.cohortStartingFrameId,\n ...stats,\n });\n cohortBidder = undefined;\n if (!runContinuous) {\n unsubscribe();\n process.exit();\n }\n }\n };\n const { unsubscribe } = await miningBids.onCohortChange({\n async onBiddingEnd(cohortStartingFrameId) {\n if (cohortBidder?.cohortStartingFrameId === cohortStartingFrameId) {\n await stopBidder(unsubscribe);\n }\n },\n async onBiddingStart(cohortStartingFrameId) {\n const seatsToWin = maxSeats ?? maxCohortSize;\n const balance = await accountset.balance();\n const feeWiggleRoom = BigInt(25e3);\n const amountAvailable = balance - feeWiggleRoom;\n let maxBidAmount = maxBid ? BigInt(maxBid * MICROGONS_PER_ARGON) : undefined;\n let maxBalanceToUse = amountAvailable;\n if (maxBalance !== undefined) {\n if (maxBalance!.endsWith('%')) {\n let maxBalancePercent = parseInt(maxBalance);\n let amountToBid = (amountAvailable * BigInt(maxBalancePercent)) / 100n;\n if (amountToBid > balance) {\n amountToBid = balance;\n }\n maxBalanceToUse = amountToBid;\n } else {\n maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * MICROGONS_PER_ARGON));\n }\n\n maxBidAmount ??= maxBalanceToUse / BigInt(seatsToWin);\n }\n if (maxBalanceToUse > amountAvailable) {\n maxBalanceToUse = amountAvailable;\n }\n if (!maxBidAmount) {\n console.error('No max bid amount set');\n process.exit(1);\n }\n const subaccountRange = await accountset.getAvailableMinerAccounts(seatsToWin);\n\n if (cohortBidder && cohortBidder?.cohortStartingFrameId !== cohortStartingFrameId) {\n await stopBidder(unsubscribe);\n }\n cohortBidder = new CohortBidder(accountset, cohortStartingFrameId, subaccountRange, {\n maxBid: maxBidAmount,\n minBid: BigInt((minBid ?? 0) * MICROGONS_PER_ARGON),\n bidIncrement: BigInt(Math.floor(bidIncrement * MICROGONS_PER_ARGON)),\n maxBudget: maxBalanceToUse,\n bidDelay,\n });\n await cohortBidder.start();\n },\n });\n },\n );\n\n program\n .command('create-bid-proxy')\n .description('Create a mining-bid proxy account for your main account')\n .requiredOption(\n '--outfile <path>',\n 'The file to use to store the proxy account json (eg: proxy.json)',\n )\n .requiredOption(\n '--fee-argons <argons>',\n 'How many argons should be sent to the proxy account for fees (proxies must pay fees)',\n parseFloat,\n )\n .option('--proxy-passphrase <passphrase>', 'The passphrase for your proxy account')\n .action(async ({ outfile, proxyPassphrase, feeArgons }) => {\n const { mainchainUrl } = globalOptions(program);\n const client = await getClient(mainchainUrl);\n\n const keyringPair = await saveKeyringPair({\n filePath: outfile,\n passphrase: proxyPassphrase,\n });\n const address = keyringPair.address;\n console.log(`✅ Created proxy account at \"${outfile}\" with address ${address}`);\n const tx = client.tx.utility.batchAll([\n client.tx.proxy.addProxy(address, 'MiningBid', 0),\n client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * MICROGONS_PER_ARGON)),\n ]);\n let keypair: KeyringPair;\n try {\n const accountset = await accountsetFromCli(program);\n keypair = accountset.txSubmitterPair;\n } catch (e) {\n const polkadotLink = `https://polkadot.js.org/apps/?rpc=${mainchainUrl}#/extrinsics/decode/${tx.toHex()}`;\n console.log(`Complete the registration at this link:`, polkadotLink);\n process.exit(0);\n }\n try {\n await new TxSubmitter(client, tx, keypair).submit({\n waitForBlock: true,\n });\n\n console.log('Mining bid proxy added and funded.');\n process.exit();\n } catch (error) {\n console.error('Error adding mining proxy', error);\n process.exit(1);\n }\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { BidPool } from '../BidPool';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { formatArgons, MICROGONS_PER_ARGON } from '../utils';\nimport { accountsetFromCli } from './index';\n\nexport default function liquidityCli() {\n const program = new Command('liquidity-pools').description('Monitor or bond to liquidity pools');\n program\n .command('list', { isDefault: true })\n .description('Show or watch the vault bid pool rewards')\n .action(async () => {\n const accountset = await accountsetFromCli(program);\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n await bidPool.watch();\n });\n\n program\n .command('bond')\n .description('Bond argons to a liquidity pool')\n .requiredOption('-v, --vault-id <id>', 'The vault id to use', parseInt)\n .requiredOption('-a, --argons <amount>', 'The number of argons to set the vault to', parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ tip, argons, vaultId }) => {\n const accountset = await accountsetFromCli(program);\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n\n const microgons = BigInt(argons * MICROGONS_PER_ARGON);\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n await bidPool.bondArgons(vaultId, microgons, { tip: resolvedTip });\n console.log('Bonded argons to liquidity pool bond');\n process.exit();\n });\n\n program\n .command('wait-for-space')\n .description('Add bonded argons to a liquidity pool when the market rate is favorable')\n .requiredOption('--max-argons <amount>', 'Max daily argons to use per slot', parseFloat)\n .option(\n '--min-pct-sharing <percent>',\n 'The minimum profit sharing percent to allow',\n parseInt,\n 30,\n )\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat)\n .action(async ({ maxArgons, minPctSharing, tip }) => {\n const maxAmountPerSlot = BigInt(maxArgons * MICROGONS_PER_ARGON);\n\n const accountset = await accountsetFromCli(program);\n const vaults = new VaultMonitor(\n accountset,\n {\n liquidityPoolSpaceAvailable: 1_000_000n,\n },\n { shouldLog: false },\n );\n const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);\n const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;\n console.log('Waiting for liquidity pool space...');\n\n vaults.events.on('liquidity-pool-space-above', async (vaultId, amount) => {\n const vault = vaults.vaultsById[vaultId];\n if (vault.terms.liquidityPoolProfitSharing.times(100).toNumber() < minPctSharing) {\n console.info(\n `Skipping vault ${vaultId} due to lower profit sharing than ${minPctSharing}%`,\n );\n return;\n }\n let amountToAdd = amount;\n if (amountToAdd > maxAmountPerSlot) {\n amountToAdd = maxAmountPerSlot;\n }\n await bidPool.bondArgons(vaultId, amountToAdd, { tip: resolvedTip });\n console.log('Bonding argons to vault liquidity pool', {\n vaultId,\n amount: formatArgons(amountToAdd),\n });\n });\n await vaults.monitor();\n });\n return program;\n}\n","import { Command } from '@commander-js/extra-typings';\nimport { VaultMonitor } from '../VaultMonitor';\nimport { BitcoinLocks } from '../BitcoinLocks';\nimport { formatArgons, MICROGONS_PER_ARGON } from '../utils';\nimport { accountsetFromCli } from './index';\n\nexport default function bitcoinCli() {\n const program = new Command('bitcoin').description('Wait for bitcoin space');\n\n program\n .command('watch')\n .requiredOption(\n '-a, --argons <argons>',\n 'Alert when bitcoin space exceeds this amount',\n parseFloat,\n )\n .description('Watch for bitcoin space available')\n .action(async ({ argons }) => {\n const accountset = await accountsetFromCli(program);\n const bot = new VaultMonitor(accountset, {\n bitcoinSpaceAvailable: argons ? BigInt(argons * MICROGONS_PER_ARGON) : 1n,\n });\n bot.events.on('bitcoin-space-above', async (vaultId, amount) => {\n const vault = bot.vaultsById[vaultId];\n const fee = vault.calculateBitcoinFee(amount);\n const ratio = (100n * fee) / amount;\n console.log(\n `Vault ${vaultId} has ${formatArgons(amount)} argons available for bitcoin. Fee ratio is ${ratio}%`,\n );\n });\n await bot.monitor();\n });\n\n program\n .command('wait-for-space')\n .description('Lock bitcoin when available at a given rate')\n .requiredOption(\n '-a, --argons <amount>',\n 'Bitcoin argons needed. NOTE: your account must have enough to cover fees + tip after this amount.',\n parseFloat,\n )\n .requiredOption('--bitcoin-xpub <xpub>', 'The xpub key to use for bitcoin locking')\n .option('--max-lock-fee <argons>', \"The max lock fee you're willing to pay\", parseFloat)\n .option('--tip <amount>', 'The tip to include with the transaction', parseFloat, 0.0)\n .action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {\n const amountToLock = BigInt(argons * MICROGONS_PER_ARGON);\n\n const accountset = await accountsetFromCli(program);\n await BitcoinLocks.waitForSpace(accountset, {\n argonAmount: amountToLock,\n bitcoinXpub,\n maxLockFee: maxLockFee !== undefined ? BigInt(maxLockFee * MICROGONS_PER_ARGON) : undefined,\n tip: BigInt(tip * MICROGONS_PER_ARGON),\n }).then(({ vaultId, satoshis, txFee, securityFee }) => {\n console.log(\n `Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${formatArgons(\n txFee,\n )}, Lock fee=${formatArgons(securityFee)}.`,\n );\n process.exit(0);\n });\n });\n\n return program;\n}\n","import { createKeyringPair, Keyring, KeyringPair } from '../index';\nimport { promises } from 'node:fs';\nimport * as os from 'node:os';\n\nconst { readFile, writeFile } = promises;\n\nexport async function keyringFromFile(opts: {\n filePath: string;\n passphrase?: string;\n passphraseFile?: string;\n}): Promise<KeyringPair> {\n if (!opts.filePath) {\n throw new Error(\n 'No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)',\n );\n }\n const path = opts.filePath.replace('~', os.homedir());\n const json = JSON.parse(await readFile(path, 'utf-8'));\n let passphrase = opts.passphrase;\n if (opts.passphraseFile) {\n const passphrasePath = opts.passphraseFile.replace('~', os.homedir());\n passphrase = await readFile(passphrasePath, 'utf-8');\n }\n const mainAccount = new Keyring().createFromJson(json);\n mainAccount.decodePkcs8(passphrase);\n return mainAccount;\n}\n\nexport async function saveKeyringPair(opts: {\n filePath: string;\n passphrase?: string;\n cryptoType?: 'sr25519' | 'ed25519';\n}): Promise<KeyringPair> {\n const { filePath, passphrase, cryptoType } = opts;\n const keyring = createKeyringPair({ cryptoType });\n if (filePath) {\n const json = keyring.toJson(passphrase);\n await writeFile(filePath, JSON.stringify(json, null, 2));\n }\n return keyring;\n}\n"]}
@@ -261,10 +261,10 @@ var TxResult = class {
261
261
  import BigNumber, * as BN from "bignumber.js";
262
262
  var { ROUND_FLOOR } = BN;
263
263
  var MICROGONS_PER_ARGON = 1e6;
264
- function formatArgons(x) {
265
- if (x === void 0 || x === null) return "na";
266
- const isNegative = x < 0;
267
- let format = BigNumber(x.toString()).abs().div(MICROGONS_PER_ARGON).toFormat(2, ROUND_FLOOR);
264
+ function formatArgons(microgons) {
265
+ if (microgons === void 0 || microgons === null) return "na";
266
+ const isNegative = microgons < 0;
267
+ let format = BigNumber(microgons.toString()).abs().div(MICROGONS_PER_ARGON).toFormat(2, ROUND_FLOOR);
268
268
  if (format.endsWith(".00")) {
269
269
  format = format.slice(0, -3);
270
270
  }
@@ -2845,4 +2845,4 @@ export {
2845
2845
  u64,
2846
2846
  u8
2847
2847
  };
2848
- //# sourceMappingURL=chunk-P3OMJABP.js.map
2848
+ //# sourceMappingURL=chunk-GZ2TLGCG.js.map