From a5dfefa55f69c1c701efd04240ed664d465c36c6 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Fri, 10 Jan 2025 14:51:33 +0530 Subject: [PATCH 01/13] automation registry - introduce new `AutomationRegistryConfig` struct to handle configrable data --- .../src/aptos_framework_sdk_builder.rs | 86 +++------ .../doc/automation_registry.md | 182 ++++++++---------- .../sources/automation_registry.move | 125 ++++++------ 3 files changed, 174 insertions(+), 219 deletions(-) diff --git a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs index aeeca7f3e7502..2a677f8bca093 100644 --- a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs +++ b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs @@ -158,15 +158,11 @@ pub enum EntryFunctionCall { id: u64, }, - /// Update Automation gas limit. - /// If the committed gas amount for the next epoch is greater then the new gas limit, then error is reported. - AutomationRegistryUpdateAutomationGasLimit { + /// Update Automation Registry Config + AutomationRegistryUpdateConfig { automation_gas_limit: u64, - }, - - /// Update duration upper limit - AutomationRegistryUpdateDurationUpperLimit { duration_upper_limit: u64, + automation_unit_price: u64, }, /// Same as `publish_package` but as an entry function which can be called as a transaction. Because @@ -1265,12 +1261,15 @@ impl EntryFunctionCall { cap_update_table, ), AutomationRegistryCancelTask { id } => automation_registry_cancel_task(id), - AutomationRegistryUpdateAutomationGasLimit { + AutomationRegistryUpdateConfig { automation_gas_limit, - } => automation_registry_update_automation_gas_limit(automation_gas_limit), - AutomationRegistryUpdateDurationUpperLimit { duration_upper_limit, - } => automation_registry_update_duration_upper_limit(duration_upper_limit), + automation_unit_price, + } => automation_registry_update_config( + automation_gas_limit, + duration_upper_limit, + automation_unit_price, + ), CodePublishPackageTxn { metadata_serialized, code, @@ -2295,28 +2294,11 @@ pub fn automation_registry_cancel_task(id: u64) -> TransactionPayload { )) } -/// Update Automation gas limit. -/// If the committed gas amount for the next epoch is greater then the new gas limit, then error is reported. -pub fn automation_registry_update_automation_gas_limit( +/// Update Automation Registry Config +pub fn automation_registry_update_config( automation_gas_limit: u64, -) -> TransactionPayload { - TransactionPayload::EntryFunction(EntryFunction::new( - ModuleId::new( - AccountAddress::new([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, - ]), - ident_str!("automation_registry").to_owned(), - ), - ident_str!("update_automation_gas_limit").to_owned(), - vec![], - vec![bcs::to_bytes(&automation_gas_limit).unwrap()], - )) -} - -/// Update duration upper limit -pub fn automation_registry_update_duration_upper_limit( duration_upper_limit: u64, + automation_unit_price: u64, ) -> TransactionPayload { TransactionPayload::EntryFunction(EntryFunction::new( ModuleId::new( @@ -2326,9 +2308,13 @@ pub fn automation_registry_update_duration_upper_limit( ]), ident_str!("automation_registry").to_owned(), ), - ident_str!("update_duration_upper_limit").to_owned(), + ident_str!("update_config").to_owned(), vec![], - vec![bcs::to_bytes(&duration_upper_limit).unwrap()], + vec![ + bcs::to_bytes(&automation_gas_limit).unwrap(), + bcs::to_bytes(&duration_upper_limit).unwrap(), + bcs::to_bytes(&automation_unit_price).unwrap(), + ], )) } @@ -5648,29 +5634,15 @@ mod decoder { } } - pub fn automation_registry_update_automation_gas_limit( - payload: &TransactionPayload, - ) -> Option { - if let TransactionPayload::EntryFunction(script) = payload { - Some( - EntryFunctionCall::AutomationRegistryUpdateAutomationGasLimit { - automation_gas_limit: bcs::from_bytes(script.args().get(0)?).ok()?, - }, - ) - } else { - None - } - } - - pub fn automation_registry_update_duration_upper_limit( + pub fn automation_registry_update_config( payload: &TransactionPayload, ) -> Option { if let TransactionPayload::EntryFunction(script) = payload { - Some( - EntryFunctionCall::AutomationRegistryUpdateDurationUpperLimit { - duration_upper_limit: bcs::from_bytes(script.args().get(0)?).ok()?, - }, - ) + Some(EntryFunctionCall::AutomationRegistryUpdateConfig { + automation_gas_limit: bcs::from_bytes(script.args().get(0)?).ok()?, + duration_upper_limit: bcs::from_bytes(script.args().get(1)?).ok()?, + automation_unit_price: bcs::from_bytes(script.args().get(2)?).ok()?, + }) } else { None } @@ -7609,12 +7581,8 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy + -## Resource `AutomationRegistry` +## Resource `AutomationRegistryConfig` -It tracks entries both pending and completed, organized by unique indices. +Automation registry config -
struct AutomationRegistry has store, key
+
struct AutomationRegistryConfig has store, key
 
@@ -66,40 +65,62 @@ It tracks entries both pending and completed, organized by unique indices.
-tasks: enumerable_map::EnumerableMap<u64, automation_registry::AutomationTaskMetaData> +automation_gas_limit: u64
- A collection of automation task entries that are active state. + Automation task max gas limit
-current_index: u64 +duration_upper_limit: u64
- Automation task id which increase + Automation task duration upper limit.
-gas_committed_for_next_epoch: u64 +automation_unit_price: u64
- Gas committed for next epoch + Automation task unit price per second
+
+ + + + + + +## Resource `AutomationRegistry` + +It tracks entries both pending and completed, organized by unique indices. + + +
struct AutomationRegistry has store, key
+
+ + + +
+Fields + + +
-automation_gas_limit: u64 +tasks: enumerable_map::EnumerableMap<u64, automation_registry::AutomationTaskMetaData>
- Automation task max gas limit + A collection of automation task entries that are active state.
-duration_upper_limit: u64 +current_index: u64
- Automation task duration upper limit. + Automation task id which increase
-automation_unit_price: u64 +gas_committed_for_next_epoch: u64
- Automation task unit price per second + Gas committed for next epoch
registry_fee_address: address @@ -309,15 +330,15 @@ Withdraw user's registration fee event
- + -## Struct `UpdateDurationUpperLimit` +## Struct `AutomationRegistryConfigUpdate` -Update duration upper limit event +Update Automation Registry Config event
#[event]
-struct UpdateDurationUpperLimit has drop, store
+struct AutomationRegistryConfigUpdate has drop, store
 
