From adfc615b81db70d8cce4bbfc29533edad0b32858 Mon Sep 17 00:00:00 2001 From: herryho Date: Fri, 19 Jan 2024 14:45:06 +0800 Subject: [PATCH 1/2] add recreate_currency_ongoing_timeunit function --- pallets/vtoken-minting/src/lib.rs | 21 +++++++++++++++++++ pallets/vtoken-minting/src/tests.rs | 19 +++++++++++++++++ pallets/vtoken-minting/src/weights.rs | 7 +++++++ .../src/weights/bifrost_vtoken_minting.rs | 6 ++++++ .../src/weights/bifrost_vtoken_minting.rs | 6 ++++++ 5 files changed, 59 insertions(+) diff --git a/pallets/vtoken-minting/src/lib.rs b/pallets/vtoken-minting/src/lib.rs index 0b46582f6..d40a79999 100644 --- a/pallets/vtoken-minting/src/lib.rs +++ b/pallets/vtoken-minting/src/lib.rs @@ -219,6 +219,10 @@ pub mod pallet { FastRedeemFailed { err: DispatchError, }, + CurrencyTimeUnitRecreated { + token_id: CurrencyIdOf, + time_unit: TimeUnit, + }, } #[pallet::error] @@ -802,6 +806,23 @@ pub mod pallet { Self::deposit_event(Event::MinTimeUnitSet { token_id, time_unit }); Ok(()) } + + #[pallet::call_index(13)] + #[pallet::weight({0})] + pub fn recreate_currency_ongoing_time_unit( + origin: OriginFor, + token_id: CurrencyIdOf, + time_unit: TimeUnit, + ) -> DispatchResult { + T::ControlOrigin::ensure_origin(origin)?; + + OngoingTimeUnit::::mutate(&token_id, |old_time_unit| { + *old_time_unit = Some(time_unit.clone()) + }); + + Self::deposit_event(Event::CurrencyTimeUnitRecreated { token_id, time_unit }); + Ok(()) + } } impl Pallet { diff --git a/pallets/vtoken-minting/src/tests.rs b/pallets/vtoken-minting/src/tests.rs index f2d91c3e7..0ee5ebdf5 100644 --- a/pallets/vtoken-minting/src/tests.rs +++ b/pallets/vtoken-minting/src/tests.rs @@ -489,3 +489,22 @@ fn fast_redeem_for_fil() { ); }); } + +#[test] +fn recreate_currency_ongoing_time_unit_should_work() { + ExtBuilder::default().one_hundred_for_alice_n_bob().build().execute_with(|| { + env_logger::try_init().unwrap_or(()); + + // set KSM ongoing time unit to be Era(1) + OngoingTimeUnit::::insert(KSM, TimeUnit::Era(1)); + assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Era(1))); + + // recreate_currency_ongoing_time_unit the ongoing time unit of KSM to be Round(2) + assert_ok!(VtokenMinting::recreate_currency_ongoing_time_unit( + RuntimeOrigin::root(), + KSM, + TimeUnit::Round(2) + )); + assert_eq!(VtokenMinting::ongoing_time_unit(KSM), Some(TimeUnit::Round(2))); + }) +} diff --git a/pallets/vtoken-minting/src/weights.rs b/pallets/vtoken-minting/src/weights.rs index f83fd7ca5..2cdc0f2de 100644 --- a/pallets/vtoken-minting/src/weights.rs +++ b/pallets/vtoken-minting/src/weights.rs @@ -65,6 +65,7 @@ pub trait WeightInfo { fn rebond() -> Weight; fn rebond_by_unlock_id() -> Weight; fn on_initialize() -> Weight; + fn recreate_currency_ongoing_time_unit() -> Weight; } // For backwards compatibility and tests @@ -278,4 +279,10 @@ impl WeightInfo for () { Weight::from_parts(15_243_000, 3492) .saturating_add(RocksDbWeight::get().reads(1_u64)) } + + fn recreate_currency_ongoing_time_unit() -> Weight { + Weight::from_parts(70_238_000, 4197) + .saturating_add(RocksDbWeight::get().reads(2_u64)) + .saturating_add(RocksDbWeight::get().writes(1_u64)) + } } diff --git a/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs b/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs index 357805ee9..5868cdd65 100644 --- a/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs +++ b/runtime/bifrost-kusama/src/weights/bifrost_vtoken_minting.rs @@ -263,4 +263,10 @@ impl bifrost_vtoken_minting::WeightInfo for BifrostWeig Weight::from_parts(16_763_000, 3492) .saturating_add(T::DbWeight::get().reads(1)) } + + fn recreate_currency_ongoing_time_unit() -> Weight { + Weight::from_parts(70_238_000, 4197) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } diff --git a/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs b/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs index 357805ee9..5868cdd65 100644 --- a/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs +++ b/runtime/bifrost-polkadot/src/weights/bifrost_vtoken_minting.rs @@ -263,4 +263,10 @@ impl bifrost_vtoken_minting::WeightInfo for BifrostWeig Weight::from_parts(16_763_000, 3492) .saturating_add(T::DbWeight::get().reads(1)) } + + fn recreate_currency_ongoing_time_unit() -> Weight { + Weight::from_parts(70_238_000, 4197) + .saturating_add(T::DbWeight::get().reads(2_u64)) + .saturating_add(T::DbWeight::get().writes(1_u64)) + } } From 7506ad50e706fb0cb6f16365a5b0629405b5f552 Mon Sep 17 00:00:00 2001 From: herryho Date: Fri, 19 Jan 2024 15:52:01 +0800 Subject: [PATCH 2/2] fixes --- pallets/vtoken-minting/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/vtoken-minting/src/tests.rs b/pallets/vtoken-minting/src/tests.rs index 0ee5ebdf5..55825f508 100644 --- a/pallets/vtoken-minting/src/tests.rs +++ b/pallets/vtoken-minting/src/tests.rs @@ -501,7 +501,7 @@ fn recreate_currency_ongoing_time_unit_should_work() { // recreate_currency_ongoing_time_unit the ongoing time unit of KSM to be Round(2) assert_ok!(VtokenMinting::recreate_currency_ongoing_time_unit( - RuntimeOrigin::root(), + RuntimeOrigin::signed(ALICE), KSM, TimeUnit::Round(2) ));