forked from ymmmmmmmm/BeraChainTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
230 lines (178 loc) · 7.97 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
# 首先,导入必要的库和模块
from eth_account import Account
from loguru import logger
from bera_tools import BeraChainTools
import time
# 接下来,从配置文件中导入所有需要的地址
from config.address_config import (
usdc_address, wbear_address, weth_address,
bex_approve_liquidity_address, usdc_pool_liquidity_address,
weth_pool_liquidity_address, honey_swap_address, honey_address,
bend_address, bend_pool_address, ooga_booga_address
)
def LingShui(key, proxy):
address = ""
wallet_key = ""
file_path = './wallet.txt'
if os.path.exists(file_path):
with open(file_path, 'r') as file:
content = file.readlines()
print(content)
address = content[0].replace("\n", "").split(':')[-1]
wallet_key = content[1].replace("\n", "").split(':')[-1]
else:
account = Account.create()
wallet_key = account.key.hex()
address = account.address
WriteKey(f'address:{address}\nkey:{wallet_key}')
logger.debug(f'address:{address}')
logger.debug(f'key:{wallet_key}')
# TODO 填写你的 YesCaptcha client key 或者2Captcha API Key 或者 ez-captcha ClientKey
client_key = f'{key}'
# 使用yescaptcha solver googlev3
bera = BeraChainTools(private_key=wallet_key, client_key=client_key,solver_provider='yescaptcha',rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# 使用2captcha solver googlev3
# bera = BeraChainTools(private_key=wallet_key, client_key=client_key,solver_provider='2captcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 使用ez-captcha solver googlev3
# bera = BeraChainTools(private_key=wallet_key, client_key=client_key,solver_provider='ez-captcha',rpc_url='https://rpc.ankr.com/berachain_testnet')
# 不使用代理
result = bera.claim_bera()
# 使用代理
# result = bera.claim_bera(proxies={'http':"http://127.0.0.1:8888","https":"http://127.0.0.1:8888"})
logger.debug(result.text)
return wallet_key
def Bex(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# bex 使用bera交换usdc
bera_balance = bera.w3.eth.get_balance(account.address)
result = bera.bex_swap(int(bera_balance * 0.2), wbear_address, usdc_address)
logger.debug(result)
# bex 使用usdc交换weth
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.bex_swap(int(usdc_balance * 0.2), usdc_address, weth_address)
logger.debug(result)
# 授权usdc
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# bex 增加 usdc 流动性
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(usdc_balance * 0.5), usdc_pool_liquidity_address, usdc_address)
logger.debug(result)
# 授权weth
approve_result = bera.approve_token(bex_approve_liquidity_address, int("0x" + "f" * 64, 16), weth_address)
logger.debug(approve_result)
# bex 增加 weth 流动性
weth_balance = bera.weth_contract.functions.balanceOf(account.address).call()
result = bera.bex_add_liquidity(int(weth_balance * 0.5), weth_pool_liquidity_address, weth_address)
logger.debug(result)
def Honey(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# 授权usdc
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), usdc_address)
logger.debug(approve_result)
# 使用usdc mint honey
usdc_balance = bera.usdc_contract.functions.balanceOf(account.address).call()
result = bera.honey_mint(int(usdc_balance * 0.5))
logger.debug(result)
# 授权honey
approve_result = bera.approve_token(honey_swap_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 赎回
honey_balance = bera.honey_contract.functions.balanceOf(account.address).call()
result = bera.honey_redeem(int(honey_balance * 0.5))
logger.debug(result)
def Bend(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# 授权
approve_result = bera.approve_token(bend_address, int("0x" + "f" * 64, 16), weth_address)
logger.debug(approve_result)
# deposit
weth_balance = bera.weth_contract.functions.balanceOf(account.address).call()
result = bera.bend_deposit(int(weth_balance), weth_address)
logger.debug(result)
# borrow
balance = bera.bend_contract.functions.getUserAccountData(account.address).call()[2]
logger.debug(balance)
result = bera.bend_borrow(int(balance * 0.8 * 1e10), honey_address)
logger.debug(result)
# 授权
approve_result = bera.approve_token(bend_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 查询数量
call_result = bera.bend_borrows_contract.functions.getUserReservesData(bend_pool_address, bera.account.address).call()
repay_amount = call_result[0][0][4]
logger.debug(repay_amount)
# repay
result = bera.bend_repay(int(repay_amount * 0.9), honey_address)
logger.debug(result)
def honeyjar(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# https://faucet.0xhoneyjar.xyz/mint
# 授权
approve_result = bera.approve_token(ooga_booga_address, int("0x" + "f" * 64, 16), honey_address)
logger.debug(approve_result)
# 花费4.2 honey mint
result = bera.honey_jar_mint()
logger.debug(result)
def contract(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
# 安装0.4.18 版本编译器
install_solc('0.4.18')
# 读取sol文件
with open('config/WETH.sol', 'r') as f:
code = f.read()
# 部署合约
result = bera.deploy_contract(code, '0.4.18')
logger.debug(result)
def domain(wallet_key, proxy):
account = Account.from_key(wallet_key)
bera = BeraChainTools(private_key=account.key, rpc_url='https://rpc.ankr.com/berachain_testnet', proxy=proxy)
result = bera.create_bera_name()
logger.debug(result)
def ReadKey():
# Define the path to the file
file_path = './client_key.txt'
# Open the file in read mode ('r') and read the contents
with open(file_path, 'r') as file:
content = file.read()
return content
def WriteKey(text = ''):
# Define the path to the file
file_path = './wallet.txt'
# Open the file in write mode ('w') and write the text
with open(file_path, 'w') as file:
file.write(text)
print("Wallet written to file successfully.")
def getSocks5():
file_path = './s5_ip.txt'
with open(file_path, 'r') as file:
content = file.read()
return content
if __name__ == '__main__':
# print(get_no_captcha_google_token(''))
proxy = getSocks5()
client_key = ReadKey()
next_call = time.time() + 28801 # 当前时间加上8小时(以秒为单位)
wallet_key = LingShui(client_key, proxy)
while True:
current_time = time.time()
if current_time >= next_call:
LingShui(client_key, proxy)
next_call = current_time + 28801 # 更新下一次调用的时间
Bex(wallet_key, proxy)
time.sleep(60)
Honey(wallet_key, proxy)
time.sleep(60)
Bend(wallet_key, proxy)
time.sleep(60)
honeyjar(wallet_key, proxy)
time.sleep(60)
contract(wallet_key, proxy)
time.sleep(60)
domain(wallet_key, proxy)
time.sleep(300)