@@ -328,36 +349,19 @@ Update duration upper limit event
-duration_upper_limit: u64 +automation_gas_limit: u64
-
- - - - - - -## Struct `UpdateAutomationGasLimit` - -Update automation gas limit event - - -
#[event]
-struct UpdateAutomationGasLimit has drop, store
-
- - - -
-Fields - +
+duration_upper_limit: u64 +
+
-
+
-automation_gas_limit: u64 +automation_unit_price: u64
@@ -657,11 +661,14 @@ Initialization of Automation Registry tasks: enumerable_map::new_map(), current_index: 0, gas_committed_for_next_epoch: 0, + registry_fee_address: signer::address_of(®istry_fee_resource_signer), + registry_fee_address_signer_cap, + }); + + move_to(supra_framework, AutomationRegistryConfig { automation_gas_limit: DEFAULT_AUTOMATION_GAS_LIMIT, duration_upper_limit: DEFAULT_DURATION_UPPER_LIMIT, automation_unit_price: DEFAULT_AUTOMATION_UNIT_PRICE, - registry_fee_address: signer::address_of(®istry_fee_resource_signer), - registry_fee_address_signer_cap, }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -790,15 +797,14 @@ Transfers the specified fee amount from the resource account to the target accou
- + -## Function `update_automation_gas_limit` +## Function `update_config` -Update Automation gas limit. -If the committed gas amount for the next epoch is greater then the new gas limit, then error is reported. +Update Automation Registry Config -
public entry fun update_automation_gas_limit(supra_framework: &signer, automation_gas_limit: u64)
+
public entry fun update_config(supra_framework: &signer, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
 
@@ -807,54 +813,29 @@ If the committed gas amount for the next epoch is greater then the new gas limit Implementation -
public entry fun update_automation_gas_limit(
+
public entry fun update_config(
     supra_framework: &signer,
-    automation_gas_limit: u64
-) acquires AutomationRegistry {
+    automation_gas_limit: u64,
+    duration_upper_limit: u64,
+    automation_unit_price: u64,
+) acquires AutomationRegistryConfig, AutomationRegistry {
     system_addresses::assert_supra_framework(supra_framework);
 
     let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
+    let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
+
     assert!(
         automation_registry.gas_committed_for_next_epoch < automation_gas_limit,
         EUNACCEPTABLE_AUTOMATION_GAS_LIMIT
     );
 
-    automation_registry.automation_gas_limit = automation_gas_limit;
-
-    event::emit(UpdateAutomationGasLimit { automation_gas_limit });
-}
-
- - - - - - - -## Function `update_duration_upper_limit` - -Update duration upper limit - - -
public entry fun update_duration_upper_limit(supra_framework: &signer, duration_upper_limit: u64)
-
- - - -
-Implementation - - -
public entry fun update_duration_upper_limit(
-    supra_framework: &signer,
-    duration_upper_limit: u64
-) acquires AutomationRegistry {
-    system_addresses::assert_supra_framework(supra_framework);
+    automation_registry_config.automation_gas_limit = automation_gas_limit;
+    automation_registry_config.duration_upper_limit = duration_upper_limit;
+    automation_registry_config.automation_unit_price = automation_unit_price;
 
-    let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
-    automation_registry.duration_upper_limit = duration_upper_limit;
-
-    event::emit(UpdateDurationUpperLimit { duration_upper_limit });
+    event::emit(
+        AutomationRegistryConfigUpdate { automation_gas_limit, duration_upper_limit, automation_unit_price }
+    );
 }
 
@@ -917,15 +898,17 @@ Registers a new automation task entry. max_gas_amount: u64, gas_price_cap: u64, tx_hash: vector<u8> -) acquires AutomationRegistry, AutomationEpochInfo { +) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework); + let automation_registry_config = borrow_global<AutomationRegistryConfig>(@supra_framework); let automation_epoch_info = borrow_global<AutomationEpochInfo>(@supra_framework); + //Well-formedness check of payload_tx is done in native layer beforehand. let registration_time = timestamp::now_seconds(); assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); let task_duration = expiry_time - registration_time; - assert!(task_duration < automation_registry.duration_upper_limit, EEXPIRY_TIME_UPPER); + assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); // Check that task is valid at least in the next epoch assert!( @@ -941,7 +924,7 @@ Registers a new automation task entry. assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry.automation_gas_limit, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.automation_gas_limit, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -963,7 +946,7 @@ Registers a new automation task entry. charge_automation_fee_from_user( owner, - automation_registry.automation_unit_price, + automation_registry_config.automation_unit_price, task_duration, automation_registry.registry_fee_address); } @@ -995,8 +978,9 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can Implementation -
public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry {
+
public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, AutomationRegistryConfig {
     let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
+    let automation_registry_config = borrow_global<AutomationRegistryConfig>(@supra_framework);
     assert!(enumerable_map::contains(&automation_registry.tasks, id), EAUTOMATION_TASK_NOT_FOUND);
 
     let automation_task_metadata = enumerable_map::get_value(&mut automation_registry.tasks, id);
@@ -1020,7 +1004,7 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can
     refund_automation_task_fee(
         signer::address_of(owner),
         &automation_task_metadata,
-        automation_registry.automation_unit_price
+        automation_registry_config.automation_unit_price
     );
 }
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index daec1194e7db5..0e035f1713730 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -65,6 +65,16 @@ module supra_framework::automation_registry { const ACTIVE: u8 = 1; const CANCELLED: u8 = 2; + /// Automation registry config + struct AutomationRegistryConfig has key, store { + /// Automation task max gas limit + automation_gas_limit: u64, + /// Automation task duration upper limit. + duration_upper_limit: u64, + /// Automation task unit price per second + automation_unit_price: u64, + } + /// It tracks entries both pending and completed, organized by unique indices. struct AutomationRegistry has key, store { /// A collection of automation task entries that are active state. @@ -73,12 +83,6 @@ module supra_framework::automation_registry { current_index: u64, /// Gas committed for next epoch gas_committed_for_next_epoch: u64, - /// Automation task max gas limit - automation_gas_limit: u64, - /// Automation task duration upper limit. - duration_upper_limit: u64, - /// Automation task unit price per second - automation_unit_price: u64, /// It's resource address which is use to deposit user automation fee registry_fee_address: address, /// Resource account signature capability @@ -137,15 +141,11 @@ module supra_framework::automation_registry { } #[event] - /// Update duration upper limit event - struct UpdateDurationUpperLimit has drop, store { - duration_upper_limit: u64 - } - - #[event] - /// Update automation gas limit event - struct UpdateAutomationGasLimit has drop, store { - automation_gas_limit: u64 + /// Update Automation Registry Config event + struct AutomationRegistryConfigUpdate has drop, store { + automation_gas_limit: u64, + duration_upper_limit: u64, + automation_unit_price: u64, } #[event] @@ -167,11 +167,14 @@ module supra_framework::automation_registry { tasks: enumerable_map::new_map(), current_index: 0, gas_committed_for_next_epoch: 0, + registry_fee_address: signer::address_of(®istry_fee_resource_signer), + registry_fee_address_signer_cap, + }); + + move_to(supra_framework, AutomationRegistryConfig { automation_gas_limit: DEFAULT_AUTOMATION_GAS_LIMIT, duration_upper_limit: DEFAULT_DURATION_UPPER_LIMIT, automation_unit_price: DEFAULT_AUTOMATION_UNIT_PRICE, - registry_fee_address: signer::address_of(®istry_fee_resource_signer), - registry_fee_address_signer_cap, }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -235,36 +238,30 @@ module supra_framework::automation_registry { supra_account::transfer(&resource_signer, to, amount); } - /// Update Automation gas limit. - /// If the committed gas amount for the next epoch is greater then the new gas limit, then error is reported. - public entry fun update_automation_gas_limit( + /// Update Automation Registry Config + public entry fun update_config( supra_framework: &signer, - automation_gas_limit: u64 - ) acquires AutomationRegistry { + automation_gas_limit: u64, + duration_upper_limit: u64, + automation_unit_price: u64, + ) acquires AutomationRegistryConfig, AutomationRegistry { system_addresses::assert_supra_framework(supra_framework); let automation_registry = borrow_global_mut(@supra_framework); + let automation_registry_config = borrow_global_mut(@supra_framework); + assert!( automation_registry.gas_committed_for_next_epoch < automation_gas_limit, EUNACCEPTABLE_AUTOMATION_GAS_LIMIT ); - automation_registry.automation_gas_limit = automation_gas_limit; - - event::emit(UpdateAutomationGasLimit { automation_gas_limit }); - } - - /// Update duration upper limit - public entry fun update_duration_upper_limit( - supra_framework: &signer, - duration_upper_limit: u64 - ) acquires AutomationRegistry { - system_addresses::assert_supra_framework(supra_framework); + automation_registry_config.automation_gas_limit = automation_gas_limit; + automation_registry_config.duration_upper_limit = duration_upper_limit; + automation_registry_config.automation_unit_price = automation_unit_price; - let automation_registry = borrow_global_mut(@supra_framework); - automation_registry.duration_upper_limit = duration_upper_limit; - - event::emit(UpdateDurationUpperLimit { duration_upper_limit }); + event::emit( + AutomationRegistryConfigUpdate { automation_gas_limit, duration_upper_limit, automation_unit_price } + ); } /// Deducts the automation fee from the user's account based on the selected expiry time. @@ -287,15 +284,17 @@ module supra_framework::automation_registry { max_gas_amount: u64, gas_price_cap: u64, tx_hash: vector - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); + let automation_registry_config = borrow_global(@supra_framework); let automation_epoch_info = borrow_global(@supra_framework); + //Well-formedness check of payload_tx is done in native layer beforehand. let registration_time = timestamp::now_seconds(); assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); let task_duration = expiry_time - registration_time; - assert!(task_duration < automation_registry.duration_upper_limit, EEXPIRY_TIME_UPPER); + assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); // Check that task is valid at least in the next epoch assert!( @@ -311,7 +310,7 @@ module supra_framework::automation_registry { assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry.automation_gas_limit, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.automation_gas_limit, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -333,7 +332,7 @@ module supra_framework::automation_registry { charge_automation_fee_from_user( owner, - automation_registry.automation_unit_price, + automation_registry_config.automation_unit_price, task_duration, automation_registry.registry_fee_address); } @@ -345,8 +344,9 @@ module supra_framework::automation_registry { /// - pending, it is removed form the list. /// - cancelled, an error is reported /// Committed gas-limit is updated by reducing it with the max-gas-amount of the cancelled task. - public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry { + public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, AutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); + let automation_registry_config = borrow_global(@supra_framework); assert!(enumerable_map::contains(&automation_registry.tasks, id), EAUTOMATION_TASK_NOT_FOUND); let automation_task_metadata = enumerable_map::get_value(&mut automation_registry.tasks, id); @@ -370,7 +370,7 @@ module supra_framework::automation_registry { refund_automation_task_fee( signer::address_of(owner), &automation_task_metadata, - automation_registry.automation_unit_price + automation_registry_config.automation_unit_price ); } @@ -486,7 +486,10 @@ module supra_framework::automation_registry { } #[test(supra_framework = @supra_framework, user = @0x1cafe)] - fun test_registry(supra_framework: &signer, user: &signer) acquires AutomationRegistry, AutomationEpochInfo { + fun test_registry( + supra_framework: &signer, + user: &signer + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(supra_framework, user); let payload = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344"; @@ -497,7 +500,7 @@ module supra_framework::automation_registry { #[test(framework = @supra_framework, user = @0x1cafe)] fun check_automation_gas_limit_success_update( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -508,8 +511,8 @@ module supra_framework::automation_registry { ); // Next epoch gas committed gas is less than the new limit value. - update_automation_gas_limit(framework, 75); - let state = borrow_global(@supra_framework); + update_config(framework, 75, DEFAULT_DURATION_UPPER_LIMIT, DEFAULT_AUTOMATION_UNIT_PRICE); + let state = borrow_global(@supra_framework); assert!(state.automation_gas_limit == 75, 1); } @@ -517,7 +520,7 @@ module supra_framework::automation_registry { #[expected_failure(abort_code = EUNACCEPTABLE_AUTOMATION_GAS_LIMIT, location = Self)] fun check_automation_gas_limit_failed_update( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -528,14 +531,14 @@ module supra_framework::automation_registry { ); // Next epoch gas committed gas is greater than the new limit value. - update_automation_gas_limit(framework, 45); + update_config(framework, 45, DEFAULT_DURATION_UPPER_LIMIT, DEFAULT_AUTOMATION_UNIT_PRICE); } #[test(framework = @supra_framework, user = @0x1cafe)] fun check_task_registration( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -553,7 +556,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_expiry_time( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); timestamp::update_global_time_for_test_secs(50); @@ -571,7 +574,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_expiry_time_before_next_epoch( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -588,7 +591,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_gas_price_cap( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -605,7 +608,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_max_gas_amount( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -621,7 +624,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_parent_hash( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -638,7 +641,7 @@ module supra_framework::automation_registry { fun check_registration_with_overflow_gas_limit( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -662,7 +665,7 @@ module supra_framework::automation_registry { fun check_task_activation_on_new_epoch( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -713,7 +716,7 @@ module supra_framework::automation_registry { fun check_task_successful_cancellation( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -794,7 +797,7 @@ module supra_framework::automation_registry { fun check_cancellation_of_non_existing_task( framework: &signer, user: &signer - ) acquires AutomationRegistry { + ) acquires AutomationRegistry, AutomationRegistryConfig { initialize_registry_test(framework, user); cancel_task(user, 1); @@ -806,7 +809,7 @@ module supra_framework::automation_registry { framework: &signer, user: &signer, user2: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -824,7 +827,7 @@ module supra_framework::automation_registry { fun check_cacellation_of_cancelled_task( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo { + ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); register(user, From b73353f63306c59586284b025dfd4087a6406fdc Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Fri, 10 Jan 2025 20:07:19 +0530 Subject: [PATCH 02/13] automation registry - use `config_buffer` to store `AutomationRegistryConfig` and replace the data after on_new_epoch --- .../doc/automation_registry.md | 73 +++++-------------- .../sources/automation_registry.move | 43 +++++------ .../sources/configs/config_buffer.move | 2 + 3 files changed, 43 insertions(+), 75 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 2f8742a2420fa..805981f1b333a 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -14,7 +14,6 @@ This contract is part of the Supra Framework and is designed to manage automated - [Struct `AutomationTaskMetaData`](#0x1_automation_registry_AutomationTaskMetaData) - [Struct `FeeWithdrawnAdmin`](#0x1_automation_registry_FeeWithdrawnAdmin) - [Struct `RefundFeeUser`](#0x1_automation_registry_RefundFeeUser) -- [Struct `AutomationRegistryConfigUpdate`](#0x1_automation_registry_AutomationRegistryConfigUpdate) - [Struct `CancelledAutomationTask`](#0x1_automation_registry_CancelledAutomationTask) - [Constants](#@Constants_0) - [Function `initialize`](#0x1_automation_registry_initialize) @@ -36,6 +35,7 @@ This contract is part of the Supra Framework and is designed to manage automated
use 0x1::account;
+use 0x1::config_buffer;
 use 0x1::enumerable_map;
 use 0x1::event;
 use 0x1::signer;
@@ -54,7 +54,8 @@ This contract is part of the Supra Framework and is designed to manage automated
 Automation registry config
 
 
-
struct AutomationRegistryConfig has store, key
+
#[event]
+struct AutomationRegistryConfig has copy, drop, store, key
 
@@ -328,47 +329,6 @@ Withdraw user's registration fee event -
- - - -## Struct `AutomationRegistryConfigUpdate` - -Update Automation Registry Config event - - -
#[event]
-struct AutomationRegistryConfigUpdate has drop, store
-
- - - -
-Fields - - -
-
-automation_gas_limit: u64 -
-
- -
-
-duration_upper_limit: u64 -
-
- -
-
-automation_unit_price: u64 -
-
- -
-
- -
@@ -700,7 +660,7 @@ On new epoch this function will be triggered and update the automation registry Implementation -
public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo {
+
public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig {
     let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
     let ids = enumerable_map::get_map_list(&automation_registry.tasks);
 
@@ -727,6 +687,14 @@ On new epoch this function will be triggered and update the automation registry
         }
     });
 
+    if (config_buffer::does_exist<AutomationRegistryConfig>()) {
+        let buffer = config_buffer::extract<AutomationRegistryConfig>();
+        let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
+        automation_registry_config.automation_unit_price = buffer.automation_unit_price;
+        automation_registry_config.duration_upper_limit = buffer.duration_upper_limit;
+        automation_registry_config.automation_gas_limit = buffer.automation_gas_limit;
+    };
+
     automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch;
     automation_epoch_info.start_time = current_time;
     automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval;
@@ -818,24 +786,21 @@ Update Automation Registry Config
     automation_gas_limit: u64,
     duration_upper_limit: u64,
     automation_unit_price: u64,
-) acquires AutomationRegistryConfig, AutomationRegistry {
+) acquires AutomationRegistry {
     system_addresses::assert_supra_framework(supra_framework);
 
-    let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
-    let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
+    let automation_registry = borrow_global<AutomationRegistry>(@supra_framework);
 
     assert!(
         automation_registry.gas_committed_for_next_epoch < automation_gas_limit,
         EUNACCEPTABLE_AUTOMATION_GAS_LIMIT
     );
 
-    automation_registry_config.automation_gas_limit = automation_gas_limit;
-    automation_registry_config.duration_upper_limit = duration_upper_limit;
-    automation_registry_config.automation_unit_price = automation_unit_price;
-
-    event::emit(
-        AutomationRegistryConfigUpdate { automation_gas_limit, duration_upper_limit, automation_unit_price }
-    );
+    let automation_registry_config = AutomationRegistryConfig {
+        automation_gas_limit, duration_upper_limit, automation_unit_price
+    };
+    config_buffer::upsert(copy automation_registry_config);
+    event::emit(automation_registry_config);
 }
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 0e035f1713730..f86e5534473e0 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -9,6 +9,7 @@ module supra_framework::automation_registry { use supra_std::enumerable_map::{Self, EnumerableMap}; use supra_framework::account::{Self, SignerCapability}; + use supra_framework::config_buffer; use supra_framework::event; use supra_framework::supra_account; use supra_framework::system_addresses; @@ -65,8 +66,9 @@ module supra_framework::automation_registry { const ACTIVE: u8 = 1; const CANCELLED: u8 = 2; + #[event] /// Automation registry config - struct AutomationRegistryConfig has key, store { + struct AutomationRegistryConfig has key, store, drop, copy { /// Automation task max gas limit automation_gas_limit: u64, /// Automation task duration upper limit. @@ -140,14 +142,6 @@ module supra_framework::automation_registry { amount: u64 } - #[event] - /// Update Automation Registry Config event - struct AutomationRegistryConfigUpdate has drop, store { - automation_gas_limit: u64, - duration_upper_limit: u64, - automation_unit_price: u64, - } - #[event] /// Cancelled automation task registry event struct CancelledAutomationTask has drop, store { @@ -186,7 +180,7 @@ module supra_framework::automation_registry { } /// On new epoch this function will be triggered and update the automation registry state - public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo { + public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); let ids = enumerable_map::get_map_list(&automation_registry.tasks); @@ -213,6 +207,14 @@ module supra_framework::automation_registry { } }); + if (config_buffer::does_exist()) { + let buffer = config_buffer::extract(); + let automation_registry_config = borrow_global_mut(@supra_framework); + automation_registry_config.automation_unit_price = buffer.automation_unit_price; + automation_registry_config.duration_upper_limit = buffer.duration_upper_limit; + automation_registry_config.automation_gas_limit = buffer.automation_gas_limit; + }; + automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; automation_epoch_info.start_time = current_time; automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval; @@ -244,24 +246,21 @@ module supra_framework::automation_registry { automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64, - ) acquires AutomationRegistryConfig, AutomationRegistry { + ) acquires AutomationRegistry { system_addresses::assert_supra_framework(supra_framework); - let automation_registry = borrow_global_mut(@supra_framework); - let automation_registry_config = borrow_global_mut(@supra_framework); + let automation_registry = borrow_global(@supra_framework); assert!( automation_registry.gas_committed_for_next_epoch < automation_gas_limit, EUNACCEPTABLE_AUTOMATION_GAS_LIMIT ); - automation_registry_config.automation_gas_limit = automation_gas_limit; - automation_registry_config.duration_upper_limit = duration_upper_limit; - automation_registry_config.automation_unit_price = automation_unit_price; - - event::emit( - AutomationRegistryConfigUpdate { automation_gas_limit, duration_upper_limit, automation_unit_price } - ); + let automation_registry_config = AutomationRegistryConfig { + automation_gas_limit, duration_upper_limit, automation_unit_price + }; + config_buffer::upsert(copy automation_registry_config); + event::emit(automation_registry_config); } /// Deducts the automation fee from the user's account based on the selected expiry time. @@ -509,9 +508,11 @@ module supra_framework::automation_registry { 20, PARENT_HASH, ); - + config_buffer::initialize(framework); // Next epoch gas committed gas is less than the new limit value. update_config(framework, 75, DEFAULT_DURATION_UPPER_LIMIT, DEFAULT_AUTOMATION_UNIT_PRICE); + + on_new_epoch(); let state = borrow_global(@supra_framework); assert!(state.automation_gas_limit == 75, 1); } diff --git a/aptos-move/framework/supra-framework/sources/configs/config_buffer.move b/aptos-move/framework/supra-framework/sources/configs/config_buffer.move index dfd161e2a991b..9729fb48a9bcb 100644 --- a/aptos-move/framework/supra-framework/sources/configs/config_buffer.move +++ b/aptos-move/framework/supra-framework/sources/configs/config_buffer.move @@ -16,6 +16,7 @@ module supra_framework::config_buffer { use aptos_std::simple_map; use aptos_std::simple_map::SimpleMap; use aptos_std::type_info; + use supra_framework::system_addresses; friend supra_framework::consensus_config; @@ -29,6 +30,7 @@ module supra_framework::config_buffer { friend supra_framework::randomness_config; friend supra_framework::randomness_config_seqnum; friend supra_framework::version; + friend supra_framework::automation_registry; /// Config buffer operations failed with permission denied. const ESTD_SIGNER_NEEDED: u64 = 1; From bc1b268057cbdbe033d5af3ff0d52bbe3a86fe8c Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Mon, 13 Jan 2025 19:25:47 +0530 Subject: [PATCH 03/13] registry sc - intialize function use values from params instead using default value, make relavent test cases update --- .../doc/automation_registry.md | 47 ++++------------ .../framework/supra-framework/doc/genesis.md | 2 - .../sources/automation_registry.move | 56 +++++++++++++------ .../supra-framework/sources/genesis.move | 2 - 4 files changed, 51 insertions(+), 56 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 805981f1b333a..5e96ae9bd58f6 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -393,36 +393,6 @@ Max U64 value - - -The default automation task gas limit - - -
const DEFAULT_AUTOMATION_GAS_LIMIT: u64 = 100000000;
-
- - - - - -The default Automation unit price for per second, in Quants - - -
const DEFAULT_AUTOMATION_UNIT_PRICE: u64 = 1000;
-
- - - - - -The default upper limit duration for automation task, specified in seconds (30.4 days). - - -
const DEFAULT_DURATION_UPPER_LIMIT: u64 = 2626560;
-
- - - Task is already cancelled. @@ -600,7 +570,7 @@ The lenght of the transaction hash. Initialization of Automation Registry -
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64)
+
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
 
@@ -609,7 +579,13 @@ Initialization of Automation Registry Implementation -
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64) {
+
public fun initialize(
+    supra_framework: &signer,
+    epoch_interval_microsecs: u64,
+    automation_gas_limit: u64,
+    duration_upper_limit: u64,
+    automation_unit_price: u64,
+) {
     system_addresses::assert_supra_framework(supra_framework);
 
     let (registry_fee_resource_signer, registry_fee_address_signer_cap) = account::create_resource_account(
@@ -626,9 +602,9 @@ Initialization of Automation Registry
     });
 
     move_to(supra_framework, AutomationRegistryConfig {
-        automation_gas_limit: DEFAULT_AUTOMATION_GAS_LIMIT,
-        duration_upper_limit: DEFAULT_DURATION_UPPER_LIMIT,
-        automation_unit_price: DEFAULT_AUTOMATION_UNIT_PRICE,
+        automation_gas_limit,
+        duration_upper_limit,
+        automation_unit_price,
     });
 
     let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR;
@@ -687,6 +663,7 @@ On new epoch this function will be triggered and update the automation registry
         }
     });
 
