@btc-vision/transaction 1.0.55 → 1.0.57
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/tokens.d.ts +5 -0
- package/browser/transaction/TransactionFactory.d.ts +4 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/tokens.d.ts +5 -0
- package/build/metadata/tokens.js +5 -0
- package/build/transaction/TransactionFactory.d.ts +4 -1
- package/build/transaction/TransactionFactory.js +10 -0
- package/build/transaction/builders/UnwrapTransaction.js +8 -5
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/metadata/tokens.ts +8 -0
- package/src/transaction/TransactionFactory.ts +17 -1
- package/src/transaction/builders/UnwrapTransaction.ts +9 -7
- package/src/transaction/interfaces/ITransactionParameters.ts +1 -0
|
@@ -4,3 +4,8 @@ export declare const POOL_ADDRESS_REGTEST: Address;
|
|
|
4
4
|
export declare const WBTC_ADDRESS_REGTEST: Address;
|
|
5
5
|
export declare const MOTO_ADDRESS_REGTEST: Address;
|
|
6
6
|
export declare const ROUTER_ADDRESS_REGTEST: Address;
|
|
7
|
+
export declare const FACTORY_ADDRESS_TESTNET: Address;
|
|
8
|
+
export declare const POOL_ADDRESS_TESTNET: Address;
|
|
9
|
+
export declare const WBTC_ADDRESS_TESTNET: Address;
|
|
10
|
+
export declare const MOTO_ADDRESS_TESTNET: Address;
|
|
11
|
+
export declare const ROUTER_ADDRESS_TESTNET: Address;
|
|
@@ -5,23 +5,26 @@ export interface DeploymentResult {
|
|
|
5
5
|
readonly transaction: [string, string];
|
|
6
6
|
readonly contractAddress: Address;
|
|
7
7
|
readonly p2trAddress: Address;
|
|
8
|
+
readonly utxos: UTXO[];
|
|
8
9
|
}
|
|
9
10
|
export interface WrapResult {
|
|
10
11
|
readonly transaction: [string, string];
|
|
11
12
|
readonly vaultAddress: Address;
|
|
12
13
|
readonly amount: bigint;
|
|
13
14
|
readonly receiverAddress: Address;
|
|
15
|
+
readonly utxos: UTXO[];
|
|
14
16
|
}
|
|
15
17
|
export interface UnwrapResult {
|
|
16
18
|
readonly fundingTransaction: string;
|
|
17
19
|
readonly psbt: string;
|
|
18
20
|
readonly feeRefundOrLoss: bigint;
|
|
21
|
+
readonly utxos: UTXO[];
|
|
19
22
|
}
|
|
20
23
|
export declare class TransactionFactory {
|
|
21
24
|
constructor();
|
|
22
25
|
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
23
26
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
24
|
-
wrap(warpParameters: IWrapParameters): Promise<WrapResult>;
|
|
27
|
+
wrap(warpParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
25
28
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
26
29
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
27
30
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<{
|
|
@@ -27,6 +27,7 @@ export interface IInteractionParameters extends SharedInteractionParameters {
|
|
|
27
27
|
}
|
|
28
28
|
export interface IWrapParameters extends SharedInteractionParameters {
|
|
29
29
|
readonly to?: undefined;
|
|
30
|
+
readonly from: Address;
|
|
30
31
|
readonly amount: bigint;
|
|
31
32
|
readonly receiver?: Address;
|
|
32
33
|
readonly generationParameters: WrappedGeneration;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.57";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.57';
|
|
@@ -4,3 +4,8 @@ export declare const POOL_ADDRESS_REGTEST: Address;
|
|
|
4
4
|
export declare const WBTC_ADDRESS_REGTEST: Address;
|
|
5
5
|
export declare const MOTO_ADDRESS_REGTEST: Address;
|
|
6
6
|
export declare const ROUTER_ADDRESS_REGTEST: Address;
|
|
7
|
+
export declare const FACTORY_ADDRESS_TESTNET: Address;
|
|
8
|
+
export declare const POOL_ADDRESS_TESTNET: Address;
|
|
9
|
+
export declare const WBTC_ADDRESS_TESTNET: Address;
|
|
10
|
+
export declare const MOTO_ADDRESS_TESTNET: Address;
|
|
11
|
+
export declare const ROUTER_ADDRESS_TESTNET: Address;
|
package/build/metadata/tokens.js
CHANGED
|
@@ -3,3 +3,8 @@ export const POOL_ADDRESS_REGTEST = 'bcrt1q5nkjpjmh6xwweprcyeylwdw7aud4een7p9pph
|
|
|
3
3
|
export const WBTC_ADDRESS_REGTEST = 'bcrt1qefq0lwqwpt5lx7hl2dr2r8q6z063725tccuqrg';
|
|
4
4
|
export const MOTO_ADDRESS_REGTEST = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
5
5
|
export const ROUTER_ADDRESS_REGTEST = 'bcrt1qyx492l440f6cm5hdppw5pmkd2fc7k3qayuuvh6';
|
|
6
|
+
export const FACTORY_ADDRESS_TESTNET = 'tb1qa7esg7wal50c287uec0qf6yztr5qaldgmr8lr8';
|
|
7
|
+
export const POOL_ADDRESS_TESTNET = 'tb1q0gua4akdw4jmu5wsat6xf8ll0xa0dyjdwqwcax';
|
|
8
|
+
export const WBTC_ADDRESS_TESTNET = 'tb1ql2lya5u0tv7zvy2rqvvr5qjmlfyw3j8jjvsj0u';
|
|
9
|
+
export const MOTO_ADDRESS_TESTNET = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw';
|
|
10
|
+
export const ROUTER_ADDRESS_TESTNET = 'tb1qzyn09v5s5ujpm5zlcqqdz6wjc67qk9sv2wzka9';
|
|
@@ -5,23 +5,26 @@ export interface DeploymentResult {
|
|
|
5
5
|
readonly transaction: [string, string];
|
|
6
6
|
readonly contractAddress: Address;
|
|
7
7
|
readonly p2trAddress: Address;
|
|
8
|
+
readonly utxos: UTXO[];
|
|
8
9
|
}
|
|
9
10
|
export interface WrapResult {
|
|
10
11
|
readonly transaction: [string, string];
|
|
11
12
|
readonly vaultAddress: Address;
|
|
12
13
|
readonly amount: bigint;
|
|
13
14
|
readonly receiverAddress: Address;
|
|
15
|
+
readonly utxos: UTXO[];
|
|
14
16
|
}
|
|
15
17
|
export interface UnwrapResult {
|
|
16
18
|
readonly fundingTransaction: string;
|
|
17
19
|
readonly psbt: string;
|
|
18
20
|
readonly feeRefundOrLoss: bigint;
|
|
21
|
+
readonly utxos: UTXO[];
|
|
19
22
|
}
|
|
20
23
|
export declare class TransactionFactory {
|
|
21
24
|
constructor();
|
|
22
25
|
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
23
26
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
24
|
-
wrap(warpParameters: IWrapParameters): Promise<WrapResult>;
|
|
27
|
+
wrap(warpParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
25
28
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
26
29
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
27
30
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<{
|
|
@@ -80,6 +80,10 @@ export class TransactionFactory {
|
|
|
80
80
|
transaction: [signedTransaction.toHex(), outTx.toHex()],
|
|
81
81
|
contractAddress: finalTransaction.contractAddress,
|
|
82
82
|
p2trAddress: finalTransaction.p2trAddress,
|
|
83
|
+
utxos: [{
|
|
84
|
+
...newUtxo,
|
|
85
|
+
outputIndex: 1,
|
|
86
|
+
}],
|
|
83
87
|
};
|
|
84
88
|
}
|
|
85
89
|
async wrap(warpParameters) {
|
|
@@ -118,6 +122,7 @@ export class TransactionFactory {
|
|
|
118
122
|
vaultAddress: finalTransaction.vault,
|
|
119
123
|
amount: finalTransaction.amount,
|
|
120
124
|
receiverAddress: finalTransaction.receiver,
|
|
125
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, warpParameters.from, 1),
|
|
121
126
|
};
|
|
122
127
|
}
|
|
123
128
|
async unwrapSegwit(unwrapParameters) {
|
|
@@ -162,9 +167,13 @@ export class TransactionFactory {
|
|
|
162
167
|
fundingTransaction: signedTransaction.tx.toHex(),
|
|
163
168
|
psbt: psbt,
|
|
164
169
|
feeRefundOrLoss: estimatedFees,
|
|
170
|
+
utxos: []
|
|
165
171
|
};
|
|
166
172
|
}
|
|
167
173
|
async unwrap(unwrapParameters) {
|
|
174
|
+
if (!unwrapParameters.from) {
|
|
175
|
+
throw new Error('Field "from" not provided.');
|
|
176
|
+
}
|
|
168
177
|
const transaction = new UnwrapTransaction(unwrapParameters);
|
|
169
178
|
await transaction.signTransaction();
|
|
170
179
|
const to = transaction.toAddress();
|
|
@@ -204,6 +213,7 @@ export class TransactionFactory {
|
|
|
204
213
|
fundingTransaction: signedTransaction.tx.toHex(),
|
|
205
214
|
psbt: psbt,
|
|
206
215
|
feeRefundOrLoss: finalTransaction.getFeeLossOrRefund(),
|
|
216
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, unwrapParameters.from, 1),
|
|
207
217
|
};
|
|
208
218
|
}
|
|
209
219
|
async createBTCTransfer(parameters) {
|
|
@@ -83,17 +83,20 @@ export class UnwrapTransaction extends SharedInteractionTransaction {
|
|
|
83
83
|
return refund - this.estimatedFeeLoss;
|
|
84
84
|
}
|
|
85
85
|
mergeVaults() {
|
|
86
|
-
const refund = this.getRefund();
|
|
87
86
|
const totalInputAmount = this.getVaultTotalOutputAmount(this.vaultUTXOs);
|
|
88
|
-
|
|
87
|
+
let refund = this.getRefund();
|
|
88
|
+
let outputLeftAmount = totalInputAmount - refund - this.amount;
|
|
89
|
+
if (outputLeftAmount === currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT) {
|
|
90
|
+
refund += currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
|
|
91
|
+
}
|
|
92
|
+
else if (outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
93
|
+
throw new Error(`Output left amount is below the minimum amount: ${outputLeftAmount} below ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}`);
|
|
94
|
+
}
|
|
89
95
|
const outAmount = this.amount + refund - this.estimatedFeeLoss;
|
|
90
96
|
const bestVault = BitcoinUtils.findVaultWithMostPublicKeys(this.vaultUTXOs);
|
|
91
97
|
if (!bestVault) {
|
|
92
98
|
throw new Error('No vaults provided');
|
|
93
99
|
}
|
|
94
|
-
if (outputLeftAmount !== 0n && outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
95
|
-
throw new Error(`Output left amount is below the minimum amount: ${outputLeftAmount} below ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}`);
|
|
96
|
-
}
|
|
97
100
|
let hasConsolidation = outputLeftAmount > currentConsensusConfig.VAULT_MINIMUM_AMOUNT &&
|
|
98
101
|
outputLeftAmount - currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT !== 0n;
|
|
99
102
|
if (hasConsolidation) {
|
|
@@ -27,6 +27,7 @@ export interface IInteractionParameters extends SharedInteractionParameters {
|
|
|
27
27
|
}
|
|
28
28
|
export interface IWrapParameters extends SharedInteractionParameters {
|
|
29
29
|
readonly to?: undefined;
|
|
30
|
+
readonly from: Address;
|
|
30
31
|
readonly amount: bigint;
|
|
31
32
|
readonly receiver?: Address;
|
|
32
33
|
readonly generationParameters: WrappedGeneration;
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.57';
|
package/src/metadata/tokens.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
2
|
|
|
3
|
+
// Addresses Regtest
|
|
3
4
|
export const FACTORY_ADDRESS_REGTEST: Address = 'bcrt1qgph2k9dahptnz2vu72ezd9r2p4phjm2pkgu7ht';
|
|
4
5
|
export const POOL_ADDRESS_REGTEST: Address = 'bcrt1q5nkjpjmh6xwweprcyeylwdw7aud4een7p9pphd';
|
|
5
6
|
export const WBTC_ADDRESS_REGTEST: Address = 'bcrt1qefq0lwqwpt5lx7hl2dr2r8q6z063725tccuqrg';
|
|
6
7
|
export const MOTO_ADDRESS_REGTEST: Address = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
7
8
|
export const ROUTER_ADDRESS_REGTEST: Address = 'bcrt1qyx492l440f6cm5hdppw5pmkd2fc7k3qayuuvh6';
|
|
9
|
+
|
|
10
|
+
// Addresses Testnet
|
|
11
|
+
export const FACTORY_ADDRESS_TESTNET: Address = 'tb1qa7esg7wal50c287uec0qf6yztr5qaldgmr8lr8';
|
|
12
|
+
export const POOL_ADDRESS_TESTNET: Address = 'tb1q0gua4akdw4jmu5wsat6xf8ll0xa0dyjdwqwcax';
|
|
13
|
+
export const WBTC_ADDRESS_TESTNET: Address = 'tb1ql2lya5u0tv7zvy2rqvvr5qjmlfyw3j8jjvsj0u';
|
|
14
|
+
export const MOTO_ADDRESS_TESTNET: Address = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw';
|
|
15
|
+
export const ROUTER_ADDRESS_TESTNET: Address = 'tb1qzyn09v5s5ujpm5zlcqqdz6wjc67qk9sv2wzka9';
|
|
@@ -25,6 +25,8 @@ export interface DeploymentResult {
|
|
|
25
25
|
|
|
26
26
|
readonly contractAddress: Address;
|
|
27
27
|
readonly p2trAddress: Address;
|
|
28
|
+
|
|
29
|
+
readonly utxos: UTXO[];
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
export interface WrapResult {
|
|
@@ -32,6 +34,7 @@ export interface WrapResult {
|
|
|
32
34
|
readonly vaultAddress: Address;
|
|
33
35
|
readonly amount: bigint;
|
|
34
36
|
readonly receiverAddress: Address;
|
|
37
|
+
readonly utxos: UTXO[];
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
export interface UnwrapResult {
|
|
@@ -45,6 +48,8 @@ export interface UnwrapResult {
|
|
|
45
48
|
* @type {bigint}
|
|
46
49
|
*/
|
|
47
50
|
readonly feeRefundOrLoss: bigint;
|
|
51
|
+
|
|
52
|
+
readonly utxos: UTXO[];
|
|
48
53
|
}
|
|
49
54
|
|
|
50
55
|
export class TransactionFactory {
|
|
@@ -169,6 +174,10 @@ export class TransactionFactory {
|
|
|
169
174
|
transaction: [signedTransaction.toHex(), outTx.toHex()],
|
|
170
175
|
contractAddress: finalTransaction.contractAddress,
|
|
171
176
|
p2trAddress: finalTransaction.p2trAddress,
|
|
177
|
+
utxos: [{
|
|
178
|
+
...newUtxo,
|
|
179
|
+
outputIndex: 1, // always 1
|
|
180
|
+
}],
|
|
172
181
|
};
|
|
173
182
|
}
|
|
174
183
|
|
|
@@ -178,7 +187,7 @@ export class TransactionFactory {
|
|
|
178
187
|
* @returns {Promise<WrapResult>} - The signed transaction
|
|
179
188
|
* @throws {Error} - If the transaction could not be signed
|
|
180
189
|
*/
|
|
181
|
-
public async wrap(warpParameters: IWrapParameters): Promise<WrapResult> {
|
|
190
|
+
public async wrap(warpParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult> {
|
|
182
191
|
if (warpParameters.amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
183
192
|
throw new Error(
|
|
184
193
|
`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.`,
|
|
@@ -232,6 +241,7 @@ export class TransactionFactory {
|
|
|
232
241
|
vaultAddress: finalTransaction.vault,
|
|
233
242
|
amount: finalTransaction.amount,
|
|
234
243
|
receiverAddress: finalTransaction.receiver,
|
|
244
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, warpParameters.from, 1),
|
|
235
245
|
};
|
|
236
246
|
}
|
|
237
247
|
|
|
@@ -307,6 +317,7 @@ export class TransactionFactory {
|
|
|
307
317
|
fundingTransaction: signedTransaction.tx.toHex(),
|
|
308
318
|
psbt: psbt,
|
|
309
319
|
feeRefundOrLoss: estimatedFees,
|
|
320
|
+
utxos: []
|
|
310
321
|
};
|
|
311
322
|
}
|
|
312
323
|
|
|
@@ -317,6 +328,10 @@ export class TransactionFactory {
|
|
|
317
328
|
* @throws {Error} - If the transaction could not be signed
|
|
318
329
|
*/
|
|
319
330
|
public async unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult> {
|
|
331
|
+
if(!unwrapParameters.from) {
|
|
332
|
+
throw new Error('Field "from" not provided.');
|
|
333
|
+
}
|
|
334
|
+
|
|
320
335
|
const transaction: UnwrapTransaction = new UnwrapTransaction(unwrapParameters);
|
|
321
336
|
await transaction.signTransaction();
|
|
322
337
|
|
|
@@ -371,6 +386,7 @@ export class TransactionFactory {
|
|
|
371
386
|
fundingTransaction: signedTransaction.tx.toHex(),
|
|
372
387
|
psbt: psbt,
|
|
373
388
|
feeRefundOrLoss: finalTransaction.getFeeLossOrRefund(),
|
|
389
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, unwrapParameters.from, 1),
|
|
374
390
|
};
|
|
375
391
|
}
|
|
376
392
|
|
|
@@ -216,21 +216,23 @@ export class UnwrapTransaction extends SharedInteractionTransaction<TransactionT
|
|
|
216
216
|
* @protected
|
|
217
217
|
*/
|
|
218
218
|
protected mergeVaults(): void {
|
|
219
|
-
const refund: bigint = this.getRefund();
|
|
220
219
|
const totalInputAmount: bigint = this.getVaultTotalOutputAmount(this.vaultUTXOs);
|
|
221
|
-
const outputLeftAmount = totalInputAmount - refund - this.amount;
|
|
222
220
|
|
|
223
|
-
|
|
221
|
+
let refund: bigint = this.getRefund();
|
|
222
|
+
let outputLeftAmount = totalInputAmount - refund - this.amount;
|
|
223
|
+
|
|
224
|
+
if(outputLeftAmount === currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT) {
|
|
225
|
+
refund += currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT;
|
|
226
|
+
} else if (outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
227
|
+
throw new Error(`Output left amount is below the minimum amount: ${outputLeftAmount} below ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}`);
|
|
228
|
+
}
|
|
224
229
|
|
|
230
|
+
const outAmount: bigint = this.amount + refund - this.estimatedFeeLoss;
|
|
225
231
|
const bestVault = BitcoinUtils.findVaultWithMostPublicKeys(this.vaultUTXOs);
|
|
226
232
|
if (!bestVault) {
|
|
227
233
|
throw new Error('No vaults provided');
|
|
228
234
|
}
|
|
229
235
|
|
|
230
|
-
if (outputLeftAmount !== 0n && outputLeftAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
231
|
-
throw new Error(`Output left amount is below the minimum amount: ${outputLeftAmount} below ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT}`);
|
|
232
|
-
}
|
|
233
|
-
|
|
234
236
|
let hasConsolidation: boolean =
|
|
235
237
|
outputLeftAmount > currentConsensusConfig.VAULT_MINIMUM_AMOUNT &&
|
|
236
238
|
outputLeftAmount - currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT !== 0n;
|
|
@@ -36,6 +36,7 @@ export interface IInteractionParameters extends SharedInteractionParameters {
|
|
|
36
36
|
export interface IWrapParameters extends SharedInteractionParameters {
|
|
37
37
|
readonly to?: undefined;
|
|
38
38
|
|
|
39
|
+
readonly from: Address;
|
|
39
40
|
readonly amount: bigint;
|
|
40
41
|
readonly receiver?: Address;
|
|
41
42
|
|