@argonprotocol/mainchain 1.2.0 → 1.3.1
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/README.md +41 -37
- package/lib/{chunk-RXCQYVE7.js → chunk-CGXT6XF7.js} +586 -288
- package/lib/chunk-CGXT6XF7.js.map +1 -0
- package/lib/{chunk-BQR6FEVP.js → chunk-FNSFV3MO.js} +114 -227
- package/lib/chunk-FNSFV3MO.js.map +1 -0
- package/lib/{chunk-EY3HYZMJ.cjs → chunk-NU36V3JQ.cjs} +152 -265
- package/lib/chunk-NU36V3JQ.cjs.map +1 -0
- package/lib/{chunk-CHGCEO2U.cjs → chunk-SHAEHPI5.cjs} +587 -289
- package/lib/chunk-SHAEHPI5.cjs.map +1 -0
- package/lib/cli.cjs +6 -6
- package/lib/cli.cjs.map +1 -1
- package/lib/cli.d.cts +1 -1
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +3 -3
- package/lib/cli.js.map +1 -1
- package/lib/clis/index.cjs +3 -3
- package/lib/clis/index.js +2 -2
- package/lib/index.cjs +10 -2
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +542 -363
- package/lib/index.d.ts +542 -363
- package/lib/index.js +9 -1
- package/package.json +15 -14
- package/lib/chunk-BQR6FEVP.js.map +0 -1
- package/lib/chunk-CHGCEO2U.cjs.map +0 -1
- package/lib/chunk-EY3HYZMJ.cjs.map +0 -1
- package/lib/chunk-RXCQYVE7.js.map +0 -1
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
var
|
|
18
|
+
var _chunkSHAEHPI5cjs = require('./chunk-SHAEHPI5.cjs');
|
|
19
19
|
|
|
20
20
|
// src/clis/index.ts
|
|
21
21
|
var _extratypings = require('@commander-js/extra-typings');
|
|
@@ -27,9 +27,7 @@ var _utilcrypto = require('@polkadot/util-crypto');
|
|
|
27
27
|
var _fs = require('fs');
|
|
28
28
|
var _process = require('process'); var process2 = _interopRequireWildcard(_process);
|
|
29
29
|
function accountCli() {
|
|
30
|
-
const program = new (0, _extratypings.Command)("accounts").description(
|
|
31
|
-
"Manage subaccounts from a single keypair"
|
|
32
|
-
);
|
|
30
|
+
const program = new (0, _extratypings.Command)("accounts").description("Manage subaccounts from a single keypair");
|
|
33
31
|
program.command("watch").description("Watch for blocks closed by subaccounts").action(async () => {
|
|
34
32
|
const accountset = await accountsetFromCli(program);
|
|
35
33
|
const accountMiners = await accountset.watchBlocks();
|
|
@@ -68,13 +66,10 @@ function accountCli() {
|
|
|
68
66
|
program.command("create").description('Create an account "env" file and optionally register keys').requiredOption(
|
|
69
67
|
"--path <path>",
|
|
70
68
|
"The path to an env file to create (convention is .env.<name>)"
|
|
71
|
-
).option(
|
|
72
|
-
"--register-keys-to <url>",
|
|
73
|
-
"Register the keys to a url (normally this is localhost)"
|
|
74
|
-
).action(async ({ registerKeysTo, path }) => {
|
|
69
|
+
).option("--register-keys-to <url>", "Register the keys to a url (normally this is localhost)").action(async ({ registerKeysTo, path }) => {
|
|
75
70
|
const { accountPassphrase, accountSuri, accountFilePath } = globalOptions(program);
|
|
76
71
|
const accountset = await accountsetFromCli(program);
|
|
77
|
-
process2.env.KEYS_MNEMONIC ||=
|
|
72
|
+
process2.env.KEYS_MNEMONIC ||= _chunkSHAEHPI5cjs.mnemonicGenerate.call(void 0, );
|
|
78
73
|
if (registerKeysTo) {
|
|
79
74
|
await accountset.registerKeys(registerKeysTo);
|
|
80
75
|
console.log("Keys registered to", registerKeysTo);
|
|
@@ -99,21 +94,15 @@ function accountCli() {
|
|
|
99
94
|
});
|
|
100
95
|
program.command("new-key-seed").description("Create a new mnemonic for runtime keys").action(async () => {
|
|
101
96
|
await _utilcrypto.cryptoWaitReady.call(void 0, );
|
|
102
|
-
const mnemonic =
|
|
103
|
-
console.log(
|
|
104
|
-
"New mnemonic (add this to your .env as KEYS_MNEMONIC):",
|
|
105
|
-
mnemonic
|
|
106
|
-
);
|
|
97
|
+
const mnemonic = _chunkSHAEHPI5cjs.mnemonicGenerate.call(void 0, );
|
|
98
|
+
console.log("New mnemonic (add this to your .env as KEYS_MNEMONIC):", mnemonic);
|
|
107
99
|
process2.exit(0);
|
|
108
100
|
});
|
|
109
101
|
program.command("register-keys").description("Create an insert-keys script with curl").argument(
|
|
110
102
|
"[node-rpc-url]",
|
|
111
103
|
"The url to your node host (should be installed on machine via localhost)",
|
|
112
104
|
"http://localhost:9944"
|
|
113
|
-
).option(
|
|
114
|
-
"--print-only",
|
|
115
|
-
"Output as curl commands instead of direct registration"
|
|
116
|
-
).action(async (nodeRpcUrl, { printOnly }) => {
|
|
105
|
+
).option("--print-only", "Output as curl commands instead of direct registration").action(async (nodeRpcUrl, { printOnly }) => {
|
|
117
106
|
const accountset = await accountsetFromCli(program);
|
|
118
107
|
if (printOnly) {
|
|
119
108
|
const { gran, seal } = accountset.keys();
|
|
@@ -146,7 +135,7 @@ function accountCli() {
|
|
|
146
135
|
program.command("consolidate").description("Consolidate all argons into parent account").option(
|
|
147
136
|
"-s, --subaccounts <range>",
|
|
148
137
|
"Restrict this operation to a subset of the subaccounts (eg, 0-10)",
|
|
149
|
-
|
|
138
|
+
_chunkSHAEHPI5cjs.parseSubaccountRange
|
|
150
139
|
).action(async ({ subaccounts }) => {
|
|
151
140
|
const accountset = await accountsetFromCli(program);
|
|
152
141
|
const result = await accountset.consolidate(subaccounts);
|
|
@@ -163,12 +152,10 @@ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
|
163
152
|
// src/clis/vaultCli.ts
|
|
164
153
|
|
|
165
154
|
function vaultCli() {
|
|
166
|
-
const program = new (0, _extratypings.Command)("vaults").description(
|
|
167
|
-
"Monitor vaults and manage securitization"
|
|
168
|
-
);
|
|
155
|
+
const program = new (0, _extratypings.Command)("vaults").description("Monitor vaults and manage securitization");
|
|
169
156
|
program.command("list", { isDefault: true }).description("Show current state of vaults").action(async () => {
|
|
170
157
|
const accountset = await accountsetFromCli(program);
|
|
171
|
-
const vaults = new (0,
|
|
158
|
+
const vaults = new (0, _chunkSHAEHPI5cjs.VaultMonitor)(accountset, void 0, {
|
|
172
159
|
vaultOnlyWatchMode: true
|
|
173
160
|
});
|
|
174
161
|
await vaults.monitor(true);
|
|
@@ -178,15 +165,11 @@ function vaultCli() {
|
|
|
178
165
|
"-a, --argons <amount>",
|
|
179
166
|
"The number of argons to set as securitization",
|
|
180
167
|
parseFloat
|
|
181
|
-
).option("--ratio <ratio>", "The new securitization ratio", parseFloat).option(
|
|
182
|
-
"--tip <amount>",
|
|
183
|
-
"The tip to include with the transaction",
|
|
184
|
-
parseFloat
|
|
185
|
-
).action(async ({ tip, argons, vaultId, ratio }) => {
|
|
168
|
+
).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 }) => {
|
|
186
169
|
const accountset = await accountsetFromCli(program);
|
|
187
170
|
const client = await accountset.client;
|
|
188
|
-
const resolvedTip = tip ? BigInt(tip *
|
|
189
|
-
const microgons = BigInt(argons *
|
|
171
|
+
const resolvedTip = tip ? BigInt(tip * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : 0n;
|
|
172
|
+
const microgons = BigInt(argons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON);
|
|
190
173
|
const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();
|
|
191
174
|
if (rawVault.operatorAccountId.toHuman() !== accountset.seedAddress) {
|
|
192
175
|
console.error("Vault does not belong to this account");
|
|
@@ -199,7 +182,7 @@ function vaultCli() {
|
|
|
199
182
|
microgons,
|
|
200
183
|
ratio !== void 0 ? BigNumber(ratio).times(BigNumber(2).pow(64)).toFixed(0) : rawVault.securitizationRatio.toBigInt()
|
|
201
184
|
);
|
|
202
|
-
const submit = new (0,
|
|
185
|
+
const submit = new (0, _chunkSHAEHPI5cjs.TxSubmitter)(client, tx, accountset.txSubmitterPair);
|
|
203
186
|
const canAfford = await submit.canAfford({
|
|
204
187
|
tip: resolvedTip,
|
|
205
188
|
unavailableBalance: additionalFunds
|
|
@@ -221,34 +204,19 @@ function vaultCli() {
|
|
|
221
204
|
process.exit(1);
|
|
222
205
|
}
|
|
223
206
|
});
|
|
224
|
-
program.command("make-bitcoin-space").description(
|
|
225
|
-
"Make bitcoin space in a vault and lock it immediately in the same tx."
|
|
226
|
-
).requiredOption("-v, --vault-id <id>", "The vault id to use", parseInt).requiredOption(
|
|
227
|
-
"-a, --argons <amount>",
|
|
228
|
-
"The number of argons to add",
|
|
229
|
-
parseFloat
|
|
230
|
-
).requiredOption(
|
|
231
|
-
"--bitcoin-pubkey <pubkey>",
|
|
232
|
-
"The pubkey to use for the bitcoin lock"
|
|
233
|
-
).option(
|
|
234
|
-
"--tip <amount>",
|
|
235
|
-
"The tip to include with the transaction",
|
|
236
|
-
parseFloat
|
|
237
|
-
).action(async ({ tip, argons, vaultId, bitcoinPubkey }) => {
|
|
207
|
+
program.command("make-bitcoin-space").description("Make bitcoin space in a vault and lock it immediately in the same tx.").requiredOption("-v, --vault-id <id>", "The vault id to use", parseInt).requiredOption("-a, --argons <amount>", "The number of argons to add", parseFloat).requiredOption("--bitcoin-pubkey <pubkey>", "The pubkey to use for the bitcoin lock").option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ tip, argons, vaultId, bitcoinPubkey }) => {
|
|
238
208
|
let pubkey = bitcoinPubkey;
|
|
239
209
|
if (!bitcoinPubkey.startsWith("0x")) {
|
|
240
210
|
pubkey = `0x${bitcoinPubkey}`;
|
|
241
211
|
}
|
|
242
212
|
if (pubkey.length !== 68) {
|
|
243
|
-
throw new Error(
|
|
244
|
-
"Bitcoin pubkey must be 66 characters (add 0x in front optionally)"
|
|
245
|
-
);
|
|
213
|
+
throw new Error("Bitcoin pubkey must be 66 characters (add 0x in front optionally)");
|
|
246
214
|
}
|
|
247
215
|
const accountset = await accountsetFromCli(program);
|
|
248
216
|
const client = await accountset.client;
|
|
249
|
-
const resolvedTip = tip ? BigInt(tip *
|
|
250
|
-
const microgons = BigInt(argons *
|
|
251
|
-
const bitcoinLocks = new (0,
|
|
217
|
+
const resolvedTip = tip ? BigInt(tip * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : 0n;
|
|
218
|
+
const microgons = BigInt(argons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON);
|
|
219
|
+
const bitcoinLocks = new (0, _chunkSHAEHPI5cjs.BitcoinLocks)(Promise.resolve(client));
|
|
252
220
|
const existentialDeposit = client.consts.balances.existentialDeposit.toBigInt();
|
|
253
221
|
const tickDuration = (await client.query.ticks.genesisTicker()).tickDurationMillis.toNumber();
|
|
254
222
|
const rawVault = (await client.query.vaults.vaultsById(vaultId)).unwrap();
|
|
@@ -262,37 +230,36 @@ function vaultCli() {
|
|
|
262
230
|
rawVault.securitizationRatio.toBigInt()
|
|
263
231
|
);
|
|
264
232
|
const vaultTxFee = (await vaultModifyTx.paymentInfo(accountset.txSubmitterPair)).partialFee.toBigInt();
|
|
265
|
-
const vault = new (0,
|
|
233
|
+
const vault = new (0, _chunkSHAEHPI5cjs.Vault)(vaultId, rawVault, tickDuration);
|
|
266
234
|
const argonsNeeded = microgons - vault.securitization;
|
|
267
235
|
const argonsAvailable = microgons - vault.availableBitcoinSpace();
|
|
268
236
|
const account = await client.query.system.account(accountset.seedAddress);
|
|
269
237
|
const freeBalance = account.data.free.toBigInt();
|
|
238
|
+
let satoshis = await bitcoinLocks.requiredSatoshisForArgonLiquidity(argonsAvailable);
|
|
239
|
+
satoshis -= 100n;
|
|
270
240
|
const {
|
|
271
241
|
tx: lockTx,
|
|
272
|
-
btcFee,
|
|
242
|
+
securityFee: btcFee,
|
|
273
243
|
txFee
|
|
274
|
-
} = await bitcoinLocks.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
244
|
+
} = await bitcoinLocks.createInitializeLockTx({
|
|
245
|
+
vault,
|
|
246
|
+
argonKeyring: accountset.txSubmitterPair,
|
|
247
|
+
satoshis,
|
|
248
|
+
ownerBitcoinPubkey: Buffer.from(pubkey, "hex"),
|
|
279
249
|
tip: resolvedTip,
|
|
280
250
|
reducedBalanceBy: argonsNeeded + vaultTxFee + resolvedTip
|
|
281
251
|
});
|
|
282
252
|
if (argonsNeeded + txFee + vaultTxFee + resolvedTip + btcFee + existentialDeposit > freeBalance) {
|
|
283
|
-
console.warn(
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
neededBalanceAboveED: argonsNeeded + txFee + resolvedTip + btcFee + vaultTxFee
|
|
294
|
-
}
|
|
295
|
-
);
|
|
253
|
+
console.warn("Insufficient balance to add bitcoin space and use bitcoins", {
|
|
254
|
+
freeBalance,
|
|
255
|
+
txFee,
|
|
256
|
+
vaultTxFee,
|
|
257
|
+
btcFee,
|
|
258
|
+
argonsAvailable,
|
|
259
|
+
vaultMicrogons: microgons,
|
|
260
|
+
existentialDeposit,
|
|
261
|
+
neededBalanceAboveED: argonsNeeded + txFee + resolvedTip + btcFee + vaultTxFee
|
|
262
|
+
});
|
|
296
263
|
process.exit(1);
|
|
297
264
|
}
|
|
298
265
|
console.log("Adding bitcoin space and locking bitcoins...", {
|
|
@@ -302,7 +269,7 @@ function vaultCli() {
|
|
|
302
269
|
btcFee,
|
|
303
270
|
resolvedTip
|
|
304
271
|
});
|
|
305
|
-
const txSubmitter = new (0,
|
|
272
|
+
const txSubmitter = new (0, _chunkSHAEHPI5cjs.TxSubmitter)(
|
|
306
273
|
client,
|
|
307
274
|
client.tx.utility.batchAll([vaultModifyTx, lockTx]),
|
|
308
275
|
accountset.txSubmitterPair
|
|
@@ -323,12 +290,10 @@ function vaultCli() {
|
|
|
323
290
|
|
|
324
291
|
|
|
325
292
|
function miningCli() {
|
|
326
|
-
const program = new (0, _extratypings.Command)("mining").description(
|
|
327
|
-
"Watch mining seats or setup bidding"
|
|
328
|
-
);
|
|
293
|
+
const program = new (0, _extratypings.Command)("mining").description("Watch mining seats or setup bidding");
|
|
329
294
|
program.command("list", { isDefault: true }).description("Monitor all miners").action(async () => {
|
|
330
295
|
const accountset = await accountsetFromCli(program);
|
|
331
|
-
const bids = new (0,
|
|
296
|
+
const bids = new (0, _chunkSHAEHPI5cjs.MiningBids)(accountset.client);
|
|
332
297
|
const api = await accountset.client;
|
|
333
298
|
let lastMiners = {};
|
|
334
299
|
function print(blockNumber) {
|
|
@@ -344,80 +309,68 @@ function miningCli() {
|
|
|
344
309
|
_consoletableprinter.printTable.call(void 0,
|
|
345
310
|
toPrint.map((x) => ({
|
|
346
311
|
...x,
|
|
347
|
-
bid: x.bid ?
|
|
312
|
+
bid: x.bid ? _chunkSHAEHPI5cjs.formatArgons.call(void 0, x.bid) : "-",
|
|
348
313
|
isLastDay: x.isLastDay ? "Y" : "",
|
|
349
314
|
miner: x.miner
|
|
350
315
|
}))
|
|
351
316
|
);
|
|
352
317
|
}
|
|
353
318
|
if (!bids.nextCohort.length) {
|
|
354
|
-
console.log(
|
|
355
|
-
"-------------------------------------\nNo bids for next cohort"
|
|
356
|
-
);
|
|
319
|
+
console.log("-------------------------------------\nNo bids for next cohort");
|
|
357
320
|
} else {
|
|
358
321
|
bids.print();
|
|
359
322
|
}
|
|
360
323
|
}
|
|
361
|
-
const { unsubscribe } = await bids.watch(
|
|
362
|
-
accountset.namedAccounts,
|
|
363
|
-
void 0,
|
|
364
|
-
print
|
|
365
|
-
);
|
|
324
|
+
const { unsubscribe } = await bids.watch(accountset.namedAccounts, void 0, print);
|
|
366
325
|
console.log("Watching miners...");
|
|
367
326
|
const minMiners = api.consts.miningSlot.minCohortSize.toNumber();
|
|
368
|
-
const unsub = await api.query.miningSlot.nextFrameId(
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
i++;
|
|
392
|
-
}
|
|
393
|
-
while (i < minMiners) {
|
|
394
|
-
lastMiners[`${frameId}-${i}`] = {
|
|
395
|
-
miner: "none"
|
|
396
|
-
};
|
|
397
|
-
i++;
|
|
398
|
-
}
|
|
327
|
+
const unsub = await api.query.miningSlot.nextFrameId(async (nextFrameId) => {
|
|
328
|
+
const frames = new Array(nextFrameId.toNumber()).fill(0).map((_, i) => nextFrameId.toNumber() - i).sort();
|
|
329
|
+
const unseenFrames = new Set(frames);
|
|
330
|
+
const entries = await api.query.miningSlot.minersByCohort.entries();
|
|
331
|
+
const block = await api.query.system.number();
|
|
332
|
+
const sortedEntries = entries.sort((a, b) => {
|
|
333
|
+
const aIndex = a[0].args[0].toNumber();
|
|
334
|
+
const bIndex = b[0].args[0].toNumber();
|
|
335
|
+
return aIndex - bIndex;
|
|
336
|
+
});
|
|
337
|
+
for (const [rawFrameId, miners] of sortedEntries) {
|
|
338
|
+
const frameId = rawFrameId.args[0].toNumber();
|
|
339
|
+
unseenFrames.delete(frameId);
|
|
340
|
+
let i = 0;
|
|
341
|
+
for (const miner of miners) {
|
|
342
|
+
const address = miner.accountId.toHuman();
|
|
343
|
+
const startingFrameId = miner.startingFrameId.toNumber();
|
|
344
|
+
lastMiners[`${frameId}-${i}`] = {
|
|
345
|
+
miner: _nullishCoalesce(accountset.namedAccounts.get(address), () => ( address)),
|
|
346
|
+
bid: miner.bid.toBigInt(),
|
|
347
|
+
isLastDay: nextFrameId.toNumber() - startingFrameId === 10
|
|
348
|
+
};
|
|
349
|
+
i++;
|
|
399
350
|
}
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
351
|
+
while (i < minMiners) {
|
|
352
|
+
lastMiners[`${frameId}-${i}`] = {
|
|
353
|
+
miner: "none"
|
|
354
|
+
};
|
|
355
|
+
i++;
|
|
406
356
|
}
|
|
407
|
-
print(block.toNumber());
|
|
408
357
|
}
|
|
409
|
-
|
|
358
|
+
for (const frameId of unseenFrames) {
|
|
359
|
+
for (let i = 0; i < minMiners; i++) {
|
|
360
|
+
lastMiners[`${frameId}-${i}`] = {
|
|
361
|
+
miner: "none"
|
|
362
|
+
};
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
print(block.toNumber());
|
|
366
|
+
});
|
|
410
367
|
process.on("SIGINT", () => {
|
|
411
368
|
unsubscribe();
|
|
412
369
|
unsub();
|
|
413
370
|
process.exit(0);
|
|
414
371
|
});
|
|
415
372
|
});
|
|
416
|
-
program.command("bid").description("Submit mining bids within a range of parameters").option("--min-bid <amount>", "The minimum bid amount to use", parseFloat).option("--max-bid <amount>", "The maximum bid amount to use", parseFloat).option(
|
|
417
|
-
"--max-seats <n>",
|
|
418
|
-
"The maximum number of seats to bid on for the slot",
|
|
419
|
-
parseInt
|
|
420
|
-
).option(
|
|
373
|
+
program.command("bid").description("Submit mining bids within a range of parameters").option("--min-bid <amount>", "The minimum bid amount to use", parseFloat).option("--max-bid <amount>", "The maximum bid amount to use", parseFloat).option("--max-seats <n>", "The maximum number of seats to bid on for the slot", parseInt).option(
|
|
421
374
|
"--max-balance <argons>",
|
|
422
375
|
"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"
|
|
423
376
|
).option("--bid-increment <argons>", "The bid increment", parseFloat, 0.01).option("--bid-delay <ticks>", "Delay between bids in ticks", parseInt, 0).option("--run-continuous", "Keep running and rebid every day").option(
|
|
@@ -436,7 +389,7 @@ function miningCli() {
|
|
|
436
389
|
}) => {
|
|
437
390
|
const accountset = await accountsetFromCli(program, proxyForAddress);
|
|
438
391
|
let cohortBidder;
|
|
439
|
-
const miningBids = new (0,
|
|
392
|
+
const miningBids = new (0, _chunkSHAEHPI5cjs.MiningBids)(accountset.client, false);
|
|
440
393
|
const maxCohortSize = await miningBids.maxCohortSize();
|
|
441
394
|
const stopBidder = async (unsubscribe2) => {
|
|
442
395
|
if (cohortBidder) {
|
|
@@ -463,7 +416,7 @@ function miningCli() {
|
|
|
463
416
|
const balance = await accountset.balance();
|
|
464
417
|
const feeWiggleRoom = BigInt(25e3);
|
|
465
418
|
const amountAvailable = balance - feeWiggleRoom;
|
|
466
|
-
let maxBidAmount = maxBid ? BigInt(maxBid *
|
|
419
|
+
let maxBidAmount = maxBid ? BigInt(maxBid * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : void 0;
|
|
467
420
|
let maxBalanceToUse = amountAvailable;
|
|
468
421
|
if (maxBalance !== void 0) {
|
|
469
422
|
if (maxBalance.endsWith("%")) {
|
|
@@ -474,9 +427,7 @@ function miningCli() {
|
|
|
474
427
|
}
|
|
475
428
|
maxBalanceToUse = amountToBid;
|
|
476
429
|
} else {
|
|
477
|
-
maxBalanceToUse = BigInt(
|
|
478
|
-
Math.floor(parseFloat(maxBalance) * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON)
|
|
479
|
-
);
|
|
430
|
+
maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON));
|
|
480
431
|
}
|
|
481
432
|
maxBidAmount ??= maxBalanceToUse / BigInt(seatsToWin);
|
|
482
433
|
}
|
|
@@ -491,20 +442,13 @@ function miningCli() {
|
|
|
491
442
|
if (cohortBidder && _optionalChain([cohortBidder, 'optionalAccess', _3 => _3.cohortStartingFrameId]) !== cohortStartingFrameId) {
|
|
492
443
|
await stopBidder(unsubscribe);
|
|
493
444
|
}
|
|
494
|
-
cohortBidder = new (0,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
bidIncrement: BigInt(
|
|
502
|
-
Math.floor(bidIncrement * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON)
|
|
503
|
-
),
|
|
504
|
-
maxBudget: maxBalanceToUse,
|
|
505
|
-
bidDelay
|
|
506
|
-
}
|
|
507
|
-
);
|
|
445
|
+
cohortBidder = new (0, _chunkSHAEHPI5cjs.CohortBidder)(accountset, cohortStartingFrameId, subaccountRange, {
|
|
446
|
+
maxBid: maxBidAmount,
|
|
447
|
+
minBid: BigInt((_nullishCoalesce(minBid, () => ( 0))) * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON),
|
|
448
|
+
bidIncrement: BigInt(Math.floor(bidIncrement * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON)),
|
|
449
|
+
maxBudget: maxBalanceToUse,
|
|
450
|
+
bidDelay
|
|
451
|
+
});
|
|
508
452
|
await cohortBidder.start();
|
|
509
453
|
}
|
|
510
454
|
});
|
|
@@ -517,26 +461,18 @@ function miningCli() {
|
|
|
517
461
|
"--fee-argons <argons>",
|
|
518
462
|
"How many argons should be sent to the proxy account for fees (proxies must pay fees)",
|
|
519
463
|
parseFloat
|
|
520
|
-
).option(
|
|
521
|
-
"--proxy-passphrase <passphrase>",
|
|
522
|
-
"The passphrase for your proxy account"
|
|
523
|
-
).action(async ({ outfile, proxyPassphrase, feeArgons }) => {
|
|
464
|
+
).option("--proxy-passphrase <passphrase>", "The passphrase for your proxy account").action(async ({ outfile, proxyPassphrase, feeArgons }) => {
|
|
524
465
|
const { mainchainUrl } = globalOptions(program);
|
|
525
|
-
const client = await
|
|
466
|
+
const client = await _chunkSHAEHPI5cjs.getClient.call(void 0, mainchainUrl);
|
|
526
467
|
const keyringPair = await saveKeyringPair({
|
|
527
468
|
filePath: outfile,
|
|
528
469
|
passphrase: proxyPassphrase
|
|
529
470
|
});
|
|
530
471
|
const address = keyringPair.address;
|
|
531
|
-
console.log(
|
|
532
|
-
`\u2705 Created proxy account at "${outfile}" with address ${address}`
|
|
533
|
-
);
|
|
472
|
+
console.log(`\u2705 Created proxy account at "${outfile}" with address ${address}`);
|
|
534
473
|
const tx = client.tx.utility.batchAll([
|
|
535
474
|
client.tx.proxy.addProxy(address, "MiningBid", 0),
|
|
536
|
-
client.tx.balances.transferAllowDeath(
|
|
537
|
-
address,
|
|
538
|
-
BigInt(feeArgons * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON)
|
|
539
|
-
)
|
|
475
|
+
client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON))
|
|
540
476
|
]);
|
|
541
477
|
let keypair;
|
|
542
478
|
try {
|
|
@@ -548,7 +484,7 @@ function miningCli() {
|
|
|
548
484
|
process.exit(0);
|
|
549
485
|
}
|
|
550
486
|
try {
|
|
551
|
-
await new (0,
|
|
487
|
+
await new (0, _chunkSHAEHPI5cjs.TxSubmitter)(client, tx, keypair).submit({
|
|
552
488
|
waitForBlock: true
|
|
553
489
|
});
|
|
554
490
|
console.log("Mining bid proxy added and funded.");
|
|
@@ -564,89 +500,57 @@ function miningCli() {
|
|
|
564
500
|
// src/clis/liquidityCli.ts
|
|
565
501
|
|
|
566
502
|
function liquidityCli() {
|
|
567
|
-
const program = new (0, _extratypings.Command)("liquidity-pools").description(
|
|
568
|
-
"Monitor or bond to liquidity pools"
|
|
569
|
-
);
|
|
503
|
+
const program = new (0, _extratypings.Command)("liquidity-pools").description("Monitor or bond to liquidity pools");
|
|
570
504
|
program.command("list", { isDefault: true }).description("Show or watch the vault bid pool rewards").action(async () => {
|
|
571
505
|
const accountset = await accountsetFromCli(program);
|
|
572
|
-
const bidPool = new (0,
|
|
573
|
-
accountset.client,
|
|
574
|
-
accountset.txSubmitterPair
|
|
575
|
-
);
|
|
506
|
+
const bidPool = new (0, _chunkSHAEHPI5cjs.BidPool)(accountset.client, accountset.txSubmitterPair);
|
|
576
507
|
await bidPool.watch();
|
|
577
508
|
});
|
|
578
|
-
program.command("bond").description("Bond argons to a liquidity pool").requiredOption("-v, --vault-id <id>", "The vault id to use", parseInt).requiredOption(
|
|
579
|
-
"-a, --argons <amount>",
|
|
580
|
-
"The number of argons to set the vault to",
|
|
581
|
-
parseFloat
|
|
582
|
-
).option(
|
|
583
|
-
"--tip <amount>",
|
|
584
|
-
"The tip to include with the transaction",
|
|
585
|
-
parseFloat
|
|
586
|
-
).action(async ({ tip, argons, vaultId }) => {
|
|
509
|
+
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 }) => {
|
|
587
510
|
const accountset = await accountsetFromCli(program);
|
|
588
|
-
const resolvedTip = tip ? BigInt(tip *
|
|
589
|
-
const microgons = BigInt(argons *
|
|
590
|
-
const bidPool = new (0,
|
|
591
|
-
accountset.client,
|
|
592
|
-
accountset.txSubmitterPair
|
|
593
|
-
);
|
|
511
|
+
const resolvedTip = tip ? BigInt(tip * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : 0n;
|
|
512
|
+
const microgons = BigInt(argons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON);
|
|
513
|
+
const bidPool = new (0, _chunkSHAEHPI5cjs.BidPool)(accountset.client, accountset.txSubmitterPair);
|
|
594
514
|
await bidPool.bondArgons(vaultId, microgons, { tip: resolvedTip });
|
|
595
515
|
console.log("Bonded argons to liquidity pool bond");
|
|
596
516
|
process.exit();
|
|
597
517
|
});
|
|
598
|
-
program.command("wait-for-space").description(
|
|
599
|
-
"Add bonded argons to a liquidity pool when the market rate is favorable"
|
|
600
|
-
).requiredOption(
|
|
601
|
-
"--max-argons <amount>",
|
|
602
|
-
"Max daily argons to use per slot",
|
|
603
|
-
parseFloat
|
|
604
|
-
).option(
|
|
518
|
+
program.command("wait-for-space").description("Add bonded argons to a liquidity pool when the market rate is favorable").requiredOption("--max-argons <amount>", "Max daily argons to use per slot", parseFloat).option(
|
|
605
519
|
"--min-pct-sharing <percent>",
|
|
606
520
|
"The minimum profit sharing percent to allow",
|
|
607
521
|
parseInt,
|
|
608
522
|
30
|
|
609
|
-
).option(
|
|
610
|
-
|
|
611
|
-
"The tip to include with the transaction",
|
|
612
|
-
parseFloat
|
|
613
|
-
).action(async ({ maxArgons, minPctSharing, tip }) => {
|
|
614
|
-
const maxAmountPerSlot = BigInt(maxArgons * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON);
|
|
523
|
+
).option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ maxArgons, minPctSharing, tip }) => {
|
|
524
|
+
const maxAmountPerSlot = BigInt(maxArgons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON);
|
|
615
525
|
const accountset = await accountsetFromCli(program);
|
|
616
|
-
const vaults = new (0,
|
|
526
|
+
const vaults = new (0, _chunkSHAEHPI5cjs.VaultMonitor)(
|
|
617
527
|
accountset,
|
|
618
528
|
{
|
|
619
529
|
liquidityPoolSpaceAvailable: 1000000n
|
|
620
530
|
},
|
|
621
531
|
{ shouldLog: false }
|
|
622
532
|
);
|
|
623
|
-
const bidPool = new (0,
|
|
624
|
-
|
|
625
|
-
accountset.txSubmitterPair
|
|
626
|
-
);
|
|
627
|
-
const resolvedTip = tip ? BigInt(tip * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON) : 0n;
|
|
533
|
+
const bidPool = new (0, _chunkSHAEHPI5cjs.BidPool)(accountset.client, accountset.txSubmitterPair);
|
|
534
|
+
const resolvedTip = tip ? BigInt(tip * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : 0n;
|
|
628
535
|
console.log("Waiting for liquidity pool space...");
|
|
629
|
-
vaults.events.on(
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
);
|
|
637
|
-
return;
|
|
638
|
-
}
|
|
639
|
-
let amountToAdd = amount;
|
|
640
|
-
if (amountToAdd > maxAmountPerSlot) {
|
|
641
|
-
amountToAdd = maxAmountPerSlot;
|
|
642
|
-
}
|
|
643
|
-
await bidPool.bondArgons(vaultId, amountToAdd, { tip: resolvedTip });
|
|
644
|
-
console.log("Bonding argons to vault liquidity pool", {
|
|
645
|
-
vaultId,
|
|
646
|
-
amount: _chunkCHGCEO2Ucjs.formatArgons.call(void 0, amountToAdd)
|
|
647
|
-
});
|
|
536
|
+
vaults.events.on("liquidity-pool-space-above", async (vaultId, amount) => {
|
|
537
|
+
const vault = vaults.vaultsById[vaultId];
|
|
538
|
+
if (vault.terms.liquidityPoolProfitSharing.times(100).toNumber() < minPctSharing) {
|
|
539
|
+
console.info(
|
|
540
|
+
`Skipping vault ${vaultId} due to lower profit sharing than ${minPctSharing}%`
|
|
541
|
+
);
|
|
542
|
+
return;
|
|
648
543
|
}
|
|
649
|
-
|
|
544
|
+
let amountToAdd = amount;
|
|
545
|
+
if (amountToAdd > maxAmountPerSlot) {
|
|
546
|
+
amountToAdd = maxAmountPerSlot;
|
|
547
|
+
}
|
|
548
|
+
await bidPool.bondArgons(vaultId, amountToAdd, { tip: resolvedTip });
|
|
549
|
+
console.log("Bonding argons to vault liquidity pool", {
|
|
550
|
+
vaultId,
|
|
551
|
+
amount: _chunkSHAEHPI5cjs.formatArgons.call(void 0, amountToAdd)
|
|
552
|
+
});
|
|
553
|
+
});
|
|
650
554
|
await vaults.monitor();
|
|
651
555
|
});
|
|
652
556
|
return program;
|
|
@@ -662,15 +566,15 @@ function bitcoinCli() {
|
|
|
662
566
|
parseFloat
|
|
663
567
|
).description("Watch for bitcoin space available").action(async ({ argons }) => {
|
|
664
568
|
const accountset = await accountsetFromCli(program);
|
|
665
|
-
const bot = new (0,
|
|
666
|
-
bitcoinSpaceAvailable: argons ? BigInt(argons *
|
|
569
|
+
const bot = new (0, _chunkSHAEHPI5cjs.VaultMonitor)(accountset, {
|
|
570
|
+
bitcoinSpaceAvailable: argons ? BigInt(argons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : 1n
|
|
667
571
|
});
|
|
668
572
|
bot.events.on("bitcoin-space-above", async (vaultId, amount) => {
|
|
669
573
|
const vault = bot.vaultsById[vaultId];
|
|
670
574
|
const fee = vault.calculateBitcoinFee(amount);
|
|
671
575
|
const ratio = 100n * fee / amount;
|
|
672
576
|
console.log(
|
|
673
|
-
`Vault ${vaultId} has ${
|
|
577
|
+
`Vault ${vaultId} has ${_chunkSHAEHPI5cjs.formatArgons.call(void 0, amount)} argons available for bitcoin. Fee ratio is ${ratio}%`
|
|
674
578
|
);
|
|
675
579
|
});
|
|
676
580
|
await bot.monitor();
|
|
@@ -679,31 +583,19 @@ function bitcoinCli() {
|
|
|
679
583
|
"-a, --argons <amount>",
|
|
680
584
|
"Bitcoin argons needed. NOTE: your account must have enough to cover fees + tip after this amount.",
|
|
681
585
|
parseFloat
|
|
682
|
-
).requiredOption(
|
|
683
|
-
|
|
684
|
-
"The xpub key to use for bitcoin locking"
|
|
685
|
-
).option(
|
|
686
|
-
"--max-lock-fee <argons>",
|
|
687
|
-
"The max lock fee you're willing to pay",
|
|
688
|
-
parseFloat
|
|
689
|
-
).option(
|
|
690
|
-
"--tip <amount>",
|
|
691
|
-
"The tip to include with the transaction",
|
|
692
|
-
parseFloat,
|
|
693
|
-
0
|
|
694
|
-
).action(async ({ argons, bitcoinXpub, maxLockFee, tip }) => {
|
|
695
|
-
const amountToLock = BigInt(argons * _chunkCHGCEO2Ucjs.MICROGONS_PER_ARGON);
|
|
586
|
+
).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 }) => {
|
|
587
|
+
const amountToLock = BigInt(argons * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON);
|
|
696
588
|
const accountset = await accountsetFromCli(program);
|
|
697
|
-
await
|
|
589
|
+
await _chunkSHAEHPI5cjs.BitcoinLocks.waitForSpace(accountset, {
|
|
698
590
|
argonAmount: amountToLock,
|
|
699
591
|
bitcoinXpub,
|
|
700
|
-
maxLockFee: maxLockFee !== void 0 ? BigInt(maxLockFee *
|
|
701
|
-
tip: BigInt(tip *
|
|
702
|
-
}).then(({ vaultId, satoshis, txFee,
|
|
592
|
+
maxLockFee: maxLockFee !== void 0 ? BigInt(maxLockFee * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON) : void 0,
|
|
593
|
+
tip: BigInt(tip * _chunkSHAEHPI5cjs.MICROGONS_PER_ARGON)
|
|
594
|
+
}).then(({ vaultId, satoshis, txFee, securityFee }) => {
|
|
703
595
|
console.log(
|
|
704
|
-
`Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${
|
|
596
|
+
`Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${_chunkSHAEHPI5cjs.formatArgons.call(void 0,
|
|
705
597
|
txFee
|
|
706
|
-
)}, Lock fee=${
|
|
598
|
+
)}, Lock fee=${_chunkSHAEHPI5cjs.formatArgons.call(void 0, securityFee)}.`
|
|
707
599
|
);
|
|
708
600
|
process.exit(0);
|
|
709
601
|
});
|
|
@@ -728,13 +620,13 @@ async function keyringFromFile(opts) {
|
|
|
728
620
|
const passphrasePath = opts.passphraseFile.replace("~", os.homedir());
|
|
729
621
|
passphrase = await readFile(passphrasePath, "utf-8");
|
|
730
622
|
}
|
|
731
|
-
const mainAccount = new (0,
|
|
623
|
+
const mainAccount = new (0, _chunkSHAEHPI5cjs.Keyring)().createFromJson(json);
|
|
732
624
|
mainAccount.decodePkcs8(passphrase);
|
|
733
625
|
return mainAccount;
|
|
734
626
|
}
|
|
735
627
|
async function saveKeyringPair(opts) {
|
|
736
628
|
const { filePath, passphrase, cryptoType } = opts;
|
|
737
|
-
const keyring =
|
|
629
|
+
const keyring = _chunkSHAEHPI5cjs.createKeyringPair.call(void 0, { cryptoType });
|
|
738
630
|
if (filePath) {
|
|
739
631
|
const json = keyring.toJson(passphrase);
|
|
740
632
|
await writeFile(filePath, JSON.stringify(json, null, 2));
|
|
@@ -755,32 +647,27 @@ function buildCli() {
|
|
|
755
647
|
"The path to your json seed file from polkadotjs"
|
|
756
648
|
).env("ACCOUNT_JSON_PATH")
|
|
757
649
|
).addOption(
|
|
758
|
-
new (0, _extratypings.Option)(
|
|
759
|
-
"
|
|
760
|
-
|
|
761
|
-
).env("ACCOUNT_SURI")
|
|
762
|
-
).addOption(
|
|
763
|
-
new (0, _extratypings.Option)(
|
|
764
|
-
"--account-passphrase <password>",
|
|
765
|
-
"The password for your seed file"
|
|
766
|
-
).env("ACCOUNT_PASSPHRASE")
|
|
650
|
+
new (0, _extratypings.Option)("--account-suri <secretUri>", "A secret uri (suri) to use for the account").env(
|
|
651
|
+
"ACCOUNT_SURI"
|
|
652
|
+
)
|
|
767
653
|
).addOption(
|
|
768
|
-
new (0, _extratypings.Option)(
|
|
769
|
-
"
|
|
770
|
-
"The path to a password for your seed file"
|
|
654
|
+
new (0, _extratypings.Option)("--account-passphrase <password>", "The password for your seed file").env(
|
|
655
|
+
"ACCOUNT_PASSPHRASE"
|
|
771
656
|
)
|
|
657
|
+
).addOption(
|
|
658
|
+
new (0, _extratypings.Option)("--account-passphrase-file <path>", "The path to a password for your seed file")
|
|
772
659
|
).addOption(
|
|
773
660
|
new (0, _extratypings.Option)(
|
|
774
661
|
"-s, --subaccounts <range>",
|
|
775
662
|
"Restrict this operation to a subset of the subaccounts (eg, 0-10)"
|
|
776
|
-
).env("SUBACCOUNT_RANGE").argParser(
|
|
663
|
+
).env("SUBACCOUNT_RANGE").argParser(_chunkSHAEHPI5cjs.parseSubaccountRange)
|
|
777
664
|
).addCommand(accountCli()).addCommand(vaultCli()).addCommand(miningCli()).addCommand(liquidityCli()).addCommand(bitcoinCli());
|
|
778
665
|
}
|
|
779
666
|
async function accountsetFromCli(program, proxyForAddress) {
|
|
780
667
|
const opts = _optionalChain([program, 'access', _4 => _4.parent, 'optionalAccess', _5 => _5.optsWithGlobals, 'call', _6 => _6()]);
|
|
781
668
|
let keypair;
|
|
782
669
|
if (opts.accountSuri) {
|
|
783
|
-
keypair =
|
|
670
|
+
keypair = _chunkSHAEHPI5cjs.keyringFromSuri.call(void 0, opts.accountSuri);
|
|
784
671
|
}
|
|
785
672
|
if (opts.accountFilePath) {
|
|
786
673
|
keypair = await keyringFromFile({
|
|
@@ -794,16 +681,16 @@ async function accountsetFromCli(program, proxyForAddress) {
|
|
|
794
681
|
"No ACCOUNT account loaded (either ACCOUNT_SURI or ACCOUNT_JSON_PATH required)"
|
|
795
682
|
);
|
|
796
683
|
}
|
|
797
|
-
const client =
|
|
684
|
+
const client = _chunkSHAEHPI5cjs.getClient.call(void 0, opts.mainchainUrl);
|
|
798
685
|
if (proxyForAddress) {
|
|
799
|
-
return new (0,
|
|
686
|
+
return new (0, _chunkSHAEHPI5cjs.Accountset)({
|
|
800
687
|
client,
|
|
801
688
|
isProxy: true,
|
|
802
689
|
seedAddress: proxyForAddress,
|
|
803
690
|
txSubmitter: keypair
|
|
804
691
|
});
|
|
805
692
|
} else {
|
|
806
|
-
return new (0,
|
|
693
|
+
return new (0, _chunkSHAEHPI5cjs.Accountset)({
|
|
807
694
|
seedAccount: keypair,
|
|
808
695
|
client
|
|
809
696
|
});
|
|
@@ -851,4 +738,4 @@ function applyEnv(program) {
|
|
|
851
738
|
|
|
852
739
|
|
|
853
740
|
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;
|
|
854
|
-
//# sourceMappingURL=chunk-
|
|
741
|
+
//# sourceMappingURL=chunk-NU36V3JQ.cjs.map
|