@btc-vision/transaction 1.0.53 → 1.0.54

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.
Files changed (41) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/index.js +1 -1
  3. package/browser/transaction/browser/Web3Provider.d.ts +1 -1
  4. package/build/_version.d.ts +1 -1
  5. package/build/_version.js +1 -1
  6. package/build/tests/deploy/deployMoto.d.ts +4 -0
  7. package/build/tests/deploy/deployMoto.js +89 -0
  8. package/build/tests/deploy/deployPool.d.ts +1 -0
  9. package/build/tests/deploy/deployPool.js +5 -0
  10. package/build/tests/deploy/deployStep1.d.ts +1 -0
  11. package/build/tests/deploy/deployStep1.js +5 -0
  12. package/build/tests/deploy/deployStep2.d.ts +1 -0
  13. package/build/tests/deploy/deployStep2.js +5 -0
  14. package/build/tests/deploy/deployStep3.d.ts +1 -0
  15. package/build/tests/deploy/deployStep3.js +5 -0
  16. package/build/tests/moto/allowance.js +3 -1
  17. package/build/tests/motoswap-router/addLiquidity.d.ts +11 -0
  18. package/build/tests/motoswap-router/addLiquidity.js +35 -0
  19. package/build/tests/motoswap-router/deployMoto.d.ts +4 -0
  20. package/build/tests/motoswap-router/deployMoto.js +89 -0
  21. package/build/tests/motoswap-router/deployPool.d.ts +1 -0
  22. package/build/tests/motoswap-router/deployPool.js +5 -0
  23. package/build/tests/motoswap-router/deployStep1.d.ts +1 -0
  24. package/build/tests/motoswap-router/deployStep1.js +5 -0
  25. package/build/tests/motoswap-router/deployStep2.d.ts +1 -0
  26. package/build/tests/motoswap-router/deployStep2.js +5 -0
  27. package/build/tests/motoswap-router/deployStep3.d.ts +1 -0
  28. package/build/tests/motoswap-router/deployStep3.js +5 -0
  29. package/build/tests/motoswap-router/getAmountsOut.d.ts +5 -0
  30. package/build/tests/motoswap-router/getAmountsOut.js +34 -0
  31. package/build/tests/motoswap-router/routerAddLiquidity.d.ts +11 -0
  32. package/build/tests/motoswap-router/routerAddLiquidity.js +35 -0
  33. package/build/tests/motoswap-router/swap.d.ts +8 -0
  34. package/build/tests/motoswap-router/swap.js +24 -0
  35. package/build/tests/pool/reserves.js +8 -0
  36. package/build/tests/shared/Utils.js +6 -1
  37. package/build/tests/writers/approve.js +1 -1
  38. package/build/transaction/browser/Web3Provider.d.ts +1 -1
  39. package/package.json +2 -1
  40. package/src/_version.ts +1 -1
  41. package/src/transaction/browser/Web3Provider.ts +1 -1
@@ -13,7 +13,7 @@ export interface BroadcastedTransaction {
13
13
  readonly identifier: bigint | string;
14
14
  }
15
15
  export interface Web3Provider {
16
- signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
16
+ signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[string, string, UTXO[]]>;
17
17
  signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
18
18
  broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
19
19
  }
