@btc-vision/transaction 1.0.52 → 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.
- package/browser/_version.d.ts +1 -1
- package/browser/index.js +1 -1
- package/browser/transaction/browser/Web3Provider.d.ts +7 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- 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/moto/airdropToken.js +1 -1
- package/build/tests/moto/airdropTokens.js +11 -1
- package/build/tests/moto/allowance.js +2 -1
- package/build/tests/moto/balanceOf.js +1 -2
- package/build/tests/motoswap/routerAddLiquidity.js +2 -3
- package/build/tests/motoswap-router/addLiquidity.d.ts +11 -0
- package/build/tests/motoswap-router/addLiquidity.js +35 -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/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.js +6 -1
- package/build/tests/shared/interaction.js +1 -1
- package/build/tests/wbtc/wrapReg.js +2 -5
- package/build/tests/writers/approve.js +1 -1
- package/build/transaction/browser/Web3Provider.d.ts +7 -1
- package/package.json +2 -1
- package/src/_version.ts +1 -1
- package/src/transaction/browser/Web3Provider.ts +11 -0
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
2
2
|
import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
3
3
|
export type InteractionParametersWithoutSigner = Omit<IInteractionParameters, 'signer'>;
|
|
4
|
+
export interface BroadcastTransactionOptions {
|
|
5
|
+
raw: string;
|
|
6
|
+
psbt: boolean;
|
|
7
|
+
}
|
|
4
8
|
export interface BroadcastedTransaction {
|
|
5
9
|
readonly success: boolean;
|
|
6
10
|
readonly result?: string;
|
|
@@ -9,5 +13,7 @@ export interface BroadcastedTransaction {
|
|
|
9
13
|
readonly identifier: bigint | string;
|
|
10
14
|
}
|
|
11
15
|
export interface Web3Provider {
|
|
12
|
-
signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[
|
|
16
|
+
signInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[string, string, UTXO[]]>;
|
|
17
|
+
signAndBroadcastInteraction(interactionParameters: InteractionParametersWithoutSigner): Promise<[BroadcastedTransaction, BroadcastedTransaction, UTXO[]]>;
|
|
18
|
+
broadcast(transactions: BroadcastTransactionOptions[]): Promise<BroadcastedTransaction[]>;
|
|
13
19
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.0.
|
|
1
|
+
export declare const version = "1.0.54";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.0.
|
|
1
|
+
export const version = '1.0.54';
|
|
@@ -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 @@
|
|
|
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 {};
|
|
@@ -15,7 +15,7 @@ function airdropToken(amount, to) {
|
|
|
15
15
|
return Buffer.from(calldata.getBuffer());
|
|
16
16
|
}
|
|
17
17
|
const tokenAmount = expandToDecimals(1000, 8n);
|
|
18
|
-
const receiver = '
|
|
18
|
+
const receiver = 'bcrt1pst60scy2zdyxkfzqs593aevx2jypah32zzjjx2kmz57yzf228wjq5wtyc5';
|
|
19
19
|
const calldata = airdropToken(tokenAmount, receiver);
|
|
20
20
|
console.log('airdrop ->', calldata.toString('hex'));
|
|
21
21
|
await interact(MOTO_ADDRESS_REGTEST, calldata);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { interact } from '../shared/interaction.js';
|
|
2
3
|
const abiCoder = new ABICoder();
|
|
3
4
|
const airdropSelector = Number(`0x` + abiCoder.encodeSelector('airdropDefined'));
|
|
4
5
|
function expandToDecimals(n, decimals = 18n) {
|
|
@@ -16,7 +17,7 @@ function generateFakeAddress() {
|
|
|
16
17
|
return address;
|
|
17
18
|
}
|
|
18
19
|
const tokenAmount = expandToDecimals(10, 8n);
|
|
19
|
-
const amountOfWallets =
|
|
20
|
+
const amountOfWallets = 85;
|
|
20
21
|
const maxMB = 1;
|
|
21
22
|
const maxBytes = maxMB * 1024 * 1024;
|
|
22
23
|
function generateAirdropCalldata(tokenAmount) {
|
|
@@ -39,6 +40,15 @@ function generateAirdropCalldata(tokenAmount) {
|
|
|
39
40
|
async function sendTx() {
|
|
40
41
|
const calldata = generateAirdropCalldata(tokenAmount);
|
|
41
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);
|
|
42
52
|
}
|
|
43
53
|
for (let i = 0; i < 1; i++) {
|
|
44
54
|
try {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ROUTER_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
2
|
-
import { wallet } from '../shared/interaction.js';
|
|
3
2
|
import { allowance } from '../writers/allowance.js';
|
|
3
|
+
import { wallet } from '../shared/interaction.js';
|
|
4
|
+
console.log('wallet ->', wallet);
|
|
4
5
|
const calldata = allowance(wallet.p2tr, ROUTER_ADDRESS_REGTEST);
|
|
5
6
|
console.log('allowance ->', calldata.toString('hex'));
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
-
import { wallet } from '../shared/interaction.js';
|
|
3
2
|
const abiCoder = new ABICoder();
|
|
4
3
|
const balanceSelector = Number(`0x` + abiCoder.encodeSelector('balanceOf'));
|
|
5
4
|
function balanceOf(to) {
|
|
@@ -8,6 +7,6 @@ function balanceOf(to) {
|
|
|
8
7
|
calldata.writeAddress(to);
|
|
9
8
|
return Buffer.from(calldata.getBuffer());
|
|
10
9
|
}
|
|
11
|
-
const receiver =
|
|
10
|
+
const receiver = 'bcrt1ppqk36azyunxdpadza7gtf568elqxnhu3lwufg98daek3kz07390swyvzd2';
|
|
12
11
|
const calldata = balanceOf(receiver);
|
|
13
12
|
console.log('balanceOf ->', calldata.toString('hex'));
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
-
import {
|
|
2
|
+
import { wallet } from '../shared/interaction.js';
|
|
3
3
|
import { wBTC } from '../../metadata/contracts/wBTC.js';
|
|
4
4
|
import { networks } from 'bitcoinjs-lib';
|
|
5
|
-
import { MOTO_ADDRESS_REGTEST
|
|
5
|
+
import { MOTO_ADDRESS_REGTEST } from '../../metadata/tokens.js';
|
|
6
6
|
import { expandToDecimals } from '../shared/Utils.js';
|
|
7
7
|
const abiCoder = new ABICoder();
|
|
8
8
|
const addLiquiditySelector = Number(`0x` + abiCoder.encodeSelector('addLiquidity'));
|
|
@@ -33,4 +33,3 @@ const calldata = addLiquidity({
|
|
|
33
33
|
deadline: 5000n,
|
|
34
34
|
});
|
|
35
35
|
console.log('add liquidity:', calldata.toString('hex'));
|
|
36
|
-
await interact(ROUTER_ADDRESS_REGTEST, calldata);
|
|
@@ -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,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 @@
|
|
|
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,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,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'));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BinaryReader } from '@btc-vision/bsi-binary';
|
|
2
|
+
function decodeTransferEvent(data) {
|
|
3
|
+
const reader = new BinaryReader(data);
|
|
4
|
+
const from = reader.readAddress();
|
|
5
|
+
const to = reader.readAddress();
|
|
6
|
+
const value = reader.readU256();
|
|
7
|
+
return { from, to, value };
|
|
8
|
+
}
|
|
9
|
+
const transferEventData = Buffer.from('YmNydDFwcHFrMzZhenl1bnhkcGFkemE3Z3RmNTY4ZWxxeG5odTNsd3VmZzk4ZGFlazNrejA3Mzkwc3d5dnpkMgBiY3J0MXFwaDRqejZkbXc1dW53bThnc2M1dTRxbXkwbXF0bjVkOGF2bHhqNgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9CQA==', 'base64');
|
|
10
|
+
const bytes = Uint8Array.from(transferEventData);
|
|
11
|
+
const transferEvent = decodeTransferEvent(bytes);
|
|
12
|
+
console.log(transferEvent);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BinaryReader } from '@btc-vision/bsi-binary';
|
|
2
|
+
function decodeReserves(data) {
|
|
3
|
+
const reader = new BinaryReader(data);
|
|
4
|
+
return {
|
|
5
|
+
reserve0: reader.readU256(),
|
|
6
|
+
reserve1: reader.readU256(),
|
|
7
|
+
blockTimestampLast: reader.readU64(),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const transferEventData = Buffer.from('AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlxkHwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACGd9QMYGAAAAAAAA', 'base64');
|
|
11
|
+
const bytes = Uint8Array.from(transferEventData);
|
|
12
|
+
const transferEvent = decodeReserves(bytes);
|
|
13
|
+
console.log(transferEvent);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ABICoder, BinaryWriter } from '@btc-vision/bsi-binary';
|
|
2
|
+
import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
3
|
+
import { networks } from 'bitcoinjs-lib';
|
|
4
|
+
const abiCoder = new ABICoder();
|
|
5
|
+
const reservesSelector = Number(`0x` + abiCoder.encodeSelector('getReserves'));
|
|
6
|
+
function getReserves() {
|
|
7
|
+
const calldata = new BinaryWriter();
|
|
8
|
+
calldata.writeSelector(reservesSelector);
|
|
9
|
+
return Buffer.from(calldata.getBuffer());
|
|
10
|
+
}
|
|
11
|
+
const calldata = getReserves();
|
|
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
|
-
|
|
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--) {
|
|
@@ -19,7 +19,7 @@ async function mineBlock() {
|
|
|
19
19
|
return !!ok.length;
|
|
20
20
|
}
|
|
21
21
|
await rpc.init(Regtest.config);
|
|
22
|
-
const requestedAmount = 10n ** 8n *
|
|
22
|
+
const requestedAmount = 10n ** 8n * 500n;
|
|
23
23
|
const utxoSetting = {
|
|
24
24
|
addresses: [wallet.p2wpkh, wallet.p2tr],
|
|
25
25
|
minAmount: 10000n,
|