@teleportdao/bitcoin 1.8.9 → 2.0.0

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.
Files changed (55) hide show
  1. package/.tmp/block-parser.ts +58 -0
  2. package/dist/bitcoin-interface-ordinal.d.ts +2 -2
  3. package/dist/bitcoin-interface-ordinal.d.ts.map +1 -1
  4. package/dist/bitcoin-interface-ordinal.js +1 -1
  5. package/dist/bitcoin-interface-ordinal.js.map +1 -1
  6. package/dist/bitcoin-interface-teleswap.d.ts +2 -53
  7. package/dist/bitcoin-interface-teleswap.d.ts.map +1 -1
  8. package/dist/bitcoin-interface-teleswap.js +6 -17
  9. package/dist/bitcoin-interface-teleswap.js.map +1 -1
  10. package/dist/bitcoin-interface-wallet.d.ts +29 -0
  11. package/dist/bitcoin-interface-wallet.d.ts.map +1 -0
  12. package/dist/bitcoin-interface-wallet.js +126 -0
  13. package/dist/bitcoin-interface-wallet.js.map +1 -0
  14. package/dist/bitcoin-interface.d.ts +5 -23
  15. package/dist/bitcoin-interface.d.ts.map +1 -1
  16. package/dist/bitcoin-interface.js +13 -92
  17. package/dist/bitcoin-interface.js.map +1 -1
  18. package/dist/bitcoin-wallet-base.d.ts +55 -31
  19. package/dist/bitcoin-wallet-base.d.ts.map +1 -1
  20. package/dist/bitcoin-wallet-base.js +105 -84
  21. package/dist/bitcoin-wallet-base.js.map +1 -1
  22. package/dist/ordinal-wallet.d.ts +29 -71
  23. package/dist/ordinal-wallet.d.ts.map +1 -1
  24. package/dist/ordinal-wallet.js +48 -108
  25. package/dist/ordinal-wallet.js.map +1 -1
  26. package/dist/teleswap-wallet.d.ts +10 -16
  27. package/dist/teleswap-wallet.d.ts.map +1 -1
  28. package/dist/teleswap-wallet.js +10 -30
  29. package/dist/teleswap-wallet.js.map +1 -1
  30. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +4 -11
  31. package/dist/transaction-builder/bitcoin-transaction-builder.d.ts.map +1 -1
  32. package/dist/transaction-builder/bitcoin-transaction-builder.js +2 -23
  33. package/dist/transaction-builder/bitcoin-transaction-builder.js.map +1 -1
  34. package/dist/transaction-builder/ordinal-transaction-builder.d.ts +3 -2
  35. package/dist/transaction-builder/ordinal-transaction-builder.d.ts.map +1 -1
  36. package/dist/transaction-builder/ordinal-transaction-builder.js +1 -6
  37. package/dist/transaction-builder/ordinal-transaction-builder.js.map +1 -1
  38. package/dist/transaction-builder/transaction-builder.d.ts +3 -7
  39. package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
  40. package/dist/transaction-builder/transaction-builder.js +22 -49
  41. package/dist/transaction-builder/transaction-builder.js.map +1 -1
  42. package/dist/type.d.ts +33 -18
  43. package/dist/type.d.ts.map +1 -1
  44. package/package.json +4 -4
  45. package/src/bitcoin-interface-ordinal.ts +7 -3
  46. package/src/bitcoin-interface-teleswap.ts +7 -22
  47. package/src/bitcoin-interface-wallet.ts +114 -0
  48. package/src/bitcoin-interface.ts +15 -98
  49. package/src/bitcoin-wallet-base.ts +166 -132
  50. package/src/ordinal-wallet.ts +73 -162
  51. package/src/teleswap-wallet.ts +50 -72
  52. package/src/transaction-builder/bitcoin-transaction-builder.ts +6 -24
  53. package/src/transaction-builder/ordinal-transaction-builder.ts +2 -10
  54. package/src/transaction-builder/transaction-builder.ts +34 -50
  55. package/src/type.ts +45 -19
@@ -5,10 +5,10 @@ import BitcoinSign from "./sign/sign-transaction"
5
5
  //
6
6
  import { BitcoinInterfaceOrdinal } from "./bitcoin-interface-ordinal"