@@ -1 +1 @@
1
- export declare const version = "1.0.53";
1
+ export declare const version = "1.0.54";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.53';
1
+ export const version = '1.0.54';
@@ -0,0 +1,4 @@
1
+ export declare function deployMoto(contracts: string[]): Promise<{
2
+ contract: string;
3
+ file: string;
4
+ }[]>;
@@ -0,0 +1,89 @@
1
+ import { Wallet } from '../../keypair/Wallet.js';
2
+ import { Regtest } from '../Regtest.js';
3
+ import { OPNetLimitedProvider } from '../../utxo/OPNetLimitedProvider.js';
4
+ import { networks } from 'bitcoinjs-lib';
5
+ import { TransactionFactory } from '../../transaction/TransactionFactory.js';
6
+ import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
7
+ import * as fs from 'fs';
8
+ import { shuffleArray } from '../shared/Utils.js';
9
+ const network = networks.regtest;
10
+ const rpc = new BitcoinRPC();
11
+ const wallet = new Wallet(Regtest.wallet, network);
12
+ const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
13
+ const factory = new TransactionFactory();
14
+ const shouldMineBlock = false;
15
+ async function mineBlock() {
16
+ const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
17
+ if (!ok) {
18
+ throw new Error('Could not mine block');
19
+ }
20
+ console.log(`Mined block`, ok);
21
+ return !!ok.length;
22
+ }
23
+ await rpc.init(Regtest.config);
24
+ const requestedAmount = 100000000000n;
25
+ const utxoSetting = {
26
+ addresses: [wallet.p2wpkh, wallet.p2tr],
27
+ minAmount: 10000n,
28
+ requestedAmount: requestedAmount,
29
+ };
30
+ console.log('Fetching UTXOs');
31
+ const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
32
+ if (!utxos) {
33
+ throw new Error('No UTXOs found');
34
+ }
35
+ console.log('Shuffling UTXOs', utxos.length);
36
+ shuffleArray(utxos);
37
+ export async function deployMoto(contracts) {
38
+ let deployed = [];
39
+ for (let contract of contracts) {
40
+ const bytecode = fs.readFileSync(contract);
41
+ for (let utxo of utxos) {
42
+ const deploymentParameters = {
43
+ from: wallet.p2wpkh,
44
+ utxos: [utxo],
45
+ signer: wallet.keypair,
46
+ network: network,
47
+ feeRate: 500,
48
+ priorityFee: 50000n,
49
+ bytecode: bytecode,
50
+ };
51
+ try {
52
+ const finalTx = await factory.signDeployment(deploymentParameters);
53
+ console.log(`Final transaction:`, finalTx);
54
+ let txid;
55
+ try {
56
+ txid = await utxoManager.broadcastTransaction(finalTx.transaction[0], false);
57
+ console.log(`Transaction ID:`, txid);
58
+ }
59
+ catch (e) {
60
+ continue;
61
+ }
62
+ if (!txid) {
63
+ continue;
64
+ }
65
+ try {
66
+ txid = await utxoManager.broadcastTransaction(finalTx.transaction[1], false);
67
+ console.log(`Transaction ID:`, txid);
68
+ }
69
+ catch (e) {
70
+ continue;
71
+ }
72
+ if (!txid) {
73
+ continue;
74
+ }
75
+ deployed.push({ contract: finalTx.contractAddress, file: contract });
76
+ console.log(`Contract deployed at ${finalTx.contractAddress}`);
77
+ }
78
+ catch (e) {
79
+ continue;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+ if (shouldMineBlock) {
85
+ await mineBlock();
86
+ }
87
+ rpc.destroy();
88
+ return deployed;
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 1: Deploying MotoSwap contracts`);
3
+ const contractsToDeploy = ['./bytecode/moto.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 1: Deploying MotoSwap contracts`);
3
+ const contractsToDeploy = ['./bytecode/wbtc.wasm', './bytecode/moto.wasm', './bytecode/pool.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 2: Deploying Factory`);
3
+ const contractsToDeploy = ['./bytecode/factory.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 3: Deploying Router`);
3
+ const contractsToDeploy = ['./bytecode/router.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -1,4 +1,6 @@
1
1
  import { ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
2
2
  import { allowance } from '../writers/allowance.js';
3
- const calldata = allowance('bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2', ROUTER_ADDRESS_REGTEST);
3
+ import { wallet } from '../shared/interaction.js';
4
+ console.log('wallet ->', wallet);
5
+ const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS_REGTEST);
4
6
  console.log('allowance ->', calldata.toString('hex'));
@@ -0,0 +1,11 @@
1
+ import { Address } from '@btc-vision/bsi-binary';
2
+ export interface AddLiquidityParameters {
3
+ readonly tokenA: Address;
4
+ readonly tokenB: Address;
5
+ readonly amountADesired: bigint;
6
+ readonly amountBDesired: bigint;
7
+ readonly amountAMin: bigint;
8
+ readonly amountBMin: bigint;
9
+ readonly to: Address;
10
+ readonly deadline: bigint;
11
+ }
@@ -0,0 +1,35 @@
1
+ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ import { wallet } from '../shared/interaction.js';
3
+ import { wBTC } from '../../metadata/contracts/wBTC.js';
4
+ import { networks } from 'bitcoinjs-lib';
5
+ import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
6
+ import { expandToDecimals } from '../shared/Utils.js';
7
+ const abiCoder = new ABICoder();
8
+ const addLiquiditySelector = Number(`0x` + abiCoder.encodeSelector('addLiquidity'));
9
+ function addLiquidity(parameters) {
10
+ const calldata = new BinaryWriter();
11
+ calldata.writeSelector(addLiquiditySelector);
12
+ calldata.writeAddress(parameters.tokenA);
13
+ calldata.writeAddress(parameters.tokenB);
14
+ calldata.writeU256(parameters.amountADesired);
15
+ calldata.writeU256(parameters.amountBDesired);
16
+ calldata.writeU256(parameters.amountAMin);
17
+ calldata.writeU256(parameters.amountBMin);
18
+ calldata.writeAddress(parameters.to);
19
+ calldata.writeU64(parameters.deadline);
20
+ return Buffer.from(calldata.getBuffer());
21
+ }
22
+ const token0Amount = expandToDecimals(1000, 8n);
23
+ const token1Amount = 600000n;
24
+ const receiver = wallet.p2tr;
25
+ const calldata = addLiquidity({
26
+ tokenA: MOTO_ADDRESS_REGTEST,
27
+ tokenB: wBTC.getAddress(networks.regtest),
28
+ amountADesired: token0Amount,
29
+ amountBDesired: token1Amount,
30
+ amountAMin: 0n,
31
+ amountBMin: 0n,
32
+ to: receiver,
33
+ deadline: 5000n,
34
+ });
35
+ console.log('add liquidity:', calldata.toString('hex'));
@@ -0,0 +1,4 @@
1
+ export declare function deployMoto(contracts: string[]): Promise<{
2
+ contract: string;
3
+ file: string;
4
+ }[]>;
@@ -0,0 +1,89 @@
1
+ import { Wallet } from '../../keypair/Wallet.js';
2
+ import { Regtest } from '../Regtest.js';
3
+ import { OPNetLimitedProvider } from '../../utxo/OPNetLimitedProvider.js';
4
+ import { networks } from 'bitcoinjs-lib';
5
+ import { TransactionFactory } from '../../transaction/TransactionFactory.js';
6
+ import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
7
+ import * as fs from 'fs';
8
+ import { shuffleArray } from '../shared/Utils.js';
9
+ const network = networks.regtest;
10
+ const rpc = new BitcoinRPC();
11
+ const wallet = new Wallet(Regtest.wallet, network);
12
+ const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
13
+ const factory = new TransactionFactory();
14
+ const shouldMineBlock = false;
15
+ async function mineBlock() {
16
+ const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
17
+ if (!ok) {
18
+ throw new Error('Could not mine block');
19
+ }
20
+ console.log(`Mined block`, ok);
21
+ return !!ok.length;
22
+ }
23
+ await rpc.init(Regtest.config);
24
+ const requestedAmount = 100000000000n;
25
+ const utxoSetting = {
26
+ addresses: [wallet.p2wpkh, wallet.p2tr],
27
+ minAmount: 10000n,
28
+ requestedAmount: requestedAmount,
29
+ };
30
+ console.log('Fetching UTXOs');
31
+ const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
32
+ if (!utxos) {
33
+ throw new Error('No UTXOs found');
34
+ }
35
+ console.log('Shuffling UTXOs', utxos.length);
36
+ shuffleArray(utxos);
37
+ export async function deployMoto(contracts) {
38
+ let deployed = [];
39
+ for (let contract of contracts) {
40
+ const bytecode = fs.readFileSync(contract);
41
+ for (let utxo of utxos) {
42
+ const deploymentParameters = {
43
+ from: wallet.p2wpkh,
44
+ utxos: [utxo],
45
+ signer: wallet.keypair,
46
+ network: network,
47
+ feeRate: 500,
48
+ priorityFee: 50000n,
49
+ bytecode: bytecode,
50
+ };
51
+ try {
52
+ const finalTx = await factory.signDeployment(deploymentParameters);
53
+ console.log(`Final transaction:`, finalTx);
54
+ let txid;
55
+ try {
56
+ txid = await utxoManager.broadcastTransaction(finalTx.transaction[0], false);
57
+ console.log(`Transaction ID:`, txid);
58
+ }
59
+ catch (e) {
60
+ continue;
61
+ }
62
+ if (!txid) {
63
+ continue;
64
+ }
65
+ try {
66
+ txid = await utxoManager.broadcastTransaction(finalTx.transaction[1], false);
67
+ console.log(`Transaction ID:`, txid);
68
+ }
69
+ catch (e) {
70
+ continue;
71
+ }
72
+ if (!txid) {
73
+ continue;
74
+ }
75
+ deployed.push({ contract: finalTx.contractAddress, file: contract });
76
+ console.log(`Contract deployed at ${finalTx.contractAddress}`);
77
+ }
78
+ catch (e) {
79
+ continue;
80
+ }
81
+ break;
82
+ }
83
+ }
84
+ if (shouldMineBlock) {
85
+ await mineBlock();
86
+ }
87
+ rpc.destroy();
88
+ return deployed;
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 1: Deploying MotoSwap contracts`);
3
+ const contractsToDeploy = ['./bytecode/moto.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 1: Deploying MotoSwap contracts`);
3
+ const contractsToDeploy = ['./bytecode/wbtc.wasm', './bytecode/moto.wasm', './bytecode/pool.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 2: Deploying Factory`);
3
+ const contractsToDeploy = ['./bytecode/factory.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ import { deployMoto } from './deployMoto.js';
2
+ console.log(`Step 3: Deploying Router`);
3
+ const contractsToDeploy = ['./bytecode/router.wasm'];
4
+ const contracts = await deployMoto(contractsToDeploy);
5
+ console.log(`Contracts deployed:`, contracts);
@@ -0,0 +1,5 @@
1
+ import { Address } from '@btc-vision/bsi-binary';
2
+ export interface AddLiquidityParameters {
3
+ readonly path: Address[];
4
+ readonly amount: bigint;
5
+ }
@@ -0,0 +1,34 @@
1
+ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ import { expandToDecimals } from '../shared/Utils.js';
3
+ import { MOTO_ADDRESS_REGTEST, WBTC_ADDRESS_REGTEST } from '../../metadata/tokens.js';
4
+ const abiCoder = new ABICoder();
5
+ const getAmountsOutSelector = Number(`0x` + abiCoder.encodeSelector('getAmountsOut'));
6
+ const quoteSelector = Number(`0x` + abiCoder.encodeSelector('quote'));
7
+ function getAmountsOut(parameters) {
8
+ console.log(parameters);
9
+ const calldata = new BinaryWriter();
10
+ calldata.writeSelector(getAmountsOutSelector);
11
+ calldata.writeU256(parameters.amount);
12
+ calldata.writeAddressArray(parameters.path);
13
+ return Buffer.from(calldata.getBuffer());
14
+ }
15
+ const token0Amount = 1000n;
16
+ const path = [WBTC_ADDRESS_REGTEST, MOTO_ADDRESS_REGTEST];
17
+ const calldata = getAmountsOut({ path, amount: token0Amount });
18
+ console.log('calldata', calldata.toString('hex'));
19
+ function quote(parameters) {
20
+ console.log(parameters);
21
+ const calldata = new BinaryWriter();
22
+ calldata.writeSelector(quoteSelector);
23
+ calldata.writeU256(parameters.amountA);
24
+ calldata.writeU256(parameters.reserveA);
25
+ calldata.writeU256(parameters.reserveB);
26
+ return Buffer.from(calldata.getBuffer());
27
+ }
28
+ const quoteParams = {
29
+ amountA: token0Amount,
30
+ reserveA: expandToDecimals(1, 8n),
31
+ reserveB: expandToDecimals(1000, 18n),
32
+ };
33
+ const quoteCalldata = quote(quoteParams);
34
+ console.log('quoteCalldata', quoteCalldata.toString('hex'));
@@ -0,0 +1,11 @@
1
+ import { Address } from '@btc-vision/bsi-binary';
2
+ export interface AddLiquidityParameters {
3
+ readonly tokenA: Address;
4
+ readonly tokenB: Address;
5
+ readonly amountADesired: bigint;
6
+ readonly amountBDesired: bigint;
7
+ readonly amountAMin: bigint;
8
+ readonly amountBMin: bigint;
9
+ readonly to: Address;
10
+ readonly deadline: bigint;
11
+ }
@@ -0,0 +1,35 @@
1
+ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ import { wallet } from '../shared/interaction.js';
3
+ import { wBTC } from '../../metadata/contracts/wBTC.js';
4
+ import { networks } from 'bitcoinjs-lib';
5
+ import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
6
+ import { expandToDecimals } from '../shared/Utils.js';
7
+ const abiCoder = new ABICoder();
8
+ const addLiquiditySelector = Number(`0x` + abiCoder.encodeSelector('addLiquidity'));
9
+ function addLiquidity(parameters) {
10
+ const calldata = new BinaryWriter();
11
+ calldata.writeSelector(addLiquiditySelector);
12
+ calldata.writeAddress(parameters.tokenA);
13
+ calldata.writeAddress(parameters.tokenB);
14
+ calldata.writeU256(parameters.amountADesired);
15
+ calldata.writeU256(parameters.amountBDesired);
16
+ calldata.writeU256(parameters.amountAMin);
17
+ calldata.writeU256(parameters.amountBMin);
18
+ calldata.writeAddress(parameters.to);
19
+ calldata.writeU64(parameters.deadline);
20
+ return Buffer.from(calldata.getBuffer());
21
+ }
22
+ const token0Amount = expandToDecimals(1000, 8n);
23
+ const token1Amount = 600000n;
24
+ const receiver = wallet.p2tr;
25
+ const calldata = addLiquidity({
26
+ tokenA: MOTO_ADDRESS_REGTEST,
27
+ tokenB: wBTC.getAddress(networks.regtest),
28
+ amountADesired: token0Amount,
29
+ amountBDesired: token1Amount,
30
+ amountAMin: 0n,
31
+ amountBMin: 0n,
32
+ to: receiver,
33
+ deadline: 5000n,
34
+ });
35
+ console.log('add liquidity:', calldata.toString('hex'));
@@ -0,0 +1,8 @@
1
+ import { Address } from '@btc-vision/bsi-binary';
2
+ export interface SwapParameters {
3
+ readonly amountIn: bigint;
4
+ readonly amountOutMin: bigint;
5
+ readonly path: Address[];
6
+ readonly to: Address;
7
+ readonly deadline: bigint;
8
+ }
@@ -0,0 +1,24 @@
1
+ import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ import { wallet } from '../shared/interaction.js';
3
+ import { MOTO_ADDRESS_REGTEST, WBTC_ADDRESS_REGTEST } from '../../metadata/tokens.js';
4
+ import { expandToDecimals } from '../shared/Utils.js';
5
+ const abiCoder = new ABICoder();
6
+ const swapSelector = Number(`0x` + abiCoder.encodeSelector('swap'));
7
+ function generateSwap(parameters) {
8
+ const calldata = new BinaryWriter();
9
+ calldata.writeSelector(swapSelector);
10
+ calldata.writeU256(parameters.amountIn);
11
+ calldata.writeU256(parameters.amountOutMin);
12
+ calldata.writeAddressArray(parameters.path);
13
+ calldata.writeAddress(parameters.to);
14
+ calldata.writeU64(parameters.deadline);
15
+ return Buffer.from(calldata.getBuffer());
16
+ }
17
+ const calldata = generateSwap({
18
+ amountIn: expandToDecimals(0.01, 8n),
19
+ amountOutMin: 0n,
20
+ path: [WBTC_ADDRESS_REGTEST, MOTO_ADDRESS_REGTEST],
21
+ to: wallet.p2tr,
22
+ deadline: 10000n,
23
+ });
24
+ console.log('swap:', calldata.toString('hex'));
@@ -1,4 +1,6 @@
1
1
  import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
+ import { AddressGenerator } from '../../generators/AddressGenerator.js';
3
+ import { networks } from 'bitcoinjs-lib';
2
4
  const abiCoder = new ABICoder();
3
5
  const reservesSelector = Number(`0x` + abiCoder.encodeSelector('getReserves'));
4
6
  function getReserves() {
@@ -8,3 +10,9 @@ function getReserves() {
8
10
  }
9
11
  const calldata = getReserves();
10
12
  console.log('reserves ->', calldata.toString('hex'));
13
+ const writer = new BinaryWriter();
14
+ writer.writeU256(45230079600746738308285183004243888412290717325243858060208446020071790796183n);
15
+ const virtualAddress = Buffer.from(writer.getBuffer());
16
+ console.log('virtualAddress ->', virtualAddress);
17
+ const poolAddress = AddressGenerator.generatePKSH(virtualAddress, networks.regtest);
18
+ console.log('poolAddress ->', poolAddress);
@@ -1,5 +1,10 @@
1
+ import BigNumber from 'bignumber.js';
2
+ BigNumber.config({ EXPONENTIAL_AT: 256 });
1
3
  export function expandToDecimals(n, decimals = 18n) {
2
- return BigInt(n) * 10n ** decimals;
4
+ const amount = new BigNumber(n)
5
+ .multipliedBy(new BigNumber(10).pow(decimals.toString()))
6
+ .decimalPlaces(0);
7
+ return BigInt(amount.toString());
3
8
  }
4
9
  export function shuffleArray(array) {
5
10
  for (let i = array.length - 1; i > 0; i--) {
@@ -1,7 +1,7 @@
1
1
  import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
2
2
  const abiCoder = new ABICoder();
3
3
  const approveSelector = Number(`0x` + abiCoder.encodeSelector('approve'));
4
- export const MAX_UINT256 = 2n ** 256n - 2n;
4
+ export const MAX_UINT256 = 2n ** 256n - 1n;
5
5
  export function approve(spender, amount = MAX_UINT256) {
6
6
  const calldata = new BinaryWriter();
7
7
  calldata.writeSelector(approveSelector);
@@ -13,7 +13,7 @@ export interface BroadcastedTransaction {
13
13
  readonly identifier: bigint | string;
14
14
  }
15
15
  export interface Web3Provider {
16
- signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
16
+ signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[string, string, UTXO[]]>;
17
17
  signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
18
18
  broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
19
19
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "1.0.53",
3
+ "version": "1.0.54",
4
4
  "author": "BlobMaster41",
5
5
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
6
6
  "engines": {
@@ -96,6 +96,7 @@
96
96
  "babel-preset-react": "^6.24.1",
97
97
  "babelify": "^10.0.0",
98
98
  "bech32": "^2.0.0",
99
+ "bignumber.js": "^9.1.2",
99
100
  "bip32": "^4.0.0",
100
101
  "bitcoinjs-lib": "github:btc-vision/bitcoinjs-lib",
101
102
  "browserify-zlib": "^0.2.0",
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.0.53';
1
+ export const version = '1.0.54';
@@ -36,7 +36,7 @@ export interface BroadcastedTransaction {
36
36
  export interface Web3Provider {
37
37
  signInteraction(
38
38
  interactionParameters: InteractionParametersWithoutSigner,
39
- ): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
39
+ ): Promise<[string, string, UTXO[]]>;
40
40
 
41
41
  signAndBroadcastInteraction(
42
42
  interactionParameters: InteractionParametersWithoutSigner,