-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
207 lines (182 loc) · 11.7 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
from dotenv import load_dotenv
from mixpanel import Mixpanel
import os
import sentry_sdk
import sys
from api.functions import get_from_block, get_refund_list, get_refund_list_optimism
from web3 import Web3
from eth_account import Account
from api.blockscan_api import BlockscanConnector
from web3.gas_strategies.rpc import rpc_gas_price_strategy
mp: Mixpanel
def refund_tx(w3: Web3, refund_list: dict, refund_contract_address: str, refund_contract_abi: dict, chain_name: str, account_from):
w3.eth.set_gas_price_strategy(rpc_gas_price_strategy)
value = 0
address_list = []
amount_list = []
for receiver in refund_list:
value += refund_list[receiver]
address_list.append(w3.toChecksumAddress(receiver))
amount_list.append(refund_list[receiver])
mp.track(receiver, 'GAS_REFUND', {'TYPE': chain_name, 'VALUE': refund_list[receiver]})
if value > 0: # this should be added. if value equals zero, we don't need to run tx.
refund_sc = w3.eth.contract(address=refund_contract_address, abi=refund_contract_abi)
nonce = w3.eth.get_transaction_count(account_from.address)
tx_create = refund_sc.functions.refund(address_list, amount_list).build_transaction({"value": value, "nonce": nonce, "from": account_from.address})
signed_tx = w3.eth.account.sign_transaction(tx_create, private_key=account_from.key)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(f"Transaction successful with hash: { tx_receipt.transactionHash.hex() }")
else:
print('no refund needed')
def refund_eip1559_tx(w3: Web3, refund_list: dict, refund_contract_address: str, refund_contract_abi: dict, chain_name: str, account_from):
value = 0
address_list = []
amount_list = []
for receiver in refund_list:
value += refund_list[receiver]
address_list.append(w3.toChecksumAddress(receiver))
amount_list.append(refund_list[receiver])
mp.track(receiver, 'GAS_REFUND', {'TYPE': chain_name, 'VALUE': refund_list[receiver]})
if value > 0: # this should be added. if value equals zero, we don't need to run tx.
refund_sc = w3.eth.contract(address=refund_contract_address, abi=refund_contract_abi)
nonce = w3.eth.get_transaction_count(account_from.address)
max_priority_fee = w3.eth.max_priority_fee
gas_price = w3.eth.gas_price * 2 + max_priority_fee
tx_create = refund_sc.functions.refund(address_list, amount_list).build_transaction({"value": value, "nonce": nonce, "from": account_from.address, "maxFeePerGas": gas_price, "maxPriorityFeePerGas": max_priority_fee})
signed_tx = w3.eth.account.sign_transaction(tx_create, private_key=account_from.key)
tx_hash = w3.eth.send_raw_transaction(signed_tx.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
print(
f"Transaction successful with hash: { tx_receipt.transactionHash.hex() }")
else:
print('no refund needed')
def bsc_refund():
node = os.environ['BSC_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check BSC node connected: ', w3.isConnected())
private_key = os.environ['BSC_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['BSC_REFUND_WALLET']
refund_contract_address = os.environ['BSC_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['BSCSCAN_API_PREAMBLE'], os.environ['BSCSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['BSC_COMPASS_EVM']
refund_list = get_refund_list(blockscanner, compass_evm, from_block)
refund_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'BNB', refund_wallet)
def eth_refund():
node = os.environ['ETH_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check ETH node connected: ', w3.isConnected())
private_key = os.environ['ETH_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['ETH_REFUND_WALLET']
refund_contract_address = os.environ['ETH_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['ETHERSCAN_API_PREAMBLE'], os.environ['ETHERSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['ETH_COMPASS_EVM']
refund_list = get_refund_list(blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'ETH', refund_wallet)
def polygon_refund():
node = os.environ['POLYGON_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check POLYGON node connected: ', w3.isConnected())
private_key = os.environ['POLYGON_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['POLYGON_REFUND_WALLET']
refund_contract_address = os.environ['POLYGON_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['POLYGONSCAN_API_PREAMBLE'], os.environ['POLYGONSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['POLYGON_COMPASS_EVM']
refund_list = get_refund_list(blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'POLYGON', refund_wallet)
def gnosis_refund():
node = os.environ['GNOSIS_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check GNOSIS node connected: ', w3.isConnected())
private_key = os.environ['GNOSIS_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['GNOSIS_REFUND_WALLET']
refund_contract_address = os.environ['GNOSIS_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['GNOSISSCAN_API_PREAMBLE'], os.environ['GNOSISSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['GNOSIS_COMPASS_EVM']
refund_list = get_refund_list(blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'GNOSIS', refund_wallet)
def optimism_refund():
node = os.environ['OPTIMISM_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check OPTIMISM node connected: ', w3.isConnected())
private_key = os.environ['OPTIMISM_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['OPTIMISM_REFUND_WALLET']
refund_contract_address = os.environ['OPTIMISM_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['OPTIMISMSCAN_API_PREAMBLE'], os.environ['OPTIMISMSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['OPTIMISM_COMPASS_EVM']
refund_list = get_refund_list_optimism(w3, blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'OPTIMISM', refund_wallet)
def arbitrum_refund():
node = os.environ['ARBITRUM_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check ARBITRUM node connected: ', w3.isConnected())
private_key = os.environ['ARBITRUM_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['ARBITRUM_REFUND_WALLET']
refund_contract_address = os.environ['ARBITRUM_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['ARBITRUMSCAN_API_PREAMBLE'], os.environ['ARBITRUMSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['ARBITRUM_COMPASS_EVM']
refund_list = get_refund_list(blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'ARBITRUM', refund_wallet)
def base_refund():
node = os.environ['BASE_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check BASE node connected: ', w3.isConnected())
private_key = os.environ['BASE_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['BASE_REFUND_WALLET']
refund_contract_address = os.environ['BASE_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['BASESCAN_API_PREAMBLE'], os.environ['BASESCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['BASE_COMPASS_EVM']
refund_list = get_refund_list_optimism(w3, blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'BASE', refund_wallet)
def blast_refund():
node = os.environ['BLAST_NODE']
w3 = Web3(Web3.HTTPProvider(node))
print('check BLAST node connected: ', w3.isConnected())
private_key = os.environ['BLAST_PRIVATE_KEY']
refund_wallet = Account.from_key(private_key)
assert refund_wallet.address == os.environ['BLAST_REFUND_WALLET']
refund_contract_address = os.environ['BLAST_REFUND_CONTRACT']
refund_contract_abi = [{"type": "function", "name": "refund", "stateMutability": "payable", "inputs": [{"name": "receivers", "type": "address[]"}, {"name": "amounts", "type": "uint256[]"}], "outputs": []}]
blockscanner = BlockscanConnector(os.environ['BLASTSCAN_API_PREAMBLE'], os.environ['BLASTSCAN_API_KEY'])
from_block = get_from_block(blockscanner, refund_contract_address, refund_wallet.address)
compass_evm = os.environ['BLAST_COMPASS_EVM']
refund_list = get_refund_list_optimism(w3, blockscanner, compass_evm, from_block)
refund_eip1559_tx(w3, refund_list, refund_contract_address, refund_contract_abi, 'BLAST', refund_wallet)
def main():
load_dotenv()
global mp
mp = Mixpanel(os.environ['MIXPANEL_TOKEN'])
sentry_sdk.init(dsn=os.environ['SENTRY_DSN'], traces_sample_rate=1.0)
current_dir = os.getcwd()
sys.path.insert(1, os.path.abspath(os.path.join(current_dir, '../../')))
bsc_refund()
polygon_refund()
eth_refund()
optimism_refund()
gnosis_refund()
arbitrum_refund()
base_refund()
blast_refund()
if __name__ == "__main__":
main()