+    // Apply the latest configuration if any parameter has been updated.
     if (config_buffer::does_exist<AutomationRegistryConfig>()) {
         let buffer = config_buffer::extract<AutomationRegistryConfig>();
         let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
diff --git a/aptos-move/framework/supra-framework/doc/genesis.md b/aptos-move/framework/supra-framework/doc/genesis.md
index f14bd4f499cee..39683da6eaf7d 100644
--- a/aptos-move/framework/supra-framework/doc/genesis.md
+++ b/aptos-move/framework/supra-framework/doc/genesis.md
@@ -49,7 +49,6 @@
 
 
use 0x1::account;
 use 0x1::aggregator_factory;
-use 0x1::automation_registry;
 use 0x1::block;
 use 0x1::chain_id;
 use 0x1::chain_status;
@@ -632,7 +631,6 @@ Genesis step 1: Initialize aptos framework account and core modules on chain.
     reconfiguration::initialize(&supra_framework_account);
     block::initialize(&supra_framework_account, epoch_interval_microsecs);
     state_storage::initialize(&supra_framework_account);
-    automation_registry::initialize(&supra_framework_account, epoch_interval_microsecs);
     timestamp::set_time_has_started(&supra_framework_account, genesis_timestamp_in_microseconds);
 }
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index f86e5534473e0..c60892e842f3c 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -15,7 +15,6 @@ module supra_framework::automation_registry { use supra_framework::system_addresses; use supra_framework::timestamp; - friend supra_framework::genesis; friend supra_framework::block; friend supra_framework::reconfiguration; @@ -46,12 +45,6 @@ module supra_framework::automation_registry { /// The gas committed for next epoch value is underflow after remove old max gas const EGAS_COMMITTEED_VALUE_UNDERFLOW: u64 = 13; - /// The default automation task gas limit - const DEFAULT_AUTOMATION_GAS_LIMIT: u64 = 100_000_000; - /// The default upper limit duration for automation task, specified in seconds (30.4 days). - const DEFAULT_DURATION_UPPER_LIMIT: u64 = 2_626_560; - /// The default Automation unit price for per second, in Quants - const DEFAULT_AUTOMATION_UNIT_PRICE: u64 = 1000; /// The lenght of the transaction hash. const TXN_HASH_LENGTH: u64 = 32; /// Conversion factor between microseconds and second @@ -149,7 +142,13 @@ module supra_framework::automation_registry { } /// Initialization of Automation Registry - public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64) { + public fun initialize( + supra_framework: &signer, + epoch_interval_microsecs: u64, + automation_gas_limit: u64, + duration_upper_limit: u64, + automation_unit_price: u64, + ) { system_addresses::assert_supra_framework(supra_framework); let (registry_fee_resource_signer, registry_fee_address_signer_cap) = account::create_resource_account( @@ -166,9 +165,9 @@ module supra_framework::automation_registry { }); move_to(supra_framework, AutomationRegistryConfig { - automation_gas_limit: DEFAULT_AUTOMATION_GAS_LIMIT, - duration_upper_limit: DEFAULT_DURATION_UPPER_LIMIT, - automation_unit_price: DEFAULT_AUTOMATION_UNIT_PRICE, + automation_gas_limit, + duration_upper_limit, + automation_unit_price, }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -207,6 +206,7 @@ module supra_framework::automation_registry { } }); + // Apply the latest configuration if any parameter has been updated. if (config_buffer::does_exist()) { let buffer = config_buffer::extract(); let automation_registry_config = borrow_global_mut(@supra_framework); @@ -450,6 +450,15 @@ module supra_framework::automation_registry { automation_registry.gas_committed_for_next_epoch } + #[test_only] + /// The default automation task gas limit + const AUTOMATION_GAS_LIMIT_TEST: u64 = 100_000_000; + #[test_only] + /// The default upper limit duration for automation task, specified in seconds (30.4 days). + const DURATION_UPPER_LIMIT_TEST: u64 = 2_626_560; + #[test_only] + /// The default Automation unit price for per second, in Quants + const AUTOMATION_UNIT_PRICE_TEST: u64 = 1000; #[test_only] /// Value defined in microsecond const EPOCH_INTERVAL_FOR_TEST: u64 = 7200000000; @@ -475,7 +484,13 @@ module supra_framework::automation_registry { timestamp::set_time_has_started_for_testing(supra_framework); - initialize(supra_framework, EPOCH_INTERVAL_FOR_TEST); + initialize( + supra_framework, + EPOCH_INTERVAL_FOR_TEST, + AUTOMATION_GAS_LIMIT_TEST, + DURATION_UPPER_LIMIT_TEST, + AUTOMATION_UNIT_PRICE_TEST + ); } #[test_only] @@ -491,13 +506,13 @@ module supra_framework::automation_registry { ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(supra_framework, user); - let payload = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041424344"; + let payload = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132"; let parent_hash = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20"; register(user, payload, 86400, 1000, 100000, parent_hash); } #[test(framework = @supra_framework, user = @0x1cafe)] - fun check_automation_gas_limit_success_update( + fun check_update_config_success_update( framework: &signer, user: &signer ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { initialize_registry_test(framework, user); @@ -510,11 +525,18 @@ module supra_framework::automation_registry { ); config_buffer::initialize(framework); // Next epoch gas committed gas is less than the new limit value. - update_config(framework, 75, DEFAULT_DURATION_UPPER_LIMIT, DEFAULT_AUTOMATION_UNIT_PRICE); + // Configration parameter will update after on new epoch + update_config(framework, 75, 1_626_560, 1005); + + let state = borrow_global(@supra_framework); + assert!(state.automation_gas_limit == AUTOMATION_GAS_LIMIT_TEST, 1); + // Automation gas limit on_new_epoch(); let state = borrow_global(@supra_framework); - assert!(state.automation_gas_limit == 75, 1); + assert!(state.automation_gas_limit == 75, 2); + assert!(state.duration_upper_limit == 1_626_560, 3); + assert!(state.automation_unit_price == 1005, 4); } #[test(framework = @supra_framework, user = @0x1cafe)] @@ -532,7 +554,7 @@ module supra_framework::automation_registry { ); // Next epoch gas committed gas is greater than the new limit value. - update_config(framework, 45, DEFAULT_DURATION_UPPER_LIMIT, DEFAULT_AUTOMATION_UNIT_PRICE); + update_config(framework, 45, DURATION_UPPER_LIMIT_TEST, AUTOMATION_UNIT_PRICE_TEST); } #[test(framework = @supra_framework, user = @0x1cafe)] diff --git a/aptos-move/framework/supra-framework/sources/genesis.move b/aptos-move/framework/supra-framework/sources/genesis.move index b218495693754..79e4423cf94b7 100644 --- a/aptos-move/framework/supra-framework/sources/genesis.move +++ b/aptos-move/framework/supra-framework/sources/genesis.move @@ -8,7 +8,6 @@ module supra_framework::genesis { use supra_framework::account; use supra_framework::aggregator_factory; - use supra_framework::automation_registry; use supra_framework::block; use supra_framework::chain_id; use supra_framework::chain_status; @@ -195,7 +194,6 @@ module supra_framework::genesis { reconfiguration::initialize(&supra_framework_account); block::initialize(&supra_framework_account, epoch_interval_microsecs); state_storage::initialize(&supra_framework_account); - automation_registry::initialize(&supra_framework_account, epoch_interval_microsecs); timestamp::set_time_has_started(&supra_framework_account, genesis_timestamp_in_microseconds); } From 742e0f45b38408a9b74d2d85381caaadcc73e0cb Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Thu, 16 Jan 2025 16:05:56 +0530 Subject: [PATCH 04/13] automation registry - remove entry from update_config function + create `check_registration_task_duration` to check necessory time related operation --- .../sources/automation_registry.move | 45 ++++++++++++------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index c60892e842f3c..3837846ccf997 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -241,7 +241,7 @@ module supra_framework::automation_registry { } /// Update Automation Registry Config - public entry fun update_config( + public fun update_config( supra_framework: &signer, automation_gas_limit: u64, duration_upper_limit: u64, @@ -266,11 +266,11 @@ module supra_framework::automation_registry { /// Deducts the automation fee from the user's account based on the selected expiry time. fun charge_automation_fee_from_user( owner: &signer, - automation_unit_price: u64, + automation_registry_config: &AutomationRegistryConfig, task_duration: u64, registry_fee_address: address ) { - let automation_base_fee = task_duration * automation_unit_price; + let automation_base_fee = task_duration * automation_registry_config.automation_unit_price; // todo : dynamic price calculation is pending supra_account::transfer(owner, registry_fee_address, automation_base_fee); } @@ -291,14 +291,11 @@ module supra_framework::automation_registry { //Well-formedness check of payload_tx is done in native layer beforehand. let registration_time = timestamp::now_seconds(); - assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); - let task_duration = expiry_time - registration_time; - assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); - - // Check that task is valid at least in the next epoch - assert!( - expiry_time > (automation_epoch_info.start_time + automation_epoch_info.epoch_interval), - EEXPIRY_BEFORE_NEXT_EPOCH + let task_duration = check_registration_task_duration( + expiry_time, + registration_time, + automation_registry_config, + automation_epoch_info ); assert!(gas_price_cap > 0, EINVALID_GAS_PRICE); @@ -331,11 +328,29 @@ module supra_framework::automation_registry { charge_automation_fee_from_user( owner, - automation_registry_config.automation_unit_price, + automation_registry_config, task_duration, automation_registry.registry_fee_address); } + fun check_registration_task_duration( + expiry_time: u64, + registration_time: u64, + automation_registry_config: &AutomationRegistryConfig, + automation_epoch_info: &AutomationEpochInfo + ): u64 { + assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); + let task_duration = expiry_time - registration_time; + assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); + + // Check that task is valid at least in the next epoch + assert!( + expiry_time > (automation_epoch_info.start_time + automation_epoch_info.epoch_interval), + EEXPIRY_BEFORE_NEXT_EPOCH + ); + task_duration + } + /// Cancel Automation task with specified id. /// Only existing task, which is PENDING or ACTIVE, can be cancled and only by task onwer. /// If the task is @@ -369,7 +384,7 @@ module supra_framework::automation_registry { refund_automation_task_fee( signer::address_of(owner), &automation_task_metadata, - automation_registry_config.automation_unit_price + automation_registry_config ); } @@ -377,12 +392,12 @@ module supra_framework::automation_registry { fun refund_automation_task_fee( user: address, automation_task_metadata: &AutomationTaskMetaData, - automation_unit_price: u64, + automation_registry_config: &AutomationRegistryConfig, ) acquires AutomationRegistry { let current_time = timestamp::now_seconds(); let expiry_time_duration = automation_task_metadata.expiry_time - current_time; - let refund_amount = expiry_time_duration * automation_unit_price; + let refund_amount = expiry_time_duration * automation_registry_config.automation_unit_price; transfer_fee_to_account_internal(user, refund_amount); event::emit(RefundFeeUser { user, amount: refund_amount }); } From 9ad6d274ac6050fd399720a914c254d64d209aa4 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Thu, 16 Jan 2025 17:24:23 +0530 Subject: [PATCH 05/13] automation registry - create `initializate_by_default` function until we have initialization flow properly implemented --- .../doc/automation_registry.md | 107 +++++++++++++++--- .../framework/supra-framework/doc/genesis.md | 2 + .../sources/automation_registry.move | 14 +++ .../supra-framework/sources/genesis.move | 2 + 4 files changed, 107 insertions(+), 18 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 5e96ae9bd58f6..60f0f3ae52437 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -16,6 +16,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Struct `RefundFeeUser`](#0x1_automation_registry_RefundFeeUser) - [Struct `CancelledAutomationTask`](#0x1_automation_registry_CancelledAutomationTask) - [Constants](#@Constants_0) +- [Function `initializate_by_default`](#0x1_automation_registry_initializate_by_default) - [Function `initialize`](#0x1_automation_registry_initialize) - [Function `on_new_epoch`](#0x1_automation_registry_on_new_epoch) - [Function `withdraw_automation_task_fees`](#0x1_automation_registry_withdraw_automation_task_fees) @@ -23,6 +24,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Function `update_config`](#0x1_automation_registry_update_config) - [Function `charge_automation_fee_from_user`](#0x1_automation_registry_charge_automation_fee_from_user) - [Function `register`](#0x1_automation_registry_register) +- [Function `check_registration_task_duration`](#0x1_automation_registry_check_registration_task_duration) - [Function `cancel_task`](#0x1_automation_registry_cancel_task) - [Function `refund_automation_task_fee`](#0x1_automation_registry_refund_automation_task_fee) - [Function `update_epoch_interval_in_registry`](#0x1_automation_registry_update_epoch_interval_in_registry) @@ -563,6 +565,40 @@ The lenght of the transaction hash. + + +## Function `initializate_by_default` + +This is temporary function : until we have initialization flow properly implemented + + +
public fun initializate_by_default(supra_framework: &signer, epoch_interval_microsecs: u64)
+
+ + + +
+Implementation + + +
public fun initializate_by_default(supra_framework: &signer, epoch_interval_microsecs: u64) {
+    let default_automation_gas_limit: u64 = 100_000_000;
+    let default_duration_upper_limit: u64 = 2_626_560;
+    let default_automation_unit_price: u64 = 1000;
+    initialize(
+        supra_framework,
+        epoch_interval_microsecs,
+        default_automation_gas_limit,
+        default_duration_upper_limit,
+        default_automation_unit_price
+    );
+}
+
+ + + +
+ ## Function `initialize` @@ -749,7 +785,7 @@ Transfers the specified fee amount from the resource account to the target accou Update Automation Registry Config -
public entry fun update_config(supra_framework: &signer, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
+
public fun update_config(supra_framework: &signer, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
 
@@ -758,7 +794,7 @@ Update Automation Registry Config Implementation -
public entry fun update_config(
+
public fun update_config(
     supra_framework: &signer,
     automation_gas_limit: u64,
     duration_upper_limit: u64,
@@ -792,7 +828,7 @@ Update Automation Registry Config
 Deducts the automation fee from the user's account based on the selected expiry time.
 
 
-
fun charge_automation_fee_from_user(owner: &signer, automation_unit_price: u64, task_duration: u64, registry_fee_address: address)
+
fun charge_automation_fee_from_user(owner: &signer, automation_registry_config: &automation_registry::AutomationRegistryConfig, task_duration: u64, registry_fee_address: address)
 
@@ -803,11 +839,11 @@ Deducts the automation fee from the user's account based on the selected expiry
fun charge_automation_fee_from_user(
     owner: &signer,
-    automation_unit_price: u64,
+    automation_registry_config: &AutomationRegistryConfig,
     task_duration: u64,
     registry_fee_address: address
 ) {
-    let automation_base_fee = task_duration * automation_unit_price;
+    let automation_base_fee = task_duration * automation_registry_config.automation_unit_price;
     // todo : dynamic price calculation is pending
     supra_account::transfer(owner, registry_fee_address, automation_base_fee);
 }
@@ -848,14 +884,11 @@ Registers a new automation task entry.
     //Well-formedness check of payload_tx is done in native layer beforehand.
 
     let registration_time = timestamp::now_seconds();
-    assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME);
-    let task_duration = expiry_time - registration_time;
-    assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER);
-
-    // Check that task is valid at least in the next epoch
-    assert!(
-        expiry_time > (automation_epoch_info.start_time + automation_epoch_info.epoch_interval),
-        EEXPIRY_BEFORE_NEXT_EPOCH
+    let task_duration = check_registration_task_duration(
+        expiry_time,
+        registration_time,
+        automation_registry_config,
+        automation_epoch_info
     );
 
     assert!(gas_price_cap > 0, EINVALID_GAS_PRICE);
@@ -888,7 +921,7 @@ Registers a new automation task entry.
 
     charge_automation_fee_from_user(
         owner,
-        automation_registry_config.automation_unit_price,
+        automation_registry_config,
         task_duration,
         automation_registry.registry_fee_address);
 }
@@ -896,6 +929,44 @@ Registers a new automation task entry.
 
 
 
+
+
+
+
+## Function `check_registration_task_duration`
+
+
+
+
fun check_registration_task_duration(expiry_time: u64, registration_time: u64, automation_registry_config: &automation_registry::AutomationRegistryConfig, automation_epoch_info: &automation_registry::AutomationEpochInfo): u64
+
+ + + +
+Implementation + + +
fun check_registration_task_duration(
+    expiry_time: u64,
+    registration_time: u64,
+    automation_registry_config: &AutomationRegistryConfig,
+    automation_epoch_info: &AutomationEpochInfo
+): u64 {
+    assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME);
+    let task_duration = expiry_time - registration_time;
+    assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER);
+
+    // Check that task is valid at least in the next epoch
+    assert!(
+        expiry_time > (automation_epoch_info.start_time + automation_epoch_info.epoch_interval),
+        EEXPIRY_BEFORE_NEXT_EPOCH
+    );
+    task_duration
+}
+
+ + +
@@ -946,7 +1017,7 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can refund_automation_task_fee( signer::address_of(owner), &automation_task_metadata, - automation_registry_config.automation_unit_price + automation_registry_config ); }
@@ -962,7 +1033,7 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can Refunds the automation task fee to the user who has removed their task registration from the list. -
fun refund_automation_task_fee(user: address, automation_task_metadata: &automation_registry::AutomationTaskMetaData, automation_unit_price: u64)
+
fun refund_automation_task_fee(user: address, automation_task_metadata: &automation_registry::AutomationTaskMetaData, automation_registry_config: &automation_registry::AutomationRegistryConfig)
 
@@ -974,12 +1045,12 @@ Refunds the automation task fee to the user who has removed their task registrat
fun refund_automation_task_fee(
     user: address,
     automation_task_metadata: &AutomationTaskMetaData,
-    automation_unit_price: u64,
+    automation_registry_config: &AutomationRegistryConfig,
 ) acquires AutomationRegistry {
     let current_time = timestamp::now_seconds();
     let expiry_time_duration = automation_task_metadata.expiry_time - current_time;
 
-    let refund_amount = expiry_time_duration * automation_unit_price;
+    let refund_amount = expiry_time_duration * automation_registry_config.automation_unit_price;
     transfer_fee_to_account_internal(user, refund_amount);
     event::emit(RefundFeeUser { user, amount: refund_amount });
 }
diff --git a/aptos-move/framework/supra-framework/doc/genesis.md b/aptos-move/framework/supra-framework/doc/genesis.md
index 39683da6eaf7d..c2b14175f9050 100644
--- a/aptos-move/framework/supra-framework/doc/genesis.md
+++ b/aptos-move/framework/supra-framework/doc/genesis.md
@@ -49,6 +49,7 @@
 
 
use 0x1::account;
 use 0x1::aggregator_factory;
+use 0x1::automation_registry;
 use 0x1::block;
 use 0x1::chain_id;
 use 0x1::chain_status;
@@ -631,6 +632,7 @@ Genesis step 1: Initialize aptos framework account and core modules on chain.
     reconfiguration::initialize(&supra_framework_account);
     block::initialize(&supra_framework_account, epoch_interval_microsecs);
     state_storage::initialize(&supra_framework_account);
+    automation_registry::initializate_by_default(&supra_framework_account, epoch_interval_microsecs);
     timestamp::set_time_has_started(&supra_framework_account, genesis_timestamp_in_microseconds);
 }
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 3837846ccf997..feb0ea70107e8 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -141,6 +141,20 @@ module supra_framework::automation_registry { id: u64 } + /// This is temporary function : until we have initialization flow properly implemented + public fun initializate_by_default(supra_framework: &signer, epoch_interval_microsecs: u64) { + let default_automation_gas_limit: u64 = 100_000_000; + let default_duration_upper_limit: u64 = 2_626_560; + let default_automation_unit_price: u64 = 1000; + initialize( + supra_framework, + epoch_interval_microsecs, + default_automation_gas_limit, + default_duration_upper_limit, + default_automation_unit_price + ); + } + /// Initialization of Automation Registry public fun initialize( supra_framework: &signer, diff --git a/aptos-move/framework/supra-framework/sources/genesis.move b/aptos-move/framework/supra-framework/sources/genesis.move index 79e4423cf94b7..00989603a2dcf 100644 --- a/aptos-move/framework/supra-framework/sources/genesis.move +++ b/aptos-move/framework/supra-framework/sources/genesis.move @@ -8,6 +8,7 @@ module supra_framework::genesis { use supra_framework::account; use supra_framework::aggregator_factory; + use supra_framework::automation_registry; use supra_framework::block; use supra_framework::chain_id; use supra_framework::chain_status; @@ -194,6 +195,7 @@ module supra_framework::genesis { reconfiguration::initialize(&supra_framework_account); block::initialize(&supra_framework_account, epoch_interval_microsecs); state_storage::initialize(&supra_framework_account); + automation_registry::initializate_by_default(&supra_framework_account, epoch_interval_microsecs); timestamp::set_time_has_started(&supra_framework_account, genesis_timestamp_in_microseconds); } From 0d109e787eee1a63c2295851e6aa9da8bd5ce6f7 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Thu, 16 Jan 2025 18:48:02 +0530 Subject: [PATCH 06/13] automation registry - make it all the structure as `resource_group_member` --- .../supra-framework/doc/automation_registry.md | 14 +++++++++----- .../sources/automation_registry.move | 6 +++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 60f0f3ae52437..1ca398e7210bf 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -11,7 +11,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Resource `AutomationRegistryConfig`](#0x1_automation_registry_AutomationRegistryConfig) - [Resource `AutomationRegistry`](#0x1_automation_registry_AutomationRegistry) - [Resource `AutomationEpochInfo`](#0x1_automation_registry_AutomationEpochInfo) -- [Struct `AutomationTaskMetaData`](#0x1_automation_registry_AutomationTaskMetaData) +- [Resource `AutomationTaskMetaData`](#0x1_automation_registry_AutomationTaskMetaData) - [Struct `FeeWithdrawnAdmin`](#0x1_automation_registry_FeeWithdrawnAdmin) - [Struct `RefundFeeUser`](#0x1_automation_registry_RefundFeeUser) - [Struct `CancelledAutomationTask`](#0x1_automation_registry_CancelledAutomationTask) @@ -57,6 +57,7 @@ Automation registry config
#[event]
+#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
 struct AutomationRegistryConfig has copy, drop, store, key
 
