@btc-vision/transaction 1.0.84 → 1.0.86
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/.gitattributes +2 -2
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/keypair/Wallet.d.ts +3 -0
- package/browser/transaction/builders/TapUnwarpTransaction.d.ts +40 -40
- package/browser/transaction/builders/UnwarpTransaction.d.ts +34 -34
- package/browser/utxo/UTXOManager.d.ts +7 -7
- package/build/Utils.d.ts +0 -0
- package/build/Utils.js +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/consensus/metadata/RoswsellConsensus.d.ts +2 -0
- package/build/consensus/metadata/RoswsellConsensus.js +4 -0
- package/build/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/contracts/ContractMetadataManager.js +1 -0
- package/build/generators/OPNetAddressGenerator.d.ts +0 -0
- package/build/generators/OPNetAddressGenerator.js +1 -0
- package/build/generators/builders/UnwrapGenerator.d.ts +8 -0
- package/build/generators/builders/UnwrapGenerator.js +79 -0
- package/build/keypair/Wallet.d.ts +3 -0
- package/build/keypair/Wallet.js +8 -0
- package/build/keypair/interfaces/GeneratedWallet.d.ts +5 -0
- package/build/keypair/interfaces/GeneratedWallet.js +1 -0
- package/build/metadata/CommonContracts.d.ts +6 -0
- package/build/metadata/CommonContracts.js +5 -0
- package/build/metadata/ContractMetadataManager.d.ts +1 -0
- package/build/metadata/ContractMetadataManager.js +9 -0
- package/build/metadata/contracts/ContractBase.d.ts +9 -0
- package/build/metadata/contracts/ContractBase.js +13 -0
- package/build/metadata/contracts/ContractBaseMetadata.d.ts +9 -0
- package/build/metadata/contracts/ContractBaseMetadata.js +13 -0
- package/build/metadata/contracts/ContractMetadataManager.d.ts +0 -0
- package/build/metadata/contracts/ContractMetadataManager.js +1 -0
- package/build/metadata/tokens.js +5 -5
- package/build/network/NetworkConverter.d.ts +0 -0
- package/build/network/NetworkConverter.js +14 -0
- package/build/scripts/Regtest.d.ts +2 -0
- package/build/scripts/Regtest.js +15 -0
- package/build/scripts/test.d.ts +1 -0
- package/build/scripts/test.js +74 -0
- package/build/signer/Regtest.d.ts +2 -0
- package/build/signer/Regtest.js +15 -0
- package/build/tests/Regtest.d.ts +3 -0
- package/build/tests/Regtest.js +29 -0
- package/build/tests/adaptPSBT.d.ts +1 -0
- package/build/tests/adaptPSBT.js +44 -0
- package/build/tests/btc/send.d.ts +1 -0
- package/build/tests/btc/send.js +35 -0
- package/build/tests/btc/transfer.d.ts +1 -0
- package/build/tests/btc/transfer.js +35 -0
- package/build/tests/createPairReg.d.ts +1 -0
- package/build/tests/createPairReg.js +73 -0
- package/build/tests/deploy/deployMoto.d.ts +4 -0
- package/build/tests/deploy/deployMoto.js +89 -0
- package/build/tests/deploy/deployPool.d.ts +1 -0
- package/build/tests/deploy/deployPool.js +5 -0
- package/build/tests/deploy/deployStep1.d.ts +1 -0
- package/build/tests/deploy/deployStep1.js +5 -0
- package/build/tests/deploy/deployStep2.d.ts +1 -0
- package/build/tests/deploy/deployStep2.js +5 -0
- package/build/tests/deploy/deployStep3.d.ts +1 -0
- package/build/tests/deploy/deployStep3.js +5 -0
- package/build/tests/deploy.d.ts +1 -0
- package/build/tests/deploy.js +41 -0
- package/build/tests/deployMotoRegStep1.d.ts +1 -0
- package/build/tests/deployMotoRegStep1.js +85 -0
- package/build/tests/deployReg.d.ts +1 -0
- package/build/tests/deployReg.js +85 -0
- package/build/tests/factory/createPairReg.d.ts +1 -0
- package/build/tests/factory/createPairReg.js +13 -0
- package/build/tests/gen.d.ts +1 -0
- package/build/tests/gen.js +19 -0
- package/build/tests/interaction.d.ts +5 -0
- package/build/tests/interaction.js +62 -0
- package/build/tests/massWrapReg.d.ts +1 -0
- package/build/tests/massWrapReg.js +105 -0
- package/build/tests/mineReg.d.ts +1 -0
- package/build/tests/mineReg.js +19 -0
- package/build/tests/moto/airdropToken.d.ts +1 -0
- package/build/tests/moto/airdropToken.js +21 -0
- package/build/tests/moto/airdropTokens.d.ts +1 -0
- package/build/tests/moto/airdropTokens.js +60 -0
- package/build/tests/moto/allowance.d.ts +1 -0
- package/build/tests/moto/allowance.js +6 -0
- package/build/tests/moto/approve.d.ts +1 -0
- package/build/tests/moto/approve.js +10 -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 +12 -0
- package/build/tests/moto/transfer.d.ts +1 -0
- package/build/tests/moto/transfer.js +16 -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 +89 -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/deployPool.d.ts +1 -0
- package/build/tests/motoswap/deployPool.js +5 -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 +35 -0
- package/build/tests/motoswap-router/addLiquidity.d.ts +11 -0
- package/build/tests/motoswap-router/addLiquidity.js +36 -0
- package/build/tests/motoswap-router/deployMoto.d.ts +4 -0
- package/build/tests/motoswap-router/deployMoto.js +89 -0
- package/build/tests/motoswap-router/deployPool.d.ts +1 -0
- package/build/tests/motoswap-router/deployPool.js +5 -0
- package/build/tests/motoswap-router/deployStep1.d.ts +1 -0
- package/build/tests/motoswap-router/deployStep1.js +5 -0
- package/build/tests/motoswap-router/deployStep2.d.ts +1 -0
- package/build/tests/motoswap-router/deployStep2.js +5 -0
- package/build/tests/motoswap-router/deployStep3.d.ts +1 -0
- package/build/tests/motoswap-router/deployStep3.js +5 -0
- package/build/tests/motoswap-router/getAmountsOut.d.ts +5 -0
- package/build/tests/motoswap-router/getAmountsOut.js +34 -0
- package/build/tests/motoswap-router/routerAddLiquidity.d.ts +11 -0
- package/build/tests/motoswap-router/routerAddLiquidity.js +35 -0
- package/build/tests/motoswap-router/swap.d.ts +8 -0
- package/build/tests/motoswap-router/swap.js +24 -0
- package/build/tests/multisign.d.ts +1 -0
- package/build/tests/multisign.js +47 -0
- package/build/tests/multisign2.d.ts +1 -0
- package/build/tests/multisign2.js +27 -0
- 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 +18 -0
- package/build/tests/shared/Utils.d.ts +2 -0
- package/build/tests/shared/Utils.js +14 -0
- package/build/tests/shared/interaction.d.ts +7 -0
- package/build/tests/shared/interaction.js +85 -0
- package/build/tests/shared/tokens.d.ts +6 -0
- package/build/tests/shared/tokens.js +5 -0
- package/build/tests/stakeReg.d.ts +1 -0
- package/build/tests/stakeReg.js +73 -0
- package/build/tests/stakedReg.d.ts +1 -0
- package/build/tests/stakedReg.js +28 -0
- package/build/tests/test.d.ts +1 -0
- package/build/tests/test.js +51 -0
- package/build/tests/test2.d.ts +1 -0
- package/build/tests/test2.js +73 -0
- package/build/tests/testReg.d.ts +1 -0
- package/build/tests/testReg.js +91 -0
- package/build/tests/tokens.d.ts +6 -0
- package/build/tests/tokens.js +5 -0
- package/build/tests/totalRewardReg.d.ts +1 -0
- package/build/tests/totalRewardReg.js +28 -0
- package/build/tests/transfer.d.ts +1 -0
- package/build/tests/transfer.js +74 -0
- package/build/tests/transferReg.d.ts +1 -0
- package/build/tests/transferReg.js +74 -0
- package/build/tests/unStakeReg.d.ts +1 -0
- package/build/tests/unStakeReg.js +72 -0
- package/build/tests/unwrapReg.d.ts +1 -0
- package/build/tests/unwrapReg.js +61 -0
- package/build/tests/unwrapReg2.d.ts +1 -0
- package/build/tests/unwrapReg2.js +56 -0
- package/build/tests/unwrapRegSegwit.d.ts +1 -0
- package/build/tests/unwrapRegSegwit.js +83 -0
- 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/transfer.d.ts +1 -0
- package/build/tests/wbtc/transfer.js +16 -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 +65 -0
- package/build/tests/wbtc/wrapTest.d.ts +1 -0
- package/build/tests/wbtc/wrapTest.js +66 -0
- package/build/tests/withdrawalRequestReg.d.ts +1 -0
- package/build/tests/withdrawalRequestReg.js +71 -0
- package/build/tests/wrap.d.ts +1 -0
- package/build/tests/wrap.js +65 -0
- package/build/tests/wrapReg.d.ts +1 -0
- package/build/tests/wrapReg.js +68 -0
- package/build/tests/wrapTest.d.ts +1 -0
- package/build/tests/wrapTest.js +66 -0
- package/build/tests/wrapTestg.d.ts +1 -0
- package/build/tests/wrapTestg.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/TransactionBuilder.d.ts +60 -0
- package/build/transaction/TransactionBuilder.js +244 -0
- package/build/transaction/browser/BrowserSigner.d.ts +11 -0
- package/build/transaction/browser/BrowserSigner.js +10 -0
- package/build/transaction/browser/extensions/Unisat.d.ts +54 -0
- package/build/transaction/browser/extensions/Unisat.js +11 -0
- package/build/transaction/builders/GenericTransaction.d.ts +11 -0
- package/build/transaction/builders/GenericTransaction.js +23 -0
- package/build/transaction/builders/TapUnwarpTransaction.d.ts +37 -0
- package/build/transaction/builders/TapUnwarpTransaction.js +201 -0
- package/build/transaction/builders/UnwarpSegwitTransaction.d.ts +34 -0
- package/build/transaction/builders/UnwarpSegwitTransaction.js +184 -0
- package/build/transaction/builders/UnwarpTransaction.d.ts +35 -0
- package/build/transaction/builders/UnwarpTransaction.js +199 -0
- package/build/transaction/interfaces/ITransactions.d.ts +32 -0
- package/build/transaction/interfaces/ITransactions.js +1 -0
- package/build/utxo/IUTXO.d.ts +0 -0
- package/build/utxo/IUTXO.js +1 -0
- package/build/utxo/OPNetUtils.d.ts +7 -0
- package/build/utxo/OPNetUtils.js +47 -0
- package/build/utxo/UTXOManager.d.ts +7 -0
- package/build/utxo/UTXOManager.js +47 -0
- package/build/wbtc/BroadcastResponse.d.ts +0 -0
- package/build/wbtc/BroadcastResponse.js +1 -0
- package/gulpfile.js +152 -152
- package/package.json +109 -109
- package/src/_version.ts +1 -1
- package/src/consensus/Consensus.ts +36 -36
- package/src/consensus/ConsensusConfig.ts +39 -39
- package/src/crypto/crypto-browser.js +75 -75
- package/src/generators/AddressGenerator.ts +24 -24
- package/src/generators/Features.ts +5 -5
- package/src/generators/Generator.ts +75 -75
- package/src/generators/builders/CalldataGenerator.ts +148 -148
- package/src/generators/builders/DeploymentGenerator.ts +66 -66
- package/src/index.ts +4 -4
- package/src/keypair/AddressVerificator.ts +40 -40
- package/src/keypair/EcKeyPair.ts +282 -282
- package/src/keypair/Wallet.ts +120 -97
- package/src/keypair/interfaces/IWallet.ts +19 -19
- package/src/metadata/ContractBaseMetadata.ts +23 -23
- package/src/metadata/contracts/wBTC.ts +60 -60
- package/src/metadata/tokens.ts +135 -135
- package/src/network/NetworkInformation.ts +7 -7
- package/src/transaction/TransactionFactory.ts +496 -496
- package/src/transaction/browser/BrowserSignerBase.ts +37 -37
- package/src/transaction/browser/Web3Provider.ts +46 -46
- package/src/transaction/browser/extensions/UnisatSigner.ts +218 -218
- package/src/transaction/browser/types/Unisat.ts +97 -97
- package/src/transaction/builders/FundingTransaction.ts +40 -40
- package/src/transaction/builders/InteractionTransaction.ts +38 -38
- package/src/transaction/builders/SharedInteractionTransaction.ts +368 -368
- package/src/transaction/builders/TransactionBuilder.ts +665 -665
- package/src/transaction/builders/UnwrapSegwitTransaction.ts +365 -365
- package/src/transaction/builders/UnwrapTransaction.ts +507 -507
- package/src/transaction/builders/WrapTransaction.ts +346 -346
- package/src/transaction/interfaces/ITransactionParameters.ts +59 -59
- package/src/transaction/interfaces/Tap.ts +26 -26
- package/src/transaction/psbt/PSBTTypes.ts +3 -3
- package/src/transaction/shared/TweakedTransaction.ts +539 -539
- package/src/utxo/OPNetLimitedProvider.ts +244 -244
- package/src/utxo/interfaces/BroadcastResponse.ts +10 -10
- package/src/utxo/interfaces/IUTXO.ts +29 -29
- package/src/verification/TapscriptVerificator.ts +89 -89
- package/src/wbtc/Generate.ts +40 -40
- package/src/wbtc/UnwrapGeneration.ts +13 -13
- package/src/wbtc/WrappedGenerationParameters.ts +33 -33
- package/webpack.config.js +78 -78
- /package/build/generators/builders/{MultiSignGenerator.d.ts → MultisignGenerator.d.ts} +0 -0
- /package/build/generators/builders/{MultiSignGenerator.js → MultisignGenerator.js} +0 -0
- /package/build/generators/{Features.d.ts → features.d.ts} +0 -0
- /package/build/generators/{Features.js → features.js} +0 -0
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
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 { currentConsensusConfig } from '../consensus/ConsensusConfig.js';
|
|
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 = 10000000000000n;
|
|
24
|
+
const utxoSetting = {
|
|
25
|
+
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
26
|
+
minAmount: 10000n,
|
|
27
|
+
requestedAmount: requestedAmount,
|
|
28
|
+
};
|
|
29
|
+
const utxos = await utxoManager.fetchUTXOMultiAddr(utxoSetting);
|
|
30
|
+
let totalAmount = 0n;
|
|
31
|
+
try {
|
|
32
|
+
for (let i = 0; i < 700; i++) {
|
|
33
|
+
if (!utxos) {
|
|
34
|
+
console.log(`Used all UTXOs`);
|
|
35
|
+
throw new Error('No UTXOs found');
|
|
36
|
+
}
|
|
37
|
+
const utxo = utxos.shift();
|
|
38
|
+
if (!utxo) {
|
|
39
|
+
console.log(`Used all UTXOs`);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
const wrapAmount = currentConsensusConfig.VAULT_MINIMUM_AMOUNT +
|
|
43
|
+
(currentConsensusConfig.VAULT_MINIMUM_AMOUNT *
|
|
44
|
+
10000000n *
|
|
45
|
+
BigInt(Math.floor(Math.random() * 10000))) /
|
|
46
|
+
10000000000n;
|
|
47
|
+
if (wrapAmount < currentConsensusConfig.VAULT_MINIMUM_AMOUNT) {
|
|
48
|
+
console.log(`Wrap amount too low: ${wrapAmount}`);
|
|
49
|
+
i--;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const generationParameters = await utxoManager.fetchWrapParameters(wrapAmount);
|
|
54
|
+
if (!generationParameters) {
|
|
55
|
+
throw new Error('No generation parameters found');
|
|
56
|
+
}
|
|
57
|
+
const interactionParameters = {
|
|
58
|
+
from: wallet.p2wpkh,
|
|
59
|
+
utxos: [utxo],
|
|
60
|
+
signer: wallet.keypair,
|
|
61
|
+
network: network,
|
|
62
|
+
feeRate: 500,
|
|
63
|
+
priorityFee: 100000n,
|
|
64
|
+
receiver: wallet.p2tr,
|
|
65
|
+
amount: wrapAmount,
|
|
66
|
+
generationParameters: generationParameters,
|
|
67
|
+
};
|
|
68
|
+
const finalTx = factory.wrap(interactionParameters);
|
|
69
|
+
const firstTxBroadcast = await rpc
|
|
70
|
+
.sendRawTransaction({
|
|
71
|
+
hexstring: finalTx.transaction[0],
|
|
72
|
+
})
|
|
73
|
+
.catch(() => { });
|
|
74
|
+
console.log(`First transaction broadcasted: ${firstTxBroadcast}`);
|
|
75
|
+
if (!firstTxBroadcast) {
|
|
76
|
+
i--;
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
const secondTxBroadcast = await rpc
|
|
80
|
+
.sendRawTransaction({
|
|
81
|
+
hexstring: finalTx.transaction[1],
|
|
82
|
+
})
|
|
83
|
+
.catch(() => { });
|
|
84
|
+
console.log(`Second transaction broadcasted: ${secondTxBroadcast}`);
|
|
85
|
+
if (!secondTxBroadcast) {
|
|
86
|
+
throw new Error('Could not broadcast second transaction');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
totalAmount += wrapAmount;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
console.log(e);
|
|
94
|
+
i--;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
catch (e) {
|
|
99
|
+
console.error(e);
|
|
100
|
+
}
|
|
101
|
+
console.log(`All transactions broadcasted for a total of ${totalAmount} satoshis.`);
|
|
102
|
+
if (shouldMineBlock) {
|
|
103
|
+
await mineBlock();
|
|
104
|
+
}
|
|
105
|
+
rpc.destroy();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Wallet } from '../keypair/Wallet.js';
|
|
2
|
+
import { Regtest } from './Regtest.js';
|
|
3
|
+
import { networks } from 'bitcoinjs-lib';
|
|
4
|
+
import { BitcoinRPC } from '@btc-vision/bsi-bitcoin-rpc';
|
|
5
|
+
const network = networks.regtest;
|
|
6
|
+
const rpc = new BitcoinRPC();
|
|
7
|
+
const wallet = new Wallet(Regtest.wallet, network);
|
|
8
|
+
async function mineBlock() {
|
|
9
|
+
const ok = await rpc.generateToAddress(1, wallet.p2wpkh, 'default');
|
|
10
|
+
if (!ok) {
|
|
11
|
+
throw new Error('Could not mine block');
|
|
12
|
+
}
|
|
13
|
+
console.log(`Mined block`, ok);
|
|
14
|
+
return !!ok.length;
|
|
15
|
+
}
|
|
16
|
+
console.log('Mining a block...', wallet.p2wpkh);
|
|
17
|
+
await rpc.init(Regtest.config);
|
|
18
|
+
await mineBlock();
|
|
19
|
+
rpc.destroy();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact } from '../shared/interaction.js';
|
|
3
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/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(1000, 8n);
|
|
18
|
+
const receiver = 'bcrt1pst60scy2zdyxkfzqs593aevx2jypah32zzjjx2kmz57yzf228wjq5wtyc5';
|
|
19
|
+
const calldata = airdropToken(tokenAmount, receiver);
|
|
20
|
+
console.log('airdrop ->', calldata.toString('hex'));
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
2
|
+
import { allowance } from '../writers/allowance.js';
|
|
3
|
+
import { wallet } from '../shared/interaction.js';
|
|
4
|
+
console.log('wallet ->', wallet);
|
|
5
|
+
const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS_REGTEST);
|
|
6
|
+
console.log('allowance ->', calldata.toString('hex'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { approve, MAX_UINT256 } from '../writers/approve.js';
|
|
2
|
+
import { MOTO_ADDRESS_REGTEST, ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
3
|
+
import { interact } from '../shared/interaction.js';
|
|
4
|
+
const calldata = approve(ROUTER_ADDRESS_REGTEST, MAX_UINT256);
|
|
5
|
+
console.log('approve ->', calldata.toString('hex'));
|
|
6
|
+
const interaction = await interact(MOTO_ADDRESS_REGTEST, calldata, false);
|
|
7
|
+
console.log(interaction);
|
|
8
|
+
if (!interaction) {
|
|
9
|
+
throw new Error('Interaction failed');
|
|
10
|
+
}
|
|
@@ -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,12 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
const abiCoder = new ABICoder();
|
|
3
|
+
const balanceSelector = Number(`0x` + abiCoder.encodeSelector('balanceOf'));
|
|
4
|
+
function balanceOf(to) {
|
|
5
|
+
const calldata = new BinaryWriter();
|
|
6
|
+
calldata.writeSelector(balanceSelector);
|
|
7
|
+
calldata.writeAddress(to);
|
|
8
|
+
return Buffer.from(calldata.getBuffer());
|
|
9
|
+
}
|
|
10
|
+
const receiver = 'bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2';
|
|
11
|
+
const calldata = balanceOf(receiver);
|
|
12
|
+
console.log('balanceOf ->', calldata.toString('hex'));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact } from '../shared/interaction.js';
|
|
3
|
+
import { expandToDecimals } from '../shared/Utils.js';
|
|
4
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
5
|
+
const abiCoder = new ABICoder();
|
|
6
|
+
const transferSelector = Number(`0x` + abiCoder.encodeSelector('transfer'));
|
|
7
|
+
function getTransferToCalldata(to, amount) {
|
|
8
|
+
const addCalldata = new BinaryWriter();
|
|
9
|
+
addCalldata.writeSelector(transferSelector);
|
|
10
|
+
addCalldata.writeAddress(to);
|
|
11
|
+
addCalldata.writeU256(amount);
|
|
12
|
+
return Buffer.from(addCalldata.getBuffer());
|
|
13
|
+
}
|
|
14
|
+
const tokenAmount = expandToDecimals(250, 8n);
|
|
15
|
+
const calldata = getTransferToCalldata('bcrt1pst60scy2zdyxkfzqs593aevx2jypah32zzjjx2kmz57yzf228wjq5wtyc5', tokenAmount);
|
|
16
|
+
await interact(MOTO_ADDRESS_REGTEST, calldata, false);
|
|
@@ -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,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,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 {};
|