@@ -19,7 +19,8 @@ pub mod Core {
1919 };
2020 use perpetuals :: core :: errors :: {
2121 AMOUNT_OVERFLOW , FORCED_WAIT_REQUIRED , INVALID_ZERO_TIMEOUT , LENGTH_MISMATCH ,
22- ORDER_IS_NOT_EXPIRED , TRADE_ASSET_NOT_SYNTHETIC , TRANSFER_FAILED ,
22+ NON_MONOTONIC_TIME , ORDER_IS_NOT_EXPIRED , STALE_TIME , TRADE_ASSET_NOT_SYNTHETIC ,
23+ TRANSFER_FAILED ,
2324 };
2425 use perpetuals :: core :: events;
2526 use perpetuals :: core :: interface :: {ICore , Settlement };
@@ -161,6 +162,7 @@ pub mod Core {
161162 forced_action_timelock : TimeDelta ,
162163 // Cost for executing forced actions.
163164 premium_cost : u64 ,
165+ system_time : Timestamp ,
164166 }
165167
166168 #[event]
@@ -953,6 +955,41 @@ pub mod Core {
953955 },
954956 );
955957 }
958+
959+ /// Updates the system time stored in the contract.
960+ ///
961+ /// Validations:
962+ /// - The contract must not be paused.
963+ /// - Only the operator can call this function.
964+ /// - The operator_nonce must be valid.
965+ /// - The new system time must be strictly greater than the current system time.
966+ /// - The new system time must not exceed the current Starknet block timestamp.
967+ ///
968+ /// Execution:
969+ /// - Updates the system time.
970+ /// - Emits no events.
971+ fn update_system_time (
972+ ref self : ContractState , operator_nonce : u64 , new_timestamp : Timestamp ,
973+ ) {
974+ self . pausable. assert_not_paused ();
975+ self . operator_nonce. use_checked_nonce (: operator_nonce );
976+
977+ // The new system time must be strictly greater than the current system time.
978+ let current_system_time = self . system_time. read ();
979+ assert (new_timestamp > current_system_time , NON_MONOTONIC_TIME );
980+
981+ // The new system time must not exceed the current Starknet block timestamp.
982+ let now = Time :: now ();
983+ assert (new_timestamp <= now , STALE_TIME );
984+
985+ // Update the system time.
986+ self . system_time. write (new_timestamp );
987+ }
988+
989+ /// Returns the current system time stored in the contract.
990+ fn get_system_time (self : @ ContractState ) -> Timestamp {
991+ self . system_time. read ()
992+ }
956993 }
957994
958995 #[generate_trait]
0 commit comments