-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathseibot.js
88 lines (67 loc) · 3.8 KB
/
seibot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
import {getSigningClient, getQueryClient} from "@sei-js/core";
import { calculateFee } from "@cosmjs/stargate";
export const seiFunctionBot = async (newMnemonics) => {
const restEndPoint = 'https://rest.atlantic-2.seinetwork.io/';
const rpcEndPoint = 'https://rpc.atlantic-2.seinetwork.io/';
const fee = calculateFee(100000, "0.01usei");
for (let j=0;j<=2000;j++) {
const transactions = [];
for (let i = 0; i < newMnemonics.length; i += 2) {
const transaction = async () => {
try {
const wallet1 = await DirectSecp256k1HdWallet.fromMnemonic(
newMnemonics[i],
{prefix: 'sei'}
);
const wallet2 = await DirectSecp256k1HdWallet.fromMnemonic(
newMnemonics[i + 1],
{prefix: 'sei'}
);
const [firstAccountWallet1] = await wallet1.getAccounts();
const [firstAccountWallet2] = await wallet2.getAccounts();
const queryClient = await getQueryClient(restEndPoint);
const client1 = await getSigningClient(rpcEndPoint, wallet1);
const client2 = await getSigningClient(rpcEndPoint, wallet2);
const wallet1Balances = await queryClient.cosmos.bank.v1beta1
.allBalances({address: firstAccountWallet1.address});
const wallet2Balances = await queryClient.cosmos.bank.v1beta1
.allBalances({address: firstAccountWallet2.address});
const wallet1SeiBalance = wallet1Balances.balances.find(token => token.denom === 'usei')?.amount || '0';
const wallet2SeiBalance = wallet2Balances.balances.find(token => token.denom === 'usei')?.amount || '0';
if (parseInt(wallet1SeiBalance) > 3000) {
const amount = {
amount: String(parseInt(wallet1SeiBalance) - 2000),
denom: 'usei'
};
try {
await client1.sendTokens(firstAccountWallet1.address, firstAccountWallet2.address, [amount], fee);
} catch (err) {
console.error(`Error occurred while sending tokens from wallet ${firstAccountWallet1.address} to ${firstAccountWallet2.address}: ${err.message}`);
}
} else if (parseInt(wallet2SeiBalance) > 3000) {
const amount = {
amount: String(parseInt(wallet2SeiBalance) - 2000),
denom: 'usei'
};
try {
await client2.sendTokens(firstAccountWallet2.address, firstAccountWallet1.address, [amount], fee);
} catch (err) {
console.error(`Error occurred while sending tokens from wallet ${firstAccountWallet2.address} to ${firstAccountWallet1.address}: ${err.message}`);
}
} else {
console.log('Dont have a balance');
}
} catch (err) {
console.error(`Error occurred while processing transactions: ${error.message}`);
}
console.log(`Done wallets: ${i} ${i+1}`);
}
transactions.push(transaction());
}
await Promise.allSettled(transactions).catch(err => console.log(err));
console.log(`Done iteration ${j}`);
await new Promise(resolve => setTimeout(resolve, 20000));
}
//TODO: Add sending function
}