@btc-vision/transaction 1.0.86 → 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.
@@ -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: bigint;
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;
@@ -1 +1 @@
1
- export declare const version = "1.0.86";
1
+ export declare const version = "1.0.88";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.86';
1
+ export const version = '1.0.88';
@@ -11,7 +11,7 @@ export const MOTO_ADDRESS_TESTNET = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw'
11
11
  export const ROUTER_ADDRESS_TESTNET = 'tb1qnh9mj95nnej25dwhjvvsppwmdm0myhxv7tllgt';
12
12
  export const FACTORY_ADDRESS_FRACTAL = 'bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q';
13
13
  export const POOL_ADDRESS_FRACTAL = 'bc1qv55cht4zzlt29ea7vdgwsedsn63a2sxtkgpv6h';
14
- export const WBTC_ADDRESS_FRACTAL = 'bc1qdtzlucslvrvu4useyh9r69supqrw3w4xn9t4yv';
14
+ export const WBTC_ADDRESS_FRACTAL = 'u fou';
15
15
  export const MOTO_ADDRESS_FRACTAL = 'bc1qfzq6w5uvgg5489egv0lj4shlqx4dagqt0ewdnu';
16
16
  export const ROUTER_ADDRESS_FRACTAL = 'bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn';
17
17
  export var OPNetNetwork;
@@ -275,6 +275,8 @@ export class TransactionFactory {
275
275
  return Buffer.concat([header, buf]).toString('hex');
276
276
  }
