@btc-vision/transaction 1.0.50 → 1.0.52

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.
@@ -1,6 +1,6 @@
1
1
  import { Address } from '@btc-vision/bsi-binary';
2
- export declare const FACTORY_ADDRESS: Address;
3
- export declare const POOL_ADDRESS: Address;
4
- export declare const WBTC_ADDRESS: Address;
5
- export declare const MOTO_ADDRESS: Address;
6
- export declare const ROUTER_ADDRESS: Address;
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 +1 @@
1
- export declare const version = "1.0.50";
1
+ export declare const version = "1.0.52";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.50';
1
+ export const version = '1.0.52';
@@ -1,7 +1,7 @@
1
1
  import { bech32 } from 'bech32';
2
2
  import { initEccLib } from 'bitcoinjs-lib';
3
3
  import * as ecc from '@bitcoinerlab/secp256k1';
4
- import { ripemd160 } from 'bitcoinjs-lib/src/crypto';
4
+ import { ripemd160 } from 'bitcoinjs-lib/src/crypto.js';
5
5
  initEccLib(ecc);
6
6
  export class AddressGenerator {
7
7
  static generatePKSH(sha256Hash, network) {
@@ -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 'bcrt1q99qtptumw027cw8w274tqzd564q66u537vn0lh';
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 FACTORY_ADDRESS: Address;
3
- export declare const POOL_ADDRESS: Address;
4
- export declare const WBTC_ADDRESS: Address;
5
- export declare const MOTO_ADDRESS: Address;
6
- export declare const ROUTER_ADDRESS: Address;
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,5 +1,5 @@
1
- export const FACTORY_ADDRESS = 'bcrt1qz98txrd6csz0ljhp0v2rw8846k0zgn57uul8c9';
2
- export const POOL_ADDRESS = 'bcrt1qzwth3t3wdgy83tt9xegq7yww5dx0rhy3ezglg9';
3
- export const WBTC_ADDRESS = 'bcrt1q99qtptumw027cw8w274tqzd564q66u537vn0lh';
4
- export const MOTO_ADDRESS = 'bcrt1qwx9h2fvqlzx84t6jhxa424y7g2ynayt8p9rs38';
5
- export const ROUTER_ADDRESS = 'bcrt1qelqwcguvwkgr90w6u5f2q0a7gqlnq4w8rl26ht';
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 { MOTO_ADDRESS, WBTC_ADDRESS } from '../../metadata/tokens.js';
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(WBTC_ADDRESS);
9
- addCalldata.writeAddress(MOTO_ADDRESS);
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 { MOTO_ADDRESS } from '../../metadata/tokens.js';
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) {
@@ -18,4 +18,4 @@ const tokenAmount = expandToDecimals(1000, 8n);
18
18
  const receiver = 'bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2';
19
19
  const calldata = airdropToken(tokenAmount, receiver);
20
20
  console.log('airdrop ->', calldata.toString('hex'));
21
- await interact(MOTO_ADDRESS, calldata);
21
+ await interact(MOTO_ADDRESS_REGTEST, calldata);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,50 @@
1
+ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ const abiCoder = new ABICoder();
3
+ const airdropSelector = Number(`0x` + abiCoder.encodeSelector('airdropDefined'));
4
+ function expandToDecimals(n, decimals = 18n) {
5
+ return BigInt(n) * 10n ** decimals;
6
+ }
7
+ function generateFakeAddress() {
8
+ const prefix = 'bcrt1';
9
+ const base58Chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
10
+ const addressLength = 59;
11
+ let address = prefix;
12
+ while (address.length < addressLength) {
13
+ const randomIndex = Math.floor(Math.random() * base58Chars.length);
14
+ address += base58Chars[randomIndex];
15
+ }
16
+ return address;
17
+ }
18
+ const tokenAmount = expandToDecimals(10, 8n);
19
+ const amountOfWallets = 1;
20
+ const maxMB = 1;
21
+ const maxBytes = maxMB * 1024 * 1024;
22
+ function generateAirdropCalldata(tokenAmount) {
23
+ const calldata = new BinaryWriter();
24
+ calldata.writeSelector(airdropSelector);
25
+ calldata.writeU256(tokenAmount);
26
+ calldata.writeU32(amountOfWallets * 2);
27
+ for (let i = 0; i < amountOfWallets; i++) {
28
+ const taprootAddress = generateFakeAddress();
29
+ calldata.writeAddress(taprootAddress);
30
+ calldata.writeAddress(taprootAddress);
31
+ }
32
+ const buf = Buffer.from(calldata.getBuffer());
33
+ if (buf.byteLength > maxBytes) {
34
+ throw new Error(`Calldata too big. Max size: ${maxMB} MB`);
35
+ }
36
+ console.log('calldata', buf.toString('hex'));
37
+ return buf;
38
+ }
39
+ async function sendTx() {
40
+ const calldata = generateAirdropCalldata(tokenAmount);
41
+ console.log(`Calldata generated. Raw size: ${calldata.byteLength} bytes`);
42
+ }
43
+ for (let i = 0; i < 1; i++) {
44
+ try {
45
+ await sendTx();
46
+ }
47
+ catch (e) {
48
+ i--;
49
+ }
50
+ }
@@ -1,5 +1,5 @@
1
- import { ROUTER_ADDRESS } from '../../metadata/tokens.js';
1
+ import { ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
2
2
  import { wallet } from '../shared/interaction.js';
3
3
  import { allowance } from '../writers/allowance.js';
4
- const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS);
4
+ const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS_REGTEST);
5
5
  console.log('allowance ->', calldata.toString('hex'));
@@ -1,11 +1,10 @@
1
1
  import { approve, MAX_UINT256 } from '../writers/approve.js';
2
- import { MOTO_ADDRESS, ROUTER_ADDRESS } from '../../metadata/tokens.js';
2
+ import { MOTO_ADDRESS_REGTEST, ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
3
3
  import { interact } from '../shared/interaction.js';
4
- const calldata = approve(ROUTER_ADDRESS, MAX_UINT256);
4
+ const calldata = approve(ROUTER_ADDRESS_REGTEST, MAX_UINT256);
5
5
  console.log('approve ->', calldata.toString('hex'));
6
- const interaction = await interact(MOTO_ADDRESS, calldata, false);
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,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 { MOTO_ADDRESS } from '../../metadata/tokens.js';
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(MOTO_ADDRESS, calldata, false);
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/pool.wasm'];
3
+ const contractsToDeploy = ['./bytecode/moto.wasm'];
4
4
  const contracts = await deployMoto(contractsToDeploy);
5
5
  console.log(`Contracts deployed:`, contracts);
@@ -2,7 +2,7 @@ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
2
  import { interact, wallet } from '../shared/interaction.js';
3
3
  import { wBTC } from '../../metadata/contracts/wBTC.js';
4
4
  import { networks } from 'bitcoinjs-lib';
5
- import { MOTO_ADDRESS, ROUTER_ADDRESS } from '../../metadata/tokens.js';
5
+ import { MOTO_ADDRESS_REGTEST, ROUTER_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: MOTO_ADDRESS,
26
+ tokenA: MOTO_ADDRESS_REGTEST,
27
27
  tokenB: wBTC.getAddress(networks.regtest),
28
28
  amountADesired: token0Amount,
29
29
  amountBDesired: token1Amount,
@@ -33,4 +33,4 @@ const calldata = addLiquidity({
33
33
  deadline: 5000n,
34
34
  });
35
35
  console.log('add liquidity:', calldata.toString('hex'));
36
- await interact(ROUTER_ADDRESS, calldata);
36
+ await interact(ROUTER_ADDRESS_REGTEST, calldata);
@@ -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 * 1n;
22
+ const requestedAmount = 10n ** 8n * 50n;
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: 450,
44
- priorityFee: 10000n,
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 { ROUTER_ADDRESS, WBTC_ADDRESS } from '../../metadata/tokens.js';
2
+ import { ROUTER_ADDRESS_REGTEST, WBTC_ADDRESS_REGTEST } from '../../metadata/tokens.js';
3
3
  import { interact } from '../shared/interaction.js';
4
- const calldata = approve(ROUTER_ADDRESS, MAX_UINT256);
4
+ const calldata = approve(ROUTER_ADDRESS_REGTEST, MAX_UINT256);
5
5
  console.log('approve ->', calldata.toString('hex'));
6
- await interact(WBTC_ADDRESS, calldata, false);
6
+ await interact(WBTC_ADDRESS_REGTEST, calldata, false);
@@ -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 wrap parameters: ${resp.statusText}`);
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 wrap parameters found');
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.50",
3
+ "version": "1.0.52",
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.28",
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.50';
1
+ export const version = '1.0.52';
@@ -1,7 +1,7 @@
1
1
  import { bech32 } from 'bech32';
2
2
  import { initEccLib, Network } from 'bitcoinjs-lib';
3
3
  import * as ecc from '@bitcoinerlab/secp256k1';
4
- import { ripemd160 } from 'bitcoinjs-lib/src/crypto';
4
+ import { ripemd160 } from 'bitcoinjs-lib/src/crypto.js';
5
5
 
6
6
  initEccLib(ecc);
7
7
 
@@ -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 'bcrt1q99qtptumw027cw8w274tqzd564q66u537vn0lh';
38
+ return WBTC_ADDRESS_REGTEST;
38
39
  case networks.testnet.bech32:
39
40
  return 'tb1qj58a6yf4pez426nqvf8wyu6ssggcajw8kr44vy';
40
41
  default:
@@ -1,7 +1,7 @@
1
1
  import { Address } from '@btc-vision/bsi-binary';
2
2
 
3
- export const FACTORY_ADDRESS: Address = 'bcrt1qz98txrd6csz0ljhp0v2rw8846k0zgn57uul8c9';
4
- export const POOL_ADDRESS: Address = 'bcrt1qzwth3t3wdgy83tt9xegq7yww5dx0rhy3ezglg9';
5
- export const WBTC_ADDRESS: Address = 'bcrt1q99qtptumw027cw8w274tqzd564q66u537vn0lh';
6
- export const MOTO_ADDRESS: Address = 'bcrt1qwx9h2fvqlzx84t6jhxa424y7g2ynayt8p9rs38';
7
- export const ROUTER_ADDRESS: Address = 'bcrt1qelqwcguvwkgr90w6u5f2q0a7gqlnq4w8rl26ht';
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';
@@ -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 wrap parameters: ${resp.statusText}`);
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 wrap parameters found');
178
+ throw new Error('No rpc parameters found');
179
179
  }
180
180
 
181
181
  if ('error' in result) {