@btc-vision/transaction 1.0.77 → 1.0.78

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.
@@ -9,6 +9,6 @@ export declare class wBTC extends ContractBaseMetadata {
9
9
  readonly decimals: number;
10
10
  protected readonly address: Address;
11
11
  constructor(network?: Network, chainId?: ChainId);
12
- private static getWBTCAddressForChain;
13
12
  static getAddress(network?: Network, chainId?: ChainId): Address;
13
+ private static getWBTCAddressForChain;
14
14
  }
@@ -26,7 +26,7 @@ export interface IInteractionParameters extends SharedInteractionParameters {
26
26
  readonly to: Address;
27
27
  }
28
28
  export interface IWrapParameters extends SharedInteractionParameters {
29
- readonly to?: undefined;
29
+ readonly to?: undefined | Address;
30
30
  readonly from: Address;
31
31
  readonly amount: bigint;
32
32
  readonly receiver?: Address;
@@ -4,9 +4,11 @@ import { Network, Payment, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
4
4
  import { PsbtInput } from 'bip174/src/lib/interfaces.js';
5
5
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
6
6
  import { PsbtInputExtended, TapLeafScript } from '../interfaces/Tap.js';
7
+ import { ChainId } from '../../network/ChainId.js';
7
8
  export interface ITweakedTransactionData {
8
9
  readonly signer: Signer;
9
10
  readonly network: Network;
11
+ readonly chainId?: ChainId;
10
12
  readonly nonWitnessUtxo?: Buffer;
11
13
  }
12
14
  export declare enum TransactionSequence {
@@ -1 +1 @@
1
- export declare const version = "1.0.77";
1
+ export declare const version = "1.0.78";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.77';
1
+ export const version = '1.0.78';
@@ -9,6 +9,6 @@ export declare class wBTC extends ContractBaseMetadata {
9
9
  readonly decimals: number;
10
10
  protected readonly address: Address;
11
11
  constructor(network?: Network, chainId?: ChainId);
12
- private static getWBTCAddressForChain;
13
12
  static getAddress(network?: Network, chainId?: ChainId): Address;
13
+ private static getWBTCAddressForChain;
14
14
  }
@@ -13,22 +13,10 @@ export class wBTC extends ContractBaseMetadata {
13
13
  this.network = network;
14
14
  this.address = wBTC.getAddress(network, chainId);
15
15
  }
16
- static getWBTCAddressForChain(chainId) {
17
- switch (chainId) {
18
- case ChainId.Bitcoin:
19
- return 'unknown';
20
- case ChainId.Fractal:
21
- return WBTC_ADDRESS_FRACTAL;
22
- default:
23
- throw new Error(`Invalid chainId: ${chainId}`);
24
- }
25
- }
26
16
  static getAddress(network = networks.bitcoin, chainId) {
27
17
  switch (network.bech32) {
28
18
  case networks.bitcoin.bech32:
29
- if (chainId)
30
- return this.getWBTCAddressForChain(chainId);
31
- return 'unknown';
19
+ return this.getWBTCAddressForChain(chainId ?? ChainId.Bitcoin);
32
20
  case networks.regtest.bech32:
33
21
  return WBTC_ADDRESS_REGTEST;
34
22
  case networks.testnet.bech32:
@@ -37,4 +25,14 @@ export class wBTC extends ContractBaseMetadata {
37
25
  throw new Error(`Invalid network: ${network}`);
38
26
  }
39
27
  }
28
+ static getWBTCAddressForChain(chainId) {
29
+ switch (chainId) {
30
+ case ChainId.Bitcoin:
31
+ return 'unknown';
32
+ case ChainId.Fractal:
33
+ return WBTC_ADDRESS_FRACTAL;
34
+ default:
35
+ throw new Error(`Invalid chainId: ${chainId}`);
36
+ }
37
+ }
40
38
  }
@@ -98,12 +98,12 @@ export class TransactionFactory {
98
98
  throw new Error(`Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${warpParameters.amount} sat. Make sure that you cover the unwrap consolidation fees of ${currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT}sat.`);
99
99
  }
100
100
  const childTransactionRequiredValue = warpParameters.amount + currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
101
- const wbtc = new wBTC(warpParameters.network);
101
+ const wbtc = new wBTC(warpParameters.network, warpParameters.chainId);
102
102
  const to = wbtc.getAddress();
103
103
  const fundingParameters = {
104
104
  ...warpParameters,
105
105
  amount: childTransactionRequiredValue,
106
- to: to,
106
+ to: warpParameters.to ?? to,
107
107
  };
108
108
  const preFundingTransaction = await this.createFundTransaction(fundingParameters);
109
109
  warpParameters.utxos = this.getUTXOAsTransaction(preFundingTransaction.tx, to, 0);
@@ -174,7 +174,7 @@ export class TransactionFactory {
174
174
  fundingTransaction: signedTransaction.tx.toHex(),
175
175
  psbt: psbt,
176
176
  feeRefundOrLoss: estimatedFees,
177
- utxos: []
177
+ utxos: [],
178
178
  };
179
179
  }
180
180
  async unwrap(unwrapParameters) {
@@ -26,7 +26,7 @@ export interface IInteractionParameters extends SharedInteractionParameters {
26
26
  readonly to: Address;
27
27
  }
28
28
  export interface IWrapParameters extends SharedInteractionParameters {
29
- readonly to?: undefined;
29
+ readonly to?: undefined | Address;
30
30
  readonly from: Address;
31
31
  readonly amount: bigint;
32
32
  readonly receiver?: Address;
@@ -4,9 +4,11 @@ import { Network, Payment, Psbt, Signer, Transaction } from 'bitcoinjs-lib';
4
4
  import { PsbtInput } from 'bip174/src/lib/interfaces.js';
5
5
  import { UTXO } from '../../utxo/interfaces/IUTXO.js';
6
6
  import { PsbtInputExtended, TapLeafScript } from '../interfaces/Tap.js';
7
+ import { ChainId } from '../../network/ChainId.js';
7
8
  export interface ITweakedTransactionData {
8
9
  readonly signer: Signer;
9
10
  readonly network: Network;
11
+ readonly chainId?: ChainId;
10
12
  readonly nonWitnessUtxo?: Buffer;
11
13
  }
12
14
  export declare enum TransactionSequence {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "author": "BlobMaster41",
5
5
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
6
6
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.77';
1
+ export const version = '1.0.78';
@@ -1,58 +1,60 @@
1
- import { Network, networks } from 'bitcoinjs-lib';
2
- import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
3
- import { Address } from '@btc-vision/bsi-binary';
4
- import { WBTC_ADDRESS_FRACTAL, WBTC_ADDRESS_REGTEST, WBTC_ADDRESS_TESTNET } from '../tokens.js';
5
- import { ChainId } from '../../network/ChainId.js';
6
-
7
- /**
8
- * @description Wrapped Bitcoin (wBTC) contract metadata.
9
- * */
10
- export class wBTC extends ContractBaseMetadata {
11
- /**
12
- * @description Token Name
13
- */
14
- public readonly tokenName: string = 'Wrapped Bitcoin';
15
-
16
- /**
17
- * @description Token Symbol
18
- */
19
- public readonly tokenSymbol: string = 'wBTC';
20
-
21
- /**
22
- * @description Token Decimals, same as Bitcoin
23
- */
24
- public readonly decimals: number = 8;
25
-
26
- protected readonly address: Address;
27
-
28
- constructor(protected network: Network = networks.bitcoin, chainId: ChainId = ChainId.Bitcoin) {
29
- super(network);
30
-
31
- this.address = wBTC.getAddress(network, chainId);
32
- }
33
-
34
- private static getWBTCAddressForChain(chainId: ChainId): Address {
35
- switch (chainId) {
36
- case ChainId.Bitcoin:
37
- return 'unknown';
38
- case ChainId.Fractal:
39
- return WBTC_ADDRESS_FRACTAL;
40
- default:
41
- throw new Error(`Invalid chainId: ${chainId}`);
42
- }
43
- }
44
-
45
- public static getAddress(network: Network = networks.bitcoin, chainId?: ChainId): Address {
46
- switch (network.bech32) {
47
- case networks.bitcoin.bech32:
48
- if(chainId) return this.getWBTCAddressForChain(chainId);
49
- return 'unknown';
50
- case networks.regtest.bech32:
51
- return WBTC_ADDRESS_REGTEST;
52
- case networks.testnet.bech32:
53
- return WBTC_ADDRESS_TESTNET;
54
- default:
55
- throw new Error(`Invalid network: ${network}`);
56
- }
57
- }
58
- }
1
+ import { Network, networks } from 'bitcoinjs-lib';
2
+ import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
3
+ import { Address } from '@btc-vision/bsi-binary';
4
+ import { WBTC_ADDRESS_FRACTAL, WBTC_ADDRESS_REGTEST, WBTC_ADDRESS_TESTNET } from '../tokens.js';
5
+ import { ChainId } from '../../network/ChainId.js';
6
+
7
+ /**
8
+ * @description Wrapped Bitcoin (wBTC) contract metadata.
9
+ * */
10
+ export class wBTC extends ContractBaseMetadata {
11
+ /**
12
+ * @description Token Name
13
+ */
14
+ public readonly tokenName: string = 'Wrapped Bitcoin';
15
+
16
+ /**
17
+ * @description Token Symbol
18
+ */
19
+ public readonly tokenSymbol: string = 'wBTC';
20
+
21
+ /**
22
+ * @description Token Decimals, same as Bitcoin
23
+ */
24
+ public readonly decimals: number = 8;
25
+
26
+ protected readonly address: Address;
27
+
28
+ constructor(
29
+ protected network: Network = networks.bitcoin,
30
+ chainId: ChainId = ChainId.Bitcoin,
31
+ ) {
32
+ super(network);
33
+
34
+ this.address = wBTC.getAddress(network, chainId);
35
+ }
36
+
37
+ public static getAddress(network: Network = networks.bitcoin, chainId?: ChainId): Address {
38
+ switch (network.bech32) {
39
+ case networks.bitcoin.bech32:
40
+ return this.getWBTCAddressForChain(chainId ?? ChainId.Bitcoin);
41
+ case networks.regtest.bech32:
42
+ return WBTC_ADDRESS_REGTEST;
43
+ case networks.testnet.bech32:
44
+ return WBTC_ADDRESS_TESTNET;
45
+ default:
46
+ throw new Error(`Invalid network: ${network}`);
47
+ }
48
+ }
49
+
50
+ private static getWBTCAddressForChain(chainId: ChainId): Address {
51
+ switch (chainId) {
52
+ case ChainId.Bitcoin:
53
+ return 'unknown';
54
+ case ChainId.Fractal:
55
+ return WBTC_ADDRESS_FRACTAL;
56
+ default:
57
+ throw new Error(`Invalid chainId: ${chainId}`);
58
+ }
59
+ }
60
+ }