3737SERVICE_ID_PATH = Path (STORE_PATH , "service_id.txt" )
3838SERVICE_SAFE_ADDRESS_PATH = Path (STORE_PATH , "service_safe_address.txt" )
3939OWNER_KEYS_JSON_PATH = Path (STORE_PATH , "operator_keys.json" )
40+ DEFAULT_ENCODING = "utf-8"
4041
4142OLAS_TOKEN_ADDRESS_GNOSIS = "0xcE11e14225575945b8E6Dc0D4F2dD4C570f79d9f"
4243GNOSIS_CHAIN_ID = 100
44+ DEFAULT_GAS = 100000
45+ SAFE_WEBAPP_URL = "https://app.safe.global/home?safe=gno:"
4346
4447STAKING_TOKEN_INSTANCE_ABI_PATH = Path (
4548 SCRIPT_PATH ,
@@ -74,7 +77,7 @@ def _load_abi_from_file(path: Path) -> Dict[str, Any]:
7477 )
7578 sys .exit (1 )
7679
77- with open (path , "r" , encoding = "utf-8" ) as f :
80+ with open (path , "r" , encoding = DEFAULT_ENCODING ) as f :
7881 data = json .load (f )
7982
8083 return data .get ("abi" )
@@ -84,32 +87,33 @@ def _erc20_balance(
8487 address : str ,
8588 token_address : str = OLAS_TOKEN_ADDRESS_GNOSIS ,
8689 token_name : str = "OLAS" ,
90+ decimal_precision : int = 2
8791) -> str :
8892 """Get ERC20 balance"""
89- rpc = RPC_PATH .read_text (encoding = "utf-8" ).strip ()
93+ rpc = RPC_PATH .read_text (encoding = DEFAULT_ENCODING ).strip ()
9094 w3 = Web3 (Web3 .HTTPProvider (rpc ))
9195 abi = _load_abi_from_file (ERC20_ABI_PATH )
9296 contract = w3 .eth .contract (address = token_address , abi = abi )
9397 balance = contract .functions .balanceOf (address ).call ()
94- return f"{ balance / 10 ** 18 :.2f } { token_name } "
98+ return f"{ balance / 10 ** 18 :.{ decimal_precision }f } { token_name } "
9599
96100
97101def _claim_rewards () -> None :
98- service_safe_address = SERVICE_SAFE_ADDRESS_PATH .read_text (encoding = "utf-8" ).strip ()
102+ service_safe_address = SERVICE_SAFE_ADDRESS_PATH .read_text (encoding = DEFAULT_ENCODING ).strip ()
99103 print (
100104 f"OLAS Balance on service Safe { service_safe_address } : { _erc20_balance (service_safe_address )} "
101105 )
102106
103107 env_file_vars = dotenv_values (DOTENV_PATH )
104108 staking_token_address = env_file_vars ["CUSTOM_STAKING_ADDRESS" ]
105- service_id = int (SERVICE_ID_PATH .read_text (encoding = "utf-8" ).strip ())
109+ service_id = int (SERVICE_ID_PATH .read_text (encoding = DEFAULT_ENCODING ).strip ())
106110
107- rpc = RPC_PATH .read_text (encoding = "utf-8" ).strip ()
111+ rpc = RPC_PATH .read_text (encoding = DEFAULT_ENCODING ).strip ()
108112 w3 = Web3 (Web3 .HTTPProvider (rpc ))
109113 abi = _load_abi_from_file (STAKING_TOKEN_IMPLEMENTATION_ABI_PATH )
110114 staking_token_contract = w3 .eth .contract (address = staking_token_address , abi = abi )
111115
112- owner_private_key = json .loads (OWNER_KEYS_JSON_PATH .read_text (encoding = "utf-8" ))[0 ][
116+ owner_private_key = json .loads (OWNER_KEYS_JSON_PATH .read_text (encoding = DEFAULT_ENCODING ))[0 ][
113117 "private_key"
114118 ]
115119 owner_address = Web3 .to_checksum_address (
@@ -120,7 +124,7 @@ def _claim_rewards() -> None:
120124 claim_transaction = function .build_transaction (
121125 {
122126 "chainId" : GNOSIS_CHAIN_ID ,
123- "gas" : 100000 ,
127+ "gas" : DEFAULT_GAS ,
124128 "gasPrice" : w3 .to_wei ("3" , "gwei" ),
125129 "nonce" : w3 .eth .get_transaction_count (owner_address ),
126130 }
@@ -141,7 +145,7 @@ def _claim_rewards() -> None:
141145 print (
142146 f"You can use your Owner/Operator wallet (address { owner_address } ) to connect your Safe at"
143147 )
144- print (f"https://app.safe.global/home?safe=gno: { service_safe_address } " )
148+ print (f"{ SAFE_WEBAPP_URL } { service_safe_address } " )
145149
146150
147151def main () -> None :
0 commit comments