@@ -97,7 +98,8 @@ Automation registry config It tracks entries both pending and completed, organized by unique indices. -
struct AutomationRegistry has store, key
+
#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
+struct AutomationRegistry has store, key
 
@@ -149,7 +151,8 @@ It tracks entries both pending and completed, organized by unique indices. Epoch state -
struct AutomationEpochInfo has key
+
#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
+struct AutomationEpochInfo has key
 
@@ -188,13 +191,14 @@ Epoch state -## Struct `AutomationTaskMetaData` +## Resource `AutomationTaskMetaData` AutomationTaskMetaData represents a single automation task item, containing metadata.
#[event]
-struct AutomationTaskMetaData has copy, drop, store
+#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
+struct AutomationTaskMetaData has copy, drop, store, key
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index feb0ea70107e8..7a4d88bdb54b1 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -59,6 +59,7 @@ module supra_framework::automation_registry { const ACTIVE: u8 = 1; const CANCELLED: u8 = 2; + #[resource_group_member(group = supra_framework::object::ObjectGroup)] #[event] /// Automation registry config struct AutomationRegistryConfig has key, store, drop, copy { @@ -70,6 +71,7 @@ module supra_framework::automation_registry { automation_unit_price: u64, } + #[resource_group_member(group = supra_framework::object::ObjectGroup)] /// It tracks entries both pending and completed, organized by unique indices. struct AutomationRegistry has key, store { /// A collection of automation task entries that are active state. @@ -84,6 +86,7 @@ module supra_framework::automation_registry { registry_fee_address_signer_cap: SignerCapability, } + #[resource_group_member(group = supra_framework::object::ObjectGroup)] /// Epoch state struct AutomationEpochInfo has key { /// Epoch expected duration at the beginning of the new epoch, Based on this and actual @@ -98,9 +101,10 @@ module supra_framework::automation_registry { start_time: u64, } + #[resource_group_member(group = supra_framework::object::ObjectGroup)] #[event] /// `AutomationTaskMetaData` represents a single automation task item, containing metadata. - struct AutomationTaskMetaData has copy, store, drop { + struct AutomationTaskMetaData has key, copy, store, drop { /// Automation task index in registry id: u64, /// The address of the task owner. From c4bb0d04d424dc51186e52db787bb86179e7fa4d Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Fri, 17 Jan 2025 13:08:25 +0530 Subject: [PATCH 07/13] automation registry - add new configration parameters and rename old as well --- .../doc/automation_registry.md | 144 ++++++++++++---- .../sources/automation_registry.move | 155 ++++++++++++------ 2 files changed, 220 insertions(+), 79 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 1ca398e7210bf..ee0b4eaf8861d 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -34,6 +34,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Function `has_sender_active_task_with_id`](#0x1_automation_registry_has_sender_active_task_with_id) - [Function `get_registry_fee_address`](#0x1_automation_registry_get_registry_fee_address) - [Function `get_gas_committed_for_next_epoch`](#0x1_automation_registry_get_gas_committed_for_next_epoch) +- [Function `get_automation_registry_config`](#0x1_automation_registry_get_automation_registry_config)
use 0x1::account;
@@ -69,22 +70,50 @@ Automation registry config
 
 
-automation_gas_limit: u64 +task_duration_cap_in_secs: u64
- Automation task max gas limit + Maximum allowable duration (in seconds) from the registration time that an automation task can run. + If the expiration time exceeds this duration, the task registration will fail.
-duration_upper_limit: u64 +registry_max_gas_cap: u64
- Automation task duration upper limit. + Maximum gas allocation for automation tasks per epoch + Exceeding this limit during task registration will cause failure and is used in fee calculation.
-automation_unit_price: u64 +automation_base_fee_in_quants_per_sec: u64
- Automation task unit price per second + Base fee per second for the full capacity of the automation registry, measured in quants/sec. + The capacity is considered full if the total committed gas of all registered tasks equals registry_max_gas_cap. +
+
+flat_registration_fee_in_quants: u64 +
+
+ Flat registration fee charged by default for each task. +
+
+congestion_threshold_percentage: u8 +
+
+ Ratio (in the range [0;100]) representing the acceptable upper limit of committed gas amount + relative to registry_max_gas_cap. Beyond this threshold, congestion fees apply. +
+
+congestion_base_fee_in_quants_per_sec: u64 +
+
+ Base fee per second for the full capacity of the automation registry when the congestion threshold is exceeded. +
+
+cancellation_fee_in_qunats: u64 +
+
+ System-configured penalty charged for task cancellations.
@@ -586,15 +615,16 @@ This is temporary function : until we have initialization flow properly implemen
public fun initializate_by_default(supra_framework: &signer, epoch_interval_microsecs: u64) {
-    let default_automation_gas_limit: u64 = 100_000_000;
-    let default_duration_upper_limit: u64 = 2_626_560;
-    let default_automation_unit_price: u64 = 1000;
     initialize(
         supra_framework,
         epoch_interval_microsecs,
-        default_automation_gas_limit,
-        default_duration_upper_limit,
-        default_automation_unit_price
+        2_626_560,
+        100_000_000,
+        1000,
+        500000000, // 5 supra
+        80,
+        100,
+        300000000, // 3 supra
     );
 }
 
@@ -610,7 +640,7 @@ This is temporary function : until we have initialization flow properly implemen Initialization of Automation Registry -
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
+
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, cancellation_fee_in_qunats: u64)
 
@@ -622,9 +652,13 @@ Initialization of Automation Registry
public fun initialize(
     supra_framework: &signer,
     epoch_interval_microsecs: u64,
-    automation_gas_limit: u64,
-    duration_upper_limit: u64,
-    automation_unit_price: u64,
+    task_duration_cap_in_secs: u64,
+    registry_max_gas_cap: u64,
+    automation_base_fee_in_quants_per_sec: u64,
+    flat_registration_fee_in_quants: u64,
+    congestion_threshold_percentage: u8,
+    congestion_base_fee_in_quants_per_sec: u64,
+    cancellation_fee_in_qunats: u64,
 ) {
     system_addresses::assert_supra_framework(supra_framework);
 
@@ -642,9 +676,13 @@ Initialization of Automation Registry
     });
 
     move_to(supra_framework, AutomationRegistryConfig {
-        automation_gas_limit,
-        duration_upper_limit,
-        automation_unit_price,
+        task_duration_cap_in_secs,
+        registry_max_gas_cap,
+        automation_base_fee_in_quants_per_sec,
+        flat_registration_fee_in_quants,
+        congestion_threshold_percentage,
+        cancellation_fee_in_qunats,
+        congestion_base_fee_in_quants_per_sec,
     });
 
     let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR;
