-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathindex.js
More file actions
698 lines (694 loc) · 30.9 KB
/
index.js
File metadata and controls
698 lines (694 loc) · 30.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const commander_1 = require("commander");
const utxo_1 = require("../utxo");
const btc = tslib_1.__importStar(require("../btc"));
const brc20 = tslib_1.__importStar(require("../brc20"));
const collectible = tslib_1.__importStar(require("../collectible"));
const rune = tslib_1.__importStar(require("../rune"));
require("dotenv/config");
const __1 = require("..");
const bitcoin = tslib_1.__importStar(require("bitcoinjs-lib"));
const __2 = require("..");
const __3 = require("..");
const __4 = require("..");
const errors_1 = require("../errors");
const defaultProvider = {
bitcoin: new __2.Provider({
url: 'https://mainnet.sandshrew.io',
projectId: process.env.SANDSHREW_PROJECT_ID,
network: bitcoin.networks.bitcoin,
networkType: 'mainnet',
apiUrl: 'https://staging-api.oyl.gg',
//opiUrl: 'https://mainnet-opi.sandshrew.io/v1'
}),
regtest: new __2.Provider({
url: 'http://localhost:3000',
projectId: 'regtest',
network: bitcoin.networks.regtest,
networkType: 'regtest',
apiUrl: 'https://staging-api.oyl.gg',
//opiUrl: 'https://mainnet-opi.sandshrew.io/v1'
}),
};
const program = new commander_1.Command();
program
.name('default')
.description('All functionality for oyl-sdk in a cli-wrapper')
.version('0.0.1');
const generateCommand = new commander_1.Command('generate')
.description('Creates a new account object')
.option('-m, --mnemonic <mnemonic>', 'mnemonic you want to generate an account from')
.option('-i, --index <index>', 'index you want to derive your account keys from')
.option('-n, --network <network>', 'the network you want to derive keys on')
.action((options) => {
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
index: options.index,
network: bitcoin.networks[options.network],
},
});
console.log(account);
});
const privateKeysCommand = new commander_1.Command('privateKeys')
.description('Returns private keys for an account object')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.option('-i, --index <index>', 'index you want to derive your account keys from')
.requiredOption('-n, --network <network>', 'the network you want to derive keys on')
.action((options) => {
const privateKeys = (0, __1.getWalletPrivateKeys)({
mnemonic: options.mnemonic,
opts: {
index: options.index,
network: bitcoin.networks[options.network],
},
});
console.log(privateKeys);
});
const generateMnemonicCommand = new commander_1.Command('generateMnemonic')
.description('Returns a new mnemonic phrase')
.action(() => {
const mnemonic = (0, __1.generateMnemonic)();
console.log(mnemonic);
});
const signPsbt = new commander_1.Command('sign')
.requiredOption('-p, --provider <provider>', 'provider to use when signing the network psbt')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-f, --finalize <finalize>', 'flag to finalize and push psbt')
.requiredOption('-e, --extract <finalize>', 'flag to extract transaction')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
/* @dev example call
oyl account sign
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native '4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3'
-p regtest
-f yes
-e yes
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
let finalize = options.finalize == 'yes' ? true : false;
let extract = options.extract == 'yes' ? true : false;
const { signedHexPsbt } = await signer.signAllInputs({
rawPsbtHex: process.env.PSBT_HEX,
finalize,
});
if (extract) {
const extractedTx = bitcoin.Psbt.fromHex(signedHexPsbt).extractTransaction();
console.log('extracted tx', extractedTx);
console.log('extracted tx hex', extractedTx.toHex());
}
console.log('signed hex psbt', signedHexPsbt);
});
const accountUtxosToSpend = new commander_1.Command('accountUtxos')
.description('Returns available utxos to spend')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
/* @dev example call
oyl utxo accountUtxos -m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' -p regtest
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: { network: provider.network },
});
console.log(await (0, utxo_1.accountUtxos)({
account,
provider,
}));
});
const accountAvailableBalance = new commander_1.Command('balance')
.description('Returns available utxos to spend')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
/* @dev example call
oyl utxo balance -m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' -p regtest
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: { network: provider.network },
});
console.log(await (0, utxo_1.accountBalance)({
account,
provider,
}));
});
const addressBRC20Balance = new commander_1.Command('addressBRC20Balance')
.description('Returns all BRC20 balances')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-a, --address <address>', 'address you want to get utxos for')
.action(async (options) => {
const provider = defaultProvider[options.provider];
console.log((await provider.api.getBrc20sByAddress(options.address)).data);
});
const addressUtxosToSpend = new commander_1.Command('addressUtxos')
.description('Returns available utxos to spend')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-a, --address <address>', 'address you want to get utxos for')
/* @dev example call
oyl utxo addressUtxos -a bcrt1qcr8te4kr609gcawutmrza0j4xv80jy8zeqchgx -p regtest
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
console.log(await (0, utxo_1.addressUtxos)({
address: options.address,
provider,
}));
});
const btcSend = new commander_1.Command('send')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-amt, --amount <amount>', 'amount you want to send')
.requiredOption('-t, --to <to>', 'address you want to send to')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
/* @dev example call
oyl btc send
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native '4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3'
-p regtest
-t bcrt1qzr9vhs60g6qlmk7x3dd7g3ja30wyts48sxuemv
-amt 1000
-feeRate 2
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await btc.send({
toAddress: options.to,
feeRate: options.feeRate,
account,
signer,
provider,
amount: options.amount,
}));
});
const brc20Send = new commander_1.Command('send')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-amt, --amount <amount>', 'amount you want to send')
.requiredOption('-t, --to <to>', 'address you want to send to')
.requiredOption('-tick', '--ticker <ticker>', 'brc20 ticker to send')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
/* @dev example call
oyl brc20 send
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3
-taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361
-p regtest
-t bcrt1qzr9vhs60g6qlmk7x3dd7g3ja30wyts48sxuemv
-tick toyl
-amt 1000
-feeRate 2
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await brc20.send({
ticker: options.ticker,
toAddress: options.to,
feeRate: options.feeRate,
account,
signer,
provider,
amount: options.amount,
}));
});
const collectibleSend = new commander_1.Command('send')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-t, --to <to>', 'address you want to send to')
.requiredOption('-inscId, --inscriptionId <inscriptionId>', 'inscription to send')
.requiredOption('-inscAdd, --inscriptionAddress <inscriptionAddress>', 'current holder of inscription to send')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
/* @dev example call
oyl collectible send
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3
-taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361
-p regtest
-t bcrt1qzr9vhs60g6qlmk7x3dd7g3ja30wyts48sxuemv
-inscId d0c21b35f27ba6361acd5172fcfafe8f4f96d424c80c00b5793290387bcbcf44i0
-inscAdd bcrt1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqvg32hk
-feeRate 2
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await collectible.send({
inscriptionId: options.inscriptionId,
inscriptionAddress: options.inscriptionAddress,
toAddress: options.to,
feeRate: options.feeRate,
account,
signer,
provider,
}));
});
const runeSend = new commander_1.Command('send')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-t, --to <to>', 'address you want to send to')
.requiredOption('-runeId, --runeId <runeId>', 'runeId to send')
.requiredOption('-inscAdd, --inscriptionAddress <inscriptionAddress>', 'current holder of inscription to send')
.requiredOption('-amt, --amount <amount>', 'amount of runes you want to send')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
/* @dev example call
oyl rune send
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3
-taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361
-p regtest
-t bcrt1qzr9vhs60g6qlmk7x3dd7g3ja30wyts48sxuemv
-amt 100
-runeId 279:1
-inscAdd bcrt1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqvg32hk
-feeRate 2
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await rune.send({
runeId: options.runeId,
amount: options.amount,
inscriptionAddress: options.inscriptionAddress,
toAddress: options.to,
feeRate: options.feeRate,
account,
signer,
provider,
}));
});
const runeMint = new commander_1.Command('mint')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-runeId, --runeId <runeId>', 'runeId to send')
.requiredOption('-amt, --amount <amount>', 'amount of runes you want to send')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
/* @dev example call
oyl rune mint
-m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about'
-native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3
-taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361
-p regtest
-amt 1000
-runeId 279:1
-feeRate 2
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await rune.mint({
runeId: options.runeId,
amount: options.amount,
feeRate: options.feeRate,
account,
signer,
provider,
}));
});
const runeEtch = new commander_1.Command('etch')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-symbol, --symbol <symbol>', 'symbol for rune to etch')
.requiredOption('-rune-name, --rune-name <runeName>', 'name of rune to etch')
.requiredOption('-per-mint-amount, --per-mint-amount <perMintAmount>', 'the amount of runes each mint')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
.option('-turbo, --turbo <turbo>', 'use turbo')
.option('-divisibility, --divisibility <divisibility>', 'divisibility of rune')
.option('-cap, --cap <cap>', 'cap / total number of rune')
.option('-pre, --premine <premine>', 'premined amount of rune')
/* @dev example call
oyl rune etch -m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' -native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3 -taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361 -p regtest -feeRate 2 -divisibility 3 -cap 100000 -pre 1000 -symbol Z -rune-name OYLTESTER -per-mint-amount 500
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await rune.etch({
symbol: options.symbol,
premine: options.premine,
perMintAmount: options.perMintAmount,
turbo: Boolean(Number(options.turbo)),
divisibility: Number(options.divisibility),
runeName: options.runeName,
cap: options.cap,
feeRate: options.feeRate,
account,
signer,
provider,
}));
});
const runeProtoburn = new commander_1.Command('protoburn')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-tag, --protocolTag <protoTag>', 'Protorune Tag to be set')
.requiredOption('-rId, --runeId <runeId>', 'name of rune to etch')
.requiredOption('-ptr, --pointer <pointer>', 'the amount of runes each mint')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-feeRate, --feeRate <feeRate>', 'fee rate')
.option('-amt, --amount <amount>', 'amount to burn')
.option('-inscAdd, --inscriptionAddress <inscriptionAdd>', 'address runes live on that you are burning')
/* @dev example call
oyl rune protoburn -m 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about' -native 4604b4b710fe91f584fff084e1a9159fe4f8408fff380596a604948474ce4fa3 -taproot 41f41d69260df4cf277826a9b65a3717e4eeddbeedf637f212ca096576479361 -p regtest -feeRate 2 -tag 369 -inscAdd 'bcrt1p5cyxnuxmeuwuvkwfem96lqzszd02n6xdcjrs20cac6yqjjwudpxqvg32hk' -amt 100 -rId 263:1 -ptr 0
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
},
});
console.log(await rune.protoburn({
pointer: Number(options.pointer),
runeId: options.runeId,
inscriptionAddress: options.inscriptionAddress,
amount: Number(options.amount),
protocolTag: options.protocolTag,
feeRate: options.feeRate,
account,
signer,
provider,
}));
});
const getRuneByName = new commander_1.Command('getRuneByName')
.description('Returns rune details based on name provided')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-name, --name <name>', 'name of the rune you want to fetch')
/* @dev example call
oyl rune getRuneByName -name ETCHSGSXCUMYO -p regtest
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
console.log(await provider.ord.getRuneByName(options.name));
});
const multiCallSandshrewProviderCall = new commander_1.Command('sandShrewMulticall')
.description('Returns available utxos to spend')
.requiredOption('-p, --provider <provider>', 'provider to use when querying the network for utxos')
.requiredOption('-c, --calls <calls>', 'calls in this format: {method: string, params: string[]}')
/* @dev example call
oyl provider sandShrewMulticall -c '[{"method":"esplora_tx","params":["688f5c239e4e114af461dc1331d02ad5702e795daf2dcf397815e0b05cd23dbc"]},{"method":"btc_getblockcount", "params":[]}]' -p bitcoin
*/
.action(async (options) => {
let isJson = [];
try {
isJson = JSON.parse(options.calls);
const multiCall = isJson.map((call) => {
return [call.method, call.params];
});
const provider = defaultProvider[options.provider];
console.log(await provider.sandshrew.multiCall(multiCall));
}
catch (error) {
console.log(error);
}
});
const apiProviderCall = new commander_1.Command('api')
.description('Returns data based on api method invoked')
.requiredOption('-p, --provider <provider>', 'provider to use to access the network.')
.requiredOption('-method, --method <method>', 'name of the method you want to call for the api.')
.option('-params, --parameters <parameters>', 'parameters for the api method you are calling.')
/* @dev example call
oyl provider api -method getUnisatTickerOffers -params '{"ticker":"ordi"}' -p bitcoin
please note the json format if you need to pass an object.
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
let isJson;
try {
isJson = JSON.parse(options.parameters);
console.log(await provider.api[options.method](isJson));
}
catch (error) {
console.log(await provider.api[options.method](options.parameters));
}
});
const ordProviderCall = new commander_1.Command('ord')
.description('Returns data based on ord method invoked')
.requiredOption('-p, --provider <provider>', 'provider to use to access the network.')
.requiredOption('-method, --method <method>', 'name of the method you want to call for the api.')
.option('-params, --parameters <parameters>', 'parameters for the ord method you are calling.')
/* @dev example call
oyl provider ord -method getTxOutput -params '{"ticker":"ordi"}' -p bitcoin
please note the json format if you need to pass an object.
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
let isJson;
try {
isJson = JSON.parse(options.parameters);
console.log(await provider.ord[options.method](isJson));
}
catch (error) {
console.log(await provider.ord[options.method](options.parameters));
}
});
const opiProviderCall = new commander_1.Command('opi')
.description('Returns data based on opi query')
.requiredOption('-p, --provider <provider>', 'provider to use to access the network.')
.requiredOption('-method, --method <method>', 'name of the method you want to call for the api.')
.option('-params, --parameters <parameters>', 'parameters for the ord method you are calling.')
/* @dev example call
oyl provider opi -method getBrc20Balance -params '{"address":"bcrt1qzr9vhs60g6qlmk7x3dd7g3ja30wyts48sxuemv","ticker":"ordi"}' -p bitcoin
please note the json format if you need to pass an object.
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
let isJson;
try {
isJson = JSON.parse(options.parameters);
console.log(await provider.opi[options.method](isJson));
}
catch (error) {
console.log(await provider.opi[options.method](options.parameters));
}
});
const marketPlaceBuy = new commander_1.Command('buy')
.description('Returns rune details based on name provided')
.requiredOption('-p, --provider <provider>', 'provider to use to access the network.')
.requiredOption('-m, --mnemonic <mnemonic>', 'mnemonic you want to get private keys from')
.requiredOption('-type, --asset-type <assetType>', 'pass BRC20, COLLECTIBLE or RUNE')
.requiredOption('-feeRate, --feeRate <feeRate>', 'fee rate')
.requiredOption('-tick --ticker <ticker>', 'Asset ticker to fetch quotes for.')
.option('-legacy, --legacy <legacy>', 'legacy private key')
.option('-taproot, --taproot <taproot>', 'taproot private key')
.option('-nested, --nested-segwit <nestedSegwit>', 'nested segwit private key')
.option('-native, --native-segwit <nativeSegwit>', 'native segwit private key')
.option('-receive, --receive-address <receiveAddress>', 'address to receieve the assets.')
/* @dev example call
oyl marketplace buy -type BRC20 -tick ordi -feeRate 30 -native <nativePrivateKey> -p bitcoin
please note the json format if you need to pass an object.
*/
.action(async (options) => {
const provider = defaultProvider[options.provider];
const signer = new __3.Signer(provider.network, {
segwitPrivateKey: options.nativeSegwit,
taprootPrivateKey: options.taproot,
nestedSegwitPrivateKey: options.nestedSegwit,
legacyPrivateKey: options.legacy,
});
const account = (0, __1.mnemonicToAccount)({
mnemonic: options.mnemonic,
opts: {
network: provider.network,
spendStrategy: {
addressOrder: ['taproot', 'nativeSegwit'],
utxoSortGreatestToLeast: true,
changeAddress: 'taproot',
},
},
});
let quotes;
switch (options.assetType) {
case 'BRC20':
options.assetType = __4.AssetType.BRC20;
quotes = await provider.api.getBrc20Offers({
ticker: options.ticker,
});
break;
case 'RUNES':
options.assetType = __4.AssetType.RUNES;
quotes = await provider.api.getRuneOffers({
ticker: options.ticker,
});
break;
case 'COLLECTIBLE':
options.assetType = __4.AssetType.COLLECTIBLE;
break;
default:
throw new errors_1.OylTransactionError(Error('Incorrect asset type'));
}
// const marketplace: Trade = new Trade({
// provider: provider,
// receiveAddress:
// options.receiveAddress === undefined
// ? account.taproot.address
// : options.receiveAddress,
// account: account,
// assetType: options.assetType,
// signer,
// feeRate: Number(options.feeRate),
// })
// const offersToBuy = await marketplace.processAllOffers(quotes)
// const signedTxs = await marketplace.buyMarketPlaceOffers(offersToBuy)
// console.log(signedTxs)
});
const accountCommand = new commander_1.Command('account')
.description('Manage accounts')
.addCommand(generateCommand)
.addCommand(signPsbt)
.addCommand(privateKeysCommand)
.addCommand(generateMnemonicCommand);
const utxosCommand = new commander_1.Command('utxo')
.description('Examine utxos')
.addCommand(accountUtxosToSpend)
.addCommand(addressUtxosToSpend)
.addCommand(accountAvailableBalance);
const btcCommand = new commander_1.Command('btc')
.description('Functions for sending bitcoin')
.addCommand(btcSend);
const brc20Command = new commander_1.Command('brc20')
.description('Functions for brc20')
.addCommand(brc20Send)
.addCommand(addressBRC20Balance);
const collectibleCommand = new commander_1.Command('collectible')
.description('Functions for collectibles')
.addCommand(collectibleSend);
const runeCommand = new commander_1.Command('rune')
.description('Functions for runes')
.addCommand(runeSend)
.addCommand(runeMint)
.addCommand(runeEtch)
.addCommand(runeProtoburn)
.addCommand(getRuneByName);
const providerCommand = new commander_1.Command('provider')
.description('Functions avaialble for all provider services')
.addCommand(apiProviderCall)
.addCommand(ordProviderCall)
.addCommand(opiProviderCall)
.addCommand(multiCallSandshrewProviderCall);
const marketPlaceCommand = new commander_1.Command('marketplace')
.description('Functions for marketplace')
.addCommand(marketPlaceBuy);
program.addCommand(utxosCommand);
program.addCommand(accountCommand);
program.addCommand(btcCommand);
program.addCommand(brc20Command);
program.addCommand(collectibleCommand);
program.addCommand(runeCommand);
program.addCommand(providerCommand);
program.addCommand(marketPlaceCommand);
program.parse(process.argv);
//# sourceMappingURL=index.js.map