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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.cts CHANGED
@@ -90,12 +90,10 @@ export { KeypairType } from '@polkadot/util-crypto/types';
90
90
  import { ISubmittableResult } from '@polkadot/types/types/extrinsic';
91
91
  import { SubmittableExtrinsic as SubmittableExtrinsic$1 } from '@polkadot/api/promise/types';
92
92
  import { SignerOptions, ApiDecoration } from '@polkadot/api/types';
93
- import { Command } from '@commander-js/extra-typings';
94
- import TypedEventEmitter from 'typed-emitter';
93
+ import * as nanoevents from 'nanoevents';
95
94
  import { Header as Header$1, DispatchError as DispatchError$1 } from '@polkadot/types/interfaces';
96
95
  export * from '@polkadot/types/interfaces';
97
96
  import BigNumber from 'bignumber.js';
98
- import { IGlobalOptions } from './clis/index.cjs';
99
97
 
100
98
  declare module '@polkadot/api-base/types/consts' {
101
99
  interface AugmentedConsts<ApiType extends ApiTypes> {
@@ -11063,7 +11061,7 @@ declare function getAuthorFromHeader(client: ArgonClient, header: Header$1): str
11063
11061
  declare class BlockWatch {
11064
11062
  private readonly mainchain;
11065
11063
  private options;
11066
- readonly events: TypedEventEmitter<BlockWatchEvents>;
11064
+ readonly events: nanoevents.Emitter<BlockWatchEvents>;
11067
11065
  readonly obligationsById: {
11068
11066
  [obligationId: number]: {
11069
11067
  vaultId: number;
@@ -11100,7 +11098,7 @@ declare class MiningRotations {
11100
11098
  declare class AccountMiners {
11101
11099
  private accountset;
11102
11100
  private options;
11103
- events: TypedEventEmitter<{
11101
+ events: nanoevents.Emitter<{
11104
11102
  mined: (header: Header, earnings: {
11105
11103
  author: string;
11106
11104
  argons: bigint;
@@ -11249,7 +11247,6 @@ declare class Accountset {
11249
11247
  }>;
11250
11248
  getAccountsInRange(range?: SubaccountRange): IAccountAndKey[];
11251
11249
  watchBlocks(shouldLog?: boolean): Promise<AccountMiners>;
11252
- static fromCli(program: Command, proxyForAddress?: string): Promise<Accountset>;
11253
11250
  }
11254
11251
  type IAccountAndKey = {
11255
11252
  pair?: KeyringPair;
@@ -11350,9 +11347,9 @@ declare class VaultMonitor {
11350
11347
  vaultOnlyWatchMode?: boolean;
11351
11348
  shouldLog?: boolean;
11352
11349
  };
11353
- events: TypedEventEmitter<{
11354
- "bitcoin-space-above": (vaultId: number, amount: bigint) => void;
11355
- "liquidity-pool-space-above": (vaultId: number, amount: bigint) => void;
11350
+ events: nanoevents.Emitter<{
11351
+ 'bitcoin-space-above': (vaultId: number, amount: bigint) => void;
11352
+ 'liquidity-pool-space-above': (vaultId: number, amount: bigint) => void;
11356
11353
  }>;
11357
11354
  readonly vaultsById: {
11358
11355
  [id: number]: Vault;
@@ -11528,17 +11525,10 @@ declare class BitcoinLocks {
11528
11525
  }>;
11529
11526
  }
11530
11527
 
11531
- declare function keyringFromCli(opts: IGlobalOptions): Promise<KeyringPair>;
11532
11528
  declare function keyringFromSuri(suri: string, cryptoType?: 'sr25519' | 'ed25519'): KeyringPair;
11533
- declare function keyringFromFile(opts: {
11534
- filePath: string;
11535
- passphrase?: string;
11536
- }): Promise<KeyringPair>;
11537
11529
  declare function createKeyringPair(opts: {
11538
- filePath?: string;
11539
- passphrase?: string;
11540
11530
  cryptoType?: 'sr25519' | 'ed25519';
11541
- }): Promise<KeyringPair>;
11531
+ }): KeyringPair;
11542
11532
 
11543
11533
  type ArgonClient = ApiPromise;
11544
11534
  /**
@@ -11552,4 +11542,4 @@ declare function waitForLoad(): Promise<void>;
11552
11542
  */
11553
11543
  declare function getClient(host: string): Promise<ArgonClient>;
11554
11544
 
11555
- export { AccountMiners, AccountRegistry, Accountset, type ArgonClient, BidPool, BitcoinLocks, BlockWatch, CohortBidder, IGlobalOptions, JsonExt, MiningBids, MiningRotations, TxSubmitter, Vault, VaultMonitor, WageProtector, checkForExtrinsicSuccess, convertFixedU128ToBigNumber, convertPermillToBigNumber, createKeyringPair, dispatchErrorToString, eventDataToJson, filterUndefined, formatArgons, formatPercent, getAuthorFromHeader, getClient, getTickFromHeader, gettersToObject, keyringFromCli, keyringFromFile, keyringFromSuri, waitForLoad };
11545
+ export { AccountMiners, AccountRegistry, Accountset, type ArgonClient, BidPool, BitcoinLocks, BlockWatch, CohortBidder, JsonExt, MiningBids, MiningRotations, TxSubmitter, Vault, VaultMonitor, WageProtector, checkForExtrinsicSuccess, convertFixedU128ToBigNumber, convertPermillToBigNumber, createKeyringPair, dispatchErrorToString, eventDataToJson, filterUndefined, formatArgons, formatPercent, getAuthorFromHeader, getClient, getTickFromHeader, gettersToObject, keyringFromSuri, waitForLoad };
package/lib/index.d.ts CHANGED
@@ -90,12 +90,10 @@ export { KeypairType } from '@polkadot/util-crypto/types';
90
90
  import { ISubmittableResult } from '@polkadot/types/types/extrinsic';
91
91
  import { SubmittableExtrinsic as SubmittableExtrinsic$1 } from '@polkadot/api/promise/types';
92
92
  import { SignerOptions, ApiDecoration } from '@polkadot/api/types';
93
- import { Command } from '@commander-js/extra-typings';
94
- import TypedEventEmitter from 'typed-emitter';
93
+ import * as nanoevents from 'nanoevents';
95
94
  import { Header as Header$1, DispatchError as DispatchError$1 } from '@polkadot/types/interfaces';
96
95
  export * from '@polkadot/types/interfaces';
97
96
  import BigNumber from 'bignumber.js';
98
- import { IGlobalOptions } from './clis/index.js';
99
97
 
100
98
  declare module '@polkadot/api-base/types/consts' {
101
99
  interface AugmentedConsts<ApiType extends ApiTypes> {
@@ -11063,7 +11061,7 @@ declare function getAuthorFromHeader(client: ArgonClient, header: Header$1): str
11063
11061
  declare class BlockWatch {
11064
11062
  private readonly mainchain;
11065
11063
  private options;
11066
- readonly events: TypedEventEmitter<BlockWatchEvents>;
11064
+ readonly events: nanoevents.Emitter<BlockWatchEvents>;
11067
11065
  readonly obligationsById: {
11068
11066
  [obligationId: number]: {
11069
11067
  vaultId: number;
@@ -11100,7 +11098,7 @@ declare class MiningRotations {
11100
11098
  declare class AccountMiners {
11101
11099
  private accountset;
11102
11100
  private options;
11103
- events: TypedEventEmitter<{
11101
+ events: nanoevents.Emitter<{
11104
11102
  mined: (header: Header, earnings: {
11105
11103
  author: string;
11106
11104
  argons: bigint;
@@ -11249,7 +11247,6 @@ declare class Accountset {
11249
11247
  }>;
11250
11248
  getAccountsInRange(range?: SubaccountRange): IAccountAndKey[];
11251
11249
  watchBlocks(shouldLog?: boolean): Promise<AccountMiners>;
11252
- static fromCli(program: Command, proxyForAddress?: string): Promise<Accountset>;
11253
11250
  }
11254
11251
  type IAccountAndKey = {
11255
11252
  pair?: KeyringPair;
@@ -11350,9 +11347,9 @@ declare class VaultMonitor {
11350
11347
  vaultOnlyWatchMode?: boolean;
11351
11348
  shouldLog?: boolean;
11352
11349
  };
11353
- events: TypedEventEmitter<{
11354
- "bitcoin-space-above": (vaultId: number, amount: bigint) => void;
11355
- "liquidity-pool-space-above": (vaultId: number, amount: bigint) => void;
11350
+ events: nanoevents.Emitter<{
11351
+ 'bitcoin-space-above': (vaultId: number, amount: bigint) => void;
11352
+ 'liquidity-pool-space-above': (vaultId: number, amount: bigint) => void;
11356
11353
  }>;
11357
11354
  readonly vaultsById: {
11358
11355
  [id: number]: Vault;
@@ -11528,17 +11525,10 @@ declare class BitcoinLocks {
11528
11525
  }>;
11529
11526
  }
11530
11527
 
11531
- declare function keyringFromCli(opts: IGlobalOptions): Promise<KeyringPair>;
11532
11528
  declare function keyringFromSuri(suri: string, cryptoType?: 'sr25519' | 'ed25519'): KeyringPair;
11533
- declare function keyringFromFile(opts: {
11534
- filePath: string;
11535
- passphrase?: string;
11536
- }): Promise<KeyringPair>;
11537
11529
  declare function createKeyringPair(opts: {
11538
- filePath?: string;
11539
- passphrase?: string;
11540
11530
  cryptoType?: 'sr25519' | 'ed25519';
11541
- }): Promise<KeyringPair>;
11531
+ }): KeyringPair;
11542
11532
 
11543
11533
  type ArgonClient = ApiPromise;
11544
11534
  /**
@@ -11552,4 +11542,4 @@ declare function waitForLoad(): Promise<void>;
11552
11542
  */
11553
11543
  declare function getClient(host: string): Promise<ArgonClient>;
11554
11544
 
11555
- export { AccountMiners, AccountRegistry, Accountset, type ArgonClient, BidPool, BitcoinLocks, BlockWatch, CohortBidder, IGlobalOptions, JsonExt, MiningBids, MiningRotations, TxSubmitter, Vault, VaultMonitor, WageProtector, checkForExtrinsicSuccess, convertFixedU128ToBigNumber, convertPermillToBigNumber, createKeyringPair, dispatchErrorToString, eventDataToJson, filterUndefined, formatArgons, formatPercent, getAuthorFromHeader, getClient, getTickFromHeader, gettersToObject, keyringFromCli, keyringFromFile, keyringFromSuri, waitForLoad };
11545
+ export { AccountMiners, AccountRegistry, Accountset, type ArgonClient, BidPool, BitcoinLocks, BlockWatch, CohortBidder, JsonExt, MiningBids, MiningRotations, TxSubmitter, Vault, VaultMonitor, WageProtector, checkForExtrinsicSuccess, convertFixedU128ToBigNumber, convertPermillToBigNumber, createKeyringPair, dispatchErrorToString, eventDataToJson, filterUndefined, formatArgons, formatPercent, getAuthorFromHeader, getClient, getTickFromHeader, gettersToObject, keyringFromSuri, waitForLoad };
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;
@@ -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