4545)
4646
4747
48- EVEREST_STAKING_CONTRACT_ADDRESS = " 0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"
48+ OLD_STAKING_PROGRAMS = { "Everest" : " 0x5add592ce0a1B5DceCebB5Dcac086Cd9F9e3eA5C"}
4949
5050
5151def _format_duration (duration_seconds : int ) -> str :
@@ -56,33 +56,51 @@ def _format_duration(duration_seconds: int) -> str:
5656 return formatted_duration
5757
5858
59- def _unstake_everest (
60- ledger_api : EthereumApi , service_id : int , owner_crypto : EthereumCrypto
59+ def _unstake (
60+ ledger_api : EthereumApi ,
61+ service_id : int ,
62+ staking_contract_address : str ,
63+ staking_program : str ,
64+ owner_crypto : EthereumCrypto ,
6165) -> None :
62- print ("Checking if service is staked on Everest..." )
63- staking_contract_address = EVEREST_STAKING_CONTRACT_ADDRESS
64-
65- if service_id not in get_service_ids (ledger_api , staking_contract_address ):
66- print (f"Service { service_id } is not staked on Everest." )
67- return
66+ print (f"Checking if service is staked on { staking_program } ..." )
67+
68+ # Check if service is staked
69+ if staking_program .startswith ("Everest" ):
70+ if service_id not in get_service_ids (ledger_api , staking_contract_address ):
71+ print (f"Service { service_id } is not staked on { staking_program } ." )
72+ return
73+ elif staking_program .startswith ("Alpine" ):
74+ if not is_service_staked (
75+ ledger_api , args .service_id , args .staking_contract_address
76+ ):
77+ print (f"Service { args .service_id } is not staked on { staking_program } .." )
78+ return
6879
6980 print (
70- f"Service { service_id } is staked on Everest . To continue in a new staking program, first, it must be unstaked from Everest ."
81+ f"Service { service_id } is staked on { staking_program } . To continue in a new staking program, first, it must be unstaked from { staking_program } ."
7182 )
7283 user_input = input (
73- "Do you want to continue unstaking from Everest ? (yes/no)\n "
84+ "Do you want to continue unstaking from {staking_program} ? (yes/no)\n "
7485 ).lower ()
7586 print ()
7687
7788 if user_input not in ["yes" , "y" ]:
7889 print ("Terminating script." )
7990 sys .exit (1 )
8091
81- print (f"Unstaking service { service_id } from Everest ..." )
92+ print (f"Unstaking service { service_id } from { staking_program } ..." )
8293 unstake_txs = get_unstake_txs (ledger_api , service_id , staking_contract_address )
8394 for tx in unstake_txs :
8495 send_tx_and_wait_for_receipt (ledger_api , owner_crypto , tx )
85- print ("Successfully unstaked from Everest." )
96+ print (f"Successfully unstaked service { args .service_id } from { staking_program } ." )
97+
98+
99+ def _unstake_old_programs (
100+ ledger_api : EthereumApi , service_id : int , owner_crypto : EthereumCrypto
101+ ) -> None :
102+ for program , address in OLD_STAKING_PROGRAMS .items ():
103+ _unstake (ledger_api , service_id , address , program , owner_crypto )
86104
87105
88106def _check_unstaking_availability (
@@ -184,7 +202,7 @@ def _try_stake_service(
184202 private_key_path = args .owner_private_key_path , password = args .password
185203 )
186204
187- _unstake_everest (ledger_api , args .service_id , owner_crypto )
205+ _unstake_old_programs (ledger_api , args .service_id , owner_crypto )
188206
189207 # Collect information
190208 next_ts = get_next_checkpoint_ts (ledger_api , args .staking_contract_address )
@@ -208,7 +226,7 @@ def _try_stake_service(
208226 ledger_api , args .service_id , args .staking_contract_address
209227 ):
210228 # the service is not staked, so we don't need to do anything
211- print (f"Service { args .service_id } is not staked." )
229+ print (f"Service { args .service_id } is not staked on { staking_program } . ." )
212230 sys .exit (0 )
213231
214232 if is_service_evicted (
0 commit comments