This repository has been archived by the owner on Jul 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
232 lines (215 loc) · 8.89 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
import random
import logging
import time
from web3 import Web3
from web3.gas_strategies.rpc import rpc_gas_price_strategy
import os
from dotenv import load_dotenv
from utils.actions import build_and_send_transaction, read_function_from_contract
from utils.utils import read_abi
from utils.constants import LZ_VALUE, GENEREAL_SLEEP_TIMER
ACTION_MULTIPLIER = 1000 # Make sure you have testnet gas! :)
load_dotenv()
account_address = os.getenv("ACCOUNT_ADDRESS")
private_key = os.getenv("PRIVATE_KEY")
url = os.getenv("ARBITRUM_GOERLI_URL")
web3 = Web3(Web3.HTTPProvider(url))
web3.eth.set_gas_price_strategy(
rpc_gas_price_strategy
) # Set gas price strategy to RPC, auto set gas.
if __name__ == "__main__":
# Check wallet balance in ETH
main_contract_address = "0xe0875CBD144Fe66C015a95E5B2d2C15c3b612179"
faucet_address = "0xfb2c2196831DeEb8311d2CB4B646B94Ed5eCF684"
bridge_contract = "0x2F1673beD3E85219E2B01BC988ABCc482261c38c"
eth_usd_chainlink_feed = "0xd30e2101a97dcbAeBCBC04F14C3f624E67A35165"
main_abi = read_abi(f"./abis/{main_contract_address}.json")
faucet_abi = read_abi(f"./abis/{faucet_address}.json")
chainlink_abi = read_abi(f"./abis/{eth_usd_chainlink_feed}.json")
bridge_abi = read_abi(f"./abis/{bridge_contract}.json")
running_total_diff = 0
amount_to_swap = 10
for c in range(ACTION_MULTIPLIER):
initial_balance = web3.from_wei(web3.eth.get_balance(account_address), "ether")
logging.info(f"Wallet balance: {initial_balance} ETH")
# Faucet action preparation
synthr_faucet_token_amount = int(
10 * 1e18 + random.randint(0, 100) * 1e18
) # Faucet amount to extract
# Synthr Faucet extract tokens
build_and_send_transaction(
web3_client=web3,
contract_address=Web3.to_checksum_address(faucet_address),
function_name="faucetToken",
abi=faucet_abi,
account_address=account_address,
private_key=private_key,
function_args=(synthr_faucet_token_amount,),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Approve Synthr faucet tokens
build_and_send_transaction(
web3_client=web3,
contract_address=faucet_address,
function_name="approve",
abi=faucet_abi,
account_address=account_address,
private_key=private_key,
function_args=(
main_contract_address,
115792089237316195423570985008687907853269984665640564039457584007913129639935,
),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Deposit Synthr faucet tokens
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="issueSynths",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
"0x4545544800000000000000000000000000000000000000000000000000000000",
synthr_faucet_token_amount,
0,
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
0,
False,
),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Issue sUSD
issue_amount = int(1e18 * 10_000) + random.randint(
0, int(1e8)
) # 10,000 sUSD + random amount
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="issueSynths",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
"0x0000000000000000000000000000000000000000000000000000000000000000",
0,
issue_amount,
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
0,
False,
),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Burn sUSD
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="burnSynths",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
int(issue_amount // 1e8),
"0x7355534400000000000000000000000000000000000000000000000000000000",
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Withdraw Collateral
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="withdrawCollateral",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
"0x4554480000000000000000000000000000000000000000000000000000000000",
int(
issue_amount // 1e8
), # Feel free to change it to any amount you want,
# if you want to test liquidation functionality of the protocol.
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
0,
False,
),
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Cross chain swap, you need lz_value (to add more fees), to change chainID,
# please test via UI to get the rest of arguments correctly.
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="exchangeAtomically",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
"0x7355534400000000000000000000000000000000000000000000000000000000",
int(100 * 1e18), # 100 sUSD
"0x7355534400000000000000000000000000000000000000000000000000000000",
98802000000000000000,
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
10106,
False,
),
lz_value=LZ_VALUE,
)
time.sleep(GENEREAL_SLEEP_TIMER)
# Same chain swap
eth_usd_price_raw = read_function_from_contract(
web3_client=web3,
contract_address=eth_usd_chainlink_feed,
function_name="latestAnswer",
abi=chainlink_abi,
).call()
eth_usd_price = int(eth_usd_price_raw) / 1e8 if eth_usd_price_raw != 0 else 0
usd_eth_price = 1 / eth_usd_price
build_and_send_transaction(
web3_client=web3,
contract_address=main_contract_address,
function_name="exchangeAtomically",
abi=main_abi,
account_address=account_address,
private_key=private_key,
function_args=(
"0x7355534400000000000000000000000000000000000000000000000000000000",
int(amount_to_swap * 1e18), # 10 sUSD
"0x7345544800000000000000000000000000000000000000000000000000000000",
int(usd_eth_price * amount_to_swap * 1e18)
- 68014044637676, # min amount received, tinker as price changes, this is an example.
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
0,
False,
),
)
# Bridge only every % 10 == 0 iteration
if c % 10 == 0:
# Bridge some sUSD to another chain, similar to cross chain swap,
# you need to test via UI to get the right arguments.
bridge_amount = int(10 * 1e18) + random.randint(0, 10000000000)
build_and_send_transaction(
web3_client=web3,
contract_address=bridge_contract,
function_name="bridgeSynth",
abi=bridge_abi,
account_address=account_address,
private_key=private_key,
function_args=(
account_address,
"0x7355534400000000000000000000000000000000000000000000000000000000",
bridge_amount,
"0x4c617965725a65726f0000000000000000000000000000000000000000000000",
10106,
False,
),
lz_value=LZ_VALUE,
)
time.sleep(GENEREAL_SLEEP_TIMER)
balance = web3.from_wei(web3.eth.get_balance(account_address), "ether")
diff = initial_balance - balance
running_total_diff += diff
logging.warning(
f"Difference from initial balance: {-diff} ETH, from {initial_balance} to {balance}"
)
logging.warning(f"Running total difference: {-running_total_diff} ETH")