@btc-vision/transaction 1.0.108 → 1.0.109
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/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +1 -0
- package/build/transaction/TransactionFactory.d.ts +1 -0
- package/build/transaction/TransactionFactory.js +15 -5
- package/build/transaction/builders/FundingTransaction.js +3 -12
- package/package.json +1 -1
- package/src/transaction/TransactionFactory.ts +19 -6
- package/src/transaction/builders/FundingTransaction.ts +3 -12
- package/src/transaction/builders/TransactionBuilder.ts +1 -1
|
@@ -4,6 +4,7 @@ import { CustomScriptTransaction, } from './builders/CustomScriptTransaction.js'
|
|
|
4
4
|
import { DeploymentTransaction } from './builders/DeploymentTransaction.js';
|
|
5
5
|
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
6
6
|
import { InteractionTransaction } from './builders/InteractionTransaction.js';
|
|
7
|
+
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
7
8
|
import { UnwrapSegwitTransaction } from './builders/UnwrapSegwitTransaction.js';
|
|
8
9
|
import { UnwrapTransaction } from './builders/UnwrapTransaction.js';
|
|
9
10
|
import { WrapTransaction } from './builders/WrapTransaction.js';
|
|
@@ -24,7 +25,8 @@ export class TransactionFactory {
|
|
|
24
25
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
25
26
|
parameters.utxos = interactionParameters.utxos;
|
|
26
27
|
parameters.amount =
|
|
27
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
28
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
29
|
+
this.getPriorityFee(interactionParameters);
|
|
28
30
|
const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
|
|
29
31
|
if (!feeEstimationFundingTransaction) {
|
|
30
32
|
throw new Error('Could not sign funding transaction.');
|
|
@@ -65,7 +67,8 @@ export class TransactionFactory {
|
|
|
65
67
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
66
68
|
parameters.utxos = interactionParameters.utxos;
|
|
67
69
|
parameters.amount =
|
|
68
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
70
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
71
|
+
this.getPriorityFee(interactionParameters);
|
|
69
72
|
const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
|
|
70
73
|
if (!feeEstimationFundingTransaction) {
|
|
71
74
|
throw new Error('Could not sign funding transaction.');
|
|
@@ -115,7 +118,7 @@ export class TransactionFactory {
|
|
|
115
118
|
utxos: [newUtxo],
|
|
116
119
|
randomBytes: preTransaction.getRndBytes(),
|
|
117
120
|
nonWitnessUtxo: signedTransaction.toBuffer(),
|
|
118
|
-
optionalOutputs: []
|
|
121
|
+
optionalOutputs: [],
|
|
119
122
|
};
|
|
120
123
|
const finalTransaction = new DeploymentTransaction(newParams);
|
|
121
124
|
const outTx = await finalTransaction.signTransaction();
|
|
@@ -142,7 +145,7 @@ export class TransactionFactory {
|
|
|
142
145
|
}
|
|
143
146
|
const childTransactionRequiredValue = wrapParameters.amount +
|
|
144
147
|
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT +
|
|
145
|
-
(wrapParameters
|
|
148
|
+
this.getPriorityFee(wrapParameters);
|
|
146
149
|
const wbtc = new wBTC(wrapParameters.network, wrapParameters.chainId);
|
|
147
150
|
const to = wbtc.getAddress();
|
|
148
151
|
const fundingParameters = {
|
|
@@ -247,7 +250,8 @@ export class TransactionFactory {
|
|
|
247
250
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
248
251
|
parameters.utxos = fundingParameters.utxos;
|
|
249
252
|
parameters.amount =
|
|
250
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
253
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
254
|
+
this.getPriorityFee(unwrapParameters);
|
|
251
255
|
const signedTransaction = await this.createFundTransaction(parameters);
|
|
252
256
|
if (!signedTransaction) {
|
|
253
257
|
throw new Error('Could not sign funding transaction.');
|
|
@@ -340,6 +344,12 @@ export class TransactionFactory {
|
|
|
340
344
|
header.writeUInt8(currentConsensus, 1);
|
|
341
345
|
return Buffer.concat([header, buf]).toString('hex');
|
|
342
346
|
}
|
|
347
|
+
getPriorityFee(params) {
|
|
348
|
+
if (params.priorityFee < TransactionBuilder.MINIMUM_DUST) {
|
|
349
|
+
return TransactionBuilder.MINIMUM_DUST;
|
|
350
|
+
}
|
|
351
|
+
return params.priorityFee;
|
|
352
|
+
}
|
|
343
353
|
getUTXOAsTransaction(tx, to, index) {
|
|
344
354
|
if (!tx.outs[index])
|
|
345
355
|
return [];
|
|
@@ -13,25 +13,16 @@ export class FundingTransaction extends TransactionBuilder {
|
|
|
13
13
|
throw new Error('Recipient address is required');
|
|
14
14
|
}
|
|
15
15
|
this.addInputsFromUTXO();
|
|
16
|
-
let amountSpent = this.amount;
|
|
17
|
-
if (this.getTransactionOPNetFee() === TransactionBuilder.MINIMUM_DUST) {
|
|
18
|
-
if (amountSpent < TransactionBuilder.MINIMUM_DUST) {
|
|
19
|
-
amountSpent += TransactionBuilder.MINIMUM_DUST;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
amountSpent += this.getTransactionOPNetFee();
|
|
24
|
-
}
|
|
25
16
|
if (this.splitInputsInto > 1) {
|
|
26
|
-
this.splitInputs(
|
|
17
|
+
this.splitInputs(this.amount);
|
|
27
18
|
}
|
|
28
19
|
else {
|
|
29
20
|
this.addOutput({
|
|
30
|
-
value: Number(
|
|
21
|
+
value: Number(this.amount),
|
|
31
22
|
address: this.to,
|
|
32
23
|
});
|
|
33
24
|
}
|
|
34
|
-
await this.addRefundOutput(
|
|
25
|
+
await this.addRefundOutput(this.amount);
|
|
35
26
|
}
|
|
36
27
|
splitInputs(amountSpent) {
|
|
37
28
|
if (!this.to) {
|
package/package.json
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
IDeploymentParameters,
|
|
21
21
|
IFundingTransactionParameters,
|
|
22
22
|
IInteractionParameters,
|
|
23
|
+
ITransactionParameters,
|
|
23
24
|
IUnwrapParameters,
|
|
24
25
|
IWrapParameters,
|
|
25
26
|
} from './interfaces/ITransactionParameters.js';
|
|
@@ -102,7 +103,8 @@ export class TransactionFactory {
|
|
|
102
103
|
|
|
103
104
|
parameters.utxos = interactionParameters.utxos;
|
|
104
105
|
parameters.amount =
|
|
105
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
106
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
107
|
+
this.getPriorityFee(interactionParameters);
|
|
106
108
|
|
|
107
109
|
const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
|
|
108
110
|
if (!feeEstimationFundingTransaction) {
|
|
@@ -170,7 +172,8 @@ export class TransactionFactory {
|
|
|
170
172
|
|
|
171
173
|
parameters.utxos = interactionParameters.utxos;
|
|
172
174
|
parameters.amount =
|
|
173
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
175
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
176
|
+
this.getPriorityFee(interactionParameters);
|
|
174
177
|
|
|
175
178
|
const feeEstimationFundingTransaction = await this.createFundTransaction({ ...parameters });
|
|
176
179
|
if (!feeEstimationFundingTransaction) {
|
|
@@ -224,7 +227,8 @@ export class TransactionFactory {
|
|
|
224
227
|
// Initial generation
|
|
225
228
|
await preTransaction.signTransaction();
|
|
226
229
|
|
|
227
|
-
const parameters: IFundingTransactionParameters =
|
|
230
|
+
const parameters: IFundingTransactionParameters =
|
|
231
|
+
await preTransaction.getFundingTransactionParameters();
|
|
228
232
|
|
|
229
233
|
const fundingTransaction: FundingTransaction = new FundingTransaction(parameters);
|
|
230
234
|
const signedTransaction: Transaction = await fundingTransaction.signTransaction();
|
|
@@ -248,7 +252,7 @@ export class TransactionFactory {
|
|
|
248
252
|
utxos: [newUtxo],
|
|
249
253
|
randomBytes: preTransaction.getRndBytes(),
|
|
250
254
|
nonWitnessUtxo: signedTransaction.toBuffer(),
|
|
251
|
-
optionalOutputs: []
|
|
255
|
+
optionalOutputs: [],
|
|
252
256
|
};
|
|
253
257
|
|
|
254
258
|
const finalTransaction: DeploymentTransaction = new DeploymentTransaction(newParams);
|
|
@@ -291,7 +295,7 @@ export class TransactionFactory {
|
|
|
291
295
|
const childTransactionRequiredValue: bigint =
|
|
292
296
|
wrapParameters.amount +
|
|
293
297
|
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT +
|
|
294
|
-
(wrapParameters
|
|
298
|
+
this.getPriorityFee(wrapParameters);
|
|
295
299
|
|
|
296
300
|
const wbtc: wBTC = new wBTC(wrapParameters.network, wrapParameters.chainId);
|
|
297
301
|
const to = wbtc.getAddress();
|
|
@@ -458,7 +462,8 @@ export class TransactionFactory {
|
|
|
458
462
|
|
|
459
463
|
parameters.utxos = fundingParameters.utxos;
|
|
460
464
|
parameters.amount =
|
|
461
|
-
(await preTransaction.estimateTransactionFees()) +
|
|
465
|
+
(await preTransaction.estimateTransactionFees()) +
|
|
466
|
+
this.getPriorityFee(unwrapParameters);
|
|
462
467
|
|
|
463
468
|
const signedTransaction = await this.createFundTransaction(parameters);
|
|
464
469
|
if (!signedTransaction) {
|
|
@@ -596,6 +601,14 @@ export class TransactionFactory {
|
|
|
596
601
|
return Buffer.concat([header, buf]).toString('hex');
|
|
597
602
|
}
|
|
598
603
|
|
|
604
|
+
private getPriorityFee(params: ITransactionParameters): bigint {
|
|
605
|
+
if (params.priorityFee < TransactionBuilder.MINIMUM_DUST) {
|
|
606
|
+
return TransactionBuilder.MINIMUM_DUST;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return params.priorityFee;
|
|
610
|
+
}
|
|
611
|
+
|
|
599
612
|
private getUTXOAsTransaction(tx: Transaction, to: Address, index: number): UTXO[] {
|
|
600
613
|
if (!tx.outs[index]) return [];
|
|
601
614
|
|
|
@@ -25,25 +25,16 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
25
25
|
|
|
26
26
|
this.addInputsFromUTXO();
|
|
27
27
|
|
|
28
|
-
let amountSpent: bigint = this.amount;
|
|
29
|
-
if (this.getTransactionOPNetFee() === TransactionBuilder.MINIMUM_DUST) {
|
|
30
|
-
if (amountSpent < TransactionBuilder.MINIMUM_DUST) {
|
|
31
|
-
amountSpent += TransactionBuilder.MINIMUM_DUST;
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
amountSpent += this.getTransactionOPNetFee();
|
|
35
|
-
}
|
|
36
|
-
|
|
37
28
|
if (this.splitInputsInto > 1) {
|
|
38
|
-
this.splitInputs(
|
|
29
|
+
this.splitInputs(this.amount);
|
|
39
30
|
} else {
|
|
40
31
|
this.addOutput({
|
|
41
|
-
value: Number(
|
|
32
|
+
value: Number(this.amount),
|
|
42
33
|
address: this.to,
|
|
43
34
|
});
|
|
44
35
|
}
|
|
45
36
|
|
|
46
|
-
await this.addRefundOutput(
|
|
37
|
+
await this.addRefundOutput(this.amount);
|
|
47
38
|
}
|
|
48
39
|
|
|
49
40
|
protected splitInputs(amountSpent: bigint): void {
|
|
@@ -365,7 +365,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
365
365
|
const fee: number = this.feeRate * size;
|
|
366
366
|
|
|
367
367
|
this.estimatedFees = BigInt(Math.ceil(fee) + 1);
|
|
368
|
-
|
|
368
|
+
|
|
369
369
|
return this.estimatedFees;
|
|
370
370
|
} else {
|
|
371
371
|
throw new Error(
|