@@ -707,9 +745,13 @@ On new epoch this function will be triggered and update the automation registry
     if (config_buffer::does_exist<AutomationRegistryConfig>()) {
         let buffer = config_buffer::extract<AutomationRegistryConfig>();
         let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
-        automation_registry_config.automation_unit_price = buffer.automation_unit_price;
-        automation_registry_config.duration_upper_limit = buffer.duration_upper_limit;
-        automation_registry_config.automation_gas_limit = buffer.automation_gas_limit;
+        automation_registry_config.task_duration_cap_in_secs = buffer.task_duration_cap_in_secs;
+        automation_registry_config.registry_max_gas_cap = buffer.registry_max_gas_cap;
+        automation_registry_config.automation_base_fee_in_quants_per_sec = buffer.automation_base_fee_in_quants_per_sec;
+        automation_registry_config.flat_registration_fee_in_quants = buffer.flat_registration_fee_in_quants;
+        automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage;
+        automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec;
+        automation_registry_config.cancellation_fee_in_qunats = buffer.cancellation_fee_in_qunats;
     };
 
     automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch;
@@ -789,7 +831,7 @@ Transfers the specified fee amount from the resource account to the target accou
 Update Automation Registry Config
 
 
-
public fun update_config(supra_framework: &signer, automation_gas_limit: u64, duration_upper_limit: u64, automation_unit_price: u64)
+
public fun update_config(supra_framework: &signer, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, cancellation_fee_in_qunats: u64)
 
@@ -800,21 +842,31 @@ Update Automation Registry Config
public fun update_config(
     supra_framework: &signer,
-    automation_gas_limit: u64,
-    duration_upper_limit: u64,
-    automation_unit_price: u64,
+    task_duration_cap_in_secs: u64,
+    registry_max_gas_cap: u64,
+    automation_base_fee_in_quants_per_sec: u64,
+    flat_registration_fee_in_quants: u64,
+    congestion_threshold_percentage: u8,
+    congestion_base_fee_in_quants_per_sec: u64,
+    cancellation_fee_in_qunats: u64,
 ) acquires AutomationRegistry {
     system_addresses::assert_supra_framework(supra_framework);
 
     let automation_registry = borrow_global<AutomationRegistry>(@supra_framework);
 
     assert!(
-        automation_registry.gas_committed_for_next_epoch < automation_gas_limit,
+        automation_registry.gas_committed_for_next_epoch < registry_max_gas_cap,
         EUNACCEPTABLE_AUTOMATION_GAS_LIMIT
     );
 
     let automation_registry_config = AutomationRegistryConfig {
-        automation_gas_limit, duration_upper_limit, automation_unit_price
+        task_duration_cap_in_secs,
+        registry_max_gas_cap,
+        automation_base_fee_in_quants_per_sec,
+        flat_registration_fee_in_quants,
+        congestion_threshold_percentage,
+        congestion_base_fee_in_quants_per_sec,
+        cancellation_fee_in_qunats
     };
     config_buffer::upsert(copy automation_registry_config);
     event::emit(automation_registry_config);
@@ -847,9 +899,9 @@ Deducts the automation fee from the user's account based on the selected expiry
     task_duration: u64,
     registry_fee_address: address
 ) {
-    let automation_base_fee = task_duration * automation_registry_config.automation_unit_price;
+    let automation_base_fee_in_quants_per_sec = task_duration * automation_registry_config.automation_base_fee_in_quants_per_sec;
     // todo : dynamic price calculation is pending
-    supra_account::transfer(owner, registry_fee_address, automation_base_fee);
+    supra_account::transfer(owner, registry_fee_address, automation_base_fee_in_quants_per_sec);
 }
 
@@ -903,7 +955,7 @@ Registers a new automation task entry. assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry_config.automation_gas_limit, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.registry_max_gas_cap, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -958,7 +1010,7 @@ Registers a new automation task entry. ): u64 { assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); let task_duration = expiry_time - registration_time; - assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); + assert!(task_duration < automation_registry_config.task_duration_cap_in_secs, EEXPIRY_TIME_UPPER); // Check that task is valid at least in the next epoch assert!( @@ -1054,7 +1106,7 @@ Refunds the automation task fee to the user who has removed their task registrat let current_time = timestamp::now_seconds(); let expiry_time_duration = automation_task_metadata.expiry_time - current_time; - let refund_amount = expiry_time_duration * automation_registry_config.automation_unit_price; + let refund_amount = expiry_time_duration * automation_registry_config.automation_base_fee_in_quants_per_sec; transfer_fee_to_account_internal(user, refund_amount); event::emit(RefundFeeUser { user, amount: refund_amount }); } @@ -1265,6 +1317,32 @@ Get gas committed for next epoch + + + + +## Function `get_automation_registry_config` + +Get automation registry configration + + +
#[view]
+public fun get_automation_registry_config(): automation_registry::AutomationRegistryConfig
+
+ + + +
+Implementation + + +
public fun get_automation_registry_config(): AutomationRegistryConfig acquires AutomationRegistryConfig {
+    *borrow_global<AutomationRegistryConfig>(@supra_framework)
+}
+
+ + +
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 7a4d88bdb54b1..ba9ab8d6de5da 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -63,12 +63,24 @@ module supra_framework::automation_registry { #[event] /// Automation registry config struct AutomationRegistryConfig has key, store, drop, copy { - /// Automation task max gas limit - automation_gas_limit: u64, - /// Automation task duration upper limit. - duration_upper_limit: u64, - /// Automation task unit price per second - automation_unit_price: u64, + /// Maximum allowable duration (in seconds) from the registration time that an automation task can run. + /// If the expiration time exceeds this duration, the task registration will fail. + task_duration_cap_in_secs: u64, + /// Maximum gas allocation for automation tasks per epoch + /// Exceeding this limit during task registration will cause failure and is used in fee calculation. + registry_max_gas_cap: u64, + /// Base fee per second for the full capacity of the automation registry, measured in quants/sec. + /// The capacity is considered full if the total committed gas of all registered tasks equals registry_max_gas_cap. + automation_base_fee_in_quants_per_sec: u64, + /// Flat registration fee charged by default for each task. + flat_registration_fee_in_quants: u64, + /// Ratio (in the range [0;100]) representing the acceptable upper limit of committed gas amount + /// relative to registry_max_gas_cap. Beyond this threshold, congestion fees apply. + congestion_threshold_percentage: u8, + /// Base fee per second for the full capacity of the automation registry when the congestion threshold is exceeded. + congestion_base_fee_in_quants_per_sec: u64, + /// System-configured penalty charged for task cancellations. + cancellation_fee_in_qunats: u64, } #[resource_group_member(group = supra_framework::object::ObjectGroup)] @@ -147,15 +159,16 @@ module supra_framework::automation_registry { /// This is temporary function : until we have initialization flow properly implemented public fun initializate_by_default(supra_framework: &signer, epoch_interval_microsecs: u64) { - let default_automation_gas_limit: u64 = 100_000_000; - let default_duration_upper_limit: u64 = 2_626_560; - let default_automation_unit_price: u64 = 1000; initialize( supra_framework, epoch_interval_microsecs, - default_automation_gas_limit, - default_duration_upper_limit, - default_automation_unit_price + 2_626_560, + 100_000_000, + 1000, + 500000000, // 5 supra + 80, + 100, + 300000000, // 3 supra ); } @@ -163,9 +176,13 @@ module supra_framework::automation_registry { public fun initialize( supra_framework: &signer, epoch_interval_microsecs: u64, - automation_gas_limit: u64, - duration_upper_limit: u64, - automation_unit_price: u64, + task_duration_cap_in_secs: u64, + registry_max_gas_cap: u64, + automation_base_fee_in_quants_per_sec: u64, + flat_registration_fee_in_quants: u64, + congestion_threshold_percentage: u8, + congestion_base_fee_in_quants_per_sec: u64, + cancellation_fee_in_qunats: u64, ) { system_addresses::assert_supra_framework(supra_framework); @@ -183,9 +200,13 @@ module supra_framework::automation_registry { }); move_to(supra_framework, AutomationRegistryConfig { - automation_gas_limit, - duration_upper_limit, - automation_unit_price, + task_duration_cap_in_secs, + registry_max_gas_cap, + automation_base_fee_in_quants_per_sec, + flat_registration_fee_in_quants, + congestion_threshold_percentage, + cancellation_fee_in_qunats, + congestion_base_fee_in_quants_per_sec, }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -228,9 +249,13 @@ module supra_framework::automation_registry { if (config_buffer::does_exist()) { let buffer = config_buffer::extract(); let automation_registry_config = borrow_global_mut(@supra_framework); - automation_registry_config.automation_unit_price = buffer.automation_unit_price; - automation_registry_config.duration_upper_limit = buffer.duration_upper_limit; - automation_registry_config.automation_gas_limit = buffer.automation_gas_limit; + automation_registry_config.task_duration_cap_in_secs = buffer.task_duration_cap_in_secs; + automation_registry_config.registry_max_gas_cap = buffer.registry_max_gas_cap; + automation_registry_config.automation_base_fee_in_quants_per_sec = buffer.automation_base_fee_in_quants_per_sec; + automation_registry_config.flat_registration_fee_in_quants = buffer.flat_registration_fee_in_quants; + automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage; + automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec; + automation_registry_config.cancellation_fee_in_qunats = buffer.cancellation_fee_in_qunats; }; automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; @@ -261,21 +286,31 @@ module supra_framework::automation_registry { /// Update Automation Registry Config public fun update_config( supra_framework: &signer, - automation_gas_limit: u64, - duration_upper_limit: u64, - automation_unit_price: u64, + task_duration_cap_in_secs: u64, + registry_max_gas_cap: u64, + automation_base_fee_in_quants_per_sec: u64, + flat_registration_fee_in_quants: u64, + congestion_threshold_percentage: u8, + congestion_base_fee_in_quants_per_sec: u64, + cancellation_fee_in_qunats: u64, ) acquires AutomationRegistry { system_addresses::assert_supra_framework(supra_framework); let automation_registry = borrow_global(@supra_framework); assert!( - automation_registry.gas_committed_for_next_epoch < automation_gas_limit, + automation_registry.gas_committed_for_next_epoch < registry_max_gas_cap, EUNACCEPTABLE_AUTOMATION_GAS_LIMIT ); let automation_registry_config = AutomationRegistryConfig { - automation_gas_limit, duration_upper_limit, automation_unit_price + task_duration_cap_in_secs, + registry_max_gas_cap, + automation_base_fee_in_quants_per_sec, + flat_registration_fee_in_quants, + congestion_threshold_percentage, + congestion_base_fee_in_quants_per_sec, + cancellation_fee_in_qunats }; config_buffer::upsert(copy automation_registry_config); event::emit(automation_registry_config); @@ -288,9 +323,9 @@ module supra_framework::automation_registry { task_duration: u64, registry_fee_address: address ) { - let automation_base_fee = task_duration * automation_registry_config.automation_unit_price; + let automation_base_fee_in_quants_per_sec = task_duration * automation_registry_config.automation_base_fee_in_quants_per_sec; // todo : dynamic price calculation is pending - supra_account::transfer(owner, registry_fee_address, automation_base_fee); + supra_account::transfer(owner, registry_fee_address, automation_base_fee_in_quants_per_sec); } /// Registers a new automation task entry. @@ -324,7 +359,7 @@ module supra_framework::automation_registry { assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry_config.automation_gas_limit, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.registry_max_gas_cap, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -359,7 +394,7 @@ module supra_framework::automation_registry { ): u64 { assert!(expiry_time > registration_time, EINVALID_EXPIRY_TIME); let task_duration = expiry_time - registration_time; - assert!(task_duration < automation_registry_config.duration_upper_limit, EEXPIRY_TIME_UPPER); + assert!(task_duration < automation_registry_config.task_duration_cap_in_secs, EEXPIRY_TIME_UPPER); // Check that task is valid at least in the next epoch assert!( @@ -415,7 +450,7 @@ module supra_framework::automation_registry { let current_time = timestamp::now_seconds(); let expiry_time_duration = automation_task_metadata.expiry_time - current_time; - let refund_amount = expiry_time_duration * automation_registry_config.automation_unit_price; + let refund_amount = expiry_time_duration * automation_registry_config.automation_base_fee_in_quants_per_sec; transfer_fee_to_account_internal(user, refund_amount); event::emit(RefundFeeUser { user, amount: refund_amount }); } @@ -483,15 +518,26 @@ module supra_framework::automation_registry { automation_registry.gas_committed_for_next_epoch } + #[view] + /// Get automation registry configration + public fun get_automation_registry_config(): AutomationRegistryConfig acquires AutomationRegistryConfig { + *borrow_global(@supra_framework) + } + + #[test_only] + const AUTOMATION_MAX_GAS_TEST: u64 = 100_000_000; #[test_only] - /// The default automation task gas limit - const AUTOMATION_GAS_LIMIT_TEST: u64 = 100_000_000; + const TTL_UPPER_BOUND_TEST: u64 = 2_626_560; #[test_only] - /// The default upper limit duration for automation task, specified in seconds (30.4 days). - const DURATION_UPPER_LIMIT_TEST: u64 = 2_626_560; + const AUTOMATION_BASE_FEE_TEST: u64 = 1000; #[test_only] - /// The default Automation unit price for per second, in Quants - const AUTOMATION_UNIT_PRICE_TEST: u64 = 1000; + const FLATE_REGISTRATION_FEE_TEST: u64 = 500000000; + #[test_only] + const CONGESTION_THRESHOLD_TEST: u8 = 80; + #[test_only] + const CONGESTION_BASE_FEE_TEST: u64 = 100; + #[test_only] + const CANCELLATION_FEE_TEST: u64 = 300000000; #[test_only] /// Value defined in microsecond const EPOCH_INTERVAL_FOR_TEST: u64 = 7200000000; @@ -520,9 +566,13 @@ module supra_framework::automation_registry { initialize( supra_framework, EPOCH_INTERVAL_FOR_TEST, - AUTOMATION_GAS_LIMIT_TEST, - DURATION_UPPER_LIMIT_TEST, - AUTOMATION_UNIT_PRICE_TEST + TTL_UPPER_BOUND_TEST, + AUTOMATION_MAX_GAS_TEST, + AUTOMATION_BASE_FEE_TEST, + FLATE_REGISTRATION_FEE_TEST, + CONGESTION_THRESHOLD_TEST, + CONGESTION_BASE_FEE_TEST, + CANCELLATION_FEE_TEST, ); } @@ -559,17 +609,21 @@ module supra_framework::automation_registry { config_buffer::initialize(framework); // Next epoch gas committed gas is less than the new limit value. // Configration parameter will update after on new epoch - update_config(framework, 75, 1_626_560, 1005); + update_config(framework, 1_626_560, 75, 1005, 700000000, 70, 2000, 400000000); let state = borrow_global(@supra_framework); - assert!(state.automation_gas_limit == AUTOMATION_GAS_LIMIT_TEST, 1); + assert!(state.registry_max_gas_cap == AUTOMATION_MAX_GAS_TEST, 1); // Automation gas limit on_new_epoch(); let state = borrow_global(@supra_framework); - assert!(state.automation_gas_limit == 75, 2); - assert!(state.duration_upper_limit == 1_626_560, 3); - assert!(state.automation_unit_price == 1005, 4); + assert!(state.registry_max_gas_cap == 75, 2); + assert!(state.task_duration_cap_in_secs == 1_626_560, 3); + assert!(state.automation_base_fee_in_quants_per_sec == 1005, 4); + assert!(state.flat_registration_fee_in_quants == 700000000, 5); + assert!(state.congestion_threshold_percentage == 70, 6); + assert!(state.congestion_base_fee_in_quants_per_sec == 2000, 7); + assert!(state.cancellation_fee_in_qunats == 400000000, 8); } #[test(framework = @supra_framework, user = @0x1cafe)] @@ -587,7 +641,16 @@ module supra_framework::automation_registry { ); // Next epoch gas committed gas is greater than the new limit value. - update_config(framework, 45, DURATION_UPPER_LIMIT_TEST, AUTOMATION_UNIT_PRICE_TEST); + update_config( + framework, + TTL_UPPER_BOUND_TEST, + 45, + AUTOMATION_BASE_FEE_TEST, + FLATE_REGISTRATION_FEE_TEST, + CONGESTION_THRESHOLD_TEST, + CONGESTION_BASE_FEE_TEST, + CANCELLATION_FEE_TEST + ); } #[test(framework = @supra_framework, user = @0x1cafe)] From 5f2422df4c2639f288bc78b12da856d03e3fec41 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Mon, 20 Jan 2025 10:56:57 +0530 Subject: [PATCH 08/13] automation registry - combining, cancellation/flat registration --- .../supra-framework/doc/automation_registry.md | 16 ++-------------- .../sources/automation_registry.move | 15 +-------------- 2 files changed, 3 insertions(+), 28 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index ee0b4eaf8861d..fa9aba4c74601 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -109,12 +109,6 @@ Automation registry config
Base fee per second for the full capacity of the automation registry when the congestion threshold is exceeded.
-
-cancellation_fee_in_qunats: u64 -
-
- System-configured penalty charged for task cancellations. -
@@ -624,7 +618,6 @@ This is temporary function : until we have initialization flow properly implemen 500000000, // 5 supra 80, 100, - 300000000, // 3 supra ); }
@@ -640,7 +633,7 @@ This is temporary function : until we have initialization flow properly implemen Initialization of Automation Registry -
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, cancellation_fee_in_qunats: u64)
+
public fun initialize(supra_framework: &signer, epoch_interval_microsecs: u64, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64)
 
