-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
79 lines (68 loc) · 3.36 KB
/
main.py
File metadata and controls
79 lines (68 loc) · 3.36 KB
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
import asyncio
import json
from time import time_ns
from build_onchain_metadata import get_onchain_metadata
from wallet_w5 import *
from constats import *
ONCHAIN_METADATA = get_onchain_metadata()
def create_transfer_message(jetton_amount, user_address, first_unlock_time, first_unlock_size, unlocks_number, cycle_length=int(30.5 * ONE_DAY)):
first_unlock_size = (first_unlock_size * 100000000) // jetton_amount
payload = (begin_cell()
.store_address(JETTON_MINTER_ADDRESS)
.store_address(user_address)
.store_uint(first_unlock_time, 32)
.store_uint(first_unlock_size, 32)
.store_uint(cycle_length, 32)
.store_uint(unlocks_number, 32)
.store_maybe_ref(ONCHAIN_METADATA)
.end_cell())
return (begin_cell()
.store_uint(0x0f8a7ea5, 32)
.store_uint(time_ns(), 64)
.store_coins(jetton_amount)
.store_address(FACTORY_ADDRESS)
.store_address(WALLET_ADDRESS)
.store_bit(0)
.store_coins(int(0.2 * 10 ** 9))
.store_maybe_ref(payload)
.end_cell())
async def get_jetton_wallet_address(client: LiteBalancer) -> Address:
res = await client.run_get_method(JETTON_MINTER_ADDRESS, "get_wallet_address", [begin_cell().store_address(WALLET_ADDRESS).to_slice()])
return res[0].load_address()
async def get_account_seqno(client: LiteBalancer, address: Address) -> int:
res = await client.run_get_method(address, "seqno", [])
return res[0]
async def process_messages(client: LiteBalancer, wallet: WalletV5, messages: list[WalletMessage]):
seqno = await get_account_seqno(client, wallet.address)
transfer_msg = WalletV5.raw_create_transfer_msg(private_key=PRIVATE_KEY, seqno=seqno, wallet_id=wallet.wallet_id, messages=messages)
external_msg = wallet.create_external_msg(dest=wallet.address, body=transfer_msg)
await client.raw_send_message(external_msg.serialize().to_boc())
while seqno == await get_account_seqno(client, wallet.address):
await asyncio.sleep(1)
async def main():
# with open("network-config.json", "r") as f:
# network_config = json.load(f)
# client = LiteBalancer.from_config(network_config, trust_level=2)
client = LiteBalancer.from_mainnet_config(trust_level=2)
await client.start_up()
wallet = await WalletV5.from_mnemonic(client, MNEMONIC)
assert wallet.address == Address(WALLET_ADDRESS)
jetton_wallet_address = await get_jetton_wallet_address(client)
messages = []
with open("users.csv", "r") as f:
data = f.readlines()[1:]
for i in range(len(data)):
user_address, jetton_amount, first_unlock_time, first_unlock_size, unlocks_number = data[i].split(",")
messages.append(WalletV5.create_wallet_internal_message(jetton_wallet_address,
value=int(0.255 * 10 ** 9),
body=create_transfer_message(int(jetton_amount), user_address, int(first_unlock_time), int(first_unlock_size), int(unlocks_number))
))
if (i + 1) % 200 == 0:
await process_messages(client, wallet, messages)
messages = []
print(f"Processed {i} messages")
if messages:
await process_messages(client, wallet, messages)
print(f"Processed {len(data)} messages")
if __name__ == "__main__":
asyncio.run(main())