@btc-vision/transaction 1.0.76 → 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.
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/metadata/contracts/wBTC.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +2 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/contracts/wBTC.d.ts +1 -1
- package/build/metadata/contracts/wBTC.js +11 -13
- package/build/metadata/tokens.js +3 -3
- package/build/transaction/TransactionFactory.js +3 -3
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/transaction/shared/TweakedTransaction.d.ts +2 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/metadata/contracts/wBTC.ts +60 -58
- package/src/metadata/tokens.ts +3 -3
- package/src/transaction/TransactionFactory.ts +496 -496
- package/src/transaction/interfaces/ITransactionParameters.ts +56 -56
- package/src/transaction/shared/TweakedTransaction.ts +539 -537
|
@@ -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 {
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.78";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
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
|
-
|
|
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
|
}
|
package/build/metadata/tokens.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ChainId } from '../network/ChainId.js';
|
|
2
|
-
export const FACTORY_ADDRESS_REGTEST = '
|
|
3
|
-
export const POOL_ADDRESS_REGTEST = '
|
|
2
|
+
export const FACTORY_ADDRESS_REGTEST = 'bcrt1qxtpreq8zg7pp9wm550kjrhaa2r5kj6lhph9he5';
|
|
3
|
+
export const POOL_ADDRESS_REGTEST = 'bcrt1qqg2a8076rwuruzetdyquj8fh5jxtc22pmh9vep';
|
|
4
4
|
export const WBTC_ADDRESS_REGTEST = 'bcrt1qdr7sjgtnudda8zrfklw8l5cnrxum5hns7e46hf';
|
|
5
5
|
export const MOTO_ADDRESS_REGTEST = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
6
|
-
export const ROUTER_ADDRESS_REGTEST = '
|
|
6
|
+
export const ROUTER_ADDRESS_REGTEST = 'bcrt1qplnz54sca73t8a03nh494jatr9ffjg6ecarrj8';
|
|
7
7
|
export const FACTORY_ADDRESS_TESTNET = 'tb1qgev5kldhp5zvg6j8t9vl6x4phkrwn8nk9felxh';
|
|
8
8
|
export const POOL_ADDRESS_TESTNET = 'tb1q6a7yw353hjmresphupytw5vczpqxtg4yrupayk';
|
|
9
9
|
export const WBTC_ADDRESS_TESTNET = 'tb1qp28xna6pv47x6wflcplhu0a9hkld5shtvjx6xv';
|
|
@@ -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
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
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(
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
case
|
|
53
|
-
return
|
|
54
|
-
|
|
55
|
-
|
|
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
|
+
}
|
package/src/metadata/tokens.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Address } from '@btc-vision/bsi-binary';
|
|
|
2
2
|
import { ChainId } from '../network/ChainId.js';
|
|
3
3
|
|
|
4
4
|
// Addresses Regtest
|
|
5
|
-
export const FACTORY_ADDRESS_REGTEST: Address = '
|
|
6
|
-
export const POOL_ADDRESS_REGTEST: Address = '
|
|
5
|
+
export const FACTORY_ADDRESS_REGTEST: Address = 'bcrt1qxtpreq8zg7pp9wm550kjrhaa2r5kj6lhph9he5';
|
|
6
|
+
export const POOL_ADDRESS_REGTEST: Address = 'bcrt1qqg2a8076rwuruzetdyquj8fh5jxtc22pmh9vep';
|
|
7
7
|
export const WBTC_ADDRESS_REGTEST: Address = 'bcrt1qdr7sjgtnudda8zrfklw8l5cnrxum5hns7e46hf';
|
|
8
8
|
export const MOTO_ADDRESS_REGTEST: Address = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
9
|
-
export const ROUTER_ADDRESS_REGTEST: Address = '
|
|
9
|
+
export const ROUTER_ADDRESS_REGTEST: Address = 'bcrt1qplnz54sca73t8a03nh494jatr9ffjg6ecarrj8';
|
|
10
10
|
|
|
11
11
|
// Addresses Testnet
|
|
12
12
|
export const FACTORY_ADDRESS_TESTNET: Address = 'tb1qgev5kldhp5zvg6j8t9vl6x4phkrwn8nk9felxh';
|