7
7
  import { generateBrc2OpReturn } from "./helper/brc20-helper"
8
- import { runWithRetries, sleep } from "./utils/tools"
9
- import { BitcoinConnectionInfo } from "./type"
8
+ import { sleep } from "./utils/tools"
10
9
  import { ChangeTarget, ExtendedUtxo, SignerInfo, Target } from "./transaction-builder"
11
- import { BitcoinBaseWallet } from "./bitcoin-wallet-base"
10
+ import { BitcoinBaseWallet, FeeRateType } from "./bitcoin-wallet-base"
11
+ import { BTCTokenConnectionInfo, RPCConnectionInfo, UtxoConnectionInfo } from "./type"
12
12
 
13
13
  class OrdinalWallet extends BitcoinBaseWallet {
14
14
  unisat: bitcoinProviders.UniSat
@@ -18,29 +18,29 @@ class OrdinalWallet extends BitcoinBaseWallet {
18
18
  constructor(
19
19
  networkName: string,
20
20
  uniSatToken: string,
21
- connectionInfo: BitcoinConnectionInfo = {
22
- api: {
23
- provider: "MempoolSpace",
24
- },
21
+ connectionInfo: {
22
+ // btcToken: BTCTokenConnectionInfo
23
+ rpc: RPCConnectionInfo
24
+ utxo?: UtxoConnectionInfo
25
+ // rpc used for getRawTransaction in transaction builder if set (optional)
25
26
  },
26
27
  ) {
27
- super(networkName, connectionInfo)
28
- if (!connectionInfo.rpc?.enabled) {
28
+ if (!connectionInfo.rpc) {
29
+ // because api providers usually don't support sending custom psbt include p2tr address so we need rpc provider
29
30
  throw new Error("rpc is required")
30
31
  }
31
- this.transactionBuilder = new OrdinalTransactionBuilder(connectionInfo, networkName)
32
+ super(networkName, connectionInfo)
33
+
34
+ this.transactionBuilder = new OrdinalTransactionBuilder(
35
+ networkName,
36
+ this.network,
37
+ connectionInfo,
38
+ )
32
39
  this.signer = new BitcoinSign(this.network)
33
40
  this.btcInterface = new BitcoinInterfaceOrdinal(connectionInfo, networkName, uniSatToken)
34
41
  this.unisat = this.btcInterface.unisat
35
42
  }
36
43
 
37
- async sendSignedPsbtWithRetry(signedPsbt: string, { maxTries = 5, retrySleep = 5000 } = {}) {
38
- return runWithRetries(() => this.sendSignedPsbt(signedPsbt), {
39
- retrySleep,
40
- maxTries,
41
- })
42
- }
43
-
44
44
  static deployBRC20Data(tickName: string, max: number | string, limit: number | string) {
45
45
  let data = {
46
46
  p: "brc-20",
@@ -86,82 +86,6 @@ class OrdinalWallet extends BitcoinBaseWallet {
86
86
  }
87
87
  }
88
88
 
89
- async sendUsingUtxosUnsigned({
90
- receivers,
91
- speed = "normal",
92
- utxo,
93
- changeAddress,
94
- staticFeeRate,
95
- }: {
96
- receivers: {
97
- address: string
98
- value: number
99
- }[]
100
- changeAddress: string
101
- speed?: "normal" | "fast" | "slow"
102
- staticFeeRate?: number
103
- utxo: ExtendedUtxo[]
104
- }) {
105
- let extendedUtxo: ExtendedUtxo[] = utxo
106
-
107
- receivers.forEach(({ value }) => {
108
- if (value - +value.toFixed(0) !== 0)
109
- throw new Error("incorrect amount. amount should be in satoshi")
110
- })
111
-
112
- // eslint-disable-next-line no-underscore-dangle
113
- let feeRate = staticFeeRate || (await this.transactionBuilder._getFeeRate(speed))
114
- let unsignedTx = await this.transactionBuilder.processUnsignedTransaction({
115
- extendedUtxo,
116
- targets: receivers,
117
- changeAddress,
118
- feeRate,
119
- fullAmount: false,
120
- })
121
-
122
- return {
123
- ...unsignedTx,
124
- possibleTxId: this.transactionBuilder.getUnsignedPsbtTxId(unsignedTx.unsignedTransaction),
125
- }
126
- }
127
-
128
- async sendUsingUtxos({
129
- receivers,
130
- speed = "normal",
131
- utxo,
132
- }: {
133
- receivers: {
134
- address: string
135
- value: number
136
- }[]
137
- speed?: "normal" | "fast" | "slow"
138
- utxo?: ExtendedUtxo[]
139
- }) {
140
- if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
141
- throw new Error("account not initialized")
142
- }
143
-
144
- let extendedUtxo: ExtendedUtxo[] = utxo
145
- ? utxo.filter((u) => u.signerInfo.address === this.currentAccount!)
146
- : await this.getExtendedUtxo({
147
- address: this.currentAccount,
148
- addressType: this.currentAccountType,
149
- publicKey: this.publicKey.toString("hex"),
150
- })
151
-
152
- let unsignedTx = await this.sendUsingUtxosUnsigned({
153
- receivers,
154
- speed,
155
- utxo: extendedUtxo,
156
- changeAddress: this.bitcoinAddress!,
157
- })
158
- let signedPsbt = await this.signer.signPsbt(unsignedTx, this.privateKey)
159
- let signedTx = this.signer.finalizePsbts([signedPsbt])
160
- let txId = await this.transactionBuilder.sendTx(signedTx)
161
- const { inputs, outputs, change, fee } = unsignedTx
162
- return { txId, inputs, outputs, change, fee }
163
- }
164
-
165
89
  async inscribeOrdinalDepositUnsigned(
166
90
  file: {
167
91
  buffer: Buffer
@@ -169,8 +93,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
169
93
  },
170
94
  signer: SignerInfo,
171
95
  ordinalSigner?: SignerInfo,
96
+ fee: FeeRateType = "normal",
172
97
  extendedUtxo?: ExtendedUtxo[],
173
- staticFeeRate?: number,
174
98
  ) {
175
99
  const ordinalSignerPublicKey = ordinalSigner?.publicKey || signer.publicKey
176
100
  const publicKey = Buffer.from(ordinalSignerPublicKey, "hex")
@@ -178,23 +102,20 @@ class OrdinalWallet extends BitcoinBaseWallet {
178
102
  const leafScript = transferOrdinal.redeem.output
179
103
  const { ordinalAddress } = transferOrdinal
180
104
 
181
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
182
- let fee = +(((400 + leafScript.length) / 4) * feeRate * 1.5).toFixed(0)
105
+ let feeRate = await this.getFeeRate(fee)
106
+ let extraFee = +(((400 + leafScript.length) / 4) * feeRate * 1.5).toFixed(0)
183
107
  let ordinalAmount = 600
184
108
 
185
109
  let utxo1: ExtendedUtxo[] =
186
110
  extendedUtxo || (await this.btcInterface.getBTCUtxo(signer.address, signer))
187
111
 
188
- let inscribeDepositUnsignedInfo = await this.sendUsingUtxosUnsigned({
189
- receivers: [
190
- {
191
- address: ordinalAddress,
192
- value: ordinalAmount + fee,
193
- },
194
- ],
195
- utxo: utxo1,
196
- changeAddress: signer.address,
197
- })
112
+ let inscribeDepositUnsignedInfo = await this.sendBTCUnsignedTx(
113
+ ordinalAddress,
114
+ ordinalAmount + extraFee,
115
+ signer,
116
+ feeRate,
117
+ utxo1,
118
+ )
198
119
 
199
120
  return {
200
121
  inscribeDepositUnsignedInfo,
@@ -209,20 +130,20 @@ class OrdinalWallet extends BitcoinBaseWallet {
209
130
  },
210
131
  signer: SignerInfo,
211
132
  ordinalSigner?: SignerInfo,
133
+ fee: FeeRateType = "normal",
212
134
  extendedUtxo?: ExtendedUtxo[],
213
- staticFeeRate?: number,
214
135
  ) {
215
136
  const receiverAddress = ordinalSigner?.address || signer.address
216
137
  const { inscribeDepositUnsignedInfo, transferOrdinal } =
217
- await this.inscribeOrdinalDepositUnsigned(
218
- file,
219
- signer,
220
- ordinalSigner,
221
- extendedUtxo,
222
- staticFeeRate,
223
- )
138
+ await this.inscribeOrdinalDepositUnsigned(file, signer, ordinalSigner, fee, extendedUtxo)
224
139
  const { ordinalAddress } = transferOrdinal
225
140
  let ordinalAmount = 600
141
+
142
+ if (!inscribeDepositUnsignedInfo.possibleTxId)
143
+ throw new Error(
144
+ "inscribeDepositUnsignedInfo.possibleTxId is required. inscriber address type is not p2tr",
145
+ )
146
+
226
147
  let inscribeDeposit: {
227
148
  hash: string
228
149
  value: number
@@ -239,18 +160,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
239
160
  ordinalAmount,
240
161
  )
241
162
  return {
242
- inscribeDepositUnsignedInfo: {
243
- ...inscribeDepositUnsignedInfo,
244
- possibleTxId: this.transactionBuilder.getUnsignedPsbtTxId(
245
- inscribeDepositUnsignedInfo.unsignedTransaction,
246
- ),
247
- },
248
- inscribeUnsignedInfo: {
249
- ...inscribeUnsignedInfo,
250
- possibleTxId: this.transactionBuilder.getUnsignedPsbtTxId(
251
- inscribeUnsignedInfo.unsignedTransaction,
252
- ),
253
- },
163
+ inscribeDepositUnsignedInfo,
164
+ inscribeUnsignedInfo,
254
165
  inscribeAddress: ordinalAddress,
255
166
  receiverAddress,
256
167
  }
@@ -261,8 +172,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
261
172
  buffer: Buffer
262
173
  type: string
263
174
  },
175
+ fee: FeeRateType = "normal",
264
176
  extendedUtxo?: ExtendedUtxo[],
265
- staticFeeRate?: number,
266
177
  ordinalReceiverAddress?: string,
267
178
  ) {
268
179
  if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
@@ -275,8 +186,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
275
186
  file,
276
187
  this.signerInfo!,
277
188
  undefined,
189
+ fee,
278
190
  extendedUtxo,
279
- staticFeeRate,
280
191
  )
281
192
  let ordinalUtxo = await this.btcInterface.getBTCUtxo(
282
193
  transferOrdinal.ordinalAddress,
@@ -360,40 +271,40 @@ class OrdinalWallet extends BitcoinBaseWallet {
360
271
 
361
272
  async deployBrc20(
362
273
  brc: { tick: string; max: number; limit: number },
274
+ fee: FeeRateType = "normal",
363
275
  extendedUtxo?: ExtendedUtxo[],
364
- staticFeeRate?: number,
365
276
  ) {
366
277
  let file = OrdinalWallet.deployBRC20Data(brc.tick, brc.max, brc.limit)
367
- return this.inscribeOrdinal(file, extendedUtxo, staticFeeRate)
278
+ return this.inscribeOrdinal(file, fee, extendedUtxo)
368
279
  }
369
280
 
370
281
  async mintBrc20(
371
282
  brc: { tick: string; amount: number | string },
283
+ fee: FeeRateType = "normal",
372
284
  extendedUtxo?: ExtendedUtxo[],
373
- staticFeeRate?: number,
374
285
  ) {
375
286
  let file = OrdinalWallet.mintBRC20Data(brc.tick, brc.amount)
376
- return this.inscribeOrdinal(file, extendedUtxo, staticFeeRate)
287
+ return this.inscribeOrdinal(file, fee, extendedUtxo)
377
288
  }
378
289
 
379
290
  async inscribeBrc20Unsigned(
380
291
  brc: { tick: string; amount: number | string },
381
292
  signer: SignerInfo,
382
293
  ordinalSigner?: SignerInfo,
294
+ fee: FeeRateType = "normal",
383
295
  extendedUtxo?: ExtendedUtxo[],
384
- staticFeeRate?: number,
385
296
  ) {
386
297
  let file = OrdinalWallet.transferBRC20Data(brc.tick, brc.amount)
387
- return this.inscribeOrdinalUnsigned(file, signer, ordinalSigner, extendedUtxo, staticFeeRate)
298
+ return this.inscribeOrdinalUnsigned(file, signer, ordinalSigner, fee, extendedUtxo)
388
299
  }
389
300
 
390
301
  async inscribeBrc20(
391
302
  brc: { tick: string; amount: number | string },
303
+ fee: FeeRateType = "normal",
392
304
  extendedUtxo?: ExtendedUtxo[],
393
- staticFeeRate?: number,
394
305
  ) {
395
306
  let file = OrdinalWallet.transferBRC20Data(brc.tick, brc.amount)
396
- return this.inscribeOrdinal(file, extendedUtxo, staticFeeRate)
307
+ return this.inscribeOrdinal(file, fee, extendedUtxo)
397
308
  }
398
309
 
399
310
  async transferBrc20Unsigned(
@@ -405,13 +316,13 @@ class OrdinalWallet extends BitcoinBaseWallet {
405
316
  },
406
317
  signer: SignerInfo,
407
318
  ordinalSigner?: SignerInfo,
319
+ fee: FeeRateType = "normal",
408
320
  extendedUtxo?: ExtendedUtxo[],
409
- staticFeeRate?: number,
410
321
  otherTargets?: Target[],
411
322
  ) {
412
323
  const ordinalSignerInfo = ordinalSigner || signer
413
324
  let utxo = extendedUtxo || (await this.btcInterface.getBTCUtxo(signer.address, signer))
414
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
325
+ let feeRate = await this.getFeeRate(fee)
415
326
  let unsignedTx = await this.transactionBuilder.createNftPsbt({
416
327
  extendedUtxo: utxo,
417
328
  nftExtendedUtxo: {
@@ -438,14 +349,14 @@ class OrdinalWallet extends BitcoinBaseWallet {
438
349
  value: number
439
350
  index: number
440
351
  },
352
+ fee: FeeRateType = "normal",
441
353
  extendedUtxo: ExtendedUtxo[],
442
- staticFeeRate?: number,
443
354
  otherTargets?: Target[],
444
355
  ) {
445
356
  if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
446
357
  throw new Error("account not initialized")
447
358
  }
448
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
359
+ let feeRate = await this.getFeeRate(fee)
449
360
  let unsignedTx = await this.transactionBuilder.createNftPsbt({
450
361
  extendedUtxo,
451
362
  nftExtendedUtxo: {
@@ -478,8 +389,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
478
389
  signer: SignerInfo,
479
390
  ordinalSigner?: SignerInfo,
480
391
  otherTargets?: Target[],
392
+ fee: FeeRateType = "normal",
481
393
  extendedUtxo?: ExtendedUtxo[],
482
- staticFeeRate?: number,
483
394
  ) {
484
395
  const ordinalSignerInfo = ordinalSigner || signer
485
396
  // check all fee before process transaction
@@ -497,13 +408,13 @@ class OrdinalWallet extends BitcoinBaseWallet {
497
408
  throw new Error("insufficient balance")
498
409
  }
499
410
 
500
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
411
+ let feeRate = await this.getFeeRate(fee)
501
412
 
502
413
  let utxo1: ExtendedUtxo[] =
503
414
  extendedUtxo || (await this.btcInterface.getBTCUtxo(signer.address, signer))
504
415
  let utxo2: ExtendedUtxo[] = []
505
416
  const { inscribeAddress, inscribeDepositUnsignedInfo, inscribeUnsignedInfo } =
506
- await this.inscribeBrc20Unsigned(brc, signer, ordinalSignerInfo, utxo1, feeRate)
417
+ await this.inscribeBrc20Unsigned(brc, signer, ordinalSignerInfo, feeRate, utxo1)
507
418
 
508
419
  utxo2 = utxo1.filter(
509
420
  (u) =>
@@ -513,6 +424,9 @@ class OrdinalWallet extends BitcoinBaseWallet {
513
424
  )
514
425
 
515
426
  if (inscribeDepositUnsignedInfo.change) {
427
+ if (!inscribeDepositUnsignedInfo.possibleTxId) {
428
+ throw new Error("inscribeDepositUnsignedInfo.possibleTxId is required")
429
+ }
516
430
  utxo2.push({
517
431
  hash: inscribeDepositUnsignedInfo.possibleTxId,
518
432
  index: inscribeDepositUnsignedInfo.outputs.length,
@@ -529,8 +443,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
529
443
  },
530
444
  signer,
531
445
  ordinalSignerInfo,
532
- utxo2,
533
446
  feeRate,
447
+ utxo2,
534
448
  otherTargets,
535
449
  )
536
450
  return {
@@ -545,8 +459,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
545
459
  receiver: string,
546
460
  brc: { tick: string; amount: number | string },
547
461
  otherTargets?: Target[],
462
+ fee: FeeRateType = "normal",
548
463
  extendedUtxo?: ExtendedUtxo[],
549
- staticFeeRate?: number,
550
464
  ) {
551
465
  // check all fee before process transaction
552
466
  let brc20Balance = await this.unisat.getBrc20AddressBalanceForTicker(
@@ -573,9 +487,9 @@ class OrdinalWallet extends BitcoinBaseWallet {
573
487
  index: ins.utxo.vout!,
574
488
  value: ins.utxo.satoshi!,
575
489
  },
490
+ await this.getFeeRate(fee),
576
491
  extendedUtxo ||
577
492
  (await this.btcInterface.getBTCUtxo(this.bitcoinAddress!, this.signerInfo!)),
578
- staticFeeRate || (await this.btcInterface.getFeeRate("normal")),
579
493
  otherTargets,
580
494
  )
581
495
  return {
@@ -589,15 +503,15 @@ class OrdinalWallet extends BitcoinBaseWallet {
589
503
  throw new Error(`insufficient balance ${brc20Balance.availableBalanceSafe} ${brc.amount}`)
590
504
  }
591
505
 
592
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
506
+ let feeRate = await this.getFeeRate(fee)
593
507
 
594
508
  let utxo1: ExtendedUtxo[] =
595
509
  extendedUtxo || (await this.btcInterface.getBTCUtxo(this.bitcoinAddress!, this.signerInfo!))
596
510
  let utxo2: ExtendedUtxo[] = []
597
511
  const { inscribeAddress, inscribeDepositTx, inscribeTx } = await this.inscribeBrc20(
598
512
  brc,
599
- utxo1,
600
513
  feeRate,
514
+ utxo1,
601
515
  )
602
516
 
603
517
  utxo2 = utxo1.filter(
@@ -614,7 +528,7 @@ class OrdinalWallet extends BitcoinBaseWallet {
614
528
  })
615
529
  }
616
530
  await sleep(10 * 1000)
617
- let transferTx = await this.transferBrc20(receiver, inscribeTx, utxo2, feeRate, otherTargets)
531
+ let transferTx = await this.transferBrc20(receiver, inscribeTx, feeRate, utxo2, otherTargets)
618
532
  return {
619
533
  inscribeTx,
620
534
  inscribeAddress,
@@ -634,8 +548,9 @@ class OrdinalWallet extends BitcoinBaseWallet {
634
548
  outputAmount: string
635
549
  },
636
550
  ordinalSigner?: SignerInfo,
551
+ fee: FeeRateType = "normal",
637
552
  extendedUtxo?: ExtendedUtxo[],
638
- staticFeeRate?: number,
553
+
639
554
  { chainId = 137, appId = exchange ? 1 : 0 } = {},
640
555
  ) {
641
556
  const isExchange = !!exchange
@@ -656,8 +571,8 @@ class OrdinalWallet extends BitcoinBaseWallet {
656
571
  signer,
657
572
  ordinalSigner,
658
573
  [opTarget],
574
+ fee,
659
575
  extendedUtxo,
660
- staticFeeRate,
661
576
  )
662
577
  }
663
578
 
@@ -677,8 +592,9 @@ class OrdinalWallet extends BitcoinBaseWallet {
677
592
  outputAmount: string
678
593
  },
679
594
  ordinalSigner?: SignerInfo,
595
+ fee: FeeRateType = "normal",
680
596
  extendedUtxo?: ExtendedUtxo[],
681
- staticFeeRate?: number,
597
+
682
598
  { chainId = 137, appId = exchange ? 1 : 0 } = {},
683
599
  ) {
684
600
  let utxo: ExtendedUtxo[] =
@@ -696,14 +612,14 @@ class OrdinalWallet extends BitcoinBaseWallet {
696
612
  outputAmount: exchange?.outputAmount,
697
613
  })
698
614
  let opTarget = this.transactionBuilder.getOpReturnTarget(dataHex)
699
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
615
+ let feeRate = await this.getFeeRate(fee)
700
616
  let transferTxUnsignedInfo = await this.transferBrc20Unsigned(
701
617
  lockerAddress,
702
618
  brcInscribeTx,
703
619
  signer,
704
620
  ordinalSigner,
705
- utxo,
706
621
  feeRate,
622
+ utxo,
707
623
  [opTarget],
708
624
  )
709
625
  return transferTxUnsignedInfo
@@ -718,8 +634,9 @@ class OrdinalWallet extends BitcoinBaseWallet {
718
634
  outputToken: string
719
635
  outputAmount: string
720
636
  },
637
+ fee: FeeRateType = "normal",
721
638
  extendedUtxo?: ExtendedUtxo[],
722
- staticFeeRate?: number,
639
+
723
640
  { chainId = 137, appId = exchange ? 1 : 0 } = {},
724
641
  ) {
725
642
  const isExchange = !!exchange
@@ -735,13 +652,7 @@ class OrdinalWallet extends BitcoinBaseWallet {
735
652
  outputAmount: exchange?.outputAmount,
736
653
  })
737
654
  let opTarget = this.transactionBuilder.getOpReturnTarget(dataHex)
738
- return this.inscribeAndTransferBrc20(
739
- lockerAddress,
740
- brc,
741
- [opTarget],
742
- extendedUtxo,
743
- staticFeeRate,
744
- )
655
+ return this.inscribeAndTransferBrc20(lockerAddress, brc, [opTarget], fee, extendedUtxo)
745
656
  }
746
657
  }
747
658
 
@@ -1,10 +1,10 @@
1
- import { teleswap } from "@teleportdao/configs"
1
+ import { teleswap, chainInfo } from "@teleportdao/configs"
2
2
  import type {
3
3
  ExtendedUtxo,
4
4
  SignerInfo,
5
5
  TargetAddress,
6
6
  } from "./transaction-builder/transaction-builder"
7
- import { BitcoinBaseWallet } from "./bitcoin-wallet-base"
7
+ import { BitcoinBaseWallet, FeeRateType } from "./bitcoin-wallet-base"
8
8
  import { generateWrapOpReturn } from "./helper/teleswap-helper"
9
9
 
10
10
  export type TransferRequest = {
@@ -28,52 +28,71 @@ export type TransferRequest = {
28
28
  }
29
29
 
30
30
  export class TeleswapWallet extends BitcoinBaseWallet {
31
- // payment
32
- async sendToMultipleAddress(
33
- receivers: TargetAddress[],
34
- feeSpeed: "normal" | "fast" | "slow" = "normal",
31
+ // signed methods
32
+ async wrap(
33
+ recipientAddress: string,
34
+ amount: string,
35
+ networkFee: string,
36
+ lockerAddress: string,
37
+ chainId: number, // 80001
38
+ exchange?: {
39
+ outputToken: string
40
+ outputAmount: string
41
+ bridgePercentageFee?: number
42
+ },
43
+ appId = exchange
44
+ ? teleswap.requestAppId.WrapAndSwap.default
45
+ : teleswap.requestAppId.Wrap.default,
46
+ fee: FeeRateType = "normal",
47
+ thirdPartyId?: number,
48
+ staticExtendedUtxo?: ExtendedUtxo[],
49
+ changeAddress?: string,
50
+ fullAmount = false,
35
51
  ) {
36
52
  if (!this.signerInfo || !this.privateKey) {
37
53
  throw new Error("account not initialized")
38
54
  }
39
- let extendedUtxo = await this.getExtendedUtxo(this.signerInfo)
40
- let feeRate = await this.transactionBuilder._getFeeRate(feeSpeed)
41
- let unsignedTx = await this.transactionBuilder.processUnsignedTransaction({
42
- extendedUtxo,
43
- targets: receivers,
44
- changeAddress: this.currentAccount,
45
- feeRate,
46
- fullAmount: false,
47
- })
48
- let signedPsbt = await this.signer.signPsbt(unsignedTx, this.privateKey)
49
- let signedTx = this.signer.finalizePsbts([signedPsbt])
50
- let txId = await this.transactionBuilder.sendTx(signedTx)
51
- return txId
55
+ let unsignedTransaction = await this.wrapUnsigned(
56
+ recipientAddress,
57
+ amount,
58
+ networkFee,
59
+ lockerAddress,
60
+ chainId,
61
+ this.signerInfo,
62
+ exchange,
63
+ appId,
64
+ fee,
65
+ thirdPartyId,
66
+ staticExtendedUtxo,
67
+ changeAddress,
68
+ fullAmount,
69
+ )
70
+ let signedPsbt = await this.signer.signPsbt(unsignedTransaction, this.privateKey)
71
+ return this.sendSignedPsbt(signedPsbt)
52
72
  }
53
73
 
54
- // send
74
+ // unsigned methods
55
75
 
56
76
  async wrapUnsigned(
57
77
  recipientAddress: string,
58
78
  amount: string,
59
79
  networkFee: string,
60
- signer: SignerInfo,
61
80
  lockerAddress: string,
81
+ chainId: number, // 80001
82
+ signer: SignerInfo,
62
83
  exchange?: {
63
84
  outputToken: string
64
85
  outputAmount: string
65
86
  bridgePercentageFee?: number
66
87
  },
67
- {
68
- chainId = 137, // 80001
69
- appId = exchange
70
- ? teleswap.requestAppId.WrapAndSwap.default
71
- : teleswap.requestAppId.Wrap.default,
72
- } = {},
73
- fullAmount = false,
88
+ appId = exchange
89
+ ? teleswap.requestAppId.WrapAndSwap.default
90
+ : teleswap.requestAppId.Wrap.default,
91
+ fee: FeeRateType = "normal",
92
+ thirdPartyId?: number,
74
93
  staticExtendedUtxo?: ExtendedUtxo[],
75
- staticFeeRate?: number,
76
94
  changeAddress?: string,
95
+ fullAmount = false,
77
96
  ) {
78
97
  const dataHex = generateWrapOpReturn({
79
98
  chainId,
@@ -85,9 +104,10 @@ export class TeleswapWallet extends BitcoinBaseWallet {
85
104
  outputAmount: exchange?.outputAmount,
86
105
  outputToken: exchange?.outputToken,
87
106
  bridgePercentageFee: exchange?.bridgePercentageFee,
107
+ thirdPartyId,
88
108
  })
89
109
  let extendedUtxo = staticExtendedUtxo || (await this.getExtendedUtxo(signer))
90
- let feeRate = staticFeeRate || (await this.btcInterface.getFeeRate("normal"))
110
+ let feeRate = await this.getFeeRate(fee)
91
111
 
92
112
  const targets = fullAmount
93
113
  ? [this.transactionBuilder.getOpReturnTarget(dataHex)]
@@ -109,47 +129,5 @@ export class TeleswapWallet extends BitcoinBaseWallet {
109
129
 
110
130
  return unsignedTx
111
131
  }
112
-
113
- async wrap(
114
- recipientAddress: string,
115
- amount: string,
116
- networkFee: string,
117
- lockerAddress: string,
118
- exchange?: {
119
- outputToken: string
120
- outputAmount: string
121
- bridgePercentageFee?: number
122
- },
123
- {
124
- chainId = 137, // 80001
125
- appId = exchange ? 1 : 0,
126
- } = {},
127
- fullAmount = false,
128
- staticExtendedUtxo?: ExtendedUtxo[],
129
- staticFeeRate?: number,
130
- changeAddress?: string,
131
- ) {
132
- if (!this.signerInfo || !this.privateKey) {
133
- throw new Error("account not initialized")
134
- }
135
- let unsignedTransaction = await this.wrapUnsigned(
136
- recipientAddress,
137
- amount,
138
- networkFee,
139
- this.signerInfo,
140
- lockerAddress,
141
- exchange,
142
- {
143
- chainId,
144
- appId,
145
- },
146
- fullAmount,
147
- staticExtendedUtxo,
148
- staticFeeRate,
149
- changeAddress,
150
- )
151
- let signedPsbt = await this.signer.signPsbt(unsignedTransaction, this.privateKey)
152
- return this.sendSignedPsbt(signedPsbt)
153
- }
154
132
  }
155
133
  export default TeleswapWallet