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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -25,7 +25,7 @@ import "@polkadot/types/types/registry";
25
25
  // src/index.ts
26
26
  import { ApiPromise, HttpProvider, Keyring, WsProvider } from "@polkadot/api";
27
27
  import {
28
- cryptoWaitReady as cryptoWaitReady2,
28
+ cryptoWaitReady,
29
29
  decodeAddress,
30
30
  mnemonicGenerate
31
31
  } from "@polkadot/util-crypto";
@@ -87,11 +87,11 @@ var WageProtector = class _WageProtector {
87
87
  };
88
88
 
89
89
  // src/utils.ts
90
- import BigNumber2, * as BN from "bignumber.js";
90
+ import BigNumber, * as BN from "bignumber.js";
91
91
  var { ROUND_FLOOR } = BN;
92
92
  function formatArgons(x) {
93
93
  const isNegative = x < 0;
94
- let format = BigNumber2(x.toString()).abs().div(1e6).toFormat(2, ROUND_FLOOR);
94
+ let format = BigNumber(x.toString()).abs().div(1e6).toFormat(2, ROUND_FLOOR);
95
95
  if (format.endsWith(".00")) {
96
96
  format = format.slice(0, -3);
97
97
  }
@@ -134,13 +134,13 @@ async function gettersToObject(obj) {
134
134
  return result;
135
135
  }
136
136
  function convertFixedU128ToBigNumber(fixedU128) {
137
- const decimalFactor = new BigNumber2(10).pow(new BigNumber2(18));
138
- const rawValue = new BigNumber2(fixedU128.toString());
137
+ const decimalFactor = new BigNumber(10).pow(new BigNumber(18));
138
+ const rawValue = new BigNumber(fixedU128.toString());
139
139
  return rawValue.div(decimalFactor);
140
140
  }
141
141
  function convertPermillToBigNumber(permill) {
142
- const decimalFactor = new BigNumber2(1e6);
143
- const rawValue = new BigNumber2(permill.toString());
142
+ const decimalFactor = new BigNumber(1e6);
143
+ const rawValue = new BigNumber(permill.toString());
144
144
  return rawValue.div(decimalFactor);
145
145
  }
146
146
  function eventDataToJson(event) {
@@ -372,11 +372,8 @@ var AccountRegistry = class _AccountRegistry {
372
372
  // src/Accountset.ts
373
373
  import * as process2 from "node:process";
374
374
 
375
- // src/AccountMiners.ts
376
- import EventEmitter2 from "node:events";
377
-
378
375
  // src/BlockWatch.ts
379
- import EventEmitter from "node:events";
376
+ import { createNanoEvents } from "nanoevents";
380
377
  function getTickFromHeader(client, header) {
381
378
  for (const x of header.digest.logs) {
382
379
  if (x.isPreRuntime) {
@@ -406,7 +403,7 @@ var BlockWatch = class {
406
403
  this.options.shouldLog ??= true;
407
404
  this.options.finalizedBlocks ??= false;
408
405
  }
409
- events = new EventEmitter();
406
+ events = createNanoEvents();
410
407
  obligationsById = {};
411
408
  obligationIdByUtxoId = {};
412
409
  unsubscribe;
@@ -583,10 +580,10 @@ var MiningRotations = class {
583
580
  }));
584
581
  this.genesisTick ??= await client.query.ticks.genesisTick().then((x) => x.toNumber());
585
582
  const ticksBetweenSlots = this.miningConfig.ticksBetweenSlots;
586
- const slot1BiddingStartTick = this.genesisTick + this.miningConfig.slotBiddingStartAfterTicks;
587
- if (tick < slot1BiddingStartTick) return 0;
588
- const ticksSinceBiddingStart = tick - slot1BiddingStartTick;
589
- return Math.floor(ticksSinceBiddingStart / ticksBetweenSlots) + 1;
583
+ const slot1StartTick = this.genesisTick + this.miningConfig.slotBiddingStartAfterTicks + ticksBetweenSlots;
584
+ if (tick < slot1StartTick) return 0;
585
+ const ticksSinceSlot1 = tick - slot1StartTick;
586
+ return Math.floor(ticksSinceSlot1 / ticksBetweenSlots);
590
587
  }
591
588
  async getForHeader(client, header) {
592
589
  if (header.number.toNumber() === 0) return 0;
@@ -597,6 +594,7 @@ var MiningRotations = class {
597
594
  };
598
595
 
599
596
  // src/AccountMiners.ts
597
+ import { createNanoEvents as createNanoEvents2 } from "nanoevents";
600
598
  var AccountMiners = class _AccountMiners {
601
599
  constructor(accountset, registeredMiners, options = { shouldLog: false }) {
602
600
  this.accountset = accountset;
@@ -609,7 +607,7 @@ var AccountMiners = class _AccountMiners {
609
607
  };
610
608
  }
611
609
  }
612
- events = new EventEmitter2();
610
+ events = createNanoEvents2();
613
611
  miningRotations;
614
612
  trackedAccountsByAddress = {};
615
613
  async watch() {
@@ -724,7 +722,7 @@ var AccountMiners = class _AccountMiners {
724
722
  };
725
723
 
726
724
  // src/Accountset.ts
727
- var Accountset = class _Accountset {
725
+ var Accountset = class {
728
726
  txSubmitterPair;
729
727
  isProxy = false;
730
728
  seedAddress;
@@ -1107,24 +1105,6 @@ var Accountset = class _Accountset {
1107
1105
  await accountMiners.watch();
1108
1106
  return accountMiners;
1109
1107
  }
1110
- static async fromCli(program, proxyForAddress) {
1111
- const parentOptions = program.parent?.optsWithGlobals();
1112
- const keypair = await keyringFromCli(parentOptions);
1113
- const client = getClient(parentOptions.mainchainUrl);
1114
- if (proxyForAddress) {
1115
- return new _Accountset({
1116
- client,
1117
- isProxy: true,
1118
- seedAddress: proxyForAddress,
1119
- txSubmitter: keypair
1120
- });
1121
- } else {
1122
- return new _Accountset({
1123
- seedAccount: keypair,
1124
- client
1125
- });
1126
- }
1127
- }
1128
1108
  };
1129
1109
  function getDefaultSubaccountRange() {
1130
1110
  try {
@@ -1249,7 +1229,7 @@ var MiningBids = class {
1249
1229
  };
1250
1230
 
1251
1231
  // src/Vault.ts
1252
- import BigNumber3, * as BN2 from "bignumber.js";
1232
+ import BigNumber2, * as BN2 from "bignumber.js";
1253
1233
  var { ROUND_FLOOR: ROUND_FLOOR2 } = BN2;
1254
1234
  var Vault = class {
1255
1235
  securitization;
@@ -1302,21 +1282,21 @@ var Vault = class {
1302
1282
  return this.securitization - recoverySecuritization - this.bitcoinLocked;
1303
1283
  }
1304
1284
  recoverySecuritization() {
1305
- const reserved = new BigNumber3(1).div(this.securitizationRatio);
1285
+ const reserved = new BigNumber2(1).div(this.securitizationRatio);
1306
1286
  return this.securitization - BigInt(
1307
1287
  reserved.multipliedBy(this.securitization.toString()).toFixed(0, ROUND_FLOOR2)
1308
1288
  );
1309
1289
  }
1310
1290
  minimumSecuritization() {
1311
1291
  return BigInt(
1312
- this.securitizationRatio.multipliedBy(this.bitcoinLocked.toString()).decimalPlaces(0, BigNumber3.ROUND_CEIL).toString()
1292
+ this.securitizationRatio.multipliedBy(this.bitcoinLocked.toString()).decimalPlaces(0, BigNumber2.ROUND_CEIL).toString()
1313
1293
  );
1314
1294
  }
1315
1295
  activatedSecuritization() {
1316
1296
  const activated = this.bitcoinLocked - this.bitcoinPending;
1317
1297
  let maxRatio = this.securitizationRatio;
1318
1298
  if (this.securitizationRatio.toNumber() > 2) {
1319
- maxRatio = BigNumber3(2);
1299
+ maxRatio = BigNumber2(2);
1320
1300
  }
1321
1301
  return BigInt(
1322
1302
  maxRatio.multipliedBy(activated.toString()).toFixed(0, ROUND_FLOOR2)
@@ -1330,14 +1310,14 @@ var Vault = class {
1330
1310
  return activated / 10n;
1331
1311
  }
1332
1312
  calculateBitcoinFee(amount) {
1333
- const fee = this.terms.bitcoinAnnualPercentRate.multipliedBy(Number(amount)).integerValue(BigNumber3.ROUND_CEIL);
1313
+ const fee = this.terms.bitcoinAnnualPercentRate.multipliedBy(Number(amount)).integerValue(BigNumber2.ROUND_CEIL);
1334
1314
  return BigInt(fee.toString()) + this.terms.bitcoinBaseFee;
1335
1315
  }
1336
1316
  };
1337
1317
 
1338
1318
  // src/VaultMonitor.ts
1339
- import { EventEmitter as EventEmitter3 } from "node:events";
1340
1319
  import { printTable as printTable2 } from "console-table-printer";
1320
+ import { createNanoEvents as createNanoEvents3 } from "nanoevents";
1341
1321
  var VaultMonitor = class {
1342
1322
  constructor(accountset, alerts = {}, options = {}) {
1343
1323
  this.accountset = accountset;
@@ -1367,7 +1347,7 @@ var VaultMonitor = class {
1367
1347
  this.printBids(header.hash);
1368
1348
  });
1369
1349
  }
1370
- events = new EventEmitter3();
1350
+ events = createNanoEvents3();
1371
1351
  vaultsById = {};
1372
1352
  blockWatch;
1373
1353
  mainchain;
@@ -2245,81 +2225,20 @@ var BitcoinLocks = class _BitcoinLocks {
2245
2225
  };
2246
2226
 
2247
2227
  // src/keyringUtils.ts
2248
- import { promises } from "node:fs";
2249
- import * as os from "node:os";
2250
- var { readFile, writeFile } = promises;
2251
- async function keyringFromCli(opts) {
2252
- if (opts.accountSuri) {
2253
- return keyringFromSuri(opts.accountSuri);
2254
- }
2255
- if (opts.accountFilePath) {
2256
- return keyringFromFile({
2257
- filePath: opts.accountFilePath,
2258
- passphrase: opts.accountPassphrase
2259
- });
2260
- }
2261
- throw new Error(
2262
- "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
2263
- );
2264
- }
2265
2228
  function keyringFromSuri(suri, cryptoType = "sr25519") {
2266
2229
  return new Keyring({ type: cryptoType }).createFromUri(suri);
2267
2230
  }
2268
- async function keyringFromFile(opts) {
2269
- if (!opts.filePath) {
2270
- throw new Error(
2271
- "No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
2272
- );
2273
- }
2274
- const path = opts.filePath.replace("~", os.homedir());
2275
- const json = JSON.parse(await readFile(path, "utf-8"));
2276
- const mainAccount = new Keyring().createFromJson(json);
2277
- mainAccount.decodePkcs8(opts.passphrase);
2278
- return mainAccount;
2279
- }
2280
- async function createKeyringPair(opts) {
2281
- const { filePath, passphrase, cryptoType } = opts;
2231
+ function createKeyringPair(opts) {
2232
+ const { cryptoType } = opts;
2282
2233
  const seed = mnemonicGenerate();
2283
- const keyring = keyringFromSuri(seed, cryptoType);
2284
- if (filePath) {
2285
- const json = keyring.toJson(passphrase);
2286
- await writeFile(filePath, JSON.stringify(json, null, 2));
2287
- }
2288
- return keyring;
2234
+ return keyringFromSuri(seed, cryptoType);
2289
2235
  }
2290
2236
 
2291
- // src/clis/index.ts
2292
- import { Command as Command6, Option as Option2 } from "@commander-js/extra-typings";
2293
-
2294
- // src/clis/accountCli.ts
2295
- import { Command } from "@commander-js/extra-typings";
2296
- import { printTable as printTable3 } from "console-table-printer";
2297
- import { cryptoWaitReady } from "@polkadot/util-crypto";
2298
- import { writeFileSync } from "node:fs";
2299
- import * as process3 from "node:process";
2300
-
2301
- // src/clis/index.ts
2302
- import { configDotenv } from "dotenv";
2303
- import Path from "node:path";
2304
-
2305
- // src/clis/vaultCli.ts
2306
- import { Command as Command2 } from "@commander-js/extra-typings";
2307
-
2308
- // src/clis/miningCli.ts
2309
- import { Command as Command3 } from "@commander-js/extra-typings";
2310
- import { printTable as printTable4 } from "console-table-printer";
2311
-
2312
- // src/clis/liquidityCli.ts
2313
- import { Command as Command4 } from "@commander-js/extra-typings";
2314
-
2315
- // src/clis/bitcoinCli.ts
2316
- import { Command as Command5 } from "@commander-js/extra-typings";
2317
-
2318
2237
  // src/index.ts
2319
2238
  export * from "@polkadot/types";
2320
2239
  export * from "@polkadot/types/interfaces";
2321
2240
  async function waitForLoad() {
2322
- await cryptoWaitReady2();
2241
+ await cryptoWaitReady();
2323
2242
  }
2324
2243
  async function getClient(host) {
2325
2244
  let provider;
@@ -2360,8 +2279,6 @@ export {
2360
2279
  getClient,
2361
2280
  getTickFromHeader,
2362
2281
  gettersToObject,
2363
- keyringFromCli,
2364
- keyringFromFile,
2365
2282
  keyringFromSuri,
2366
2283
  mnemonicGenerate,
2367
2284
  waitForLoad