forked from stakewise/oracle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
81 lines (69 loc) · 2.26 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
import sys
import time
from loguru import logger
from notifiers.logging import NotificationHandler # type: ignore
from src.reward_token import RewardToken
from src.settings import (
WEB3_WS_ENDPOINT,
WEB3_HTTP_ENDPOINT,
INJECT_POA_MIDDLEWARE,
INJECT_STALE_CHECK_MIDDLEWARE,
INJECT_RETRY_REQUEST_MIDDLEWARE,
INJECT_LOCAL_FILTER_MIDDLEWARE,
STALE_CHECK_MIDDLEWARE_ALLOWABLE_DELAY,
ORACLE_PRIVATE_KEY,
BALANCE_WARNING_THRESHOLD,
BALANCE_ERROR_THRESHOLD,
APPLY_GAS_PRICE_STRATEGY,
MAX_TX_WAIT_SECONDS,
LOG_LEVEL,
PROCESS_INTERVAL,
)
from src.utils import (
get_web3_client,
configure_default_account,
InterruptHandler,
check_default_account_balance,
)
# Send notification to admins on error
handler = NotificationHandler("telegram")
logger.remove(0)
logger.add(
sink=sys.stderr,
format="<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green>"
" <level>{level}</level> <level>{message}</level>",
level=LOG_LEVEL,
)
logger.add(handler, level="ERROR", backtrace=False, diagnose=False)
@logger.catch
def main() -> None:
# setup Web3 client
web3_client = get_web3_client(
http_endpoint=WEB3_HTTP_ENDPOINT,
ws_endpoint=WEB3_WS_ENDPOINT,
apply_gas_price_strategy=APPLY_GAS_PRICE_STRATEGY,
max_tx_wait_seconds=MAX_TX_WAIT_SECONDS,
inject_retry_request=INJECT_RETRY_REQUEST_MIDDLEWARE,
inject_poa=INJECT_POA_MIDDLEWARE,
inject_local_filter=INJECT_LOCAL_FILTER_MIDDLEWARE,
inject_stale_check=INJECT_STALE_CHECK_MIDDLEWARE,
stale_check_allowable_delay=STALE_CHECK_MIDDLEWARE_ALLOWABLE_DELAY,
)
# setup default account
configure_default_account(web3_client, ORACLE_PRIVATE_KEY)
# wait for interrupt
interrupt_handler = InterruptHandler()
reward_token_total_rewards = RewardToken(
w3=web3_client, interrupt_handler=interrupt_handler
)
# check oracle balance
check_default_account_balance(
web3_client, BALANCE_WARNING_THRESHOLD, BALANCE_ERROR_THRESHOLD
)
while not interrupt_handler.exit:
# update Reward Token total rewards
reward_token_total_rewards.process()
# wait until next processing time
time.sleep(PROCESS_INTERVAL)
if __name__ == "__main__":
main()