277
277
  getUTXOAsTransaction(tx, to, index) {
278
+ if (!tx.outs[index])
279
+ return [];
278
280
  const out = tx.outs[index];
279
281
  const newUtxo = {
280
282
  transactionId: tx.getId(),
@@ -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.addOutput({
18
- value: Number(amountSpent),
19
- address: this.to,
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: bigint;
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
- try {
105
- const resp = await fetch(url, params);
106
- if (!resp.ok) {
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
- catch (e) {
123
- console.error(`Failed to fetch wrap parameters: ${e.stack}`);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.86",
3
+ "version": "1.0.88",
4
4
  "author": "BlobMaster41",
5
5
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
6
6
  "engines": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.86';
1
+ export const version = '1.0.88';
@@ -1,135 +1,135 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
- import { ChainId } from '../network/ChainId.js';
3
-
4
- // Addresses Regtest
5
- export const FACTORY_ADDRESS_REGTEST: Address = 'bcrt1qxtpreq8zg7pp9wm550kjrhaa2r5kj6lhph9he5';
6
- export const POOL_ADDRESS_REGTEST: Address = 'bcrt1qqg2a8076rwuruzetdyquj8fh5jxtc22pmh9vep';
7
- export const WBTC_ADDRESS_REGTEST: Address = 'bcrt1qdr7sjgtnudda8zrfklw8l5cnrxum5hns7e46hf';
8
- export const MOTO_ADDRESS_REGTEST: Address = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
9
- export const ROUTER_ADDRESS_REGTEST: Address = 'bcrt1qplnz54sca73t8a03nh494jatr9ffjg6ecarrj8';
10
-
11
- // Addresses Testnet
12
- export const FACTORY_ADDRESS_TESTNET: Address = 'tb1qgev5kldhp5zvg6j8t9vl6x4phkrwn8nk9felxh';
13
- export const POOL_ADDRESS_TESTNET: Address = 'tb1q6a7yw353hjmresphupytw5vczpqxtg4yrupayk';
14
- export const WBTC_ADDRESS_TESTNET: Address = 'tb1qp28xna6pv47x6wflcplhu0a9hkld5shtvjx6xv';
15
- export const MOTO_ADDRESS_TESTNET: Address = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw';
16
- export const ROUTER_ADDRESS_TESTNET: Address = 'tb1qnh9mj95nnej25dwhjvvsppwmdm0myhxv7tllgt';
17
-
18
- // Addresses Fractal
19
- export const FACTORY_ADDRESS_FRACTAL: Address = 'bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q';
20
- export const POOL_ADDRESS_FRACTAL: Address = 'bc1qv55cht4zzlt29ea7vdgwsedsn63a2sxtkgpv6h';
21
- export const WBTC_ADDRESS_FRACTAL: Address = 'bc1qdtzlucslvrvu4useyh9r69supqrw3w4xn9t4yv';
22
- export const MOTO_ADDRESS_FRACTAL: Address = 'bc1qfzq6w5uvgg5489egv0lj4shlqx4dagqt0ewdnu';
23
- export const ROUTER_ADDRESS_FRACTAL: Address = 'bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn';
24
-
25
- export enum OPNetNetwork {
26
- Mainnet = 'mainnet',
27
- Testnet = 'testnet',
28
- Regtest = 'regtest',
29
- }
30
-
31
- export interface OPNetTokenMetadata {
32
- readonly factory: Address;
33
- readonly pool: Address;
34
- readonly wbtc: Address;
35
- readonly moto: Address;
36
- readonly router: Address;
37
- }
38
-
39
- export class OPNetTokenAddressManager {
40
- private readonly metadata: {
41
- [key in ChainId]: { [key in OPNetNetwork]?: OPNetTokenMetadata };
42
- } = {
43
- [ChainId.Bitcoin]: {
44
- [OPNetNetwork.Testnet]: {
45
- factory: FACTORY_ADDRESS_TESTNET,
46
- pool: POOL_ADDRESS_TESTNET,
47
- wbtc: WBTC_ADDRESS_TESTNET,
48
- moto: MOTO_ADDRESS_TESTNET,
49
- router: ROUTER_ADDRESS_TESTNET,
50
- },
51
- [OPNetNetwork.Regtest]: {
52
- factory: FACTORY_ADDRESS_REGTEST,
53
- pool: POOL_ADDRESS_REGTEST,
54
- wbtc: WBTC_ADDRESS_REGTEST,
55
- moto: MOTO_ADDRESS_REGTEST,
56
- router: ROUTER_ADDRESS_REGTEST,
57
- },
58
- },
59
- [ChainId.Fractal]: {
60
- [OPNetNetwork.Mainnet]: {
61
- factory: FACTORY_ADDRESS_FRACTAL,
62
- pool: POOL_ADDRESS_FRACTAL,
63
- wbtc: WBTC_ADDRESS_FRACTAL,
64
- moto: MOTO_ADDRESS_FRACTAL,
65
- router: ROUTER_ADDRESS_FRACTAL,
66
- },
67
- },
68
- };
69
-
70
- public getFactoryAddress(network: OPNetNetwork, chainId: ChainId): Address {
71
- const address = this.metadata[chainId][network]?.factory;
72
-
73
- if (!address) {
74
- throw new Error(
75
- `Factory address not found for network ${network} and chainId ${chainId}`,
76
- );
77
- }
78
-
79
- return address;
80
- }
81
-
82
- public getPoolAddress(network: OPNetNetwork, chainId: ChainId): Address {
83
- const address = this.metadata[chainId][network]?.pool;
84
-
85
- if (!address) {
86
- throw new Error(`Pool address not found for network ${network} and chainId ${chainId}`);
87
- }
88
-
89
- return address;
90
- }
91
-
92
- public getWBTCAddress(network: OPNetNetwork, chainId: ChainId): Address {
93
- const address = this.metadata[chainId][network]?.wbtc;
94
-
95
- if (!address) {
96
- throw new Error(`WBTC address not found for network ${network} and chainId ${chainId}`);
97
- }
98
-
99
- return address;
100
- }
101
-
102
- public getMOTOAddress(network: OPNetNetwork, chainId: ChainId): Address {
103
- const address = this.metadata[chainId][network]?.moto;
104
-
105
- if (!address) {
106
- throw new Error(`MOTO address not found for network ${network} and chainId ${chainId}`);
107
- }
108
-
109
- return address;
110
- }
111
-
112
- public getRouterAddress(network: OPNetNetwork, chainId: ChainId): Address {
113
- const address = this.metadata[chainId][network]?.router;
114
-
115
- if (!address) {
116
- throw new Error(
117
- `Router address not found for network ${network} and chainId ${chainId}`,
118
- );
119
- }
120
-
121
- return address;
122
- }
123
-
124
- public getAddresses(network: OPNetNetwork, chainId: ChainId): OPNetTokenMetadata {
125
- const metadata = this.metadata[chainId][network];
126
-
127
- if (!metadata) {
128
- throw new Error(`Metadata not found for network ${network} and chainId ${chainId}`);
129
- }
130
-
131
- return metadata;
132
- }
133
- }
134
-
135
- export const OPNetMetadata: OPNetTokenAddressManager = new OPNetTokenAddressManager();
1
+ import { Address } from '@btc-vision/bsi-binary';
2
+ import { ChainId } from '../network/ChainId.js';
3
+
4
+ // Addresses Regtest
5
+ export const FACTORY_ADDRESS_REGTEST: Address = 'bcrt1qxtpreq8zg7pp9wm550kjrhaa2r5kj6lhph9he5';
6
+ export const POOL_ADDRESS_REGTEST: Address = 'bcrt1qqg2a8076rwuruzetdyquj8fh5jxtc22pmh9vep';
7
+ export const WBTC_ADDRESS_REGTEST: Address = 'bcrt1qdr7sjgtnudda8zrfklw8l5cnrxum5hns7e46hf';
8
+ export const MOTO_ADDRESS_REGTEST: Address = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
9
+ export const ROUTER_ADDRESS_REGTEST: Address = 'bcrt1qplnz54sca73t8a03nh494jatr9ffjg6ecarrj8';
10
+
11
+ // Addresses Testnet
12
+ export const FACTORY_ADDRESS_TESTNET: Address = 'tb1qgev5kldhp5zvg6j8t9vl6x4phkrwn8nk9felxh';
13
+ export const POOL_ADDRESS_TESTNET: Address = 'tb1q6a7yw353hjmresphupytw5vczpqxtg4yrupayk';
14
+ export const WBTC_ADDRESS_TESTNET: Address = 'tb1qp28xna6pv47x6wflcplhu0a9hkld5shtvjx6xv';
15
+ export const MOTO_ADDRESS_TESTNET: Address = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw';
16
+ export const ROUTER_ADDRESS_TESTNET: Address = 'tb1qnh9mj95nnej25dwhjvvsppwmdm0myhxv7tllgt';
17
+
18
+ // Addresses Fractal
19
+ export const FACTORY_ADDRESS_FRACTAL: Address = 'bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q';
20
+ export const POOL_ADDRESS_FRACTAL: Address = 'bc1qv55cht4zzlt29ea7vdgwsedsn63a2sxtkgpv6h';
21
+ export const WBTC_ADDRESS_FRACTAL: Address = 'u fou';
22
+ export const MOTO_ADDRESS_FRACTAL: Address = 'bc1qfzq6w5uvgg5489egv0lj4shlqx4dagqt0ewdnu';
23
+ export const ROUTER_ADDRESS_FRACTAL: Address = 'bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn';
24
+
25
+ export enum OPNetNetwork {
26
+ Mainnet = 'mainnet',
27
+ Testnet = 'testnet',
28
+ Regtest = 'regtest',
29
+ }
30
+
31
+ export interface OPNetTokenMetadata {
32
+ readonly factory: Address;
33
+ readonly pool: Address;
34
+ readonly wbtc: Address;
35
+ readonly moto: Address;
36
+ readonly router: Address;
37
+ }
38
+
39
+ export class OPNetTokenAddressManager {
40
+ private readonly metadata: {
41
+ [key in ChainId]: { [key in OPNetNetwork]?: OPNetTokenMetadata };
42
+ } = {
43
+ [ChainId.Bitcoin]: {
44
+ [OPNetNetwork.Testnet]: {
45
+ factory: FACTORY_ADDRESS_TESTNET,
46
+ pool: POOL_ADDRESS_TESTNET,
47
+ wbtc: WBTC_ADDRESS_TESTNET,
48
+ moto: MOTO_ADDRESS_TESTNET,
49
+ router: ROUTER_ADDRESS_TESTNET,
50
+ },
51
+ [OPNetNetwork.Regtest]: {
52
+ factory: FACTORY_ADDRESS_REGTEST,
53
+ pool: POOL_ADDRESS_REGTEST,
54
+ wbtc: WBTC_ADDRESS_REGTEST,
55
+ moto: MOTO_ADDRESS_REGTEST,
56
+ router: ROUTER_ADDRESS_REGTEST,
57
+ },
58
+ },
59
+ [ChainId.Fractal]: {
60
+ [OPNetNetwork.Mainnet]: {
61
+ factory: FACTORY_ADDRESS_FRACTAL,
62
+ pool: POOL_ADDRESS_FRACTAL,
63
+ wbtc: WBTC_ADDRESS_FRACTAL,
64
+ moto: MOTO_ADDRESS_FRACTAL,
65
+ router: ROUTER_ADDRESS_FRACTAL,
66
+ },
67
+ },
68
+ };
69
+
70
+ public getFactoryAddress(network: OPNetNetwork, chainId: ChainId): Address {
71
+ const address = this.metadata[chainId][network]?.factory;
72
+
73
+ if (!address) {
74
+ throw new Error(
75
+ `Factory address not found for network ${network} and chainId ${chainId}`,
76
+ );
77
+ }
78
+
79
+ return address;
80
+ }
81
+
82
+ public getPoolAddress(network: OPNetNetwork, chainId: ChainId): Address {
83
+ const address = this.metadata[chainId][network]?.pool;
84
+
85
+ if (!address) {
86
+ throw new Error(`Pool address not found for network ${network} and chainId ${chainId}`);
87
+ }
88
+
89
+ return address;
90
+ }
91
+
92
+ public getWBTCAddress(network: OPNetNetwork, chainId: ChainId): Address {
93
+ const address = this.metadata[chainId][network]?.wbtc;
94
+
95
+ if (!address) {
96
+ throw new Error(`WBTC address not found for network ${network} and chainId ${chainId}`);
97
+ }
98
+
99
+ return address;
100
+ }
101
+
102
+ public getMOTOAddress(network: OPNetNetwork, chainId: ChainId): Address {
103
+ const address = this.metadata[chainId][network]?.moto;
104
+
105
+ if (!address) {
106
+ throw new Error(`MOTO address not found for network ${network} and chainId ${chainId}`);
107
+ }
108
+
109
+ return address;
110
+ }
111
+
112
+ public getRouterAddress(network: OPNetNetwork, chainId: ChainId): Address {
113
+ const address = this.metadata[chainId][network]?.router;
114
+
115
+ if (!address) {
116
+ throw new Error(
117
+ `Router address not found for network ${network} and chainId ${chainId}`,
118
+ );
119
+ }
120
+
121
+ return address;
122
+ }
123
+
124
+ public getAddresses(network: OPNetNetwork, chainId: ChainId): OPNetTokenMetadata {
125
+ const metadata = this.metadata[chainId][network];
126
+
127
+ if (!metadata) {
128
+ throw new Error(`Metadata not found for network ${network} and chainId ${chainId}`);
129
+ }
130
+
131
+ return metadata;
132
+ }
133
+ }
134
+
135
+ export const OPNetMetadata: OPNetTokenAddressManager = new OPNetTokenAddressManager();