@btc-vision/transaction 1.0.88 → 1.0.90
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/README.md +3 -152
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/TransactionFactory.d.ts +18 -5
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/tokens.js +1 -1
- package/build/transaction/TransactionFactory.d.ts +18 -5
- package/build/transaction/TransactionFactory.js +22 -2
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/FundingTransaction.js +11 -3
- package/build/transaction/builders/TransactionBuilder.d.ts +2 -2
- package/build/transaction/builders/TransactionBuilder.js +15 -9
- package/{Deploy.md → examples/Deploy.md} +2 -0
- package/{Unwrap.md → examples/Unwrap.md} +2 -0
- package/{Wrap.md → examples/Wrap.md} +2 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/metadata/tokens.ts +135 -135
- package/src/transaction/TransactionFactory.ts +56 -12
- package/src/transaction/builders/FundingTransaction.ts +11 -5
- package/src/transaction/builders/TransactionBuilder.ts +30 -21
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { Transaction } from 'bitcoinjs-lib';
|
|
1
2
|
import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters, IUnwrapParameters, IWrapParameters } from './interfaces/ITransactionParameters.js';
|
|
3
|
+
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
2
4
|
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
3
5
|
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
7
|
+
import { TransactionType } from './enums/TransactionType.js';
|
|
4
8
|
export interface DeploymentResult {
|
|
5
9
|
readonly transaction: [string, string];
|
|
6
10
|
readonly contractAddress: Address;
|
|
@@ -14,6 +18,18 @@ export interface WrapResult {
|
|
|
14
18
|
readonly receiverAddress: Address;
|
|
15
19
|
readonly utxos: UTXO[];
|
|
16
20
|
}
|
|
21
|
+
export interface FundingTransactionResponse {
|
|
22
|
+
readonly tx: Transaction;
|
|
23
|
+
readonly original: FundingTransaction;
|
|
24
|
+
readonly estimatedFees: bigint;
|
|
25
|
+
readonly nextUTXOs: UTXO[];
|
|
26
|
+
}
|
|
27
|
+
export interface BitcoinTransferResponse {
|
|
28
|
+
readonly tx: string;
|
|
29
|
+
readonly original: FundingTransaction;
|
|
30
|
+
readonly estimatedFees: bigint;
|
|
31
|
+
readonly nextUTXOs: UTXO[];
|
|
32
|
+
}
|
|
17
33
|
export interface UnwrapResult {
|
|
18
34
|
readonly fundingTransaction: string;
|
|
19
35
|
readonly psbt: string;
|
|
@@ -27,11 +43,8 @@ export declare class TransactionFactory {
|
|
|
27
43
|
wrap(warpParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
28
44
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
29
45
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
30
|
-
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<
|
|
31
|
-
|
|
32
|
-
tx: string;
|
|
33
|
-
nextUTXOs: UTXO[];
|
|
34
|
-
}>;
|
|
46
|
+
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
47
|
+
getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: Address): UTXO[];
|
|
35
48
|
private createFundTransaction;
|
|
36
49
|
private calculateNumSignatures;
|
|
37
50
|
private calculateNumInputs;
|
|
@@ -4,7 +4,7 @@ import { Signer } from 'bitcoinjs-lib';
|
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
5
|
export declare class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
6
6
|
readonly type: TransactionType.FUNDING;
|
|
7
|
-
protected
|
|
7
|
+
protected amount: bigint;
|
|
8
8
|
protected splitInputsInto: number;
|
|
9
9
|
constructor(parameters: IFundingTransactionParameters);
|
|
10
10
|
protected buildTransaction(): Promise<void>;
|
|
@@ -44,6 +44,8 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
44
44
|
estimateTransactionFees(): Promise<bigint>;
|
|
45
45
|
rebuildFromBase64(base64: string): Promise<Psbt>;
|
|
46
46
|
setPSBT(psbt: Psbt): void;
|
|
47
|
+
getInputs(): PsbtInputExtended[];
|
|
48
|
+
getOutputs(): PsbtOutputExtended[];
|
|
47
49
|
protected addRefundOutput(amountSpent: bigint): Promise<void>;
|
|
48
50
|
protected addValueToToOutput(value: number | bigint): void;
|
|
49
51
|
protected getTransactionOPNetFee(): bigint;
|
|
@@ -55,8 +57,6 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
55
57
|
protected updateInput(input: UpdateInput): void;
|
|
56
58
|
protected getWitness(): Buffer;
|
|
57
59
|
protected getTapOutput(): Buffer;
|
|
58
|
-
protected getInputs(): PsbtInputExtended[];
|
|
59
|
-
protected getOutputs(): PsbtOutputExtended[];
|
|
60
60
|
protected verifyUTXOValidity(): void;
|
|
61
61
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
62
62
|
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.90";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.90';
|
package/build/metadata/tokens.js
CHANGED
|
@@ -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 = '
|
|
14
|
+
export const WBTC_ADDRESS_FRACTAL = 'bc1qdtzlucslvrvu4useyh9r69supqrw3w4xn9t4yv';
|
|
15
15
|
export const MOTO_ADDRESS_FRACTAL = 'bc1qfzq6w5uvgg5489egv0lj4shlqx4dagqt0ewdnu';
|
|
16
16
|
export const ROUTER_ADDRESS_FRACTAL = 'bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn';
|
|
17
17
|
export var OPNetNetwork;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { Transaction } from 'bitcoinjs-lib';
|
|
1
2
|
import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters, IUnwrapParameters, IWrapParameters } from './interfaces/ITransactionParameters.js';
|
|
3
|
+
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
2
4
|
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
3
5
|
import { Address } from '@btc-vision/bsi-binary';
|
|
6
|
+
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
7
|
+
import { TransactionType } from './enums/TransactionType.js';
|
|
4
8
|
export interface DeploymentResult {
|
|
5
9
|
readonly transaction: [string, string];
|
|
6
10
|
readonly contractAddress: Address;
|
|
@@ -14,6 +18,18 @@ export interface WrapResult {
|
|
|
14
18
|
readonly receiverAddress: Address;
|
|
15
19
|
readonly utxos: UTXO[];
|
|
16
20
|
}
|
|
21
|
+
export interface FundingTransactionResponse {
|
|
22
|
+
readonly tx: Transaction;
|
|
23
|
+
readonly original: FundingTransaction;
|
|
24
|
+
readonly estimatedFees: bigint;
|
|
25
|
+
readonly nextUTXOs: UTXO[];
|
|
26
|
+
}
|
|
27
|
+
export interface BitcoinTransferResponse {
|
|
28
|
+
readonly tx: string;
|
|
29
|
+
readonly original: FundingTransaction;
|
|
30
|
+
readonly estimatedFees: bigint;
|
|
31
|
+
readonly nextUTXOs: UTXO[];
|
|
32
|
+
}
|
|
17
33
|
export interface UnwrapResult {
|
|
18
34
|
readonly fundingTransaction: string;
|
|
19
35
|
readonly psbt: string;
|
|
@@ -27,11 +43,8 @@ export declare class TransactionFactory {
|
|
|
27
43
|
wrap(warpParameters: Omit<IWrapParameters, 'calldata'>): Promise<WrapResult>;
|
|
28
44
|
unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
29
45
|
unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
|
|
30
|
-
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<
|
|
31
|
-
|
|
32
|
-
tx: string;
|
|
33
|
-
nextUTXOs: UTXO[];
|
|
34
|
-
}>;
|
|
46
|
+
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
47
|
+
getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: Address): UTXO[];
|
|
35
48
|
private createFundTransaction;
|
|
36
49
|
private calculateNumSignatures;
|
|
37
50
|
private calculateNumInputs;
|
|
@@ -230,11 +230,30 @@ export class TransactionFactory {
|
|
|
230
230
|
const resp = await this.createFundTransaction(parameters);
|
|
231
231
|
return {
|
|
232
232
|
estimatedFees: resp.estimatedFees,
|
|
233
|
+
original: resp.original,
|
|
233
234
|
tx: resp.tx.toHex(),
|
|
234
|
-
nextUTXOs: this.
|
|
235
|
+
nextUTXOs: this.getAllNewUTXOs(resp.original, resp.tx, parameters.from),
|
|
235
236
|
};
|
|
236
237
|
}
|
|
238
|
+
getAllNewUTXOs(original, tx, to) {
|
|
239
|
+
const outputs = original.getOutputs();
|
|
240
|
+
const utxos = [];
|
|
241
|
+
for (let i = 0; i < tx.outs.length; i++) {
|
|
242
|
+
const output = outputs[i];
|
|
243
|
+
if ('address' in output) {
|
|
244
|
+
if (output.address !== to)
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
continue;
|
|
249
|
+
}
|
|
250
|
+
utxos.push(...this.getUTXOAsTransaction(tx, to, i));
|
|
251
|
+
}
|
|
252
|
+
return utxos;
|
|
253
|
+
}
|
|
237
254
|
async createFundTransaction(parameters) {
|
|
255
|
+
if (!parameters.to)
|
|
256
|
+
throw new Error('Field "to" not provided.');
|
|
238
257
|
const fundingTransaction = new FundingTransaction(parameters);
|
|
239
258
|
const signedTransaction = await fundingTransaction.signTransaction();
|
|
240
259
|
if (!signedTransaction) {
|
|
@@ -243,7 +262,8 @@ export class TransactionFactory {
|
|
|
243
262
|
return {
|
|
244
263
|
tx: signedTransaction,
|
|
245
264
|
original: fundingTransaction,
|
|
246
|
-
estimatedFees:
|
|
265
|
+
estimatedFees: fundingTransaction.estimatedFees,
|
|
266
|
+
nextUTXOs: this.getUTXOAsTransaction(signedTransaction, parameters.to, 0),
|
|
247
267
|
};
|
|
248
268
|
}
|
|
249
269
|
calculateNumSignatures(vault) {
|
|
@@ -4,7 +4,7 @@ import { Signer } from 'bitcoinjs-lib';
|
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
5
|
export declare class FundingTransaction extends TransactionBuilder<TransactionType.FUNDING> {
|
|
6
6
|
readonly type: TransactionType.FUNDING;
|
|
7
|
-
protected
|
|
7
|
+
protected amount: bigint;
|
|
8
8
|
protected splitInputsInto: number;
|
|
9
9
|
constructor(parameters: IFundingTransactionParameters);
|
|
10
10
|
protected buildTransaction(): Promise<void>;
|
|
@@ -2,11 +2,11 @@ import { TransactionType } from '../enums/TransactionType.js';
|
|
|
2
2
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
3
3
|
export class FundingTransaction extends TransactionBuilder {
|
|
4
4
|
type = TransactionType.FUNDING;
|
|
5
|
-
|
|
5
|
+
amount;
|
|
6
6
|
splitInputsInto;
|
|
7
7
|
constructor(parameters) {
|
|
8
8
|
super(parameters);
|
|
9
|
-
this.
|
|
9
|
+
this.amount = parameters.amount;
|
|
10
10
|
this.splitInputsInto = parameters.splitInputsInto ?? 1;
|
|
11
11
|
this.internalInit();
|
|
12
12
|
}
|
|
@@ -15,7 +15,15 @@ export class FundingTransaction extends TransactionBuilder {
|
|
|
15
15
|
throw new Error('Recipient address is required');
|
|
16
16
|
}
|
|
17
17
|
this.addInputsFromUTXO();
|
|
18
|
-
|
|
18
|
+
let amountSpent = this.amount;
|
|
19
|
+
if (this.getTransactionOPNetFee() === TransactionBuilder.MINIMUM_DUST) {
|
|
20
|
+
if (amountSpent < TransactionBuilder.MINIMUM_DUST) {
|
|
21
|
+
amountSpent += TransactionBuilder.MINIMUM_DUST;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
amountSpent += this.getTransactionOPNetFee();
|
|
26
|
+
}
|
|
19
27
|
if (this.splitInputsInto > 1) {
|
|
20
28
|
await this.splitInputs(amountSpent);
|
|
21
29
|
}
|
|
@@ -44,6 +44,8 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
44
44
|
estimateTransactionFees(): Promise<bigint>;
|
|
45
45
|
rebuildFromBase64(base64: string): Promise<Psbt>;
|
|
46
46
|
setPSBT(psbt: Psbt): void;
|
|
47
|
+
getInputs(): PsbtInputExtended[];
|
|
48
|
+
getOutputs(): PsbtOutputExtended[];
|
|
47
49
|
protected addRefundOutput(amountSpent: bigint): Promise<void>;
|
|
48
50
|
protected addValueToToOutput(value: number | bigint): void;
|
|
49
51
|
protected getTransactionOPNetFee(): bigint;
|
|
@@ -55,8 +57,6 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
|
|
|
55
57
|
protected updateInput(input: UpdateInput): void;
|
|
56
58
|
protected getWitness(): Buffer;
|
|
57
59
|
protected getTapOutput(): Buffer;
|
|
58
|
-
protected getInputs(): PsbtInputExtended[];
|
|
59
|
-
protected getOutputs(): PsbtOutputExtended[];
|
|
60
60
|
protected verifyUTXOValidity(): void;
|
|
61
61
|
protected setFeeOutput(output: PsbtOutputExtended): Promise<void>;
|
|
62
62
|
protected internalBuildTransaction(transaction: Psbt): Promise<boolean>;
|
|
@@ -95,6 +95,9 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
95
95
|
this._maximumFeeRate = feeRate;
|
|
96
96
|
}
|
|
97
97
|
async signTransaction() {
|
|
98
|
+
if (!this.utxos.length) {
|
|
99
|
+
throw new Error('No UTXOs specified');
|
|
100
|
+
}
|
|
98
101
|
if (this.to && !EcKeyPair.verifyContractAddress(this.to, this.network)) {
|
|
99
102
|
throw new Error('Invalid contract address. The contract address must be a taproot address.');
|
|
100
103
|
}
|
|
@@ -151,6 +154,9 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
151
154
|
return this.tapData?.address;
|
|
152
155
|
}
|
|
153
156
|
async estimateTransactionFees() {
|
|
157
|
+
if (!this.utxos.length) {
|
|
158
|
+
throw new Error('No UTXOs specified');
|
|
159
|
+
}
|
|
154
160
|
if (this.estimatedFees)
|
|
155
161
|
return this.estimatedFees;
|
|
156
162
|
const fakeTx = new Psbt({
|
|
@@ -177,6 +183,15 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
177
183
|
setPSBT(psbt) {
|
|
178
184
|
this.transaction = psbt;
|
|
179
185
|
}
|
|
186
|
+
getInputs() {
|
|
187
|
+
return this.inputs;
|
|
188
|
+
}
|
|
189
|
+
getOutputs() {
|
|
190
|
+
const outputs = [...this.outputs];
|
|
191
|
+
if (this.feeOutput)
|
|
192
|
+
outputs.push(this.feeOutput);
|
|
193
|
+
return outputs;
|
|
194
|
+
}
|
|
180
195
|
async addRefundOutput(amountSpent) {
|
|
181
196
|
const sendBackAmount = this.totalInputAmount - amountSpent;
|
|
182
197
|
if (sendBackAmount >= TransactionBuilder.MINIMUM_DUST) {
|
|
@@ -263,15 +278,6 @@ export class TransactionBuilder extends TweakedTransaction {
|
|
|
263
278
|
}
|
|
264
279
|
return this.tapData.output;
|
|
265
280
|
}
|
|
266
|
-
getInputs() {
|
|
267
|
-
return this.inputs;
|
|
268
|
-
}
|
|
269
|
-
getOutputs() {
|
|
270
|
-
const outputs = [...this.outputs];
|
|
271
|
-
if (this.feeOutput)
|
|
272
|
-
outputs.push(this.feeOutput);
|
|
273
|
-
return outputs;
|
|
274
|
-
}
|
|
275
281
|
verifyUTXOValidity() {
|
|
276
282
|
for (let utxo of this.utxos) {
|
|
277
283
|
if (!utxo.scriptPubKey) {
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Deploying a Smart Contract on OPNet
|
|
2
2
|
|
|
3
|
+
WARNING: POSSIBLY OUTDATED
|
|
4
|
+
|
|
3
5
|
This guide will walk you through the process of deploying a smart contract on the OPNet protocol. OPNet allows for the
|
|
4
6
|
execution of smart contracts on the Bitcoin network, leveraging the security and stability of Bitcoin.
|
|
5
7
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Unwrapping wBTC Guide
|
|
2
2
|
|
|
3
|
+
WARNING: POSSIBLY OUTDATED
|
|
4
|
+
|
|
3
5
|
This guide will walk you through the process of unwrapping wBTC (Wrapped Bitcoin) using the OPNet protocol. Unwrapping
|
|
4
6
|
wBTC converts it back into regular Bitcoin, enabling you to use it directly on the Bitcoin network.
|
|
5
7
|
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Wrapping Bitcoin (wBTC) Guide
|
|
2
2
|
|
|
3
|
+
WARNING: POSSIBLY OUTDATED
|
|
4
|
+
|
|
3
5
|
This guide will walk you through the process of wrapping Bitcoin (wBTC) using the OPNet protocol. Wrapping Bitcoin
|
|
4
6
|
allows you to use Bitcoin in smart contracts, similar to how ERC-20 tokens are used on Ethereum.
|
|
5
7
|
|
package/package.json
CHANGED
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.90';
|
package/src/metadata/tokens.ts
CHANGED
|
@@ -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 = '
|
|
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 = '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();
|