@btc-vision/transaction 1.0.51 → 1.0.53
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/metadata/tokens.d.ts +5 -5
- package/browser/transaction/browser/Web3Provider.d.ts +6 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/contracts/wBTC.js +2 -1
- package/build/metadata/tokens.d.ts +5 -5
- package/build/metadata/tokens.js +5 -5
- package/build/tests/factory/createPairReg.js +3 -3
- package/build/tests/moto/airdropToken.js +3 -3
- package/build/tests/moto/airdropTokens.d.ts +1 -0
- package/build/tests/moto/airdropTokens.js +60 -0
- package/build/tests/moto/allowance.js +2 -3
- package/build/tests/moto/approve.js +3 -4
- package/build/tests/moto/balanceOf.js +1 -2
- package/build/tests/moto/transfer.js +2 -2
- package/build/tests/motoswap/deployMoto.js +2 -0
- package/build/tests/motoswap/deployPool.js +1 -1
- package/build/tests/motoswap/routerAddLiquidity.js +3 -4
- package/build/tests/pool/DecodePoolAddress.d.ts +6 -0
- package/build/tests/pool/DecodePoolAddress.js +12 -0
- package/build/tests/pool/decodeReserves.d.ts +5 -0
- package/build/tests/pool/decodeReserves.js +13 -0
- package/build/tests/pool/reserves.d.ts +1 -0
- package/build/tests/pool/reserves.js +10 -0
- package/build/tests/shared/interaction.d.ts +2 -1
- package/build/tests/shared/interaction.js +12 -6
- package/build/tests/wbtc/approve.js +3 -3
- package/build/tests/wbtc/wrapReg.js +2 -5
- package/build/transaction/browser/Web3Provider.d.ts +6 -0
- package/build/utxo/OPNetLimitedProvider.js +2 -2
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/metadata/contracts/wBTC.ts +2 -1
- package/src/metadata/tokens.ts +5 -5
- package/src/transaction/browser/Web3Provider.ts +11 -0
- package/src/utxo/OPNetLimitedProvider.ts +2 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
2
|
+
export declare const FACTORY_ADDRESS_REGTEST: Address;
|
|
3
|
+
export declare const POOL_ADDRESS_REGTEST: Address;
|
|
4
|
+
export declare const WBTC_ADDRESS_REGTEST: Address;
|
|
5
|
+
export declare const MOTO_ADDRESS_REGTEST: Address;
|
|
6
|
+
export declare const ROUTER_ADDRESS_REGTEST: Address;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
2
2
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
3
3
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
|
|
4
|
+
export interface BroadcastTransactionOptions {
|
|
5
|
+
raw: string;
|
|
6
|
+
psbt: boolean;
|
|
7
|
+
}
|
|
4
8
|
export interface BroadcastedTransaction {
|
|
5
9
|
readonly success: boolean;
|
|
6
10
|
readonly result?: string;
|
|
@@ -10,4 +14,6 @@ export interface BroadcastedTransaction {
|
|
|
10
14
|
}
|
|
11
15
|
export interface Web3Provider {
|
|
12
16
|
signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
17
|
+
signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
18
|
+
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
13
19
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.53";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.53';
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { networks } from 'bitcoinjs-lib';
|
|
2
2
|
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
3
|
+
import { WBTC_ADDRESS_REGTEST } from '../tokens.js';
|
|
3
4
|
export class wBTC extends ContractBaseMetadata {
|
|
4
5
|
network;
|
|
5
6
|
tokenName = 'Wrapped Bitcoin';
|
|
@@ -16,7 +17,7 @@ export class wBTC extends ContractBaseMetadata {
|
|
|
16
17
|
case networks.bitcoin.bech32:
|
|
17
18
|
return 'unknown';
|
|
18
19
|
case networks.regtest.bech32:
|
|
19
|
-
return
|
|
20
|
+
return WBTC_ADDRESS_REGTEST;
|
|
20
21
|
case networks.testnet.bech32:
|
|
21
22
|
return 'tb1qj58a6yf4pez426nqvf8wyu6ssggcajw8kr44vy';
|
|
22
23
|
default:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare const
|
|
2
|
+
export declare const FACTORY_ADDRESS_REGTEST: Address;
|
|
3
|
+
export declare const POOL_ADDRESS_REGTEST: Address;
|
|
4
|
+
export declare const WBTC_ADDRESS_REGTEST: Address;
|
|
5
|
+
export declare const MOTO_ADDRESS_REGTEST: Address;
|
|
6
|
+
export declare const ROUTER_ADDRESS_REGTEST: Address;
|
package/build/metadata/tokens.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export const
|
|
2
|
-
export const
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
1
|
+
export const FACTORY_ADDRESS_REGTEST = 'bcrt1qgph2k9dahptnz2vu72ezd9r2p4phjm2pkgu7ht';
|
|
2
|
+
export const POOL_ADDRESS_REGTEST = 'bcrt1q5nkjpjmh6xwweprcyeylwdw7aud4een7p9pphd';
|
|
3
|
+
export const WBTC_ADDRESS_REGTEST = 'bcrt1qefq0lwqwpt5lx7hl2dr2r8q6z063725tccuqrg';
|
|
4
|
+
export const MOTO_ADDRESS_REGTEST = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
5
|
+
export const ROUTER_ADDRESS_REGTEST = 'bcrt1qyx492l440f6cm5hdppw5pmkd2fc7k3qayuuvh6';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
-
import {
|
|
2
|
+
import { MOTO_ADDRESS_REGTEST, WBTC_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
3
3
|
const abiCoder = new ABICoder();
|
|
4
4
|
const createPoolSelector = Number(`0x` + abiCoder.encodeSelector('createPool'));
|
|
5
5
|
function generateCalldata() {
|
|
6
6
|
const addCalldata = new BinaryWriter();
|
|
7
7
|
addCalldata.writeSelector(createPoolSelector);
|
|
8
|
-
addCalldata.writeAddress(
|
|
9
|
-
addCalldata.writeAddress(
|
|
8
|
+
addCalldata.writeAddress(WBTC_ADDRESS_REGTEST);
|
|
9
|
+
addCalldata.writeAddress(MOTO_ADDRESS_REGTEST);
|
|
10
10
|
return Buffer.from(addCalldata.getBuffer());
|
|
11
11
|
}
|
|
12
12
|
const calldata = generateCalldata();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
2
|
import { interact } from '../shared/interaction.js';
|
|
3
|
-
import {
|
|
3
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
4
4
|
const abiCoder = new ABICoder();
|
|
5
5
|
const airdropSelector = Number(`0x` + abiCoder.encodeSelector('airdrop'));
|
|
6
6
|
function expandToDecimals(n, decimals = 18n) {
|
|
@@ -15,7 +15,7 @@ function airdropToken(amount, to) {
|
|
|
15
15
|
return Buffer.from(calldata.getBuffer());
|
|
16
16
|
}
|
|
17
17
|
const tokenAmount = expandToDecimals(1000, 8n);
|
|
18
|
-
const receiver = '
|
|
18
|
+
const receiver = 'bcrt1pst60scy2zdyxkfzqs593aevx2jypah32zzjjx2kmz57yzf228wjq5wtyc5';
|
|
19
19
|
const calldata = airdropToken(tokenAmount, receiver);
|
|
20
20
|
console.log('airdrop ->', calldata.toString('hex'));
|
|
21
|
-
await interact(
|
|
21
|
+
await interact(MOTO_ADDRESS_REGTEST, calldata);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact } from '../shared/interaction.js';
|
|
3
|
+
const abiCoder = new ABICoder();
|
|
4
|
+
const airdropSelector = Number(`0x` + abiCoder.encodeSelector('airdropDefined'));
|
|
5
|
+
function expandToDecimals(n, decimals = 18n) {
|
|
6
|
+
return BigInt(n) * 10n ** decimals;
|
|
7
|
+
}
|
|
8
|
+
function generateFakeAddress() {
|
|
9
|
+
const prefix = 'bcrt1';
|
|
10
|
+
const base58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
11
|
+
const addressLength = 59;
|
|
12
|
+
let address = prefix;
|
|
13
|
+
while (address.length < addressLength) {
|
|
14
|
+
const randomIndex = Math.floor(Math.random() * base58Chars.length);
|
|
15
|
+
address += base58Chars[randomIndex];
|
|
16
|
+
}
|
|
17
|
+
return address;
|
|
18
|
+
}
|
|
19
|
+
const tokenAmount = expandToDecimals(10, 8n);
|
|
20
|
+
const amountOfWallets = 85;
|
|
21
|
+
const maxMB = 1;
|
|
22
|
+
const maxBytes = maxMB * 1024 * 1024;
|
|
23
|
+
function generateAirdropCalldata(tokenAmount) {
|
|
24
|
+
const calldata = new BinaryWriter();
|
|
25
|
+
calldata.writeSelector(airdropSelector);
|
|
26
|
+
calldata.writeU256(tokenAmount);
|
|
27
|
+
calldata.writeU32(amountOfWallets * 2);
|
|
28
|
+
for (let i = 0; i < amountOfWallets; i++) {
|
|
29
|
+
const taprootAddress = generateFakeAddress();
|
|
30
|
+
calldata.writeAddress(taprootAddress);
|
|
31
|
+
calldata.writeAddress(taprootAddress);
|
|
32
|
+
}
|
|
33
|
+
const buf = Buffer.from(calldata.getBuffer());
|
|
34
|
+
if (buf.byteLength > maxBytes) {
|
|
35
|
+
throw new Error(`Calldata too big. Max size: ${maxMB} MB`);
|
|
36
|
+
}
|
|
37
|
+
console.log('calldata', buf.toString('hex'));
|
|
38
|
+
return buf;
|
|
39
|
+
}
|
|
40
|
+
async function sendTx() {
|
|
41
|
+
const calldata = generateAirdropCalldata(tokenAmount);
|
|
42
|
+
console.log(`Calldata generated. Raw size: ${calldata.byteLength} bytes`);
|
|
43
|
+
const interaction = await interact('bcrt1qdzueflfht0ctk6agpyndh5f8wydsxy2dmz737p', calldata, false, [], 5, 100000n);
|
|
44
|
+
if (!interaction) {
|
|
45
|
+
throw new Error('No interaction');
|
|
46
|
+
}
|
|
47
|
+
const broadcast = interaction[1];
|
|
48
|
+
if (!broadcast) {
|
|
49
|
+
throw new Error('No broadcast');
|
|
50
|
+
}
|
|
51
|
+
console.log('sent tx', broadcast);
|
|
52
|
+
}
|
|
53
|
+
for (let i = 0; i < 1; i++) {
|
|
54
|
+
try {
|
|
55
|
+
await sendTx();
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
i--;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { wallet } from '../shared/interaction.js';
|
|
1
|
+
import { ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
3
2
|
import { allowance } from '../writers/allowance.js';
|
|
4
|
-
const calldata = allowance(
|
|
3
|
+
const calldata = allowance('bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2', ROUTER_ADDRESS_REGTEST);
|
|
5
4
|
console.log('allowance ->', calldata.toString('hex'));
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { approve, MAX_UINT256 } from '../writers/approve.js';
|
|
2
|
-
import {
|
|
2
|
+
import { MOTO_ADDRESS_REGTEST, ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
3
3
|
import { interact } from '../shared/interaction.js';
|
|
4
|
-
const calldata = approve(
|
|
4
|
+
const calldata = approve(ROUTER_ADDRESS_REGTEST, MAX_UINT256);
|
|
5
5
|
console.log('approve ->', calldata.toString('hex'));
|
|
6
|
-
const interaction = await interact(
|
|
6
|
+
const interaction = await interact(MOTO_ADDRESS_REGTEST, calldata, false);
|
|
7
7
|
console.log(interaction);
|
|
8
8
|
if (!interaction) {
|
|
9
9
|
throw new Error('Interaction failed');
|
|
10
10
|
}
|
|
11
|
-
const interaction2 = await interact(MOTO_ADDRESS, calldata, false, interaction[2]);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
-
import { wallet } from '../shared/interaction.js';
|
|
3
2
|
const abiCoder = new ABICoder();
|
|
4
3
|
const balanceSelector = Number(`0x` + abiCoder.encodeSelector('balanceOf'));
|
|
5
4
|
function balanceOf(to) {
|
|
@@ -8,6 +7,6 @@ function balanceOf(to) {
|
|
|
8
7
|
calldata.writeAddress(to);
|
|
9
8
|
return Buffer.from(calldata.getBuffer());
|
|
10
9
|
}
|
|
11
|
-
const receiver =
|
|
10
|
+
const receiver = 'bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2';
|
|
12
11
|
const calldata = balanceOf(receiver);
|
|
13
12
|
console.log('balanceOf ->', calldata.toString('hex'));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
2
|
import { interact } from '../shared/interaction.js';
|
|
3
3
|
import { expandToDecimals } from '../shared/Utils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
5
5
|
const abiCoder = new ABICoder();
|
|
6
6
|
const transferSelector = Number(`0x` + abiCoder.encodeSelector('transfer'));
|
|
7
7
|
function getTransferToCalldata(to, amount) {
|
|
@@ -13,4 +13,4 @@ function getTransferToCalldata(to, amount) {
|
|
|
13
13
|
}
|
|
14
14
|
const tokenAmount = expandToDecimals(250, 8n);
|
|
15
15
|
const calldata = getTransferToCalldata('bcrt1pst60scy2zdyxkfzqs593aevx2jypah32zzjjx2kmz57yzf228wjq5wtyc5', tokenAmount);
|
|
16
|
-
await interact(
|
|
16
|
+
await interact(MOTO_ADDRESS_REGTEST, calldata, false);
|
|
@@ -27,10 +27,12 @@ const utxoSetting = {
|
|
|
27
27
|
minAmount: 10000n,
|
|
28
28
|
requestedAmount: requestedAmount,
|
|
29
29
|
};
|
|
30
|
+
console.log('Fetching UTXOs');
|
|
30
31
|
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
31
32
|
if (!utxos) {
|
|
32
33
|
throw new Error('No UTXOs found');
|
|
33
34
|
}
|
|
35
|
+
console.log('Shuffling UTXOs', utxos.length);
|
|
34
36
|
shuffleArray(utxos);
|
|
35
37
|
export async function deployMoto(contracts) {
|
|
36
38
|
let deployed = [];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { deployMoto } from './deployMoto.js';
|
|
2
2
|
console.log(`Step 1: Deploying MotoSwap contracts`);
|
|
3
|
-
const contractsToDeploy = ['./bytecode/
|
|
3
|
+
const contractsToDeploy = ['./bytecode/moto.wasm'];
|
|
4
4
|
const contracts = await deployMoto(contractsToDeploy);
|
|
5
5
|
console.log(`Contracts deployed:`, contracts);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
-
import {
|
|
2
|
+
import { wallet } from '../shared/interaction.js';
|
|
3
3
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
4
4
|
import { networks } from 'bitcoinjs-lib';
|
|
5
|
-
import {
|
|
5
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
6
6
|
import { expandToDecimals } from '../shared/Utils.js';
|
|
7
7
|
const abiCoder = new ABICoder();
|
|
8
8
|
const addLiquiditySelector = Number(`0x` + abiCoder.encodeSelector('addLiquidity'));
|
|
@@ -23,7 +23,7 @@ const token0Amount = expandToDecimals(1000, 8n);
|
|
|
23
23
|
const token1Amount = 600000n;
|
|
24
24
|
const receiver = wallet.p2tr;
|
|
25
25
|
const calldata = addLiquidity({
|
|
26
|
-
tokenA:
|
|
26
|
+
tokenA: MOTO_ADDRESS_REGTEST,
|
|
27
27
|
tokenB: wBTC.getAddress(networks.regtest),
|
|
28
28
|
amountADesired: token0Amount,
|
|
29
29
|
amountBDesired: token1Amount,
|
|
@@ -33,4 +33,3 @@ const calldata = addLiquidity({
|
|
|
33
33
|
deadline: 5000n,
|
|
34
34
|
});
|
|
35
35
|
console.log('add liquidity:', calldata.toString('hex'));
|
|
36
|
-
await interact(ROUTER_ADDRESS, calldata);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BinaryReader } from '@btc-vision/bsi-binary';
|
|
2
|
+
function decodeTransferEvent(data) {
|
|
3
|
+
const reader = new BinaryReader(data);
|
|
4
|
+
const from = reader.readAddress();
|
|
5
|
+
const to = reader.readAddress();
|
|
6
|
+
const value = reader.readU256();
|
|
7
|
+
return { from, to, value };
|
|
8
|
+
}
|
|
9
|
+
const transferEventData = Buffer.from('YmNydDFwcHFrMzZhenl1bnhkcGFkemE3Z3RmNTY4ZWxxeG5odTNsd3VmZzk4ZGFlazNrejA3Mzkwc3d5dnpkMgBiY3J0MXFwaDRqejZkbXc1dW53bThnc2M1dTRxbXkwbXF0bjVkOGF2bHhqNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9CQA==', 'base64');
|
|
10
|
+
const bytes = Uint8Array.from(transferEventData);
|
|
11
|
+
const transferEvent = decodeTransferEvent(bytes);
|
|
12
|
+
console.log(transferEvent);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BinaryReader } from '@btc-vision/bsi-binary';
|
|
2
|
+
function decodeReserves(data) {
|
|
3
|
+
const reader = new BinaryReader(data);
|
|
4
|
+
return {
|
|
5
|
+
reserve0: reader.readU256(),
|
|
6
|
+
reserve1: reader.readU256(),
|
|
7
|
+
blockTimestampLast: reader.readU64(),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const transferEventData = Buffer.from('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlxkHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACGd9QMYGAAAAAAAA', 'base64');
|
|
11
|
+
const bytes = Uint8Array.from(transferEventData);
|
|
12
|
+
const transferEvent = decodeReserves(bytes);
|
|
13
|
+
console.log(transferEvent);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
const abiCoder = new ABICoder();
|
|
3
|
+
const reservesSelector = Number(`0x` + abiCoder.encodeSelector('getReserves'));
|
|
4
|
+
function getReserves() {
|
|
5
|
+
const calldata = new BinaryWriter();
|
|
6
|
+
calldata.writeSelector(reservesSelector);
|
|
7
|
+
return Buffer.from(calldata.getBuffer());
|
|
8
|
+
}
|
|
9
|
+
const calldata = getReserves();
|
|
10
|
+
console.log('reserves ->', calldata.toString('hex'));
|
|
@@ -2,5 +2,6 @@
|
|
|
2
2
|
import { Wallet } from '../../keypair/Wallet.js';
|
|
3
3
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
4
4
|
import { Address } from '@btc-vision/bsi-binary';
|
|
5
|
+
import { BroadcastResponse } from '../../utxo/interfaces/BroadcastResponse.js';
|
|
5
6
|
export declare const wallet: Wallet;
|
|
6
|
-
export declare function interact(contract: Address, calldata: Buffer, mine?: boolean, UTXOs?: UTXO[]): Promise<[string, string, UTXO[]] | undefined>;
|
|
7
|
+
export declare function interact(contract: Address, calldata: Buffer, mine?: boolean, UTXOs?: UTXO[], feeRate?: number, priorityFee?: bigint): Promise<[[string, string, UTXO[]] | undefined, BroadcastResponse | undefined]>;
|
|
@@ -19,7 +19,7 @@ async function mineBlock() {
|
|
|
19
19
|
return !!ok.length;
|
|
20
20
|
}
|
|
21
21
|
await rpc.init(Regtest.config);
|
|
22
|
-
const requestedAmount = 10n ** 8n *
|
|
22
|
+
const requestedAmount = 10n ** 8n * 500n;
|
|
23
23
|
const utxoSetting = {
|
|
24
24
|
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
25
25
|
minAmount: 10000n,
|
|
@@ -30,7 +30,14 @@ shuffleArray(utxos);
|
|
|
30
30
|
if (!utxos) {
|
|
31
31
|
throw new Error('No UTXOs found');
|
|
32
32
|
}
|
|
33
|
-
export async function interact(contract, calldata, mine = false, UTXOs = utxos) {
|
|
33
|
+
export async function interact(contract, calldata, mine = false, UTXOs = utxos, feeRate = 450, priorityFee = 10000n) {
|
|
34
|
+
if (!UTXOs.length) {
|
|
35
|
+
UTXOs = utxos;
|
|
36
|
+
}
|
|
37
|
+
if (!UTXOs.length) {
|
|
38
|
+
throw new Error('No UTXOs found');
|
|
39
|
+
}
|
|
40
|
+
let txid;
|
|
34
41
|
let finalTx;
|
|
35
42
|
for (let i = 0; i < UTXOs.length; i += 1) {
|
|
36
43
|
let utxo = UTXOs[i];
|
|
@@ -40,13 +47,12 @@ export async function interact(contract, calldata, mine = false, UTXOs = utxos)
|
|
|
40
47
|
utxos: [utxo],
|
|
41
48
|
signer: wallet.keypair,
|
|
42
49
|
network: network,
|
|
43
|
-
feeRate:
|
|
44
|
-
priorityFee:
|
|
50
|
+
feeRate: feeRate,
|
|
51
|
+
priorityFee: priorityFee,
|
|
45
52
|
calldata: calldata,
|
|
46
53
|
};
|
|
47
54
|
try {
|
|
48
55
|
finalTx = await factory.signInteraction(interactionParameters);
|
|
49
|
-
let txid;
|
|
50
56
|
try {
|
|
51
57
|
txid = await utxoManager.broadcastTransaction(finalTx[0], false);
|
|
52
58
|
console.log(`Transaction ID:`, txid);
|
|
@@ -75,5 +81,5 @@ export async function interact(contract, calldata, mine = false, UTXOs = utxos)
|
|
|
75
81
|
await mineBlock();
|
|
76
82
|
}
|
|
77
83
|
rpc.destroy();
|
|
78
|
-
return finalTx;
|
|
84
|
+
return [finalTx, txid];
|
|
79
85
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { approve, MAX_UINT256 } from '../writers/approve.js';
|
|
2
|
-
import {
|
|
2
|
+
import { ROUTER_ADDRESS_REGTEST, WBTC_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
3
3
|
import { interact } from '../shared/interaction.js';
|
|
4
|
-
const calldata = approve(
|
|
4
|
+
const calldata = approve(ROUTER_ADDRESS_REGTEST, MAX_UINT256);
|
|
5
5
|
console.log('approve ->', calldata.toString('hex'));
|
|
6
|
-
await interact(
|
|
6
|
+
await interact(WBTC_ADDRESS_REGTEST, calldata, false);
|
|
@@ -20,7 +20,7 @@ async function mineBlock() {
|
|
|
20
20
|
return !!ok.length;
|
|
21
21
|
}
|
|
22
22
|
await rpc.init(Regtest.config);
|
|
23
|
-
const wrapAmount =
|
|
23
|
+
const wrapAmount = 5n * 100000000n;
|
|
24
24
|
const utxoSetting = {
|
|
25
25
|
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
26
26
|
minAmount: 10000n,
|
|
@@ -41,7 +41,7 @@ const wrapParameters = {
|
|
|
41
41
|
network: network,
|
|
42
42
|
feeRate: 500,
|
|
43
43
|
priorityFee: 100000n,
|
|
44
|
-
receiver:
|
|
44
|
+
receiver: 'bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2',
|
|
45
45
|
amount: wrapAmount,
|
|
46
46
|
generationParameters: generationParameters,
|
|
47
47
|
};
|
|
@@ -61,8 +61,5 @@ console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
|
61
61
|
if (!secondTxBroadcast) {
|
|
62
62
|
throw new Error('Could not broadcast second transaction');
|
|
63
63
|
}
|
|
64
|
-
if (shouldMineBlock) {
|
|
65
|
-
await mineBlock();
|
|
66
|
-
}
|
|
67
64
|
rpc.destroy();
|
|
68
65
|
console.log(`Wrapped ${wrapAmount} sats to ${wallet.p2tr}.`);
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
2
2
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
3
3
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
|
|
4
|
+
export interface BroadcastTransactionOptions {
|
|
5
|
+
raw: string;
|
|
6
|
+
psbt: boolean;
|
|
7
|
+
}
|
|
4
8
|
export interface BroadcastedTransaction {
|
|
5
9
|
readonly success: boolean;
|
|
6
10
|
readonly result?: string;
|
|
@@ -10,4 +14,6 @@ export interface BroadcastedTransaction {
|
|
|
10
14
|
}
|
|
11
15
|
export interface Web3Provider {
|
|
12
16
|
signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
17
|
+
signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
18
|
+
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
13
19
|
}
|
|
@@ -104,7 +104,7 @@ export class OPNetLimitedProvider {
|
|
|
104
104
|
try {
|
|
105
105
|
const resp = await fetch(url, params);
|
|
106
106
|
if (!resp.ok) {
|
|
107
|
-
throw new Error(`Failed to fetch
|
|
107
|
+
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
108
108
|
}
|
|
109
109
|
const fetchedData = await resp.json();
|
|
110
110
|
if (!fetchedData) {
|
|
@@ -112,7 +112,7 @@ export class OPNetLimitedProvider {
|
|
|
112
112
|
}
|
|
113
113
|
const result = fetchedData.result;
|
|
114
114
|
if (!result) {
|
|
115
|
-
throw new Error('No
|
|
115
|
+
throw new Error('No rpc parameters found');
|
|
116
116
|
}
|
|
117
117
|
if ('error' in result) {
|
|
118
118
|
throw new Error(`Error in fetching to rpc ${result.error}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"author": "BlobMaster41",
|
|
5
5
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
6
6
|
"engines": {
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
88
88
|
"@bitcoinerlab/secp256k1": "^1.1.1",
|
|
89
|
-
"@btc-vision/bsi-binary": "^1.0.
|
|
89
|
+
"@btc-vision/bsi-binary": "^1.0.37",
|
|
90
90
|
"@btc-vision/bsi-bitcoin-rpc": "^1.0.22",
|
|
91
91
|
"@btc-vision/bsi-common": "^1.0.16",
|
|
92
92
|
"@btc-vision/logger": "^1.0.2",
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.53';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Network, networks } from 'bitcoinjs-lib';
|
|
2
2
|
import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
|
|
3
3
|
import { Address } from '@btc-vision/bsi-binary';
|
|
4
|
+
import { WBTC_ADDRESS_REGTEST } from '../tokens.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @description Wrapped Bitcoin (wBTC) contract metadata.
|
|
@@ -34,7 +35,7 @@ export class wBTC extends ContractBaseMetadata {
|
|
|
34
35
|
case networks.bitcoin.bech32:
|
|
35
36
|
return 'unknown';
|
|
36
37
|
case networks.regtest.bech32:
|
|
37
|
-
return
|
|
38
|
+
return WBTC_ADDRESS_REGTEST;
|
|
38
39
|
case networks.testnet.bech32:
|
|
39
40
|
return 'tb1qj58a6yf4pez426nqvf8wyu6ssggcajw8kr44vy';
|
|
40
41
|
default:
|
package/src/metadata/tokens.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Address } from '@btc-vision/bsi-binary';
|
|
2
2
|
|
|
3
|
-
export const
|
|
4
|
-
export const
|
|
5
|
-
export const
|
|
6
|
-
export const
|
|
7
|
-
export const
|
|
3
|
+
export const FACTORY_ADDRESS_REGTEST: Address = 'bcrt1qgph2k9dahptnz2vu72ezd9r2p4phjm2pkgu7ht';
|
|
4
|
+
export const POOL_ADDRESS_REGTEST: Address = 'bcrt1q5nkjpjmh6xwweprcyeylwdw7aud4een7p9pphd';
|
|
5
|
+
export const WBTC_ADDRESS_REGTEST: Address = 'bcrt1qefq0lwqwpt5lx7hl2dr2r8q6z063725tccuqrg';
|
|
6
|
+
export const MOTO_ADDRESS_REGTEST: Address = 'bcrt1q8reuxx9naek4mqesrfsgdpjv3q7a5g2llkh6ua';
|
|
7
|
+
export const ROUTER_ADDRESS_REGTEST: Address = 'bcrt1qyx492l440f6cm5hdppw5pmkd2fc7k3qayuuvh6';
|
|
@@ -3,6 +3,11 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
|
3
3
|
|
|
4
4
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>; //| 'utxos'
|
|
5
5
|
|
|
6
|
+
export interface BroadcastTransactionOptions {
|
|
7
|
+
raw: string;
|
|
8
|
+
psbt: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
6
11
|
export interface BroadcastedTransaction {
|
|
7
12
|
/** Whether the transaction was successfully broadcasted. */
|
|
8
13
|
readonly success: boolean;
|
|
@@ -32,4 +37,10 @@ export interface Web3Provider {
|
|
|
32
37
|
signInteraction(
|
|
33
38
|
interactionParameters: InteractionParametersWithoutSigner,
|
|
34
39
|
): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
40
|
+
|
|
41
|
+
signAndBroadcastInteraction(
|
|
42
|
+
interactionParameters: InteractionParametersWithoutSigner,
|
|
43
|
+
): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
44
|
+
|
|
45
|
+
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
35
46
|
}
|
|
@@ -165,7 +165,7 @@ export class OPNetLimitedProvider {
|
|
|
165
165
|
try {
|
|
166
166
|
const resp: Response = await fetch(url, params);
|
|
167
167
|
if (!resp.ok) {
|
|
168
|
-
throw new Error(`Failed to fetch
|
|
168
|
+
throw new Error(`Failed to fetch to rpc: ${resp.statusText}`);
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
const fetchedData = await resp.json();
|
|
@@ -175,7 +175,7 @@ export class OPNetLimitedProvider {
|
|
|
175
175
|
|
|
176
176
|
const result = fetchedData.result;
|
|
177
177
|
if (!result) {
|
|
178
|
-
throw new Error('No
|
|
178
|
+
throw new Error('No rpc parameters found');
|
|
179
179
|
}
|
|
180
180
|
|
|
181
181
|
if ('error' in result) {
|