-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
340 lines (255 loc) · 13.8 KB
/
main.py
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import time
import random
from datetime import timedelta
from core.config import BRIDGE_CONTRACT_ABI, BRIDGE_CONTRACT_ADDRESS, REDDIO_RPC_URL, REDDIO_COIN_NAME, SEPOLIA_CHAIN_ID, SEPOLIA_RPC_URL
from core.utils import connect_to_web3, get_account, random_between, retry
from solcx import install_solc, set_solc_version, compile_source
from colorama import Fore, Style, init
# Install Solidity Compiler
install_solc('0.8.0')
set_solc_version('0.8.0')
# Initialize colorama for terminal color support
init(autoreset=True)
# ASCII art with red and white colors
ASCII_ART = r"""
░▒▓███████▓▒░▒▓█▓▒░░▒▓█▓▒░░▒▓██████▓▒░░▒▓████████▓▒░░▒▓██████▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░░▒▓█▓▒░ ░▒▓██▓▒░░▒▓█▓▒░░▒▓█▓▒░
░▒▓██████▓▒░ ░▒▓██████▓▒░░▒▓████████▓▒░ ░▒▓██▓▒░ ░▒▓████████▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░░▒▓██▓▒░ ░▒▓█▓▒░░▒▓█▓▒░
░▒▓█▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░
░▒▓███████▓▒░ ░▒▓█▓▒░ ░▒▓█▓▒░░▒▓█▓▒░▒▓████████▓▒░▒▓█▓▒░░▒▓█▓▒░
"""
# Red and White colors
RED = Fore.RED
WHITE = Fore.WHITE
def print_red_white_ascii_art():
"""Prints ASCII art with the top half in red and bottom half in white."""
# Split ASCII art into lines
ascii_lines = ASCII_ART.split('\n')
# Calculate the middle of the ASCII art (to split it into red and white parts)
mid_point = len(ascii_lines) // 2
# Print the upper half in red
for i in range(mid_point):
print(RED + ascii_lines[i] + Style.RESET_ALL)
# Print the lower half in white
for i in range(mid_point, len(ascii_lines)):
print(WHITE + ascii_lines[i] + Style.RESET_ALL)
# Add the 'Reddio Onchain' text at the bottom right in white
text_to_add = "Reddio Onchain"
# Find the length of the longest line in ASCII art
max_line_length = max(len(line) for line in ascii_lines) # Find the longest line
# Adjust the text position to be closer to the bottom right (exact alignment)
text_position = max_line_length - len(text_to_add) # Position text at the exact right
# Print the text with no extra spaces and apply white color
print(WHITE + " " * text_position + text_to_add + Style.RESET_ALL)
CONTRACT_SOURCE_CODE = '''
pragma solidity ^0.8.0;
contract SimpleStorage {
uint256 storedData;
constructor() {
storedData = 100;
}
function set(uint256 x) public {
storedData = x;
}
function get() public view returns (uint256) {
return storedData;
}
}
'''
def countdown_timer(seconds):
while seconds:
time_display = str(timedelta(seconds=seconds))
print(f"Restarting in: {time_display}", end="\r")
time.sleep(1)
seconds -= 1
print("\nStarting new cycle...")
def send_eth(account, amount):
web3 = connect_to_web3(REDDIO_RPC_URL)
balance_wei = web3.eth.get_balance(account.address)
balance_eth = web3.from_wei(balance_wei, 'ether')
print(f"Balance of {account.address}: {balance_eth} {REDDIO_COIN_NAME}")
nonce = web3.eth.get_transaction_count(account.address)
print(f"nonce of {account.address}: {nonce}")
tx = {
'nonce': nonce,
'to': account.address,
'value': web3.to_wei(amount, 'ether'),
'gas': 1000000,
'gasPrice': web3.to_wei(2.5, 'gwei')
}
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_hash_link = f"https://reddio-devnet.l2scan.co/tx/{web3.to_hex(tx_hash)}"
print(f"Transaction hash: {tx_hash_link}")
time.sleep(3)
receipt = retry(lambda: web3.eth.wait_for_transaction_receipt(tx_hash, timeout=120), max_retries=5, wait_time=2)
txStatus = "Success" if receipt.status == 1 else "Failed"
print(f"Transaction hash: {receipt.transactionHash.hex()} ({txStatus})")
def bridge_eth(account, amount_eth):
web3 = connect_to_web3(SEPOLIA_RPC_URL)
balance_wei = web3.eth.get_balance(account.address)
balance_eth = web3.from_wei(balance_wei, 'ether')
print(f"Balance of {account.address}: {balance_eth} ETH")
nonce = web3.eth.get_transaction_count(account.address)
contract = web3.eth.contract(address=BRIDGE_CONTRACT_ADDRESS, abi=BRIDGE_CONTRACT_ABI)
recipient_address = account.address
amount_in_wei = web3.to_wei(amount_eth, 'ether')
escrow_fee = 3000000
gas_price = round(float(web3.from_wei(web3.eth.gas_price, 'gwei')) * random_between(1.3, 1.4), 2)
tx = contract.functions.depositETH(
recipient_address,
amount_in_wei,
escrow_fee
).build_transaction({
'chainId': SEPOLIA_CHAIN_ID,
'gas': 100000,
'gasPrice': web3.to_wei(gas_price, 'gwei'),
'nonce': nonce,
'value': amount_in_wei,
})
signed_tx = web3.eth.account.sign_transaction(tx, private_key)
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_hash_link = f"https://sepolia.etherscan.io/tx/{web3.to_hex(tx_hash)}"
print(f"Transaction hash: {tx_hash_link}")
receipt = retry(lambda: web3.eth.wait_for_transaction_receipt(tx_hash, timeout=120), max_retries=5, wait_time=2)
txStatus = "Success" if receipt.status == 1 else "Failed"
print(f"Transaction hash: {receipt.transactionHash.hex()} ({txStatus})")
# Fungsi untuk menghasilkan nama token acak dengan menggabungkan kata sifat dan kata benda
def generate_creative_token():
adjectives = [
"Quantum", "Stellar", "Lunar", "Solar", "Crypto", "Nebula", "Galaxy", "Ether", "Cosmic", "Radiant",
"Celestial", "Ethereal", "Digital", "Futuristic", "Ancient", "Nova", "Atomic", "Eclipse", "Infinite", "Vortex"
]
nouns = [
"Chain", "Element", "Coin", "Token", "Crystal", "Verse", "Galaxy", "Universe", "Sphere", "Orbit",
"Network", "Link", "Foundation", "Block", "Core", "Matrix", "Circuit", "Realm", "Force", "Core", "System"
]
adjective = random.choice(adjectives)
noun = random.choice(nouns)
name = f"{adjective} {noun}"
contract_name = name.replace(" ", "_")
symbol = generate_symbol(name)
return contract_name, name, symbol
# Fungsi untuk menghasilkan simbol token berdasarkan nama token
def generate_symbol(name):
words = name.split()
symbol = ''.join([word[0] for word in words]).upper()
for word in words:
symbol += random.choice(word[1:3]).upper()
return symbol
# Fungsi untuk menghasilkan initial supply acak (antara 1 juta sampai 1 miliar)
def generate_initial_supply():
return random.randint(1000000, 1000000000)
# Perbarui fungsi deploy_contract agar nama, simbol, dan supply acak digunakan
def deploy_contract(account):
web3 = connect_to_web3(REDDIO_RPC_URL)
try:
contract_name, token_name, symbol = generate_creative_token()
initial_supply = generate_initial_supply()
updated_contract_code = f'''
pragma solidity ^0.8.0;
interface IERC20 {{
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address recipient, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}}
contract {contract_name} is IERC20 {{
string public name = "{token_name}";
string public symbol = "{symbol}";
uint8 public decimals = 18;
uint256 private _totalSupply;
mapping(address => uint256) private _balances;
mapping(address => mapping(address => uint256)) private _allowances;
constructor(uint256 initialSupply) {{
_totalSupply = initialSupply * (10 ** uint256(decimals));
_balances[msg.sender] = _totalSupply;
emit Transfer(address(0), msg.sender, _totalSupply);
}}
function totalSupply() public view override returns (uint256) {{
return _totalSupply;
}}
function balanceOf(address account) public view override returns (uint256) {{
return _balances[account];
}}
function transfer(address recipient, uint256 amount) public override returns (bool) {{
require(recipient != address(0), "ERC20: transfer to the zero address");
require(_balances[msg.sender] >= amount, "ERC20: transfer amount exceeds balance");
_balances[msg.sender] -= amount;
_balances[recipient] += amount;
emit Transfer(msg.sender, recipient, amount);
return true;
}}
function allowance(address owner, address spender) public view override returns (uint256) {{
return _allowances[owner][spender];
}}
function approve(address spender, uint256 amount) public override returns (bool) {{
_allowances[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {{
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(_balances[sender] >= amount, "ERC20: transfer amount exceeds balance");
require(_allowances[sender][msg.sender] >= amount, "ERC20: transfer amount exceeds allowance");
_balances[sender] -= amount;
_balances[recipient] += amount;
_allowances[sender][msg.sender] -= amount;
emit Transfer(sender, recipient, amount);
return true;
}}
}}
'''
compiled_sol = compile_source(updated_contract_code)
contract_interface = compiled_sol[f'<stdin>:{contract_name}']
abi = contract_interface['abi']
bytecode = contract_interface['bin']
TokenContract = web3.eth.contract(abi=abi, bytecode=bytecode)
gas_estimate = TokenContract.constructor(initial_supply).estimate_gas({'from': account.address})
print(f"Gas estimate for {token_name} ({symbol}) deployment: {gas_estimate}")
transaction = TokenContract.constructor(initial_supply).build_transaction({
'from': account.address,
'nonce': web3.eth.get_transaction_count(account.address),
'gas': gas_estimate + 10000,
'gasPrice': web3.eth.gas_price,
})
signed_tx = web3.eth.account.sign_transaction(transaction, account.key)
tx_hash = web3.eth.send_raw_transaction(signed_tx.raw_transaction)
tx_hash_link = f"https://reddio-devnet.l2scan.co/tx/{web3.to_hex(tx_hash)}"
print(f"Deployment transaction for {token_name} sent. Hash: {tx_hash_link}")
receipt = retry(lambda: web3.eth.wait_for_transaction_receipt(tx_hash, timeout=120), max_retries=5, wait_time=2)
print(f"{token_name} contract deployed at: {receipt.contractAddress}")
except Exception as e:
print(f"Failed to deploy contract: {str(e)}")
if __name__ == "__main__":
print_red_white_ascii_art()
deploy_choice = input("Apakah Anda ingin menjalankan deploy token? (y/n): ").strip().lower()
deploy_contract_flag = deploy_choice == 'y'
web3 = connect_to_web3(REDDIO_RPC_URL)
with open('data/private_keys.txt') as f:
private_keys = f.readlines()
private_keys = [x.strip() for x in private_keys]
while True:
for i, private_key in enumerate(private_keys):
print(f"================================================================================\n")
account = get_account(web3, private_key)
send_amount = random_between(0.0001, 0.001)
wallet_link = f"https://reddio-devnet.l2scan.co/address/{account.address}"
print(f"Sending {send_amount} RED to {wallet_link}")
send_eth(account, send_amount)
bridge_amount = random_between(0.0001, 0.0009)
print(f"Bridging {bridge_amount} ETH from Sepolia to Reddio ({wallet_link})")
bridge_eth(account, bridge_amount)
if deploy_contract_flag:
print(f"Deploying contract for {wallet_link}")
deploy_contract(account)
print(f"================================================================================\n")
delay_seconds = random_between(86400, 86777)
countdown_timer(int(delay_seconds))