@btc-vision/transaction 1.0.87 → 1.0.88
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/builders/FundingTransaction.d.ts +2 -0
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +2 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/transaction/builders/FundingTransaction.d.ts +2 -0
- package/build/transaction/builders/FundingTransaction.js +23 -4
- package/build/transaction/builders/TransactionBuilder.js +2 -2
- package/build/transaction/interfaces/ITransactionParameters.d.ts +2 -1
- package/build/utxo/OPNetLimitedProvider.js +14 -19
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/transaction/builders/FundingTransaction.ts +25 -4
- package/src/transaction/builders/TransactionBuilder.ts +2 -2
- package/src/transaction/interfaces/ITransactionParameters.ts +61 -59
- package/src/utxo/OPNetLimitedProvider.ts +244 -244
|
@@ -5,7 +5,9 @@ import { TransactionBuilder } from './TransactionBuilder.js';
|
|
|
5
5
|
export declare class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
6
6
|
readonly type: TransactionType.FUNDING;
|
|
7
7
|
protected childTransactionRequiredFees: bigint;
|
|
8
|
+
protected splitInputsInto: number;
|
|
8
9
|
constructor(parameters: IFundingTransactionParameters);
|
|
9
10
|
protected buildTransaction(): Promise<void>;
|
|
11
|
+
protected splitInputs(amountSpent: bigint): Promise<void>;
|
|
10
12
|
protected getSignerKey(): Signer;
|
|
11
13
|
}
|
|
@@ -13,10 +13,11 @@ 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;
|
|
20
|
+
splitInputsInto?: number;
|
|
20
21
|
}
|
|
21
22
|
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
22
23
|
calldata?: Buffer | undefined;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.88";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.88';
|
|
@@ -5,7 +5,9 @@ import { TransactionBuilder } from './TransactionBuilder.js';
|
|
|
5
5
|
export declare class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
6
6
|
readonly type: TransactionType.FUNDING;
|
|
7
7
|
protected childTransactionRequiredFees: bigint;
|
|
8
|
+
protected splitInputsInto: number;
|
|
8
9
|
constructor(parameters: IFundingTransactionParameters);
|
|
9
10
|
protected buildTransaction(): Promise<void>;
|
|
11
|
+
protected splitInputs(amountSpent: bigint): Promise<void>;
|
|
10
12
|
protected getSignerKey(): Signer;
|
|
11
13
|
}
|
|
@@ -3,9 +3,11 @@ import { TransactionBuilder } from './TransactionBuilder.js';
|
|
|
3
3
|
export class FundingTransaction extends TransactionBuilder {
|
|
4
4
|
type = TransactionType.FUNDING;
|
|
5
5
|
childTransactionRequiredFees;
|
|
6
|
+
splitInputsInto;
|
|
6
7
|
constructor(parameters) {
|
|
7
8
|
super(parameters);
|
|
8
9
|
this.childTransactionRequiredFees = parameters.amount;
|
|
10
|
+
this.splitInputsInto = parameters.splitInputsInto ?? 1;
|
|
9
11
|
this.internalInit();
|
|
10
12
|
}
|
|
11
13
|
async buildTransaction() {
|
|
@@ -14,12 +16,29 @@ export class FundingTransaction extends TransactionBuilder {
|
|
|
14
16
|
}
|
|
15
17
|
this.addInputsFromUTXO();
|
|
16
18
|
const amountSpent = this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
|
|
17
|
-
this.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
if (this.splitInputsInto > 1) {
|
|
20
|
+
await this.splitInputs(amountSpent);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
this.addOutput({
|
|
24
|
+
value: Number(amountSpent),
|
|
25
|
+
address: this.to,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
21
28
|
await this.addRefundOutput(amountSpent);
|
|
22
29
|
}
|
|
30
|
+
async splitInputs(amountSpent) {
|
|
31
|
+
if (!this.to) {
|
|
32
|
+
throw new Error('Recipient address is required');
|
|
33
|
+
}
|
|
34
|
+
const splitAmount = amountSpent / BigInt(this.splitInputsInto);
|
|
35
|
+
for (let i = 0; i < this.splitInputsInto; i++) {
|
|
36
|
+
this.addOutput({
|
|
37
|
+
value: Number(splitAmount),
|
|
38
|
+
address: this.to,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
23
42
|
getSignerKey() {
|
|
24
43
|
return this.signer;
|
|
25
44
|
}
|
|
@@ -35,7 +35,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
35
35
|
this.signer = parameters.signer;
|
|
36
36
|
this.network = parameters.network;
|
|
37
37
|
this.feeRate = parameters.feeRate;
|
|
38
|
-
this.priorityFee = parameters.priorityFee;
|
|
38
|
+
this.priorityFee = parameters.priorityFee ?? 0n;
|
|
39
39
|
this.utxos = parameters.utxos;
|
|
40
40
|
this.to = parameters.to || undefined;
|
|
41
41
|
this.from = TransactionBuilder.getFrom(parameters.from, this.signer, this.network);
|
|
@@ -83,7 +83,7 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
83
83
|
signer: this.signer,
|
|
84
84
|
network: this.network,
|
|
85
85
|
feeRate: this.feeRate,
|
|
86
|
-
priorityFee: this.priorityFee,
|
|
86
|
+
priorityFee: this.priorityFee ?? 0n,
|
|
87
87
|
from: this.from,
|
|
88
88
|
amount: this.estimatedFees,
|
|
89
89
|
};
|
|
@@ -13,10 +13,11 @@ 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;
|
|
20
|
+
splitInputsInto?: number;
|
|
20
21
|
}
|
|
21
22
|
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
22
23
|
calldata?: Buffer | undefined;
|
|
@@ -101,27 +101,22 @@ export class OPNetLimitedProvider {
|
|
|
101
101
|
}),
|
|
102
102
|
};
|
|
103
103
|
const url = `${this.opnetAPIUrl}/api/v1/${this.rpc}`;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
108
|
-
}
|
|
109
|
-
const fetchedData = await resp.json();
|
|
110
|
-
if (!fetchedData) {
|
|
111
|
-
throw new Error('No data fetched');
|
|
112
|
-
}
|
|
113
|
-
const result = fetchedData.result;
|
|
114
|
-
if (!result) {
|
|
115
|
-
throw new Error('No rpc parameters found');
|
|
116
|
-
}
|
|
117
|
-
if ('error' in result) {
|
|
118
|
-
throw new Error(`Error in fetching to rpc ${result.error}`);
|
|
119
|
-
}
|
|
120
|
-
return result;
|
|
104
|
+
const resp = await fetch(url, params);
|
|
105
|
+
if (!resp.ok) {
|
|
106
|
+
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
121
107
|
}
|
|
122
|
-
|
|
123
|
-
|
|
108
|
+
const fetchedData = await resp.json();
|
|
109
|
+
if (!fetchedData) {
|
|
110
|
+
throw new Error('No data fetched');
|
|
111
|
+
}
|
|
112
|
+
const result = fetchedData.result;
|
|
113
|
+
if (!result) {
|
|
114
|
+
throw new Error('No rpc parameters found');
|
|
124
115
|
}
|
|
116
|
+
if ('error' in result) {
|
|
117
|
+
throw new Error(`Error in fetching to rpc ${result.error}`);
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
125
120
|
}
|
|
126
121
|
async fetchWrapParameters(amount) {
|
|
127
122
|
if (amount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.88';
|
|
@@ -7,11 +7,13 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
7
7
|
public readonly type: TransactionType.FUNDING = TransactionType.FUNDING;
|
|
8
8
|
|
|
9
9
|
protected childTransactionRequiredFees: bigint;
|
|
10
|
+
protected splitInputsInto: number;
|
|
10
11
|
|
|
11
12
|
constructor(parameters: IFundingTransactionParameters) {
|
|
12
13
|
super(parameters);
|
|
13
14
|
|
|
14
15
|
this.childTransactionRequiredFees = parameters.amount;
|
|
16
|
+
this.splitInputsInto = parameters.splitInputsInto ?? 1;
|
|
15
17
|
|
|
16
18
|
this.internalInit();
|
|
17
19
|
}
|
|
@@ -26,14 +28,33 @@ export class FundingTransaction extends TransactionBuilder<TransactionType.FUNDI
|
|
|
26
28
|
const amountSpent: bigint =
|
|
27
29
|
this.getTransactionOPNetFee() + this.childTransactionRequiredFees;
|
|
28
30
|
|
|
29
|
-
this.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
if(this.splitInputsInto > 1) {
|
|
32
|
+
await this.splitInputs(amountSpent);
|
|
33
|
+
} else {
|
|
34
|
+
this.addOutput({
|
|
35
|
+
value: Number(amountSpent),
|
|
36
|
+
address: this.to,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
33
39
|
|
|
34
40
|
await this.addRefundOutput(amountSpent);
|
|
35
41
|
}
|
|
36
42
|
|
|
43
|
+
protected async splitInputs(amountSpent: bigint): Promise<void> {
|
|
44
|
+
if (!this.to) {
|
|
45
|
+
throw new Error('Recipient address is required');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const splitAmount = amountSpent / BigInt(this.splitInputsInto);
|
|
49
|
+
|
|
50
|
+
for (let i = 0; i < this.splitInputsInto; i++) {
|
|
51
|
+
this.addOutput({
|
|
52
|
+
value: Number(splitAmount),
|
|
53
|
+
address: this.to,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
37
58
|
protected override getSignerKey(): Signer {
|
|
38
59
|
return this.signer;
|
|
39
60
|
}
|
|
@@ -115,7 +115,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
115
115
|
this.signer = parameters.signer;
|
|
116
116
|
this.network = parameters.network;
|
|
117
117
|
this.feeRate = parameters.feeRate;
|
|
118
|
-
this.priorityFee = parameters.priorityFee;
|
|
118
|
+
this.priorityFee = parameters.priorityFee ?? 0n;
|
|
119
119
|
this.utxos = parameters.utxos;
|
|
120
120
|
this.to = parameters.to || undefined;
|
|
121
121
|
|
|
@@ -192,7 +192,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
192
192
|
signer: this.signer,
|
|
193
193
|
network: this.network,
|
|
194
194
|
feeRate: this.feeRate,
|
|
195
|
-
priorityFee: this.priorityFee,
|
|
195
|
+
priorityFee: this.priorityFee ?? 0n,
|
|
196
196
|
from: this.from,
|
|
197
197
|
amount: this.estimatedFees,
|
|
198
198
|
};
|
|
@@ -1,59 +1,61 @@
|
|
|
1
|
-
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
2
|
-
import { Address } from '@btc-vision/bsi-binary';
|
|
3
|
-
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
4
|
-
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
|
-
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
|
-
import { ChainId } from '../../network/ChainId.js';
|
|
7
|
-
|
|
8
|
-
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
9
|
-
readonly from?: Address;
|
|
10
|
-
readonly to?: Address | undefined;
|
|
11
|
-
utxos: UTXO[];
|
|
12
|
-
|
|
13
|
-
nonWitnessUtxo?: Buffer | undefined;
|
|
14
|
-
estimatedFees?: bigint;
|
|
15
|
-
|
|
16
|
-
chainId?: ChainId;
|
|
17
|
-
|
|
18
|
-
readonly feeRate: number;
|
|
19
|
-
readonly priorityFee
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
23
|
-
amount: bigint;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
readonly
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
readonly
|
|
43
|
-
|
|
44
|
-
readonly
|
|
45
|
-
|
|
46
|
-
readonly
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
readonly
|
|
58
|
-
|
|
59
|
-
|
|
1
|
+
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
2
|
+
import { Address } from '@btc-vision/bsi-binary';
|
|
3
|
+
import { WrappedGeneration } from '../../wbtc/WrappedGenerationParameters.js';
|
|
4
|
+
import { ITweakedTransactionData } from '../shared/TweakedTransaction.js';
|
|
5
|
+
import { VaultUTXOs } from '../processor/PsbtTransaction.js';
|
|
6
|
+
import { ChainId } from '../../network/ChainId.js';
|
|
7
|
+
|
|
8
|
+
export interface ITransactionParameters extends ITweakedTransactionData {
|
|
9
|
+
readonly from?: Address;
|
|
10
|
+
readonly to?: Address | undefined;
|
|
11
|
+
utxos: UTXO[];
|
|
12
|
+
|
|
13
|
+
nonWitnessUtxo?: Buffer | undefined;
|
|
14
|
+
estimatedFees?: bigint;
|
|
15
|
+
|
|
16
|
+
chainId?: ChainId;
|
|
17
|
+
|
|
18
|
+
readonly feeRate: number;
|
|
19
|
+
readonly priorityFee?: bigint;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
23
|
+
amount: bigint;
|
|
24
|
+
|
|
25
|
+
splitInputsInto?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
29
|
+
calldata?: Buffer | undefined;
|
|
30
|
+
disableAutoRefund?: boolean;
|
|
31
|
+
|
|
32
|
+
readonly randomBytes?: Buffer;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface IInteractionParameters extends SharedInteractionParameters {
|
|
36
|
+
readonly calldata: Buffer;
|
|
37
|
+
|
|
38
|
+
readonly to: Address;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface IWrapParameters extends SharedInteractionParameters {
|
|
42
|
+
readonly to?: Address;
|
|
43
|
+
|
|
44
|
+
readonly from: Address;
|
|
45
|
+
readonly amount: bigint;
|
|
46
|
+
readonly receiver?: Address;
|
|
47
|
+
|
|
48
|
+
readonly generationParameters: WrappedGeneration;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface IUnwrapParameters extends SharedInteractionParameters {
|
|
52
|
+
readonly unwrapUTXOs: VaultUTXOs[];
|
|
53
|
+
readonly amount: bigint;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export interface IDeploymentParameters extends ITransactionParameters {
|
|
57
|
+
readonly bytecode: Buffer;
|
|
58
|
+
|
|
59
|
+
readonly to?: undefined;
|
|
60
|
+
readonly randomBytes?: Buffer;
|
|
61
|
+
}
|