-
Notifications
You must be signed in to change notification settings - Fork 3
/
deployAllAndStart.ts
91 lines (74 loc) · 3.27 KB
/
deployAllAndStart.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
import { SendMode, fromNano, toNano } from '@ton/core';
import { MasterCounter } from '../wrappers/MasterCounter';
import { compile, NetworkProvider, sleep } from '@ton/blueprint';
import { monitorTPSfromMaster, now, readCreateKeyPair, setMasterCounter } from '../wrappers/utils';
import { Retranslator, RetranslatorOptions } from '../wrappers/Retranslator';
const spamConfig: RetranslatorOptions = {
amount: toNano(4000000),
hops: 999999999,
threads: 20,
splitHops: 9,
sameShardProbability: 1.0,
};
const masterCounterBalance = toNano('100');
export async function run(provider: NetworkProvider) {
const sender = provider.sender();
const ui = provider.ui();
const deployerAddr = sender.address!;
await ui.input(
"You'll need about " +
fromNano(
(spamConfig.amount || toNano(20000)) * BigInt(spamConfig.threads || 1) +
masterCounterBalance +
toNano(1)
) +
' TON for this action. Press Enter to continue...'
);
const keypair = await readCreateKeyPair();
const masterCounterCode = await compile('MasterCounter');
const masterCounter = provider.open(
MasterCounter.createFromConfig(
{ owner: deployerAddr, publicKey: keypair.publicKey },
masterCounterCode,
-1 // workchain = masterchain
)
);
setMasterCounter(masterCounter.address);
const retranslatorCode = await compile('Retranslator');
const counterCode = await compile('Counter');
const retranslator0 = provider.open(
Retranslator.createFromConfig({ id: 0, keypair, counterCode }, retranslatorCode)
);
ui.write('Deploying master counter to the masterchain and/or giving it the counter code, addr: ' + masterCounter.address.toString() + '\n');
await masterCounter.sendCounterCode(sender, counterCode, masterCounterBalance);
await provider.waitForDeploy(masterCounter.address, 10);
ui.write('Activated master counter: ' + masterCounter.address.toString() + '\n');
const topupAmount = (spamConfig.amount || toNano(20000)) * BigInt(spamConfig.threads || 1) + toNano('1');
try {
ui.write('Trying to topup from connected wallet (won\'t work with mobile wallets)');
await sender.send({
to: retranslator0.address,
value: topupAmount,
bounce: false,
sendMode: SendMode.PAY_GAS_SEPARATELY,
});
} catch {
ui.write(
'Please, topup the first retranslator with ' +
fromNano(topupAmount) +
' TON: ' +
retranslator0.address.toString({ bounceable: false })
);
await ui.input("Press Enter when you're ready...");
}
ui.write("We'll hope retranslator " + retranslator0.address.toString() + ' now have coins...\n');
await ui.input('Press Enter to start the spam...');
await retranslator0.sendStart(spamConfig);
const startTime = now();
sleep(3000);
ui.write('Started spam. Here is the TPS monitor:\n');
await monitorTPSfromMaster(masterCounter, ui);
const endTime = now() - 120; // 2 mins for monitor to stop
const totalTPS = await masterCounter.getTpsOnPeriod(startTime, endTime);
ui.write('Total average TPS: ' + totalTPS.toString());
}