-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathapp.ts
174 lines (146 loc) · 5.85 KB
/
app.ts
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
import * as dotenv from "dotenv"
import { AptosClient, AptosAccount, CoinClient } from "aptos"
import { promises as fs } from 'fs'
import * as path from 'path'
import delay from "delay"
import { Telegraf } from "telegraf"
dotenv.config()
const NODE_URL = process.env.NODE_URL
const BOT = process.env.BOT_TOKEN
const ADMIN = process.env.TELEGRAM_ID
const FAUCET_KEY = process.env.FAUCET_KEY
const END_KEY = process.env.END_KEY
const SWAPS = process.env.MAX_SWAPS || 3
const MIXS = parseInt(process.env.MAX_MIXS) || 2
const TIMEOUT = parseInt(process.env.TIMEOUT || '250')
const GLOBAL_DELAY = parseInt(process.env.GLOBAL_DELAY || '10000')
const AMOUNT = Math.floor((parseInt(process.env.MAX_AMOUNT || '1') / 2) * 100000000)
// Init
const bot = new Telegraf(BOT)
const client = new AptosClient(NODE_URL)
const coinClient = new CoinClient(client)
// const tokenClient = new TokenClient(client)
// Helpers
const toAPT = (value: bigint | string, fixed = 4) => (Number(value) / 100000000).toFixed(fixed)
const randomInt = (value) => Math.floor(Math.random() * value)
const isLocal = process.env.NODE_ENV !== 'production'
// Transactions
const sendTransaction = async (wallet : AptosAccount, payload, simulate = false) => {
try {
const rawTxn = await client.generateTransaction(wallet.address(), payload)
const bcsTxn = await client.signTransaction(wallet, rawTxn)
if (simulate) {
const simulate = await client.simulateTransaction(wallet, rawTxn)
console.log(simulate)
return true
}
const transaction = await client.submitTransaction(bcsTxn)
// console.log('https://explorer.aptoslabs.com/txn/' + transaction.hash + '?network=testnet')
return await client.waitForTransactionWithResult(transaction.hash)
} catch (e) {
console.log(e)
return 'Send transaction error'
}
}
// Get wallet by key
const getSigner = async (key) => await AptosAccount.fromAptosAccountObject({ privateKeyHex: key });
// Send some APT
const sendSomeAPT = async (from : AptosAccount, to : AptosAccount, amount : bigint) =>
await sendTransaction(from, {
"function": "0x1::aptos_account::transfer",
"type_arguments": [],
"arguments": [
to.address(),
amount
]
})
// Aptoswap contract
const contract = '0xa5d3ac4d429052674ed38adc62d010e52d7c24ca159194d17ddc196ddb7e480b'
const swap = async (wallet : AptosAccount) => {
const input = '0x1::aptos_coin::AptosCoin'
const output = '0x498d8926f16eb9ca90cab1b3a26aa6f97a080b3fcbe6e83ae150b7243a00fb68::devnet_coins::DevnetBTC'
const balance = await coinClient.checkBalance(wallet).catch(e => null) - BigInt(100000000 + randomInt(100000))
let outputAmount = parseInt(balance.toString())
const inputAmount = Math.floor(outputAmount / 3.741)
await sendTransaction(wallet, {
"function": `${contract}::pool::swap_y_to_x`,
"type_arguments": [ output, input ],
"arguments": [ BigInt(outputAmount).toString(), BigInt(inputAmount).toString() ]
})
await delay(TIMEOUT + randomInt(TIMEOUT))
outputAmount = Math.floor(inputAmount * 3.649)
await sendTransaction(wallet, {
"function": `${contract}::pool::swap_x_to_y`,
"type_arguments": [ output, input ],
"arguments": [ BigInt(inputAmount).toString(), BigInt(outputAmount).toString() ]
})
}
// Return all tokens
const sendAllAPT = async (from : AptosAccount, to : AptosAccount) => {
const balance = await coinClient.checkBalance(from).catch(e => null)
return sendSomeAPT(from, to, balance - await client.estimateMaxGasAmount(from.address()))
}
// Simple mixer
const mixer = async (faucet: AptosAccount, wallet: AptosAccount, amount, count = 2) => {
const mixers = []
for (let i = 0; i <= count; i++)
mixers.push(await new AptosAccount())
await sendSomeAPT(faucet, mixers[0], amount)
for (let i = 0; i < mixers.length - 1; i++) {
await sendAllAPT(mixers[i], mixers[i+1])
await delay(1500)
if (isLocal) await fs.appendFile(path.join(__dirname, '/wallets/temps.txt'), `${mixers[i].toPrivateKeyObject().privateKeyHex}\n`)
else bot.telegram.sendMessage(ADMIN, mixers[i].toPrivateKeyObject().privateKeyHex)
}
await sendAllAPT(mixers[mixers.length-1], wallet)
}
// Swaps multiple
const someSwaps = async (wallet, timeout, repeats) => {
for (let i = 0; i < repeats; i++) {
await swap(wallet).catch(e => console.log(e))
await delay(randomInt(timeout))
}
}
let state = false
const abuse = async () => {
bot.telegram.sendMessage(ADMIN, 'Start abuse https://testnet.aptoswap.net/ !')
const start = await getSigner(FAUCET_KEY)
const end = await getSigner(END_KEY)
for (;;) {
if (!state) break
try {
const amount = BigInt(AMOUNT + randomInt(AMOUNT))
const balance = await coinClient.checkBalance(start)
if (balance < BigInt(amount)) {
bot.telegram.sendMessage(ADMIN, 'Refill balance of faucet wallet!')
await sendAllAPT(end, start)
} else {
const wallet = await new AptosAccount()
console.log('1. Start mixing...')
await mixer(start, wallet, amount, MIXS)
console.log('2. Making swaps...')
await someSwaps(wallet, 500, 1 + randomInt(SWAPS))
console.log('3. Return funds...')
await sendAllAPT(wallet, end)
console.log('Wait some time and start again!\nPress CONTROL+C in two seconds to break script!')
if (isLocal) await fs.appendFile(path.join(__dirname, '/wallets/wallets.txt'), `${wallet.toPrivateKeyObject().privateKeyHex}\n`)
else bot.telegram.sendMessage(ADMIN, wallet.toPrivateKeyObject().privateKeyHex)
await delay(GLOBAL_DELAY)
}
} catch (e) {
console.log(e)
bot.telegram.sendMessage(ADMIN, 'Abuse bot broken, see console logs and try reboot server!')
await delay(5000)
}
}
}
bot.command('abuse', (ctx) => {
state = true
ctx.reply('Starting...')
abuse()
})
bot.command('stop', (ctx) => {
state = false
ctx.reply('Stop abusing')
})
bot.launch()