@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 @@ import {
|
|
|
15
15
|
keyringFromSuri,
|
|
16
16
|
mnemonicGenerate,
|
|
17
17
|
parseSubaccountRange
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-CGXT6XF7.js";
|
|
19
19
|
|
|
20
20
|
// src/clis/index.ts
|
|
21
21
|
import { Command as Command6, Option } from "@commander-js/extra-typings";
|
|
@@ -27,9 +27,7 @@ import { cryptoWaitReady } from "@polkadot/util-crypto";
|
|
|
27
27
|
import { writeFileSync } from "node:fs";
|
|
28
28
|
import * as process2 from "node:process";
|
|
29
29
|
function accountCli() {
|
|
30
|
-
const program = new Command("accounts").description(
|
|
31
|
-
"Manage subaccounts from a single keypair"
|
|
32
|
-
);
|
|
30
|
+
const program = new 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,10 +66,7 @@ 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
72
|
process2.env.KEYS_MNEMONIC ||= mnemonicGenerate();
|
|
@@ -100,20 +95,14 @@ function accountCli() {
|
|
|
100
95
|
program.command("new-key-seed").description("Create a new mnemonic for runtime keys").action(async () => {
|
|
101
96
|
await cryptoWaitReady();
|
|
102
97
|
const mnemonic = mnemonicGenerate();
|
|
103
|
-
console.log(
|
|
104
|
-
"New mnemonic (add this to your .env as KEYS_MNEMONIC):",
|
|
105
|
-
mnemonic
|
|
106
|
-
);
|
|
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();
|
|
@@ -163,9 +152,7 @@ import Path from "node:path";
|
|
|
163
152
|
// src/clis/vaultCli.ts
|
|
164
153
|
import { Command as Command2 } from "@commander-js/extra-typings";
|
|
165
154
|
function vaultCli() {
|
|
166
|
-
const program = new Command2("vaults").description(
|
|
167
|
-
"Monitor vaults and manage securitization"
|
|
168
|
-
);
|
|
155
|
+
const program = new Command2("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
158
|
const vaults = new VaultMonitor(accountset, void 0, {
|
|
@@ -178,11 +165,7 @@ 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
171
|
const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;
|
|
@@ -221,28 +204,13 @@ 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;
|
|
@@ -267,32 +235,31 @@ function vaultCli() {
|
|
|
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...", {
|
|
@@ -323,9 +290,7 @@ function vaultCli() {
|
|
|
323
290
|
import { Command as Command3 } from "@commander-js/extra-typings";
|
|
324
291
|
import { printTable as printTable2 } from "console-table-printer";
|
|
325
292
|
function miningCli() {
|
|
326
|
-
const program = new Command3("mining").description(
|
|
327
|
-
"Watch mining seats or setup bidding"
|
|
328
|
-
);
|
|
293
|
+
const program = new Command3("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
296
|
const bids = new MiningBids(accountset.client);
|
|
@@ -351,73 +316,61 @@ function miningCli() {
|
|
|
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: 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(
|
|
@@ -474,9 +427,7 @@ function miningCli() {
|
|
|
474
427
|
}
|
|
475
428
|
maxBalanceToUse = amountToBid;
|
|
476
429
|
} else {
|
|
477
|
-
maxBalanceToUse = BigInt(
|
|
478
|
-
Math.floor(parseFloat(maxBalance) * MICROGONS_PER_ARGON)
|
|
479
|
-
);
|
|
430
|
+
maxBalanceToUse = BigInt(Math.floor(parseFloat(maxBalance) * MICROGONS_PER_ARGON));
|
|
480
431
|
}
|
|
481
432
|
maxBidAmount ??= maxBalanceToUse / BigInt(seatsToWin);
|
|
482
433
|
}
|
|
@@ -491,20 +442,13 @@ function miningCli() {
|
|
|
491
442
|
if (cohortBidder && cohortBidder?.cohortStartingFrameId !== cohortStartingFrameId) {
|
|
492
443
|
await stopBidder(unsubscribe);
|
|
493
444
|
}
|
|
494
|
-
cohortBidder = new CohortBidder(
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
bidIncrement: BigInt(
|
|
502
|
-
Math.floor(bidIncrement * MICROGONS_PER_ARGON)
|
|
503
|
-
),
|
|
504
|
-
maxBudget: maxBalanceToUse,
|
|
505
|
-
bidDelay
|
|
506
|
-
}
|
|
507
|
-
);
|
|
445
|
+
cohortBidder = new CohortBidder(accountset, cohortStartingFrameId, subaccountRange, {
|
|
446
|
+
maxBid: maxBidAmount,
|
|
447
|
+
minBid: BigInt((minBid ?? 0) * MICROGONS_PER_ARGON),
|
|
448
|
+
bidIncrement: BigInt(Math.floor(bidIncrement * MICROGONS_PER_ARGON)),
|
|
449
|
+
maxBudget: maxBalanceToUse,
|
|
450
|
+
bidDelay
|
|
451
|
+
});
|
|
508
452
|
await cohortBidder.start();
|
|
509
453
|
}
|
|
510
454
|
});
|
|
@@ -517,10 +461,7 @@ 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
466
|
const client = await getClient(mainchainUrl);
|
|
526
467
|
const keyringPair = await saveKeyringPair({
|
|
@@ -528,15 +469,10 @@ function miningCli() {
|
|
|
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 * MICROGONS_PER_ARGON)
|
|
539
|
-
)
|
|
475
|
+
client.tx.balances.transferAllowDeath(address, BigInt(feeArgons * MICROGONS_PER_ARGON))
|
|
540
476
|
]);
|
|
541
477
|
let keypair;
|
|
542
478
|
try {
|
|
@@ -564,53 +500,27 @@ function miningCli() {
|
|
|
564
500
|
// src/clis/liquidityCli.ts
|
|
565
501
|
import { Command as Command4 } from "@commander-js/extra-typings";
|
|
566
502
|
function liquidityCli() {
|
|
567
|
-
const program = new Command4("liquidity-pools").description(
|
|
568
|
-
"Monitor or bond to liquidity pools"
|
|
569
|
-
);
|
|
503
|
+
const program = new Command4("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 BidPool(
|
|
573
|
-
accountset.client,
|
|
574
|
-
accountset.txSubmitterPair
|
|
575
|
-
);
|
|
506
|
+
const bidPool = new 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
511
|
const resolvedTip = tip ? BigInt(tip * MICROGONS_PER_ARGON) : 0n;
|
|
589
512
|
const microgons = BigInt(argons * MICROGONS_PER_ARGON);
|
|
590
|
-
const bidPool = new BidPool(
|
|
591
|
-
accountset.client,
|
|
592
|
-
accountset.txSubmitterPair
|
|
593
|
-
);
|
|
513
|
+
const bidPool = new 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
|
-
"--tip <amount>",
|
|
611
|
-
"The tip to include with the transaction",
|
|
612
|
-
parseFloat
|
|
613
|
-
).action(async ({ maxArgons, minPctSharing, tip }) => {
|
|
523
|
+
).option("--tip <amount>", "The tip to include with the transaction", parseFloat).action(async ({ maxArgons, minPctSharing, tip }) => {
|
|
614
524
|
const maxAmountPerSlot = BigInt(maxArgons * MICROGONS_PER_ARGON);
|
|
615
525
|
const accountset = await accountsetFromCli(program);
|
|
616
526
|
const vaults = new VaultMonitor(
|
|
@@ -620,33 +530,27 @@ function liquidityCli() {
|
|
|
620
530
|
},
|
|
621
531
|
{ shouldLog: false }
|
|
622
532
|
);
|
|
623
|
-
const bidPool = new BidPool(
|
|
624
|
-
accountset.client,
|
|
625
|
-
accountset.txSubmitterPair
|
|
626
|
-
);
|
|
533
|
+
const bidPool = new BidPool(accountset.client, accountset.txSubmitterPair);
|
|
627
534
|
const resolvedTip = tip ? BigInt(tip * 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: formatArgons(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: formatArgons(amountToAdd)
|
|
552
|
+
});
|
|
553
|
+
});
|
|
650
554
|
await vaults.monitor();
|
|
651
555
|
});
|
|
652
556
|
return program;
|
|
@@ -679,19 +583,7 @@ 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
|
-
"--bitcoin-xpub <xpub>",
|
|
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 }) => {
|
|
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 }) => {
|
|
695
587
|
const amountToLock = BigInt(argons * MICROGONS_PER_ARGON);
|
|
696
588
|
const accountset = await accountsetFromCli(program);
|
|
697
589
|
await BitcoinLocks.waitForSpace(accountset, {
|
|
@@ -699,11 +591,11 @@ function bitcoinCli() {
|
|
|
699
591
|
bitcoinXpub,
|
|
700
592
|
maxLockFee: maxLockFee !== void 0 ? BigInt(maxLockFee * MICROGONS_PER_ARGON) : void 0,
|
|
701
593
|
tip: BigInt(tip * MICROGONS_PER_ARGON)
|
|
702
|
-
}).then(({ vaultId, satoshis, txFee,
|
|
594
|
+
}).then(({ vaultId, satoshis, txFee, securityFee }) => {
|
|
703
595
|
console.log(
|
|
704
596
|
`Locked ${satoshis} satoshis in vault ${vaultId}. Tx fee=${formatArgons(
|
|
705
597
|
txFee
|
|
706
|
-
)}, Lock fee=${formatArgons(
|
|
598
|
+
)}, Lock fee=${formatArgons(securityFee)}.`
|
|
707
599
|
);
|
|
708
600
|
process.exit(0);
|
|
709
601
|
});
|
|
@@ -755,20 +647,15 @@ function buildCli() {
|
|
|
755
647
|
"The path to your json seed file from polkadotjs"
|
|
756
648
|
).env("ACCOUNT_JSON_PATH")
|
|
757
649
|
).addOption(
|
|
758
|
-
new Option(
|
|
759
|
-
"
|
|
760
|
-
|
|
761
|
-
).env("ACCOUNT_SURI")
|
|
762
|
-
).addOption(
|
|
763
|
-
new Option(
|
|
764
|
-
"--account-passphrase <password>",
|
|
765
|
-
"The password for your seed file"
|
|
766
|
-
).env("ACCOUNT_PASSPHRASE")
|
|
650
|
+
new Option("--account-suri <secretUri>", "A secret uri (suri) to use for the account").env(
|
|
651
|
+
"ACCOUNT_SURI"
|
|
652
|
+
)
|
|
767
653
|
).addOption(
|
|
768
|
-
new Option(
|
|
769
|
-
"
|
|
770
|
-
"The path to a password for your seed file"
|
|
654
|
+
new Option("--account-passphrase <password>", "The password for your seed file").env(
|
|
655
|
+
"ACCOUNT_PASSPHRASE"
|
|
771
656
|
)
|
|
657
|
+
).addOption(
|
|
658
|
+
new Option("--account-passphrase-file <path>", "The path to a password for your seed file")
|
|
772
659
|
).addOption(
|
|
773
660
|
new Option(
|
|
774
661
|
"-s, --subaccounts <range>",
|
|
@@ -851,4 +738,4 @@ export {
|
|
|
851
738
|
addGlobalArgs,
|
|
852
739
|
applyEnv
|
|
853
740
|
};
|
|
854
|
-
//# sourceMappingURL=chunk-
|
|
741
|
+
//# sourceMappingURL=chunk-FNSFV3MO.js.map
|