@btc-vision/transaction 1.0.91 → 1.0.92
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/transaction/TransactionFactory.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/transaction/TransactionFactory.d.ts +1 -1
- package/build/transaction/TransactionFactory.js +13 -11
- package/build/transaction/builders/TransactionBuilder.js +2 -2
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/transaction/TransactionFactory.ts +14 -12
- package/src/transaction/builders/TransactionBuilder.ts +2 -2
- package/src/transaction/interfaces/ITransactionParameters.ts +1 -1
|
@@ -40,7 +40,7 @@ export declare class TransactionFactory {
|
|
|
40
40
|
constructor();
|
|
41
41
|
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
42
42
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
43
|
-
wrap(
|
|
43
|
+
wrap(wrapParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
44
44
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
45
45
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
46
46
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
@@ -13,7 +13,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
13
13
|
estimatedFees?: bigint;
|
|
14
14
|
chainId?: ChainId;
|
|
15
15
|
readonly feeRate: number;
|
|
16
|
-
readonly priorityFee
|
|
16
|
+
readonly priorityFee: bigint;
|
|
17
17
|
}
|
|
18
18
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
19
19
|
amount: bigint;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.92";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.92';
|
|
@@ -40,7 +40,7 @@ export declare class TransactionFactory {
|
|
|
40
40
|
constructor();
|
|
41
41
|
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
42
42
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
43
|
-
wrap(
|
|
43
|
+
wrap(wrapParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
44
44
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
45
45
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
46
46
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
@@ -93,21 +93,23 @@ export class TransactionFactory {
|
|
|
93
93
|
utxos: [refundUTXO],
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
-
async wrap(
|
|
97
|
-
if (
|
|
98
|
-
throw new Error(`Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${
|
|
96
|
+
async wrap(wrapParameters) {
|
|
97
|
+
if (wrapParameters.amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
98
|
+
throw new Error(`Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${wrapParameters.amount} sat. Make sure that you cover the unwrap consolidation fees of ${currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT}sat.`);
|
|
99
99
|
}
|
|
100
|
-
const childTransactionRequiredValue =
|
|
101
|
-
|
|
100
|
+
const childTransactionRequiredValue = wrapParameters.amount +
|
|
101
|
+
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT +
|
|
102
|
+
(wrapParameters.priorityFee || 300n);
|
|
103
|
+
const wbtc = new wBTC(wrapParameters.network, wrapParameters.chainId);
|
|
102
104
|
const to = wbtc.getAddress();
|
|
103
105
|
const fundingParameters = {
|
|
104
|
-
...
|
|
106
|
+
...wrapParameters,
|
|
105
107
|
amount: childTransactionRequiredValue,
|
|
106
|
-
to:
|
|
108
|
+
to: wrapParameters.to ?? to,
|
|
107
109
|
};
|
|
108
110
|
const preFundingTransaction = await this.createFundTransaction(fundingParameters);
|
|
109
|
-
|
|
110
|
-
const preTransaction = new WrapTransaction(
|
|
111
|
+
wrapParameters.utxos = this.getUTXOAsTransaction(preFundingTransaction.tx, to, 0);
|
|
112
|
+
const preTransaction = new WrapTransaction(wrapParameters);
|
|
111
113
|
await preTransaction.signTransaction();
|
|
112
114
|
const parameters = await preTransaction.getFundingTransactionParameters();
|
|
113
115
|
parameters.amount += childTransactionRequiredValue;
|
|
@@ -117,7 +119,7 @@ export class TransactionFactory {
|
|
|
117
119
|
throw new Error('Could not sign funding transaction.');
|
|
118
120
|
}
|
|
119
121
|
const newParams = {
|
|
120
|
-
...
|
|
122
|
+
...wrapParameters,
|
|
121
123
|
utxos: this.getUTXOAsTransaction(signedTransaction.tx, to, 0),
|
|
122
124
|
randomBytes: preTransaction.getRndBytes(),
|
|
123
125
|
nonWitnessUtxo: signedTransaction.tx.toBuffer(),
|
|
@@ -129,7 +131,7 @@ export class TransactionFactory {
|
|
|
129
131
|
vaultAddress: finalTransaction.vault,
|
|
130
132
|
amount: finalTransaction.amount,
|
|
131
133
|
receiverAddress: finalTransaction.receiver,
|
|
132
|
-
utxos: this.getUTXOAsTransaction(signedTransaction.tx,
|
|
134
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, wrapParameters.from, 1),
|
|
133
135
|
};
|
|
134
136
|
}
|
|
135
137
|
async unwrapSegwit(unwrapParameters) {
|
|
@@ -110,7 +110,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
110
110
|
if (this.regenerated) {
|
|
111
111
|
throw new Error('Transaction was regenerated');
|
|
112
112
|
}
|
|
113
|
-
return this.transaction.extractTransaction(
|
|
113
|
+
return this.transaction.extractTransaction(true, true);
|
|
114
114
|
}
|
|
115
115
|
throw new Error('Could not sign transaction');
|
|
116
116
|
}
|
|
@@ -292,7 +292,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
292
292
|
if (output.value < TransactionBuilder.MINIMUM_DUST) {
|
|
293
293
|
this.feeOutput = null;
|
|
294
294
|
if (output.value < 0) {
|
|
295
|
-
throw new Error(`setFeeOutput: Insufficient funds to pay the fees. Fee: ${fee}
|
|
295
|
+
throw new Error(`setFeeOutput: Insufficient funds to pay the fees. Fee: ${fee} < Value: ${initialValue}. Total input: ${this.totalInputAmount} sat`);
|
|
296
296
|
}
|
|
297
297
|
}
|
|
298
298
|
else {
|
|
@@ -13,7 +13,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
13
13
|
estimatedFees?: bigint;
|
|
14
14
|
chainId?: ChainId;
|
|
15
15
|
readonly feeRate: number;
|
|
16
|
-
readonly priorityFee
|
|
16
|
+
readonly priorityFee: bigint;
|
|
17
17
|
}
|
|
18
18
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
19
19
|
amount: bigint;
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.92';
|
|
@@ -207,32 +207,34 @@ export class TransactionFactory {
|
|
|
207
207
|
|
|
208
208
|
/**
|
|
209
209
|
* Basically it's fun to manage UTXOs.
|
|
210
|
-
* @param {IWrapParameters}
|
|
210
|
+
* @param {IWrapParameters} wrapParameters - The wrap parameters
|
|
211
211
|
* @returns {Promise<WrapResult>} - The signed transaction
|
|
212
212
|
* @throws {Error} - If the transaction could not be signed
|
|
213
213
|
*/
|
|
214
|
-
public async wrap(
|
|
215
|
-
if (
|
|
214
|
+
public async wrap(wrapParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult> {
|
|
215
|
+
if (wrapParameters.amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
216
216
|
throw new Error(
|
|
217
|
-
`Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${
|
|
217
|
+
`Amount is too low. Minimum consolidation is ${currentConsensusConfig.VAULT_MINIMUM_AMOUNT} sat. Received ${wrapParameters.amount} sat. Make sure that you cover the unwrap consolidation fees of ${currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT}sat.`,
|
|
218
218
|
);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
const childTransactionRequiredValue: bigint =
|
|
222
|
-
|
|
222
|
+
wrapParameters.amount +
|
|
223
|
+
currentConsensusConfig.UNWRAP_CONSOLIDATION_PREPAID_FEES_SAT +
|
|
224
|
+
(wrapParameters.priorityFee || 300n);
|
|
223
225
|
|
|
224
|
-
const wbtc: wBTC = new wBTC(
|
|
226
|
+
const wbtc: wBTC = new wBTC(wrapParameters.network, wrapParameters.chainId);
|
|
225
227
|
const to = wbtc.getAddress();
|
|
226
228
|
const fundingParameters: IFundingTransactionParameters = {
|
|
227
|
-
...
|
|
229
|
+
...wrapParameters,
|
|
228
230
|
amount: childTransactionRequiredValue,
|
|
229
|
-
to:
|
|
231
|
+
to: wrapParameters.to ?? to,
|
|
230
232
|
};
|
|
231
233
|
|
|
232
234
|
const preFundingTransaction = await this.createFundTransaction(fundingParameters);
|
|
233
|
-
|
|
235
|
+
wrapParameters.utxos = this.getUTXOAsTransaction(preFundingTransaction.tx, to, 0);
|
|
234
236
|
|
|
235
|
-
const preTransaction: WrapTransaction = new WrapTransaction(
|
|
237
|
+
const preTransaction: WrapTransaction = new WrapTransaction(wrapParameters);
|
|
236
238
|
|
|
237
239
|
// Initial generation
|
|
238
240
|
await preTransaction.signTransaction();
|
|
@@ -250,7 +252,7 @@ export class TransactionFactory {
|
|
|
250
252
|
}
|
|
251
253
|
|
|
252
254
|
const newParams: IWrapParameters = {
|
|
253
|
-
...
|
|
255
|
+
...wrapParameters,
|
|
254
256
|
utxos: this.getUTXOAsTransaction(signedTransaction.tx, to, 0), // always 0
|
|
255
257
|
randomBytes: preTransaction.getRndBytes(),
|
|
256
258
|
nonWitnessUtxo: signedTransaction.tx.toBuffer(),
|
|
@@ -265,7 +267,7 @@ export class TransactionFactory {
|
|
|
265
267
|
vaultAddress: finalTransaction.vault,
|
|
266
268
|
amount: finalTransaction.amount,
|
|
267
269
|
receiverAddress: finalTransaction.receiver,
|
|
268
|
-
utxos: this.getUTXOAsTransaction(signedTransaction.tx,
|
|
270
|
+
utxos: this.getUTXOAsTransaction(signedTransaction.tx, wrapParameters.from, 1),
|
|
269
271
|
};
|
|
270
272
|
}
|
|
271
273
|
|
|
@@ -243,7 +243,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
243
243
|
throw new Error('Transaction was regenerated');
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
-
return this.transaction.extractTransaction(
|
|
246
|
+
return this.transaction.extractTransaction(true, true);
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
throw new Error('Could not sign transaction');
|
|
@@ -607,7 +607,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
607
607
|
|
|
608
608
|
if (output.value < 0) {
|
|
609
609
|
throw new Error(
|
|
610
|
-
`setFeeOutput: Insufficient funds to pay the fees. Fee: ${fee}
|
|
610
|
+
`setFeeOutput: Insufficient funds to pay the fees. Fee: ${fee} < Value: ${initialValue}. Total input: ${this.totalInputAmount} sat`,
|
|
611
611
|
);
|
|
612
612
|
}
|
|
613
613
|
} else {
|
|
@@ -16,7 +16,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
16
16
|
chainId?: ChainId;
|
|
17
17
|
|
|
18
18
|
readonly feeRate: number;
|
|
19
|
-
readonly priorityFee
|
|
19
|
+
readonly priorityFee: bigint;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|