@btc-vision/transaction 1.0.41 → 1.0.44
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/opnet.d.ts +3 -0
- package/browser/transaction/TransactionFactory.d.ts +3 -3
- package/browser/transaction/browser/BrowserSigner.d.ts +9 -0
- package/browser/transaction/browser/BrowserSignerBase.d.ts +18 -0
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +35 -0
- package/browser/transaction/browser/types/Unisat.d.ts +54 -0
- package/browser/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/MultiSignTransaction.d.ts +4 -4
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/browser/transaction/builders/TransactionBuilder.d.ts +10 -9
- package/browser/transaction/builders/UnwrapSegwitTransaction.d.ts +3 -3
- package/browser/transaction/builders/UnwrapTransaction.d.ts +2 -2
- package/browser/transaction/builders/WrapTransaction.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -4
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/metadata/contracts/wBTC.js +1 -1
- package/build/opnet.d.ts +3 -0
- package/build/opnet.js +3 -0
- package/build/tests/adaptPSBT.js +1 -1
- package/build/tests/deploy.js +1 -2
- package/build/tests/deployMotoRegStep1.d.ts +1 -0
- package/build/tests/deployMotoRegStep1.js +85 -0
- package/build/tests/deployReg.js +2 -2
- package/build/tests/factory/createPairReg.js +6 -77
- package/build/tests/gen.js +6 -17
- package/build/tests/interaction.d.ts +5 -0
- package/build/tests/interaction.js +62 -0
- package/build/tests/mineReg.js +1 -4
- package/build/tests/moto/airdropToken.d.ts +1 -0
- package/build/tests/moto/airdropToken.js +21 -0
- package/build/tests/moto/allowance.d.ts +1 -0
- package/build/tests/moto/allowance.js +5 -0
- package/build/tests/moto/approve.d.ts +1 -0
- package/build/tests/moto/approve.js +6 -0
- package/build/tests/moto/approveWBTC.d.ts +1 -0
- package/build/tests/moto/approveWBTC.js +12 -0
- package/build/tests/moto/balanceOf.d.ts +1 -0
- package/build/tests/moto/balanceOf.js +13 -0
- package/build/tests/motoswap/airdropToken.d.ts +11 -0
- package/build/tests/motoswap/airdropToken.js +36 -0
- package/build/tests/motoswap/deployMoto.d.ts +4 -0
- package/build/tests/motoswap/deployMoto.js +87 -0
- package/build/tests/motoswap/deployMotoRegStep1.d.ts +1 -0
- package/build/tests/motoswap/deployMotoRegStep1.js +91 -0
- package/build/tests/motoswap/deployMotoRegStep2.d.ts +1 -0
- package/build/tests/motoswap/deployMotoRegStep2.js +91 -0
- package/build/tests/motoswap/deployStep1.d.ts +1 -0
- package/build/tests/motoswap/deployStep1.js +5 -0
- package/build/tests/motoswap/deployStep2.d.ts +1 -0
- package/build/tests/motoswap/deployStep2.js +5 -0
- package/build/tests/motoswap/deployStep3.d.ts +1 -0
- package/build/tests/motoswap/deployStep3.js +5 -0
- package/build/tests/motoswap/interaction.d.ts +3 -0
- package/build/tests/motoswap/interaction.js +63 -0
- package/build/tests/motoswap/routerAddLiquidity.d.ts +11 -0
- package/build/tests/motoswap/routerAddLiquidity.js +36 -0
- package/build/tests/multisign.js +1 -1
- package/build/tests/shared/Utils.d.ts +2 -0
- package/build/tests/shared/Utils.js +9 -0
- package/build/tests/shared/interaction.d.ts +5 -0
- package/build/tests/shared/interaction.js +76 -0
- package/build/tests/shared/tokens.d.ts +6 -0
- package/build/tests/shared/tokens.js +5 -0
- package/build/tests/stakeReg.js +1 -1
- package/build/tests/test.js +1 -1
- package/build/tests/testReg.js +1 -1
- package/build/tests/tokens.d.ts +6 -0
- package/build/tests/tokens.js +5 -0
- package/build/tests/transfer.js +1 -1
- package/build/tests/wbtc/approve.d.ts +1 -0
- package/build/tests/wbtc/approve.js +6 -0
- package/build/tests/wbtc/approveWBTC.d.ts +1 -0
- package/build/tests/wbtc/approveWBTC.js +12 -0
- package/build/tests/wbtc/massWrapReg.d.ts +1 -0
- package/build/tests/wbtc/massWrapReg.js +105 -0
- package/build/tests/wbtc/transferReg.d.ts +1 -0
- package/build/tests/wbtc/transferReg.js +16 -0
- package/build/tests/wbtc/unStakeReg.d.ts +1 -0
- package/build/tests/wbtc/unStakeReg.js +72 -0
- package/build/tests/wbtc/unwrapReg.d.ts +1 -0
- package/build/tests/wbtc/unwrapReg.js +60 -0
- package/build/tests/wbtc/unwrapRegSegwit.d.ts +1 -0
- package/build/tests/wbtc/unwrapRegSegwit.js +83 -0
- package/build/tests/wbtc/withdrawalRequestReg.d.ts +1 -0
- package/build/tests/wbtc/withdrawalRequestReg.js +71 -0
- package/build/tests/wbtc/wrapReg.d.ts +1 -0
- package/build/tests/wbtc/wrapReg.js +69 -0
- package/build/tests/wbtc/wrapTest.d.ts +1 -0
- package/build/tests/wbtc/wrapTest.js +66 -0
- package/build/tests/writers/allowance.d.ts +3 -0
- package/build/tests/writers/allowance.js +10 -0
- package/build/tests/writers/approve.d.ts +4 -0
- package/build/tests/writers/approve.js +11 -0
- package/build/transaction/TransactionFactory.d.ts +3 -3
- package/build/transaction/TransactionFactory.js +41 -38
- package/build/transaction/browser/BrowserSigner.d.ts +11 -0
- package/build/transaction/browser/BrowserSigner.js +10 -0
- package/build/transaction/browser/BrowserSignerBase.d.ts +18 -0
- package/build/transaction/browser/BrowserSignerBase.js +3 -0
- package/build/transaction/browser/extensions/Unisat.d.ts +54 -0
- package/build/transaction/browser/extensions/Unisat.js +11 -0
- package/build/transaction/browser/extensions/UnisatSigner.d.ts +35 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +150 -0
- package/build/transaction/browser/types/Unisat.d.ts +54 -0
- package/build/transaction/browser/types/Unisat.js +11 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +2 -2
- package/build/transaction/builders/DeploymentTransaction.js +4 -4
- package/build/transaction/builders/FundingTransaction.d.ts +1 -1
- package/build/transaction/builders/FundingTransaction.js +2 -2
- package/build/transaction/builders/MultiSignTransaction.d.ts +4 -4
- package/build/transaction/builders/MultiSignTransaction.js +7 -7
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -2
- package/build/transaction/builders/SharedInteractionTransaction.js +6 -6
- package/build/transaction/builders/TransactionBuilder.d.ts +10 -9
- package/build/transaction/builders/TransactionBuilder.js +29 -22
- package/build/transaction/builders/UnwrapSegwitTransaction.d.ts +3 -3
- package/build/transaction/builders/UnwrapSegwitTransaction.js +10 -10
- package/build/transaction/builders/UnwrapTransaction.d.ts +2 -2
- package/build/transaction/builders/UnwrapTransaction.js +9 -6
- package/build/transaction/builders/WrapTransaction.d.ts +1 -1
- package/build/transaction/builders/WrapTransaction.js +2 -2
- package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
- package/build/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/build/transaction/processor/PsbtTransaction.js +2 -2
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -4
- package/build/transaction/shared/TweakedTransaction.js +59 -23
- package/package.json +2 -2
- package/src/_version.ts +1 -1
- package/src/metadata/contracts/wBTC.ts +1 -1
- package/src/opnet.ts +81 -76
- package/src/transaction/TransactionFactory.ts +52 -44
- package/src/transaction/browser/BrowserSignerBase.ts +44 -0
- package/src/transaction/browser/extensions/UnisatSigner.ts +218 -0
- package/src/transaction/browser/types/Unisat.ts +77 -0
- package/src/transaction/builders/DeploymentTransaction.ts +4 -4
- package/src/transaction/builders/FundingTransaction.ts +40 -40
- package/src/transaction/builders/MultiSignTransaction.ts +9 -17
- package/src/transaction/builders/SharedInteractionTransaction.ts +368 -368
- package/src/transaction/builders/TransactionBuilder.ts +637 -632
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +365 -362
- package/src/transaction/builders/UnwrapTransaction.ts +503 -499
- package/src/transaction/builders/WrapTransaction.ts +346 -346
- package/src/transaction/interfaces/ITransactionParameters.ts +55 -54
- package/src/transaction/processor/PsbtTransaction.ts +192 -192
- package/src/transaction/shared/TweakedTransaction.ts +109 -56
|
@@ -0,0 +1,62 @@
|
|
|
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
|
+
const network = networks.regtest;
|
|
8
|
+
const rpc = new BitcoinRPC();
|
|
9
|
+
export const wallet = new Wallet(Regtest.wallet, network);
|
|
10
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
11
|
+
const factory = new TransactionFactory();
|
|
12
|
+
async function mineBlock() {
|
|
13
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
14
|
+
if (!ok) {
|
|
15
|
+
throw new Error('Could not mine block');
|
|
16
|
+
}
|
|
17
|
+
console.log(`Mined block`, ok);
|
|
18
|
+
return !!ok.length;
|
|
19
|
+
}
|
|
20
|
+
await rpc.init(Regtest.config);
|
|
21
|
+
const requestedAmount = 1n * 100000000n;
|
|
22
|
+
const utxoSetting = {
|
|
23
|
+
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
24
|
+
minAmount: 10000n,
|
|
25
|
+
requestedAmount: requestedAmount,
|
|
26
|
+
};
|
|
27
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
28
|
+
console.log(`UTXOs:`, utxos);
|
|
29
|
+
if (!utxos) {
|
|
30
|
+
throw new Error('No UTXOs found');
|
|
31
|
+
}
|
|
32
|
+
export async function interact(contract, calldata, mine = true) {
|
|
33
|
+
const interactionParameters = {
|
|
34
|
+
from: wallet.p2wpkh,
|
|
35
|
+
to: contract,
|
|
36
|
+
utxos: utxos,
|
|
37
|
+
signer: wallet.keypair,
|
|
38
|
+
network: network,
|
|
39
|
+
feeRate: 1000,
|
|
40
|
+
priorityFee: 100000n,
|
|
41
|
+
calldata: calldata,
|
|
42
|
+
};
|
|
43
|
+
const finalTx = factory.signInteraction(interactionParameters);
|
|
44
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
45
|
+
hexstring: finalTx[0],
|
|
46
|
+
});
|
|
47
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
48
|
+
if (!firstTxBroadcast) {
|
|
49
|
+
throw new Error('Could not broadcast first transaction');
|
|
50
|
+
}
|
|
51
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
52
|
+
hexstring: finalTx[1],
|
|
53
|
+
});
|
|
54
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`, finalTx[1]);
|
|
55
|
+
if (!secondTxBroadcast) {
|
|
56
|
+
throw new Error('Could not broadcast second transaction');
|
|
57
|
+
}
|
|
58
|
+
if (mine) {
|
|
59
|
+
await mineBlock();
|
|
60
|
+
}
|
|
61
|
+
rpc.destroy();
|
|
62
|
+
}
|
package/build/tests/mineReg.js
CHANGED
|
@@ -5,7 +5,6 @@ import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
|
5
5
|
const network = networks.regtest;
|
|
6
6
|
const rpc = new BitcoinRPC();
|
|
7
7
|
const wallet = new Wallet(Regtest.wallet, network);
|
|
8
|
-
const shouldMineBlock = true;
|
|
9
8
|
async function mineBlock() {
|
|
10
9
|
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
11
10
|
if (!ok) {
|
|
@@ -15,7 +14,5 @@ async function mineBlock() {
|
|
|
15
14
|
return !!ok.length;
|
|
16
15
|
}
|
|
17
16
|
await rpc.init(Regtest.config);
|
|
18
|
-
|
|
19
|
-
await mineBlock();
|
|
20
|
-
}
|
|
17
|
+
await mineBlock();
|
|
21
18
|
rpc.destroy();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact, wallet } from '../shared/interaction.js';
|
|
3
|
+
import { MOTO_ADDRESS } from '../shared/tokens.js';
|
|
4
|
+
const abiCoder = new ABICoder();
|
|
5
|
+
const airdropSelector = Number(`0x` + abiCoder.encodeSelector('airdrop'));
|
|
6
|
+
function expandToDecimals(n, decimals = 18n) {
|
|
7
|
+
return BigInt(n) * 10n ** decimals;
|
|
8
|
+
}
|
|
9
|
+
function airdropToken(amount, to) {
|
|
10
|
+
const aidropToken = new Map();
|
|
11
|
+
aidropToken.set(to, amount);
|
|
12
|
+
const calldata = new BinaryWriter();
|
|
13
|
+
calldata.writeSelector(airdropSelector);
|
|
14
|
+
calldata.writeAddressValueTupleMap(aidropToken);
|
|
15
|
+
return Buffer.from(calldata.getBuffer());
|
|
16
|
+
}
|
|
17
|
+
const tokenAmount = expandToDecimals(10000, 8n);
|
|
18
|
+
const receiver = wallet.p2tr;
|
|
19
|
+
const calldata = airdropToken(tokenAmount, receiver);
|
|
20
|
+
console.log('airdrop ->', calldata.toString('hex'));
|
|
21
|
+
await interact(MOTO_ADDRESS, calldata);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ROUTER_ADDRESS } from '../shared/tokens.js';
|
|
2
|
+
import { wallet } from '../shared/interaction.js';
|
|
3
|
+
import { allowance } from '../writers/allowance.js';
|
|
4
|
+
const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS);
|
|
5
|
+
console.log('allowance ->', calldata.toString('hex'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { approve, MAX_UINT256 } from '../writers/approve.js';
|
|
2
|
+
import { MOTO_ADDRESS, ROUTER_ADDRESS } from '../shared/tokens.js';
|
|
3
|
+
import { interact } from '../shared/interaction.js';
|
|
4
|
+
const calldata = approve(ROUTER_ADDRESS, MAX_UINT256);
|
|
5
|
+
console.log('approve ->', calldata.toString('hex'));
|
|
6
|
+
await interact(MOTO_ADDRESS, calldata, false);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
const abiCoder = new ABICoder();
|
|
3
|
+
const approveSelector = Number(`0x` + abiCoder.encodeSelector('approve'));
|
|
4
|
+
const MAX_UINT256 = 2n ** 256n - 1n;
|
|
5
|
+
function approve(amount = MAX_UINT256) {
|
|
6
|
+
const calldata = new BinaryWriter();
|
|
7
|
+
calldata.writeSelector(approveSelector);
|
|
8
|
+
calldata.writeU256(amount);
|
|
9
|
+
return Buffer.from(calldata.getBuffer());
|
|
10
|
+
}
|
|
11
|
+
const calldata = approve(MAX_UINT256);
|
|
12
|
+
console.log('approve ->', calldata.toString('hex'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { wallet } from '../shared/interaction.js';
|
|
3
|
+
const abiCoder = new ABICoder();
|
|
4
|
+
const balanceSelector = Number(`0x` + abiCoder.encodeSelector('balanceOf'));
|
|
5
|
+
function balanceOf(to) {
|
|
6
|
+
const calldata = new BinaryWriter();
|
|
7
|
+
calldata.writeSelector(balanceSelector);
|
|
8
|
+
calldata.writeAddress(to);
|
|
9
|
+
return Buffer.from(calldata.getBuffer());
|
|
10
|
+
}
|
|
11
|
+
const receiver = wallet.p2tr;
|
|
12
|
+
const calldata = balanceOf(receiver);
|
|
13
|
+
console.log('balanceOf ->', 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,36 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { wallet } from '../interaction.js';
|
|
3
|
+
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
4
|
+
import { networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { MOTO_ADDRESS } from '../tokens.js';
|
|
6
|
+
const abiCoder = new ABICoder();
|
|
7
|
+
const transferSelector = Number(`0x` + abiCoder.encodeSelector('transfer'));
|
|
8
|
+
function expandToDecimals(n, decimals = 18n) {
|
|
9
|
+
return BigInt(n) * 10n ** decimals;
|
|
10
|
+
}
|
|
11
|
+
function addLiquidity(parameters) {
|
|
12
|
+
const calldata = new BinaryWriter();
|
|
13
|
+
calldata.writeAddress(parameters.tokenA);
|
|
14
|
+
calldata.writeAddress(parameters.tokenB);
|
|
15
|
+
calldata.writeU256(parameters.amountADesired);
|
|
16
|
+
calldata.writeU256(parameters.amountBDesired);
|
|
17
|
+
calldata.writeU256(parameters.amountAMin);
|
|
18
|
+
calldata.writeU256(parameters.amountBMin);
|
|
19
|
+
calldata.writeAddress(parameters.to);
|
|
20
|
+
calldata.writeU64(parameters.deadline);
|
|
21
|
+
return Buffer.from(calldata.getBuffer());
|
|
22
|
+
}
|
|
23
|
+
const token0Amount = expandToDecimals(1);
|
|
24
|
+
const token1Amount = expandToDecimals(1);
|
|
25
|
+
const receiver = wallet.p2tr;
|
|
26
|
+
const calldata = addLiquidity({
|
|
27
|
+
tokenA: wBTC.getAddress(networks.regtest),
|
|
28
|
+
tokenB: MOTO_ADDRESS,
|
|
29
|
+
amountADesired: token0Amount,
|
|
30
|
+
amountBDesired: token1Amount,
|
|
31
|
+
amountAMin: 0n,
|
|
32
|
+
amountBMin: 0n,
|
|
33
|
+
to: receiver,
|
|
34
|
+
deadline: 2n,
|
|
35
|
+
});
|
|
36
|
+
console.log(calldata.toString('hex'));
|
|
@@ -0,0 +1,87 @@
|
|
|
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
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
31
|
+
if (!utxos) {
|
|
32
|
+
throw new Error('No UTXOs found');
|
|
33
|
+
}
|
|
34
|
+
shuffleArray(utxos);
|
|
35
|
+
export async function deployMoto(contracts) {
|
|
36
|
+
let deployed = [];
|
|
37
|
+
for (let contract of contracts) {
|
|
38
|
+
const bytecode = fs.readFileSync(contract);
|
|
39
|
+
for (let utxo of utxos) {
|
|
40
|
+
const deploymentParameters = {
|
|
41
|
+
from: wallet.p2wpkh,
|
|
42
|
+
utxos: [utxo],
|
|
43
|
+
signer: wallet.keypair,
|
|
44
|
+
network: network,
|
|
45
|
+
feeRate: 500,
|
|
46
|
+
priorityFee: 50000n,
|
|
47
|
+
bytecode: bytecode,
|
|
48
|
+
};
|
|
49
|
+
try {
|
|
50
|
+
const finalTx = await factory.signDeployment(deploymentParameters);
|
|
51
|
+
console.log(`Final transaction:`, finalTx);
|
|
52
|
+
let txid;
|
|
53
|
+
try {
|
|
54
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[0], false);
|
|
55
|
+
console.log(`Transaction ID:`, txid);
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (!txid) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[1], false);
|
|
65
|
+
console.log(`Transaction ID:`, txid);
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
if (!txid) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
deployed.push({ contract: finalTx.contractAddress, file: contract });
|
|
74
|
+
console.log(`Contract deployed at ${finalTx.contractAddress}`);
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (shouldMineBlock) {
|
|
83
|
+
await mineBlock();
|
|
84
|
+
}
|
|
85
|
+
rpc.destroy();
|
|
86
|
+
return deployed;
|
|
87
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const network = networks.regtest;
|
|
9
|
+
const rpc = new BitcoinRPC();
|
|
10
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
11
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
12
|
+
const factory = new TransactionFactory();
|
|
13
|
+
const shouldMineBlock = false;
|
|
14
|
+
async function mineBlock() {
|
|
15
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
16
|
+
if (!ok) {
|
|
17
|
+
throw new Error('Could not mine block');
|
|
18
|
+
}
|
|
19
|
+
console.log(`Mined block`, ok);
|
|
20
|
+
return !!ok.length;
|
|
21
|
+
}
|
|
22
|
+
await rpc.init(Regtest.config);
|
|
23
|
+
const requestedAmount = 100000000000n;
|
|
24
|
+
const utxoSetting = {
|
|
25
|
+
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
26
|
+
minAmount: 10000n,
|
|
27
|
+
requestedAmount: requestedAmount,
|
|
28
|
+
};
|
|
29
|
+
function shuffleArray(array) {
|
|
30
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
31
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
32
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
36
|
+
if (!utxos) {
|
|
37
|
+
throw new Error('No UTXOs found');
|
|
38
|
+
}
|
|
39
|
+
shuffleArray(utxos);
|
|
40
|
+
const contracts = ['./bytecode/wbtc.wasm', './bytecode/moto.wasm', './bytecode/pool.wasm'];
|
|
41
|
+
let deployed = [];
|
|
42
|
+
for (let contract of contracts) {
|
|
43
|
+
const bytecode = fs.readFileSync(contract);
|
|
44
|
+
for (let utxo of utxos) {
|
|
45
|
+
const deploymentParameters = {
|
|
46
|
+
from: wallet.p2wpkh,
|
|
47
|
+
utxos: [utxo],
|
|
48
|
+
signer: wallet.keypair,
|
|
49
|
+
network: network,
|
|
50
|
+
feeRate: 500,
|
|
51
|
+
priorityFee: 50000n,
|
|
52
|
+
bytecode: bytecode,
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const finalTx = factory.signDeployment(deploymentParameters);
|
|
56
|
+
console.log(`Final transaction:`, finalTx);
|
|
57
|
+
let txid;
|
|
58
|
+
try {
|
|
59
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[0], false);
|
|
60
|
+
console.log(`Transaction ID:`, txid);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!txid) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[1], false);
|
|
70
|
+
console.log(`Transaction ID:`, txid);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!txid) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
deployed.push({ contract: finalTx.contractAddress, file: contract });
|
|
79
|
+
console.log(`Contract deployed at ${finalTx.contractAddress}`);
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log(deployed);
|
|
88
|
+
if (shouldMineBlock) {
|
|
89
|
+
await mineBlock();
|
|
90
|
+
}
|
|
91
|
+
rpc.destroy();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const network = networks.regtest;
|
|
9
|
+
const rpc = new BitcoinRPC();
|
|
10
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
11
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
12
|
+
const factory = new TransactionFactory();
|
|
13
|
+
const shouldMineBlock = false;
|
|
14
|
+
async function mineBlock() {
|
|
15
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
16
|
+
if (!ok) {
|
|
17
|
+
throw new Error('Could not mine block');
|
|
18
|
+
}
|
|
19
|
+
console.log(`Mined block`, ok);
|
|
20
|
+
return !!ok.length;
|
|
21
|
+
}
|
|
22
|
+
await rpc.init(Regtest.config);
|
|
23
|
+
const requestedAmount = 100000000000n;
|
|
24
|
+
const utxoSetting = {
|
|
25
|
+
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
26
|
+
minAmount: 10000n,
|
|
27
|
+
requestedAmount: requestedAmount,
|
|
28
|
+
};
|
|
29
|
+
function shuffleArray(array) {
|
|
30
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
31
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
32
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
36
|
+
if (!utxos) {
|
|
37
|
+
throw new Error('No UTXOs found');
|
|
38
|
+
}
|
|
39
|
+
shuffleArray(utxos);
|
|
40
|
+
const contracts = ['./bytecode/wbtc.wasm', './bytecode/wbtc.wasm'];
|
|
41
|
+
let deployed = [];
|
|
42
|
+
for (let contract of contracts) {
|
|
43
|
+
const bytecode = fs.readFileSync(contract);
|
|
44
|
+
for (let utxo of utxos) {
|
|
45
|
+
const deploymentParameters = {
|
|
46
|
+
from: wallet.p2wpkh,
|
|
47
|
+
utxos: [utxo],
|
|
48
|
+
signer: wallet.keypair,
|
|
49
|
+
network: network,
|
|
50
|
+
feeRate: 500,
|
|
51
|
+
priorityFee: 50000n,
|
|
52
|
+
bytecode: bytecode,
|
|
53
|
+
};
|
|
54
|
+
try {
|
|
55
|
+
const finalTx = factory.signDeployment(deploymentParameters);
|
|
56
|
+
console.log(`Final transaction:`, finalTx);
|
|
57
|
+
let txid;
|
|
58
|
+
try {
|
|
59
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[0], false);
|
|
60
|
+
console.log(`Transaction ID:`, txid);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (!txid) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
try {
|
|
69
|
+
txid = await utxoManager.broadcastTransaction(finalTx.transaction[1], false);
|
|
70
|
+
console.log(`Transaction ID:`, txid);
|
|
71
|
+
}
|
|
72
|
+
catch (e) {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
if (!txid) {
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
deployed.push({ contract: finalTx.contractAddress, file: contract });
|
|
79
|
+
console.log(`Contract deployed at ${finalTx.contractAddress}`);
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
console.log(deployed);
|
|
88
|
+
if (shouldMineBlock) {
|
|
89
|
+
await mineBlock();
|
|
90
|
+
}
|
|
91
|
+
rpc.destroy();
|
|
@@ -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 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,63 @@
|
|
|
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
|
+
const network = networks.regtest;
|
|
8
|
+
const rpc = new BitcoinRPC();
|
|
9
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
10
|
+
const utxoManager = new OPNetLimitedProvider('http://localhost:9001');
|
|
11
|
+
const factory = new TransactionFactory();
|
|
12
|
+
const shouldMineBlock = true;
|
|
13
|
+
async function mineBlock() {
|
|
14
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
15
|
+
if (!ok) {
|
|
16
|
+
throw new Error('Could not mine block');
|
|
17
|
+
}
|
|
18
|
+
console.log(`Mined block`, ok);
|
|
19
|
+
return !!ok.length;
|
|
20
|
+
}
|
|
21
|
+
await rpc.init(Regtest.config);
|
|
22
|
+
const requestedAmount = 1n * 100000000n;
|
|
23
|
+
const utxoSetting = {
|
|
24
|
+
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
25
|
+
minAmount: 10000n,
|
|
26
|
+
requestedAmount: requestedAmount,
|
|
27
|
+
};
|
|
28
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
29
|
+
console.log(`UTXOs:`, utxos);
|
|
30
|
+
if (!utxos) {
|
|
31
|
+
throw new Error('No UTXOs found');
|
|
32
|
+
}
|
|
33
|
+
export async function interact(contract, calldata) {
|
|
34
|
+
const interactionParameters = {
|
|
35
|
+
from: wallet.p2wpkh,
|
|
36
|
+
to: contract,
|
|
37
|
+
utxos: utxos,
|
|
38
|
+
signer: wallet.keypair,
|
|
39
|
+
network: network,
|
|
40
|
+
feeRate: 1000,
|
|
41
|
+
priorityFee: 100000n,
|
|
42
|
+
calldata: calldata,
|
|
43
|
+
};
|
|
44
|
+
const finalTx = factory.signInteraction(interactionParameters);
|
|
45
|
+
const firstTxBroadcast = await rpc.sendRawTransaction({
|
|
46
|
+
hexstring: finalTx[0],
|
|
47
|
+
});
|
|
48
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
49
|
+
if (!firstTxBroadcast) {
|
|
50
|
+
throw new Error('Could not broadcast first transaction');
|
|
51
|
+
}
|
|
52
|
+
const secondTxBroadcast = await rpc.sendRawTransaction({
|
|
53
|
+
hexstring: finalTx[1],
|
|
54
|
+
});
|
|
55
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`, finalTx[1]);
|
|
56
|
+
if (!secondTxBroadcast) {
|
|
57
|
+
throw new Error('Could not broadcast second transaction');
|
|
58
|
+
}
|
|
59
|
+
if (shouldMineBlock) {
|
|
60
|
+
await mineBlock();
|
|
61
|
+
}
|
|
62
|
+
rpc.destroy();
|
|
63
|
+
}
|
|
@@ -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,36 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact, wallet } from '../shared/interaction.js';
|
|
3
|
+
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
4
|
+
import { networks } from 'bitcoinjs-lib';
|
|
5
|
+
import { MOTO_ADDRESS, ROUTER_ADDRESS } from '../shared/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,
|
|
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'));
|
|
36
|
+
await interact(ROUTER_ADDRESS, calldata);
|
package/build/tests/multisign.js
CHANGED
|
@@ -36,7 +36,7 @@ const multiSignParams = {
|
|
|
36
36
|
requestedAmount: 600000n,
|
|
37
37
|
};
|
|
38
38
|
const multiSign = new MultiSignTransaction(multiSignParams);
|
|
39
|
-
const signed = multiSign.signPSBT();
|
|
39
|
+
const signed = await multiSign.signPSBT();
|
|
40
40
|
const signed3 = MultiSignTransaction.signPartial(signed, rlSigner2, 0, [2]);
|
|
41
41
|
console.log(`Signed`, signed3, signed.toHex());
|
|
42
42
|
const signed2 = MultiSignTransaction.signPartial(signed, realSigner.keypair, 0, [2]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function expandToDecimals(n, decimals = 18n) {
|
|
2
|
+
return BigInt(n) * 10n ** decimals;
|
|
3
|
+
}
|
|
4
|
+
export function shuffleArray(array) {
|
|
5
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
6
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
7
|
+
[array[i], array[j]] = [array[j], array[i]];
|
|
8
|
+
}
|
|
9
|
+
}
|