@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/cli.cjs +87 -85
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.js +85 -83
- package/lib/cli.js.map +1 -1
- package/lib/clis/index.cjs +93 -85
- package/lib/clis/index.cjs.map +1 -1
- package/lib/clis/index.d.cts +101 -1
- package/lib/clis/index.d.ts +101 -1
- package/lib/clis/index.js +88 -83
- package/lib/clis/index.js.map +1 -1
- package/lib/index.cjs +15 -100
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +8 -18
- package/lib/index.d.ts +8 -18
- package/lib/index.js +23 -106
- package/lib/index.js.map +1 -1
- package/package.json +8 -8
package/lib/cli.js
CHANGED
|
@@ -55,8 +55,6 @@ __export(index_exports, {
|
|
|
55
55
|
getClient: () => getClient,
|
|
56
56
|
getTickFromHeader: () => getTickFromHeader,
|
|
57
57
|
gettersToObject: () => gettersToObject,
|
|
58
|
-
keyringFromCli: () => keyringFromCli,
|
|
59
|
-
keyringFromFile: () => keyringFromFile,
|
|
60
58
|
keyringFromSuri: () => keyringFromSuri,
|
|
61
59
|
mnemonicGenerate: () => mnemonicGenerate,
|
|
62
60
|
waitForLoad: () => waitForLoad
|
|
@@ -437,11 +435,8 @@ var AccountRegistry = class _AccountRegistry {
|
|
|
437
435
|
// src/Accountset.ts
|
|
438
436
|
import * as process2 from "node:process";
|
|
439
437
|
|
|
440
|
-
// src/AccountMiners.ts
|
|
441
|
-
import EventEmitter2 from "node:events";
|
|
442
|
-
|
|
443
438
|
// src/BlockWatch.ts
|
|
444
|
-
import
|
|
439
|
+
import { createNanoEvents } from "nanoevents";
|
|
445
440
|
function getTickFromHeader(client, header) {
|
|
446
441
|
for (const x of header.digest.logs) {
|
|
447
442
|
if (x.isPreRuntime) {
|
|
@@ -471,7 +466,7 @@ var BlockWatch = class {
|
|
|
471
466
|
this.options.shouldLog ??= true;
|
|
472
467
|
this.options.finalizedBlocks ??= false;
|
|
473
468
|
}
|
|
474
|
-
events =
|
|
469
|
+
events = createNanoEvents();
|
|
475
470
|
obligationsById = {};
|
|
476
471
|
obligationIdByUtxoId = {};
|
|
477
472
|
unsubscribe;
|
|
@@ -662,6 +657,7 @@ var MiningRotations = class {
|
|
|
662
657
|
};
|
|
663
658
|
|
|
664
659
|
// src/AccountMiners.ts
|
|
660
|
+
import { createNanoEvents as createNanoEvents2 } from "nanoevents";
|
|
665
661
|
var AccountMiners = class _AccountMiners {
|
|
666
662
|
constructor(accountset, registeredMiners, options = { shouldLog: false }) {
|
|
667
663
|
this.accountset = accountset;
|
|
@@ -674,7 +670,7 @@ var AccountMiners = class _AccountMiners {
|
|
|
674
670
|
};
|
|
675
671
|
}
|
|
676
672
|
}
|
|
677
|
-
events =
|
|
673
|
+
events = createNanoEvents2();
|
|
678
674
|
miningRotations;
|
|
679
675
|
trackedAccountsByAddress = {};
|
|
680
676
|
async watch() {
|
|
@@ -789,7 +785,7 @@ var AccountMiners = class _AccountMiners {
|
|
|
789
785
|
};
|
|
790
786
|
|
|
791
787
|
// src/Accountset.ts
|
|
792
|
-
var Accountset = class
|
|
788
|
+
var Accountset = class {
|
|
793
789
|
txSubmitterPair;
|
|
794
790
|
isProxy = false;
|
|
795
791
|
seedAddress;
|
|
@@ -1172,24 +1168,6 @@ var Accountset = class _Accountset {
|
|
|
1172
1168
|
await accountMiners.watch();
|
|
1173
1169
|
return accountMiners;
|
|
1174
1170
|
}
|
|
1175
|
-
static async fromCli(program2, proxyForAddress) {
|
|
1176
|
-
const parentOptions = program2.parent?.optsWithGlobals();
|
|
1177
|
-
const keypair = await keyringFromCli(parentOptions);
|
|
1178
|
-
const client = getClient(parentOptions.mainchainUrl);
|
|
1179
|
-
if (proxyForAddress) {
|
|
1180
|
-
return new _Accountset({
|
|
1181
|
-
client,
|
|
1182
|
-
isProxy: true,
|
|
1183
|
-
seedAddress: proxyForAddress,
|
|
1184
|
-
txSubmitter: keypair
|
|
1185
|
-
});
|
|
1186
|
-
} else {
|
|
1187
|
-
return new _Accountset({
|
|
1188
|
-
seedAccount: keypair,
|
|
1189
|
-
client
|
|
1190
|
-
});
|
|
1191
|
-
}
|
|
1192
|
-
}
|
|
1193
1171
|
};
|
|
1194
1172
|
function getDefaultSubaccountRange() {
|
|
1195
1173
|
try {
|
|
@@ -1401,8 +1379,8 @@ var Vault = class {
|
|
|
1401
1379
|
};
|
|
1402
1380
|
|
|
1403
1381
|
// src/VaultMonitor.ts
|
|
1404
|
-
import { EventEmitter as EventEmitter3 } from "node:events";
|
|
1405
1382
|
import { printTable as printTable2 } from "console-table-printer";
|
|
1383
|
+
import { createNanoEvents as createNanoEvents3 } from "nanoevents";
|
|
1406
1384
|
var VaultMonitor = class {
|
|
1407
1385
|
constructor(accountset, alerts = {}, options = {}) {
|
|
1408
1386
|
this.accountset = accountset;
|
|
@@ -1432,7 +1410,7 @@ var VaultMonitor = class {
|
|
|
1432
1410
|
this.printBids(header.hash);
|
|
1433
1411
|
});
|
|
1434
1412
|
}
|
|
1435
|
-
events =
|
|
1413
|
+
events = createNanoEvents3();
|
|
1436
1414
|
vaultsById = {};
|
|
1437
1415
|
blockWatch;
|
|
1438
1416
|
mainchain;
|
|
@@ -2310,47 +2288,13 @@ var BitcoinLocks = class _BitcoinLocks {
|
|
|
2310
2288
|
};
|
|
2311
2289
|
|
|
2312
2290
|
// src/keyringUtils.ts
|
|
2313
|
-
import { promises } from "node:fs";
|
|
2314
|
-
import * as os from "node:os";
|
|
2315
|
-
var { readFile, writeFile } = promises;
|
|
2316
|
-
async function keyringFromCli(opts) {
|
|
2317
|
-
if (opts.accountSuri) {
|
|
2318
|
-
return keyringFromSuri(opts.accountSuri);
|
|
2319
|
-
}
|
|
2320
|
-
if (opts.accountFilePath) {
|
|
2321
|
-
return keyringFromFile({
|
|
2322
|
-
filePath: opts.accountFilePath,
|
|
2323
|
-
passphrase: opts.accountPassphrase
|
|
2324
|
-
});
|
|
2325
|
-
}
|
|
2326
|
-
throw new Error(
|
|
2327
|
-
"No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
|
|
2328
|
-
);
|
|
2329
|
-
}
|
|
2330
2291
|
function keyringFromSuri(suri, cryptoType = "sr25519") {
|
|
2331
2292
|
return new Keyring({ type: cryptoType }).createFromUri(suri);
|
|
2332
2293
|
}
|
|
2333
|
-
|
|
2334
|
-
|
|
2335
|
-
throw new Error(
|
|
2336
|
-
"No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
|
|
2337
|
-
);
|
|
2338
|
-
}
|
|
2339
|
-
const path = opts.filePath.replace("~", os.homedir());
|
|
2340
|
-
const json = JSON.parse(await readFile(path, "utf-8"));
|
|
2341
|
-
const mainAccount = new Keyring().createFromJson(json);
|
|
2342
|
-
mainAccount.decodePkcs8(opts.passphrase);
|
|
2343
|
-
return mainAccount;
|
|
2344
|
-
}
|
|
2345
|
-
async function createKeyringPair(opts) {
|
|
2346
|
-
const { filePath, passphrase, cryptoType } = opts;
|
|
2294
|
+
function createKeyringPair(opts) {
|
|
2295
|
+
const { cryptoType } = opts;
|
|
2347
2296
|
const seed = mnemonicGenerate();
|
|
2348
|
-
|
|
2349
|
-
if (filePath) {
|
|
2350
|
-
const json = keyring.toJson(passphrase);
|
|
2351
|
-
await writeFile(filePath, JSON.stringify(json, null, 2));
|
|
2352
|
-
}
|
|
2353
|
-
return keyring;
|
|
2297
|
+
return keyringFromSuri(seed, cryptoType);
|
|
2354
2298
|
}
|
|
2355
2299
|
|
|
2356
2300
|
// src/index.ts
|
|
@@ -2381,7 +2325,7 @@ function accountCli() {
|
|
|
2381
2325
|
"Manage subaccounts from a single keypair"
|
|
2382
2326
|
);
|
|
2383
2327
|
program2.command("watch").description("Watch for blocks closed by subaccounts").action(async () => {
|
|
2384
|
-
const accountset = await
|
|
2328
|
+
const accountset = await accountsetFromCli(program2);
|
|
2385
2329
|
const accountMiners = await accountset.watchBlocks();
|
|
2386
2330
|
accountMiners.events.on("mined", (_block, mined) => {
|
|
2387
2331
|
console.log("Your accounts authored a block", mined);
|
|
@@ -2392,7 +2336,7 @@ function accountCli() {
|
|
|
2392
2336
|
});
|
|
2393
2337
|
program2.command("list", { isDefault: true }).description("Show subaccounts").option("--addresses", "Just show a list of ids").action(async ({ addresses }) => {
|
|
2394
2338
|
const { subaccounts } = globalOptions(program2);
|
|
2395
|
-
const accountset = await
|
|
2339
|
+
const accountset = await accountsetFromCli(program2);
|
|
2396
2340
|
if (addresses) {
|
|
2397
2341
|
const addresses2 = accountset.addresses;
|
|
2398
2342
|
console.log(addresses2.join(","));
|
|
@@ -2423,7 +2367,7 @@ function accountCli() {
|
|
|
2423
2367
|
"Register the keys to a url (normally this is localhost)"
|
|
2424
2368
|
).action(async ({ registerKeysTo, path }) => {
|
|
2425
2369
|
const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program2);
|
|
2426
|
-
const accountset = await
|
|
2370
|
+
const accountset = await accountsetFromCli(program2);
|
|
2427
2371
|
process3.env.KEYS_MNEMONIC ||= mnemonicGenerate();
|
|
2428
2372
|
if (registerKeysTo) {
|
|
2429
2373
|
await accountset.registerKeys(registerKeysTo);
|
|
@@ -2464,7 +2408,7 @@ function accountCli() {
|
|
|
2464
2408
|
"--print-only",
|
|
2465
2409
|
"Output as curl commands instead of direct registration"
|
|
2466
2410
|
).action(async (nodeRpcUrl, { printOnly }) => {
|
|
2467
|
-
const accountset = await
|
|
2411
|
+
const accountset = await accountsetFromCli(program2);
|
|
2468
2412
|
if (printOnly) {
|
|
2469
2413
|
const { gran, seal } = accountset.keys();
|
|
2470
2414
|
const commands = [];
|
|
@@ -2498,7 +2442,7 @@ function accountCli() {
|
|
|
2498
2442
|
"Restrict this operation to a subset of the subaccounts (eg, 0-10)",
|
|
2499
2443
|
parseSubaccountRange
|
|
2500
2444
|
).action(async ({ subaccounts }) => {
|
|
2501
|
-
const accountset = await
|
|
2445
|
+
const accountset = await accountsetFromCli(program2);
|
|
2502
2446
|
const result = await accountset.consolidate(subaccounts);
|
|
2503
2447
|
printTable3(result);
|
|
2504
2448
|
process3.exit(0);
|
|
@@ -2517,7 +2461,7 @@ function vaultCli() {
|
|
|
2517
2461
|
"Monitor vaults and manage securitization"
|
|
2518
2462
|
);
|
|
2519
2463
|
program2.command("list", { isDefault: true }).description("Show current state of vaults").action(async () => {
|
|
2520
|
-
const accountset = await
|
|
2464
|
+
const accountset = await accountsetFromCli(program2);
|
|
2521
2465
|
const vaults = new VaultMonitor(accountset, void 0, {
|
|
2522
2466
|
vaultOnlyWatchMode: true
|
|
2523
2467
|
});
|
|
@@ -2533,7 +2477,7 @@ function vaultCli() {
|
|
|
2533
2477
|
"The tip to include with the transaction",
|
|
2534
2478
|
parseFloat
|
|
2535
2479
|
).action(async ({ tip, argons, vaultId, ratio }) => {
|
|
2536
|
-
const accountset = await
|
|
2480
|
+
const accountset = await accountsetFromCli(program2);
|
|
2537
2481
|
const client = await accountset.client;
|
|
2538
2482
|
const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
|
|
2539
2483
|
const microgons = BigInt(argons * 1e6);
|
|
@@ -2594,7 +2538,7 @@ function vaultCli() {
|
|
|
2594
2538
|
"Bitcoin pubkey must be 66 characters (add 0x in front optionally)"
|
|
2595
2539
|
);
|
|
2596
2540
|
}
|
|
2597
|
-
const accountset = await
|
|
2541
|
+
const accountset = await accountsetFromCli(program2);
|
|
2598
2542
|
const client = await accountset.client;
|
|
2599
2543
|
const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
|
|
2600
2544
|
const microgons = BigInt(argons * 1e6);
|
|
@@ -2677,7 +2621,7 @@ function miningCli() {
|
|
|
2677
2621
|
"Watch mining seats or setup bidding"
|
|
2678
2622
|
);
|
|
2679
2623
|
program2.command("list", { isDefault: true }).description("Monitor all miners").action(async () => {
|
|
2680
|
-
const accountset = await
|
|
2624
|
+
const accountset = await accountsetFromCli(program2);
|
|
2681
2625
|
const bids = new MiningBids(accountset.client);
|
|
2682
2626
|
const api = await accountset.client;
|
|
2683
2627
|
let lastMiners = {};
|
|
@@ -2773,7 +2717,7 @@ function miningCli() {
|
|
|
2773
2717
|
bidIncrement,
|
|
2774
2718
|
proxyForAddress
|
|
2775
2719
|
}) => {
|
|
2776
|
-
const accountset = await
|
|
2720
|
+
const accountset = await accountsetFromCli(program2, proxyForAddress);
|
|
2777
2721
|
let cohortBidder;
|
|
2778
2722
|
const miningBids = new MiningBids(accountset.client, false);
|
|
2779
2723
|
const maxCohortSize = await miningBids.maxCohortSize();
|
|
@@ -2860,7 +2804,7 @@ function miningCli() {
|
|
|
2860
2804
|
).action(async ({ outfile, proxyPassphrase, feeArgons }) => {
|
|
2861
2805
|
const { mainchainUrl } = globalOptions(program2);
|
|
2862
2806
|
const client = await getClient(mainchainUrl);
|
|
2863
|
-
const keyringPair = await
|
|
2807
|
+
const keyringPair = await saveKeyringPair({
|
|
2864
2808
|
filePath: outfile,
|
|
2865
2809
|
passphrase: proxyPassphrase
|
|
2866
2810
|
});
|
|
@@ -2874,7 +2818,7 @@ function miningCli() {
|
|
|
2874
2818
|
]);
|
|
2875
2819
|
let keypair;
|
|
2876
2820
|
try {
|
|
2877
|
-
const accountset = await
|
|
2821
|
+
const accountset = await accountsetFromCli(program2);
|
|
2878
2822
|
keypair = accountset.txSubmitterPair;
|
|
2879
2823
|
} catch (e) {
|
|
2880
2824
|
const polkadotLink = `https://polkadot.js.org/apps/?rpc=${mainchainUrl}#/extrinsics/decode/${tx.toHex()}`;
|
|
@@ -2902,7 +2846,7 @@ function liquidityCli() {
|
|
|
2902
2846
|
"Monitor or bond to liquidity pools"
|
|
2903
2847
|
);
|
|
2904
2848
|
program2.command("list", { isDefault: true }).description("Show or watch the vault bid pool rewards").action(async () => {
|
|
2905
|
-
const accountset = await
|
|
2849
|
+
const accountset = await accountsetFromCli(program2);
|
|
2906
2850
|
const bidPool = new BidPool(
|
|
2907
2851
|
accountset.client,
|
|
2908
2852
|
accountset.txSubmitterPair
|
|
@@ -2918,7 +2862,7 @@ function liquidityCli() {
|
|
|
2918
2862
|
"The tip to include with the transaction",
|
|
2919
2863
|
parseFloat
|
|
2920
2864
|
).action(async ({ tip, argons, vaultId }) => {
|
|
2921
|
-
const accountset = await
|
|
2865
|
+
const accountset = await accountsetFromCli(program2);
|
|
2922
2866
|
const resolvedTip = tip ? BigInt(tip * 1e6) : 0n;
|
|
2923
2867
|
const microgons = BigInt(argons * 1e6);
|
|
2924
2868
|
const bidPool = new BidPool(
|
|
@@ -2946,7 +2890,7 @@ function liquidityCli() {
|
|
|
2946
2890
|
parseFloat
|
|
2947
2891
|
).action(async ({ maxArgons, minPctSharing, tip }) => {
|
|
2948
2892
|
const maxAmountPerSlot = BigInt(maxArgons * 1e6);
|
|
2949
|
-
const accountset = await
|
|
2893
|
+
const accountset = await accountsetFromCli(program2);
|
|
2950
2894
|
const vaults = new VaultMonitor(
|
|
2951
2895
|
accountset,
|
|
2952
2896
|
{
|
|
@@ -2995,7 +2939,7 @@ function bitcoinCli() {
|
|
|
2995
2939
|
"Alert when bitcoin space exceeds this amount",
|
|
2996
2940
|
parseFloat
|
|
2997
2941
|
).description("Watch for bitcoin space available").action(async ({ argons }) => {
|
|
2998
|
-
const accountset = await
|
|
2942
|
+
const accountset = await accountsetFromCli(program2);
|
|
2999
2943
|
const bot = new VaultMonitor(accountset, {
|
|
3000
2944
|
bitcoinSpaceAvailable: argons ? BigInt(argons * 1e6) : 1n
|
|
3001
2945
|
});
|
|
@@ -3027,7 +2971,7 @@ function bitcoinCli() {
|
|
|
3027
2971
|
0
|
|
3028
2972
|
).action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {
|
|
3029
2973
|
const amountToLock = BigInt(argons * 1e6);
|
|
3030
|
-
const accountset = await
|
|
2974
|
+
const accountset = await accountsetFromCli(program2);
|
|
3031
2975
|
await BitcoinLocks.waitForSpace(accountset, {
|
|
3032
2976
|
argonAmount: amountToLock,
|
|
3033
2977
|
bitcoinXpub,
|
|
@@ -3045,6 +2989,32 @@ function bitcoinCli() {
|
|
|
3045
2989
|
return program2;
|
|
3046
2990
|
}
|
|
3047
2991
|
|
|
2992
|
+
// src/clis/keyringStore.ts
|
|
2993
|
+
import { promises } from "node:fs";
|
|
2994
|
+
import * as os from "node:os";
|
|
2995
|
+
var { readFile, writeFile } = promises;
|
|
2996
|
+
async function keyringFromFile(opts) {
|
|
2997
|
+
if (!opts.filePath) {
|
|
2998
|
+
throw new Error(
|
|
2999
|
+
"No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
|
|
3000
|
+
);
|
|
3001
|
+
}
|
|
3002
|
+
const path = opts.filePath.replace("~", os.homedir());
|
|
3003
|
+
const json = JSON.parse(await readFile(path, "utf-8"));
|
|
3004
|
+
const mainAccount = new Keyring().createFromJson(json);
|
|
3005
|
+
mainAccount.decodePkcs8(opts.passphrase);
|
|
3006
|
+
return mainAccount;
|
|
3007
|
+
}
|
|
3008
|
+
async function saveKeyringPair(opts) {
|
|
3009
|
+
const { filePath, passphrase, cryptoType } = opts;
|
|
3010
|
+
const keyring = createKeyringPair({ cryptoType });
|
|
3011
|
+
if (filePath) {
|
|
3012
|
+
const json = keyring.toJson(passphrase);
|
|
3013
|
+
await writeFile(filePath, JSON.stringify(json, null, 2));
|
|
3014
|
+
}
|
|
3015
|
+
return keyring;
|
|
3016
|
+
}
|
|
3017
|
+
|
|
3048
3018
|
// src/clis/index.ts
|
|
3049
3019
|
function globalOptions(program2) {
|
|
3050
3020
|
return program2.optsWithGlobals();
|
|
@@ -3074,6 +3044,38 @@ function buildCli() {
|
|
|
3074
3044
|
).env("SUBACCOUNT_RANGE").argParser(parseSubaccountRange)
|
|
3075
3045
|
).addCommand(accountCli()).addCommand(vaultCli()).addCommand(miningCli()).addCommand(liquidityCli()).addCommand(bitcoinCli());
|
|
3076
3046
|
}
|
|
3047
|
+
async function accountsetFromCli(program2, proxyForAddress) {
|
|
3048
|
+
const opts = program2.parent?.optsWithGlobals();
|
|
3049
|
+
let keypair;
|
|
3050
|
+
if (opts.accountSuri) {
|
|
3051
|
+
keypair = keyringFromSuri(opts.accountSuri);
|
|
3052
|
+
}
|
|
3053
|
+
if (opts.accountFilePath) {
|
|
3054
|
+
keypair = await keyringFromFile({
|
|
3055
|
+
filePath: opts.accountFilePath,
|
|
3056
|
+
passphrase: opts.accountPassphrase
|
|
3057
|
+
});
|
|
3058
|
+
}
|
|
3059
|
+
if (!keypair) {
|
|
3060
|
+
throw new Error(
|
|
3061
|
+
"No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
|
|
3062
|
+
);
|
|
3063
|
+
}
|
|
3064
|
+
const client = getClient(opts.mainchainUrl);
|
|
3065
|
+
if (proxyForAddress) {
|
|
3066
|
+
return new Accountset({
|
|
3067
|
+
client,
|
|
3068
|
+
isProxy: true,
|
|
3069
|
+
seedAddress: proxyForAddress,
|
|
3070
|
+
txSubmitter: keypair
|
|
3071
|
+
});
|
|
3072
|
+
} else {
|
|
3073
|
+
return new Accountset({
|
|
3074
|
+
seedAccount: keypair,
|
|
3075
|
+
client
|
|
3076
|
+
});
|
|
3077
|
+
}
|
|
3078
|
+
}
|
|
3077
3079
|
function addGlobalArgs(program2) {
|
|
3078
3080
|
for (const command of program2.commands) {
|
|
3079
3081
|
command.configureHelp({
|