@@ -658,7 +651,6 @@ Initialization of Automation Registry flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, - cancellation_fee_in_qunats: u64, ) { system_addresses::assert_supra_framework(supra_framework); @@ -681,7 +673,6 @@ Initialization of Automation Registry automation_base_fee_in_quants_per_sec, flat_registration_fee_in_quants, congestion_threshold_percentage, - cancellation_fee_in_qunats, congestion_base_fee_in_quants_per_sec, }); @@ -751,7 +742,6 @@ On new epoch this function will be triggered and update the automation registry automation_registry_config.flat_registration_fee_in_quants = buffer.flat_registration_fee_in_quants; automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage; automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec; - automation_registry_config.cancellation_fee_in_qunats = buffer.cancellation_fee_in_qunats; }; automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; @@ -831,7 +821,7 @@ Transfers the specified fee amount from the resource account to the target accou Update Automation Registry Config -
public fun update_config(supra_framework: &signer, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, cancellation_fee_in_qunats: u64)
+
public fun update_config(supra_framework: &signer, task_duration_cap_in_secs: u64, registry_max_gas_cap: u64, automation_base_fee_in_quants_per_sec: u64, flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64)
 
@@ -848,7 +838,6 @@ Update Automation Registry Config flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, - cancellation_fee_in_qunats: u64, ) acquires AutomationRegistry { system_addresses::assert_supra_framework(supra_framework); @@ -866,7 +855,6 @@ Update Automation Registry Config flat_registration_fee_in_quants, congestion_threshold_percentage, congestion_base_fee_in_quants_per_sec, - cancellation_fee_in_qunats }; config_buffer::upsert(copy automation_registry_config); event::emit(automation_registry_config); diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index ba9ab8d6de5da..84e4938fae3e7 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -79,8 +79,6 @@ module supra_framework::automation_registry { congestion_threshold_percentage: u8, /// Base fee per second for the full capacity of the automation registry when the congestion threshold is exceeded. congestion_base_fee_in_quants_per_sec: u64, - /// System-configured penalty charged for task cancellations. - cancellation_fee_in_qunats: u64, } #[resource_group_member(group = supra_framework::object::ObjectGroup)] @@ -168,7 +166,6 @@ module supra_framework::automation_registry { 500000000, // 5 supra 80, 100, - 300000000, // 3 supra ); } @@ -182,7 +179,6 @@ module supra_framework::automation_registry { flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, - cancellation_fee_in_qunats: u64, ) { system_addresses::assert_supra_framework(supra_framework); @@ -205,7 +201,6 @@ module supra_framework::automation_registry { automation_base_fee_in_quants_per_sec, flat_registration_fee_in_quants, congestion_threshold_percentage, - cancellation_fee_in_qunats, congestion_base_fee_in_quants_per_sec, }); @@ -255,7 +250,6 @@ module supra_framework::automation_registry { automation_registry_config.flat_registration_fee_in_quants = buffer.flat_registration_fee_in_quants; automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage; automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec; - automation_registry_config.cancellation_fee_in_qunats = buffer.cancellation_fee_in_qunats; }; automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; @@ -292,7 +286,6 @@ module supra_framework::automation_registry { flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, - cancellation_fee_in_qunats: u64, ) acquires AutomationRegistry { system_addresses::assert_supra_framework(supra_framework); @@ -310,7 +303,6 @@ module supra_framework::automation_registry { flat_registration_fee_in_quants, congestion_threshold_percentage, congestion_base_fee_in_quants_per_sec, - cancellation_fee_in_qunats }; config_buffer::upsert(copy automation_registry_config); event::emit(automation_registry_config); @@ -537,8 +529,6 @@ module supra_framework::automation_registry { #[test_only] const CONGESTION_BASE_FEE_TEST: u64 = 100; #[test_only] - const CANCELLATION_FEE_TEST: u64 = 300000000; - #[test_only] /// Value defined in microsecond const EPOCH_INTERVAL_FOR_TEST: u64 = 7200000000; #[test_only] @@ -572,7 +562,6 @@ module supra_framework::automation_registry { FLATE_REGISTRATION_FEE_TEST, CONGESTION_THRESHOLD_TEST, CONGESTION_BASE_FEE_TEST, - CANCELLATION_FEE_TEST, ); } @@ -609,7 +598,7 @@ module supra_framework::automation_registry { config_buffer::initialize(framework); // Next epoch gas committed gas is less than the new limit value. // Configration parameter will update after on new epoch - update_config(framework, 1_626_560, 75, 1005, 700000000, 70, 2000, 400000000); + update_config(framework, 1_626_560, 75, 1005, 700000000, 70, 2000); let state = borrow_global(@supra_framework); assert!(state.registry_max_gas_cap == AUTOMATION_MAX_GAS_TEST, 1); @@ -623,7 +612,6 @@ module supra_framework::automation_registry { assert!(state.flat_registration_fee_in_quants == 700000000, 5); assert!(state.congestion_threshold_percentage == 70, 6); assert!(state.congestion_base_fee_in_quants_per_sec == 2000, 7); - assert!(state.cancellation_fee_in_qunats == 400000000, 8); } #[test(framework = @supra_framework, user = @0x1cafe)] @@ -649,7 +637,6 @@ module supra_framework::automation_registry { FLATE_REGISTRATION_FEE_TEST, CONGESTION_THRESHOLD_TEST, CONGESTION_BASE_FEE_TEST, - CANCELLATION_FEE_TEST ); } From 898c1dfe965d0a41599fb187cda3d454582dc55e Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Mon, 20 Jan 2025 11:54:37 +0530 Subject: [PATCH 09/13] automation registry - create seprate config of active one --- .../doc/automation_registry.md | 118 ++++++++++++++---- .../sources/automation_registry.move | 106 ++++++++++------ 2 files changed, 160 insertions(+), 64 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index fa9aba4c74601..0909857c45def 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -8,6 +8,7 @@ Supra Automation Registry This contract is part of the Supra Framework and is designed to manage automated task entries +- [Resource `ActiveAutomationRegistryConfig`](#0x1_automation_registry_ActiveAutomationRegistryConfig) - [Resource `AutomationRegistryConfig`](#0x1_automation_registry_AutomationRegistryConfig) - [Resource `AutomationRegistry`](#0x1_automation_registry_AutomationRegistry) - [Resource `AutomationEpochInfo`](#0x1_automation_registry_AutomationEpochInfo) @@ -35,6 +36,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Function `get_registry_fee_address`](#0x1_automation_registry_get_registry_fee_address) - [Function `get_gas_committed_for_next_epoch`](#0x1_automation_registry_get_gas_committed_for_next_epoch) - [Function `get_automation_registry_config`](#0x1_automation_registry_get_automation_registry_config) +- [Function `get_next_epoch_registry_max_gas_cap`](#0x1_automation_registry_get_next_epoch_registry_max_gas_cap)
use 0x1::account;
@@ -50,6 +52,40 @@ This contract is part of the Supra Framework and is designed to manage automated
 
 
 
+
+
+## Resource `ActiveAutomationRegistryConfig`
+
+
+
+
#[resource_group_member(#[group = 0x1::object::ObjectGroup])]
+struct ActiveAutomationRegistryConfig has key
+
+ + + +
+Fields + + +
+
+main_config: automation_registry::AutomationRegistryConfig +
+
+ +
+
+next_epoch_registry_max_gas_cap: u64 +
+
+ Will be the same as main_config.registry_max_gas_cap, unless updated during the epoch. +
+
+ + +
+ ## Resource `AutomationRegistryConfig` @@ -667,13 +703,16 @@ Initialization of Automation Registry registry_fee_address_signer_cap, }); - move_to(supra_framework, AutomationRegistryConfig { - task_duration_cap_in_secs, - registry_max_gas_cap, - automation_base_fee_in_quants_per_sec, - flat_registration_fee_in_quants, - congestion_threshold_percentage, - congestion_base_fee_in_quants_per_sec, + move_to(supra_framework, ActiveAutomationRegistryConfig { + main_config: AutomationRegistryConfig { + task_duration_cap_in_secs, + registry_max_gas_cap, + automation_base_fee_in_quants_per_sec, + flat_registration_fee_in_quants, + congestion_threshold_percentage, + congestion_base_fee_in_quants_per_sec, + }, + next_epoch_registry_max_gas_cap: registry_max_gas_cap }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -705,7 +744,7 @@ On new epoch this function will be triggered and update the automation registry Implementation -
public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig {
+
public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig {
     let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
     let ids = enumerable_map::get_map_list(&automation_registry.tasks);
 
@@ -735,7 +774,9 @@ On new epoch this function will be triggered and update the automation registry
     // Apply the latest configuration if any parameter has been updated.
     if (config_buffer::does_exist<AutomationRegistryConfig>()) {
         let buffer = config_buffer::extract<AutomationRegistryConfig>();
-        let automation_registry_config = borrow_global_mut<AutomationRegistryConfig>(@supra_framework);
+        let automation_registry_config = &mut borrow_global_mut<ActiveAutomationRegistryConfig>(
+            @supra_framework
+        ).main_config;
         automation_registry_config.task_duration_cap_in_secs = buffer.task_duration_cap_in_secs;
         automation_registry_config.registry_max_gas_cap = buffer.registry_max_gas_cap;
         automation_registry_config.automation_base_fee_in_quants_per_sec = buffer.automation_base_fee_in_quants_per_sec;
@@ -838,7 +879,7 @@ Update Automation Registry Config
     flat_registration_fee_in_quants: u64,
     congestion_threshold_percentage: u8,
     congestion_base_fee_in_quants_per_sec: u64,
-) acquires AutomationRegistry {
+) acquires AutomationRegistry, ActiveAutomationRegistryConfig {
     system_addresses::assert_supra_framework(supra_framework);
 
     let automation_registry = borrow_global<AutomationRegistry>(@supra_framework);
@@ -848,7 +889,7 @@ Update Automation Registry Config
         EUNACCEPTABLE_AUTOMATION_GAS_LIMIT
     );
 
-    let automation_registry_config = AutomationRegistryConfig {
+    let new_automation_registry_config = AutomationRegistryConfig {
         task_duration_cap_in_secs,
         registry_max_gas_cap,
         automation_base_fee_in_quants_per_sec,
@@ -856,8 +897,13 @@ Update Automation Registry Config
         congestion_threshold_percentage,
         congestion_base_fee_in_quants_per_sec,
     };
-    config_buffer::upsert(copy automation_registry_config);
-    event::emit(automation_registry_config);
+    config_buffer::upsert(copy new_automation_registry_config);
+
+    // next_epoch_registry_max_gas_cap will be update instantly
+    let automation_registry_config = borrow_global_mut<ActiveAutomationRegistryConfig>(@supra_framework);
+    automation_registry_config.next_epoch_registry_max_gas_cap = registry_max_gas_cap;
+
+    event::emit(new_automation_registry_config);
 }
 
@@ -920,9 +966,9 @@ Registers a new automation task entry. max_gas_amount: u64, gas_price_cap: u64, tx_hash: vector<u8> -) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { +) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework); - let automation_registry_config = borrow_global<AutomationRegistryConfig>(@supra_framework); + let automation_registry_config = borrow_global<ActiveAutomationRegistryConfig>(@supra_framework); let automation_epoch_info = borrow_global<AutomationEpochInfo>(@supra_framework); //Well-formedness check of payload_tx is done in native layer beforehand. @@ -931,7 +977,7 @@ Registers a new automation task entry. let task_duration = check_registration_task_duration( expiry_time, registration_time, - automation_registry_config, + &automation_registry_config.main_config, automation_epoch_info ); @@ -943,7 +989,7 @@ Registers a new automation task entry. assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry_config.registry_max_gas_cap, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.next_epoch_registry_max_gas_cap, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -965,7 +1011,7 @@ Registers a new automation task entry. charge_automation_fee_from_user( owner, - automation_registry_config, + &automation_registry_config.main_config, task_duration, automation_registry.registry_fee_address); } @@ -1035,9 +1081,9 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can Implementation -
public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, AutomationRegistryConfig {
+
public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, ActiveAutomationRegistryConfig {
     let automation_registry = borrow_global_mut<AutomationRegistry>(@supra_framework);
-    let automation_registry_config = borrow_global<AutomationRegistryConfig>(@supra_framework);
+    let automation_registry_config = borrow_global<ActiveAutomationRegistryConfig>(@supra_framework);
     assert!(enumerable_map::contains(&automation_registry.tasks, id), EAUTOMATION_TASK_NOT_FOUND);
 
     let automation_task_metadata = enumerable_map::get_value(&mut automation_registry.tasks, id);
@@ -1061,7 +1107,7 @@ Committed gas-limit is updated by reducing it with the max-gas-amount of the can
     refund_automation_task_fee(
         signer::address_of(owner),
         &automation_task_metadata,
-        automation_registry_config
+        &automation_registry_config.main_config
     );
 }
 
@@ -1324,8 +1370,34 @@ Get automation registry configration Implementation -
public fun get_automation_registry_config(): AutomationRegistryConfig acquires AutomationRegistryConfig {
-    *borrow_global<AutomationRegistryConfig>(@supra_framework)
+
public fun get_automation_registry_config(): AutomationRegistryConfig acquires ActiveAutomationRegistryConfig {
+    borrow_global<ActiveAutomationRegistryConfig>(@supra_framework).main_config
+}
+
+ + + + + + + +## Function `get_next_epoch_registry_max_gas_cap` + +Get automation registry configration + + +
#[view]
+public fun get_next_epoch_registry_max_gas_cap(): u64
+
+ + + +
+Implementation + + +
public fun get_next_epoch_registry_max_gas_cap(): u64 acquires ActiveAutomationRegistryConfig {
+    borrow_global<ActiveAutomationRegistryConfig>(@supra_framework).next_epoch_registry_max_gas_cap
 }
 
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 84e4938fae3e7..06bb480b4d016 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -59,6 +59,13 @@ module supra_framework::automation_registry { const ACTIVE: u8 = 1; const CANCELLED: u8 = 2; + #[resource_group_member(group = supra_framework::object::ObjectGroup)] + struct ActiveAutomationRegistryConfig has key { + main_config: AutomationRegistryConfig, + /// Will be the same as main_config.registry_max_gas_cap, unless updated during the epoch. + next_epoch_registry_max_gas_cap: u64, + } + #[resource_group_member(group = supra_framework::object::ObjectGroup)] #[event] /// Automation registry config @@ -195,13 +202,16 @@ module supra_framework::automation_registry { registry_fee_address_signer_cap, }); - move_to(supra_framework, AutomationRegistryConfig { - task_duration_cap_in_secs, - registry_max_gas_cap, - automation_base_fee_in_quants_per_sec, - flat_registration_fee_in_quants, - congestion_threshold_percentage, - congestion_base_fee_in_quants_per_sec, + move_to(supra_framework, ActiveAutomationRegistryConfig { + main_config: AutomationRegistryConfig { + task_duration_cap_in_secs, + registry_max_gas_cap, + automation_base_fee_in_quants_per_sec, + flat_registration_fee_in_quants, + congestion_threshold_percentage, + congestion_base_fee_in_quants_per_sec, + }, + next_epoch_registry_max_gas_cap: registry_max_gas_cap }); let epoch_interval = epoch_interval_microsecs / MICROSECS_CONVERSION_FACTOR; @@ -213,7 +223,7 @@ module supra_framework::automation_registry { } /// On new epoch this function will be triggered and update the automation registry state - public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + public(friend) fun on_new_epoch() acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); let ids = enumerable_map::get_map_list(&automation_registry.tasks); @@ -243,7 +253,9 @@ module supra_framework::automation_registry { // Apply the latest configuration if any parameter has been updated. if (config_buffer::does_exist()) { let buffer = config_buffer::extract(); - let automation_registry_config = borrow_global_mut(@supra_framework); + let automation_registry_config = &mut borrow_global_mut( + @supra_framework + ).main_config; automation_registry_config.task_duration_cap_in_secs = buffer.task_duration_cap_in_secs; automation_registry_config.registry_max_gas_cap = buffer.registry_max_gas_cap; automation_registry_config.automation_base_fee_in_quants_per_sec = buffer.automation_base_fee_in_quants_per_sec; @@ -286,7 +298,7 @@ module supra_framework::automation_registry { flat_registration_fee_in_quants: u64, congestion_threshold_percentage: u8, congestion_base_fee_in_quants_per_sec: u64, - ) acquires AutomationRegistry { + ) acquires AutomationRegistry, ActiveAutomationRegistryConfig { system_addresses::assert_supra_framework(supra_framework); let automation_registry = borrow_global(@supra_framework); @@ -296,7 +308,7 @@ module supra_framework::automation_registry { EUNACCEPTABLE_AUTOMATION_GAS_LIMIT ); - let automation_registry_config = AutomationRegistryConfig { + let new_automation_registry_config = AutomationRegistryConfig { task_duration_cap_in_secs, registry_max_gas_cap, automation_base_fee_in_quants_per_sec, @@ -304,8 +316,13 @@ module supra_framework::automation_registry { congestion_threshold_percentage, congestion_base_fee_in_quants_per_sec, }; - config_buffer::upsert(copy automation_registry_config); - event::emit(automation_registry_config); + config_buffer::upsert(copy new_automation_registry_config); + + // next_epoch_registry_max_gas_cap will be update instantly + let automation_registry_config = borrow_global_mut(@supra_framework); + automation_registry_config.next_epoch_registry_max_gas_cap = registry_max_gas_cap; + + event::emit(new_automation_registry_config); } /// Deducts the automation fee from the user's account based on the selected expiry time. @@ -328,9 +345,9 @@ module supra_framework::automation_registry { max_gas_amount: u64, gas_price_cap: u64, tx_hash: vector - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); - let automation_registry_config = borrow_global(@supra_framework); + let automation_registry_config = borrow_global(@supra_framework); let automation_epoch_info = borrow_global(@supra_framework); //Well-formedness check of payload_tx is done in native layer beforehand. @@ -339,7 +356,7 @@ module supra_framework::automation_registry { let task_duration = check_registration_task_duration( expiry_time, registration_time, - automation_registry_config, + &automation_registry_config.main_config, automation_epoch_info ); @@ -351,7 +368,7 @@ module supra_framework::automation_registry { assert!(committed_gas <= MAX_U64, EGAS_COMMITTEED_VALUE_OVERFLOW); let committed_gas = (committed_gas as u64); - assert!(committed_gas < automation_registry_config.registry_max_gas_cap, EGAS_AMOUNT_UPPER); + assert!(committed_gas < automation_registry_config.next_epoch_registry_max_gas_cap, EGAS_AMOUNT_UPPER); automation_registry.gas_committed_for_next_epoch = committed_gas; let task_index = automation_registry.current_index; @@ -373,7 +390,7 @@ module supra_framework::automation_registry { charge_automation_fee_from_user( owner, - automation_registry_config, + &automation_registry_config.main_config, task_duration, automation_registry.registry_fee_address); } @@ -403,9 +420,9 @@ module supra_framework::automation_registry { /// - pending, it is removed form the list. /// - cancelled, an error is reported /// Committed gas-limit is updated by reducing it with the max-gas-amount of the cancelled task. - public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, AutomationRegistryConfig { + public entry fun cancel_task(owner: &signer, id: u64) acquires AutomationRegistry, ActiveAutomationRegistryConfig { let automation_registry = borrow_global_mut(@supra_framework); - let automation_registry_config = borrow_global(@supra_framework); + let automation_registry_config = borrow_global(@supra_framework); assert!(enumerable_map::contains(&automation_registry.tasks, id), EAUTOMATION_TASK_NOT_FOUND); let automation_task_metadata = enumerable_map::get_value(&mut automation_registry.tasks, id); @@ -429,7 +446,7 @@ module supra_framework::automation_registry { refund_automation_task_fee( signer::address_of(owner), &automation_task_metadata, - automation_registry_config + &automation_registry_config.main_config ); } @@ -512,8 +529,14 @@ module supra_framework::automation_registry { #[view] /// Get automation registry configration - public fun get_automation_registry_config(): AutomationRegistryConfig acquires AutomationRegistryConfig { - *borrow_global(@supra_framework) + public fun get_automation_registry_config(): AutomationRegistryConfig acquires ActiveAutomationRegistryConfig { + borrow_global(@supra_framework).main_config + } + + #[view] + /// Get automation registry configration + public fun get_next_epoch_registry_max_gas_cap(): u64 acquires ActiveAutomationRegistryConfig { + borrow_global(@supra_framework).next_epoch_registry_max_gas_cap } #[test_only] @@ -575,7 +598,7 @@ module supra_framework::automation_registry { fun test_registry( supra_framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(supra_framework, user); let payload = x"0102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132"; @@ -586,7 +609,7 @@ module supra_framework::automation_registry { #[test(framework = @supra_framework, user = @0x1cafe)] fun check_update_config_success_update( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -600,12 +623,13 @@ module supra_framework::automation_registry { // Configration parameter will update after on new epoch update_config(framework, 1_626_560, 75, 1005, 700000000, 70, 2000); - let state = borrow_global(@supra_framework); - assert!(state.registry_max_gas_cap == AUTOMATION_MAX_GAS_TEST, 1); + let state = borrow_global(@supra_framework); + assert!(state.main_config.registry_max_gas_cap == AUTOMATION_MAX_GAS_TEST, 1); + assert!(state.next_epoch_registry_max_gas_cap == 75, 1); // Automation gas limit on_new_epoch(); - let state = borrow_global(@supra_framework); + let state = borrow_global(@supra_framework).main_config; assert!(state.registry_max_gas_cap == 75, 2); assert!(state.task_duration_cap_in_secs == 1_626_560, 3); assert!(state.automation_base_fee_in_quants_per_sec == 1005, 4); @@ -618,7 +642,7 @@ module supra_framework::automation_registry { #[expected_failure(abort_code = EUNACCEPTABLE_AUTOMATION_GAS_LIMIT, location = Self)] fun check_automation_gas_limit_failed_update( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -644,7 +668,7 @@ module supra_framework::automation_registry { fun check_task_registration( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -662,7 +686,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_expiry_time( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); timestamp::update_global_time_for_test_secs(50); @@ -680,7 +704,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_expiry_time_before_next_epoch( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -697,7 +721,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_gas_price_cap( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -714,7 +738,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_max_gas_amount( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -730,7 +754,7 @@ module supra_framework::automation_registry { fun check_registration_invalid_parent_hash( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -747,7 +771,7 @@ module supra_framework::automation_registry { fun check_registration_with_overflow_gas_limit( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -771,7 +795,7 @@ module supra_framework::automation_registry { fun check_task_activation_on_new_epoch( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, PAYLOAD, @@ -822,7 +846,7 @@ module supra_framework::automation_registry { fun check_task_successful_cancellation( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -903,7 +927,7 @@ module supra_framework::automation_registry { fun check_cancellation_of_non_existing_task( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationRegistryConfig { + ) acquires AutomationRegistry, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); cancel_task(user, 1); @@ -915,7 +939,7 @@ module supra_framework::automation_registry { framework: &signer, user: &signer, user2: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, @@ -933,7 +957,7 @@ module supra_framework::automation_registry { fun check_cacellation_of_cancelled_task( framework: &signer, user: &signer - ) acquires AutomationRegistry, AutomationEpochInfo, AutomationRegistryConfig { + ) acquires AutomationRegistry, AutomationEpochInfo, ActiveAutomationRegistryConfig { initialize_registry_test(framework, user); register(user, From edb24cc9e326ed4d59823dda1c9c422853eabec6 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Wed, 22 Jan 2025 19:04:07 +0530 Subject: [PATCH 10/13] automation registry - rename `RefundFeeUser` to `AutomationCancellationRefund` and add task_index + create common `config_update_from_buffer` internal function + add expirty_time>current_time condition in to `refund_automation_task_fee` fun --- .../doc/automation_registry.md | 67 ++++++++++++++++--- .../sources/automation_registry.move | 27 +++++--- 2 files changed, 75 insertions(+), 19 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 0909857c45def..037620815bbe1 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -14,12 +14,13 @@ This contract is part of the Supra Framework and is designed to manage automated - [Resource `AutomationEpochInfo`](#0x1_automation_registry_AutomationEpochInfo) - [Resource `AutomationTaskMetaData`](#0x1_automation_registry_AutomationTaskMetaData) - [Struct `FeeWithdrawnAdmin`](#0x1_automation_registry_FeeWithdrawnAdmin) -- [Struct `RefundFeeUser`](#0x1_automation_registry_RefundFeeUser) +- [Struct `AutomationCancellationRefund`](#0x1_automation_registry_AutomationCancellationRefund) - [Struct `CancelledAutomationTask`](#0x1_automation_registry_CancelledAutomationTask) - [Constants](#@Constants_0) - [Function `initializate_by_default`](#0x1_automation_registry_initializate_by_default) - [Function `initialize`](#0x1_automation_registry_initialize) - [Function `on_new_epoch`](#0x1_automation_registry_on_new_epoch) +- [Function `config_update_from_buffer`](#0x1_automation_registry_config_update_from_buffer) - [Function `withdraw_automation_task_fees`](#0x1_automation_registry_withdraw_automation_task_fees) - [Function `transfer_fee_to_account_internal`](#0x1_automation_registry_transfer_fee_to_account_internal) - [Function `update_config`](#0x1_automation_registry_update_config) @@ -361,15 +362,15 @@ Withdraw user's registration fee event
- + -## Struct `RefundFeeUser` +## Struct `AutomationCancellationRefund` Withdraw user's registration fee event
#[event]
-struct RefundFeeUser has drop, store
+struct AutomationCancellationRefund has drop, store
 
@@ -384,6 +385,12 @@ Withdraw user's registration fee event
+
+
+task_index: u64 +
+
+
amount: u64 @@ -568,6 +575,16 @@ Transactoin hash that registring current task is invalid. Lenght should be 32. + + +The task is already expired + + +
const ETASK_IS_ALREADY_EXPIRED: u64 = 14;
+
+ + + Current committed gas amount is greater than the automation gas limit. @@ -772,6 +789,35 @@ On new epoch this function will be triggered and update the automation registry }); // Apply the latest configuration if any parameter has been updated. + config_update_from_buffer(); + + automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; + automation_epoch_info.start_time = current_time; + automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval; +} +
+ + + + + + + +## Function `config_update_from_buffer` + +The function updates the ActiveAutomationRegistryConfig structure with values extracted from the buffer, if the buffer exists. + + +
fun config_update_from_buffer()
+
+ + + +
+Implementation + + +
fun config_update_from_buffer() acquires ActiveAutomationRegistryConfig {
     if (config_buffer::does_exist<AutomationRegistryConfig>()) {
         let buffer = config_buffer::extract<AutomationRegistryConfig>();
         let automation_registry_config = &mut borrow_global_mut<ActiveAutomationRegistryConfig>(
@@ -784,10 +830,6 @@ On new epoch this function will be triggered and update the automation registry
         automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage;
         automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec;
     };
-
-    automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch;
-    automation_epoch_info.start_time = current_time;
-    automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval;
 }
 
@@ -1138,11 +1180,14 @@ Refunds the automation task fee to the user who has removed their task registrat automation_registry_config: &AutomationRegistryConfig, ) acquires AutomationRegistry { let current_time = timestamp::now_seconds(); - let expiry_time_duration = automation_task_metadata.expiry_time - current_time; + assert!(automation_task_metadata.expiry_time < current_time, ETASK_IS_ALREADY_EXPIRED); + let residual_ttl = automation_task_metadata.expiry_time - current_time; - let refund_amount = expiry_time_duration * automation_registry_config.automation_base_fee_in_quants_per_sec; + let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; transfer_fee_to_account_internal(user, refund_amount); - event::emit(RefundFeeUser { user, amount: refund_amount }); + event::emit( + AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } + ); }
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 06bb480b4d016..26e895c74847d 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -44,6 +44,8 @@ module supra_framework::automation_registry { const EGAS_COMMITTEED_VALUE_OVERFLOW: u64 = 12; /// The gas committed for next epoch value is underflow after remove old max gas const EGAS_COMMITTEED_VALUE_UNDERFLOW: u64 = 13; + /// The task is already expired + const ETASK_IS_ALREADY_EXPIRED: u64 = 14; /// The lenght of the transaction hash. const TXN_HASH_LENGTH: u64 = 32; @@ -151,8 +153,9 @@ module supra_framework::automation_registry { #[event] /// Withdraw user's registration fee event - struct RefundFeeUser has drop, store { + struct AutomationCancellationRefund has drop, store { user: address, + task_index: u64, amount: u64 } @@ -251,6 +254,15 @@ module supra_framework::automation_registry { }); // Apply the latest configuration if any parameter has been updated. + config_update_from_buffer(); + + automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; + automation_epoch_info.start_time = current_time; + automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval; + } + + /// The function updates the ActiveAutomationRegistryConfig structure with values extracted from the buffer, if the buffer exists. + fun config_update_from_buffer() acquires ActiveAutomationRegistryConfig { if (config_buffer::does_exist()) { let buffer = config_buffer::extract(); let automation_registry_config = &mut borrow_global_mut( @@ -263,10 +275,6 @@ module supra_framework::automation_registry { automation_registry_config.congestion_threshold_percentage = buffer.congestion_threshold_percentage; automation_registry_config.congestion_base_fee_in_quants_per_sec = buffer.congestion_base_fee_in_quants_per_sec; }; - - automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; - automation_epoch_info.start_time = current_time; - automation_epoch_info.expected_epoch_duration = automation_epoch_info.epoch_interval; } /// Withdraw accumulated automation task fees from the resource account - access by admin @@ -457,11 +465,14 @@ module supra_framework::automation_registry { automation_registry_config: &AutomationRegistryConfig, ) acquires AutomationRegistry { let current_time = timestamp::now_seconds(); - let expiry_time_duration = automation_task_metadata.expiry_time - current_time; + assert!(automation_task_metadata.expiry_time < current_time, ETASK_IS_ALREADY_EXPIRED); + let residual_ttl = automation_task_metadata.expiry_time - current_time; - let refund_amount = expiry_time_duration * automation_registry_config.automation_base_fee_in_quants_per_sec; + let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; transfer_fee_to_account_internal(user, refund_amount); - event::emit(RefundFeeUser { user, amount: refund_amount }); + event::emit( + AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } + ); } /// Update epoch interval in registry while actually update happens in block module From 0f3b49ead364f410838665015423311c9894e432 Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Wed, 22 Jan 2025 19:14:21 +0530 Subject: [PATCH 11/13] fix - asserstion mistake fix which included in last commit and update function name --- .../supra-framework/doc/automation_registry.md | 14 +++++++------- .../sources/automation_registry.move | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md index 037620815bbe1..168daaa73e7a0 100644 --- a/aptos-move/framework/supra-framework/doc/automation_registry.md +++ b/aptos-move/framework/supra-framework/doc/automation_registry.md @@ -20,7 +20,7 @@ This contract is part of the Supra Framework and is designed to manage automated - [Function `initializate_by_default`](#0x1_automation_registry_initializate_by_default) - [Function `initialize`](#0x1_automation_registry_initialize) - [Function `on_new_epoch`](#0x1_automation_registry_on_new_epoch) -- [Function `config_update_from_buffer`](#0x1_automation_registry_config_update_from_buffer) +- [Function `update_config_from_buffer`](#0x1_automation_registry_update_config_from_buffer) - [Function `withdraw_automation_task_fees`](#0x1_automation_registry_withdraw_automation_task_fees) - [Function `transfer_fee_to_account_internal`](#0x1_automation_registry_transfer_fee_to_account_internal) - [Function `update_config`](#0x1_automation_registry_update_config) @@ -789,7 +789,7 @@ On new epoch this function will be triggered and update the automation registry }); // Apply the latest configuration if any parameter has been updated. - config_update_from_buffer(); + update_config_from_buffer(); automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch; automation_epoch_info.start_time = current_time; @@ -801,14 +801,14 @@ On new epoch this function will be triggered and update the automation registry - + -## Function `config_update_from_buffer` +## Function `update_config_from_buffer` The function updates the ActiveAutomationRegistryConfig structure with values extracted from the buffer, if the buffer exists. -
fun config_update_from_buffer()
+
fun update_config_from_buffer()
 
@@ -817,7 +817,7 @@ The function updates the ActiveAutomationRegistryConfig structure with values ex Implementation -
fun config_update_from_buffer() acquires ActiveAutomationRegistryConfig {
+
fun update_config_from_buffer() acquires ActiveAutomationRegistryConfig {
     if (config_buffer::does_exist<AutomationRegistryConfig>()) {
         let buffer = config_buffer::extract<AutomationRegistryConfig>();
         let automation_registry_config = &mut borrow_global_mut<ActiveAutomationRegistryConfig>(
@@ -1180,7 +1180,7 @@ Refunds the automation task fee to the user who has removed their task registrat
     automation_registry_config: &AutomationRegistryConfig,
 ) acquires AutomationRegistry {
     let current_time = timestamp::now_seconds();
-    assert!(automation_task_metadata.expiry_time < current_time, ETASK_IS_ALREADY_EXPIRED);
+    assert!(automation_task_metadata.expiry_time > current_time, ETASK_IS_ALREADY_EXPIRED);
     let residual_ttl = automation_task_metadata.expiry_time - current_time;
 
     let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec;
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move
index 26e895c74847d..04c62f31b03b4 100644
--- a/aptos-move/framework/supra-framework/sources/automation_registry.move
+++ b/aptos-move/framework/supra-framework/sources/automation_registry.move
@@ -254,7 +254,7 @@ module supra_framework::automation_registry {
         });
 
         // Apply the latest configuration if any parameter has been updated.
-        config_update_from_buffer();
+        update_config_from_buffer();
 
         automation_registry.gas_committed_for_next_epoch = gas_committed_for_next_epoch;
         automation_epoch_info.start_time = current_time;
@@ -262,7 +262,7 @@ module supra_framework::automation_registry {
     }
 
     /// The function updates the ActiveAutomationRegistryConfig structure with values extracted from the buffer, if the buffer exists.
-    fun config_update_from_buffer() acquires ActiveAutomationRegistryConfig {
+    fun update_config_from_buffer() acquires ActiveAutomationRegistryConfig {
         if (config_buffer::does_exist()) {
             let buffer = config_buffer::extract();
             let automation_registry_config = &mut borrow_global_mut(
@@ -465,7 +465,7 @@ module supra_framework::automation_registry {
         automation_registry_config: &AutomationRegistryConfig,
     ) acquires AutomationRegistry {
         let current_time = timestamp::now_seconds();
-        assert!(automation_task_metadata.expiry_time < current_time, ETASK_IS_ALREADY_EXPIRED);
+        assert!(automation_task_metadata.expiry_time > current_time, ETASK_IS_ALREADY_EXPIRED);
         let residual_ttl = automation_task_metadata.expiry_time - current_time;
 
         let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec;

From 5c745c8846b7f21f406ad0ad2bf799671f1e1d88 Mon Sep 17 00:00:00 2001
From: nizam-supraoracles 
Date: Thu, 23 Jan 2025 18:02:27 +0530
Subject: [PATCH 12/13] automation registry - `refund_automation_task_fee` only
 if `automation_task_metadata.expiry_time > current_time`, otherwise do not
 fail the tx

---
 .../doc/automation_registry.md                | 29 +++++++------------
 .../sources/automation_registry.move          | 21 +++++++-------
 2 files changed, 20 insertions(+), 30 deletions(-)

diff --git a/aptos-move/framework/supra-framework/doc/automation_registry.md b/aptos-move/framework/supra-framework/doc/automation_registry.md
index 168daaa73e7a0..10c140bf4e24e 100644
--- a/aptos-move/framework/supra-framework/doc/automation_registry.md
+++ b/aptos-move/framework/supra-framework/doc/automation_registry.md
@@ -575,16 +575,6 @@ Transactoin hash that registring current task is invalid. Lenght should be 32.
 
 
 
-
-
-The task is already expired
-
-
-
const ETASK_IS_ALREADY_EXPIRED: u64 = 14;
-
- - - Current committed gas amount is greater than the automation gas limit. @@ -668,7 +658,7 @@ This is temporary function : until we have initialization flow properly implemen 2_626_560, 100_000_000, 1000, - 500000000, // 5 supra + 100_000_000, // 1 supra 80, 100, ); @@ -1180,14 +1170,15 @@ Refunds the automation task fee to the user who has removed their task registrat automation_registry_config: &AutomationRegistryConfig, ) acquires AutomationRegistry { let current_time = timestamp::now_seconds(); - assert!(automation_task_metadata.expiry_time > current_time, ETASK_IS_ALREADY_EXPIRED); - let residual_ttl = automation_task_metadata.expiry_time - current_time; - - let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; - transfer_fee_to_account_internal(user, refund_amount); - event::emit( - AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } - ); + if (automation_task_metadata.expiry_time > current_time) { + let residual_ttl = automation_task_metadata.expiry_time - current_time; + + let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; + transfer_fee_to_account_internal(user, refund_amount); + event::emit( + AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } + ); + } }
diff --git a/aptos-move/framework/supra-framework/sources/automation_registry.move b/aptos-move/framework/supra-framework/sources/automation_registry.move index 04c62f31b03b4..591af5402f7d4 100644 --- a/aptos-move/framework/supra-framework/sources/automation_registry.move +++ b/aptos-move/framework/supra-framework/sources/automation_registry.move @@ -44,8 +44,6 @@ module supra_framework::automation_registry { const EGAS_COMMITTEED_VALUE_OVERFLOW: u64 = 12; /// The gas committed for next epoch value is underflow after remove old max gas const EGAS_COMMITTEED_VALUE_UNDERFLOW: u64 = 13; - /// The task is already expired - const ETASK_IS_ALREADY_EXPIRED: u64 = 14; /// The lenght of the transaction hash. const TXN_HASH_LENGTH: u64 = 32; @@ -173,7 +171,7 @@ module supra_framework::automation_registry { 2_626_560, 100_000_000, 1000, - 500000000, // 5 supra + 100_000_000, // 1 supra 80, 100, ); @@ -465,14 +463,15 @@ module supra_framework::automation_registry { automation_registry_config: &AutomationRegistryConfig, ) acquires AutomationRegistry { let current_time = timestamp::now_seconds(); - assert!(automation_task_metadata.expiry_time > current_time, ETASK_IS_ALREADY_EXPIRED); - let residual_ttl = automation_task_metadata.expiry_time - current_time; - - let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; - transfer_fee_to_account_internal(user, refund_amount); - event::emit( - AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } - ); + if (automation_task_metadata.expiry_time > current_time) { + let residual_ttl = automation_task_metadata.expiry_time - current_time; + + let refund_amount = residual_ttl * automation_registry_config.automation_base_fee_in_quants_per_sec; + transfer_fee_to_account_internal(user, refund_amount); + event::emit( + AutomationCancellationRefund { user, task_index: automation_task_metadata.id, amount: refund_amount } + ); + } } /// Update epoch interval in registry while actually update happens in block module From 31b131494988b1860de73a9b151e50fd7e286def Mon Sep 17 00:00:00 2001 From: nizam-supraoracles Date: Thu, 23 Jan 2025 18:10:56 +0530 Subject: [PATCH 13/13] automation registry - autoupdate aptos_framework_sdk_builder --- .../src/aptos_framework_sdk_builder.rs | 58 ------------------- 1 file changed, 58 deletions(-) diff --git a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs index 2a677f8bca093..976a54183931a 100644 --- a/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs +++ b/aptos-move/framework/cached-packages/src/aptos_framework_sdk_builder.rs @@ -158,13 +158,6 @@ pub enum EntryFunctionCall { id: u64, }, - /// Update Automation Registry Config - AutomationRegistryUpdateConfig { - automation_gas_limit: u64, - duration_upper_limit: u64, - automation_unit_price: u64, - }, - /// Same as `publish_package` but as an entry function which can be called as a transaction. Because /// of current restrictions for txn parameters, the metadata needs to be passed in serialized form. CodePublishPackageTxn { @@ -1261,15 +1254,6 @@ impl EntryFunctionCall { cap_update_table, ), AutomationRegistryCancelTask { id } => automation_registry_cancel_task(id), - AutomationRegistryUpdateConfig { - automation_gas_limit, - duration_upper_limit, - automation_unit_price, - } => automation_registry_update_config( - automation_gas_limit, - duration_upper_limit, - automation_unit_price, - ), CodePublishPackageTxn { metadata_serialized, code, @@ -2294,30 +2278,6 @@ pub fn automation_registry_cancel_task(id: u64) -> TransactionPayload { )) } -/// Update Automation Registry Config -pub fn automation_registry_update_config( - automation_gas_limit: u64, - duration_upper_limit: u64, - automation_unit_price: u64, -) -> TransactionPayload { - TransactionPayload::EntryFunction(EntryFunction::new( - ModuleId::new( - AccountAddress::new([ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, - ]), - ident_str!("automation_registry").to_owned(), - ), - ident_str!("update_config").to_owned(), - vec![], - vec![ - bcs::to_bytes(&automation_gas_limit).unwrap(), - bcs::to_bytes(&duration_upper_limit).unwrap(), - bcs::to_bytes(&automation_unit_price).unwrap(), - ], - )) -} - /// Same as `publish_package` but as an entry function which can be called as a transaction. Because /// of current restrictions for txn parameters, the metadata needs to be passed in serialized form. pub fn code_publish_package_txn( @@ -5634,20 +5594,6 @@ mod decoder { } } - pub fn automation_registry_update_config( - payload: &TransactionPayload, - ) -> Option { - if let TransactionPayload::EntryFunction(script) = payload { - Some(EntryFunctionCall::AutomationRegistryUpdateConfig { - automation_gas_limit: bcs::from_bytes(script.args().get(0)?).ok()?, - duration_upper_limit: bcs::from_bytes(script.args().get(1)?).ok()?, - automation_unit_price: bcs::from_bytes(script.args().get(2)?).ok()?, - }) - } else { - None - } - } - pub fn code_publish_package_txn(payload: &TransactionPayload) -> Option { if let TransactionPayload::EntryFunction(script) = payload { Some(EntryFunctionCall::CodePublishPackageTxn { @@ -7580,10 +7526,6 @@ static SCRIPT_FUNCTION_DECODER_MAP: once_cell::sync::Lazy